Skip to content

Commit

Permalink
fix: peg-out request UTXO output amount correction + docstrings for p…
Browse files Browse the repository at this point in the history
…eg ops

Co-authored-by: Jude Nelson <[email protected]>
  • Loading branch information
netrome and jcnelson committed Feb 21, 2023
1 parent 4529a90 commit e01cf64
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/chainstate/burn/operations/peg_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ use crate::vm::types::QualifiedContractIdentifier;
use crate::vm::types::StandardPrincipalData;
use crate::vm::ContractName;

/// Transaction structure:
///
/// Output 0: data output (see PegInOp::parse_data())
/// Output 1: payment to peg wallet address
///
impl PegInOp {
pub fn from_tx(
block_header: &BurnchainBlockHeader,
Expand Down
7 changes: 7 additions & 0 deletions src/chainstate/burn/operations/peg_out_fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ use crate::types::Address;
use crate::chainstate::burn::operations::Error as OpError;
use crate::chainstate::burn::operations::PegOutFulfillOp;

/// Transaction structure:
///
/// Input 0: The 2nd output of a PegOutRequestOp, spent by the peg wallet (to pay the tx fee)
///
/// Output 0: data output (see PegOutFulfillOp::parse_data())
/// Output 1: Bitcoin address to send the BTC to
///
impl PegOutFulfillOp {
pub fn from_tx(
block_header: &BurnchainBlockHeader,
Expand Down
6 changes: 6 additions & 0 deletions src/chainstate/burn/operations/peg_out_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ use crate::types::Address;
use crate::chainstate::burn::operations::Error as OpError;
use crate::chainstate::burn::operations::PegOutRequestOp;

/// Transaction structure:
///
/// Output 0: data output (see PegOutRequestOp::parse_data())
/// Output 1: Bitcoin address to send the BTC to
/// Output 2: Bitcoin fee payment to the peg wallet (which the peg wallet will spend on fulfillment)
///
impl PegOutRequestOp {
pub fn from_tx(
block_header: &BurnchainBlockHeader,
Expand Down
10 changes: 7 additions & 3 deletions testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,8 +1243,8 @@ impl BitcoinRegtestController {
let dust_amount = 10000;

let output_amt = DUST_UTXO_LIMIT
+ dust_amount
+ max_tx_size * self.config.burnchain.satoshis_per_byte
+ payload.amount
+ payload.fulfillment_fee;
let (mut tx, mut utxos) =
self.prepare_tx(epoch_id, &public_key, output_amt, None, None, 0)?;
Expand All @@ -1268,12 +1268,16 @@ impl BitcoinRegtestController {
tx.output = vec![amount_and_signature_output];
tx.output
.push(payload.recipient.to_bitcoin_tx_out(dust_amount));
tx.output.push(payload.peg_wallet_address.to_bitcoin_tx_out(payload.fulfillment_fee));
tx.output.push(
payload
.peg_wallet_address
.to_bitcoin_tx_out(payload.fulfillment_fee),
);

self.finalize_tx(
epoch_id,
&mut tx,
payload.amount + payload.fulfillment_fee,
payload.fulfillment_fee,
0,
max_tx_size,
self.config.burnchain.satoshis_per_byte,
Expand Down
19 changes: 9 additions & 10 deletions testnet/stacks-node/src/tests/neon_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10757,8 +10757,7 @@ fn test_submit_and_observe_sbtc_ops() {
StandardPrincipalData::from(recipient_stx_addr).into();

let peg_wallet_sk = StacksPrivateKey::from_hex(SK_1).unwrap();
let peg_wallet_address =
address::PoxAddress::Standard(to_addr(&peg_wallet_sk), None);
let peg_wallet_address = address::PoxAddress::Standard(to_addr(&peg_wallet_sk), None);

let recipient_btc_addr = address::PoxAddress::Standard(recipient_stx_addr, None);

Expand Down Expand Up @@ -10916,13 +10915,13 @@ fn test_submit_and_observe_sbtc_ops() {
let mut miner_signer = Keychain::default(conf.node.seed.clone()).generate_op_signer();

let peg_out_request_txid = btc_regtest_controller
.submit_operation(
StacksEpochId::Epoch21,
BlockstackOperationType::PegOutRequest(peg_out_request_op.clone()),
&mut miner_signer,
1
).expect(
"Peg-out request operation should submit successfully");
.submit_operation(
StacksEpochId::Epoch21,
BlockstackOperationType::PegOutRequest(peg_out_request_op.clone()),
&mut miner_signer,
1,
)
.expect("Peg-out request operation should submit successfully");

next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);

Expand Down Expand Up @@ -10955,7 +10954,7 @@ fn test_submit_and_observe_sbtc_ops() {
StacksEpochId::Epoch21,
BlockstackOperationType::PegOutFulfill(peg_out_fulfill_op.clone()),
&mut peg_wallet_signer,
Some(peg_out_request_utxo),
Some(peg_out_request_utxo),
)
.is_some(),
"Peg-out fulfill operation should submit successfully"
Expand Down

0 comments on commit e01cf64

Please sign in to comment.