Skip to content

Commit 7e8f2a3

Browse files
authored
Merge pull request #5769 from stacks-network/test/partial-tenure-flake
Test: fix some test flake in partial_tenure_forking
2 parents 59c7e7c + 0b16c0a commit 7e8f2a3

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

testnet/stacks-node/src/globals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct Globals<T> {
5353
unconfirmed_txs: Arc<Mutex<UnconfirmedTxMap>>,
5454
/// Writer endpoint to the relayer thread
5555
pub relay_send: SyncSender<T>,
56-
/// Cointer state in the main thread
56+
/// Counter state in the main thread
5757
pub counters: Counters,
5858
/// Connection to the PoX sync watchdog
5959
pub sync_comms: PoxSyncWatchdogComms,

testnet/stacks-node/src/nakamoto_node/relayer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ impl RelayerThread {
16391639
self.last_commits.insert(txid);
16401640
self.globals
16411641
.counters
1642-
.bump_naka_submitted_commits(last_committed.burn_tip.block_height);
1642+
.bump_naka_submitted_commits(last_committed.burn_tip.block_height, tip_height);
16431643
self.last_committed = Some(last_committed);
16441644

16451645
Ok(())

testnet/stacks-node/src/run_loop/neon.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub struct Counters {
116116
pub naka_mined_tenures: RunLoopCounter,
117117
pub naka_signer_pushed_blocks: RunLoopCounter,
118118
pub naka_miner_directives: RunLoopCounter,
119+
pub naka_submitted_commit_last_stacks_tip: RunLoopCounter,
119120

120121
#[cfg(test)]
121122
pub naka_skip_commit_op: TestFlag<bool>,
@@ -170,11 +171,19 @@ impl Counters {
170171
Counters::inc(&self.naka_submitted_vrfs);
171172
}
172173

173-
pub fn bump_naka_submitted_commits(&self, committed_height: u64) {
174+
pub fn bump_naka_submitted_commits(
175+
&self,
176+
committed_burn_height: u64,
177+
committed_stacks_height: u64,
178+
) {
174179
Counters::inc(&self.naka_submitted_commits);
175180
Counters::set(
176181
&self.naka_submitted_commit_last_burn_height,
177-
committed_height,
182+
committed_burn_height,
183+
);
184+
Counters::set(
185+
&self.naka_submitted_commit_last_stacks_tip,
186+
committed_stacks_height,
178187
);
179188
}
180189

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub struct RunningNodes {
8383
pub nakamoto_blocks_signer_pushed: RunLoopCounter,
8484
pub nakamoto_miner_directives: Arc<AtomicU64>,
8585
pub nakamoto_test_skip_commit_op: TestFlag<bool>,
86+
pub counters: Counters,
8687
pub coord_channel: Arc<Mutex<CoordinatorChannels>>,
8788
pub conf: NeonConfig,
8889
}
@@ -933,6 +934,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
933934
naka_signer_pushed_blocks,
934935
..
935936
} = run_loop.counters();
937+
let counters = run_loop.counters();
936938

937939
let coord_channel = run_loop.coordinator_channels();
938940
let run_loop_thread = thread::spawn(move || run_loop.start(None, 0));
@@ -970,6 +972,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
970972
nakamoto_test_skip_commit_op,
971973
nakamoto_miner_directives: naka_miner_directives.0,
972974
coord_channel,
975+
counters,
973976
conf: naka_conf,
974977
}
975978
}

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,6 +5031,8 @@ fn partial_tenure_fork() {
50315031
naka_skip_commit_op: rl2_skip_commit_op,
50325032
..
50335033
} = run_loop_2.counters();
5034+
let rl2_counters = run_loop_2.counters();
5035+
let rl1_counters = signer_test.running_nodes.counters.clone();
50345036

50355037
signer_test.boot_to_epoch_3();
50365038
let run_loop_2_thread = thread::Builder::new()
@@ -5101,35 +5103,37 @@ fn partial_tenure_fork() {
51015103
rl1_skip_commit_op.set(true);
51025104
rl2_skip_commit_op.set(true);
51035105

5104-
let mined_before_1 = blocks_mined1.load(Ordering::SeqCst);
5105-
let mined_before_2 = blocks_mined2.load(Ordering::SeqCst);
5106-
let commits_before_1 = commits_1.load(Ordering::SeqCst);
5107-
let commits_before_2 = commits_2.load(Ordering::SeqCst);
5106+
let info_before = get_chain_info(&conf);
51085107

51095108
// Mine the first block
51105109
next_block_and(
51115110
&mut signer_test.running_nodes.btc_regtest_controller,
51125111
180,
51135112
|| {
5114-
let mined_1 = blocks_mined1.load(Ordering::SeqCst);
5115-
let mined_2 = blocks_mined2.load(Ordering::SeqCst);
5116-
5117-
Ok(mined_1 > mined_before_1 || mined_2 > mined_before_2)
5113+
let info_1 = get_chain_info(&conf);
5114+
Ok(info_1.stacks_tip_height > info_before.stacks_tip_height)
51185115
},
51195116
)
51205117
.expect("Timed out waiting for new Stacks block to be mined");
51215118

51225119
info!("-------- Mined first block, wait for block commits --------");
51235120

5121+
let info_before = get_chain_info(&conf);
5122+
51245123
// Unpause block commits and wait for both miners' commits
51255124
rl1_skip_commit_op.set(false);
51265125
rl2_skip_commit_op.set(false);
51275126

5128-
// Ensure that both block commits have been sent before continuing
5127+
// Ensure that both miners' commits point at the stacks tip
51295128
wait_for(60, || {
5130-
let commits_after_1 = commits_1.load(Ordering::SeqCst);
5131-
let commits_after_2 = commits_2.load(Ordering::SeqCst);
5132-
Ok(commits_after_1 > commits_before_1 && commits_after_2 > commits_before_2)
5129+
let last_committed_1 = rl1_counters
5130+
.naka_submitted_commit_last_stacks_tip
5131+
.load(Ordering::SeqCst);
5132+
let last_committed_2 = rl2_counters
5133+
.naka_submitted_commit_last_stacks_tip
5134+
.load(Ordering::SeqCst);
5135+
Ok(last_committed_1 >= info_before.stacks_tip_height
5136+
&& last_committed_2 >= info_before.stacks_tip_height)
51335137
})
51345138
.expect("Timed out waiting for block commits");
51355139

0 commit comments

Comments
 (0)