Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Introduce SyncState::Importing state
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Aug 29, 2022
1 parent bee40e1 commit 912eb7a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion client/informant/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ impl<B: BlockT> InformantDisplay<B> {
(SyncState::Idle, _, _, _) => ("💤", "Idle".into(), "".into()),
(SyncState::Downloading, None, _, _) =>
("⚙️ ", format!("Preparing{}", speed), "".into()),
(SyncState::Downloading, Some(n), None, _) =>
(SyncState::Downloading, Some(n), _, _) =>
("⚙️ ", format!("Syncing{}", speed), format!(", target=#{}", n)),
(SyncState::Importing, _, _, _) => ("⚙️ ", format!("Importing{}", speed), "".into()),
};

if self.format.enable_color {
Expand Down
2 changes: 2 additions & 0 deletions client/network/common/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub enum SyncState {
Idle,
/// Actively catching up with the chain.
Downloading,
/// All blocks are downloaded and are being imported.
Importing,
}

/// Reported state download progress.
Expand Down
14 changes: 10 additions & 4 deletions client/network/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,18 @@ where
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(n) = median_seen {
let sync_state = if let Some(n) = best_seen_block.or(median_seen) {
// A chain is classified as downloading if the provided best block is
// more than `MAJOR_SYNC_BLOCKS` behind the best block.
// more than `MAJOR_SYNC_BLOCKS` behind the best block or as importing
// if the same can be said about queued blocks.
let best_block = self.client.info().best_number;
if n > best_block && n - best_block > MAJOR_SYNC_BLOCKS.into() {
SyncState::Downloading
// If target is not queued, we're downloading, otherwise importing.
if n > self.best_queued_number {
SyncState::Downloading
} else {
SyncState::Importing
}
} else {
SyncState::Idle
}
Expand All @@ -416,7 +422,7 @@ where
_ => None,
};

let is_major_syncing = matches!(sync_state, SyncState::Downloading);
let is_major_syncing = !matches!(sync_state, SyncState::Idle);

SyncStatus {
state: sync_state,
Expand Down

0 comments on commit 912eb7a

Please sign in to comment.