Skip to content

Commit df5f6b8

Browse files
committed
Merge remote-tracking branch 'origin/develop' into test/4976-signer-set-handoff
2 parents 69872cf + f49e69a commit df5f6b8

File tree

7 files changed

+492
-38
lines changed

7 files changed

+492
-38
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
- tests::signer::v0::multiple_miners
9595
- tests::signer::v0::mock_sign_epoch_25
9696
- tests::signer::v0::signer_set_rollover
97+
- tests::signer::v0::miner_forking
9798
- tests::nakamoto_integrations::stack_stx_burn_op_integration_test
9899
- tests::nakamoto_integrations::check_block_heights
99100
- tests::nakamoto_integrations::clarity_burn_state

stacks-signer/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,18 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
77

88
## [Unreleased]
99

10+
## [2.5.0.0.5.1]
11+
12+
### Added
13+
14+
- Adds signerdb schema versioning (#4965)
15+
- Added voting cli commands `generate-vote` and `verify-vote` (#4934)
16+
- Add soritiion tracking cache (#4905)
17+
- Push blocks to signer set and adds `/v3/blocks/upload` (#4902)
18+
19+
### Changed
20+
21+
- Fix an issue of poorly timed tenure and bitcoin blocks (#4956)
22+
- Process pending blocks before ending tenure (#4952)
23+
- Update rusqlite/sqlite versions (#4948)
24+
- return last block sortition in `/v3/sortitions` (#4939)

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: 40 additions & 19 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;
@@ -626,6 +625,21 @@ where
626625
Ok(())
627626
}
628627

628+
pub fn wait_for<F>(timeout_secs: u64, mut check: F) -> Result<(), String>
629+
where
630+
F: FnMut() -> Result<bool, String>,
631+
{
632+
let start = Instant::now();
633+
while !check()? {
634+
if start.elapsed() > Duration::from_secs(timeout_secs) {
635+
error!("Timed out waiting for check to process");
636+
return Err("Timed out".into());
637+
}
638+
thread::sleep(Duration::from_millis(100));
639+
}
640+
Ok(())
641+
}
642+
629643
/// Mine a bitcoin block, and wait until:
630644
/// (1) a new block has been processed by the coordinator
631645
pub fn next_block_and_process_new_stacks_block(
@@ -1630,6 +1644,10 @@ fn multiple_miners() {
16301644

16311645
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
16321646
naka_conf.node.local_peer_seed = vec![1, 1, 1, 1];
1647+
naka_conf.miner.mining_key = Some(Secp256k1PrivateKey::from_seed(&[1]));
1648+
1649+
let node_2_rpc = 51026;
1650+
let node_2_p2p = 51025;
16331651
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
16341652
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
16351653
let sender_sk = Secp256k1PrivateKey::new();
@@ -1654,7 +1672,11 @@ fn multiple_miners() {
16541672
let stacker_sk = setup_stacker(&mut naka_conf);
16551673

16561674
let mut conf_node_2 = naka_conf.clone();
1657-
set_random_binds(&mut conf_node_2);
1675+
let localhost = "127.0.0.1";
1676+
conf_node_2.node.rpc_bind = format!("{}:{}", localhost, node_2_rpc);
1677+
conf_node_2.node.p2p_bind = format!("{}:{}", localhost, node_2_p2p);
1678+
conf_node_2.node.data_url = format!("http://{}:{}", localhost, node_2_rpc);
1679+
conf_node_2.node.p2p_address = format!("{}:{}", localhost, node_2_p2p);
16581680
conf_node_2.node.seed = vec![2, 2, 2, 2];
16591681
conf_node_2.burnchain.local_mining_public_key = Some(
16601682
Keychain::default(conf_node_2.node.seed.clone())
@@ -1663,6 +1685,8 @@ fn multiple_miners() {
16631685
);
16641686
conf_node_2.node.local_peer_seed = vec![2, 2, 2, 2];
16651687
conf_node_2.node.miner = true;
1688+
conf_node_2.miner.mining_key = Some(Secp256k1PrivateKey::from_seed(&[2]));
1689+
conf_node_2.events_observers.clear();
16661690

16671691
let node_1_sk = Secp256k1PrivateKey::from_seed(&naka_conf.node.local_peer_seed);
16681692
let node_1_pk = StacksPublicKey::from_private(&node_1_sk);
@@ -1802,16 +1826,14 @@ fn multiple_miners() {
18021826
make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt);
18031827
submit_tx(&http_origin, &transfer_tx);
18041828

1805-
loop {
1829+
wait_for(20, || {
18061830
let blocks_processed = coord_channel
18071831
.lock()
18081832
.expect("Mutex poisoned")
18091833
.get_stacks_blocks_processed();
1810-
if blocks_processed > blocks_processed_before {
1811-
break;
1812-
}
1813-
thread::sleep(Duration::from_millis(100));
1814-
}
1834+
Ok(blocks_processed > blocks_processed_before)
1835+
})
1836+
.unwrap();
18151837

18161838
let info = get_chain_info_result(&naka_conf).unwrap();
18171839
assert_ne!(info.stacks_tip, last_tip);
@@ -1821,13 +1843,10 @@ fn multiple_miners() {
18211843
last_tip_height = info.stacks_tip_height;
18221844
}
18231845

1824-
let start_time = Instant::now();
1825-
while commits_submitted.load(Ordering::SeqCst) <= commits_before {
1826-
if start_time.elapsed() >= Duration::from_secs(20) {
1827-
panic!("Timed out waiting for block-commit");
1828-
}
1829-
thread::sleep(Duration::from_millis(100));
1830-
}
1846+
wait_for(20, || {
1847+
Ok(commits_submitted.load(Ordering::SeqCst) > commits_before)
1848+
})
1849+
.unwrap();
18311850
}
18321851

18331852
// load the chain tip, and assert that it is a nakamoto block and at least 30 blocks have advanced in epoch 3
@@ -3726,6 +3745,7 @@ fn forked_tenure_is_ignored() {
37263745
naka_submitted_commits: commits_submitted,
37273746
naka_proposed_blocks: proposals_submitted,
37283747
naka_mined_blocks: mined_blocks,
3748+
naka_skip_commit_op: test_skip_commit_op,
37293749
..
37303750
} = run_loop.counters();
37313751

@@ -3794,7 +3814,7 @@ fn forked_tenure_is_ignored() {
37943814
info!("Commit op is submitted; unpause tenure B's block");
37953815

37963816
// Unpause the broadcast of Tenure B's block, do not submit commits.
3797-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(true);
3817+
test_skip_commit_op.0.lock().unwrap().replace(true);
37983818
TEST_BROADCAST_STALL.lock().unwrap().replace(false);
37993819

38003820
// Wait for a stacks block to be broadcasted
@@ -3819,7 +3839,7 @@ fn forked_tenure_is_ignored() {
38193839
let commits_before = commits_submitted.load(Ordering::SeqCst);
38203840
let blocks_before = mined_blocks.load(Ordering::SeqCst);
38213841
next_block_and(&mut btc_regtest_controller, 60, || {
3822-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(false);
3842+
test_skip_commit_op.0.lock().unwrap().replace(false);
38233843
let commits_count = commits_submitted.load(Ordering::SeqCst);
38243844
let blocks_count = mined_blocks.load(Ordering::SeqCst);
38253845
Ok(commits_count > commits_before && blocks_count > blocks_before)
@@ -5493,6 +5513,7 @@ fn continue_tenure_extend() {
54935513
blocks_processed,
54945514
naka_submitted_commits: commits_submitted,
54955515
naka_proposed_blocks: proposals_submitted,
5516+
naka_skip_commit_op: test_skip_commit_op,
54965517
..
54975518
} = run_loop.counters();
54985519

@@ -5564,7 +5585,7 @@ fn continue_tenure_extend() {
55645585
);
55655586

55665587
info!("Pausing commit ops to trigger a tenure extend.");
5567-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(true);
5588+
test_skip_commit_op.0.lock().unwrap().replace(true);
55685589

55695590
next_block_and(&mut btc_regtest_controller, 60, || Ok(true)).unwrap();
55705591

@@ -5619,7 +5640,7 @@ fn continue_tenure_extend() {
56195640
);
56205641

56215642
info!("Resuming commit ops to mine regular tenures.");
5622-
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(false);
5643+
test_skip_commit_op.0.lock().unwrap().replace(false);
56235644

56245645
// Mine 15 more regular nakamoto tenures
56255646
for _i in 0..15 {

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

Lines changed: 7 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::{
@@ -82,6 +82,7 @@ pub struct RunningNodes {
8282
pub blocks_processed: Arc<AtomicU64>,
8383
pub nakamoto_blocks_proposed: Arc<AtomicU64>,
8484
pub nakamoto_blocks_mined: Arc<AtomicU64>,
85+
pub nakamoto_test_skip_commit_op: TestFlag,
8586
pub coord_channel: Arc<Mutex<CoordinatorChannels>>,
8687
pub conf: NeonConfig,
8788
}
@@ -92,6 +93,8 @@ pub struct SignerTest<S> {
9293
pub running_nodes: RunningNodes,
9394
// The spawned signers and their threads
9495
pub spawned_signers: Vec<S>,
96+
// The spawned signers and their threads
97+
pub signer_configs: Vec<SignerConfig>,
9598
// the private keys of the signers
9699
pub signer_stacks_private_keys: Vec<StacksPrivateKey>,
97100
// link to the stacks node
@@ -214,6 +217,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
214217
stacks_client,
215218
run_stamp,
216219
num_stacking_cycles: 12_u64,
220+
signer_configs,
217221
}
218222
}
219223

@@ -692,6 +696,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig) -> ()>(
692696
naka_submitted_commits: commits_submitted,
693697
naka_proposed_blocks: naka_blocks_proposed,
694698
naka_mined_blocks: naka_blocks_mined,
699+
naka_skip_commit_op: nakamoto_test_skip_commit_op,
695700
..
696701
} = run_loop.counters();
697702

@@ -724,6 +729,7 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig) -> ()>(
724729
blocks_processed: blocks_processed.0,
725730
nakamoto_blocks_proposed: naka_blocks_proposed.0,
726731
nakamoto_blocks_mined: naka_blocks_mined.0,
732+
nakamoto_test_skip_commit_op,
727733
coord_channel,
728734
conf: naka_conf,
729735
}

0 commit comments

Comments
 (0)