Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
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 Mar 26, 2019
878a7ae
merge backend stuff from old branch, add insertion of child trie root in
cheme Mar 26, 2019
a464936
commit before wasm_executor change (we will keep old interface for now:
cheme Mar 26, 2019
4de73d7
tabify
cheme Mar 26, 2019
be0e340
Things compile (account change is unoptimized), not for wasm.
cheme Mar 26, 2019
7f3a282
Make SutrieField non public
cheme Mar 27, 2019
4d208db
Compile no std child trie with subtrie query (super costy: do we trust
cheme Mar 27, 2019
6d7f355
Make the single child trie test pass.
cheme Mar 27, 2019
25bcb4c
Proving synch child trie content (TODO it requires deletion tests).
cheme Mar 28, 2019
9eaef35
restore test
cheme Apr 1, 2019
37d9536
Merge branch 'master' into child-trie-soft-min
cheme Apr 1, 2019
67c03a2
Fix test error (wrong vec alloc).
cheme Apr 2, 2019
99dbb5a
tests for no key collision
cheme Apr 3, 2019
3be1802
Merge branch 'master' into child-trie-soft-min
cheme Apr 3, 2019
fec73d0
Revert `storage_root` using child, create a variant for it: see
cheme Apr 4, 2019
20d168d
indentation and remove comment
cheme Apr 4, 2019
d797bd0
Remove some TODOs, fix compile error
cheme Apr 4, 2019
27096aa
plaindb does not need to be keyspaceddb
cheme Apr 4, 2019
3560acc
Merge branch 'master' into child-trie-soft-min
cheme Apr 5, 2019
c3fc432
bump impl_version
cheme Apr 8, 2019
3e417eb
Merge branch 'master' into child-trie-soft-min
cheme Apr 16, 2019
5af490f
fix and 2299
cheme Apr 16, 2019
5a8dddd
Merge branch 'master' into child-trie-soft-min
cheme Apr 16, 2019
8f04f00
Merge branch 'master' into child-trie-soft-min
cheme Apr 26, 2019
8051179
fix keyspace insert and start proof (missing in higher level test case a
cheme Apr 29, 2019
8eac118
remove todo of test
cheme Apr 30, 2019
a65f9f2
Merge branch 'master' into child-trie-soft-min
cheme Apr 30, 2019
d495ef5
Merge branch 'master' into child-trie-soft-min &
cheme May 14, 2019
197d77a
- refactor api, use noderef of read only query (require and additional
cheme May 15, 2019
2ea3c89
Remove SubTrieNode struct
cheme May 16, 2019
99c45ea
put extension in encoding/decoding properly
cheme May 16, 2019
3553ab2
SubTrie struct renaming (and single encode point)
cheme May 16, 2019
47984fe
remove contract prefix, and make use of a child trie prefix.
cheme May 16, 2019
2bf2d7b
fix for overlay before reverting
cheme May 16, 2019
bc7165c
fix2 for prefix in overlay
cheme May 16, 2019
21c3acf
revert (will probably need two variant, but for rpc pr)
cheme May 16, 2019
98b2fc3
break some lines
cheme May 16, 2019
432cb10
Merge branch 'master' into child-trie-soft-min
cheme May 16, 2019
e266dfe
Add module specific seed to generator (accountid is undefined)
cheme May 16, 2019
7f64652
Update core/primitives/src/subtrie.rs
cheme May 17, 2019
999a26e
Merge branch 'master' into child-trie-soft-min and adapt rpc test
cheme May 21, 2019
7bbd681
Merge branch 'child-trie-soft-min' of github.com:cheme/substrate into…
cheme May 21, 2019
87f03b7
child trie additional prefix is bad design for primitive, removing it.
cheme May 21, 2019
f18e002
safer encoding of version.
cheme May 24, 2019
0eaeca0
Merge branch 'master' into child-trie-soft-min (untested)
cheme May 24, 2019
b57319d
missing import
cheme May 24, 2019
1f848d2
bump impl version
cheme May 24, 2019
403df51
Merge branch 'master' into child-trie-soft-min
cheme May 24, 2019
305b60a
Merge branch 'master' into child-trie-soft-min
cheme May 28, 2019
423cfb1
correct version
cheme May 28, 2019
a0ffa31
fix typing
cheme May 28, 2019
6e3bed7
Merge branch 'master' into child-trie-soft-min
cheme May 29, 2019
7411146
misnamed storage key variables.
cheme May 29, 2019
331be51
fix error messages.
cheme May 29, 2019
bc2935c
remove convenience constructor, remove unneeded pub on field.
cheme May 29, 2019
5a87b6a
Merge branch 'master' into child-trie-soft-min
cheme May 29, 2019
f40400b
minor tweaks before reworking docs
cheme May 30, 2019
9bc1ab7
First pass of documentation improvement.
cheme May 30, 2019
c073b21
do not refer to parent_key when it is ParentTrie:
cheme May 30, 2019
d15ca49
child trie renaming did exceed 100 character line.
cheme May 30, 2019
0736b96
Link github issue for TODOs
cheme May 31, 2019
9e0485d
Merge branch 'master' into child-trie-soft-min
cheme May 31, 2019
586b50e
comment incorrect variable
cheme May 31, 2019
65d7485
Merge branch 'master' into child-trie-soft-min
cheme Jun 6, 2019
95a69b2
Makes child trie instantiation a bisschen more explicit.
cheme Jun 6, 2019
d089693
Merge branch 'master' into child-trie-soft-min
cheme Jun 12, 2019
ec69ae0
rename fetch and init trie function.
cheme Jun 12, 2019
76ea14d
moved_child is a bad idea, just delete in top, if it is reinserted this
cheme Jun 14, 2019
b2050c8
moved map is correct (fix usage of child trie to return option<option<)
cheme Jun 14, 2019
5a0cbe1
Add missing wasm boilerplate.
cheme Jun 14, 2019
6e84810
remove moved_ct from overlay in favor to optional in pending.
cheme Jun 14, 2019
7f5694f
Merge branch 'master' into child-trie-soft-min
cheme Jun 14, 2019
5006d73
Use keyspace for storage_cache.
cheme Jun 17, 2019
b85508e
Comment of unsafety of `set_child` if directly exposed.
cheme Jun 17, 2019
0c14777
Merge branch 'master' into child-trie-soft-min
cheme Jun 17, 2019
10c4f58
use named fields.
cheme Jun 17, 2019
453927b
Merge branch 'master' into child-trie-soft-min
cheme Jun 21, 2019
349f9a5
Merge branch 'master' into child-trie-soft-min
cheme Jun 25, 2019
fc034fb
Refacto of keyspace to use static creation unique info.
cheme Jun 27, 2019
45cfbd6
put child trie content under their own prefix (with common root with
cheme Jun 28, 2019
4f9717e
Revert to storing keyspace in state approach.
cheme Jun 28, 2019
7cb2d84
invalid asumption for `child_delta_trie_root`.
cheme Jun 28, 2019
c821a08
clean unused child storage key relative methods.
cheme Jun 28, 2019
c3ba830
Merge branch 'master' into child-trie-soft-min and
cheme Jun 28, 2019
acf9641
invalid comment
cheme Jun 28, 2019
0050457
indent and remove deprecated comments/struct
cheme Jun 28, 2019
c36b91b
Make top trie write through keyspace db, this is not going fine because
cheme Jul 2, 2019
9d3d9e2
Fix issue: prefixed_key already got the keyspace in prefix.
cheme Jul 2, 2019
3db4da8
Merge branch 'master' into child-trie-soft-min
cheme Jul 2, 2019
4348d70
Address review comment:
cheme Jul 4, 2019
134a4bf
Merge branch 'master' into child-trie-soft-min
cheme Jul 4, 2019
5325621
Restore auth version.
cheme Jul 4, 2019
97118e8
Avoid confusing Option<Option< in result return of overlay.
cheme Jul 4, 2019
0ed7f80
Missing fix from review on testing ext for set child trie (code from
cheme Jul 4, 2019
8a6986a
Use fields for change trie storage.
cheme Jul 4, 2019
7652de9
switch MapTransaction to a struct.
cheme Jul 4, 2019
94c629e
Merge branch 'master' into child-trie-soft-min
cheme Jul 4, 2019
7675740
Apply same encoding for parent root (compatible with implementation of a
cheme Jul 1, 2019
90fba8a
Fix previous cherry pick
cheme Jul 4, 2019
d8c58c6
Addressing nits.
cheme Jul 4, 2019
661ba2e
Avoid unused creation of child trie.
cheme Jul 4, 2019
833e9ff
Create child trie id from additional storage state.
cheme Jul 5, 2019
71bda12
update default encoding.
cheme Jul 5, 2019
08b3062
Handle possible switch to multiple trie layer.
cheme Jul 5, 2019
89f3cd5
Remove a redundancy on keyspaceddb instantiation.
cheme Jul 5, 2019
834f52a
actually remove redundancy correctly
cheme Jul 5, 2019
0445228
comment
cheme Jul 5, 2019
75add99
Merge branch 'child-trie-soft-min-old' into child-trie-soft-min
cheme Jul 5, 2019
e70edab
Merge branch 'master' into child-trie-soft-min and apply review
cheme Jul 9, 2019
b8a0cd4
Merge branch 'master' into child-trie-soft-min
cheme Jul 10, 2019
1514171
Merge branch 'master' into child-trie-soft-min
cheme Jul 10, 2019
a7da811
Fix new test cases.
cheme Jul 10, 2019
b96c523
Merge branch 'master' into child-trie-soft-min
cheme Jul 11, 2019
865672d
Merge branch 'master' into child-trie-soft-min
cheme Jul 12, 2019
b6d7705
bump runtime version
cheme Jul 12, 2019
b45344c
Merge branch 'master' into child-trie-soft-min
cheme Jul 18, 2019
517f95c
Merge branch 'master' into child-trie-soft-min
cheme Jul 31, 2019
79a07de
Merge branch 'master' into child-trie-soft-min
cheme Aug 2, 2019
a027fb0
Some doc enhancement.
cheme Aug 2, 2019
b92655c
ChildRead correctly defined (previous definition was wrong).
cheme Aug 2, 2019
8a875f4
child_trie 'is_updatable_with' to avoid already broken redundancy.
cheme Aug 2, 2019
fcd8bdb
fix system bench error.
cheme Aug 2, 2019
3241fc4
Fix client doc rust code.
cheme Aug 2, 2019
ecac03b
Merge branch 'master' into child-trie-soft-min
cheme Aug 2, 2019
10369b9
Merge branch 'master' into child-trie-soft-min
cheme Aug 7, 2019
15a2967
Merge branch 'master' into child-trie-soft-min
cheme Aug 8, 2019
acc94e4
Merge branch 'master' into child-trie-soft-min
cheme Aug 8, 2019
7d96338
Remove unused method (in favor of assimilate).
cheme Aug 8, 2019
ba7bdcb
Merge branch 'child-trie-soft-min' of github.com:cheme/polkadot into …
cheme Aug 14, 2019
aacea85
Merge branch 'master' into child-trie-soft-min
cheme Aug 14, 2019
6789641
merge fix.
cheme Aug 14, 2019
2b37160
Rename MapTransaction to StorageContent.
cheme Aug 14, 2019
b1183bd
Get subscription stuff from child-deletion branch:
cheme Aug 14, 2019
bc5653c
Merge branch 'master' into child-trie-soft-min
cheme Aug 22, 2019
5ecfd19
update to master.
cheme Aug 22, 2019
baf89c8
Cast explicitelly for readability.
cheme Aug 26, 2019
0f8bff9
bump spec version.
cheme Aug 26, 2019
5a8576b
Merge branch 'master' into child-trie-soft-min
cheme Aug 29, 2019
045ee32
Merge branch 'master' into child-trie-soft-min
cheme Aug 29, 2019
58e6e41
Fix compilation.
cheme Aug 29, 2019
70555c5
Merge branch 'master' into child-trie-soft-min with conflicts.
cheme Sep 5, 2019
130e5e4
build passing, regression on extrinsics for a set_child (see new TODO).
cheme Sep 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
commit before wasm_executor change (we will keep old interface for now:
huge performance cost for wasm but need to get feedback on best/safe
wasm design).
  • Loading branch information
cheme committed Mar 26, 2019
commit a464936dc2eabfe188b0ad7dc1cb302a9eb0fc0f
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions core/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ impl SubTrie {
parent,
}
}
/// encoded parent trie node content
pub fn encoded_node(&self) -> Vec<u8> {
parity_codec::Encode::encode(&self.node)
}
/// encoded parent trie node content
pub fn parent_storage_key(&self) -> Vec<u8> {
// !! TODO EMCH (there is probably many places with incorrect parent key usage)
unimplemented!("TODO build from well known key or better build on construct: create a setter and make parentn non public");
}

}
41 changes: 20 additions & 21 deletions core/sr-io/with_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use parity_codec as codec;
// re-export hashing functions.
pub use primitives::{
blake2_256, twox_128, twox_256, ed25519, Blake2Hasher, sr25519,
Pair
Pair, SubTrie,
};
pub use tiny_keccak::keccak256 as keccak_256;
// Switch to this after PoC-3
Expand All @@ -43,13 +43,19 @@ pub type ChildrenStorageOverlay = HashMap<Vec<u8>, StorageOverlay>;

/// Get `key` from storage and return a `Vec`, empty if there's a problem.
pub fn storage(key: &[u8]) -> Option<Vec<u8>> {
ext::with(|ext| ext.storage(key).map(|s| s.to_vec()))
ext::with(|ext| ext.storage(key))
.expect("storage cannot be called outside of an Externalities-provided environment.")
}

/// Get `key` from child storage and return a `Vec`, empty if there's a problem.
pub fn child_storage(storage_key: &[u8], key: &[u8]) -> Option<Vec<u8>> {
ext::with(|ext| ext.child_storage(storage_key, key).map(|s| s.to_vec()))
pub fn child_storage(subtrie: &SubTrie, key: &[u8]) -> Option<Vec<u8>> {
ext::with(|ext| ext.child_storage(subtrie, key))
.expect("storage cannot be called outside of an Externalities-provided environment.")
}

/// get child trie at storage key location
pub fn get_child_trie(storage_key: &[u8]) -> Option<SubTrie> {
ext::with(|ext| ext.get_child_trie(storage_key))
.expect("storage cannot be called outside of an Externalities-provided environment.")
}

Expand All @@ -70,8 +76,8 @@ pub fn read_storage(key: &[u8], value_out: &mut [u8], value_offset: usize) -> Op
/// the number of bytes that the entry in storage had beyond the offset or None if the storage entry
/// doesn't exist at all. Note that if the buffer is smaller than the storage entry length, the returned
/// number of bytes is not equal to the number of bytes written to the `value_out`.
pub fn read_child_storage(storage_key: &[u8], key: &[u8], value_out: &mut [u8], value_offset: usize) -> Option<usize> {
ext::with(|ext| ext.child_storage(storage_key, key).map(|value| {
pub fn read_child_storage(subtrie: &SubTrie, key: &[u8], value_out: &mut [u8], value_offset: usize) -> Option<usize> {
ext::with(|ext| ext.child_storage(subtrie, key).map(|value| {
let value = &value[value_offset..];
let written = ::std::cmp::min(value.len(), value_out.len());
value_out[..written].copy_from_slice(&value[..written]);
Expand All @@ -87,9 +93,9 @@ pub fn set_storage(key: &[u8], value: &[u8]) {
}

/// Set the child storage of a key to some value.
pub fn set_child_storage(storage_key: &[u8], key: &[u8], value: &[u8]) {
pub fn set_child_storage(subtrie: &SubTrie, key: &[u8], value: &[u8]) {
ext::with(|ext|
ext.set_child_storage(storage_key.to_vec(), key.to_vec(), value.to_vec())
ext.set_child_storage(subtrie, key.to_vec(), value.to_vec())
);
}

Expand All @@ -101,9 +107,9 @@ pub fn clear_storage(key: &[u8]) {
}

/// Clear the storage of a key.
pub fn clear_child_storage(storage_key: &[u8], key: &[u8]) {
pub fn clear_child_storage(subtrie: &SubTrie, key: &[u8]) {
ext::with(|ext|
ext.clear_child_storage(storage_key, key)
ext.clear_child_storage(subtrie, key)
);
}

Expand All @@ -115,9 +121,9 @@ pub fn exists_storage(key: &[u8]) -> bool {
}

/// Check whether a given `key` exists in storage.
pub fn exists_child_storage(storage_key: &[u8], key: &[u8]) -> bool {
pub fn exists_child_storage(subtrie: &SubTrie, key: &[u8]) -> bool {
ext::with(|ext|
ext.exists_child_storage(storage_key, key)
ext.exists_child_storage(subtrie, key)
).unwrap_or(false)
}

Expand All @@ -129,9 +135,9 @@ pub fn clear_prefix(prefix: &[u8]) {
}

/// Clear an entire child storage.
pub fn kill_child_storage(storage_key: &[u8]) {
pub fn kill_child_storage(subtrie: &SubTrie) {
ext::with(|ext|
ext.kill_child_storage(storage_key)
ext.kill_child_storage(subtrie)
);
}

Expand All @@ -149,13 +155,6 @@ pub fn storage_root() -> H256 {
).unwrap_or(H256::zero())
}

/// "Commit" all existing operations and compute the resultant child storage root.
pub fn child_storage_root(storage_key: &[u8]) -> Option<Vec<u8>> {
ext::with(|ext|
ext.child_storage_root(storage_key)
).unwrap_or(None)
}

/// "Commit" all existing operations and get the resultant storage change root.
pub fn storage_changes_root(parent_hash: [u8; 32], parent_num: u64) -> Option<H256> {
ext::with(|ext|
Expand Down
2 changes: 1 addition & 1 deletion core/sr-io/without_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub fn storage_root() -> [u8; 32] {
}

/// "Commit" all existing operations and compute the resultant child storage root.
pub fn child_storage_root(storage_key: &[u8]) -> Option<Vec<u8>> {
pub fn child_storage_root(subtrie: &SubTrie) -> Vec<u8> {
let mut length: u32 = 0;
unsafe {
let ptr = ext_child_storage_root.get()(storage_key.as_ptr(), storage_key.len() as u32, &mut length);
Expand Down
17 changes: 8 additions & 9 deletions core/state-machine/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use hash_db::Hasher;
use heapsize::HeapSizeOf;
use trie::trie_root;
use primitives::storage::well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES};
use primitives::SubTrie;
use parity_codec::Encode;
use super::{Externalities, OverlayedChanges};
use log::warn;
Expand Down Expand Up @@ -111,8 +112,8 @@ impl<H: Hasher> Externalities<H> for BasicExternalities where H::Out: Ord + Heap
}
}

fn child_storage(&self, _storage_key: &[u8], _key: &[u8]) -> Option<Vec<u8>> {
None
fn child_storage(&self, _subtrie: &SubTrie, _key: &[u8]) -> Option<Vec<u8>> {
unreachable!("basic not used for child trie");
}

fn place_storage(&mut self, key: Vec<u8>, maybe_value: Option<Vec<u8>>) {
Expand All @@ -128,11 +129,13 @@ impl<H: Hasher> Externalities<H> for BasicExternalities where H::Out: Ord + Heap
}
}

fn place_child_storage(&mut self, _storage_key: Vec<u8>, _key: Vec<u8>, _value: Option<Vec<u8>>) -> bool {
false
fn place_child_storage(&mut self, _subtrie: &SubTrie, _key: Vec<u8>, _value: Option<Vec<u8>>) {
unreachable!("basic not used for child trie");
}

fn kill_child_storage(&mut self, _storage_key: &[u8]) { }
fn kill_child_storage(&mut self, _subtrie: &SubTrie) {
unreachable!("basic not used for child trie");
}

fn clear_prefix(&mut self, prefix: &[u8]) {
self.changes.clear_prefix(prefix);
Expand All @@ -145,10 +148,6 @@ impl<H: Hasher> Externalities<H> for BasicExternalities where H::Out: Ord + Heap
trie_root::<H, _, _, _>(self.inner.clone())
}

fn child_storage_root(&mut self, _storage_key: &[u8]) -> Option<Vec<u8>> {
None
}

fn storage_changes_root(&mut self, _parent: H::Out, _parent_num: u64) -> Option<H::Out> {
None
}
Expand Down
66 changes: 24 additions & 42 deletions core/state-machine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use crate::changes_trie::{AnchorBlockId, Storage as ChangesTrieStorage, compute_
use crate::{Externalities, OverlayedChanges, OffchainExt};
use hash_db::Hasher;
use primitives::storage::well_known_keys::is_child_storage_key;
use trie::{MemoryDB, TrieDBMut, TrieMut, default_child_trie_root, is_child_trie_key_valid};
use primitives::SubTrie;
use trie::{MemoryDB, TrieDBMut, TrieMut, default_child_trie_root};
use heapsize::HeapSizeOf;

const EXT_NOT_ALLOWED_TO_FAIL: &str = "Externalities not allowed to fail within runtime";
Expand Down Expand Up @@ -136,26 +137,26 @@ where
}

/// Fetch child storage root together with its transaction.
fn child_storage_root_transaction(&mut self, storage_key: &[u8]) -> (Vec<u8>, B::Transaction) {
fn child_storage_root_transaction(&mut self, subtrie: &SubTrie) -> (Vec<u8>, B::Transaction) {
self.mark_dirty();

let (root, is_default, transaction) = {
let delta = self.overlay.committed.children.get(storage_key)
let delta = self.overlay.committed.children.get(&subtrie.node.keyspace)
.into_iter()
.flat_map(|map| map.1.iter().map(|(k, v)| (k.clone(), v.clone())))
.chain(self.overlay.prospective.children.get(storage_key)
.chain(self.overlay.prospective.children.get(&subtrie.node.keyspace)
.into_iter()
.flat_map(|map| map.1.iter().map(|(k, v)| (k.clone(), v.clone()))));

self.backend.child_storage_root(storage_key, delta)
self.backend.child_storage_root(subtrie, delta)
};

let root_val = if is_default {
None
} else {
Some(root.clone())
};
self.overlay.sync_child_storage_root(storage_key, root_val);
self.overlay.sync_child_storage_root(subtrie, root_val);

(root, transaction)
}
Expand Down Expand Up @@ -204,10 +205,10 @@ where
self.backend.storage_hash(key).expect(EXT_NOT_ALLOWED_TO_FAIL))
}

fn child_storage(&self, storage_key: &[u8], key: &[u8]) -> Option<Vec<u8>> {
fn child_storage(&self, subtrie: &SubTrie, key: &[u8]) -> Option<Vec<u8>> {
let _guard = panic_handler::AbortGuard::new(true);
self.overlay.child_storage(storage_key, key).map(|x| x.map(|x| x.to_vec())).unwrap_or_else(||
self.backend.child_storage(storage_key, key).expect(EXT_NOT_ALLOWED_TO_FAIL))
self.overlay.child_storage(subtrie, key).map(|x| x.map(|x| x.to_vec())).unwrap_or_else(||
self.backend.child_storage(subtrie, key).expect(EXT_NOT_ALLOWED_TO_FAIL))
}

fn exists_storage(&self, key: &[u8]) -> bool {
Expand All @@ -218,11 +219,11 @@ where
}
}

fn exists_child_storage(&self, storage_key: &[u8], key: &[u8]) -> bool {
fn exists_child_storage(&self, subtrie: &SubTrie, key: &[u8]) -> bool {
let _guard = panic_handler::AbortGuard::new(true);
match self.overlay.child_storage(storage_key, key) {
match self.overlay.child_storage(subtrie, key) {
Some(x) => x.is_some(),
_ => self.backend.exists_child_storage(storage_key, key).expect(EXT_NOT_ALLOWED_TO_FAIL),
_ => self.backend.exists_child_storage(subtrie, key).expect(EXT_NOT_ALLOWED_TO_FAIL),
}
}

Expand All @@ -237,28 +238,21 @@ where
self.overlay.set_storage(key, value);
}

fn place_child_storage(&mut self, storage_key: Vec<u8>, key: Vec<u8>, value: Option<Vec<u8>>) -> bool {
fn place_child_storage(&mut self, subtrie: &SubTrie, key: Vec<u8>, value: Option<Vec<u8>>) {
let _guard = panic_handler::AbortGuard::new(true);
if !is_child_storage_key(&storage_key) || !is_child_trie_key_valid::<H>(&storage_key) {
return false;
}

self.mark_dirty();
self.overlay.set_child_storage(storage_key, key, value);

true
self.overlay.set_child_storage(&subtrie, key, value);
}

fn kill_child_storage(&mut self, storage_key: &[u8]) {
fn kill_child_storage(&mut self, subtrie: &SubTrie) {
let _guard = panic_handler::AbortGuard::new(true);
if !is_child_storage_key(storage_key) || !is_child_trie_key_valid::<H>(storage_key) {
return;
}

self.mark_dirty();
self.overlay.clear_child_storage(storage_key);
self.backend.for_keys_in_child_storage(storage_key, |key| {
self.overlay.set_child_storage(storage_key.to_vec(), key.to_vec(), None);
self.overlay.clear_child_storage(subtrie);
self.overlay.sync_child_storage_root(subtrie, None);
self.backend.for_keys_in_child_storage(subtrie, |key| {
self.overlay.set_child_storage(subtrie, key.to_vec(), None);
});
}

Expand Down Expand Up @@ -287,10 +281,11 @@ where
}

let mut transaction = B::Transaction::default();
let child_storage_keys: Vec<_> = self.overlay.prospective.children.keys().cloned().collect();
// TODO avoid this clone somehow?
let child_storage_subtries: Vec<_> = self.overlay.prospective.children.values().map(|v|v.2.clone()).collect();

for key in child_storage_keys {
let (_, t) = self.child_storage_root_transaction(&key);
for subtrie in child_storage_subtries {
let (_, t) = self.child_storage_root_transaction(&subtrie);
transaction.consolidate(t);
}

Expand All @@ -304,19 +299,6 @@ where
root
}

fn child_storage_root(&mut self, storage_key: &[u8]) -> Option<Vec<u8>> {
let _guard = panic_handler::AbortGuard::new(true);
if !is_child_storage_key(storage_key) || !is_child_trie_key_valid::<H>(storage_key) {
return None;
}

if self.storage_transaction.is_some() {
return Some(self.storage(storage_key).unwrap_or(default_child_trie_root::<H>()));
}

Some(self.child_storage_root_transaction(storage_key).0)
}

fn storage_changes_root(&mut self, parent: H::Out, parent_num: u64) -> Option<H::Out> {
let _guard = panic_handler::AbortGuard::new(true);
let root_and_tx = compute_changes_trie_root::<_, T, H>(
Expand Down
Loading