Skip to content

Commit

Permalink
CRC: when reissuing a tenure change payload use the winning stacks bl…
Browse files Browse the repository at this point in the history
…ock hash to form the parent_tenure_start

Signed-off-by: Jacinta Ferrant <[email protected]>
  • Loading branch information
jferrant committed Nov 8, 2024
1 parent 8c9d129 commit 2dced24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
15 changes: 6 additions & 9 deletions testnet/stacks-node/src/nakamoto_node/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,25 +922,22 @@ impl BlockMinerThread {
fn make_vrf_proof(&mut self) -> Option<VRFProof> {
// if we're a mock miner, then make sure that the keychain has a keypair for the mocked VRF
// key
let sortition_hash = if matches!(self.reason, MinerReason::EmptyTenure) {
self.burn_election_block.sortition_hash
} else {
self.burn_block.sortition_hash
};
let vrf_proof = if self.config.get_node_config(false).mock_mining {
self.keychain
.generate_proof(VRF_MOCK_MINER_KEY, sortition_hash.as_bytes())
self.keychain.generate_proof(
VRF_MOCK_MINER_KEY,
self.burn_election_block.sortition_hash.as_bytes(),
)
} else {
self.keychain.generate_proof(
self.registered_key.target_block_height,
sortition_hash.as_bytes(),
self.burn_election_block.sortition_hash.as_bytes(),
)
};

debug!(
"Generated VRF Proof: {} over {} ({},{}) with key {}",
vrf_proof.to_hex(),
&sortition_hash,
&self.burn_election_block.sortition_hash,
&self.burn_block.block_height,
&self.burn_block.burn_header_hash,
&self.registered_key.vrf_public_key.to_hex()
Expand Down
14 changes: 7 additions & 7 deletions testnet/stacks-node/src/nakamoto_node/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ impl RelayerThread {
return Ok(());
}

let last_non_empty_sortition_snapshot =
let canonical_block_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:?}");
Expand All @@ -923,22 +923,22 @@ impl RelayerThread {
NakamotoNodeError::SnapshotNotFoundForChainTip
})?;

let won_last_non_empty_sortition_snapshot =
last_non_empty_sortition_snapshot.miner_pk_hash == Some(mining_pkh);
let won_canonical_block_snapshot =
canonical_block_snapshot.miner_pk_hash == Some(mining_pkh);

let (parent_tenure_start, block_election_snapshot, reason) =
if !won_last_non_empty_sortition_snapshot {
if !won_canonical_block_snapshot {
debug!("Relayer: Failed to issue a tenure change payload in our last tenure. Issue a new tenure change payload.");
(
canonical_stacks_tip,
StacksBlockId(last_block_election_snapshot.winning_stacks_block_hash.0),
last_block_election_snapshot,
MinerReason::EmptyTenure,
)
} else {
debug!("Relayer: Successfully issued a tenure change payload in its tenure. Issue a continue extend from the chain tip.");
(
canonical_stacks_tip, //For tenure extend, we sould be extending off the canonical tip
last_non_empty_sortition_snapshot,
canonical_stacks_tip, //For tenure extend, we should be extending off the canonical tip
canonical_block_snapshot,
MinerReason::Extended {
burn_view_consensus_hash: new_burn_view,
},
Expand Down

0 comments on commit 2dced24

Please sign in to comment.