Skip to content

Commit 80fbce7

Browse files
committed
BUGFIX: use the block election snapshot when creating a tenure extend. Not the tip consensus hash as it may not match and will result in a bad signer slot generation when writing block proposal
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent cf1d13c commit 80fbce7

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

testnet/stacks-node/src/nakamoto_node/relayer.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -880,23 +880,14 @@ impl RelayerThread {
880880
SortitionDB::get_canonical_stacks_chain_tip_hash(self.sortdb.conn()).unwrap();
881881
let canonical_stacks_tip =
882882
StacksBlockId::new(&canonical_stacks_tip_ch, &canonical_stacks_tip_bh);
883-
let block_election_snapshot =
884-
SortitionDB::get_block_snapshot_consensus(self.sortdb.conn(), &canonical_stacks_tip_ch)
885-
.map_err(|e| {
886-
error!("Relayer: failed to get block snapshot for canonical tip: {e:?}");
887-
NakamotoNodeError::SnapshotNotFoundForChainTip
888-
})?
889-
.ok_or_else(|| {
890-
error!("Relayer: failed to get block snapshot for canonical tip");
891-
NakamotoNodeError::SnapshotNotFoundForChainTip
892-
})?;
893883

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

899-
let last_winner_snapshot = {
889+
// If we won the last sortition, then we should start a new tenure off of it.
890+
let block_election_snapshot = {
900891
let ih = self.sortdb.index_handle(&burn_tip.sortition_id);
901892
ih.get_last_snapshot_with_sortition(burn_tip.block_height)
902893
.map_err(|e| {
@@ -905,15 +896,14 @@ impl RelayerThread {
905896
})?
906897
};
907898

908-
let won_last_sortition = last_winner_snapshot.miner_pk_hash == Some(mining_pkh);
899+
let won_last_sortition = block_election_snapshot.miner_pk_hash == Some(mining_pkh);
909900
debug!(
910901
"Relayer: Current burn block had no sortition. Checking for tenure continuation.";
911902
"won_last_sortition" => won_last_sortition,
912903
"current_mining_pkh" => %mining_pkh,
913-
"last_winner_snapshot.miner_pk_hash" => ?last_winner_snapshot.miner_pk_hash,
904+
"block_election_snapshot.miner_pk_hash" => ?block_election_snapshot.miner_pk_hash,
914905
"canonical_stacks_tip_id" => %canonical_stacks_tip,
915906
"canonical_stacks_tip_ch" => %canonical_stacks_tip_ch,
916-
"block_election_ch" => %block_election_snapshot.consensus_hash,
917907
"burn_view_ch" => %new_burn_view,
918908
);
919909

0 commit comments

Comments
 (0)