Skip to content

Commit 02f3d01

Browse files
committed
Add tenure_timeout_secs to miner config to self-issue tenure extends
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent b3b7117 commit 02f3d01

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

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

1010
### Added
11+
- Add `tenure_timeout_secs` to the miner for determining when a time-based tenure extend should be attempted.
1112

1213
### Changed
1314

testnet/stacks-node/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ const DEFAULT_FIRST_REJECTION_PAUSE_MS: u64 = 5_000;
9393
const DEFAULT_SUBSEQUENT_REJECTION_PAUSE_MS: u64 = 10_000;
9494
const DEFAULT_BLOCK_COMMIT_DELAY_MS: u64 = 20_000;
9595
const DEFAULT_TENURE_COST_LIMIT_PER_BLOCK_PERCENTAGE: u8 = 25;
96+
// This should be greater than the signers' timeout. This is used for issuing fallback tenure extends
97+
const DEFAULT_TENURE_TIMEOUT_SECS: u64 = 420;
9698

9799
#[derive(Clone, Deserialize, Default, Debug)]
98100
#[serde(deny_unknown_fields)]
@@ -2145,6 +2147,8 @@ pub struct MinerConfig {
21452147
pub block_commit_delay: Duration,
21462148
/// The percentage of the remaining tenure cost limit to consume each block.
21472149
pub tenure_cost_limit_per_block_percentage: Option<u8>,
2150+
/// Duration to wait before attempting to issue a tenure extend
2151+
pub tenure_timeout: Duration,
21482152
}
21492153

21502154
impl Default for MinerConfig {
@@ -2181,6 +2185,7 @@ impl Default for MinerConfig {
21812185
tenure_cost_limit_per_block_percentage: Some(
21822186
DEFAULT_TENURE_COST_LIMIT_PER_BLOCK_PERCENTAGE,
21832187
),
2188+
tenure_timeout: Duration::from_secs(DEFAULT_TENURE_TIMEOUT_SECS),
21842189
}
21852190
}
21862191
}
@@ -2566,6 +2571,7 @@ pub struct MinerConfigFile {
25662571
pub subsequent_rejection_pause_ms: Option<u64>,
25672572
pub block_commit_delay_ms: Option<u64>,
25682573
pub tenure_cost_limit_per_block_percentage: Option<u8>,
2574+
pub tenure_timeout_secs: Option<u64>,
25692575
}
25702576

25712577
impl MinerConfigFile {
@@ -2706,6 +2712,7 @@ impl MinerConfigFile {
27062712
subsequent_rejection_pause_ms: self.subsequent_rejection_pause_ms.unwrap_or(miner_default_config.subsequent_rejection_pause_ms),
27072713
block_commit_delay: self.block_commit_delay_ms.map(Duration::from_millis).unwrap_or(miner_default_config.block_commit_delay),
27082714
tenure_cost_limit_per_block_percentage,
2715+
tenure_timeout: self.tenure_timeout_secs.map(Duration::from_secs).unwrap_or(miner_default_config.tenure_timeout),
27092716
})
27102717
}
27112718
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ pub struct BlockMinerThread {
160160
/// Handle to the p2p thread for block broadcast
161161
p2p_handle: NetworkHandle,
162162
signer_set_cache: Option<RewardSet>,
163+
/// The time at which tenure change was issued
164+
tenure_change_time: Instant,
163165
}
164166

165167
impl BlockMinerThread {
@@ -187,6 +189,7 @@ impl BlockMinerThread {
187189
reason,
188190
p2p_handle: rt.get_p2p_handle(),
189191
signer_set_cache: None,
192+
tenure_change_time: Instant::now(),
190193
}
191194
}
192195

@@ -1186,7 +1189,9 @@ impl BlockMinerThread {
11861189
if self.last_block_mined.is_some() {
11871190
// Check if we can extend the current tenure
11881191
let tenure_extend_timestamp = coordinator.get_tenure_extend_timestamp();
1189-
if get_epoch_time_secs() <= tenure_extend_timestamp {
1192+
if get_epoch_time_secs() <= tenure_extend_timestamp
1193+
&& self.tenure_change_time.elapsed() <= self.config.miner.tenure_timeout
1194+
{
11901195
return Ok(NakamotoTenureInfo {
11911196
coinbase_tx: None,
11921197
tenure_change_tx: None,
@@ -1195,6 +1200,8 @@ impl BlockMinerThread {
11951200
info!("Miner: Time-based tenure extend";
11961201
"current_timestamp" => get_epoch_time_secs(),
11971202
"tenure_extend_timestamp" => tenure_extend_timestamp,
1203+
"tenure_change_time_elapsed" => self.tenure_change_time.elapsed().as_secs(),
1204+
"tenure_timeout_secs" => self.config.miner.tenure_timeout.as_secs(),
11981205
);
11991206
self.tenure_extend_reset();
12001207
}
@@ -1265,6 +1272,7 @@ impl BlockMinerThread {
12651272
}
12661273

12671274
fn tenure_extend_reset(&mut self) {
1275+
self.tenure_change_time = Instant::now();
12681276
self.reason = MinerReason::Extended {
12691277
burn_view_consensus_hash: self.burn_block.consensus_hash,
12701278
};

0 commit comments

Comments
 (0)