Skip to content

Commit 820702c

Browse files
committed
test: use last_commit_burn_height counter to address flakiness in miner_forking
1 parent ab90a9d commit 820702c

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,8 +1229,10 @@ impl RelayerThread {
12291229
// update local state
12301230
last_committed.set_txid(&txid);
12311231
self.last_commits.insert(txid);
1232+
self.globals
1233+
.counters
1234+
.bump_naka_submitted_commits(last_committed.burn_tip.block_height);
12321235
self.last_committed = Some(last_committed);
1233-
self.globals.counters.bump_naka_submitted_commits();
12341236

12351237
Ok(())
12361238
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ pub struct Counters {
106106

107107
pub naka_submitted_vrfs: RunLoopCounter,
108108
pub naka_submitted_commits: RunLoopCounter,
109+
/// the burn block height when the last commit was submitted
110+
pub naka_submitted_commit_last_burn_height: RunLoopCounter,
109111
pub naka_mined_blocks: RunLoopCounter,
110112
pub naka_rejected_blocks: RunLoopCounter,
111113
pub naka_proposed_blocks: RunLoopCounter,
@@ -161,8 +163,12 @@ impl Counters {
161163
Counters::inc(&self.naka_submitted_vrfs);
162164
}
163165

164-
pub fn bump_naka_submitted_commits(&self) {
166+
pub fn bump_naka_submitted_commits(&self, committed_height: u64) {
165167
Counters::inc(&self.naka_submitted_commits);
168+
Counters::set(
169+
&self.naka_submitted_commit_last_burn_height,
170+
committed_height,
171+
);
166172
}
167173

168174
pub fn bump_naka_mined_blocks(&self) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub struct RunningNodes {
8888
pub run_loop_stopper: Arc<AtomicBool>,
8989
pub vrfs_submitted: RunLoopCounter,
9090
pub commits_submitted: RunLoopCounter,
91+
pub last_commit_burn_height: RunLoopCounter,
9192
pub blocks_processed: RunLoopCounter,
9293
pub nakamoto_blocks_proposed: RunLoopCounter,
9394
pub nakamoto_blocks_mined: RunLoopCounter,
@@ -902,6 +903,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
902903
blocks_processed,
903904
naka_submitted_vrfs: vrfs_submitted,
904905
naka_submitted_commits: commits_submitted,
906+
naka_submitted_commit_last_burn_height: last_commit_burn_height,
905907
naka_proposed_blocks: naka_blocks_proposed,
906908
naka_mined_blocks: naka_blocks_mined,
907909
naka_rejected_blocks: naka_blocks_rejected,
@@ -936,6 +938,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
936938
run_loop_stopper,
937939
vrfs_submitted,
938940
commits_submitted,
941+
last_commit_burn_height,
939942
blocks_processed,
940943
nakamoto_blocks_proposed: naka_blocks_proposed,
941944
nakamoto_blocks_mined: naka_blocks_mined,

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,7 @@ fn miner_forking() {
18821882
let Counters {
18831883
naka_skip_commit_op: skip_commit_op_rl2,
18841884
naka_submitted_commits: commits_submitted_rl2,
1885+
naka_submitted_commit_last_burn_height: commits_submitted_rl2_last_burn_height,
18851886
..
18861887
} = run_loop_2.counters();
18871888
let _run_loop_2_thread = thread::Builder::new()
@@ -1903,6 +1904,8 @@ fn miner_forking() {
19031904
.expect("Timed out waiting for boostrapped node to catch up to the miner");
19041905

19051906
let commits_submitted_rl1 = signer_test.running_nodes.commits_submitted.clone();
1907+
let commits_submitted_rl1_last_burn_height =
1908+
signer_test.running_nodes.last_commit_burn_height.clone();
19061909
let skip_commit_op_rl1 = signer_test
19071910
.running_nodes
19081911
.nakamoto_test_skip_commit_op
@@ -1947,13 +1950,18 @@ fn miner_forking() {
19471950
info!("Pausing stacks block proposal to force an empty tenure commit from RL2");
19481951
TEST_BROADCAST_STALL.lock().unwrap().replace(true);
19491952
let rl1_commits_before = commits_submitted_rl1.load(Ordering::SeqCst);
1953+
let burn_height_before = get_burn_height();
19501954

19511955
info!("Unpausing commits from RL1");
19521956
skip_commit_op_rl1.set(false);
19531957

19541958
info!("Waiting for commits from RL1");
19551959
wait_for(30, || {
1956-
Ok(commits_submitted_rl1.load(Ordering::SeqCst) > rl1_commits_before)
1960+
Ok(
1961+
commits_submitted_rl1.load(Ordering::SeqCst) > rl1_commits_before
1962+
&& commits_submitted_rl1_last_burn_height.load(Ordering::SeqCst)
1963+
>= burn_height_before,
1964+
)
19571965
})
19581966
.expect("Timed out waiting for miner 1 to submit a commit op");
19591967

@@ -1984,13 +1992,17 @@ fn miner_forking() {
19841992
"------------------------- RL2 Wins Sortition With Outdated View -------------------------"
19851993
);
19861994
let rl2_commits_before = commits_submitted_rl2.load(Ordering::SeqCst);
1995+
let burn_height = get_burn_height();
19871996

19881997
info!("Unpausing commits from RL2");
19891998
skip_commit_op_rl2.set(false);
19901999

19912000
info!("Waiting for commits from RL2");
19922001
wait_for(30, || {
1993-
Ok(commits_submitted_rl2.load(Ordering::SeqCst) > rl2_commits_before)
2002+
Ok(
2003+
commits_submitted_rl2.load(Ordering::SeqCst) > rl2_commits_before
2004+
&& commits_submitted_rl2_last_burn_height.load(Ordering::SeqCst) >= burn_height,
2005+
)
19942006
})
19952007
.expect("Timed out waiting for miner 1 to submit a commit op");
19962008

0 commit comments

Comments
 (0)