Skip to content

Commit

Permalink
Backport change to checkpoints format
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed Apr 7, 2022
1 parent 84bfb53 commit 4e1bca5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
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. ()

## 0.6.14 - 2022-04-07

### Fixed
Expand Down
20 changes: 17 additions & 3 deletions src/chain_spec/light_sync_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4e1bca5

Please sign in to comment.