Skip to content

Commit

Permalink
Merge pull request #5254 from stacks-network/fix/testnet-launch-fixes
Browse files Browse the repository at this point in the history
Fix: /v3/sortitions calculation and tenure extend behavior
  • Loading branch information
kantai authored Oct 1, 2024
2 parents 18c70b4 + 2875d45 commit c39ba88
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 5 additions & 1 deletion stackslib/src/net/api/getsortition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ impl GetSortitionHandler {
// try to figure out what the last snapshot in this fork was with a successful
// sortition.
// optimization heuristic: short-circuit the load if its just `stacks_parent_sn`
let last_sortition_ch = if stacks_parent_sn.sortition {
// if the sortition count incremented by exactly 1 between us and our **stacks** parent,
// then the stacks parent's sortition *must* be the last one with a winner.
let sortitions_incremented_by_1 =
sortition_sn.num_sortitions == stacks_parent_sn.num_sortitions + 1;
let last_sortition_ch = if sortitions_incremented_by_1 {
stacks_parent_sn.consensus_hash.clone()
} else {
// we actually need to perform the marf lookup
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 @@ -1123,6 +1123,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 @@ -1152,10 +1158,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
6 changes: 4 additions & 2 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8460,8 +8460,10 @@ fn mock_mining() {
let mock_mining_blocks_end = follower_naka_mined_blocks.load(Ordering::SeqCst);
let blocks_mock_mined = mock_mining_blocks_end - mock_mining_blocks_start;
assert!(
blocks_mock_mined > tenure_count,
"Should have mock mined at least `tenure_count` nakamoto blocks"
blocks_mock_mined >= tenure_count,
"Should have mock mined at least `tenure_count` nakamoto blocks. Mined = {}. Expected = {}",
blocks_mock_mined,
tenure_count,
);

// wait for follower to reach the chain tip
Expand Down

0 comments on commit c39ba88

Please sign in to comment.