Skip to content

Commit

Permalink
fix: bug in the tenure extending logic -- only include tenure change …
Browse files Browse the repository at this point in the history
…tx in the first block after extension
  • Loading branch information
kantai committed Sep 25, 2024
1 parent b995e27 commit 541d13b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2216,7 +2216,7 @@ impl StacksBlockBuilder {
// mine an empty block so you can start your tenure quickly!
if let Some(tx) = initial_txs.first() {
if matches!(&tx.payload, TransactionPayload::TenureChange(_)) {
debug!("Nakamoto miner heuristic: during tenure change blocks, produce a fast short block to begin tenure");
info!("Nakamoto miner heuristic: during tenure change blocks, produce a fast short block to begin tenure");
return Ok((false, tx_events));
}
}
Expand Down
14 changes: 10 additions & 4 deletions testnet/stacks-node/src/nakamoto_node/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,12 @@ impl BlockMinerThread {
tenure_change_tx: None,
});
};
if self.last_block_mined.is_some() {
return Ok(NakamotoTenureInfo {
coinbase_tx: None,
tenure_change_tx: None,
});
}

let parent_block_id = parent_block_info.stacks_parent_header.index_block_hash();
let mut payload = TenureChangePayload {
Expand Down Expand Up @@ -1289,10 +1295,10 @@ impl BlockMinerThread {
&parent_block_id,
)
.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,
info!("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,
Expand Down
8 changes: 5 additions & 3 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6382,7 +6382,8 @@ fn continue_tenure_extend() {
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
let prom_bind = format!("{}:{}", "127.0.0.1", 6000);
naka_conf.node.prometheus_bind = Some(prom_bind.clone());
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1000);
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
let http_origin = naka_conf.node.data_url.clone();
let sender_sk = Secp256k1PrivateKey::new();
// setup sender + recipient for a test stx transfer
let sender_addr = tests::to_addr(&sender_sk);
Expand Down Expand Up @@ -6571,12 +6572,13 @@ fn continue_tenure_extend() {
&signers,
);

wait_for(5, || {
wait_for(25, || {
let blocks_processed = coord_channel
.lock()
.expect("Mutex poisoned")
.get_stacks_blocks_processed();
Ok(blocks_processed > blocks_processed_before)
let sender_nonce = get_account(&http_origin, &to_addr(&sender_sk)).nonce;
Ok(blocks_processed > blocks_processed_before && sender_nonce >= 1)
})
.unwrap();

Expand Down

0 comments on commit 541d13b

Please sign in to comment.