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

Add child tries support in host.rs #167

Merged
merged 15 commits into from Feb 14, 2023
Merged

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Feb 11, 2023

cc #166

This PR is the first step towards support for child tries in the VM.

While in Substrate child tries support is I believe handled by the "storage layer", in smoldot I prefer to make things clear and explicit.
For example, if the Wasm code reads the storage key :child_storage:default:foo, I don't emit a ExternalStorageGet variant but instead a ExternalStorageRoot variant with "foo" as the trie. Similarly, if the Wasm code calls ext_storage_next_key_version_1 with :child_storage:default:foo, I emit a ExternalStorageNextChildTrie variant.

Only default child storages are supported, as this is the only kind of child tries that exist at the moment (and in the foreseeable future).

After this PR, child tries don't work yet. There is a lot of effort remaining to implement support for them especially in runtime_host.rs (which is the code that handles the storage diff while the call is in progress, including things like storage transactions). However, this PR does a big chunk of the work by designing an API for them.

@github-actions
Copy link

github-actions bot commented Feb 11, 2023

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼───────────────────────────────────────────────────────────────────────────────────────
      +52267 ┊ smoldot::executor::host::ReadyToRun::run_once::h1c16150c21dac4c1
      -40639 ┊ smoldot::executor::host::ReadyToRun::run_once::h043d454b780bb679
       +2149 ┊ smoldot::executor::host::SignatureVerification::is_valid::h60e8da940c010813
       -2149 ┊ smoldot::executor::host::SignatureVerification::is_valid::hd4550138c0d2cc73
       -1117 ┊ <smoldot::executor::host::Error as core::fmt::Debug>::fmt::h6802949990fa4809
       +1117 ┊ <smoldot::executor::host::Error as core::fmt::Debug>::fmt::h851758aab05a14a6
       -1031 ┊ smoldot::executor::host::Inner::alloc_write_and_return_pointer_size::h02e51662736730bb
       +1031 ┊ smoldot::executor::host::Inner::alloc_write_and_return_pointer_size::h20f5aa4067f4cab1
        -819 ┊ smoldot::executor::host::ExternalStorageGet::resume_vectored::h6100153d7314490a
        +814 ┊ smoldot::executor::host::ExternalStorageGet::resume_vectored::h5b19ed326ba45e6b
        +797 ┊ smoldot::executor::host::ExternalStorageNextKey::resume::h9a3467cc3b307af3
        +792 ┊ smoldot::executor::host::HostVm::into_prototype::h617f2a5958a059b9
        +772 ┊ <smoldot::executor::host::LogEmit as core::fmt::Display>::fmt::h7326e766e1487a05
        -772 ┊ <smoldot::executor::host::LogEmit as core::fmt::Display>::fmt::hbf83331a1b1b4795
        +733 ┊ smoldot::executor::host::Inner::alloc_write_and_return_pointer_size::h7ff358985579e8b6
        +723 ┊ smoldot::executor::host::Inner::alloc_write_and_return_pointer_size::h65dd9c2780141c13
        -723 ┊ smoldot::executor::host::Inner::alloc_write_and_return_pointer_size::hd09c6130705981ba
        -720 ┊ smoldot::executor::host::HostVm::into_prototype::ha513330f6bb8ca1f
        +704 ┊ data[0]
        +654 ┊ smoldot::executor::read_only_runtime_host::Inner::run::h09faf6768c99a783
       +4737 ┊ ... and 119 more.
      +21760 ┊ Σ [139 Total Rows]

@tomaka
Copy link
Contributor Author

tomaka commented Feb 12, 2023

Note that the design of child tries is a complete clusterfuck full of unspecified corner cases.
It is likely that this PR has some mistakes.
Given the insane amount of time that it would take me to figure out what happens in these corner cases, I'll open an issue afterwards instead.

@tomaka tomaka marked this pull request as ready for review February 12, 2023 10:57
@tomaka tomaka added this pull request to the merge queue Feb 14, 2023
Merged via the queue into smol-dot:main with commit 77bdd60 Feb 14, 2023
@tomaka tomaka deleted the child-tries-host branch February 14, 2023 07:50
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.

None yet

1 participant