Skip to content

Commit 489aa27

Browse files
committed
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into fix/clippy-ci-stacks-lib-needless-borrow
2 parents c439560 + 04f6fc4 commit 489aa27

File tree

16 files changed

+2069
-409
lines changed

16 files changed

+2069
-409
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ jobs:
125125
- tests::signer::v0::continue_after_tenure_extend
126126
- tests::signer::v0::tenure_extend_after_idle_signers
127127
- tests::signer::v0::tenure_extend_after_idle_miner
128+
- tests::signer::v0::tenure_extend_after_failed_miner
128129
- tests::signer::v0::tenure_extend_succeeds_after_rejected_attempt
129130
- tests::signer::v0::stx_transfers_dont_effect_idle_timeout
130131
- tests::signer::v0::idle_tenure_extend_active_mining
@@ -141,6 +142,9 @@ jobs:
141142
- tests::signer::v0::incoming_signers_ignore_block_proposals
142143
- tests::signer::v0::outgoing_signers_ignore_block_proposals
143144
- tests::signer::v0::injected_signatures_are_ignored_across_boundaries
145+
- tests::signer::v0::fast_sortition
146+
- tests::signer::v0::single_miner_empty_sortition
147+
- tests::signer::v0::multiple_miners_empty_sortition
144148
- tests::signer::v0::block_proposal_timeout
145149
- tests::signer::v0::rejected_blocks_count_towards_miner_validity
146150
- tests::nakamoto_integrations::burn_ops_integration_test
@@ -162,6 +166,7 @@ jobs:
162166
- tests::nakamoto_integrations::sip029_coinbase_change
163167
- tests::nakamoto_integrations::clarity_cost_spend_down
164168
- tests::nakamoto_integrations::v3_blockbyheight_api_endpoint
169+
- tests::nakamoto_integrations::test_tenure_extend_from_flashblocks
165170
# TODO: enable these once v1 signer is supported by a new nakamoto epoch
166171
# - tests::signer::v1::dkg
167172
# - tests::signer::v1::sign_request_rejected

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to the versioning scheme outlined in the [README.md](README.md).
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
- The stacks-node miner now performs accurate tenure-extensions in certain bitcoin block production
13+
cases: when a bitcoin block is produced before the previous bitcoin block's Stacks tenure started.
14+
Previously, the miner had difficulty restarting their missed tenure and extending into the new
15+
bitcoin block, leading to 1-2 bitcoin blocks of missed Stacks block production.
16+
817
## [3.1.0.0.3]
918

1019
### Added

libstackerdb/src/libstackerdb.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ pub struct StackerDBChunkAckData {
135135
pub code: Option<u32>,
136136
}
137137

