Skip to content

Commit d651825

Browse files
committed
test: move BTC commit stall to counters()
1 parent e3b8e29 commit d651825

File tree

5 files changed

+54
-16
lines changed

5 files changed

+54
-16
lines changed

testnet/stacks-node/src/nakamoto_node/relayer.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ use crate::run_loop::nakamoto::{Globals, RunLoop};
6666
use crate::run_loop::RegisteredKey;
6767
use crate::BitcoinRegtestController;
6868

69-
#[cfg(test)]
70-
lazy_static::lazy_static! {
71-
pub static ref TEST_SKIP_COMMIT_OP: std::sync::Mutex<Option<bool>> = std::sync::Mutex::new(None);
72-
}
73-
7469
/// Command types for the Nakamoto relayer thread, issued to it by other threads
7570
pub enum RelayerDirective {
7671
/// Handle some new data that arrived on the network (such as blocks, transactions, and
@@ -937,7 +932,15 @@ impl RelayerThread {
937932
let mut last_committed = self.make_block_commit(&tip_block_ch, &tip_block_bh)?;
938933
#[cfg(test)]
939934
{
940-
if TEST_SKIP_COMMIT_OP.lock().unwrap().unwrap_or(false) {
935+
if self
936+
.globals
937+
.counters
938+
.naka_skip_commit_op
939+
.0
940+
.lock()
941+
.unwrap()
942+
.unwrap_or(false)
943+
{
941944
warn!("Relayer: not submitting block-commit to bitcoin network due to test directive.");
942945
return Ok(());
943946
}

testnet/stacks-node/src/run_loop/neon.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ impl std::ops::Deref for RunLoopCounter {
8282
}
8383
}
8484

85+
#[cfg(test)]
86+
#[derive(Clone)]
87+
pub struct TestFlag(pub Arc<std::sync::Mutex<Option<bool>>>);
88+
89+
#[cfg(test)]
90+
impl Default for TestFlag {
91+
fn default() -> Self {
92+
Self(Arc::new(std::sync::Mutex::new(None)))
93+
}
94+
}
95+
8596
#[derive(Clone, Default)]
8697
pub struct Counters {
8798
pub blocks_processed: RunLoopCounter,
@@ -95,6 +106,9 @@ pub struct Counters {
95106
pub naka_mined_blocks: RunLoopCounter,
96107
pub naka_proposed_blocks: RunLoopCounter,
97108
pub naka_mined_tenures: RunLoopCounter,
109+
110+
#[cfg(test)]
111+
pub naka_skip_commit_op: TestFlag,
98112
}
99113

100114
impl Counters {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ use wsts::net::Message;
9595
use super::bitcoin_regtest::BitcoinCoreController;
9696
use crate::config::{EventKeyType, EventObserverConfig, InitialBalance};
9797
use crate::nakamoto_node::miner::TEST_BROADCAST_STALL;
98-
use crate::nakamoto_node::relayer::TEST_SKIP_COMMIT_OP;
9998
use crate::neon::{Counters, RunLoopCounter};
10099
use crate::operations::BurnchainOpSigner;
101100
use crate::run_loop::boot_nakamoto;
@@ -3723,6 +3722,7 @@ fn forked_tenure_is_ignored() {
37233722
naka_submitted_commits: commits_submitted,
37243723
naka_proposed_blocks: proposals_submitted,
37253724
naka_mined_blocks: mined_blocks,
3725+
naka_skip_commit_op: test_skip_commit_op,
37263726
..
37273727
} = run_loop.counters();
37283728

@@ -3791,7 +3791,7 @@ fn forked_tenure_is_ignored() {
37913791
info!("Commit op is submitted; unpause tenure B's block");
37923792

37933793
// Unpause the broadcast of Tenure B's block, do not submit commits.
3794-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(true);
3794+
test_skip_commit_op.0.lock().unwrap().replace(true);
37953795
TEST_BROADCAST_STALL.lock().unwrap().replace(false);
37963796

37973797
// Wait for a stacks block to be broadcasted
@@ -3816,7 +3816,7 @@ fn forked_tenure_is_ignored() {
38163816
let commits_before = commits_submitted.load(Ordering::SeqCst);
38173817
let blocks_before = mined_blocks.load(Ordering::SeqCst);
38183818
next_block_and(&mut btc_regtest_controller, 60, || {
3819-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(false);
3819+
test_skip_commit_op.0.lock().unwrap().replace(false);
38203820
let commits_count = commits_submitted.load(Ordering::SeqCst);
38213821
let blocks_count = mined_blocks.load(Ordering::SeqCst);
38223822
Ok(commits_count > commits_before && blocks_count > blocks_before)
@@ -5478,6 +5478,7 @@ fn continue_tenure_extend() {
54785478
blocks_processed,
54795479
naka_submitted_commits: commits_submitted,
54805480
naka_proposed_blocks: proposals_submitted,
5481+
naka_skip_commit_op: test_skip_commit_op,
54815482
..
54825483
} = run_loop.counters();
54835484

@@ -5549,7 +5550,7 @@ fn continue_tenure_extend() {
55495550
);
55505551

55515552
info!("Pausing commit ops to trigger a tenure extend.");
5552-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(true);
5553+
test_skip_commit_op.0.lock().unwrap().replace(true);
55535554

55545555
next_block_and(&mut btc_regtest_controller, 60, || Ok(true)).unwrap();
55555556

@@ -5604,7 +5605,7 @@ fn continue_tenure_extend() {
56045605
);
56055606

56065607
info!("Resuming commit ops to mine regular tenures.");
5607-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(false);
5608+
test_skip_commit_op.0.lock().unwrap().replace(false);
56085609

56095610
// Mine 15 more regular nakamoto tenures
56105611
for _i in 0..15 {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use wsts::state_machine::PublicKeys;
5757

5858
use crate::config::{Config as NeonConfig, EventKeyType, EventObserverConfig, InitialBalance};
5959
use crate::event_dispatcher::MinedNakamotoBlockEvent;
60-
use crate::neon::Counters;
60+
use crate::neon::{Counters, TestFlag};
6161
use crate::run_loop::boot_nakamoto;
6262
use crate::tests::bitcoin_regtest::BitcoinCoreController;
6363
use crate::tests::nakamoto_integrations::{
@@ -81,6 +81,7 @@ pub struct RunningNodes {
8181
pub blocks_processed: Arc<AtomicU64>,
8282
pub nakamoto_blocks_proposed: Arc<AtomicU64>,
8383
pub nakamoto_blocks_mined: Arc<AtomicU64>,
84+
pub nakamoto_test_skip_commit_op: TestFlag,
8485
pub coord_channel: Arc<Mutex<CoordinatorChannels>>,
8586
pub conf: NeonConfig,
8687
}
@@ -679,6 +680,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig) -> ()>(
679680
naka_submitted_commits: commits_submitted,
680681
naka_proposed_blocks: naka_blocks_proposed,
681682
naka_mined_blocks: naka_blocks_mined,
683+
naka_skip_commit_op: nakamoto_test_skip_commit_op,
682684
..
683685
} = run_loop.counters();
684686

@@ -711,6 +713,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig) -> ()>(
711713
blocks_processed: blocks_processed.0,
712714
nakamoto_blocks_proposed: naka_blocks_proposed.0,
713715
nakamoto_blocks_mined: naka_blocks_mined.0,
716+
nakamoto_test_skip_commit_op,
714717
coord_channel,
715718
conf: naka_conf,
716719
}

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use tracing_subscriber::{fmt, EnvFilter};
5252
use super::SignerTest;
5353
use crate::event_dispatcher::MinedNakamotoBlockEvent;
5454
use crate::nakamoto_node::miner::TEST_BROADCAST_STALL;
55-
use crate::nakamoto_node::relayer::TEST_SKIP_COMMIT_OP;
5655
use crate::run_loop::boot_nakamoto;
5756
use crate::tests::nakamoto_integrations::{
5857
boot_to_epoch_25, boot_to_epoch_3_reward_set, next_block_and, POX_4_DEFAULT_STACKER_STX_AMT,
@@ -859,7 +858,13 @@ fn forked_tenure_testing(
859858
info!("Commit op is submitted; unpause tenure B's block");
860859

861860
// Unpause the broadcast of Tenure B's block, do not submit commits.
862-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(true);
861+
signer_test
862+
.running_nodes
863+
.nakamoto_test_skip_commit_op
864+
.0
865+
.lock()
866+
.unwrap()
867+
.replace(true);
863868
TEST_BROADCAST_STALL.lock().unwrap().replace(false);
864869

865870
// Wait for a stacks block to be broadcasted
@@ -892,7 +897,13 @@ fn forked_tenure_testing(
892897
&mut signer_test.running_nodes.btc_regtest_controller,
893898
60,
894899
|| {
895-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(false);
900+
signer_test
901+
.running_nodes
902+
.nakamoto_test_skip_commit_op
903+
.0
904+
.lock()
905+
.unwrap()
906+
.replace(false);
896907
let commits_count = commits_submitted.load(Ordering::SeqCst);
897908
let blocks_count = if expect_tenure_c {
898909
mined_blocks.load(Ordering::SeqCst)
@@ -1624,7 +1635,13 @@ fn empty_sortition() {
16241635
TEST_BROADCAST_STALL.lock().unwrap().replace(true);
16251636

16261637
info!("Pausing commit op to prevent tenure C from starting...");
1627-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(true);
1638+
signer_test
1639+
.running_nodes
1640+
.nakamoto_test_skip_commit_op
1641+
.0
1642+
.lock()
1643+
.unwrap()
1644+
.replace(true);
16281645

16291646
let blocks_after = signer_test
16301647
.running_nodes

0 commit comments

Comments
 (0)