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

Crescendo hardfork transitioning #633

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
121d7b7
deactivate tn11
michaelsutton Feb 6, 2025
2c7a2ca
wip fork params
michaelsutton Feb 7, 2025
aad0788
wip fork params (2)
michaelsutton Feb 9, 2025
d3e8d85
we are not forking the timestamp deviation tolerance param
michaelsutton Feb 9, 2025
f592f3b
min difficulty len can be defined only once
michaelsutton Feb 10, 2025
58a5920
forked param
michaelsutton Feb 10, 2025
cf29cab
use only a single (crescendo) activation flag. fix tx related activat…
michaelsutton Feb 10, 2025
070eb50
rename _len -> _size for consistency
michaelsutton Feb 10, 2025
da490e3
wip bps forking
michaelsutton Feb 10, 2025
b0d316f
wip bps forking: filter non activated blocks from DAA window
michaelsutton Feb 10, 2025
82881f2
bps forking logic
michaelsutton Feb 10, 2025
72039c3
fix gated feature tests
michaelsutton Feb 11, 2025
9524dc4
media time window should exclude non activated blocks as well
michaelsutton Feb 11, 2025
39f14f1
unused
michaelsutton Feb 11, 2025
273d9de
ghostdag k forking logic
michaelsutton Feb 12, 2025
e817f3c
coinbase reward forking logic
michaelsutton Feb 12, 2025
d1eb348
parents and mergeset size limits forking logic
michaelsutton Feb 16, 2025
8aea539
merge depth and finality depth forking logic
michaelsutton Feb 16, 2025
bdd2c78
pruning point forking logic
michaelsutton Feb 17, 2025
49fdcdc
fix doc test
michaelsutton Feb 17, 2025
e3d386a
various todos and leftovers
michaelsutton Feb 18, 2025
8257064
mempool-related forking logic, more todos
michaelsutton Feb 19, 2025
02f71c5
KIP-13 (part of crescendo) (#639)
michaelsutton Feb 19, 2025
ace9b8f
ghostdag: comments; extract var and reuse; handle origin edge case
michaelsutton Feb 20, 2025
3427aa1
permanent -> persistent
michaelsutton Feb 20, 2025
487b794
use bool -> option -> iter and remove code duplication
michaelsutton Feb 20, 2025
7efd014
coinbase misc
michaelsutton Feb 20, 2025
e96f232
header misc
michaelsutton Feb 20, 2025
d614b5d
comments
michaelsutton Feb 21, 2025
1d8e3b9
log the hardfork (initial)
michaelsutton Feb 21, 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
23 changes: 10 additions & 13 deletions consensus/core/src/config/bps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub fn calculate_ghostdag_k(x: f64, delta: f64) -> u64 {
}
}

/// Bps-related constants generator for testnet 11
pub type Testnet11Bps = Bps<10>;
/// Bps-related constants generator for 10-bps networks
pub type TenBps = Bps<10>;

/// Struct representing network blocks-per-second. Provides a bunch of const functions
/// computing various constants which are functions of the BPS value
Expand Down Expand Up @@ -93,24 +93,21 @@ impl<const BPS: u64> Bps<BPS> {
BPS * NEW_FINALITY_DURATION
}

/// Limit used to previously calculate the pruning depth.
const fn prev_mergeset_size_limit() -> u64 {
Self::ghostdag_k() as u64 * 10
}

pub const fn pruning_depth() -> u64 {
// Based on the analysis at https://github.com/kaspanet/docs/blob/main/Reference/prunality/Prunality.pdf
// and on the decomposition of merge depth (rule R-I therein) from finality depth (φ)
// We add an additional merge depth unit as a safety margin for anticone finalization
Self::finality_depth()
let lower_bound = Self::finality_depth()
+ Self::merge_depth_bound() * 2
+ 4 * Self::prev_mergeset_size_limit() * Self::ghostdag_k() as u64
+ 4 * Self::mergeset_size_limit() * Self::ghostdag_k() as u64
+ 2 * Self::ghostdag_k() as u64
+ 2
+ 2;

// TODO (HF or restart of TN11):
// Return `Self::finality_depth() * 3` and assert that this value is equal or larger than the above expression.
// This will give us a round easy number to track which is not sensitive to minor changes in other related params.
if lower_bound > BPS * NEW_PRUNING_DURATION {
lower_bound
} else {
BPS * NEW_PRUNING_DURATION
}
}

