Skip to content

Commit 60634c2

Browse files
committed
fix flake in check_block_times
1 parent bbc6ab8 commit 60634c2

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -780,19 +780,18 @@ pub fn next_block_and_wait_for_commits(
780780
.map(|info| info.stacks_tip_height)
781781
.max()
782782
.unwrap();
783-
let last_commit_burn_hts: Vec<_> = node_counters
783+
let last_commit_burn_hts = node_counters
784784
.iter()
785-
.map(|c| &c.naka_submitted_commit_last_burn_height)
786-
.collect();
787-
let last_commit_stacks_hts: Vec<_> = node_counters
785+
.map(|c| &c.naka_submitted_commit_last_burn_height);
786+
let last_commit_stacks_hts = node_counters
788787
.iter()
789-
.map(|c| &c.naka_submitted_commit_last_stacks_tip)
790-
.collect();
788+
.map(|c| &c.naka_submitted_commit_last_stacks_tip);
791789

792790
next_block_and(btc_controller, timeout_secs, || {
793-
let burn_height_committed_to = last_commit_burn_hts.iter().all(|last_commit_burn_height| {
794-
last_commit_burn_height.load(Ordering::SeqCst) > burn_ht_before
795-
});
791+
let burn_height_committed_to =
792+
last_commit_burn_hts.clone().all(|last_commit_burn_height| {
793+
last_commit_burn_height.load(Ordering::SeqCst) > burn_ht_before
794+
});
796795
if !wait_for_stacks_block {
797796
Ok(burn_height_committed_to)
798797
} else {
@@ -801,7 +800,7 @@ pub fn next_block_and_wait_for_commits(
801800
}
802801
let stacks_tip_committed_to =
803802
last_commit_stacks_hts
804-
.iter()
803+
.clone()
805804
.all(|last_commit_stacks_height| {
806805
last_commit_stacks_height.load(Ordering::SeqCst) > stacks_ht_before
807806
});
@@ -7564,6 +7563,7 @@ fn check_block_times() {
75647563
naka_proposed_blocks: proposals_submitted,
75657564
..
75667565
} = run_loop.counters();
7566+
let counters = run_loop.counters();
75677567

75687568
let coord_channel = run_loop.coordinator_channels();
75697569

@@ -7606,19 +7606,13 @@ fn check_block_times() {
76067606

76077607
info!("Nakamoto miner started...");
76087608
blind_signer(&naka_conf, &signers, proposals_submitted);
7609+
wait_for_first_naka_block_commit(60, &counters.naka_submitted_commits);
76097610

7610-
let epochs = naka_conf.burnchain.epochs.clone().unwrap();
7611-
let epoch_3 = &epochs[StacksEpochId::Epoch30];
7612-
let epoch_3_start = epoch_3.start_height;
7613-
let mut last_stacks_block_height = 0;
7614-
let mut last_tenure_height = 0;
7615-
next_block_and(&mut btc_regtest_controller, 60, || {
7616-
let info = get_chain_info_result(&naka_conf).unwrap();
7617-
last_stacks_block_height = info.stacks_tip_height as u128;
7618-
last_tenure_height = last_stacks_block_height + 1;
7619-
Ok(info.burn_block_height == epoch_3_start)
7620-
})
7621-
.unwrap();
7611+
let info = get_chain_info_result(&naka_conf).unwrap();
7612+
let mut last_stacks_block_height = info.stacks_tip_height as u128;
7613+
let mut last_tenure_height = last_stacks_block_height + 1;
7614+
7615+
next_block_and_mine_commit(&mut btc_regtest_controller, 60, &naka_conf, &counters).unwrap();
76227616

76237617
let time0_value = call_read_only(
76247618
&naka_conf,
@@ -7676,16 +7670,13 @@ fn check_block_times() {
76767670
Ok(stacks_block_height > last_stacks_block_height && cur_sender_nonce == sender_nonce)
76777671
})
76787672
.expect("Timed out waiting for contracts to publish");
7679-
last_stacks_block_height = stacks_block_height;
76807673

76817674
// Repeat these tests for 5 tenures
76827675
for _ in 0..5 {
7683-
next_block_and(&mut btc_regtest_controller, 60, || {
7684-
let info = get_chain_info_result(&naka_conf).unwrap();
7685-
stacks_block_height = info.stacks_tip_height as u128;
7686-
Ok(stacks_block_height > last_stacks_block_height)
7687-
})
7688-
.unwrap();
7676+
next_block_and_mine_commit(&mut btc_regtest_controller, 60, &naka_conf, &counters).unwrap();
7677+
let info = get_chain_info_result(&naka_conf).unwrap();
7678+
stacks_block_height = info.stacks_tip_height as u128;
7679+
76897680
last_stacks_block_height = stacks_block_height;
76907681
last_tenure_height += 1;
76917682
info!("New tenure {last_tenure_height}, Stacks height: {last_stacks_block_height}");

0 commit comments

Comments
 (0)