Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable mock mining in Epoch 3.0 #5029

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/bitcoin-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
- tests::nakamoto_integrations::check_block_info
- tests::nakamoto_integrations::check_block_info_rewards
- tests::nakamoto_integrations::continue_tenure_extend
- tests::nakamoto_integrations::mock_mining
# Do not run this one until we figure out why it fails in CI
# - tests::neon_integrations::bitcoin_reorg_flap
# - tests::neon_integrations::bitcoin_reorg_flap_with_follower
Expand Down
34 changes: 30 additions & 4 deletions testnet/stacks-node/src/nakamoto_node/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,32 @@ impl BlockMinerThread {
// now, actually run this tenure
loop {
let new_block = loop {
if self.config.get_node_config(false).mock_mining {
kantai marked this conversation as resolved.
Show resolved Hide resolved
let burn_db_path = self.config.get_burn_db_file_path();
let mut burn_db = SortitionDB::open(
&burn_db_path,
true,
self.burnchain.pox_constants.clone(),
)
.expect("FATAL: could not open sortition DB");
let burn_tip_changed = self.check_burn_tip_changed(&burn_db);
let mut chain_state = neon_node::open_chainstate_with_faults(&self.config)
.expect("FATAL: could not open chainstate DB");
match burn_tip_changed
.and_then(|_| self.load_block_parent_info(&mut burn_db, &mut chain_state))
{
Ok(..) => {}
Err(NakamotoNodeError::ParentNotFound) => {
info!("Mock miner has not processed parent block yet, sleeping and trying again");
thread::sleep(Duration::from_millis(ABORT_TRY_AGAIN_MS));
continue;
}
Err(e) => {
warn!("Mock miner failed to load parent info: {e:?}");
return Err(e);
}
}
}
match self.mine_block(&stackerdbs) {
Ok(x) => break Some(x),
Err(NakamotoNodeError::MiningFailure(ChainstateError::MinerAborted)) => {
Expand Down Expand Up @@ -401,6 +427,10 @@ impl BlockMinerThread {
));
};

if self.config.get_node_config(false).mock_mining {
return Ok((reward_set, Vec::new()));
}

let miner_privkey_as_scalar = Scalar::from(miner_privkey.as_slice().clone());
let mut coordinator =
SignCoordinator::new(&reward_set, miner_privkey_as_scalar, &self.config).map_err(
Expand All @@ -411,10 +441,6 @@ impl BlockMinerThread {
},
)?;

if self.config.get_node_config(false).mock_mining {
return Ok((reward_set, Vec::new()));
}

*attempts += 1;
let signature = coordinator.begin_sign_v0(
new_block,
Expand Down
22 changes: 10 additions & 12 deletions testnet/stacks-node/src/nakamoto_node/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ impl RelayerThread {

fn continue_tenure(&mut self, new_burn_view: ConsensusHash) -> Result<(), NakamotoNodeError> {
if let Err(e) = self.stop_tenure() {
error!("Relayer: Failed to stop tenure: {:?}", e);
error!("Relayer: Failed to stop tenure: {e:?}");
return Ok(());
}
debug!("Relayer: successfully stopped tenure.");
Expand Down Expand Up @@ -867,7 +867,7 @@ impl RelayerThread {
debug!("Relayer: successfully started new tenure.");
}
Err(e) => {
error!("Relayer: Failed to start new tenure: {:?}", e);
error!("Relayer: Failed to start new tenure: {e:?}");
}
}
Ok(())
Expand All @@ -879,13 +879,11 @@ impl RelayerThread {
burn_hash: BurnchainHeaderHash,
committed_index_hash: StacksBlockId,
) -> bool {
let miner_instruction =
match self.process_sortition(consensus_hash, burn_hash, committed_index_hash) {
Ok(mi) => mi,
Err(_) => {
return false;
}
};
let Ok(miner_instruction) =
self.process_sortition(consensus_hash, burn_hash, committed_index_hash)
else {
return false;
};

match miner_instruction {
MinerDirective::BeginTenure {
Expand All @@ -901,7 +899,7 @@ impl RelayerThread {
debug!("Relayer: successfully started new tenure.");
}
Err(e) => {
error!("Relayer: Failed to start new tenure: {:?}", e);
error!("Relayer: Failed to start new tenure: {e:?}");
}
},
MinerDirective::ContinueTenure { new_burn_view } => {
Expand All @@ -910,7 +908,7 @@ impl RelayerThread {
debug!("Relayer: successfully handled continue tenure.");
}
Err(e) => {
error!("Relayer: Failed to continue tenure: {:?}", e);
error!("Relayer: Failed to continue tenure: {e:?}");
return false;
}
}
Expand All @@ -920,7 +918,7 @@ impl RelayerThread {
debug!("Relayer: successfully stopped tenure.");
}
Err(e) => {
error!("Relayer: Failed to stop tenure: {:?}", e);
error!("Relayer: Failed to stop tenure: {e:?}");
}
},
}
Expand Down
Loading