Skip to content

Commit 1f1bf2c

Browse files
authored
Merge pull request #5722 from stacks-network/test/flaky-miner-forking
Test: attempt to reduce flakiness in miner-forking test
2 parents c147821 + 99ff95d commit 1f1bf2c

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
@@ -1626,8 +1626,10 @@ impl RelayerThread {
16261626
// update local state
16271627
last_committed.set_txid(&txid);
16281628
self.last_commits.insert(txid);
1629+
self.globals
1630+
.counters
1631+
.bump_naka_submitted_commits(last_committed.burn_tip.block_height);
16291632
self.last_committed = Some(last_committed);
1630-
self.globals.counters.bump_naka_submitted_commits();
16311633

16321634
Ok(())
16331635
}

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

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

109109
pub naka_submitted_vrfs: RunLoopCounter,
110110
pub naka_submitted_commits: RunLoopCounter,
111+
/// the burn block height when the last commit was submitted
112+
pub naka_submitted_commit_last_burn_height: RunLoopCounter,
111113
pub naka_mined_blocks: RunLoopCounter,
112114
pub naka_rejected_blocks: RunLoopCounter,
113115
pub naka_proposed_blocks: RunLoopCounter,
@@ -168,8 +170,12 @@ impl Counters {
168170
Counters::inc(&self.naka_submitted_vrfs);
169171
}
170172

171-
pub fn bump_naka_submitted_commits(&self) {
173+
pub fn bump_naka_submitted_commits(&self, committed_height: u64) {
172174
Counters::inc(&self.naka_submitted_commits);
175+
Counters::set(
176+
&self.naka_submitted_commit_last_burn_height,
177+
committed_height,
178+
);
173179
}
174180

175181
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 sortitions_processed: RunLoopCounter,
9394
pub nakamoto_blocks_proposed: RunLoopCounter,
@@ -933,6 +934,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
933934
sortitions_processed,
934935
naka_submitted_vrfs: vrfs_submitted,
935936
naka_submitted_commits: commits_submitted,
937+
naka_submitted_commit_last_burn_height: last_commit_burn_height,
936938
naka_proposed_blocks: naka_blocks_proposed,
937939
naka_mined_blocks: naka_blocks_mined,
938940
naka_rejected_blocks: naka_blocks_rejected,
@@ -968,6 +970,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
968970
run_loop_stopper,
969971
vrfs_submitted,
970972
commits_submitted,
973+
last_commit_burn_height,
971974
blocks_processed,
972975
sortitions_processed,
973976
nakamoto_blocks_proposed: naka_blocks_proposed,

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,7 @@ fn miner_forking() {
18891889
let Counters {
18901890
naka_skip_commit_op: skip_commit_op_rl2,
18911891
naka_submitted_commits: commits_submitted_rl2,
1892+
naka_submitted_commit_last_burn_height: commits_submitted_rl2_last_burn_height,
18921893
..
18931894
} = run_loop_2.counters();
18941895
let _run_loop_2_thread = thread::Builder::new()
@@ -1910,6 +1911,8 @@ fn miner_forking() {
19101911
.expect("Timed out waiting for boostrapped node to catch up to the miner");
19111912

19121913
let commits_submitted_rl1 = signer_test.running_nodes.commits_submitted.clone();
1914+
let commits_submitted_rl1_last_burn_height =
1915+
signer_test.running_nodes.last_commit_burn_height.clone();
19131916
let skip_commit_op_rl1 = signer_test
19141917
.running_nodes
19151918
.nakamoto_test_skip_commit_op
@@ -1966,13 +1969,18 @@ fn miner_forking() {
19661969
info!("Pausing stacks block proposal to force an empty tenure commit from RL2");
19671970
TEST_BROADCAST_STALL.set(true);
19681971
let rl1_commits_before = commits_submitted_rl1.load(Ordering::SeqCst);
1972+
let burn_height_before = get_burn_height();
19691973

19701974
info!("Unpausing commits from RL1");
19711975
skip_commit_op_rl1.set(false);
19721976

19731977
info!("Waiting for commits from RL1");
19741978
wait_for(30, || {
1975-
Ok(commits_submitted_rl1.load(Ordering::SeqCst) > rl1_commits_before)
1979+
Ok(
1980+
commits_submitted_rl1.load(Ordering::SeqCst) > rl1_commits_before
1981+
&& commits_submitted_rl1_last_burn_height.load(Ordering::SeqCst)
1982+
>= burn_height_before,
1983+
)
19761984
})
19771985
.expect("Timed out waiting for miner 1 to submit a commit op");
19781986

@@ -2003,13 +2011,17 @@ fn miner_forking() {
20032011
"------------------------- RL2 Wins Sortition With Outdated View -------------------------"
20042012
);
20052013
let rl2_commits_before = commits_submitted_rl2.load(Ordering::SeqCst);
2014+
let burn_height = get_burn_height();
20062015

20072016
info!("Unpausing commits from RL2");
20082017
skip_commit_op_rl2.set(false);
20092018

20102019
info!("Waiting for commits from RL2");
20112020
wait_for(30, || {
2012-
Ok(commits_submitted_rl2.load(Ordering::SeqCst) > rl2_commits_before)
2021+
Ok(
2022+
commits_submitted_rl2.load(Ordering::SeqCst) > rl2_commits_before
2023+
&& commits_submitted_rl2_last_burn_height.load(Ordering::SeqCst) >= burn_height,
2024+
)
20132025
})
20142026
.expect("Timed out waiting for miner 1 to submit a commit op");
20152027

0 commit comments

Comments
 (0)