138+
impl fmt::Display for StackerDBChunkAckData {
139+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140+
write!(f, "{:?}", self)
141+
}
142+
}
143+
138144
impl SlotMetadata {
139145
/// Make a new unsigned slot metadata
140146
pub fn new_unsigned(

stacks-signer/src/chainstate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ impl SortitionsView {
200200
info!(
201201
"Current miner timed out, marking as invalid.";
202202
"block_height" => block.header.chain_length,
203+
"block_proposal_timeout" => ?self.config.block_proposal_timeout,
203204
"current_sortition_consensus_hash" => ?self.cur_sortition.consensus_hash,
204205
);
205206
self.cur_sortition.miner_status = SortitionMinerStatus::InvalidatedBeforeFirstBlock;
@@ -320,7 +321,7 @@ impl SortitionsView {
320321
return Ok(false);
321322
}
322323
}
323-
ProposedBy::LastSortition(_last_sortition) => {
324+
ProposedBy::LastSortition(last_sortition) => {
324325
// should only consider blocks from the last sortition if the new sortition was invalidated
325326
// before we signed their first block.
326327
if self.cur_sortition.miner_status
@@ -331,6 +332,7 @@ impl SortitionsView {
331332
"proposed_block_consensus_hash" => %block.header.consensus_hash,
332333
"proposed_block_signer_sighash" => %block.header.signer_signature_hash(),
333334
"current_sortition_miner_status" => ?self.cur_sortition.miner_status,
335+
"last_sortition" => %last_sortition.consensus_hash
334336
);
335337
return Ok(false);
336338
}

stackslib/src/config/mod.rs

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

@@ -2149,6 +2151,9 @@ pub struct MinerConfig {
21492151
pub block_commit_delay: Duration,
21502152
/// The percentage of the remaining tenure cost limit to consume each block.
21512153
pub tenure_cost_limit_per_block_percentage: Option<u8>,
2154+
/// The number of seconds to wait in-between polling the sortition DB to see if we need to
2155+
/// extend the ongoing tenure (e.g. because the current sortition is empty or invalid).
2156+
pub tenure_extend_poll_secs: Duration,
21522157
/// Duration to wait before attempting to issue a tenure extend
21532158
pub tenure_timeout: Duration,
21542159
}
@@ -2187,6 +2192,7 @@ impl Default for MinerConfig {
21872192
tenure_cost_limit_per_block_percentage: Some(
21882193
DEFAULT_TENURE_COST_LIMIT_PER_BLOCK_PERCENTAGE,
21892194
),
2195+
tenure_extend_poll_secs: Duration::from_secs(DEFAULT_TENURE_EXTEND_POLL_SECS),
21902196
tenure_timeout: Duration::from_secs(DEFAULT_TENURE_TIMEOUT_SECS),
21912197
}
21922198
}
@@ -2582,6 +2588,7 @@ pub struct MinerConfigFile {
25822588
pub subsequent_rejection_pause_ms: Option<u64>,
25832589
pub block_commit_delay_ms: Option<u64>,
25842590
pub tenure_cost_limit_per_block_percentage: Option<u8>,
2591+
pub tenure_extend_poll_secs: Option<u64>,
25852592
pub tenure_timeout_secs: Option<u64>,
25862593
}
25872594

@@ -2723,6 +2730,7 @@ impl MinerConfigFile {
27232730
subsequent_rejection_pause_ms: self.subsequent_rejection_pause_ms.unwrap_or(miner_default_config.subsequent_rejection_pause_ms),
27242731
block_commit_delay: self.block_commit_delay_ms.map(Duration::from_millis).unwrap_or(miner_default_config.block_commit_delay),
27252732
tenure_cost_limit_per_block_percentage,
2733+
tenure_extend_poll_secs: self.tenure_extend_poll_secs.map(Duration::from_secs).unwrap_or(miner_default_config.tenure_extend_poll_secs),
27262734
tenure_timeout: self.tenure_timeout_secs.map(Duration::from_secs).unwrap_or(miner_default_config.tenure_timeout),
27272735
})
27282736
}

stackslib/src/net/api/postblock_proposal.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,15 @@ impl BlockValidateResponse {
190190
}
191191

192192
#[cfg(any(test, feature = "testing"))]
193-
fn inject_validation_delay() {
193+
fn fault_injection_validation_delay() {
194194
let delay = TEST_VALIDATE_DELAY_DURATION_SECS.get();
195195
warn!("Sleeping for {} seconds to simulate slow processing", delay);
196196
thread::sleep(Duration::from_secs(delay));
197197
}
198198

199+
#[cfg(not(any(test, feature = "testing")))]
200+
fn fault_injection_validation_delay() {}
201+
199202
/// Represents a block proposed to the `v3/block_proposal` endpoint for validation
200203
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
201204
pub struct NakamotoBlockProposal {
@@ -389,8 +392,7 @@ impl NakamotoBlockProposal {
389392
}
390393
let start = Instant::now();
391394

392-
#[cfg(any(test, feature = "testing"))]
393-
inject_validation_delay();
395+
fault_injection_validation_delay();
394396

395397
let mainnet = self.chain_id == CHAIN_ID_MAINNET;
396398
if self.chain_id != chainstate.chain_id || mainnet != chainstate.mainnet {

testnet/stacks-node/src/nakamoto_node.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use stacks::burnchains::{BurnchainSigner, Txid};
2323
use stacks::chainstate::burn::db::sortdb::SortitionDB;
2424
use stacks::chainstate::burn::BlockSnapshot;
2525
use stacks::chainstate::stacks::Error as ChainstateError;
26+
use stacks::libstackerdb::StackerDBChunkAckData;
2627
use stacks::monitoring;
2728
use stacks::monitoring::update_active_miners_count_gauge;
2829
use stacks::net::atlas::AtlasConfig;
@@ -130,6 +131,9 @@ pub enum Error {
130131
/// An error occurred while operating as the signing coordinator
131132
#[error("An error occurred while operating as the signing coordinator: {0}")]
132133
SigningCoordinatorFailure(String),
134+
/// An error occurred on StackerDB post
135+
#[error("An error occurred while uploading data to StackerDB: {0}")]
136+
StackerDBUploadError(StackerDBChunkAckData),
133137
// The thread that we tried to send to has closed
134138
#[error("The thread that we tried to send to has closed")]
135139
ChannelClosed,

0 commit comments

Comments
 (0)