From bb8abd458c939881c049f69d59f3acba47c97c5c Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Tue, 6 Sep 2022 13:32:18 +0300 Subject: [PATCH] Remove unnecessary duplicated `best_seen_block` from `SyncState` struct --- client/network/common/src/sync.rs | 2 -- client/network/src/protocol.rs | 8 ++++++-- client/network/sync/src/lib.rs | 3 --- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/client/network/common/src/sync.rs b/client/network/common/src/sync.rs index df12705985870..19c1d7c35920e 100644 --- a/client/network/common/src/sync.rs +++ b/client/network/common/src/sync.rs @@ -74,8 +74,6 @@ pub struct StateDownloadProgress { pub struct SyncStatus { /// Current global sync state. pub state: SyncState>, - /// Target sync block number. - pub best_seen_block: Option>, /// Number of peers participating in syncing. pub num_peers: u32, /// Number of blocks queued for import diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 351e7d207ad1e..101ea7c34f450 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -52,7 +52,7 @@ use sc_network_common::{ warp::{EncodedProof, WarpProofRequest}, BadPeer, ChainSync, OnBlockData, OnBlockJustification, OnStateData, OpaqueBlockRequest, OpaqueBlockResponse, OpaqueStateRequest, OpaqueStateResponse, PollBlockAnnounceValidation, - SyncStatus, + SyncState, SyncStatus, }, }; use sp_arithmetic::traits::SaturatedConversion; @@ -501,7 +501,11 @@ where /// Target sync block number. pub fn best_seen_block(&self) -> Option> { - self.chain_sync.status().best_seen_block + match self.chain_sync.status().state { + SyncState::Idle => None, + SyncState::Downloading { target } => Some(target), + SyncState::Importing { .. } => None, + } } /// Number of peers participating in syncing. diff --git a/client/network/sync/src/lib.rs b/client/network/sync/src/lib.rs index a686500eb44dd..49de6fd9268e1 100644 --- a/client/network/sync/src/lib.rs +++ b/client/network/sync/src/lib.rs @@ -390,8 +390,6 @@ where /// Returns the current sync status. fn status(&self) -> SyncStatus { let median_seen = self.median_seen(); - let best_seen_block = - median_seen.and_then(|median| (median > self.best_queued_number).then_some(median)); let sync_state = if let Some(target) = median_seen { // A chain is classified as downloading if the provided best block is // more than `MAJOR_SYNC_BLOCKS` behind the best block or as importing @@ -424,7 +422,6 @@ where SyncStatus { state: sync_state, - best_seen_block, num_peers: self.peers.len() as u32, queued_blocks: self.queue_blocks.len() as u32, state_sync: self.state_sync.as_ref().map(|s| s.progress()),