From b6b1fcf2aad31cb80aafb4600d44c93503a5e609 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Sun, 24 Dec 2023 06:28:22 +0200 Subject: [PATCH 1/2] Tiny refactoring --- crates/sc-consensus-subspace-rpc/src/lib.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/sc-consensus-subspace-rpc/src/lib.rs b/crates/sc-consensus-subspace-rpc/src/lib.rs index a2cf1dcb1a..8248dff038 100644 --- a/crates/sc-consensus-subspace-rpc/src/lib.rs +++ b/crates/sc-consensus-subspace-rpc/src/lib.rs @@ -649,18 +649,19 @@ 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) { + 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 From 9193bae466381b47dd5f783831f566de7255402f Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Sun, 24 Dec 2023 06:33:11 +0200 Subject: [PATCH 2/2] Ensure sync status persists for two subsequent checks rather than just one --- crates/sc-consensus-subspace-rpc/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/sc-consensus-subspace-rpc/src/lib.rs b/crates/sc-consensus-subspace-rpc/src/lib.rs index 8248dff038..8d4a84eecc 100644 --- a/crates/sc-consensus-subspace-rpc/src/lib.rs +++ b/crates/sc-consensus-subspace-rpc/src/lib.rs @@ -655,6 +655,18 @@ where // Update subscriber if value has changed 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 {