Skip to content

Commit

Permalink
Merge pull request #2372 from subspace/improve-sync-status-detection
Browse files Browse the repository at this point in the history
Improve sync status detection
  • Loading branch information
nazar-pc authored Dec 24, 2023
2 parents bc2844b + 9193bae commit 947eacb
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions crates/sc-consensus-subspace-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,31 @@ where
fn subscribe_node_sync_status_change(&self, mut sink: SubscriptionSink) -> SubscriptionResult {
let sync_oracle = self.sync_oracle.clone();
let fut = async move {
let mut last_node_sync_status = None;
let mut last_is_major_syncing = None;
loop {
let node_sync_status = if sync_oracle.is_major_syncing() {
NodeSyncStatus::MajorSyncing
} else {
NodeSyncStatus::Synced
};
let is_major_syncing = sync_oracle.is_major_syncing();

// Update subscriber if value has changed
if last_node_sync_status != Some(node_sync_status) {
last_node_sync_status.replace(node_sync_status);
if last_is_major_syncing != Some(is_major_syncing) {
// In case change is detected, wait for another interval to confirm.
// TODO: This is primarily because Substrate seems to lose peers for brief
// periods of time sometimes that needs to be investigated separately
futures_timer::Delay::new(NODE_SYNC_STATUS_CHECK_INTERVAL).await;

// If status returned back to what it was, ignore
if last_is_major_syncing == Some(sync_oracle.is_major_syncing()) {
futures_timer::Delay::new(NODE_SYNC_STATUS_CHECK_INTERVAL).await;
continue;
}

// Otherwise save new status
last_is_major_syncing.replace(is_major_syncing);

let node_sync_status = if is_major_syncing {
NodeSyncStatus::MajorSyncing
} else {
NodeSyncStatus::Synced
};
match sink.send(&node_sync_status) {
Ok(true) => {
// Success
Expand Down

0 comments on commit 947eacb

Please sign in to comment.