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
SubTrie struct renaming (and single encode point)
  • Loading branch information
cheme committed May 16, 2019
commit 3553ab2fba2d581fafd4c3061dcf688773ffc030
8 changes: 4 additions & 4 deletions core/client/db/src/storage_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use runtime_primitives::traits::{Block, Header};
use state_machine::{backend::Backend as StateBackend, TrieBackend};
use log::trace;
use primitives::subtrie::SubTrie;
use primitives::subtrie::SubTrieNodeRef;
use primitives::subtrie::SubTrieReadRef;

const STATE_CACHE_BLOCKS: usize = 12;

Expand Down Expand Up @@ -359,23 +359,23 @@ impl<H: Hasher, S: StateBackend<H>, B:Block> StateBackend<H> for CachingState<H,
Ok(hash)
}

fn child_storage(&self, subtrie: SubTrieNodeRef, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error> {
fn child_storage(&self, subtrie: SubTrieReadRef, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error> {
self.state.child_storage(subtrie, key)
}

fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> {
Ok(self.storage(key)?.is_some())
}

fn exists_child_storage(&self, subtrie: SubTrieNodeRef, key: &[u8]) -> Result<bool, Self::Error> {
fn exists_child_storage(&self, subtrie: SubTrieReadRef, key: &[u8]) -> Result<bool, Self::Error> {
self.state.exists_child_storage(subtrie, key)
}

fn for_keys_with_prefix<F: FnMut(&[u8])>(&self, prefix: &[u8], f: F) {
self.state.for_keys_with_prefix(prefix, f)
}

fn for_keys_in_child_storage<F: FnMut(&[u8])>(&self, subtrie: SubTrieNodeRef, f: F) {
fn for_keys_in_child_storage<F: FnMut(&[u8])>(&self, subtrie: SubTrieReadRef, f: F) {
self.state.for_keys_in_child_storage(subtrie, f)
}

Expand Down
4 changes: 2 additions & 2 deletions core/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::error::Error;
use futures::sync::mpsc;
use parking_lot::{Mutex, RwLock};
use primitives::NativeOrEncoded;
use primitives::subtrie::SubTrieNodeRef;
use primitives::subtrie::SubTrieReadRef;
use runtime_primitives::{
Justification,
generic::{BlockId, SignedBlock},
Expand Down Expand Up @@ -380,7 +380,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
pub fn read_child_proof(
&self,
id: &BlockId<Block>,
subtrie: SubTrieNodeRef,
subtrie: SubTrieReadRef,
key: &[u8]
) -> error::Result<Vec<Vec<u8>>> {
self.state_at(id)
Expand Down
10 changes: 5 additions & 5 deletions core/client/src/light/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use parking_lot::RwLock;

use runtime_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
use primitives::subtrie::SubTrie;
use primitives::subtrie::SubTrieNodeRef;
use primitives::subtrie::SubTrieReadRef;
use state_machine::{Backend as StateBackend, TrieBackend};
use state_machine::backend::{InMemory as InMemoryState, MapTransaction};
use runtime_primitives::traits::{Block as BlockT, NumberFor, Zero, Header};
Expand Down Expand Up @@ -345,15 +345,15 @@ where
.into_future().wait()
}

fn child_storage(&self, _subtrie: SubTrieNodeRef, _key: &[u8]) -> ClientResult<Option<Vec<u8>>> {
fn child_storage(&self, _subtrie: SubTrieReadRef, _key: &[u8]) -> ClientResult<Option<Vec<u8>>> {
Err(ClientError::NotAvailableOnLightClient.into())
}

fn for_keys_with_prefix<A: FnMut(&[u8])>(&self, _prefix: &[u8], _action: A) {
// whole state is not available on light node
}

fn for_keys_in_child_storage<A: FnMut(&[u8])>(&self, _subtrie: SubTrieNodeRef, _action: A) {
fn for_keys_in_child_storage<A: FnMut(&[u8])>(&self, _subtrie: SubTrieReadRef, _action: A) {
// whole state is not available on light node
}

Expand Down Expand Up @@ -407,7 +407,7 @@ where
}
}

fn child_storage(&self, subtrie: SubTrieNodeRef, key: &[u8]) -> ClientResult<Option<Vec<u8>>> {
fn child_storage(&self, subtrie: SubTrieReadRef, key: &[u8]) -> ClientResult<Option<Vec<u8>>> {
match *self {
OnDemandOrGenesisState::OnDemand(ref state) =>
StateBackend::<H>::child_storage(state, subtrie, key),
Expand All @@ -424,7 +424,7 @@ where
}
}

fn for_keys_in_child_storage<A: FnMut(&[u8])>(&self, subtrie: SubTrieNodeRef, action: A) {
fn for_keys_in_child_storage<A: FnMut(&[u8])>(&self, subtrie: SubTrieReadRef, action: A) {
match *self {
OnDemandOrGenesisState::OnDemand(ref state) =>
StateBackend::<H>::for_keys_in_child_storage(state, subtrie, action),
Expand Down
4 changes: 2 additions & 2 deletions core/client/src/light/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use futures::IntoFuture;

use hash_db::{HashDB, Hasher};
use primitives::{ChangesTrieConfiguration, convert_hash};
use primitives::subtrie::SubTrieNodeCodec;
use primitives::subtrie::SubTrieRead;
use runtime_primitives::traits::{As, Block as BlockT, Header as HeaderT, NumberFor};
use state_machine::{CodeExecutor, ChangesTrieRootsStorage, ChangesTrieAnchorBlockId,
TrieBackend, read_proof_check, key_changes_proof_check,
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct RemoteReadChildRequest<Header: HeaderT> {
/// Header of block at which read is performed.
pub header: Header,
/// Child trie
pub child_trie: SubTrieNodeCodec,
pub child_trie: SubTrieRead,
/// Child storage key to read.
pub key: Vec<u8>,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
Expand Down
8 changes: 4 additions & 4 deletions core/executor/src/wasm_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::wasm_utils::UserError;
use primitives::{blake2_128, blake2_256, twox_64, twox_128, twox_256, ed25519, sr25519, Pair};
use primitives::hexdisplay::HexDisplay;
use primitives::sandbox as sandbox_primitives;
use primitives::{H256, Blake2Hasher, subtrie::{SubTrie, SubTrieNodeRef}};
use primitives::{H256, Blake2Hasher, subtrie::{SubTrie, SubTrieReadRef}};
use trie::ordered_trie_root;
use crate::sandbox;
use crate::allocator;
Expand Down Expand Up @@ -241,7 +241,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
let root = this.memory.get(root_data, root_len as usize).map_err(|_| UserError("Invalid attempt to determine storage_key in ext_set_child_storage"))?;
let key = this.memory.get(key_data, key_len as usize).map_err(|_| UserError("Invalid attempt to determine key in ext_exists_child_storage"))?;
let root = if root.len() > 0 { Some(&root[..]) } else { None };
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't the this.memory.get should be performed inside the yes branch ? Because root_data shouldn't be read in case len is 0 no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

definitely

let subtrie = SubTrieNodeRef::new(&keyspace, root);
let subtrie = SubTrieReadRef::new(&keyspace, root);
Ok(if this.ext.exists_child_storage(subtrie, &key) { 1 } else { 0 })
},
ext_clear_prefix(prefix_data: *const u8, prefix_len: u32) => {
Expand Down Expand Up @@ -309,7 +309,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
key_len as usize
).map_err(|_| UserError("Invalid attempt to determine key in ext_get_allocated_child_storage"))?;
let root = if root.len() > 0 { Some(&root[..]) } else { None };
Copy link
Contributor

@gui1117 gui1117 May 28, 2019

Choose a reason for hiding this comment

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

ditto perform memory.get inside true-branch ?

let subtrie = SubTrieNodeRef::new(&keyspace, root);
let subtrie = SubTrieReadRef::new(&keyspace, root);
let maybe_value = this.ext.child_storage(subtrie, &key);

debug_trace!(target: "wasm-trace", "*** Getting child storage: {} -> {} == {} [k={}]",
Expand Down Expand Up @@ -384,7 +384,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
key_len as usize
).map_err(|_| UserError("Invalid attempt to determine key in ext_get_allocated_child_storage"))?;
let root = if root.len() > 0 { Some(&root[..]) } else { None };
let subtrie = SubTrieNodeRef::new(&keyspace, root);
let subtrie = SubTrieReadRef::new(&keyspace, root);

let maybe_value = this.ext.child_storage(subtrie, &key);
debug_trace!(target: "wasm-trace", "*** Getting storage: {} -> {} == {} [k={}]",
Expand Down
6 changes: 3 additions & 3 deletions core/network/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use bitflags::bitflags;
use runtime_primitives::{ConsensusEngineId, traits::{Block as BlockT, Header as HeaderT}};
use primitives::subtrie::SubTrieNodeCodec;
use primitives::subtrie::SubTrieRead;
use parity_codec::{Encode, Decode, Input, Output};
pub use self::generic::{
BlockAnnounce, RemoteCallRequest, RemoteReadRequest,
Expand Down Expand Up @@ -131,7 +131,7 @@ pub mod generic {
use runtime_primitives::Justification;
use crate::config::Roles;
use super::{
RemoteReadResponse, Transactions, Direction, SubTrieNodeCodec,
RemoteReadResponse, Transactions, Direction, SubTrieRead,
RequestId, BlockAttributes, RemoteCallResponse, ConsensusEngineId,
};
/// Consensus is mostly opaque to us
Expand Down Expand Up @@ -307,7 +307,7 @@ pub mod generic {
/// Block at which to perform call.
pub block: H,
/// Child trie info.
pub child_trie: SubTrieNodeCodec,
pub child_trie: SubTrieRead,
/// Storage key.
pub key: Vec<u8>,
}
Expand Down
4 changes: 2 additions & 2 deletions core/network/src/on_demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ pub mod tests {
use std::sync::{Arc, Mutex};
use std::time::Instant;
use futures::Future;
use primitives::subtrie::SubTrieNodeCodec;
use primitives::subtrie::SubTrieRead;
use runtime_primitives::traits::{Block as BlockT, NumberFor};
use client::{error::{Error as ClientError, Result as ClientResult}};
use client::light::fetcher::{Fetcher, FetchChecker, RemoteHeaderRequest,
Expand Down Expand Up @@ -977,7 +977,7 @@ pub mod tests {
let response = on_demand.remote_read_child(RemoteReadChildRequest {
header: dummy_header(),
block: Default::default(),
child_trie: SubTrieNodeCodec {
child_trie: SubTrieRead {
keyspace: b"keyspace".to_vec(),
// dummy : this should be queried
root: b"root".to_vec(),
Expand Down
43 changes: 26 additions & 17 deletions core/primitives/src/subtrie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,51 +50,60 @@ pub fn keyspace_as_prefix_alloc(ks: &KeySpace, prefix: &[u8]) -> Vec<u8> {
res
}

/// `SubTrieNodeRef` used for non changing state query
/// `SubTrieReadRef` used for non changing state query
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// `SubTrieReadRef` used for non changing state query
/// `SubTrieReadRef` is used for non changing state query

/// so it is safe to build
#[derive(Clone)]
pub struct SubTrieNodeRef<'a> {
pub struct SubTrieReadRef<'a> {
/// subtrie unique keyspace
Copy link
Member

Choose a reason for hiding this comment

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

useless docs again

pub keyspace: &'a KeySpace,
/// subtrie root hash
pub root: Option<&'a [u8]>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you mention in the rustdoc why this can be None and, ideally, why we need it?

}

impl<'a> SubTrieNodeRef<'a> {
/// create a SubTrieNodeRef
impl<'a> SubTrieReadRef<'a> {
/// create a SubTrieReadRef
pub fn new(keyspace: &'a KeySpace, root: Option<&'a[u8]>) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need a constructor if all fields are public? Or vice-versa, why all fields are public if we have a constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is just a convenience one (the field were probably not public at some point). It is not that much use, I will remove it.

SubTrieNodeRef {keyspace, root}
SubTrieReadRef {keyspace, root}
}
// should not be public as it produce incomplete content
Copy link
Member

Choose a reason for hiding this comment

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

more context needed for this docs to be useful

fn enc(&self) -> Option<SubTrieNodeCodecRef> {
self.root.map(|r|SubTrieNodeCodecRef {keyspace: self.keyspace, root: r})
fn enc(&self) -> Option<SubTrieReadEncode> {
self.root.map(|r|SubTrieReadEncode {keyspace: self.keyspace, root: r})
}
}

/// `SubTrieNode` encoder internal implementation
/// shall never be exposed
#[derive(Encode, Clone)]
struct SubTrieNodeCodecRef<'a> {
struct SubTrieReadEncode<'a> {
/// subtrie unique keyspace
pub keyspace: &'a KeySpace,
/// subtrie root hash
pub root: &'a [u8],
Copy link
Contributor

Choose a reason for hiding this comment

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

This struct is not public. If so, why we need public fields here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lets say it indicates that the field should be public in case the struct was public. But I agree it is mostly useless :)

}

#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[derive(PartialEq, Eq, Clone, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Hash, PartialOrd, Ord))]
/// Subtrie node info for query (with a valid root)
pub struct SubTrieNodeCodec {
pub struct SubTrieRead {
/// subtrie unique keyspace
pub keyspace: KeySpace,
/// subtrie root hash
pub root: Vec<u8>,
}
impl SubTrieNodeCodec {
impl SubTrieRead {
/// get node ref for read only query
pub fn node_ref(&self) -> SubTrieNodeRef {
pub fn node_ref(&self) -> SubTrieReadRef {
debug_assert!(self.root.len() > 0);
SubTrieNodeRef::new(&self.keyspace, Some(&self.root[..]))
SubTrieReadRef::new(&self.keyspace, Some(&self.root[..]))
}
}

impl parity_codec::Encode for SubTrieRead {
fn encode(&self) -> Vec<u8> {
SubTrieReadEncode {
keyspace: &self.keyspace,
root: &self.root[..]
}.encode()
}
}

Expand Down Expand Up @@ -131,8 +140,8 @@ impl SubTrie {
}
}
/// node ref of subtrie
pub fn node_ref(&self) -> SubTrieNodeRef {
SubTrieNodeRef::new(&self.keyspace, self.root.as_ref().map(|r|&r[..]))
pub fn node_ref(&self) -> SubTrieReadRef {
SubTrieReadRef::new(&self.keyspace, self.root.as_ref().map(|r|&r[..]))
}
/// instantiate subtrie from a read node value
pub fn decode_node(encoded_node: &[u8], parent: &[u8]) -> Option<Self> {
Expand All @@ -142,7 +151,7 @@ impl SubTrie {
/// instantiate subtrie from a read node value, parent node is prefixed
pub fn decode_node_prefixed_parent(encoded_node: &[u8], parent: Vec<u8>) -> Option<Self> {
let input = &mut &encoded_node[..];
SubTrieNodeCodec::decode(input).map(|SubTrieNodeCodec { keyspace, root }|
SubTrieRead::decode(input).map(|SubTrieRead { keyspace, root }|
SubTrie {
keyspace,
root: Some(root),
Expand Down Expand Up @@ -180,7 +189,7 @@ impl SubTrie {
}
/// encdode with an updated root
pub fn encoded_with_root(&self, new_root: &[u8]) -> Vec<u8> {
let mut enc = parity_codec::Encode::encode(&SubTrieNodeCodecRef{
let mut enc = parity_codec::Encode::encode(&SubTrieReadEncode{
keyspace: &self.keyspace,
root: new_root,
});
Expand Down
8 changes: 4 additions & 4 deletions core/sr-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rstd::vec::Vec;
pub use codec;

pub use primitives::Blake2Hasher;
pub use primitives::subtrie::{SubTrie, SubTrieNodeRef};
pub use primitives::subtrie::{SubTrie, SubTrieReadRef};

/// Error verifying ECDSA signature
pub enum EcdsaVerifyError {
Expand Down Expand Up @@ -94,7 +94,7 @@ export_api! {
fn storage(key: &[u8]) -> Option<Vec<u8>>;

/// Get `key` from child storage and return a `Vec`, empty if there's a problem.
fn child_storage(subtrie: SubTrieNodeRef, key: &[u8]) -> Option<Vec<u8>>;
fn child_storage(subtrie: SubTrieReadRef, key: &[u8]) -> Option<Vec<u8>>;

/// Get `key` from storage, placing the value into `value_out` (as much of it as possible) and return
/// the number of bytes that the entry in storage had beyond the offset or None if the storage entry
Expand All @@ -109,7 +109,7 @@ export_api! {
/// 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`.
fn read_child_storage(subtrie: SubTrieNodeRef, key: &[u8], value_out: &mut [u8], value_offset: usize) -> Option<usize>;
fn read_child_storage(subtrie: SubTrieReadRef, key: &[u8], value_out: &mut [u8], value_offset: usize) -> Option<usize>;

/// Set the storage of some particular key to Some value.
fn set_storage(key: &[u8], value: &[u8]);
Expand All @@ -130,7 +130,7 @@ export_api! {
fn exists_storage(key: &[u8]) -> bool;

/// Check whether a given `key` exists in storage.
fn exists_child_storage(subtrie: SubTrieNodeRef, key: &[u8]) -> bool;
fn exists_child_storage(subtrie: SubTrieReadRef, key: &[u8]) -> bool;

/// Clear the storage entries with a key that starts with the given prefix.
fn clear_prefix(prefix: &[u8]);
Expand Down
8 changes: 4 additions & 4 deletions core/sr-io/with_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// re-export hashing functions.
pub use primitives::{
blake2_128, blake2_256, twox_128, twox_256, twox_64, ed25519, Blake2Hasher,
sr25519, Pair, subtrie::{SubTrie, SubTrieNodeRef, KeySpace},
sr25519, Pair, subtrie::{SubTrie, SubTrieReadRef, KeySpace},
};
// Switch to this after PoC-3
// pub use primitives::BlakeHasher;
Expand Down Expand Up @@ -72,7 +72,7 @@ impl StorageApi for () {
.expect("storage cannot be called outside of an Externalities-provided environment.")
}

fn child_storage(subtrie: SubTrieNodeRef, key: &[u8]) -> Option<Vec<u8>> {
fn child_storage(subtrie: SubTrieReadRef, key: &[u8]) -> Option<Vec<u8>> {
ext::with(|ext| {
ext.child_storage(subtrie, key).map(|s| s.to_vec())
})
Expand All @@ -86,7 +86,7 @@ impl StorageApi for () {
}

fn read_child_storage(
subtrie: SubTrieNodeRef,
subtrie: SubTrieReadRef,
key: &[u8],
value_out: &mut [u8],
value_offset: usize,
Expand Down Expand Up @@ -133,7 +133,7 @@ impl StorageApi for () {
).unwrap_or(false)
}

fn exists_child_storage(subtrie: SubTrieNodeRef, key: &[u8]) -> bool {
fn exists_child_storage(subtrie: SubTrieReadRef, key: &[u8]) -> bool {
ext::with(|ext| {
ext.exists_child_storage(subtrie, key)
}).unwrap_or(false)
Expand Down
Loading