Skip to content

Commit 8f790dc

Browse files
committed
fix: btc_on_stx test
1 parent de8b6e6 commit 8f790dc

File tree

1 file changed

+55
-50
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+55
-50
lines changed

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,6 +3556,7 @@ fn tx_replay_btc_on_stx_invalidation() {
35563556
vec![(sender_addr, (send_amt + send_fee) * 10)],
35573557
|c| {
35583558
c.validate_with_replay_tx = true;
3559+
c.reset_replay_set_after_fork_blocks = 5;
35593560
},
35603561
|node_config| {
35613562
node_config.miner.block_commit_delay = Duration::from_secs(1);
@@ -3572,13 +3573,11 @@ fn tx_replay_btc_on_stx_invalidation() {
35723573
let mut miner_keychain = Keychain::default(conf.node.seed.clone()).generate_op_signer();
35733574
let _http_origin = format!("http://{}", &conf.node.rpc_bind);
35743575
let mut btc_controller = BitcoinRegtestController::new(conf.clone(), None);
3575-
3576-
let miner_pk = btc_controller
3577-
.get_mining_pubkey()
3578-
.as_deref()
3579-
.map(Secp256k1PublicKey::from_hex)
3580-
.unwrap()
3581-
.unwrap();
3576+
let submitted_commits = signer_test
3577+
.running_nodes
3578+
.counters
3579+
.naka_submitted_commits
3580+
.clone();
35823581

35833582
if signer_test.bootstrap_snapshot() {
35843583
signer_test.shutdown_and_snapshot();
@@ -3587,6 +3586,18 @@ fn tx_replay_btc_on_stx_invalidation() {
35873586

35883587
info!("------------------------- Beginning test -------------------------");
35893588

3589+
let burnchain = conf.get_burnchain();
3590+
3591+
let tip = signer_test.get_peer_info();
3592+
let pox_info = signer_test.get_pox_data();
3593+
3594+
info!("---- Burnchain ----";
3595+
// "burnchain" => ?conf.burnchain,
3596+
"pox_constants" => ?burnchain.pox_constants,
3597+
"cycle" => burnchain.pox_constants.reward_cycle_index(0, tip.burn_block_height),
3598+
"pox_info" => ?pox_info,
3599+
);
3600+
35903601
info!("Submitting first pre-stx op");
35913602
let pre_stx_op = PreStxOp {
35923603
output: sender_addr,
@@ -3609,7 +3620,7 @@ fn tx_replay_btc_on_stx_invalidation() {
36093620
"Pre-stx operation should submit successfully"
36103621
);
36113622

3612-
let pre_fork_tenures = 1;
3623+
let pre_fork_tenures = 10;
36133624
for i in 0..pre_fork_tenures {
36143625
info!("Mining pre-fork tenure {} of {pre_fork_tenures}", i + 1);
36153626
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
@@ -3659,51 +3670,45 @@ fn tx_replay_btc_on_stx_invalidation() {
36593670

36603671
info!("---- Triggering Bitcoin fork ----");
36613672

3662-
let mut commit_txid: Option<Txid> = None;
3663-
wait_for(30, || {
3664-
let Some(txid) = signer_test.get_parent_block_commit_txid(&miner_pk) else {
3665-
return Ok(false);
3666-
};
3667-
commit_txid = Some(txid);
3668-
Ok(true)
3669-
})
3670-
.expect("Failed to get unconfirmed tx");
3671-
3672-
let tip_before = signer_test.get_peer_info();
3673-
let burn_header_hash_to_fork = btc_controller.get_block_hash(tip_before.burn_block_height - 1);
3674-
TEST_MINE_STALL.set(true);
3673+
let tip = signer_test.get_peer_info();
3674+
let burn_header_hash_to_fork = btc_controller.get_block_hash(tip.burn_block_height - 2);
36753675
btc_controller.invalidate_block(&burn_header_hash_to_fork);
3676-
btc_controller.build_next_block(2);
3677-
3678-
let tip_before = get_chain_info(&conf);
3679-
3680-
info!("---- Building next block ----";
3681-
"tip_before.stacks_tip_height" => tip_before.stacks_tip_height,
3682-
"tip_before.burn_block_height" => tip_before.burn_block_height,
3683-
);
3684-
3685-
let chain_tips = BitcoinRPCRequest::get_chain_tips(&conf).unwrap();
3686-
info!("---- chain_tips -----";
3687-
"chain_tips" => ?chain_tips,
3688-
);
3676+
btc_controller.build_next_block(3);
36893677

3690-
btc_controller.build_next_block(1);
3678+
TEST_MINE_STALL.set(true);
36913679

3692-
wait_for(30, || {
3693-
let tip = get_chain_info(&conf);
3694-
info!("----- tip -----";
3695-
"tip.stacks_tip_height" => tip.stacks_tip_height,
3696-
"tip_before.stacks_tip_height" => tip_before.stacks_tip_height,
3697-
"tip.burn_block_height" => tip.burn_block_height,
3698-
"tip_before.burn_block_height" => tip_before.burn_block_height,
3680+
// we need to mine some blocks to get back to being considered a frequent miner
3681+
for i in 0..3 {
3682+
let current_burn_height = get_chain_info(&conf).burn_block_height;
3683+
info!(
3684+
"Mining block #{i} to be considered a frequent miner";
3685+
"current_burn_height" => current_burn_height,
36993686
);
3700-
Ok(tip.stacks_tip_height < tip_before.stacks_tip_height)
3701-
})
3702-
.expect("Timed out waiting for next block to be mined");
3687+
let commits_count = submitted_commits.load(Ordering::SeqCst);
3688+
next_block_and(&btc_controller, 60, || {
3689+
Ok(submitted_commits.load(Ordering::SeqCst) > commits_count)
3690+
})
3691+
.unwrap();
3692+
}
37033693

37043694
info!("---- Wait for tx replay set to be updated ----");
37053695

3706-
signer_test.wait_for_replay_set_eq(30, vec![txid.clone()]);
3696+
signer_test
3697+
.wait_for_signer_state_check(30, |state| {
3698+
let Some(tx_replay_set) = state.get_tx_replay_set() else {
3699+
info!("---- No tx replay set");
3700+
return Ok(false);
3701+
};
3702+
let len_ok = tx_replay_set.len() == 1;
3703+
let txid_ok = tx_replay_set[0].txid().to_hex() == txid;
3704+
info!("---- Signer state check ----";
3705+
"tx_replay_set" => ?tx_replay_set,
3706+
"len_ok" => len_ok,
3707+
"txid_ok" => txid_ok,
3708+
);
3709+
Ok(len_ok && txid_ok)
3710+
})
3711+
.expect("Timed out waiting for tx replay set to be updated");
37073712

37083713
info!("---- Waiting for tx replay set to be cleared ----");
37093714

@@ -3715,24 +3720,24 @@ fn tx_replay_btc_on_stx_invalidation() {
37153720
.wait_for_signer_state_check(30, |state| Ok(state.get_tx_replay_set().is_none()))
37163721
.expect("Timed out waiting for tx replay set to be cleared");
37173722

3718-
let account = get_account(&_http_origin, &recipient_addr);
3719-
assert_eq!(account.nonce, 0, "Expected recipient nonce to be 0");
3720-
37213723
// Ensure that only one block was mined
37223724
wait_for(30, || {
37233725
let new_tip = get_chain_info(&conf).stacks_tip_height;
37243726
Ok(new_tip == stacks_height_before + 1)
37253727
})
37263728
.expect("Timed out waiting for block to advance by 1");
37273729

3730+
let account = get_account(&_http_origin, &recipient_addr);
3731+
assert_eq!(account.nonce, 0, "Expected recipient nonce to be 0");
3732+
37283733
let blocks = test_observer::get_blocks();
37293734
let block: StacksBlockEvent =
37303735
serde_json::from_value(blocks.last().unwrap().clone()).expect("Failed to parse block");
37313736
assert_eq!(block.transactions.len(), 2);
37323737
assert!(matches!(
37333738
block.transactions[0].payload,
37343739
TransactionPayload::TenureChange(TenureChangePayload {
3735-
cause: TenureChangeCause::Extended,
3740+
cause: TenureChangeCause::BlockFound,
37363741
..
37373742
})
37383743
));

0 commit comments

Comments
 (0)