Skip to content

Commit

Permalink
Add TrustSync state to SyncStateChangedNotification
Browse files Browse the repository at this point in the history
Added a new state called TrustSync to the SyncStateChangedNotification enum to share information about the processing of trusted blocks. The addition of TrustSync allows the program to notify about the number of trusted blocks processed in the last one second and the total number of such blocks processed till now. This is essential for improving the supervision of the synchronization process.
  • Loading branch information
biryukovmaxim committed Aug 24, 2023
1 parent 76fa2af commit bd5f816
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions consensus/notify/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ pub enum SyncStateChangedNotification {
Blocks { blocks: u64, progress: i64 },
UtxoResync,
UtxoSync { chunks: u64, total: u64 },
TrustSync { processed: u64, total: u64 },
}

impl SyncStateChangedNotification {
Expand All @@ -204,4 +205,8 @@ impl SyncStateChangedNotification {
pub fn new_utxo_sync(chunks: u64, total: u64) -> Self {
Self::UtxoSync { chunks, total }
}

pub fn new_trust_sync(processed: u64, total: u64) -> Self {
Self::TrustSync { processed, total }
}
}
9 changes: 9 additions & 0 deletions protocol/flows/src/v5/ibd/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,15 @@ impl IbdFlow {
let passed = now.duration_since(last_time);
if passed > Duration::from_secs(1) {
info!("Processed {} trusted blocks in the last {:.2}s (total {})", i - last_index, passed.as_secs_f64(), i);
self.notification_root
.as_ref()
.unwrap()
.notify(Notification::SyncStateChanged(SyncStateChangedNotification::new_trust_sync(
(i - last_index) as u64,
i as u64,
)))
.expect("expecting an open unbounded channel");

last_time = now;
last_index = i;
}
Expand Down
3 changes: 3 additions & 0 deletions rpc/core/src/convert/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ impl From<&consensus_notify::SyncStateChangedNotification> for SyncStateChangedN
consensus_notify::SyncStateChangedNotification::UtxoSync { chunks, total } => {
Self::UtxoSync { chunks: *chunks, total: *total }
}
consensus_notify::SyncStateChangedNotification::TrustSync { processed, total } => {
Self::TrustSync { processed: *processed, total: *total }
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions rpc/core/src/model/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,12 @@ pub enum SyncStateChangedNotification {
#[allow(dead_code)]
total: u64,
},
TrustSync {
#[allow(dead_code)]
processed: u64,
#[allow(dead_code)]
total: u64,
},
}

///
Expand Down
6 changes: 6 additions & 0 deletions rpc/grpc/core/proto/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ message SyncStateChangedNotificationMessage {
BlocksState blocks = 3;
UtxoResyncState utxoResync = 4;
UtxoSyncState utxoSync = 5;
TrustSyncState trustSync = 6;
}
}

Expand All @@ -802,4 +803,9 @@ message UtxoResyncState {}
message UtxoSyncState {
uint64 chunks = 1;
uint64 total = 2;
}

message TrustSyncState {
uint64 processed = 1;
uint64 total = 2;
}
6 changes: 6 additions & 0 deletions rpc/grpc/core/src/convert/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ from!(item: &kaspa_rpc_core::SyncStateChangedNotification, SyncStateChangedNotif
total: *total
}))
},
SyncStateChangedNotification::TrustSync { processed, total} => SyncStateChangedNotificationMessage {
sync_state: Some(sync_state_changed_notification_message::SyncState::TrustSync(crate::protowire::TrustSyncState {
processed: *processed,
total: *total
}))
},
}
});

Expand Down

0 comments on commit bd5f816

Please sign in to comment.