Skip to content

Commit 4d1f9a9

Browse files
committed
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into chore/fix-multiple-miners
2 parents 836a97a + c39ba88 commit 4d1f9a9

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

stackslib/src/net/api/getsortition.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ impl GetSortitionHandler {
182182
// try to figure out what the last snapshot in this fork was with a successful
183183
// sortition.
184184
// optimization heuristic: short-circuit the load if its just `stacks_parent_sn`
185-
let last_sortition_ch = if stacks_parent_sn.sortition {
185+
// if the sortition count incremented by exactly 1 between us and our **stacks** parent,
186+
// then the stacks parent's sortition *must* be the last one with a winner.
187+
let sortitions_incremented_by_1 =
188+
sortition_sn.num_sortitions == stacks_parent_sn.num_sortitions + 1;
189+
let last_sortition_ch = if sortitions_incremented_by_1 {
186190
stacks_parent_sn.consensus_hash.clone()
187191
} else {
188192
// we actually need to perform the marf lookup

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,12 @@ impl BlockMinerThread {
11231123
tenure_change_tx: None,
11241124
});
11251125
};
1126+
if self.last_block_mined.is_some() {
1127+
return Ok(NakamotoTenureInfo {
1128+
coinbase_tx: None,
1129+
tenure_change_tx: None,
1130+
});
1131+
}
11261132

11271133
let parent_block_id = parent_block_info.stacks_parent_header.index_block_hash();
11281134
let mut payload = TenureChangePayload {
@@ -1152,10 +1158,10 @@ impl BlockMinerThread {
11521158
&parent_block_id,
11531159
)
11541160
.map_err(NakamotoNodeError::MiningFailure)?;
1155-
debug!("Miner: Extending tenure";
1156-
"burn_view_consensus_hash" => %burn_view_consensus_hash,
1157-
"parent_block_id" => %parent_block_id,
1158-
"num_blocks_so_far" => num_blocks_so_far,
1161+
info!("Miner: Extending tenure";
1162+
"burn_view_consensus_hash" => %burn_view_consensus_hash,
1163+
"parent_block_id" => %parent_block_id,
1164+
"num_blocks_so_far" => num_blocks_so_far,
11591165
);
11601166
payload = payload.extend(
11611167
*burn_view_consensus_hash,

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8461,8 +8461,10 @@ fn mock_mining() {
84618461
let mock_mining_blocks_end = follower_naka_mined_blocks.load(Ordering::SeqCst);
84628462
let blocks_mock_mined = mock_mining_blocks_end - mock_mining_blocks_start;
84638463
assert!(
8464-
blocks_mock_mined > tenure_count,
8465-
"Should have mock mined at least `tenure_count` nakamoto blocks"
8464+
blocks_mock_mined >= tenure_count,
8465+
"Should have mock mined at least `tenure_count` nakamoto blocks. Mined = {}. Expected = {}",
8466+
blocks_mock_mined,
8467+
tenure_count,
84668468
);
84678469

84688470
// wait for follower to reach the chain tip

0 commit comments

Comments
 (0)