Skip to content

Commit b30c0b4

Browse files
committed
chore: halt block-processing while we process shadow blocks
1 parent 7341a4b commit b30c0b4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

stackslib/src/chainstate/nakamoto/coordinator/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ use crate::monitoring::increment_stx_blocks_processed_counter;
5858
use crate::net::Error as NetError;
5959
use crate::util_lib::db::Error as DBError;
6060

61+
#[cfg(any(test, feature = "testing"))]
62+
pub static TEST_COORDINATOR_STALL: std::sync::Mutex<Option<bool>> = std::sync::Mutex::new(None);
63+
6164
#[cfg(test)]
6265
pub mod tests;
6366

@@ -764,6 +767,21 @@ impl<
764767
true
765768
}
766769

770+
#[cfg(any(test, feature = "testing"))]
771+
fn fault_injection_pause_nakamoto_block_processing() {
772+
if *TEST_COORDINATOR_STALL.lock().unwrap() == Some(true) {
773+
// Do an extra check just so we don't log EVERY time.
774+
warn!("Coordinator is stalled due to testing directive");
775+
while *TEST_COORDINATOR_STALL.lock().unwrap() == Some(true) {
776+
std::thread::sleep(std::time::Duration::from_millis(10));
777+
}
778+
warn!("Coordinator is no longer stalled due to testing directive. Continuing...");
779+
}
780+
}
781+
782+
#[cfg(not(any(test, feature = "testing")))]
783+
fn fault_injection_pause_nakamoto_block_processing() {}
784+
767785
/// Handle one or more new Nakamoto Stacks blocks.
768786
/// If we process a PoX anchor block, then return its block hash. This unblocks processing the
769787
/// next reward cycle's burnchain blocks. Subsequent calls to this function will terminate
@@ -776,6 +794,8 @@ impl<
776794
);
777795

778796
loop {
797+
Self::fault_injection_pause_nakamoto_block_processing();
798+
779799
// process at most one block per loop pass
780800
let mut processed_block_receipt = match NakamotoChainState::process_next_nakamoto_block(
781801
&mut self.chain_state_db,

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use stacks::chainstate::burn::operations::{
3737
};
3838
use stacks::chainstate::coordinator::comm::CoordinatorChannels;
3939
use stacks::chainstate::coordinator::OnChainRewardSetProvider;
40-
use stacks::chainstate::nakamoto::coordinator::load_nakamoto_reward_set;
40+
use stacks::chainstate::nakamoto::coordinator::{load_nakamoto_reward_set, TEST_COORDINATOR_STALL};
4141
use stacks::chainstate::nakamoto::miner::NakamotoBlockBuilder;
4242
use stacks::chainstate::nakamoto::shadow::shadow_chainstate_repair;
4343
use stacks::chainstate::nakamoto::test_signers::TestSigners;
@@ -9672,6 +9672,10 @@ fn test_shadow_recovery() {
96729672

96739673
let stacks_height_before = get_chain_info(&naka_conf).stacks_tip_height;
96749674

9675+
// TODO: stall block processing; otherwise this test can flake
9676+
// stop block processing on the node
9677+
TEST_COORDINATOR_STALL.lock().unwrap().replace(true);
9678+
96759679
// fix node
96769680
let shadow_blocks = shadow_chainstate_repair(&mut chainstate, &mut sortdb).unwrap();
96779681
assert!(shadow_blocks.len() > 0);
@@ -9685,6 +9689,7 @@ fn test_shadow_recovery() {
96859689
})
96869690
.unwrap();
96879691

9692+
TEST_COORDINATOR_STALL.lock().unwrap().replace(false);
96889693
info!("Beginning post-shadow tenures");
96899694

96909695
// revive ATC-C by waiting for commits

0 commit comments

Comments
 (0)