@@ -10,10 +10,7 @@ use crate::{
1010} ;
1111use kaspa_addresses:: Prefix ;
1212use kaspa_math:: Uint256 ;
13- use std:: {
14- cmp:: min,
15- time:: { SystemTime , UNIX_EPOCH } ,
16- } ;
13+ use std:: cmp:: min;
1714
1815#[ derive( Clone , Copy , Debug , Default , PartialEq , Eq ) ]
1916pub struct ForkActivation ( u64 ) ;
@@ -136,10 +133,6 @@ pub struct Params {
136133 pub runtime_sig_op_counting : ForkActivation ,
137134}
138135
139- fn unix_now ( ) -> u64 {
140- SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_millis ( ) as u64
141- }
142-
143136impl Params {
144137 /// Returns the size of the full blocks window that is inspected to calculate the past median time (legacy)
145138 #[ inline]
@@ -238,7 +231,7 @@ impl Params {
238231 }
239232 }
240233
241- fn expected_daa_window_duration_in_milliseconds ( & self , selected_parent_daa_score : u64 ) -> u64 {
234+ pub fn expected_daa_window_duration_in_milliseconds ( & self , selected_parent_daa_score : u64 ) -> u64 {
242235 if self . sampling_activation . is_active ( selected_parent_daa_score) {
243236 self . target_time_per_block * self . difficulty_sample_rate * self . sampled_difficulty_window_size as u64
244237 } else {
@@ -264,26 +257,6 @@ impl Params {
264257 min ( self . pruning_depth , anticone_finalization_depth)
265258 }
266259
267- /// Returns whether the sink timestamp is recent enough and the node is considered synced or nearly synced.
268- pub fn is_nearly_synced ( & self , sink_timestamp : u64 , sink_daa_score : u64 ) -> bool {
269- if self . net . is_mainnet ( ) {
270- // We consider the node close to being synced if the sink (virtual selected parent) block
271- // timestamp is within DAA window duration far in the past. Blocks mined over such DAG state would
272- // enter the DAA window of fully-synced nodes and thus contribute to overall network difficulty
273- unix_now ( ) < sink_timestamp + self . expected_daa_window_duration_in_milliseconds ( sink_daa_score)
274- } else {
275- // For testnets we consider the node to be synced if the sink timestamp is within a time range which
276- // is overwhelmingly unlikely to pass without mined blocks even if net hashrate decreased dramatically.
277- //
278- // This period is smaller than the above mainnet calculation in order to ensure that an IBDing miner
279- // with significant testnet hashrate does not overwhelm the network with deep side-DAGs.
280- //
281- // We use DAA duration as baseline and scale it down with BPS (and divide by 3 for mining only when very close to current time on TN11)
282- let max_expected_duration_without_blocks_in_milliseconds = self . target_time_per_block * NEW_DIFFICULTY_WINDOW_DURATION / 3 ; // = DAA duration in milliseconds / bps / 3
283- unix_now ( ) < sink_timestamp + max_expected_duration_without_blocks_in_milliseconds
284- }
285- }
286-
287260 pub fn network_name ( & self ) -> String {
288261 self . net . to_prefixed ( )
289262 }
0 commit comments