Skip to content

Commit d46d4ec

Browse files
committed
Cleanup more tests
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent a823146 commit d46d4ec

File tree

2 files changed

+236
-316
lines changed

2 files changed

+236
-316
lines changed

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

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,29 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
536536
}).unwrap();
537537
}
538538

539+
/// Mine a bitcoin block and wait for the signers to send an update with the new burn block and pox consensus hash
539540
pub fn mine_bitcoin_block(&self) {
541+
self.mine_bitcoin_block_without_updates();
542+
wait_for_state_machine_update_by_miner_tenure_id(
543+
30,
544+
&get_chain_info(&self.running_nodes.conf).pox_consensus,
545+
&self.signer_addresses_versions_majority(),
546+
)
547+
.expect("Failed to update signer state machine");
548+
}
549+
550+
// Mine a bitcoin block but don't wait for signers to send any updates
551+
pub fn mine_bitcoin_block_without_updates(&self) {
552+
let mined_btc_block_time = Instant::now();
540553
let info = self.get_peer_info();
541554
next_block_and(&self.running_nodes.btc_regtest_controller, 60, || {
542555
Ok(get_chain_info(&self.running_nodes.conf).burn_block_height > info.burn_block_height)
543556
})
544557
.unwrap();
558+
info!(
559+
"Bitcoin block mine time elapsed: {:?}",
560+
mined_btc_block_time.elapsed()
561+
);
545562
}
546563

547564
/// Fetch the local signer state machine for all the signers,
@@ -1100,43 +1117,19 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
11001117
output
11011118
}
11021119

1103-
/// Mine a BTC block and wait for a new Stacks block to be mined
1120+
/// Mine a BTC block and wait for a new Stacks block to be mined, but do not wait for a commit
11041121
/// 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) {
1122+
fn mine_nakamoto_block_without_commit(
1123+
&self,
1124+
timeout: Duration,
1125+
use_nakamoto_blocks_mined: bool,
1126+
) {
11061127
let info_before = get_chain_info(&self.running_nodes.conf);
11071128
info!("Pausing stacks block mining");
11081129
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-
);
1133-
wait_for_state_machine_update_by_miner_tenure_id(
1134-
timeout.as_secs(),
1135-
&get_chain_info(&self.running_nodes.conf).pox_consensus,
1136-
&self.signer_addresses_versions_majority(),
1137-
)
1138-
.expect("Failed to update signer state machine");
1139-
1130+
let mined_blocks = self.running_nodes.counters.naka_mined_blocks.clone();
1131+
let mined_before = mined_blocks.get();
1132+
self.mine_bitcoin_block();
11401133
info!("Unpausing stacks block mining");
11411134
let mined_block_time = Instant::now();
11421135
TEST_MINE_SKIP.set(false);
@@ -1145,22 +1138,35 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
11451138
wait_for(timeout.as_secs(), || {
11461139
Ok(get_chain_info(&self.running_nodes.conf).stacks_tip_height
11471140
> info_before.stacks_tip_height
1148-
&& (!use_nakamoto_blocks_mined
1149-
|| mined_blocks.load(Ordering::SeqCst) > mined_before))
1141+
&& (!use_nakamoto_blocks_mined || mined_blocks.get() > mined_before))
11501142
})
11511143
.expect("Failed to mine Tenure Change block");
1144+
info!(
1145+
"Nakamoto block mine time elapsed: {:?}",
1146+
mined_block_time.elapsed()
1147+
);
1148+
}
1149+
1150+
/// Mine a BTC block and wait for a new Stacks block to be mined and commit to be submitted
1151+
/// Note: do not use nakamoto blocks mined heuristic if running a test with multiple miners
1152+
fn mine_nakamoto_block(&self, timeout: Duration, use_nakamoto_blocks_mined: bool) {
1153+
let Counters {
1154+
naka_submitted_commits: commits_submitted,
1155+
naka_submitted_commit_last_burn_height: commits_last_burn_height,
1156+
naka_submitted_commit_last_stacks_tip: commits_last_stacks_tip,
1157+
..
1158+
} = self.running_nodes.counters.clone();
1159+
let commits_before = commits_submitted.get();
1160+
let commit_burn_height_before = commits_last_burn_height.get();
1161+
self.mine_nakamoto_block_without_commit(timeout, use_nakamoto_blocks_mined);
11521162
// Ensure the subsequent block commit confirms the previous Tenure Change block
11531163
let stacks_tip_height = get_chain_info(&self.running_nodes.conf).stacks_tip_height;
11541164
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)
1165+
Ok(commits_submitted.get() > commits_before
1166+
&& commits_last_burn_height.get() > commit_burn_height_before
1167+
&& commits_last_stacks_tip.get() >= stacks_tip_height)
11581168
})
11591169
.expect("Failed to update Block Commit");
1160-
info!(
1161-
"Nakamoto block mine time elapsed: {:?}",
1162-
mined_block_time.elapsed()
1163-
);
11641170
}
11651171

11661172
fn mine_block_wait_on_processing(

0 commit comments

Comments
 (0)