Skip to content

Commit 8185911

Browse files
committed
Merge branch 'develop' into fix/deadlock
2 parents b557827 + 1d61f35 commit 8185911

File tree

8 files changed

+818
-50
lines changed

8 files changed

+818
-50
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ jobs:
9393
- tests::signer::v0::bitcoind_forking_test
9494
- tests::signer::v0::multiple_miners
9595
- tests::signer::v0::mock_sign_epoch_25
96+
- tests::signer::v0::miner_forking
9697
- tests::nakamoto_integrations::stack_stx_burn_op_integration_test
9798
- tests::nakamoto_integrations::check_block_heights
9899
- tests::nakamoto_integrations::clarity_burn_state
99100
- tests::nakamoto_integrations::check_block_times
100101
- tests::nakamoto_integrations::check_block_info
101102
- tests::nakamoto_integrations::check_block_info_rewards
102103
- tests::nakamoto_integrations::continue_tenure_extend
104+
- tests::nakamoto_integrations::mock_mining
103105
- tests::nakamoto_integrations::multiple_miners
104106
# Do not run this one until we figure out why it fails in CI
105107
# - tests::neon_integrations::bitcoin_reorg_flap

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/miner.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,35 @@ impl BlockMinerThread {
224224
// now, actually run this tenure
225225
loop {
226226
let new_block = loop {
227+
// If we're mock mining, we may not have processed the block that the
228+
// actual tenure winner committed to yet. So, before attempting to
229+
// mock mine, check if the parent is processed.
230+
if self.config.get_node_config(false).mock_mining {
231+
let burn_db_path = self.config.get_burn_db_file_path();
232+
let mut burn_db = SortitionDB::open(
233+
&burn_db_path,
234+
true,
235+
self.burnchain.pox_constants.clone(),
236+
)
237+
.expect("FATAL: could not open sortition DB");
238+
let burn_tip_changed = self.check_burn_tip_changed(&burn_db);
239+
let mut chain_state = neon_node::open_chainstate_with_faults(&self.config)
240+
.expect("FATAL: could not open chainstate DB");
241+
match burn_tip_changed
242+
.and_then(|_| self.load_block_parent_info(&mut burn_db, &mut chain_state))
243+
{
244+
Ok(..) => {}
245+
Err(NakamotoNodeError::ParentNotFound) => {
246+
info!("Mock miner has not processed parent block yet, sleeping and trying again");
247+
thread::sleep(Duration::from_millis(ABORT_TRY_AGAIN_MS));
248+
continue;
249+
}
250+
Err(e) => {
251+
warn!("Mock miner failed to load parent info: {e:?}");
252+
return Err(e);
253+
}
254+
}
255+
}
227256
match self.mine_block(&stackerdbs) {
228257
Ok(x) => break Some(x),
229258
Err(NakamotoNodeError::MiningFailure(ChainstateError::MinerAborted)) => {
@@ -430,6 +459,11 @@ impl BlockMinerThread {
430459

431460
let miner_privkey_as_scalar = Scalar::from(miner_privkey.as_slice().clone());
432461
let reward_set = self.load_signer_set()?;
462+
463+
if self.config.get_node_config(false).mock_mining {
464+
return Ok((reward_set, Vec::new()));
465+
}
466+
433467
let mut coordinator =
434468
SignCoordinator::new(&reward_set, miner_privkey_as_scalar, &self.config).map_err(
435469
|e| {

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

Lines changed: 20 additions & 19 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
@@ -412,7 +407,7 @@ impl RelayerThread {
412407
}
413408

414409
let directive = if sn.sortition {
415-
if won_sortition {
410+
if won_sortition || self.config.get_node_config(false).mock_mining {
416411
MinerDirective::BeginTenure {
417412
parent_tenure_start: committed_index_hash,
418413
burnchain_tip: sn,
@@ -794,7 +789,7 @@ impl RelayerThread {
794789

795790
fn continue_tenure(&mut self, new_burn_view: ConsensusHash) -> Result<(), NakamotoNodeError> {
796791
if let Err(e) = self.stop_tenure() {
797-
error!("Relayer: Failed to stop tenure: {:?}", e);
792+
error!("Relayer: Failed to stop tenure: {e:?}");
798793
return Ok(());
799794
}
800795
debug!("Relayer: successfully stopped tenure.");
@@ -867,7 +862,7 @@ impl RelayerThread {
867862
debug!("Relayer: successfully started new tenure.");
868863
}
869864
Err(e) => {
870-
error!("Relayer: Failed to start new tenure: {:?}", e);
865+
error!("Relayer: Failed to start new tenure: {e:?}");
871866
}
872867
}
873868
Ok(())
@@ -879,13 +874,11 @@ impl RelayerThread {
879874
burn_hash: BurnchainHeaderHash,
880875
committed_index_hash: StacksBlockId,
881876
) -> bool {
882-
let miner_instruction =
883-
match self.process_sortition(consensus_hash, burn_hash, committed_index_hash) {
884-
Ok(mi) => mi,
885-
Err(_) => {
886-
return false;
887-
}
888-
};
877+
let Ok(miner_instruction) =
878+
self.process_sortition(consensus_hash, burn_hash, committed_index_hash)
879+
else {
880+
return false;
881+
};
889882

890883
match miner_instruction {
891884
MinerDirective::BeginTenure {
@@ -901,7 +894,7 @@ impl RelayerThread {
901894
debug!("Relayer: successfully started new tenure.");
902895
}
903896
Err(e) => {
904-
error!("Relayer: Failed to start new tenure: {:?}", e);
897+
error!("Relayer: Failed to start new tenure: {e:?}");
905898
}
906899
},
907900
MinerDirective::ContinueTenure { new_burn_view } => {
@@ -910,7 +903,7 @@ impl RelayerThread {
910903
debug!("Relayer: successfully handled continue tenure.");
911904
}
912905
Err(e) => {
913-
error!("Relayer: Failed to continue tenure: {:?}", e);
906+
error!("Relayer: Failed to continue tenure: {e:?}");
914907
return false;
915908
}
916909
}
@@ -920,7 +913,7 @@ impl RelayerThread {
920913
debug!("Relayer: successfully stopped tenure.");
921914
}
922915
Err(e) => {
923-
error!("Relayer: Failed to stop tenure: {:?}", e);
916+
error!("Relayer: Failed to stop tenure: {e:?}");
924917
}
925918
},
926919
}
@@ -937,7 +930,15 @@ impl RelayerThread {
937930
let mut last_committed = self.make_block_commit(&tip_block_ch, &tip_block_bh)?;
938931
#[cfg(test)]
939932
{
940-
if TEST_SKIP_COMMIT_OP.lock().unwrap().unwrap_or(false) {
933+
if self
934+
.globals
935+
.counters
936+
.naka_skip_commit_op
937+
.0
938+
.lock()
939+
.unwrap()
940+
.unwrap_or(false)
941+
{
941942
warn!("Relayer: not submitting block-commit to bitcoin network due to test directive.");
942943
return Ok(());
943944
}

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 {

0 commit comments

Comments
 (0)