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

Make triecache generic and work for no-std environments #14403

Merged
merged 26 commits into from
Jun 28, 2023

Conversation

skunert
Copy link
Contributor

@skunert skunert commented Jun 16, 2023

This pull request refactors the trie-cache related traits and makes the system generic. Until now the caching system was bound to the LocalTrieCache implementation. This is one step towards enabling the TrieCache in validate_block paritytech/cumulus#2432.

This refactoring contains no behavioural changes for existing code.

Change summary:

  • New trait MergeableTrieCacheProvider: This trait can be implemented to provide cache implementations to the TrieBackend
  • Removal of AsLocalTrieCache trait: No longer required since functionality is covered by MergeableTrieCacheProvider
  • Include unimplemented cache for no std to keep compatibility. The actual cache implementation will go into cumulus.

Polkadot companion: paritytech/polkadot#7435

@skunert skunert 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 Jun 16, 2023
@skunert skunert requested a review from a team June 16, 2023 11:06
primitives/state-machine/Cargo.toml Outdated Show resolved Hide resolved
primitives/state-machine/src/trie_backend.rs Outdated Show resolved Hide resolved
primitives/state-machine/src/trie_backend.rs Outdated Show resolved Hide resolved
primitives/state-machine/src/trie_backend.rs Outdated Show resolved Hide resolved
primitives/state-machine/src/trie_backend.rs Outdated Show resolved Hide resolved
primitives/state-machine/src/trie_backend.rs Outdated Show resolved Hide resolved
primitives/state-machine/src/trie_backend_essence.rs Outdated Show resolved Hide resolved
@skunert
Copy link
Contributor Author

skunert commented Jun 20, 2023

bot fmt

@command-bot
Copy link

command-bot bot commented Jun 20, 2023

@skunert https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3028934 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 5-d8d9329e-2ccf-47cc-b29a-cdd20dcc2fd0 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Jun 20, 2023

@skunert Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3028934 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3028934/artifacts/download.

@skunert skunert requested a review from a team June 26, 2023 15:17
primitives/state-machine/src/trie_backend.rs Outdated Show resolved Hide resolved
primitives/state-machine/src/trie_backend.rs Outdated Show resolved Hide resolved
primitives/state-machine/src/trie_backend_essence.rs Outdated Show resolved Hide resolved
}

/// Create new trie-based backend.
pub fn new_with_cache(storage: S, root: H::Out, cache: Option<C>) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could simplify TrieBackendEssence::new by calling this method in there. (Self::new_with_cache(storage, root, None) instead of having the whole struct initialized in two places)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also third copy below could be initialized with new.

primitives/state-machine/src/trie_backend.rs Outdated Show resolved Hide resolved
primitives/state-machine/Cargo.toml Outdated Show resolved Hide resolved
@skunert
Copy link
Contributor Author

skunert commented Jun 28, 2023

bot merge

@paritytech-processbot paritytech-processbot bot merged commit e354ae9 into paritytech:master Jun 28, 2023
4 checks passed
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
…4403)

* Remove `AsLocalTrieCache` trait

* Introduce new trait AsTrieDbCache

* Use AsTrieDbCache trait

* Make it compile

* Docs

* Improve naming of associated type, implement cache usage for no-std

* Improve naming

* Improve docs

* Allow construction with optional cache

* FMT

* Remove unused variable

* Revert unwanted change

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

* More comment adjustments

* Docs

* Trigger CI

* ".git/.scripts/commands/fmt/fmt.sh"

* Apply suggestions from code review

Co-authored-by: Koute <[email protected]>

* Review comments

* Review comments

* Apply suggestions from code review

Co-authored-by: Michal Kucharczyk <[email protected]>

* fmt

* Bump trie-db again

---------

Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: command-bot <>
Co-authored-by: Koute <[email protected]>
Co-authored-by: Michal Kucharczyk <[email protected]>
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
Status: done
Development

Successfully merging this pull request may close these issues.

4 participants