Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: fix some test flake in partial_tenure_forking #5769

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testnet/stacks-node/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct Globals<T> {
unconfirmed_txs: Arc<Mutex<UnconfirmedTxMap>>,
/// Writer endpoint to the relayer thread
pub relay_send: SyncSender<T>,
/// Cointer state in the main thread
/// Counter state in the main thread
pub counters: Counters,
/// Connection to the PoX sync watchdog
pub sync_comms: PoxSyncWatchdogComms,
Expand Down
2 changes: 1 addition & 1 deletion testnet/stacks-node/src/nakamoto_node/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ impl RelayerThread {
self.last_commits.insert(txid);
self.globals
.counters
.bump_naka_submitted_commits(last_committed.burn_tip.block_height);
.bump_naka_submitted_commits(last_committed.burn_tip.block_height, tip_height);
self.last_committed = Some(last_committed);

Ok(())
Expand Down
13 changes: 11 additions & 2 deletions testnet/stacks-node/src/run_loop/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub struct Counters {
pub naka_mined_tenures: RunLoopCounter,
pub naka_signer_pushed_blocks: RunLoopCounter,
pub naka_miner_directives: RunLoopCounter,
pub naka_submitted_commit_last_stacks_tip: RunLoopCounter,

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

pub fn bump_naka_submitted_commits(&self, committed_height: u64) {
pub fn bump_naka_submitted_commits(
&self,
committed_burn_height: u64,
committed_stacks_height: u64,
) {
Counters::inc(&self.naka_submitted_commits);
Counters::set(
&self.naka_submitted_commit_last_burn_height,
committed_height,
committed_burn_height,
);
Counters::set(
&self.naka_submitted_commit_last_stacks_tip,
committed_stacks_height,
);
}

Expand Down
3 changes: 3 additions & 0 deletions testnet/stacks-node/src/tests/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub struct RunningNodes {
pub nakamoto_blocks_signer_pushed: RunLoopCounter,
pub nakamoto_miner_directives: Arc<AtomicU64>,
pub nakamoto_test_skip_commit_op: TestFlag<bool>,
pub counters: Counters,
pub coord_channel: Arc<Mutex<CoordinatorChannels>>,
pub conf: NeonConfig,
}
Expand Down Expand Up @@ -933,6 +934,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
naka_signer_pushed_blocks,
..
} = run_loop.counters();
let counters = run_loop.counters();

let coord_channel = run_loop.coordinator_channels();
let run_loop_thread = thread::spawn(move || run_loop.start(None, 0));
Expand Down Expand Up @@ -970,6 +972,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
nakamoto_test_skip_commit_op,
nakamoto_miner_directives: naka_miner_directives.0,
coord_channel,
counters,
conf: naka_conf,
}
}
28 changes: 16 additions & 12 deletions testnet/stacks-node/src/tests/signer/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5031,6 +5031,8 @@ fn partial_tenure_fork() {
naka_skip_commit_op: rl2_skip_commit_op,
..
} = run_loop_2.counters();
let rl2_counters = run_loop_2.counters();
let rl1_counters = signer_test.running_nodes.counters.clone();

signer_test.boot_to_epoch_3();
let run_loop_2_thread = thread::Builder::new()
Expand Down Expand Up @@ -5101,35 +5103,37 @@ fn partial_tenure_fork() {
rl1_skip_commit_op.set(true);
rl2_skip_commit_op.set(true);

let mined_before_1 = blocks_mined1.load(Ordering::SeqCst);
let mined_before_2 = blocks_mined2.load(Ordering::SeqCst);
let commits_before_1 = commits_1.load(Ordering::SeqCst);
let commits_before_2 = commits_2.load(Ordering::SeqCst);
let info_before = get_chain_info(&conf);

// Mine the first block
next_block_and(
&mut signer_test.running_nodes.btc_regtest_controller,
180,
|| {
let mined_1 = blocks_mined1.load(Ordering::SeqCst);
let mined_2 = blocks_mined2.load(Ordering::SeqCst);

Ok(mined_1 > mined_before_1 || mined_2 > mined_before_2)
let info_1 = get_chain_info(&conf);
Ok(info_1.stacks_tip_height > info_before.stacks_tip_height)
},
)
.expect("Timed out waiting for new Stacks block to be mined");

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

let info_before = get_chain_info(&conf);

// Unpause block commits and wait for both miners' commits
rl1_skip_commit_op.set(false);
rl2_skip_commit_op.set(false);

// Ensure that both block commits have been sent before continuing
// Ensure that both miners' commits point at the stacks tip
wait_for(60, || {
let commits_after_1 = commits_1.load(Ordering::SeqCst);
let commits_after_2 = commits_2.load(Ordering::SeqCst);
Ok(commits_after_1 > commits_before_1 && commits_after_2 > commits_before_2)
let last_committed_1 = rl1_counters
.naka_submitted_commit_last_stacks_tip
.load(Ordering::SeqCst);
let last_committed_2 = rl2_counters
.naka_submitted_commit_last_stacks_tip
.load(Ordering::SeqCst);
Ok(last_committed_1 >= info_before.stacks_tip_height
&& last_committed_2 >= info_before.stacks_tip_height)
})
.expect("Timed out waiting for block commits");

Expand Down
Loading