Skip to content

Commit

Permalink
"Refactor DAA sync condition for readability and performance"
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. Also, reducing computation overhead by reusing the existing method could contribute to better performance.
  • Loading branch information
biryukovmaxim committed Aug 27, 2023
1 parent 43bed76 commit 7360a42
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 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
5 changes: 1 addition & 4 deletions consensus/src/processes/pruning_proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,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 7360a42

Please sign in to comment.