Skip to content

Commit

Permalink
Remove unnecessary duplicated best_seen_block from SyncState struct
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Sep 6, 2022
1 parent 03df7d5 commit bb8abd4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 0 additions & 2 deletions client/network/common/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ pub struct StateDownloadProgress {
pub struct SyncStatus<Block: BlockT> {
/// Current global sync state.
pub state: SyncState<NumberFor<Block>>,
/// Target sync block number.
pub best_seen_block: Option<NumberFor<Block>>,
/// Number of peers participating in syncing.
pub num_peers: u32,
/// Number of blocks queued for import
Expand Down
8 changes: 6 additions & 2 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -501,7 +501,11 @@ where

/// Target sync block number.
pub fn best_seen_block(&self) -> Option<NumberFor<B>> {
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.
Expand Down
3 changes: 0 additions & 3 deletions client/network/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ where
/// Returns the current sync status.
fn status(&self) -> SyncStatus<B> {
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
Expand Down Expand Up @@ -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()),
Expand Down

0 comments on commit bb8abd4

Please sign in to comment.