pub const fn pruning_proof_m() -> u64 {
Expand Down
28 changes: 14 additions & 14 deletions consensus/core/src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@ pub mod consensus {
// ~~~~~~~~~~~~~~~~~~ Timestamp deviation & Median time ~~~~~~~~~~~~~~~~~~
//

/// **Legacy** timestamp deviation tolerance (seconds)
pub const LEGACY_TIMESTAMP_DEVIATION_TOLERANCE: u64 = 132;

/// **New** timestamp deviation tolerance (seconds).
/// TODO: KIP-0004: 605 (~10 minutes)
pub const NEW_TIMESTAMP_DEVIATION_TOLERANCE: u64 = 132;
/// Timestamp deviation tolerance (seconds)
pub const TIMESTAMP_DEVIATION_TOLERANCE: u64 = 132;

/// The desired interval between samples of the median time window (seconds).
/// KIP-0004: 10 seconds
pub const PAST_MEDIAN_TIME_SAMPLE_INTERVAL: u64 = 10;

/// Size of the **sampled** median time window (independent of BPS)
pub const MEDIAN_TIME_SAMPLED_WINDOW_SIZE: u64 =
(2 * NEW_TIMESTAMP_DEVIATION_TOLERANCE - 1).div_ceil(PAST_MEDIAN_TIME_SAMPLE_INTERVAL);
(2 * TIMESTAMP_DEVIATION_TOLERANCE - 1).div_ceil(PAST_MEDIAN_TIME_SAMPLE_INTERVAL);

//
// ~~~~~~~~~~~~~~~~~~~~~~~~~ Max difficulty target ~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -56,18 +51,21 @@ pub mod consensus {
// ~~~~~~~~~~~~~~~~~~~ Difficulty Adjustment Algorithm (DAA) ~~~~~~~~~~~~~~~~~~~
//

/// Minimal size of the difficulty window. Affects the DA algorithm only at the starting period of a new net
pub const MIN_DIFFICULTY_WINDOW_LEN: usize = 10;
/// Minimal size of the difficulty window. Affects the DA algorithm at the starting period of a new net.
/// Also used during BPS fork transitions to stabilize the new rate before applying DA (see KIP-14).
/// With 4 seconds sampling interval, a value of 150 indicates 10 minutes of fixed
/// difficulty until the window grows large enough.
///
/// TODO (crescendo): finalize
pub const MIN_DIFFICULTY_WINDOW_SIZE: usize = 150;

/// **Legacy** difficulty adjustment window size corresponding to ~44 minutes with 1 BPS
pub const LEGACY_DIFFICULTY_WINDOW_SIZE: usize = 2641;

/// **New** difficulty window duration expressed in time units (seconds).
/// TODO: KIP-0004: 30,000 (500 minutes)
pub const NEW_DIFFICULTY_WINDOW_DURATION: u64 = 2641;

/// The desired interval between samples of the difficulty window (seconds).
/// TODO: KIP-0004: 30 seconds
pub const DIFFICULTY_WINDOW_SAMPLE_INTERVAL: u64 = 4;

/// Size of the **sampled** difficulty window (independent of BPS)
Expand All @@ -81,9 +79,11 @@ pub mod consensus {
pub const LEGACY_FINALITY_DEPTH: u64 = 86_400;

/// **New** finality duration expressed in time units (seconds).
/// TODO: finalize this value (consider 6-24 hours)
pub const NEW_FINALITY_DURATION: u64 = 43_200; // 12 hours

/// **New** pruning duration expressed in time units (seconds).
pub const NEW_PRUNING_DURATION: u64 = 108_000; // 30 hours

/// Merge depth bound duration (in seconds). For 1 BPS networks this equals the legacy depth
/// bound in block units. For higher BPS networks this should be scaled up.
///
Expand Down Expand Up @@ -166,7 +166,7 @@ pub mod perf {
impl PerfParams {
pub fn adjust_to_consensus_params(&mut self, consensus_params: &Params) {
// Allow caching up to 10x over the baseline
self.block_data_cache_size *= consensus_params.bps().clamp(1, 10) as usize;
self.block_data_cache_size *= consensus_params.bps().upper_bound().clamp(1, 10) as usize;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/core/src/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub const DEVNET_GENESIS: GenesisBlock = GenesisBlock {
#[cfg(test)]
mod tests {
use super::*;
use crate::{config::bps::Testnet11Bps, merkle::calc_hash_merkle_root};
use crate::{config::bps::TenBps, merkle::calc_hash_merkle_root};

#[test]
fn test_genesis_hashes() {
Expand All @@ -238,7 +238,7 @@ mod tests {

#[test]
fn gen_testnet11_genesis() {
let bps = Testnet11Bps::bps();
let bps = TenBps::bps();
let mut genesis = TESTNET_GENESIS;
let target = kaspa_math::Uint256::from_compact_target_bits(genesis.bits);
let scaled_target = target * bps / 100;
Expand Down
Loading