Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong Grandpa warp sync block being reported #3044

Merged
merged 4 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions bin/light-base/src/sync_service/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,21 @@ pub(super) async fn start_standalone_chain<TPlat: Platform>(
() = &mut task.warp_sync_taking_long_time_warning => {
match task.sync.status() {
all::Status::Sync => {},
all::Status::WarpSyncFragments { source: None } => {
log::warn!(target: &task.log_target, "GrandPa warp sync idle");
all::Status::WarpSyncFragments { source: None, finalized_block_hash, finalized_block_number } => {
log::warn!(
target: &task.log_target,
"GrandPa warp sync idle at block #{} (0x{})",
finalized_block_number,
HashDisplay(&finalized_block_hash),
);
}
all::Status::WarpSyncFragments { source: Some((_, (peer_id, _))) } |
all::Status::WarpSyncChainInformation { source: (_, (peer_id, _)) } => {
let finalized_block = task.sync.finalized_block_header();
all::Status::WarpSyncFragments { source: Some((_, (peer_id, _))), finalized_block_hash, finalized_block_number } |
all::Status::WarpSyncChainInformation { source: (_, (peer_id, _)), finalized_block_hash, finalized_block_number } => {
log::warn!(
target: &task.log_target,
"GrandPa warp sync in progress. Block: #{} (0x{}). Peer attempt: {}.",
finalized_block.number,
HashDisplay(&finalized_block.hash(task.sync.block_number_bytes())),
finalized_block_number,
HashDisplay(&finalized_block_hash),
peer_id
);
},
Expand Down
4 changes: 4 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- Fix wrong block being reported in the logs when printing the status of the Grandpa warp syncing, giving the impression that the warp syncing wasn't advancing. ([#3044](https://github.com/paritytech/smoldot/pull/3044))

## 0.7.8 - 2022-11-23

### Changed
Expand Down
36 changes: 33 additions & 3 deletions src/sync/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,28 @@ pub enum Status<'a, TSrc> {
WarpSyncFragments {
/// Source from which the fragments are currently being downloaded, if any.
source: Option<(SourceId, &'a TSrc)>,
/// Hash of the highest block that is proven to be finalized.
///
/// This isn't necessarily the same block as returned by
/// [`AllSync::as_chain_information`], as this function first has to download extra
/// information compared to just the finalized block.
finalized_block_hash: [u8; 32],
/// Height of the block indicated by [`Status::ChainInformation::finalized_block_hash`].
finalized_block_number: u64,
},
/// Warp syncing algorithm has reached the head of the finalized chain and is downloading and
/// building the chain information.
WarpSyncChainInformation {
/// Source from which the chain information is being downloaded.
source: (SourceId, &'a TSrc),
/// Hash of the highest block that is proven to be finalized.
///
/// This isn't necessarily the same block as returned by
/// [`AllSync::as_chain_information`], as this function first has to download extra
/// information compared to just the finalized block.
finalized_block_hash: [u8; 32],
/// Height of the block indicated by [`Status::ChainInformation::finalized_block_hash`].
finalized_block_number: u64,
},
}

Expand Down Expand Up @@ -233,18 +249,32 @@ impl<TRq, TSrc, TBl> AllSync<TRq, TSrc, TBl> {
match &self.inner {
AllSyncInner::AllForks(_) => Status::Sync,
AllSyncInner::GrandpaWarpSync { inner: sync } => match sync.status() {
warp_sync::Status::Fragments { source: None } => {
Status::WarpSyncFragments { source: None }
}
warp_sync::Status::Fragments {
source: None,
finalized_block_hash,
finalized_block_number,
} => Status::WarpSyncFragments {
source: None,
finalized_block_hash,
finalized_block_number,
},
warp_sync::Status::Fragments {
source: Some((_, user_data)),
finalized_block_hash,
finalized_block_number,
} => Status::WarpSyncFragments {
source: Some((user_data.outer_source_id, &user_data.user_data)),
finalized_block_hash,
finalized_block_number,
},
warp_sync::Status::ChainInformation {
source: (_, user_data),
finalized_block_hash,
finalized_block_number,
} => Status::WarpSyncChainInformation {
source: (user_data.outer_source_id, &user_data.user_data),
finalized_block_hash,
finalized_block_number,
},
},
AllSyncInner::Optimistic { .. } => Status::Sync, // TODO: right now we don't differentiate between AllForks and Optimistic, as they're kind of similar anyway
Expand Down
69 changes: 54 additions & 15 deletions src/sync/warp_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,28 @@ pub enum Status<'a, TSrc> {
Fragments {
/// Source from which the fragments are currently being downloaded, if any.
source: Option<(SourceId, &'a TSrc)>,
/// Hash of the highest block that is proven to be finalized.
///
/// This isn't necessarily the same block as returned by
/// [`InProgressWarpSync::as_chain_information`], as this function first has to download
/// extra information compared to just the finalized block.
finalized_block_hash: [u8; 32],
/// Height of the block indicated by [`Status::ChainInformation::finalized_block_hash`].
finalized_block_number: u64,
},
/// Warp syncing algorithm has reached the head of the finalized chain and is downloading and
/// building the chain information.
ChainInformation {
/// Source from which the chain information is being downloaded.
source: (SourceId, &'a TSrc),
/// Hash of the highest block that is proven to be finalized.
///
/// This isn't necessarily the same block as returned by
/// [`InProgressWarpSync::as_chain_information`], as this function first has to download
/// extra information compared to just the finalized block.
finalized_block_hash: [u8; 32],
/// Height of the block indicated by [`Status::ChainInformation::finalized_block_hash`].
finalized_block_number: u64,
},
}

Expand All @@ -377,21 +393,22 @@ impl<TSrc, TRq> InProgressWarpSync<TSrc, TRq> {
Phase::DownloadFragments {
ref previous_verifier_values,
} => {
let start_block_hash = match previous_verifier_values.as_ref() {
Some((header, _)) => header.hash(self.block_number_bytes),
None => self
.start_chain_information
.as_ref()
.finalized_block_header
.hash(self.block_number_bytes),
let (finalized_block_hash, finalized_block_number) = match previous_verifier_values
.as_ref()
{
Some((header, _)) => (header.hash(self.block_number_bytes), header.number),
None => {
let header = self.start_chain_information.as_ref().finalized_block_header;
(header.hash(self.block_number_bytes), header.number)
}
};

let source_id =
self.in_progress_requests
.iter()
.find_map(|(_, (source_id, _, rq))| match rq {
RequestDetail::WarpSyncRequest { block_hash }
if *block_hash == start_block_hash =>
if *block_hash == finalized_block_hash =>
{
Some(*source_id)
}
Expand All @@ -400,28 +417,50 @@ impl<TSrc, TRq> InProgressWarpSync<TSrc, TRq> {

Status::Fragments {
source: source_id.map(|id| (id, &self.sources[id.0].user_data)),
finalized_block_hash,
finalized_block_number,
}
}
Phase::PendingVerify {
downloaded_source, ..
} => Status::Fragments {
source: Some((
downloaded_source,
&self.sources[downloaded_source.0].user_data,
)),
},
downloaded_source,
ref previous_verifier_values,
..
} => {
let (finalized_block_hash, finalized_block_number) = match previous_verifier_values
.as_ref()
{
Some((header, _)) => (header.hash(self.block_number_bytes), header.number),
None => {
let header = self.start_chain_information.as_ref().finalized_block_header;
(header.hash(self.block_number_bytes), header.number)
}
};

Status::Fragments {
source: Some((
downloaded_source,
&self.sources[downloaded_source.0].user_data,
)),
finalized_block_hash,
finalized_block_number,
}
}
Phase::RuntimeDownload {
warp_sync_source_id,
ref header,
..
}
| Phase::ChainInformationDownload {
warp_sync_source_id,
ref header,
..
} => Status::ChainInformation {
source: (
warp_sync_source_id,
&self.sources[warp_sync_source_id.0].user_data,
),
finalized_block_hash: header.hash(self.block_number_bytes),
finalized_block_number: header.number,
},
}
}
Expand Down