Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: correct burn view for miner block broadcast #5515

Open
wants to merge 86 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
9f3f197
Merge branch 'hotfix/proposal-loads-sortition-view-from-block' into f…
jcnelson Nov 27, 2024
91d0f96
chore: use get_block_burn_view()
jcnelson Nov 27, 2024
b0ebc18
Merge branch 'develop' into fix/burn-view
jcnelson Dec 3, 2024
0d7fbfa
Merge branch 'develop' into fix/burn-view
jcnelson Dec 4, 2024
c9f72e4
chore: add new integration test
jcnelson Dec 5, 2024
8533269
chore: make `MinerReason` debug-printable, and factor out fault injec…
jcnelson Dec 5, 2024
2f16742
fix: consider the possibility that the miner can neither begin a new …
jcnelson Dec 5, 2024
3b81155
chore: track the number of miner directives
jcnelson Dec 5, 2024
08fa52a
chore: integration test to verify that a continue-tenure might not be…
jcnelson Dec 5, 2024
0996fb1
Merge branch 'develop' into fix/burn-view
jcnelson Dec 5, 2024
b110f66
chore: more fixes to differentiate the miner's burn view from the bur…
jcnelson Dec 5, 2024
2d93f24
Merge branch 'fix/burn-view' of https://github.com/stacks-network/sta…
jcnelson Dec 5, 2024
9b53d70
chore: more checks on burn view changes
jcnelson Dec 6, 2024
c8974b2
Merge branch 'feat/time-based-tenure-extend' into fix/burn-view
jcnelson Dec 7, 2024
8be6f90
Merge branch 'feat/time-based-tenure-extend' into fix/burn-view
jcnelson Dec 9, 2024
22a9815
Merge branch 'develop' into fix/burn-view
jcnelson Dec 9, 2024
4c9155b
Cargo fmt
jferrant Dec 10, 2024
eb62628
chore: record last sortition
jcnelson Dec 15, 2024
93cf523
chore: remove EmptyTenure miner reason, since it shouldn't ever be used
jcnelson Dec 15, 2024
a7a0b19
chore: factor logic for checking for a tenure-extend into a single fu…
jcnelson Dec 15, 2024
a2f010e
chore; drop needs_initial_block
jcnelson Dec 15, 2024
48e7468
test: finish check that the hotfix ensures that the correct burn view…
jcnelson Dec 15, 2024
f488b35
chore: delete old code
jcnelson Dec 15, 2024
73821ad
Merge branch 'fix/burn-view' of https://github.com/stacks-network/sta…
jcnelson Dec 15, 2024
818c064
Merge branch 'develop' into fix/burn-view
jcnelson Dec 16, 2024
06e2764
chore: clean up compile error and warnings
jcnelson Dec 16, 2024
fd28d81
Merge branch 'fix/burn-view' of https://github.com/stacks-network/sta…
jcnelson Dec 16, 2024
7abaaca
feat: tenure_extend_wait_secs: a config option to wait for a block-fo…
jcnelson Dec 20, 2024
06096ee
fix: allow a BlockFound to be produced if the Relayer determines that…
jcnelson Dec 20, 2024
7631f41
chore: fix choose_miner_directive() to attempt to continue a tenure i…
jcnelson Dec 20, 2024
0f7ada4
chore: fix tests
jcnelson Dec 20, 2024
6b18429
chore: expect a TenureExtend for a flash block
jcnelson Dec 20, 2024
1819f2a
Merge branch 'develop' into fix/burn-view
jcnelson Dec 20, 2024
f146ade
Merge branch 'develop' into fix/burn-view
jcnelson Jan 4, 2025
70833cd
refactor: use `TestFlag` for more flags
obycode Jan 9, 2025
6fe5d2d
fix: pause Stacks mining while mining blocks for miner eligibility
obycode Jan 9, 2025
911560c
test: add wait to ensure tip has advanced
obycode Jan 9, 2025
1c31090
test: add new test for tenure extend
obycode Jan 9, 2025
24193f8
Merge branch 'develop' into fix/burn-view
jcnelson Jan 13, 2025
9de3f84
fix: `won_sortition` calculation in relayer
obycode Jan 13, 2025
5590ec0
chore: get tenure_extend_after_failed_miner to pass
jcnelson Jan 13, 2025
45028e4
Merge branch 'fix/burn-view' of https://github.com/stacks-network/sta…
jcnelson Jan 13, 2025
27519c3
chore: expand test_tenure_extend_from_flashblocks to check that all b…
jcnelson Jan 13, 2025
17d6edc
fix: build issue; fix relayer to always start a new tenure if the cur…
jcnelson Jan 13, 2025
99d3eff
test: change VRF proof calculation to test a comment from @obycode
jcnelson Jan 13, 2025
49d5d65
Merge branch 'develop' into fix/burn-view
jcnelson Jan 14, 2025
262ee7d
chore: revert to LazyStatic
jcnelson Jan 14, 2025
792fcfc
Merge branch 'develop' into fix/burn-view
jcnelson Jan 14, 2025
62c9f13
chore: add docstrings, and (to test) disable the check_burn_view_chan…
jcnelson Jan 15, 2025
cc5e2fd
Merge branch 'develop' into fix/burn-view
jcnelson Jan 15, 2025
618c3a0
chore: cargo fmt
jcnelson Jan 15, 2025
fa823b1
test: disable check_burn_view_changed()
jcnelson Jan 15, 2025
a6a42cf
Merge branch 'develop' into fix/burn-view
jcnelson Jan 15, 2025
8e9303a
fix: remove compile warnings that prevent CI from running
jcnelson Jan 15, 2025
5c2cc18
Merge branch 'develop' into fix/burn-view
jcnelson Jan 15, 2025
b8622ae
chore: do not tenure-extend if the last valid sortition is higher tha…
jcnelson Jan 16, 2025
81ce1ca
Merge branch 'fix/burn-view' of https://github.com/stacks-network/sta…
jcnelson Jan 16, 2025
8b4c3d6
Merge branch 'develop' into fix/burn-view
jcnelson Jan 16, 2025
273156e
test: add simple `fast_sortition` test
obycode Jan 16, 2025
1cfc225
test: add signer set test for a flash block with miner changeover
kantai Jan 16, 2025
0abb85a
fix: explicit burnchain checks in miner thread
kantai Jan 16, 2025
65c2eb3
address PR review
kantai Jan 16, 2025
137dcf0
exit miner thread behavior for late blockfound tenures, add tests to CI
kantai Jan 16, 2025
2f675a4
chore: attempt a fix at continue_tenure_extend, but it will need some…
jcnelson Jan 16, 2025
aacd4d3
Merge branch 'fix/burn-view' of https://github.com/stacks-network/sta…
jcnelson Jan 16, 2025
11001c8
chore: cargo fmt
jcnelson Jan 17, 2025
47ec2d4
add comment for closing late blockfound tenure
kantai Jan 17, 2025
c49c853
Merge remote-tracking branch 'origin/fix/burn-view' into feat/burn-vi…
kantai Jan 17, 2025
48567ed
chore: cleanup
jcnelson Jan 17, 2025
e1547e9
Merge remote-tracking branch 'origin/fix/burn-view' into feat/burn-vi…
kantai Jan 17, 2025
02ac7d4
test: add a necessary wait condition to the continue_tenure_extend test
kantai Jan 17, 2025
abbbe54
cargo fmt
kantai Jan 17, 2025
7ad5743
Merge pull request #5717 from stacks-network/feat/burn-view-fix-burn-…
kantai Jan 17, 2025
fa0d9ac
chore: address PR feedback
jcnelson Jan 17, 2025
26cedd7
Merge branch 'fix/burn-view' of https://github.com/stacks-network/sta…
jcnelson Jan 17, 2025
275f1e2
chore: address more PR feedback
jcnelson Jan 17, 2025
dd80215
Merge branch 'develop' into fix/burn-view
jcnelson Jan 17, 2025
dc50cfb
Merge branch 'develop' into fix/burn-view
jcnelson Jan 17, 2025
51b239a
Merge branch 'develop' into fix/burn-view
jcnelson Jan 17, 2025
016d4e9
Merge branch 'develop' into fix/burn-view
kantai Jan 18, 2025
3107f61
Merge remote-tracking branch 'origin/develop' into fix/burn-view
kantai Jan 18, 2025
2c007c2
revert my own suggestion
kantai Jan 18, 2025
ddc1eca
Merge remote-tracking branch 'origin/develop' into fix/burn-view
kantai Jan 18, 2025
9970130
chore: address more PR feedback; revert can_continue_tenure() check i…
jcnelson Jan 18, 2025
e248b68
Merge branch 'fix/burn-view' of https://github.com/stacks-network/sta…
jcnelson Jan 18, 2025
94016bd
fix: remove unused variable
jcnelson Jan 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading