Skip to content

Commit

Permalink
Refactor chain information building process (#2845)
Browse files Browse the repository at this point in the history
Close #1681

Right now the code of `warp_sync` and `chain_spec` both build a
`ChainInformation` struct by making runtime calls. However the code of
these two modules is completely different.
Because these two modules were built very early on in smoldot's history,
they are getting help from the sub-modules of the `chain_information`
module, that are also very old.

This PR modernizes all of this: it removes all the sub-modules under
`chain_information` and merges them into one that does everything.

This new module is now used by `warp_sync` and `chain_spec`, and
`warp_sync` and `chain_spec` are now more simple.

I'm also planning to use this new module in order to refactor the SQLite
database. (#1752)

This PR slightly changes the behavior of the warp syncing: we now
download the runtime, then build it, and then only download the call
proofs to obtain the chain information. Right now all the downloads are
done in parallel.
This change is in principle more correct. At the moment we blindly call
functions that we expect to exist. By downloading and building the
runtime first, we can check the list of supported functions and then
only call them. (cc #949) This is really not a problem at the moment
because none of the functions that we use has ever been deprecated, but
it could have become one in the future.
  • Loading branch information
tomaka authored Oct 10, 2022
1 parent b33745d commit 6072ccc
Show file tree
Hide file tree
Showing 10 changed files with 1,362 additions and 1,804 deletions.
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

- The warp syncing algorithm no longer downloads the runtime code and the runtime call proofs at the same time. Instead, it now first downloads the runtime, then checks the list of available functions, then downloads runtime call proofs. While this slightly degrades the warp syncing time by adding a round-trip time, it is more correct to first analyze the runtime instead of blindly assuming that it supports a certain set of functions. ([#2845](https://github.com/paritytech/smoldot/pull/2845))

### Fixed

- Fix the responses to libp2p identify requests being wrongly empty. ([#2840](https://github.com/paritytech/smoldot/pull/2840))
Expand Down
12 changes: 4 additions & 8 deletions src/chain/chain_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ use crate::header;
use alloc::vec::Vec;
use core::num::NonZeroU64;

pub mod aura_config;
pub mod babe_fetch_epoch;
pub mod babe_genesis_config;
pub mod grandpa_genesis_config;
pub mod build;

/// Information about the latest finalized block and state found in its ancestors.
///
Expand Down Expand Up @@ -190,8 +187,8 @@ pub enum ChainInformationConsensus {
/// Babe epoch information about the epoch the finalized block belongs to.
///
/// If the finalized block belongs to epoch #0, which starts at block #1, then this must
/// contain the information about the epoch #0, which can be found by calling
/// [`babe_genesis_config::BabeGenesisConfiguration::from_virtual_machine_prototype`].
/// contain the information about the epoch #0, which can be found by calling the
/// `BabeApi_configuration` runtime function.
///
/// Must be `None` if and only if the finalized block is block #0.
///
Expand All @@ -210,8 +207,7 @@ pub enum ChainInformationConsensus {
/// this field must contain the epoch that follows.
///
/// If the finalized block is block #0, then this must contain the information about the
/// epoch #0, which can be found by calling
/// [`babe_genesis_config::BabeGenesisConfiguration::from_virtual_machine_prototype`].
/// epoch #0, which can be found by calling the `BabeApi_configuration` runtime function.
finalized_next_epoch_transition: BabeEpochInformation,
},
}
Expand Down
178 changes: 0 additions & 178 deletions src/chain/chain_information/aura_config.rs

This file was deleted.

Loading

0 comments on commit 6072ccc

Please sign in to comment.