Skip to content

Commit e16b7ef

Browse files
authored
Merge pull request #6399 from kantai/test/fix-miner-replay
Test: Fix `miner_constructs_replay_block`
2 parents aae99d0 + 0e5a630 commit e16b7ef

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

stacks-node/src/nakamoto_node/miner.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ pub fn fault_injection_stall_miner() {
111111
}
112112
}
113113

114+
#[cfg(test)]
115+
/// Set the `TEST_MINE_STALL` flag to `Pending` and do not block.
116+
pub fn fault_injection_try_stall_miner() {
117+
let mut stall_lock = TEST_MINE_STALL.0.lock().unwrap();
118+
if stall_lock.as_ref().is_none() || stall_lock.as_ref() == Some(&TestMineStall::NotStalled) {
119+
*stall_lock = Some(TestMineStall::Pending);
120+
}
121+
}
122+
114123
#[cfg(test)]
115124
/// Unstall the miner by setting the `TEST_MINE_STALL` flag to `NotStalled`.
116125
pub fn fault_injection_unstall_miner() {

stacks-node/src/nakamoto_node/relayer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,12 +899,21 @@ impl RelayerThread {
899899
.raise_initiative("process_sortition".to_string());
900900
return Ok(None);
901901
}
902+
902903
// Reset the tenure extend time
903904
self.tenure_extend_time = None;
904905
let Some(mining_pk) = self.get_mining_key_pkh() else {
905906
debug!("No mining key, will not mine");
906907
return Ok(None);
907908
};
909+
910+
let epoch = SortitionDB::get_stacks_epoch(self.sortdb.conn(), sn.block_height)
911+
.expect("FATAL: epoch not found for current snapshot")
912+
.expect("FATAL: epoch not found for current snapshot");
913+
if !epoch.epoch_id.uses_nakamoto_blocks() {
914+
return Ok(None);
915+
}
916+
908917
let directive_opt = if sn.sortition {
909918
self.choose_directive_sortition_with_winner(sn, mining_pk, committed_index_hash)
910919
} else {

stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ use stacks_signer::v0::SpawnedSigner;
117117

118118
use crate::burnchains::bitcoin::core_controller::BitcoinCoreController;
119119
use crate::nakamoto_node::miner::{
120-
fault_injection_stall_miner, fault_injection_unstall_miner, TEST_BLOCK_ANNOUNCE_STALL,
121-
TEST_BROADCAST_PROPOSAL_STALL, TEST_P2P_BROADCAST_SKIP, TEST_P2P_BROADCAST_STALL,
120+
fault_injection_stall_miner, fault_injection_try_stall_miner, fault_injection_unstall_miner,
121+
TEST_BLOCK_ANNOUNCE_STALL, TEST_BROADCAST_PROPOSAL_STALL, TEST_P2P_BROADCAST_SKIP,
122+
TEST_P2P_BROADCAST_STALL,
122123
};
123124
use crate::nakamoto_node::relayer::TEST_MINER_THREAD_STALL;
124125
use crate::neon::Counters;
@@ -12620,7 +12621,7 @@ fn miner_constructs_replay_block() {
1262012621

1262112622
// Pause mining to prevent any of the submitted txs getting mined.
1262212623
info!("Stalling mining...");
12623-
fault_injection_stall_miner();
12624+
fault_injection_try_stall_miner();
1262412625
let burn_height_before = get_chain_info(&naka_conf).burn_block_height;
1262512626
// Mine 1 bitcoin block to trigger a new block found transaction
1262612627
next_block_and(&mut btc_regtest_controller, 60, || {

0 commit comments

Comments
 (0)