Skip to content

Commit d937efd

Browse files
committed
WIP: enforce obvious order of events in mine_nakamoto_block
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent ef21447 commit d937efd

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ use super::nakamoto_integrations::{
7070
use super::neon_integrations::{
7171
copy_dir_all, get_account, get_sortition_info_ch, submit_tx_fallible, Account,
7272
};
73+
use crate::nakamoto_node::miner::TEST_MINE_SKIP;
7374
use crate::neon::Counters;
7475
use crate::run_loop::boot_nakamoto;
7576
use crate::tests::bitcoin_regtest::BitcoinCoreController;
@@ -80,6 +81,7 @@ use crate::tests::neon_integrations::{
8081
get_chain_info, next_block_and_wait, run_until_burnchain_height, test_observer,
8182
wait_for_runloop,
8283
};
84+
use crate::tests::signer::v0::wait_for_state_machine_update_by_miner_tenure_id;
8385
use crate::tests::to_addr;
8486
use crate::BitcoinRegtestController;
8587

@@ -1101,23 +1103,44 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
11011103
/// Mine a BTC block and wait for a new Stacks block to be mined
11021104
/// Note: do not use nakamoto blocks mined heuristic if running a test with multiple miners
11031105
fn mine_nakamoto_block(&self, timeout: Duration, use_nakamoto_blocks_mined: bool) {
1104-
let mined_block_time = Instant::now();
11051106
let mined_before = self.running_nodes.counters.naka_mined_blocks.get();
1106-
let info_before = self.get_peer_info();
1107-
1107+
let info_before = get_chain_info(&self.running_nodes.conf);
1108+
let mined_btc_block_time = Instant::now();
1109+
info!("Pausing stacks block mining");
1110+
TEST_MINE_SKIP.set(true);
11081111
next_block_and(
11091112
&self.running_nodes.btc_regtest_controller,
11101113
timeout.as_secs(),
1111-
|| {
1112-
let info_after = self.get_peer_info();
1113-
let blocks_mined = self.running_nodes.counters.naka_mined_blocks.get();
1114-
Ok(info_after.stacks_tip_height > info_before.stacks_tip_height
1115-
&& (!use_nakamoto_blocks_mined || blocks_mined > mined_before))
1116-
},
1114+
|| Ok(self.get_peer_info().burn_block_height > info_before.burn_block_height),
11171115
)
11181116
.unwrap();
1119-
let mined_block_elapsed_time = mined_block_time.elapsed();
1120-
info!("Nakamoto block mine time elapsed: {mined_block_elapsed_time:?}");
1117+
info!(
1118+
"Bitcoin block mine time elapsed: {:?}",
1119+
mined_btc_block_time.elapsed()
1120+
);
1121+
wait_for_state_machine_update_by_miner_tenure_id(
1122+
timeout.as_secs(),
1123+
&get_chain_info(&self.running_nodes.conf).pox_consensus,
1124+
&self.signer_addresses_versions(),
1125+
)
1126+
.expect("Failed to update signer state machine");
1127+
1128+
info!("Unpausing stacks block mining");
1129+
let mined_block_time = Instant::now();
1130+
TEST_MINE_SKIP.set(false);
1131+
wait_for(timeout.as_secs(), || {
1132+
let info_after = get_chain_info(&self.running_nodes.conf);
1133+
let blocks_mined = self.running_nodes.counters.naka_mined_blocks.get();
1134+
// println!("HERE BEFORE {}, AFTER {}", info_before.stacks_tip_height, info_after.stacks_tip_height);
1135+
// println!("HERE BEFORE {mined_before}, AFTER {blocks_mined}");
1136+
Ok(info_after.stacks_tip_height > info_before.stacks_tip_height
1137+
&& (!use_nakamoto_blocks_mined || blocks_mined > mined_before))
1138+
})
1139+
.expect("Failed to mine Tenure Change block");
1140+
info!(
1141+
"Nakamoto block mine time elapsed: {:?}",
1142+
mined_block_time.elapsed()
1143+
);
11211144
}
11221145

11231146
fn mine_block_wait_on_processing(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4466,7 +4466,7 @@ fn tx_replay_with_fork_occured_before_starting_replaying_txs() {
44664466
let pre_fork_tenures = 12; //go to 2nd tenure of 12th cycle
44674467
for i in 0..pre_fork_tenures {
44684468
info!("Mining pre-fork tenure {} of {pre_fork_tenures}", i + 1);
4469-
signer_test.mine_nakamoto_block(Duration::from_secs(30), true);
4469+
signer_test.mine_nakamoto_block(Duration::from_secs(60), true);
44704470
}
44714471

44724472
// Make 1 transfer tx (this will get forked)
@@ -4506,6 +4506,7 @@ fn tx_replay_with_fork_occured_before_starting_replaying_txs() {
45064506
.unwrap();
45074507
}
45084508

4509+
info!("HERE WE ARE WAITING");
45094510
// Signers move in Tx Replay mode
45104511
signer_test
45114512
.wait_for_signer_state_check(30, |state| {

0 commit comments

Comments
 (0)