This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
avoid key collision on child trie and proof on child trie #2209
Closed
Closed
Changes from 1 commit
Commits
Show all changes
142 commits
Select commit
Hold shift + click to select a range
f6c4bb2
Straight forward move of trie related only change from child-trie-soft
cheme 878a7ae
merge backend stuff from old branch, add insertion of child trie root in
cheme a464936
commit before wasm_executor change (we will keep old interface for now:
cheme 4de73d7
tabify
cheme be0e340
Things compile (account change is unoptimized), not for wasm.
cheme 7f3a282
Make SutrieField non public
cheme 4d208db
Compile no std child trie with subtrie query (super costy: do we trust
cheme 6d7f355
Make the single child trie test pass.
cheme 25bcb4c
Proving synch child trie content (TODO it requires deletion tests).
cheme 9eaef35
restore test
cheme 37d9536
Merge branch 'master' into child-trie-soft-min
cheme 67c03a2
Fix test error (wrong vec alloc).
cheme 99dbb5a
tests for no key collision
cheme 3be1802
Merge branch 'master' into child-trie-soft-min
cheme fec73d0
Revert `storage_root` using child, create a variant for it: see
cheme 20d168d
indentation and remove comment
cheme d797bd0
Remove some TODOs, fix compile error
cheme 27096aa
plaindb does not need to be keyspaceddb
cheme 3560acc
Merge branch 'master' into child-trie-soft-min
cheme c3fc432
bump impl_version
cheme 3e417eb
Merge branch 'master' into child-trie-soft-min
cheme 5af490f
fix and 2299
cheme 5a8dddd
Merge branch 'master' into child-trie-soft-min
cheme 8f04f00
Merge branch 'master' into child-trie-soft-min
cheme 8051179
fix keyspace insert and start proof (missing in higher level test case a
cheme 8eac118
remove todo of test
cheme a65f9f2
Merge branch 'master' into child-trie-soft-min
cheme d495ef5
Merge branch 'master' into child-trie-soft-min &
cheme 197d77a
- refactor api, use noderef of read only query (require and additional
cheme 2ea3c89
Remove SubTrieNode struct
cheme 99c45ea
put extension in encoding/decoding properly
cheme 3553ab2
SubTrie struct renaming (and single encode point)
cheme 47984fe
remove contract prefix, and make use of a child trie prefix.
cheme 2bf2d7b
fix for overlay before reverting
cheme bc7165c
fix2 for prefix in overlay
cheme 21c3acf
revert (will probably need two variant, but for rpc pr)
cheme 98b2fc3
break some lines
cheme 432cb10
Merge branch 'master' into child-trie-soft-min
cheme e266dfe
Add module specific seed to generator (accountid is undefined)
cheme 7f64652
Update core/primitives/src/subtrie.rs
cheme 999a26e
Merge branch 'master' into child-trie-soft-min and adapt rpc test
cheme 7bbd681
Merge branch 'child-trie-soft-min' of github.com:cheme/substrate into…
cheme 87f03b7
child trie additional prefix is bad design for primitive, removing it.
cheme f18e002
safer encoding of version.
cheme 0eaeca0
Merge branch 'master' into child-trie-soft-min (untested)
cheme b57319d
missing import
cheme 1f848d2
bump impl version
cheme 403df51
Merge branch 'master' into child-trie-soft-min
cheme 305b60a
Merge branch 'master' into child-trie-soft-min
cheme 423cfb1
correct version
cheme a0ffa31
fix typing
cheme 6e3bed7
Merge branch 'master' into child-trie-soft-min
cheme 7411146
misnamed storage key variables.
cheme 331be51
fix error messages.
cheme bc2935c
remove convenience constructor, remove unneeded pub on field.
cheme 5a87b6a
Merge branch 'master' into child-trie-soft-min
cheme f40400b
minor tweaks before reworking docs
cheme 9bc1ab7
First pass of documentation improvement.
cheme c073b21
do not refer to parent_key when it is ParentTrie:
cheme d15ca49
child trie renaming did exceed 100 character line.
cheme 0736b96
Link github issue for TODOs
cheme 9e0485d
Merge branch 'master' into child-trie-soft-min
cheme 586b50e
comment incorrect variable
cheme 65d7485
Merge branch 'master' into child-trie-soft-min
cheme 95a69b2
Makes child trie instantiation a bisschen more explicit.
cheme d089693
Merge branch 'master' into child-trie-soft-min
cheme ec69ae0
rename fetch and init trie function.
cheme 76ea14d
moved_child is a bad idea, just delete in top, if it is reinserted this
cheme b2050c8
moved map is correct (fix usage of child trie to return option<option<)
cheme 5a0cbe1
Add missing wasm boilerplate.
cheme 6e84810
remove moved_ct from overlay in favor to optional in pending.
cheme 7f5694f
Merge branch 'master' into child-trie-soft-min
cheme 5006d73
Use keyspace for storage_cache.
cheme b85508e
Comment of unsafety of `set_child` if directly exposed.
cheme 0c14777
Merge branch 'master' into child-trie-soft-min
cheme 10c4f58
use named fields.
cheme 453927b
Merge branch 'master' into child-trie-soft-min
cheme 349f9a5
Merge branch 'master' into child-trie-soft-min
cheme fc034fb
Refacto of keyspace to use static creation unique info.
cheme 45cfbd6
put child trie content under their own prefix (with common root with
cheme 4f9717e
Revert to storing keyspace in state approach.
cheme 7cb2d84
invalid asumption for `child_delta_trie_root`.
cheme c821a08
clean unused child storage key relative methods.
cheme c3ba830
Merge branch 'master' into child-trie-soft-min and
cheme acf9641
invalid comment
cheme 0050457
indent and remove deprecated comments/struct
cheme c36b91b
Make top trie write through keyspace db, this is not going fine because
cheme 9d3d9e2
Fix issue: prefixed_key already got the keyspace in prefix.
cheme 3db4da8
Merge branch 'master' into child-trie-soft-min
cheme 4348d70
Address review comment:
cheme 134a4bf
Merge branch 'master' into child-trie-soft-min
cheme 5325621
Restore auth version.
cheme 97118e8
Avoid confusing Option<Option< in result return of overlay.
cheme 0ed7f80
Missing fix from review on testing ext for set child trie (code from
cheme 8a6986a
Use fields for change trie storage.
cheme 7652de9
switch MapTransaction to a struct.
cheme 94c629e
Merge branch 'master' into child-trie-soft-min
cheme 7675740
Apply same encoding for parent root (compatible with implementation of a
cheme 90fba8a
Fix previous cherry pick
cheme d8c58c6
Addressing nits.
cheme 661ba2e
Avoid unused creation of child trie.
cheme 833e9ff
Create child trie id from additional storage state.
cheme 71bda12
update default encoding.
cheme 08b3062
Handle possible switch to multiple trie layer.
cheme 89f3cd5
Remove a redundancy on keyspaceddb instantiation.
cheme 834f52a
actually remove redundancy correctly
cheme 0445228
comment
cheme 75add99
Merge branch 'child-trie-soft-min-old' into child-trie-soft-min
cheme e70edab
Merge branch 'master' into child-trie-soft-min and apply review
cheme b8a0cd4
Merge branch 'master' into child-trie-soft-min
cheme 1514171
Merge branch 'master' into child-trie-soft-min
cheme a7da811
Fix new test cases.
cheme b96c523
Merge branch 'master' into child-trie-soft-min
cheme 865672d
Merge branch 'master' into child-trie-soft-min
cheme b6d7705
bump runtime version
cheme b45344c
Merge branch 'master' into child-trie-soft-min
cheme 517f95c
Merge branch 'master' into child-trie-soft-min
cheme 79a07de
Merge branch 'master' into child-trie-soft-min
cheme a027fb0
Some doc enhancement.
cheme b92655c
ChildRead correctly defined (previous definition was wrong).
cheme 8a875f4
child_trie 'is_updatable_with' to avoid already broken redundancy.
cheme fcd8bdb
fix system bench error.
cheme 3241fc4
Fix client doc rust code.
cheme ecac03b
Merge branch 'master' into child-trie-soft-min
cheme 10369b9
Merge branch 'master' into child-trie-soft-min
cheme 15a2967
Merge branch 'master' into child-trie-soft-min
cheme acc94e4
Merge branch 'master' into child-trie-soft-min
cheme 7d96338
Remove unused method (in favor of assimilate).
cheme ba7bdcb
Merge branch 'child-trie-soft-min' of github.com:cheme/polkadot into …
cheme aacea85
Merge branch 'master' into child-trie-soft-min
cheme 6789641
merge fix.
cheme 2b37160
Rename MapTransaction to StorageContent.
cheme b1183bd
Get subscription stuff from child-deletion branch:
cheme bc5653c
Merge branch 'master' into child-trie-soft-min
cheme 5ecfd19
update to master.
cheme baf89c8
Cast explicitelly for readability.
cheme 0f8bff9
bump spec version.
cheme 5a8576b
Merge branch 'master' into child-trie-soft-min
cheme 045ee32
Merge branch 'master' into child-trie-soft-min
cheme 58e6e41
Fix compilation.
cheme 70555c5
Merge branch 'master' into child-trie-soft-min with conflicts.
cheme 130e5e4
build passing, regression on extrinsics for a set_child (see new TODO).
cheme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Merge branch 'master' into child-trie-soft-min and
state prefix and kvdb prefix confusion fix: - revert change on state prefix - add default db prefix on all keyvalue (break db exept if using legacy feature, but then child trie are not usable). - child prefix got a first byte to differ from default
- Loading branch information
commit c3ba830e310763ca38ca36eaa23d4882591c0130
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,6 @@ use parity_codec::{Encode, Decode}; | |
| use rstd::prelude::*; | ||
| use rstd::ptr; | ||
| use crate::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX; | ||
| use crate::storage::well_known_keys::CHILD_STORAGE_CONTENT_PREFIX; | ||
| #[cfg(feature = "std")] | ||
| pub use impl_serde::serialize as bytes; | ||
|
|
||
|
|
@@ -31,38 +30,55 @@ pub use impl_serde::serialize as bytes; | |
| /// this child trie. | ||
| /// The `KeySpace` of a child trie must be unique for the canonical chain | ||
| /// in order to avoid key collision at a key value database level. | ||
| /// This is currently build by using the `ParentTrie` path of the child trie | ||
| /// at its creation and the block number at its creation (a child trie | ||
| /// when new if moved must therefore update its keyspace). | ||
| /// Child trie variant (start with 1u8), is currently build by using the `ParentTrie` | ||
| /// path of the child trie at its creation and the block number at its creation | ||
| /// (only child trie in their creation block need to update this value when moved). | ||
| /// No keyspace variant is only 0u8. | ||
| /// This id is unique as for a block number state we cannot have | ||
| /// two created child trie with the same `ParentTrie`. | ||
| pub type KeySpace = Vec<u8>; | ||
|
|
||
| /// Parent trie origin. This type contains all information | ||
| /// needed to access a parent trie. | ||
| /// Currently only a single depth is supported for child trie, | ||
| /// so it only contains the top trie key to the child trie. | ||
| /// Internally this contains a full path key (with | ||
| /// `well_known_keys::CHILD_STORAGE_KEY_PREFIX`). | ||
| pub type ParentTrie = Vec<u8>; | ||
|
|
||
| /// Keyspace to use for the parent trie key. | ||
| pub const NO_CHILD_KEYSPACE: [u8;1] = [0u8]; | ||
| const CHILD_KEYSPACE_HEAD: u8 = 1; | ||
|
|
||
| // see FIXME #2741 for removal of this allocation on every operation. | ||
| // (the PrefixedDB one is enough). Method could be to pass mutable | ||
| // vector to `KeyFunction` and have an new key function to estimate | ||
| // required additional allocation size. | ||
| /// Generate a new keyspace for a child trie. | ||
| pub fn generate_keyspace<N: Encode>(block_nb: &N, parent_trie: &ParentTrie) -> Vec<u8> { | ||
| // using 9 for block number and additional encoding targeting ~u64 | ||
|
||
| let mut result = Vec::with_capacity(parent_trie.len() + 9); | ||
| result.push(CHILD_KEYSPACE_HEAD); // 1 first value if there is a keyspace ( | ||
| parity_codec::Encode::encode_to(ChildTrie::parent_key_slice(parent_trie), &mut result); | ||
| parity_codec::Encode::encode_to(block_nb, &mut result); | ||
| result | ||
| } | ||
|
|
||
| /// Utility function used for merging `KeySpace` data and `prefix` data | ||
| /// before calling key value database primitives. | ||
| /// Note that it currently does a costy append operation resulting in bigger | ||
jimpo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// key length but possibly allowing prefix related operation at lower level. | ||
| /// Note that we also append a common prefix to avoid general state key to | ||
| /// conflict (if the KeySpace gets build from a strong cryptographic hash | ||
| /// in the future, or if general state get written with empty keyspace, | ||
| /// this would be useless). | ||
| pub fn keyspace_as_prefix_alloc(ks: &KeySpace, prefix: &[u8]) -> Vec<u8> { | ||
| let pre = CHILD_STORAGE_CONTENT_PREFIX; | ||
| let mut res = rstd::vec![0; pre.len() + ks.len() + prefix.len()]; | ||
| res[..pre.len()].copy_from_slice(&pre); | ||
| res[pre.len()..pre.len() + ks.len()].copy_from_slice(&ks); | ||
| res[pre.len() + ks.len()..].copy_from_slice(prefix); | ||
| let n_pre_len = NO_CHILD_KEYSPACE.len(); | ||
| // only use on prefixed db where NO_CHILD_KEYSPACE is added. | ||
| debug_assert!(prefix.len() >= n_pre_len); | ||
| let mut res = rstd::vec![0; ks.len() + prefix.len() - n_pre_len]; | ||
| res[..ks.len()].copy_from_slice(&ks); | ||
| res[ks.len()..].copy_from_slice(&prefix[n_pre_len..]); | ||
| res | ||
| } | ||
|
|
||
| /// Parent trie origin. This type contains all information | ||
| /// needed to access a parent trie. | ||
| /// Currently only a single depth is supported for child trie, | ||
| /// so it only contains the top trie key to the child trie. | ||
| /// Internally this contains a full path key (with | ||
| /// `well_known_keys::CHILD_STORAGE_KEY_PREFIX`). | ||
| pub type ParentTrie = Vec<u8>; | ||
|
|
||
| /// `ChildTrieReadRef` contains a reference to information | ||
| /// needed to access a child trie content. | ||
| /// Generally this should not be build directly but accessed | ||
|
|
@@ -339,12 +355,3 @@ impl AsRef<ChildTrie> for ChildTrie { | |
| self | ||
| } | ||
| } | ||
|
|
||
| /// generate a new keyspace | ||
| pub fn generate_keyspace<N: Encode>(block_nb: &N, parent_trie: &ParentTrie) -> Vec<u8> { | ||
| // using 8 for block number and additianal encoding targeting ~u64 | ||
| let mut result = Vec::with_capacity(parent_trie.len() + 8); | ||
| parity_codec::Encode::encode_to(ChildTrie::parent_key_slice(parent_trie), &mut result); | ||
| parity_codec::Encode::encode_to(block_nb, &mut result); | ||
| result | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
You are viewing a condensed version of this merge commit. You can view the full changes here.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing should be that with this PR child trie primitive should not allow (should not) to build something out of this well known key. So I kept the condition to on writing a direct k/v to this prefix but not the other one..
I also totally delete this condition of core/client/db/src/lib.rs
reset_storagefunction (for the same reason).I am not sure how things could be misuse, (I kept this debug_assert just in case)