Skip to content

Commit

Permalink
CRC: use the last snapshot with a sortition to determine if we should…
Browse files Browse the repository at this point in the history
… proceed with a continue_tenure

Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
  • Loading branch information
jferrant committed Jun 17, 2024
1 parent 24b5e79 commit 55ae4df
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions testnet/stacks-node/src/nakamoto_node/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,25 +683,24 @@ 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));
if block_election_snapshot.miner_pk_hash != Some(mining_pkh) {

let last_winner_snapshot = {
let ih = self.sortdb.index_handle(&burn_tip.sortition_id);
ih.get_last_snapshot_with_sortition(burn_tip.block_height).map_err(|e| {
error!("Relayer: failed to get last snapshot with sortition: {e:?}");
NakamotoNodeError::SnapshotNotFoundForChainTip
})?
};

if last_winner_snapshot.miner_pk_hash != Some(mining_pkh) {
debug!("Relayer: the miner did not win the last sortition. No tenure to continue.";
"current_mining_pkh" => %mining_pkh,
"block_snapshot.miner_pk_hash" => ?block_election_snapshot.miner_pk_hash,
"last_winner_snapshot.miner_pk_hash" => ?last_winner_snapshot.miner_pk_hash,
);
return Ok(());
} else {
Expand All @@ -710,7 +709,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

0 comments on commit 55ae4df

Please sign in to comment.