Skip to content

Commit 5014093

Browse files
committed
Make miner attempt to issue a tenure extend if it does not see the incoming miner produce a block
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent d2ed454 commit 5014093

File tree

4 files changed

+503
-15
lines changed

4 files changed

+503
-15
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ jobs:
150150
- tests::signer::v0::block_proposal_timeout
151151
- tests::signer::v0::rejected_blocks_count_towards_miner_validity
152152
- tests::signer::v0::allow_reorg_within_first_proposal_burn_block_timing_secs
153+
- tests::signer::v0::prev_miner_extends_if_incoming_miner_fails_to_mine
153154
- tests::nakamoto_integrations::burn_ops_integration_test
154155
- tests::nakamoto_integrations::check_block_heights
155156
- tests::nakamoto_integrations::clarity_burn_state

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1515

1616
- Miner will include other transactions in blocks with tenure extend transactions (#5760)
1717
- Miner will not issue a tenure extend until at least half of the block budget has been spent (#5757)
18+
- Miner will issue a tenure extend if the incoming miner has failed to produce a block (#5729)
1819

1920
### Fixed
2021

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,10 +1348,10 @@ impl RelayerThread {
13481348
/// Assumes that the caller has already checked that the given miner has _not_ won the new
13491349
/// sortition.
13501350
///
1351-
/// Returns Ok(Some(stacks-tip-election-snapshot)) if the last-winning miner needs to extend.
1352-
/// For now, this only happens if the miner's election snapshot was the last-known valid and
1353-
/// non-empty snapshot. In the future, this function may return Ok(Some(..)) if the node
1354-
/// determines that a subsequent miner won sortition, but never came online.
1351+
/// Returns Ok(Some(stacks-tip-election-snapshot)) if the last-winning miner should attempt to extend.
1352+
/// This can happen for two seperate reasons:
1353+
/// - the miner's election snapshot was the last-known valid and non-empty snapshot
1354+
/// - the node determines that a subsequent miner won sortition, but has not yet produced a valid block.
13551355
///
13561356
/// Returns OK(None) if the last-winning miner should not extend its tenure.
13571357
///
@@ -1407,20 +1407,21 @@ impl RelayerThread {
14071407
return Ok(None);
14081408
}
14091409

1410-
// For now, only allow the miner to extend its tenure if won the highest valid sortition.
1410+
// Allow the miner to extend its tenure if won the highest valid sortition.
14111411
// There cannot be any higher sortitions that are valid (as defined above).
1412-
//
1413-
// In the future, the miner will be able to extend its tenure even if there are higher
1414-
// valid sortitions, but only if it determines that the miners of those sortitions are
1415-
// offline.
14161412
if let Some(highest_valid_sortition) = Self::find_highest_valid_sortition(
14171413
sortdb,
14181414
chain_state,
14191415
&sort_tip,
14201416
&canonical_stacks_snapshot.consensus_hash,
14211417
)? {
1422-
info!("Relayer: will not extend tenure -- we won sortition {}, but the highest valid sortition is {}", &canonical_stacks_snapshot.consensus_hash, &highest_valid_sortition.consensus_hash);
1423-
return Ok(None);
1418+
// The miner will be able to extend its tenure even if there are higher
1419+
// valid sortitions, but IFF it determines that the miners of the sortition
1420+
// has yet to produce a valid block.
1421+
if canonical_stacks_snapshot.consensus_hash == highest_valid_sortition.consensus_hash {
1422+
info!("Relayer: will not extend tenure -- we won sortition {}, but the highest valid sortition is {} and has already produced a valid Stacks block.", &canonical_stacks_snapshot.consensus_hash, &highest_valid_sortition.consensus_hash);
1423+
return Ok(None);
1424+
}
14241425
}
14251426

14261427
Ok(Some(canonical_stacks_snapshot))
@@ -1431,7 +1432,8 @@ impl RelayerThread {
14311432
/// elected the local view of the canonical Stacks fork's ongoing tenure.
14321433
///
14331434
/// This function assumes that the caller has checked that the sortition referred to by
1434-
/// `new_burn_view` does not have a sortition winner.
1435+
/// `new_burn_view` does not have a sortition winner or that the winner has not produced a
1436+
/// valid block yet.
14351437
fn continue_tenure(&mut self, new_burn_view: ConsensusHash) -> Result<(), NakamotoNodeError> {
14361438
if let Err(e) = self.stop_tenure() {
14371439
error!("Relayer: Failed to stop tenure: {e:?}");
@@ -1758,9 +1760,9 @@ impl RelayerThread {
17581760
}
17591761

17601762
/// Try to start up a tenure-extend.
1761-
/// Only do this if the miner won the highest valid sortition but the burn view has changed.
1762-
/// In the future, the miner will also try to extend its tenure if a subsequent miner appears
1763-
/// to be offline.
1763+
/// Only do this if:
1764+
/// - the miner won the highest valid sortition but the burn view has changed.
1765+
/// - the subsequent miner appears to be offline.
17641766
fn try_continue_tenure(&mut self) {
17651767
if self.tenure_extend_timeout.is_none() {
17661768
return;

0 commit comments

Comments
 (0)