Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Decouples light-sync state from chain spec #9491

Merged
5 commits merged into from
Aug 4, 2021
Merged

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Aug 3, 2021

This decouples the light-sync state from chain spec. First, the
light-sync state currently only works with BABE+Grandpa, so not
all Substrate based chains can use this feature. The next problem was
also that this pulled the sc-consensus-babe and sc-finality-grandpa
crate into sc-chain-spec.

If a chain now wants to support the light-sync state, it needs to add
the LightSyncStateExtension to the chain spec as an extension. This is
documented in the crate level docs of sc-sync-state-rpc. If this
extension is not available, SyncStateRpc fails at initialization.

polkadot companion: paritytech/polkadot#3568

Fixes: #8886

bkchr added 3 commits August 3, 2021 12:37
This decouples the light-sync state from chain spec. First, the
light-sync state currently only works with BABE+Grandpa, so not
all *Substrate* based chains can use this feature. The next problem was
also that this pulled the `sc-consensus-babe` and `sc-finality-grandpa`
crate into `sc-chain-spec`.

If a chain now wants to support the light-sync state, it needs to add
the `LightSyncStateExtension` to the chain spec as an extension. This is
documented in the crate level docs of `sc-sync-state-rpc`. If this
extension is not available, `SyncStateRpc` fails at initialization.
@bkchr bkchr added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Aug 3, 2021
@bkchr bkchr requested a review from andresilva August 3, 2021 18:08
bkchr added a commit to paritytech/polkadot that referenced this pull request Aug 3, 2021
@@ -129,7 +129,7 @@ pub use sp_consensus_babe::{
},
AuthorityId, AuthorityPair, AuthoritySignature, BabeApi, BabeAuthorityWeight,
BabeEpochConfiguration, BabeGenesisConfiguration, ConsensusLog, BABE_ENGINE_ID,
VRF_OUTPUT_LENGTH,
VRF_OUTPUT_LENGTH, BabeBlockWeight,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to configure your editor to cargo fmt now 😏.

@arkpar
Copy link
Member

arkpar commented Aug 3, 2021

What is the "light sync state" used for? Looks like the code that was supposed to use it was never written? Why not just remove it?

Also, the light client does not really need to have epochs and authorities in the chain spec. All that's needed is a trusted finalized block hash. The rest should be recoverable from the state.

@bkchr
Copy link
Member Author

bkchr commented Aug 4, 2021

What is the "light sync state" used for? Looks like the code that was supposed to use it was never written? Why not just remove it?

Also, the light client does not really need to have epochs and authorities in the chain spec. All that's needed is a trusted finalized block hash. The rest should be recoverable from the state.

It used by the light clients as a starting state. @tomaka should be better at explaining for what this is actually required.

@andresilva
Copy link
Contributor

It's used by smoldot to start syncing from this checkpoint, on substrate only the code to export the sync state exists. This was written before warp sync was implemented on smoldot so maybe it's not super relevant anymore.

Also, the light client does not really need to have epochs and authorities in the chain spec. All that's needed is a trusted finalized block hash. The rest should be recoverable from the state.

I think when this was written there was no easy way to get this data from the runtime, I agree that now if we still want to have a checkpoint for light clients to start syncing we only need to provide finalized block hash, we can even start warp syncing from such a block. Since this is used by smoldot currently I'll defer to @tomaka on what to do right now.

@tomaka
Copy link
Contributor

tomaka commented Aug 4, 2021

The light sync state was "designed" and added before Grandpa warp sync existed.

At the time, we were also trying as much as possible to avoid having to do runtime calls in the light client (as this makes the light client binary size much larger than otherwise, and requires downloading the runtime code from the network). For this reason, retrieving the Babe epoch and finalized authorities from the state wasn't really a good solution.

Nowadays, yes we probably just need a finalized block hash. However, knowing the list of Grandpa authorities of this finalized block is necessary in order to verify the warp syncing. This list could also be retrieved from the network, but this adds some latency and most importantly we run the risk that all the nodes of the network have already pruned the block and are incapable of giving us that list.

@bkchr
Copy link
Member Author

bkchr commented Aug 4, 2021

So, you would like to keep it @tomaka?

@tomaka
Copy link
Contributor

tomaka commented Aug 4, 2021

Right now, this light sync state contains what a light client needs in order to start syncing from a certain block.

We could remove the Babe-related stuff from the light sync state, but keep the Grandpa-related stuff, in which case the light sync state would contain what a light client needs in order to warp sync from a certain block.

If we remove also the Grandpa-related stuff and keep only a finalized block header or hash, then we risk that everyone on the network has pruned the block, and/or that we make lots of useless network requests trying to find a node that hasn't. This is too much removal IMO.

Smoldot can accommodate any of the three, I don't care, but I'd be leaning towards removing the Babe stuff. But keep in mind that having everything needed in order to immediately start syncing (without doing any warp sync) might also be desirable in the absolute.

@bkchr
Copy link
Member Author

bkchr commented Aug 4, 2021

Okay, then I'm going with keeping it as is for now.

@bkchr
Copy link
Member Author

bkchr commented Aug 4, 2021

bot merge

@ghost
Copy link

ghost commented Aug 4, 2021

Trying merge.

@ghost ghost merged commit b7409a2 into master Aug 4, 2021
@ghost ghost deleted the bkchr-decouple-sync-state branch August 4, 2021 13:38
ghost pushed a commit to paritytech/polkadot that referenced this pull request Aug 4, 2021
* Substrate companion #9491

paritytech/substrate#9491

* update Substrate

* Fix build

Co-authored-by: parity-processbot <>
@apopiak
Copy link
Contributor

apopiak commented Aug 16, 2021

Could it be that a Cumulus companion is missing for this?

apopiak added a commit to paritytech/cumulus that referenced this pull request Aug 16, 2021
apopiak added a commit to paritytech/cumulus that referenced this pull request Aug 16, 2021
bkchr pushed a commit to paritytech/cumulus that referenced this pull request Aug 17, 2021
bkchr pushed a commit to paritytech/cumulus that referenced this pull request Aug 17, 2021
slumber pushed a commit to paritytech/cumulus that referenced this pull request Sep 1, 2021
WebWizrd8 added a commit to WebWizrd8/cumulus that referenced this pull request Nov 21, 2022
ggwpez pushed a commit to ggwpez/runtimes that referenced this pull request Mar 10, 2023
* Substrate companion #9491

paritytech/substrate#9491

* update Substrate

* Fix build

Co-authored-by: parity-processbot <>
ggwpez pushed a commit to ggwpez/runtimes that referenced this pull request Mar 10, 2023
ggwpez pushed a commit to ggwpez/runtimes that referenced this pull request Mar 14, 2023
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decouple sc-chain-spec from the consensuses
5 participants