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

Finish implementing state_version = 1 #230

Merged
merged 27 commits into from
Feb 27, 2023
Merged

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Feb 26, 2023

Close #221

This PR finishes the implementation of the state_version = 1 feature, also known as the trie v1.

This hasn't been tested thoroughly. However, the code for trie v0 and trie v1 is the same everywhere (the version is a value that can be either 0 or 1) except for the trie node encoding code which is known to work. For this reason, I have high confidence that it should work, in the sense that I don't see what could not work.

In terms of logic, each entry in the storage now has a "trie entry version" attached to it, whose value is either 0 or 1. Whenever a storage value is written, the corresponding trie entry version is indicated. When the storage value is retrieved, the trie entry version must be provided back. Note that providing the version back is only necessary for runtime_host and not for read_only_runtime_host, as the latter never needs to calculate any trie hash.

In terms of API, the biggest changes are:

  • The StorageDiff struct now attaches a value to each entry in the diff, and has a template parameter indicating the type of this value. Often it's StorageDiff<()> that is used, but in optimistic.rs it's a StorageDiff<TrieEntryVersion>.
  • StorageGet::inject_value must be passed the version of the storage entry.
  • I've also modified the trie node generation code to only require passing a version if the value is Some, because if there is no value then the version doesn't matter. This change solves a couple of weird cases where we passed a dummy version.
  • CoreVersionRef::state_version is now a TrieEntryVersion (an enum which can be either V0 or V1) instead of a u8.

This PR breaks the database format of the full node and the database must be purged. Given that the full node is experimental, I don't want to bother with a migration system at the moment, even though the migration would be quite easy here.

@github-actions
Copy link

github-actions bot commented Feb 26, 2023

twiggy diff report

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


 Delta Bytes │ Item
─────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
     +116592 ┊ smoldot_light::json_rpc_service::Background<TPlat>::handle_request::{{closure}}::h354614e8647ea4b0
     -116353 ┊ smoldot_light::json_rpc_service::Background<TPlat>::handle_request::{{closure}}::hc1636df6a9c0f7ef
      +50760 ┊ smoldot::executor::host::ReadyToRun::run_once::h7105369fdf0ee096
      -50644 ┊ smoldot::executor::host::ReadyToRun::run_once::h3b55e4f15cd7ab33
      -47476 ┊ smoldot::json_rpc::methods::MethodCall::from_defs::h221fcef22eae4df9
      +47476 ┊ smoldot::json_rpc::methods::MethodCall::from_defs::he05a081607954ce7
      +14119 ┊ <core::panic::unwind_safe::AssertUnwindSafe<F> as core::future::future::Future>::poll::h82c9353904d1f98e
      -14056 ┊ <core::panic::unwind_safe::AssertUnwindSafe<F> as core::future::future::Future>::poll::hea5634d9a9f49c1e
      +13105 ┊ smoldot_light::transactions_service::background_task::{{closure}}::had59ac94cb327f0f
      -13105 ┊ smoldot_light::transactions_service::background_task::{{closure}}::hff4eafe8e0ed633b
      -11934 ┊ futures_util::abortable::Abortable<T>::try_poll::hc35dc33d67a4a751
      +11926 ┊ futures_util::abortable::Abortable<T>::try_poll::h0eeccfa25139fb73
      -11707 ┊ smoldot::executor::vm::interpreter::InterpreterPrototype::new::h68b89f67941f02d2
      +11707 ┊ smoldot::executor::vm::interpreter::InterpreterPrototype::new::hfe5b75c25c394872
      +11594 ┊ smoldot_light::sync_service::standalone::start_standalone_chain::{{closure}}::h6ef1ab787ad52d1f
      -11591 ┊ smoldot_light::sync_service::standalone::start_standalone_chain::{{closure}}::h4d93918e2a0b195d
      +11392 ┊ smoldot_light::json_rpc_service::chain_head::<impl smoldot_light::json_rpc_service::Background<TPlat>>::chain_head_call::{{closure}}::{{closure}}::he3fd13bad32771e9
      -11359 ┊ smoldot_light::json_rpc_service::chain_head::<impl smoldot_light::json_rpc_service::Background<TPlat>>::chain_head_call::{{closure}}::{{closure}}::hf216509515c63d0c
      -10949 ┊ smoldot_light::Client<TPlat,TChain>::add_chain::h92afc42f3545863b
      +10949 ┊ smoldot_light::Client<TPlat,TChain>::add_chain::hbe0adeeab4ab9ecf
       +1288 ┊ ... and 26105 more.
       +6414 ┊ Σ [26125 Total Rows]

@tomaka tomaka added this pull request to the merge queue Feb 27, 2023
Merged via the queue into smol-dot:main with commit 81820de Feb 27, 2023
@tomaka tomaka deleted the trie-v1-finish branch February 27, 2023 10:12
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.

TrieVersion 1 supported?
1 participant