Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9ccf26e
In progress, runtime io must switch to future proof root +
cheme Nov 18, 2019
a0f3818
Switch interface, sr-io seems ok, rpc could use similar interface to
cheme Nov 19, 2019
41c5020
test from previous implementation.
cheme Nov 20, 2019
6eb0414
fix proving test.
cheme Nov 20, 2019
e8e72fc
Restore Keyspacedb from other branch, only apply to child trie.
cheme Nov 20, 2019
88ffbc4
Removing unneeded child_info from child root (child info are stored
cheme Nov 20, 2019
435fcb2
Switch rpc to use same format as ext: more future proof.
cheme Nov 20, 2019
b8c7e37
use root from child info for trie backend essence.
cheme Nov 20, 2019
ee43955
Breaking long lines.
cheme Nov 20, 2019
fe285ae
Merge branch 'master' into child_uuid_step1
cheme Nov 21, 2019
a8818d9
Update doc and clean pr a bit.
cheme Nov 21, 2019
9873dcb
Merge branch 'master' into child_uuid_step1
cheme Nov 23, 2019
609a847
Merge branch 'master' into child_uuid_step1
cheme Nov 25, 2019
7254f6c
Merge branch 'master' into child_uuid_step1
cheme Nov 27, 2019
cac9330
fix error type
cheme Nov 27, 2019
c3b943c
Merge branch 'master' into child_uuid_step1
cheme Nov 28, 2019
c05bc80
Restore removed doc on merge and update sr-io doc.
cheme Nov 28, 2019
cd1e343
Merge branch 'master' into child_uuid_step1
cheme Nov 29, 2019
bdff843
Switch child storage api to use directly unique id, if managed id
cheme Nov 29, 2019
9ce77bb
Clean deprecated host interface from child.
cheme Nov 29, 2019
92c7864
Removing assertion on child info (can fail depending on root
cheme Nov 29, 2019
fc91068
merging child info in the overlay when possible.
cheme Nov 29, 2019
cdabca3
child iteration by prefix using child_info.
cheme Nov 29, 2019
783f389
Merge branch 'master' into child_uuid_step1
cheme Dec 2, 2019
d4c7334
Using ChainInfo in frame support. ChainInfo gets redesign to avoid
cheme Dec 2, 2019
64f4084
Add length of root to the data of child info.
cheme Dec 2, 2019
a87bd48
comments
cheme Dec 2, 2019
68712f9
Encode compact.
cheme Dec 2, 2019
3db467e
Remove child info with root.
cheme Dec 3, 2019
a7425cc
Merge branch 'master' into child_uuid_step1
cheme Dec 3, 2019
8e2b8b9
Fix try_update condition.
cheme Dec 3, 2019
5d74151
Comment Ext child root caching.
cheme Dec 3, 2019
0ba3da5
Replace tuples by struct with field
cheme Dec 5, 2019
d924187
remove StorageTuple alias.
cheme Dec 5, 2019
43da346
Merge branch 'master' into child_uuid_step1
cheme Dec 5, 2019
ead5856
Fix doc tests, and remove StorageOverlay and ChildStorageOverlay
cheme Dec 6, 2019
9e05542
Merge branch 'master' into child_uuid_step1
cheme Dec 8, 2019
6f107d0
Merge branch 'master' into child_uuid_step1
cheme Dec 10, 2019
17dd44d
Merge branch 'master' into child_uuid_step1
cheme Dec 11, 2019
0aaeefa
Merge branch 'master' into child_uuid_step1
cheme Dec 11, 2019
489c9f9
Merge branch 'master' into child_uuid_step1
cheme Dec 11, 2019
c58b539
Merge branch 'master' into child_uuid_step1
cheme Dec 13, 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
Merge branch 'master' into child_uuid_step1
  • Loading branch information
cheme committed Nov 28, 2019
commit c3b943c3509ef4f7e9fb3dfdde0030fda981ab3a
2 changes: 1 addition & 1 deletion client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<B: BlockT> StateBackend<Blake2Hasher> for RefTrackingState<B> {
storage_key: &[u8],
child_info: ChildInfo,
delta: I,
) -> (Vec<u8>, bool, Self::Transaction)
) -> (H256, bool, Self::Transaction)
where
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
{
Expand Down
2 changes: 1 addition & 1 deletion client/db/src/storage_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl<H: Hasher, S: StateBackend<H>, B: BlockT> StateBackend<H> for CachingState<
storage_key: &[u8],
child_info: ChildInfo,
delta: I,
) -> (Vec<u8>, bool, Self::Transaction)
) -> (H::Out, bool, Self::Transaction)
where
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
H::Out: Ord
Expand Down
6 changes: 4 additions & 2 deletions client/src/light/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use std::sync::Arc;
use parking_lot::RwLock;

