@@ -3556,6 +3556,7 @@ fn tx_replay_btc_on_stx_invalidation() {
3556
3556
vec![(sender_addr, (send_amt + send_fee) * 10)],
3557
3557
|c| {
3558
3558
c.validate_with_replay_tx = true;
3559
+ c.reset_replay_set_after_fork_blocks = 5;
3559
3560
},
3560
3561
|node_config| {
3561
3562
node_config.miner.block_commit_delay = Duration::from_secs(1);
@@ -3572,13 +3573,11 @@ fn tx_replay_btc_on_stx_invalidation() {
3572
3573
let mut miner_keychain = Keychain::default(conf.node.seed.clone()).generate_op_signer();
3573
3574
let _http_origin = format!("http://{}", &conf.node.rpc_bind);
3574
3575
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();
3582
3581
3583
3582
if signer_test.bootstrap_snapshot() {
3584
3583
signer_test.shutdown_and_snapshot();
@@ -3587,6 +3586,18 @@ fn tx_replay_btc_on_stx_invalidation() {
3587
3586
3588
3587
info!("------------------------- Beginning test -------------------------");
3589
3588
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
+
3590
3601
info!("Submitting first pre-stx op");
3591
3602
let pre_stx_op = PreStxOp {
3592
3603
output: sender_addr,
@@ -3609,7 +3620,7 @@ fn tx_replay_btc_on_stx_invalidation() {
3609
3620
"Pre-stx operation should submit successfully"
3610
3621
);
3611
3622
3612
- let pre_fork_tenures = 1 ;
3623
+ let pre_fork_tenures = 10 ;
3613
3624
for i in 0..pre_fork_tenures {
3614
3625
info!("Mining pre-fork tenure {} of {pre_fork_tenures}", i + 1);
3615
3626
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
@@ -3659,51 +3670,45 @@ fn tx_replay_btc_on_stx_invalidation() {
3659
3670
3660
3671
info!("---- Triggering Bitcoin fork ----");
3661
3672
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);
3675
3675
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);
3689
3677
3690
- btc_controller.build_next_block(1 );
3678
+ TEST_MINE_STALL.set(true );
3691
3679
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,
3699
3686
);
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
+ }
3703
3693
3704
3694
info!("---- Wait for tx replay set to be updated ----");
3705
3695
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");
3707
3712
3708
3713
info!("---- Waiting for tx replay set to be cleared ----");
3709
3714
@@ -3715,24 +3720,24 @@ fn tx_replay_btc_on_stx_invalidation() {
3715
3720
.wait_for_signer_state_check(30, |state| Ok(state.get_tx_replay_set().is_none()))
3716
3721
.expect("Timed out waiting for tx replay set to be cleared");
3717
3722
3718
- let account = get_account(&_http_origin, &recipient_addr);
3719
- assert_eq!(account.nonce, 0, "Expected recipient nonce to be 0");
3720
-
3721
3723
// Ensure that only one block was mined
3722
3724
wait_for(30, || {
3723
3725
let new_tip = get_chain_info(&conf).stacks_tip_height;
3724
3726
Ok(new_tip == stacks_height_before + 1)
3725
3727
})
3726
3728
.expect("Timed out waiting for block to advance by 1");
3727
3729
3730
+ let account = get_account(&_http_origin, &recipient_addr);
3731
+ assert_eq!(account.nonce, 0, "Expected recipient nonce to be 0");
3732
+
3728
3733
let blocks = test_observer::get_blocks();
3729
3734
let block: StacksBlockEvent =
3730
3735
serde_json::from_value(blocks.last().unwrap().clone()).expect("Failed to parse block");
3731
3736
assert_eq!(block.transactions.len(), 2);
3732
3737
assert!(matches!(
3733
3738
block.transactions[0].payload,
3734
3739
TransactionPayload::TenureChange(TenureChangePayload {
3735
- cause: TenureChangeCause::Extended ,
3740
+ cause: TenureChangeCause::BlockFound ,
3736
3741
..
3737
3742
})
3738
3743
));
0 commit comments