Skip to content

Commit d313489

Browse files
Testnet-11 final adjustments (#214)
* just a minor unavoidable refactor * lim rothschild rates * finalize merge depth bound constant * mildly reduce cache sizes * finalize pruning depth * finalize daa constants
1 parent cca338f commit d313489

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

consensus/core/src/config/bps.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ impl<const BPS: u64> Bps<BPS> {
6868
}
6969

7070
pub const fn merge_depth_bound() -> u64 {
71-
// Merge depth bound needs to be upper-bounded by DAA window *block duration* in order to prevent merging
72-
// low-difficulty side-chains. TODO: finalize and decide if to make it lower
73-
BPS * NEW_DIFFICULTY_WINDOW_DURATION
71+
BPS * MERGE_DEPTH_DURATION
7472
}
7573

7674
pub const fn finality_depth() -> u64 {
@@ -79,9 +77,13 @@ impl<const BPS: u64> Bps<BPS> {
7977

8078
pub const fn pruning_depth() -> u64 {
8179
// Based on the analysis at https://github.com/kaspanet/docs/blob/main/Reference/prunality/Prunality.pdf
82-
// TODO: note that `Self::merge_depth_bound()` can replace one `Self::finality_depth()` unit, but for now we keep
83-
// this calculation identical to the legacy calculation
84-
Self::finality_depth() * 2 + 4 * Self::mergeset_size_limit() * Self::ghostdag_k() as u64 + 2 * Self::ghostdag_k() as u64 + 2
80+
// and on the decomposition of merge depth (rule R-I therein) from finality depth (φ)
81+
// We add an additional merge depth unit as a safety margin for anticone finalization
82+
Self::finality_depth()
83+
+ Self::merge_depth_bound() * 2
84+
+ 4 * Self::mergeset_size_limit() * Self::ghostdag_k() as u64
85+
+ 2 * Self::ghostdag_k() as u64
86+
+ 2
8587
}
8688

8789
pub const fn pruning_proof_m() -> u64 {

consensus/core/src/config/constants.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,22 @@ pub mod consensus {
5757
//
5858

5959
/// Minimal size of the difficulty window. Affects the DA algorithm only at the starting period of a new net
60-
pub const MIN_DIFFICULTY_WINDOW_LEN: usize = 2;
60+
pub const MIN_DIFFICULTY_WINDOW_LEN: usize = 10;
6161

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

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

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

7373
/// Size of the **sampled** difficulty window (independent of BPS)
74-
pub const DIFFICULTY_SAMPLED_WINDOW_SIZE: u64 = NEW_DIFFICULTY_WINDOW_DURATION / DIFFICULTY_WINDOW_SAMPLE_INTERVAL;
74+
pub const DIFFICULTY_SAMPLED_WINDOW_SIZE: u64 =
75+
(NEW_DIFFICULTY_WINDOW_DURATION + DIFFICULTY_WINDOW_SAMPLE_INTERVAL - 1) / DIFFICULTY_WINDOW_SAMPLE_INTERVAL;
7576

7677
//
7778
// ~~~~~~~~~~~~~~~~~~~ Finality & Pruning ~~~~~~~~~~~~~~~~~~~
@@ -84,6 +85,14 @@ pub mod consensus {
8485
/// TODO: finalize this value (consider 6-24 hours)
8586
pub const NEW_FINALITY_DURATION: u64 = 43_200; // 12 hours
8687

88+
/// Merge depth bound duration (in seconds). For 1 BPS networks this equals the legacy depth
89+
/// bound in block units. For higher BPS networks this should be scaled up.
90+
///
91+
/// This number should be roughly equal to DAA window duration in order to prevent merging
92+
/// low-difficulty side-chains (up to ~2x over DAA duration is still reasonable since creating
93+
/// a mergeable low-difficulty side-chain within this bound requires a significant hashrate fraction)
94+
pub const MERGE_DEPTH_DURATION: u64 = 3600;
95+
8796
/// The value of the pruning proof `M` parameter
8897
pub const PRUNING_PROOF_M: u64 = 1000;
8998

@@ -105,6 +114,8 @@ pub mod perf {
105114
use kaspa_hashes::Hash;
106115
use std::mem::size_of;
107116

117+
use super::consensus::NETWORK_DELAY_BOUND;
118+
108119
/// The default target depth for reachability reindexes.
109120
pub const DEFAULT_REINDEX_DEPTH: u64 = 100;
110121

@@ -188,17 +199,15 @@ pub mod perf {
188199
}
189200

190201
pub fn approx_direct_header_parents(consensus_params: &Params) -> usize {
191-
let avg_delay = 2;
192-
consensus_params.bps() as usize * avg_delay
202+
consensus_params.bps() as usize * NETWORK_DELAY_BOUND as usize
193203
}
194204

195205
pub fn approx_header_parents(consensus_params: &Params) -> usize {
196-
approx_direct_header_parents(consensus_params) * 2 // 2x for multi-levels
206+
approx_direct_header_parents(consensus_params) * 4 // 4x for multi-levels
197207
}
198208

199209
pub fn approx_mergeset_size(consensus_params: &Params) -> usize {
200-
let avg_delay = 2;
201-
consensus_params.bps() as usize * avg_delay
210+
consensus_params.bps() as usize * NETWORK_DELAY_BOUND as usize
202211
}
203212
}
204213

mining/src/manager_tests.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,11 @@ mod tests {
865865
count: usize,
866866
) -> (Vec<Transaction>, Vec<Transaction>) {
867867
// Make the funding amounts always different so that funding txs have different ids
868-
let parent_child_pairs = (0..count)
868+
(0..count)
869869
.map(|i| {
870870
create_parent_and_children_transactions(consensus, vec![500 * SOMPI_PER_KASPA, 3_000 * SOMPI_PER_KASPA + i as u64])
871871
})
872-
.collect::<Vec<(_, _)>>();
873-
let parent_txs = parent_child_pairs.iter().map(|(p, _)| p.clone()).collect::<Vec<_>>();
874-
let child_txs = parent_child_pairs.iter().map(|(_, c)| c.clone()).collect::<Vec<_>>();
875-
876-
(parent_txs, child_txs)
872+
.unzip()
877873
}
878874

879875
fn create_parent_and_children_transactions(

rothschild/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async fn main() {
128128
);
129129

130130
let mut utxos = refresh_utxos(&rpc_client, kaspa_addr.clone(), &mut pending, coinbase_maturity).await;
131-
let mut ticker = interval(Duration::from_secs_f64(1.0 / (args.tps as f64)));
131+
let mut ticker = interval(Duration::from_secs_f64(1.0 / (args.tps.min(100) as f64)));
132132
ticker.set_missed_tick_behavior(MissedTickBehavior::Burst);
133133

134134
let mut maximize_inputs = false;
@@ -173,7 +173,7 @@ fn should_maximize_inputs(
173173
async fn pause_if_mempool_is_full(rpc_client: &GrpcClient) {
174174
loop {
175175
let mempool_size = rpc_client.get_info().await.unwrap().mempool_size;
176-
if mempool_size < 100_000 {
176+
if mempool_size < 10_000 {
177177
break;
178178
}
179179

0 commit comments

Comments
 (0)