Skip to content

Commit e98c39c

Browse files
committed
Remove clones of counters out of RunningNodes
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent cdcea2c commit e98c39c

File tree

3 files changed

+289
-183
lines changed

3 files changed

+289
-183
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10778,9 +10778,14 @@ fn test_tenure_extend_from_flashblocks() {
1077810778
let counters = signer_test.running_nodes.counters.clone();
1077910779
let nakamoto_test_skip_commit_op = signer_test
1078010780
.running_nodes
10781-
.nakamoto_test_skip_commit_op
10781+
.counters
10782+
.naka_skip_commit_op
10783+
.clone();
10784+
let nakamoto_miner_directives = signer_test
10785+
.running_nodes
10786+
.counters
10787+
.naka_miner_directives
1078210788
.clone();
10783-
let nakamoto_miner_directives = signer_test.running_nodes.nakamoto_miner_directives.clone();
1078410789

1078510790
let tx_fee = 1_000;
1078610791

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

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
mod v0;
1616

1717
use std::collections::HashSet;
18-
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
18+
use std::sync::atomic::{AtomicBool, Ordering};
1919
use std::sync::{Arc, Mutex};
2020
use std::thread;
2121
use std::time::{Duration, Instant};
@@ -44,14 +44,13 @@ use stacks_common::codec::StacksMessageCodec;
4444
use stacks_common::consts::SIGNER_SLOTS_PER_USER;
4545
use stacks_common::types::StacksEpochId;
4646
use stacks_common::util::hash::Sha512Trunc256Sum;
47-
use stacks_common::util::tests::TestFlag;
4847
use stacks_signer::client::{ClientError, SignerSlotID, StackerDB, StacksClient};
4948
use stacks_signer::config::{build_signer_config_tomls, GlobalConfig as SignerConfig, Network};
5049
use stacks_signer::runloop::{SignerResult, State, StateInfo};
5150
use stacks_signer::{Signer, SpawnedSigner};
5251

5352
use super::nakamoto_integrations::{check_nakamoto_empty_block_heuristics, wait_for};
54-
use crate::neon::{Counters, RunLoopCounter};
53+
use crate::neon::Counters;
5554
use crate::run_loop::boot_nakamoto;
5655
use crate::tests::bitcoin_regtest::BitcoinCoreController;
5756
use crate::tests::nakamoto_integrations::{
@@ -72,17 +71,6 @@ pub struct RunningNodes {
7271
pub btcd_controller: BitcoinCoreController,
7372
pub run_loop_thread: thread::JoinHandle<()>,
7473
pub run_loop_stopper: Arc<AtomicBool>,
75-
pub vrfs_submitted: RunLoopCounter,
76-
pub commits_submitted: RunLoopCounter,
77-
pub last_commit_burn_height: RunLoopCounter,
78-
pub blocks_processed: RunLoopCounter,
79-
pub sortitions_processed: RunLoopCounter,
80-
pub nakamoto_blocks_proposed: RunLoopCounter,
81-
pub nakamoto_blocks_mined: RunLoopCounter,
82-
pub nakamoto_blocks_rejected: RunLoopCounter,
83-
pub nakamoto_blocks_signer_pushed: RunLoopCounter,
84-
pub nakamoto_miner_directives: Arc<AtomicU64>,
85-
pub nakamoto_test_skip_commit_op: TestFlag<bool>,
8674
pub counters: Counters,
8775
pub coord_channel: Arc<Mutex<CoordinatorChannels>>,
8876
pub conf: NeonConfig,
@@ -337,7 +325,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
337325
/// Note: do not use nakamoto blocks mined heuristic if running a test with multiple miners
338326
fn mine_nakamoto_block(&mut self, timeout: Duration, use_nakamoto_blocks_mined: bool) {
339327
let mined_block_time = Instant::now();
340-
let mined_before = self.running_nodes.nakamoto_blocks_mined.get();
328+
let mined_before = self.running_nodes.counters.naka_mined_blocks.get();
341329
let info_before = self.get_peer_info();
342330
next_block_and_mine_commit(
343331
&mut self.running_nodes.btc_regtest_controller,
@@ -349,7 +337,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
349337

350338
wait_for(timeout.as_secs(), || {
351339
let info_after = self.get_peer_info();
352-
let blocks_mined = self.running_nodes.nakamoto_blocks_mined.get();
340+
let blocks_mined = self.running_nodes.counters.naka_mined_blocks.get();
353341
Ok(info_after.stacks_tip_height > info_before.stacks_tip_height
354342
&& (!use_nakamoto_blocks_mined || blocks_mined > mined_before))
355343
})
@@ -391,14 +379,14 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
391379
/// to ensure that the block was mined.
392380
/// Note: this function does _not_ mine a BTC block.
393381
fn wait_for_nakamoto_block(&mut self, timeout_secs: u64, f: impl FnOnce() -> ()) {
394-
let blocks_before = self.running_nodes.nakamoto_blocks_mined.get();
382+
let blocks_before = self.running_nodes.counters.naka_mined_blocks.get();
395383
let info_before = self.get_peer_info();
396384

397385
f();
398386

399387
// Verify that the block was mined
400388
wait_for(timeout_secs, || {
401-
let blocks_mined = self.running_nodes.nakamoto_blocks_mined.get();
389+
let blocks_mined = self.running_nodes.counters.naka_mined_blocks.get();
402390
let info = self.get_peer_info();
403391
Ok(blocks_mined > blocks_before
404392
&& info.stacks_tip_height > info_before.stacks_tip_height)
@@ -509,7 +497,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
509497
// advance to epoch 3.0 and trigger a sign round (cannot vote on blocks in pre epoch 3.0)
510498
run_until_burnchain_height(
511499
&mut self.running_nodes.btc_regtest_controller,
512-
&self.running_nodes.blocks_processed,
500+
&self.running_nodes.counters.blocks_processed,
513501
epoch_30_boundary,
514502
&self.running_nodes.conf,
515503
);
@@ -919,21 +907,8 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
919907

920908
let mut run_loop = boot_nakamoto::BootRunLoop::new(naka_conf.clone()).unwrap();
921909
let run_loop_stopper = run_loop.get_termination_switch();
922-
let Counters {
923-
blocks_processed,
924-
sortitions_processed,
925-
naka_submitted_vrfs: vrfs_submitted,
926-
naka_submitted_commits: commits_submitted,
927-
naka_submitted_commit_last_burn_height: last_commit_burn_height,
928-
naka_proposed_blocks: naka_blocks_proposed,
929-
naka_mined_blocks: naka_blocks_mined,
930-
naka_rejected_blocks: naka_blocks_rejected,
931-
naka_miner_directives,
932-
naka_skip_commit_op: nakamoto_test_skip_commit_op,
933-
naka_signer_pushed_blocks,
934-
..
935-
} = run_loop.counters();
936910
let counters = run_loop.counters();
911+
let blocks_processed = counters.blocks_processed.clone();
937912

938913
let coord_channel = run_loop.coordinator_channels();
939914
let run_loop_thread = thread::spawn(move || run_loop.start(None, 0));
@@ -944,32 +919,21 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
944919

945920
// First block wakes up the run loop.
946921
info!("Mine first block...");
947-
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);
922+
next_block_and_wait(&mut btc_regtest_controller, &counters.blocks_processed);
948923

949924
// Second block will hold our VRF registration.
950925
info!("Mine second block...");
951-
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);
926+
next_block_and_wait(&mut btc_regtest_controller, &counters.blocks_processed);
952927

953928
// Third block will be the first mined Stacks block.
954929
info!("Mine third block...");
955-
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);
930+
next_block_and_wait(&mut btc_regtest_controller, &counters.blocks_processed);
956931

957932
RunningNodes {
958933
btcd_controller,
959934
btc_regtest_controller,
960935
run_loop_thread,
961936
run_loop_stopper,
962-
vrfs_submitted,
963-
commits_submitted,
964-
last_commit_burn_height,
965-
blocks_processed,
966-
sortitions_processed,
967-
nakamoto_blocks_proposed: naka_blocks_proposed,
968-
nakamoto_blocks_mined: naka_blocks_mined,
969-
nakamoto_blocks_rejected: naka_blocks_rejected,
970-
nakamoto_blocks_signer_pushed: naka_signer_pushed_blocks,
971-
nakamoto_test_skip_commit_op,
972-
nakamoto_miner_directives: naka_miner_directives.0,
973937
coord_channel,
974938
counters,
975939
conf: naka_conf,

0 commit comments

Comments
 (0)