Skip to content

Commit

Permalink
"Refactor DAA sync condition for readability"
Browse files Browse the repository at this point in the history
Refactored the sync condition calculation in both pruning_proof/mod.rs and virtual_processor/processor.rs by moving the logic to the daa_window_params.is_nearly_synced method. This eliminates redundant code and enhances readability
  • Loading branch information
biryukovmaxim committed Aug 27, 2023
1 parent 43bed76 commit 777748c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
5 changes: 1 addition & 4 deletions consensus/src/pipeline/virtual_processor/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,7 @@ impl VirtualStateProcessor {
{
let sink = self.virtual_stores.read().state.get().unwrap().ghostdag_data.selected_parent;
let CompactHeaderData { timestamp, daa_score, .. } = self.headers_store.get_compact_header_data(sink).unwrap();
let diff = -(unix_now() as i64)
+ timestamp as i64
+ self.daa_window_params.expected_daa_window_duration_in_milliseconds(daa_score) as i64;
if diff > 0 {
if self.daa_window_params.is_nearly_synced(timestamp, daa_score) {
self.notification_root
.notify(Notification::SyncStateChanged(
kaspa_consensus_notify::notification::SyncStateChangedNotification::new_synced(),
Expand Down
6 changes: 1 addition & 5 deletions consensus/src/processes/pruning_proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use kaspa_consensus_notify::{
notification::{Notification, SyncStateChangedNotification},
root::ConsensusNotificationRoot,
};
use kaspa_core::time::unix_now;
use kaspa_core::{debug, info, trace};
use kaspa_database::prelude::{ConnBuilder, StoreResultEmptyTuple, StoreResultExtensions};
use kaspa_hashes::Hash;
Expand Down Expand Up @@ -422,10 +421,7 @@ impl PruningProofManager {
{
let sink = self.virtual_stores.read().state.get().unwrap().ghostdag_data.selected_parent;
let CompactHeaderData { timestamp, daa_score, .. } = self.headers_store.get_compact_header_data(sink).unwrap();
let diff = -(unix_now() as i64)
+ timestamp as i64
+ self.daa_window_params.expected_daa_window_duration_in_milliseconds(daa_score) as i64;
if diff > 0 {
if !self.daa_window_params.is_nearly_synced(timestamp, daa_score) {
self.notification_root
.notify(Notification::SyncStateChanged(SyncStateChangedNotification::new_proof(level, self.max_block_level)))
.expect("expecting an open unbounded channel");
Expand Down

0 comments on commit 777748c

Please sign in to comment.