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

Only use database if it's more recent than checkpoint #2401

Merged
merged 3 commits into from
Jun 19, 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
45 changes: 34 additions & 11 deletions bin/light-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,35 @@ impl<TChain, TPlat: Platform> Client<TChain, TPlat> {
}),
finalized_serialize::decode_chain(config.database_content),
) {
(Ok(Ok(genesis_ci)), _, Ok((ci, _))) => {
// Use the database if it contains a more recent block than the chain spec checkpoint.
(Ok(Ok(genesis_ci)), checkpoint, Ok((database, _)))
if checkpoint
.as_ref()
.map(|r| r.as_ref().ok())
.flatten()
.map_or(true, |cp| {
cp.as_ref().finalized_block_header.number
< database.as_ref().finalized_block_header.number
}) =>
{
let genesis_header = genesis_ci.as_ref().finalized_block_header.clone();
(ci, genesis_header.into())
(database, genesis_header.into())
}

(Err(chain_spec::FromGenesisStorageError::UnknownStorageItems), _, Ok((ci, _))) => {
// Use the database if it contains a more recent block than the chain spec checkpoint.
(
Err(chain_spec::FromGenesisStorageError::UnknownStorageItems),
checkpoint,
Ok((database, _)),
) if checkpoint
.as_ref()
.map(|r| r.as_ref().ok())
.flatten()
.map_or(true, |cp| {
cp.as_ref().finalized_block_header.number
< database.as_ref().finalized_block_header.number
}) =>
{
let genesis_header = header::Header {
parent_hash: [0; 32],
number: 0,
Expand All @@ -423,7 +446,7 @@ impl<TChain, TPlat: Platform> Client<TChain, TPlat> {
digest: header::DigestRef::empty().into(),
};

(ci, genesis_header)
(database, genesis_header)
}

(Err(chain_spec::FromGenesisStorageError::UnknownStorageItems), None, _) => {
Expand All @@ -438,7 +461,7 @@ impl<TChain, TPlat: Platform> Client<TChain, TPlat> {

(
Err(chain_spec::FromGenesisStorageError::UnknownStorageItems),
Some(Ok(ci)),
Some(Ok(checkpoint)),
_,
) => {
let genesis_header = header::Header {
Expand All @@ -449,7 +472,7 @@ impl<TChain, TPlat: Platform> Client<TChain, TPlat> {
digest: header::DigestRef::empty().into(),
};

(ci, genesis_header)
(checkpoint, genesis_header)
}

(Err(err), _, _) => {
Expand All @@ -473,15 +496,15 @@ impl<TChain, TPlat: Platform> Client<TChain, TPlat> {
}));
}

(Ok(Ok(genesis_ci)), Some(Ok(ci)), _) => {
(Ok(Ok(genesis_ci)), Some(Ok(checkpoint)), _) => {
let genesis_header = genesis_ci.as_ref().finalized_block_header.clone();
(ci, genesis_header.into())
(checkpoint, genesis_header.into())
}

(Ok(Ok(ci)), None, _) => {
(Ok(Ok(genesis_ci)), None, _) => {
let genesis_header =
header::Header::from(ci.as_ref().finalized_block_header.clone());
(ci, genesis_header)
header::Header::from(genesis_ci.as_ref().finalized_block_header.clone());
(genesis_ci, genesis_header)
}
}
};
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

### Changed

- When a database and a chain specification checkpoint are both provided to `addChain`, the block in the database is used only if it has a higher block number than the block in the chain specification checkpoint. This makes it possible to bypass issues where smoldot is incapable of syncing over a certain block by updating the chain specification, without having to manually clear existing databases. ([#2401](https://github.com/paritytech/smoldot/pull/2401))

## 0.6.19 - 2022-06-14

### Fixed
Expand Down