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

Store the runtime code in the light client database #863

Merged
merged 7 commits into from
Jul 8, 2023

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Jul 6, 2023

Close #92

As explained in #92, we can't just store the runtime code in the database (doing so would require #177), but the Merkle value of the trie node and the closest ancestor.

When the database is loaded back, the warp syncing queries said closest ancestor and compares the Merkle value of the relevant children with the one in the database.

In practice, the storage query is thus now only around 850 bytes, compared to ~1.0 to 1.5 MiB beforehand.
While this "only" saves around 300ms on my machine, I can imagine that people with not-so-good Internet connections will be happy.

I'm not super-super happy with the changes in the code, and I've added all these fields while having in mind that they will be removed again after #177, but they're also not too bad.

@@ -620,9 +659,24 @@ impl<TSrc, TRq> InProgressWarpSync<TSrc, TRq> {
let runtime_parameters_get = if let Phase::RuntimeDownload {
header,
warp_sync_source_id,
hint_doesnt_match,
downloaded_runtime: None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This specific line fixes a bug mentioned in the CHANGELOG where the warp syncing downloads the runtime code twice.

@tomaka tomaka added this pull request to the merge queue Jul 8, 2023
Merged via the queue into smol-dot:main with commit 88d197f Jul 8, 2023
20 checks passed
@tomaka tomaka deleted the code-merkle-value-db branch July 8, 2023 17:57
@pgolovkin
Copy link

Is this caching works if I run the light client using the substrate-connect library?

@tomaka
Copy link
Contributor Author

tomaka commented Jul 10, 2023

That's more a question for substrate-connect, but yes for the 4 well-known chains (once substrate-connect has upgraded their smoldot of course).
The database is shared through the substrate-connect extension, so if you connect to Polkadot on one website, then connect to Polkadot on a different website, it will use what it has downloaded on the first one.

@pgolovkin
Copy link

Do I understand correct that even if I don't have substrate-connect extension (I'm using the Electron environment) the latest state of the smoldot will be saved and when I run my Electron application next time this saved state will be used?

The example:
Given that:

  1. Electron application with the substrate-connect
  2. Polkadot latest chainspec in the smoldot (for example) with the latest block number 16342124

User actions:

  1. The user runs the Electron application
  2. Light client is started and synching
  3. The user quits the Electron application, the latest synched block is 16342301
  4. In a few hours the user starts the Electron application again

The question:
After starting the application (item 4) the Light Client will be synching from the block 16342301?

@tomaka
Copy link
Contributor Author

tomaka commented Jul 11, 2023

Substrate-connect is kind of pointless if you don't have the extension, and I would suggest to directly use smoldot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add finalized block runtime code and heappages to wasm node database
2 participants