Skip to content

Commit

Permalink
Backport change to checkpoints format (#2219)
Browse files Browse the repository at this point in the history
* Backport change to checkpoints format

* CHANGELOG PR

* Fix warning

* Rustfmt
  • Loading branch information
tomaka authored Apr 7, 2022
1 parent 84bfb53 commit a49039d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 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. ([#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

0 comments on commit a49039d

Please sign in to comment.