use primitives::storage::{ChildInfo, OwnedChildInfo};
use state_machine::{Backend as StateBackend, TrieBackend, backend::InMemory as InMemoryState, ChangesTrieTransaction};
use state_machine::{
Backend as StateBackend, TrieBackend, backend::InMemory as InMemoryState, ChangesTrieTransaction
};
use primitives::offchain::storage::InMemOffchainStorage;
use sr_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
use sr_primitives::traits::{Block as BlockT, NumberFor, Zero, Header};
Expand Down Expand Up @@ -425,7 +427,7 @@ impl<H: Hasher> StateBackend<H> for GenesisOrUnavailableState<H>
storage_key: &[u8],
child_info: ChildInfo,
delta: I,
) -> (Vec<u8>, bool, Self::Transaction)
) -> (H::Out, bool, Self::Transaction)
where
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>
{
Expand Down
12 changes: 10 additions & 2 deletions primitives/externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@ pub trait Externalities: ExtensionStore {
fn storage_hash(&self, key: &[u8]) -> Option<Vec<u8>>;

/// Get child storage value hash. This may be optimized for large values.
///
/// Returns an `Option` that holds the SCALE encoded hash.
fn child_storage_hash(
&self,
storage_key: ChildStorageKey,
child_info: ChildInfo,
key: &[u8],
) -> Option<H256>;
) -> Option<Vec<u8>>;

/// Read original runtime storage, ignoring any overlayed changes.
fn original_storage(&self, key: &[u8]) -> Option<Vec<u8>>;

/// Read original runtime child storage, ignoring any overlayed changes.
///
/// Returns an `Option` that holds the SCALE encoded hash.
fn original_child_storage(
&self,
storage_key: ChildStorageKey,
Expand All @@ -69,14 +73,18 @@ pub trait Externalities: ExtensionStore {

/// Get original child storage value hash, ignoring any overlayed changes.
/// This may be optimized for large values.
///
/// Returns an `Option` that holds the SCALE encoded hash.
fn original_child_storage_hash(
&self,
storage_key: ChildStorageKey,
child_info: ChildInfo,
key: &[u8],
) -> Option<H256>;
) -> Option<Vec<u8>>;

/// Read child runtime storage.
///
/// Returns an `Option` that holds the SCALE encoded hash.
fn child_storage(
&self,
storage_key: ChildStorageKey,
Expand Down
4 changes: 4 additions & 0 deletions primitives/sr-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ pub trait Storage {
}

/// "Commit" all existing operations and compute the resulting child storage root.
///
/// The hashing algorithm is defined by the `Block`.
///
/// Returns the SCALE encoded hash.
fn child_root(
&mut self,
child_storage_key: &[u8],
Expand Down
9 changes: 5 additions & 4 deletions primitives/state-machine/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use trie::{
TrieMut, MemoryDB, child_trie_root, default_child_trie_root, TrieConfiguration,
trie_types::{TrieDBMut, Layout},
};
use codec::{Encode, Codec};
use primitives::storage::{ChildInfo, OwnedChildInfo};

pub(crate) type StorageTuple = (
Copy link
Member

Choose a reason for hiding this comment

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

This whole type would look much better as a struct with another struct for the second HashMap value

Expand Down Expand Up @@ -132,7 +133,7 @@ pub trait Backend<H: Hasher>: std::fmt::Debug {
storage_key: &[u8],
child_info: ChildInfo,
delta: I,
) -> (Vec<u8>, bool, Self::Transaction)
) -> (H::Out, bool, Self::Transaction)
where
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
H::Out: Ord;
Expand Down Expand Up @@ -176,7 +177,7 @@ pub trait Backend<H: Hasher>: std::fmt::Debug {
I1: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
I2i: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
I2: IntoIterator<Item=(Vec<u8>, I2i, OwnedChildInfo)>,
<H as Hasher>::Out: Ord,
H::Out: Ord + Encode,
{
let mut txs: Self::Transaction = Default::default();
let mut child_roots: Vec<_> = Default::default();
Expand Down Expand Up @@ -253,7 +254,7 @@ impl<'a, T: Backend<H>, H: Hasher> Backend<H> for &'a T {
storage_key: &[u8],
child_info: ChildInfo,
delta: I,
) -> (Vec<u8>, bool, Self::Transaction)
) -> (H::Out, bool, Self::Transaction)
where
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
H::Out: Ord,
Expand Down Expand Up @@ -514,7 +515,7 @@ impl<H: Hasher> Backend<H> for InMemory<H> where H::Out: Codec {
storage_key: &[u8],
child_info: ChildInfo,
delta: I,
) -> (Vec<u8>, bool, Self::Transaction)
) -> (H::Out, bool, Self::Transaction)
where
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
H::Out: Ord
Expand Down
6 changes: 3 additions & 3 deletions primitives/state-machine/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@ impl Externalities for BasicExternalities {
storage_key: ChildStorageKey,
child_info: ChildInfo,
key: &[u8],
) -> Option<H256> {
self.child_storage(storage_key, child_info, key).map(|v| Blake2Hasher::hash(&v))
) -> Option<Vec<u8>> {
self.child_storage(storage_key, child_info, key).map(|v| Blake2Hasher::hash(&v).encode())
}

fn original_child_storage_hash(
&self,
storage_key: ChildStorageKey,
child_info: ChildInfo,
key: &[u8],
) -> Option<H256> {
) -> Option<Vec<u8>> {
self.child_storage_hash(storage_key, child_info, key)
}

Expand Down
8 changes: 5 additions & 3 deletions primitives/state-machine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ where
storage_key: ChildStorageKey,
_child_info: ChildInfo,
key: &[u8],
) -> Option<H256> {
) -> Option<Vec<u8>> {
let _guard = panic_handler::AbortGuard::force_abort();
let result = self.overlay
.child_storage(storage_key.as_ref(), key)
Expand Down Expand Up @@ -303,7 +303,7 @@ where
storage_key: ChildStorageKey,
child_info: ChildInfo,
key: &[u8],
) -> Option<H256> {
) -> Option<Vec<u8>> {
let _guard = panic_handler::AbortGuard::force_abort();
let result = self.backend
.child_storage_hash(storage_key.as_ref(), child_info, key)
Expand Down Expand Up @@ -530,6 +530,7 @@ where
self.backend.child_storage_root(storage_key, child_info.as_ref(), delta)
};

let root = root.encode();
if is_empty {
self.overlay.set_storage(storage_key.into(), None);
} else {
Expand All @@ -546,6 +547,7 @@ where
// empty overlay
let root = self
.storage(storage_key.as_ref())
.and_then(|k| Decode::decode(&mut &k[..]).ok())
.unwrap_or(
default_child_trie_root::<Layout<H>>(storage_key.as_ref())
);
Expand All @@ -554,7 +556,7 @@ where
HexDisplay::from(&storage_key.as_ref()),
HexDisplay::from(&root.as_ref()),
);
root
root.encode()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion primitives/state-machine/src/proving_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl<'a, S, H> Backend<H> for ProvingBackend<'a, S, H>
storage_key: &[u8],
child_info: ChildInfo,
delta: I,
) -> (Vec<u8>, bool, Self::Transaction)
) -> (H::Out, bool, Self::Transaction)
where
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
H::Out: Ord
Expand Down
3 changes: 2 additions & 1 deletion primitives/state-machine/src/trie_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use trie::trie_types::{TrieDB, TrieError, Layout};
use crate::trie_backend_essence::{TrieBackendEssence, TrieBackendStorage, Ephemeral};
use crate::Backend;
use primitives::storage::ChildInfo;
use codec::{Codec, Decode};

/// Patricia trie-based backend. Transaction type is an overlay of changes to commit.
pub struct TrieBackend<S: TrieBackendStorage<H>, H: Hasher> {
Expand Down Expand Up @@ -181,7 +182,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
storage_key: &[u8],
child_info: ChildInfo,
delta: I,
) -> (Vec<u8>, bool, Self::Transaction)
) -> (H::Out, bool, Self::Transaction)
where
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
H::Out: Ord,
Expand Down
5 changes: 3 additions & 2 deletions primitives/state-machine/src/trie_backend_essence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use trie::{Trie, MemoryDB, PrefixedMemoryDB, DBValue,
use trie::trie_types::{TrieDB, TrieError, Layout};
use crate::backend::Consolidate;
use primitives::storage::ChildInfo;
use codec::Encode;

/// Patricia trie-based storage trait.
pub trait Storage<H: Hasher>: Send + Sync {
Expand Down Expand Up @@ -89,7 +90,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> where H::Out:
root
} else {
fetched_root = self.storage(storage_key)?
.unwrap_or(default_child_trie_root::<Layout<H>>(storage_key));
.unwrap_or(default_child_trie_root::<Layout<H>>(storage_key).encode());
&fetched_root
};

Expand Down Expand Up @@ -117,7 +118,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> where H::Out:
root
} else {
fetched_root = match self.storage(storage_key) {
Ok(v) => v.unwrap_or(default_child_trie_root::<Layout<H>>(storage_key)),
Ok(v) => v.unwrap_or(default_child_trie_root::<Layout<H>>(storage_key).encode()),
Err(e) => {
debug!(target: "trie", "Error while iterating child storage: {}", e);
return;
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.