Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/stacks-network/stacks-core
Browse files Browse the repository at this point in the history
… into fix/clippy-ci-stacks-lib-needless-borrow
  • Loading branch information
jferrant committed Jan 21, 2025
2 parents c439560 + 04f6fc4 commit 489aa27
Show file tree
Hide file tree
Showing 16 changed files with 2,069 additions and 409 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/bitcoin-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ jobs:
- tests::signer::v0::continue_after_tenure_extend
- tests::signer::v0::tenure_extend_after_idle_signers
- tests::signer::v0::tenure_extend_after_idle_miner
- tests::signer::v0::tenure_extend_after_failed_miner
- tests::signer::v0::tenure_extend_succeeds_after_rejected_attempt
- tests::signer::v0::stx_transfers_dont_effect_idle_timeout
- tests::signer::v0::idle_tenure_extend_active_mining
Expand All @@ -141,6 +142,9 @@ jobs:
- tests::signer::v0::incoming_signers_ignore_block_proposals
- tests::signer::v0::outgoing_signers_ignore_block_proposals
- tests::signer::v0::injected_signatures_are_ignored_across_boundaries
- tests::signer::v0::fast_sortition
- tests::signer::v0::single_miner_empty_sortition
- tests::signer::v0::multiple_miners_empty_sortition
- tests::signer::v0::block_proposal_timeout
- tests::signer::v0::rejected_blocks_count_towards_miner_validity
- tests::nakamoto_integrations::burn_ops_integration_test
Expand All @@ -162,6 +166,7 @@ jobs:
- tests::nakamoto_integrations::sip029_coinbase_change
- tests::nakamoto_integrations::clarity_cost_spend_down
- tests::nakamoto_integrations::v3_blockbyheight_api_endpoint
- tests::nakamoto_integrations::test_tenure_extend_from_flashblocks
# TODO: enable these once v1 signer is supported by a new nakamoto epoch
# - tests::signer::v1::dkg
# - tests::signer::v1::sign_request_rejected
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to the versioning scheme outlined in the [README.md](README.md).

## [Unreleased]

### Added

- The stacks-node miner now performs accurate tenure-extensions in certain bitcoin block production
cases: when a bitcoin block is produced before the previous bitcoin block's Stacks tenure started.
Previously, the miner had difficulty restarting their missed tenure and extending into the new
bitcoin block, leading to 1-2 bitcoin blocks of missed Stacks block production.

## [3.1.0.0.3]

### Added
Expand Down
6 changes: 6 additions & 0 deletions libstackerdb/src/libstackerdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ pub struct StackerDBChunkAckData {
pub code: Option<u32>,
}

impl fmt::Display for StackerDBChunkAckData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

