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

Use last winner snapshot when starting a new tenure in continue_tenure #5355

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
19 changes: 7 additions & 12 deletions testnet/stacks-node/src/nakamoto_node/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,22 +883,17 @@ impl RelayerThread {
SortitionDB::get_canonical_stacks_chain_tip_hash(self.sortdb.conn()).unwrap();
let canonical_stacks_tip =
StacksBlockId::new(&canonical_stacks_tip_ch, &canonical_stacks_tip_bh);
let block_election_snapshot =
SortitionDB::get_block_snapshot_consensus(self.sortdb.conn(), &canonical_stacks_tip_ch)
.map_err(|e| {
error!("Relayer: failed to get block snapshot for canonical tip: {e:?}");
NakamotoNodeError::SnapshotNotFoundForChainTip
})?
.ok_or_else(|| {
error!("Relayer: failed to get block snapshot for canonical tip");
NakamotoNodeError::SnapshotNotFoundForChainTip
})?;

let Some(ref mining_key) = self.config.miner.mining_key else {
return Ok(());
};
let mining_pkh = Hash160::from_node_public_key(&StacksPublicKey::from_private(mining_key));

// The node will try to build on the sortition with the last winner, even if it does not yet have all of
// the ancestor Stacks blocks necessary to do so. This is okay, because (1) the node eventually
// will catch up and (2) the signers won't let the miner orphan blocks they have already seen (and
// signers see all the blocks). So, the miner should try and mine off of the chain tip the signers
// will accept, if it mines at all.
let last_winner_snapshot = {
let ih = self.sortdb.index_handle(&burn_tip.sortition_id);
ih.get_last_snapshot_with_sortition(burn_tip.block_height)
Expand All @@ -916,7 +911,7 @@ impl RelayerThread {
"last_winner_snapshot.miner_pk_hash" => ?last_winner_snapshot.miner_pk_hash,
"canonical_stacks_tip_id" => %canonical_stacks_tip,
"canonical_stacks_tip_ch" => %canonical_stacks_tip_ch,
"block_election_ch" => %block_election_snapshot.consensus_hash,
"block_election_ch" => %last_winner_snapshot.consensus_hash,
jferrant marked this conversation as resolved.
Show resolved Hide resolved
"burn_view_ch" => %new_burn_view,
);

Expand All @@ -926,7 +921,7 @@ impl RelayerThread {

match self.start_new_tenure(
canonical_stacks_tip, // For tenure extend, we should be extending off the canonical tip
block_election_snapshot,
last_winner_snapshot,
burn_tip,
MinerReason::Extended {
burn_view_consensus_hash: new_burn_view,
Expand Down
Loading