-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Light Client: Implement checkpoints in chain_spec to speed up syncing #6804
Comments
I'm fairly interested in the snapshotting. Distributing and fetching the snapshots seems like something we could use bitswap (#6795) for. |
@andresilva I could do with some mentoring for the snapshot implementation. Do you think you could sketch out a vague plan? |
I don't know much about the light client implementation to be able to mentor you on this. Here's my very high-level view of what needs to be done:
The light client in substrate was mostly implemented by @svyatonik (@cheme might have some ideas as well as he has an open PR to fix something in the CHT). The light client in parity-ethereum was implemented by @rphmeier iirc. |
From what I looked, it is mainly cht (need to save the root that is in CHT column and all unpruned headers (HEADER column), a mapping for accessing header is also needed (KEY_LOOKUP column) but it can easily be deduced from headers so only needed when loading. Checking client/db/src/light.rs gives a good idea. And next as Andre said, there is the question of skiping the sync of the previous block which if the whole state is loaded should work as long as snapshot loading is done before starting sync (will also need to save also some datas from META column : best_block , last_finalized, as used by client/db/src/light.rs). But here I am not sure what are the best way to do thing (same for building snapshot, it should be easier from a light client instance, same for loading snapshot where I would simply define it in the chain_spec but there is probably smarter way to do it). I would feel like both saving and loading snapshot should be done in a cold state (iirc eth got a command to produce it), loading can be done before loading other substrate component (except those needed to fetch the snaps). |
@arkpar What would be your suggestion for how to do this? |
Sync always starts with the current best block. As @cheme mentioned, snapshot restoration should set the metadata to whatever has been restored from the snapshot before starting sync. This includes |
What do you mean by 'etc'? Everything in |
And where should I plug these values into? |
Everything that's written into substrate/client/db/src/light.rs Line 115 in 9f99d5f
|
Unless there exists a need for the light client to fetch the storage or get information about old blocks, which I don't think there is, I would suggest to completely give up with CHTs and MMRs. As the opening post mentions, we only need two things:
There seems to have been a lot of misunderstandings in all these discussions on Riot. |
Yes, and warp-syncing GRANDPA is only needed as an improvement over the hardcoded sync. It addresses 3 issues of hardcoded sync:
|
I've gotten the header to load from the chain spec okay, but I'm getting an error from BABE and it's not syncing: I believe this could be to do with the keys that @cheme mentions above: #6804 (comment). |
Ok, so this is failing because substrate/client/consensus/epochs/src/lib.rs Lines 540 to 550 in ccd06f0
Ok(None) . I don't know this code at all well, but I imagine that the solution is to store some sort of epoch information in the sync state. You can checkout the branch at ashley-load-sync-state .
|
Context:
The way it's currently implemented, the light client needs to sync all blocks from genesis, which, depending on the number of blocks and the environment the light client is running in, can easily take more than 24h for chains with a slightly larger number of blocks.
This will make the light client basically un-useable for occasional or one-time users who don't keep a synced version of their selected chain in the IndexedDB.
Goal
Get initial sync duration of the Light Client down to 60sec.
Proposed solution:
snapshotsin the chainspec (like we did on parity-ethereum / open-ethereum //by @andresilva )The text was updated successfully, but these errors were encountered: