Skip to content

Commit

Permalink
Fix test to only care about the 15 tenures we mine
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
  • Loading branch information
jferrant committed Jun 6, 2024
1 parent 27e206c commit 2d32ba0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 88 deletions.
7 changes: 0 additions & 7 deletions stackslib/src/chainstate/nakamoto/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,6 @@ impl NakamotoBlockBuilder {
signer_transactions: Vec<StacksTransaction>,
signer_bitvec_len: u16,
) -> Result<(NakamotoBlock, ExecutionCost, u64, Vec<TransactionEvent>), Error> {
let parent_block_id = parent_stacks_header.index_block_hash();
info!("Building a nakamoto block";
"parent_block_id" => %parent_block_id,
"tenure_id_consensus_hash" => %tenure_id_consensus_hash,
"parent_consensus_hash" => %parent_stacks_header.consensus_hash,
"tenure_info" => ?tenure_info
);
let (tip_consensus_hash, tip_block_hash, tip_height) = (
parent_stacks_header.consensus_hash.clone(),
parent_stacks_header.anchored_header.block_hash(),
Expand Down
5 changes: 0 additions & 5 deletions stackslib/src/chainstate/nakamoto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2784,10 +2784,6 @@ impl NakamotoChainState {
)
};

error!(
"Processing block: block.header.consensus_hash {:?}, parent_ch {:?}",
block.header.consensus_hash, parent_ch
);
let parent_block_id = StacksBlockId::new(&parent_ch, &parent_block_hash);
if parent_block_id != block.header.parent_block_id {
warn!("Error processing nakamoto block: Parent consensus hash does not match db view";
Expand Down Expand Up @@ -2818,7 +2814,6 @@ impl NakamotoChainState {
&block.header,
)?
{
warn!("FAILED");
// this block is not part of the ongoing tenure; it's invalid
return Err(ChainstateError::ExpectedTenureChange);
}
Expand Down
13 changes: 0 additions & 13 deletions stackslib/src/chainstate/nakamoto/tenure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,30 +865,17 @@ impl NakamotoChainState {
) -> Result<bool, ChainstateError> {
// block must have the same consensus hash as its parent
if block_header.is_first_mined() || parent_ch != &block_header.consensus_hash {
error!(
"BLOCK HEADER IS FIRST MINED: {}",
block_header.is_first_mined()
);
error!("Block is not in the same tenure as its parent";
"parent_ch" => %parent_ch,
"block_header.consensus_hash" => %block_header.consensus_hash,
"block_header" => ?block_header);
return Ok(false);
}

// block must be in the same tenure as the highest-processed tenure.
let Some(highest_tenure) = Self::get_highest_nakamoto_tenure(headers_conn, sortdb_conn)?
else {
error!("No tenure found");
// no tenures yet, so definitely not continuous
return Ok(false);
};

if &highest_tenure.tenure_id_consensus_hash != parent_ch {
error!("Block is not in the highest-known tenure";
"highest_tenure" => %highest_tenure.tenure_id_consensus_hash,
"block_header.consensus_hash" => %block_header.consensus_hash,
"block_header" => ?block_header);
// this block is not in the highest-known tenure, so it can't be continuous
return Ok(false);
}
Expand Down
66 changes: 19 additions & 47 deletions testnet/stacks-node/src/nakamoto_node/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ pub enum MinerReason {
/// Current consensus hash on the underlying burnchain. Corresponds to the last-seen
/// sortition.
burn_view_consensus_hash: ConsensusHash,
/// Wether the tenure change transaction was mined
tenure_change_mined: bool,
},
}

impl std::fmt::Display for MinerReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
MinerReason::BlockFound => write!(f, "BlockFound"),
MinerReason::Extended { burn_view_consensus_hash, tenure_change_mined } => write!(
MinerReason::Extended {
burn_view_consensus_hash,
} => write!(
f,
"Extended: burn_view_consensus_hash = {burn_view_consensus_hash:?}, tenure_change_mined = {tenure_change_mined}",
"Extended: burn_view_consensus_hash = {burn_view_consensus_hash:?}",
),
}
}
Expand Down Expand Up @@ -246,14 +246,6 @@ impl BlockMinerThread {
"consensus_hash" => %new_block.header.consensus_hash,
);
self.globals.coord().announce_new_stacks_block();
if let MinerReason::Extended {
tenure_change_mined,
..
} = &mut self.reason
{
// We should not issue multiple tenure change transactions for the same tenure
*tenure_change_mined = true;
}
}

self.globals.counters.bump_naka_mined_blocks();
Expand Down Expand Up @@ -743,7 +735,6 @@ impl BlockMinerThread {
.map_err(|_| NakamotoNodeError::SnapshotNotFoundForChainTip)?
.expect("FATAL: no epoch defined")
.epoch_id;
debug!("HERE WE GO");
let mut parent_block_info = self.load_block_parent_info(&mut burn_db, &mut chain_state)?;
let vrf_proof = self
.make_vrf_proof()
Expand All @@ -754,12 +745,6 @@ impl BlockMinerThread {
return Err(NakamotoNodeError::ParentNotFound);
};

debug!(
"Parent block info parent tenure: {:?} and {:?} mined blocks",
parent_block_info.parent_tenure,
self.mined_blocks.len()
);

// create our coinbase if this is the first block we've mined this tenure
let tenure_start_info = self.make_tenure_start_info(
&chain_state,
Expand All @@ -783,7 +768,7 @@ impl BlockMinerThread {
&mut mem_pool,
&parent_block_info.stacks_parent_header,
&self.burn_election_block.consensus_hash,
self.burn_election_block.total_burn,
self.burn_block.total_burn,
tenure_start_info,
self.config
.make_nakamoto_block_builder_settings(self.globals.get_miner_status()),
Expand Down Expand Up @@ -846,16 +831,11 @@ impl BlockMinerThread {
vrf_proof: VRFProof,
target_epoch_id: StacksEpochId,
) -> Result<NakamotoTenureInfo, NakamotoNodeError> {
debug!("MAKING TENURE START INFO");
let parent_block_id = parent_block_info.stacks_parent_header.index_block_hash();
let current_miner_nonce = parent_block_info.coinbase_nonce;
let (tenure_change_tx, coinbase_tx) = if let Some(ref parent_tenure_info) =
parent_block_info.parent_tenure
{
debug!(
"Miner: Constructing tenure change and coinbase transactions: {}",
self.reason
);
let mut payload = TenureChangePayload {
tenure_consensus_hash: self.burn_election_block.consensus_hash.clone(),
prev_tenure_consensus_hash: parent_tenure_info.parent_tenure_consensus_hash,
Expand All @@ -869,7 +849,6 @@ impl BlockMinerThread {

match &self.reason {
MinerReason::BlockFound => {
debug!("Miner: Constructing tenure change and coinbase transactions");
let tenure_change_tx =
self.generate_tenure_change_tx(current_miner_nonce, payload)?;
let coinbase_tx = self.generate_coinbase_tx(
Expand All @@ -881,31 +860,24 @@ impl BlockMinerThread {
}
MinerReason::Extended {
burn_view_consensus_hash,
tenure_change_mined,
} => {
debug!("Tenure change mined {tenure_change_mined}");
if !*tenure_change_mined {
let num_blocks_so_far = NakamotoChainState::get_nakamoto_tenure_length(
chainstate.db(),
&self.burn_election_block.consensus_hash,
)
.map_err(NakamotoNodeError::MiningFailure)?;
debug!("Miner: Extending tenure"; "burn_view_consensus_hash" => %burn_view_consensus_hash, "parent_block_id" => %parent_block_id, "num_blocks_so_far" => num_blocks_so_far);
payload = payload.extend(
*burn_view_consensus_hash,
parent_block_id,
num_blocks_so_far,
);
let tenure_change_tx =
self.generate_tenure_change_tx(current_miner_nonce, payload)?;
(Some(tenure_change_tx), None)
} else {
(None, None)
}
let num_blocks_so_far = NakamotoChainState::get_nakamoto_tenure_length(
chainstate.db(),
&self.burn_election_block.consensus_hash,
)
.map_err(NakamotoNodeError::MiningFailure)?;
debug!("Miner: Extending tenure"; "burn_view_consensus_hash" => %burn_view_consensus_hash, "parent_block_id" => %parent_block_id, "num_blocks_so_far" => num_blocks_so_far);
payload = payload.extend(
*burn_view_consensus_hash,
parent_block_id,
num_blocks_so_far,
);
let tenure_change_tx =
self.generate_tenure_change_tx(current_miner_nonce, payload)?;
(Some(tenure_change_tx), None)
}
}
} else {
debug!("Miner: NOT Constructing tenure change and coinbase transactions");
(None, None)
};

Expand Down
6 changes: 1 addition & 5 deletions testnet/stacks-node/src/nakamoto_node/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,6 @@ impl RelayerThread {
parent_tenure_id: StacksBlockId,
reason: MinerReason,
) -> Result<BlockMinerThread, NakamotoNodeError> {
debug!("Relayer: creating block miner thread";
"reason" => %reason
);
if fault_injection_skip_mining(&self.config.node.rpc_bind, burn_tip.block_height) {
debug!(
"Relayer: fault injection skip mining at block height {}",
Expand All @@ -573,7 +570,7 @@ impl RelayerThread {
return Err(NakamotoNodeError::MissedMiningOpportunity);
}

info!(
debug!(
"Relayer: Spawn tenure thread";
"height" => burn_tip.block_height,
"burn_header_hash" => %burn_header_hash,
Expand Down Expand Up @@ -713,7 +710,6 @@ impl RelayerThread {
burn_tip,
MinerReason::Extended {
burn_view_consensus_hash: new_burn_view,
tenure_change_mined: false,
},
) {
Ok(()) => {
Expand Down
14 changes: 3 additions & 11 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4037,7 +4037,7 @@ fn continue_tenure_extend() {
&signers,
);

info!("Pausing commit op for the next block");
info!("Pausing commit ops to trigger a tenure extend.");
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(true);

next_block_and(&mut btc_regtest_controller, 60, || Ok(true)).unwrap();
Expand Down Expand Up @@ -4073,7 +4073,6 @@ fn continue_tenure_extend() {
)
.unwrap();

debug!("MINING A STACKS BLOCK");
next_block_and_process_new_stacks_block(&mut btc_regtest_controller, 60, &coord_channel)
.unwrap();

Expand All @@ -4084,7 +4083,6 @@ fn continue_tenure_extend() {
&signers,
);

debug!("MINING THE NEXT BLOCK");
next_block_and(&mut btc_regtest_controller, 60, || Ok(true)).unwrap();

signer_vote_if_needed(
Expand All @@ -4094,10 +4092,9 @@ fn continue_tenure_extend() {
&signers,
);

debug!("Unpausing commit op");
info!("Resuming commit ops to mine regular tenures.");
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(false);

debug!("MINING THE NEXT TENURES");
// Mine 15 more regular nakamoto tenures
for _i in 0..15 {
let commits_before = commits_submitted.load(Ordering::SeqCst);
Expand Down Expand Up @@ -4127,11 +4124,6 @@ fn continue_tenure_extend() {
let tip = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb)
.unwrap()
.unwrap();
info!(
"Latest tip";
"height" => tip.stacks_block_height,
"is_nakamoto" => tip.anchored_header.as_stacks_nakamoto().is_some(),
);

// assert that the transfer tx was observed
let transfer_tx_included = test_observer::get_blocks()
Expand All @@ -4152,7 +4144,7 @@ fn continue_tenure_extend() {
);

assert!(tip.anchored_header.as_stacks_nakamoto().is_some());
assert!(tip.stacks_block_height >= block_height_pre_3_0 + 30);
assert!(tip.stacks_block_height >= block_height_pre_3_0 + 15);

// make sure prometheus returns an updated height
#[cfg(feature = "monitoring_prom")]
Expand Down

0 comments on commit 2d32ba0

Please sign in to comment.