Skip to content

Commit 0375c72

Browse files
committed
Fix burn_block_height_behavior test
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent a823146 commit 0375c72

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

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

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,16 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
537537
}
538538

539539
pub fn mine_bitcoin_block(&self) {
540+
let mined_btc_block_time = Instant::now();
540541
let info = self.get_peer_info();
541542
next_block_and(&self.running_nodes.btc_regtest_controller, 60, || {
542543
Ok(get_chain_info(&self.running_nodes.conf).burn_block_height > info.burn_block_height)
543544
})
544545
.unwrap();
546+
info!(
547+
"Bitcoin block mine time elapsed: {:?}",
548+
mined_btc_block_time.elapsed()
549+
);
545550
}
546551

547552
/// Fetch the local signer state machine for all the signers,
@@ -1100,36 +1105,19 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
11001105
output
11011106
}
11021107

1103-
/// Mine a BTC block and wait for a new Stacks block to be mined
1108+
/// Mine a BTC block and wait for a new Stacks block to be mined, but do not wait for a commit
11041109
/// Note: do not use nakamoto blocks mined heuristic if running a test with multiple miners
1105-
fn mine_nakamoto_block(&self, timeout: Duration, use_nakamoto_blocks_mined: bool) {
1110+
fn mine_nakamoto_block_without_commit(
1111+
&self,
1112+
timeout: Duration,
1113+
use_nakamoto_blocks_mined: bool,
1114+
) {
11061115
let info_before = get_chain_info(&self.running_nodes.conf);
11071116
info!("Pausing stacks block mining");
11081117
TEST_MINE_SKIP.set(true);
1109-
1110-
let Counters {
1111-
naka_submitted_commits: commits_submitted,
1112-
naka_submitted_commit_last_burn_height: commits_last_burn_height,
1113-
naka_submitted_commit_last_stacks_tip: commits_last_stacks_tip,
1114-
naka_mined_blocks: mined_blocks,
1115-
..
1116-
} = self.running_nodes.counters.clone();
1117-
1118-
let commits_before = commits_submitted.load(Ordering::SeqCst);
1119-
let commit_burn_height_before = commits_last_burn_height.load(Ordering::SeqCst);
1120-
let mined_before = mined_blocks.load(Ordering::SeqCst);
1121-
1122-
let mined_btc_block_time = Instant::now();
1123-
next_block_and(
1124-
&self.running_nodes.btc_regtest_controller,
1125-
timeout.as_secs(),
1126-
|| Ok(self.get_peer_info().burn_block_height > info_before.burn_block_height),
1127-
)
1128-
.unwrap();
1129-
info!(
1130-
"Bitcoin block mine time elapsed: {:?}",
1131-
mined_btc_block_time.elapsed()
1132-
);
1118+
let mined_blocks = self.running_nodes.counters.naka_mined_blocks.clone();
1119+
let mined_before = mined_blocks.get();
1120+
self.mine_bitcoin_block();
11331121
wait_for_state_machine_update_by_miner_tenure_id(
11341122
timeout.as_secs(),
11351123
&get_chain_info(&self.running_nodes.conf).pox_consensus,
@@ -1145,22 +1133,35 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
11451133
wait_for(timeout.as_secs(), || {
11461134
Ok(get_chain_info(&self.running_nodes.conf).stacks_tip_height
11471135
> info_before.stacks_tip_height
1148-
&& (!use_nakamoto_blocks_mined
1149-
|| mined_blocks.load(Ordering::SeqCst) > mined_before))
1136+
&& (!use_nakamoto_blocks_mined || mined_blocks.get() > mined_before))
11501137
})
11511138
.expect("Failed to mine Tenure Change block");
1139+
info!(
1140+
"Nakamoto block mine time elapsed: {:?}",
1141+
mined_block_time.elapsed()
1142+
);
1143+
}
1144+
1145+
/// Mine a BTC block and wait for a new Stacks block to be mined and commit to be submitted
1146+
/// Note: do not use nakamoto blocks mined heuristic if running a test with multiple miners
1147+
fn mine_nakamoto_block(&self, timeout: Duration, use_nakamoto_blocks_mined: bool) {
1148+
let Counters {
1149+
naka_submitted_commits: commits_submitted,
1150+
naka_submitted_commit_last_burn_height: commits_last_burn_height,
1151+
naka_submitted_commit_last_stacks_tip: commits_last_stacks_tip,
1152+
..
1153+
} = self.running_nodes.counters.clone();
1154+
let commits_before = commits_submitted.get();
1155+
let commit_burn_height_before = commits_last_burn_height.get();
1156+
self.mine_nakamoto_block_without_commit(timeout, use_nakamoto_blocks_mined);
11521157
// Ensure the subsequent block commit confirms the previous Tenure Change block
11531158
let stacks_tip_height = get_chain_info(&self.running_nodes.conf).stacks_tip_height;
11541159
wait_for(timeout.as_secs(), || {
1155-
Ok(commits_submitted.load(Ordering::SeqCst) > commits_before
1156-
&& commits_last_burn_height.load(Ordering::SeqCst) > commit_burn_height_before
1157-
&& commits_last_stacks_tip.load(Ordering::SeqCst) >= stacks_tip_height)
1160+
Ok(commits_submitted.get() > commits_before
1161+
&& commits_last_burn_height.get() > commit_burn_height_before
1162+
&& commits_last_stacks_tip.get() >= stacks_tip_height)
11581163
})
11591164
.expect("Failed to update Block Commit");
1160-
info!(
1161-
"Nakamoto block mine time elapsed: {:?}",
1162-
mined_block_time.elapsed()
1163-
);
11641165
}
11651166

11661167
fn mine_block_wait_on_processing(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17089,7 +17089,7 @@ fn burn_block_height_behavior() {
1708917089
skip_commit_op.set(true);
1709017090

1709117091
// Mine a regular tenure
17092-
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
17092+
signer_test.mine_nakamoto_block_without_commit(Duration::from_secs(30), true);
1709317093

1709417094
let info = get_chain_info(&signer_test.running_nodes.conf);
1709517095
let stacks_height_before = info.stacks_tip_height;

0 commit comments

Comments
 (0)