impl SlotMetadata {
/// Make a new unsigned slot metadata
pub fn new_unsigned(
Expand Down
4 changes: 3 additions & 1 deletion stacks-signer/src/chainstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl SortitionsView {
info!(
"Current miner timed out, marking as invalid.";
"block_height" => block.header.chain_length,
"block_proposal_timeout" => ?self.config.block_proposal_timeout,
"current_sortition_consensus_hash" => ?self.cur_sortition.consensus_hash,
);
self.cur_sortition.miner_status = SortitionMinerStatus::InvalidatedBeforeFirstBlock;
Expand Down Expand Up @@ -320,7 +321,7 @@ impl SortitionsView {
return Ok(false);
}
}
ProposedBy::LastSortition(_last_sortition) => {
ProposedBy::LastSortition(last_sortition) => {
// should only consider blocks from the last sortition if the new sortition was invalidated
// before we signed their first block.
if self.cur_sortition.miner_status
Expand All @@ -331,6 +332,7 @@ impl SortitionsView {
"proposed_block_consensus_hash" => %block.header.consensus_hash,
"proposed_block_signer_sighash" => %block.header.signer_signature_hash(),
"current_sortition_miner_status" => ?self.cur_sortition.miner_status,
"last_sortition" => %last_sortition.consensus_hash
);
return Ok(false);
}
Expand Down
8 changes: 8 additions & 0 deletions stackslib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const DEFAULT_FIRST_REJECTION_PAUSE_MS: u64 = 5_000;
const DEFAULT_SUBSEQUENT_REJECTION_PAUSE_MS: u64 = 10_000;
const DEFAULT_BLOCK_COMMIT_DELAY_MS: u64 = 20_000;
const DEFAULT_TENURE_COST_LIMIT_PER_BLOCK_PERCENTAGE: u8 = 25;
const DEFAULT_TENURE_EXTEND_POLL_SECS: u64 = 1;

// This should be greater than the signers' timeout. This is used for issuing fallback tenure extends
const DEFAULT_TENURE_TIMEOUT_SECS: u64 = 420;

Expand Down Expand Up @@ -2149,6 +2151,9 @@ pub struct MinerConfig {
pub block_commit_delay: Duration,
/// The percentage of the remaining tenure cost limit to consume each block.
pub tenure_cost_limit_per_block_percentage: Option<u8>,
/// The number of seconds to wait in-between polling the sortition DB to see if we need to
/// extend the ongoing tenure (e.g. because the current sortition is empty or invalid).
pub tenure_extend_poll_secs: Duration,
/// Duration to wait before attempting to issue a tenure extend
pub tenure_timeout: Duration,
}
Expand Down Expand Up @@ -2187,6 +2192,7 @@ impl Default for MinerConfig {
tenure_cost_limit_per_block_percentage: Some(
DEFAULT_TENURE_COST_LIMIT_PER_BLOCK_PERCENTAGE,
),
tenure_extend_poll_secs: Duration::from_secs(DEFAULT_TENURE_EXTEND_POLL_SECS),
tenure_timeout: Duration::from_secs(DEFAULT_TENURE_TIMEOUT_SECS),
}
}
Expand Down Expand Up @@ -2582,6 +2588,7 @@ pub struct MinerConfigFile {
pub subsequent_rejection_pause_ms: Option<u64>,
pub block_commit_delay_ms: Option<u64>,
pub tenure_cost_limit_per_block_percentage: Option<u8>,
pub tenure_extend_poll_secs: Option<u64>,
pub tenure_timeout_secs: Option<u64>,
}

Expand Down Expand Up @@ -2723,6 +2730,7 @@ impl MinerConfigFile {
subsequent_rejection_pause_ms: self.subsequent_rejection_pause_ms.unwrap_or(miner_default_config.subsequent_rejection_pause_ms),
block_commit_delay: self.block_commit_delay_ms.map(Duration::from_millis).unwrap_or(miner_default_config.block_commit_delay),
tenure_cost_limit_per_block_percentage,
tenure_extend_poll_secs: self.tenure_extend_poll_secs.map(Duration::from_secs).unwrap_or(miner_default_config.tenure_extend_poll_secs),
tenure_timeout: self.tenure_timeout_secs.map(Duration::from_secs).unwrap_or(miner_default_config.tenure_timeout),
})
}
Expand Down
8 changes: 5 additions & 3 deletions stackslib/src/net/api/postblock_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,15 @@ impl BlockValidateResponse {
}

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

#[cfg(not(any(test, feature = "testing")))]
fn fault_injection_validation_delay() {}

/// Represents a block proposed to the `v3/block_proposal` endpoint for validation
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NakamotoBlockProposal {
Expand Down Expand Up @@ -389,8 +392,7 @@ impl NakamotoBlockProposal {
}
let start = Instant::now();

#[cfg(any(test, feature = "testing"))]
inject_validation_delay();
fault_injection_validation_delay();

let mainnet = self.chain_id == CHAIN_ID_MAINNET;
if self.chain_id != chainstate.chain_id || mainnet != chainstate.mainnet {
Expand Down
4 changes: 4 additions & 0 deletions testnet/stacks-node/src/nakamoto_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use stacks::burnchains::{BurnchainSigner, Txid};
use stacks::chainstate::burn::db::sortdb::SortitionDB;
use stacks::chainstate::burn::BlockSnapshot;
use stacks::chainstate::stacks::Error as ChainstateError;
use stacks::libstackerdb::StackerDBChunkAckData;
use stacks::monitoring;
use stacks::monitoring::update_active_miners_count_gauge;
use stacks::net::atlas::AtlasConfig;
Expand Down Expand Up @@ -130,6 +131,9 @@ pub enum Error {
/// An error occurred while operating as the signing coordinator
#[error("An error occurred while operating as the signing coordinator: {0}")]
SigningCoordinatorFailure(String),
/// An error occurred on StackerDB post
#[error("An error occurred while uploading data to StackerDB: {0}")]
StackerDBUploadError(StackerDBChunkAckData),
// The thread that we tried to send to has closed
#[error("The thread that we tried to send to has closed")]
ChannelClosed,
Expand Down
Loading

0 comments on commit 489aa27

Please sign in to comment.