diff --git a/bin/light-base/src/lib.rs b/bin/light-base/src/lib.rs index ab5e13d818..abbd117bc5 100644 --- a/bin/light-base/src/lib.rs +++ b/bin/light-base/src/lib.rs @@ -409,12 +409,35 @@ impl Client { }), 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, @@ -423,7 +446,7 @@ impl Client { digest: header::DigestRef::empty().into(), }; - (ci, genesis_header) + (database, genesis_header) } (Err(chain_spec::FromGenesisStorageError::UnknownStorageItems), None, _) => { @@ -438,7 +461,7 @@ impl Client { ( Err(chain_spec::FromGenesisStorageError::UnknownStorageItems), - Some(Ok(ci)), + Some(Ok(checkpoint)), _, ) => { let genesis_header = header::Header { @@ -449,7 +472,7 @@ impl Client { digest: header::DigestRef::empty().into(), }; - (ci, genesis_header) + (checkpoint, genesis_header) } (Err(err), _, _) => { @@ -473,15 +496,15 @@ impl Client { })); } - (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) } } }; diff --git a/bin/wasm-node/CHANGELOG.md b/bin/wasm-node/CHANGELOG.md index 9161addd39..38d64ee706 100644 --- a/bin/wasm-node/CHANGELOG.md +++ b/bin/wasm-node/CHANGELOG.md @@ -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