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

Backport change to checkpoints format #2219

Merged
merged 4 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 4 additions & 7 deletions bin/polkadot.json

Large diffs are not rendered by default.

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

- Backport change to checkpoints format (generated by the `sync_state_genSyncSpec` JSON-RPC function of Substrate nodes). Smoldot maintains compatibility with checkpoints generated earlier. ([#2219](https://github.com/paritytech/smoldot/pull/2219))

## 0.6.14 - 2022-04-07

### Fixed
Expand Down
22 changes: 18 additions & 4 deletions src/chain_spec/light_sync_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{ParseError, ParseErrorInner};
use crate::header::BabeNextConfig;

use alloc::{collections::BTreeMap, format, string::String, vec::Vec};
use parity_scale_codec::{Decode, DecodeAll as _, Encode};
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -41,10 +41,13 @@ impl LightSyncState {
finalized_block_header: crate::header::decode(&self.finalized_block_header.0[..])
.map_err(|_| ParseError(ParseErrorInner::Other))?
.into(),
// Note that for some reason `decode_all` accepts a `&mut &[u8]` and makes it empty.
grandpa_authority_set: AuthoritySet::decode_all(&mut grandpa_authority_set_slice)
// We use `decode` in order to remain compatible in case new fields are added in
// Substrate to these data structures.
// This really should be solved by having a proper format for checkpoints, but
// there isn't.
grandpa_authority_set: AuthoritySet::decode(&mut grandpa_authority_set_slice)
.map_err(|_| ParseError(ParseErrorInner::Other))?,
babe_epoch_changes: EpochChanges::decode_all(&mut babe_epoch_changes_slice)
babe_epoch_changes: EpochChanges::decode(&mut babe_epoch_changes_slice)
.map_err(|_| ParseError(ParseErrorInner::Other))?,
};

Expand All @@ -63,6 +66,17 @@ pub(super) struct DecodedLightSyncState {
pub(super) struct EpochChanges {
inner: ForkTree<PersistedEpochHeader>,
pub(super) epochs: BTreeMap<([u8; 32], u32), PersistedEpoch>,
// TODO: Substrate has added the field below to the checkpoints format ; it is commented out
// right now in order to maintain compatibility with checkpoints that were generated
// a long time ago
// gap: Option<GapEpochs>,
}

#[allow(unused)]
#[derive(Debug, Decode, Encode)]
pub(super) struct GapEpochs {
current: ([u8; 32], u32, PersistedEpoch),
next: Option<([u8; 32], u32, BabeEpoch)>,
}

#[derive(Debug, Decode, Encode)]
Expand Down