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

Commit

Permalink
Fix after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-tkach committed Jan 16, 2020
1 parent 4cc7130 commit c8d0725
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion primitives/state-machine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::{
StorageKey, StorageValue, OverlayedChanges, StorageTransactionCache,
backend::Backend,
changes_trie::Storage as ChangesTrieState,
changes_trie::State as ChangesTrieState,
};

use hash_db::Hasher;
Expand Down
3 changes: 2 additions & 1 deletion primitives/state-machine/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use codec::Decode;
use hash_db::Hasher;
use crate::{
backend::Backend, OverlayedChanges, StorageTransactionCache, ext::Ext, InMemoryBackend,
StorageKey, StorageValue,
changes_trie::{
Configuration as ChangesTrieConfiguration,
InMemoryStorage as ChangesTrieInMemoryStorage,
Expand Down Expand Up @@ -104,7 +105,7 @@ impl<H: Hasher, N: ChangesTrieBlockNumber> TestExternalities<H, N>
}

/// Insert key/value into backend
pub fn insert(&mut self, k: Vec<u8>, v: Vec<u8>) {
pub fn insert(&mut self, k: StorageKey, v: StorageValue) {
self.backend = self.backend.update(vec![(None, vec![(k, Some(v))])]);
}

Expand Down
22 changes: 12 additions & 10 deletions primitives/state-machine/src/trie_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ use log::{warn, debug};
use hash_db::Hasher;
use sp_trie::{Trie, delta_trie_root, default_child_trie_root, child_delta_trie_root};
use sp_trie::trie_types::{TrieDB, TrieError, Layout};
use crate::trie_backend_essence::{TrieBackendEssence, TrieBackendStorage, Ephemeral};
use crate::Backend;
use sp_core::storage::ChildInfo;
use codec::{Codec, Decode};
use crate::{
StorageKey, StorageValue, Backend,
trie_backend_essence::{TrieBackendEssence, TrieBackendStorage, Ephemeral},
};

/// 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 @@ -72,7 +74,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
type Transaction = S::Overlay;
type TrieBackendStorage = S;

fn storage(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error> {
fn storage(&self, key: &[u8]) -> Result<Option<StorageValue>, Self::Error> {
self.essence.storage(key)
}

Expand All @@ -81,11 +83,11 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
storage_key: &[u8],
child_info: ChildInfo,
key: &[u8],
) -> Result<Option<Vec<u8>>, Self::Error> {
) -> Result<Option<StorageValue>, Self::Error> {
self.essence.child_storage(storage_key, child_info, key)
}

fn next_storage_key(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error> {
fn next_storage_key(&self, key: &[u8]) -> Result<Option<StorageKey>, Self::Error> {
self.essence.next_storage_key(key)
}

Expand All @@ -94,7 +96,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
storage_key: &[u8],
child_info: ChildInfo,
key: &[u8],
) -> Result<Option<Vec<u8>>, Self::Error> {
) -> Result<Option<StorageKey>, Self::Error> {
self.essence.next_child_storage_key(storage_key, child_info, key)
}

Expand Down Expand Up @@ -125,7 +127,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
self.essence.for_child_keys_with_prefix(storage_key, child_info, prefix, f)
}

fn pairs(&self) -> Vec<(Vec<u8>, Vec<u8>)> {
fn pairs(&self) -> Vec<(StorageKey, StorageValue)> {
let mut read_overlay = S::Overlay::default();
let eph = Ephemeral::new(self.essence.backend_storage(), &mut read_overlay);

Expand All @@ -149,7 +151,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
}
}

fn keys(&self, prefix: &[u8]) -> Vec<Vec<u8>> {
fn keys(&self, prefix: &[u8]) -> Vec<StorageKey> {
let mut read_overlay = S::Overlay::default();
let eph = Ephemeral::new(self.essence.backend_storage(), &mut read_overlay);

Expand All @@ -170,7 +172,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
}

fn storage_root<I>(&self, delta: I) -> (H::Out, S::Overlay)
where I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>
where I: IntoIterator<Item=(StorageKey, Option<StorageValue>)>
{
let mut write_overlay = S::Overlay::default();
let mut root = *self.essence.root();
Expand All @@ -197,7 +199,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
delta: I,
) -> (H::Out, bool, Self::Transaction)
where
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
I: IntoIterator<Item=(StorageKey, Option<StorageValue>)>,
H::Out: Ord,
{
let default_root = default_child_trie_root::<Layout<H>>(storage_key);
Expand Down
12 changes: 6 additions & 6 deletions primitives/state-machine/src/trie_backend_essence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sp_trie::{Trie, MemoryDB, PrefixedMemoryDB, DBValue,
default_child_trie_root, read_trie_value, read_child_trie_value,
for_keys_in_child_trie, KeySpacedDB};
use sp_trie::trie_types::{TrieDB, TrieError, Layout};
use crate::backend::Consolidate;
use crate::{backend::Consolidate, StorageKey, StorageValue};
use sp_core::storage::ChildInfo;
use codec::Encode;

Expand Down Expand Up @@ -67,7 +67,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> where H::Out:

/// Return the next key in the trie i.e. the minimum key that is strictly superior to `key` in
/// lexicographic order.
pub fn next_storage_key(&self, key: &[u8]) -> Result<Option<Vec<u8>>, String> {
pub fn next_storage_key(&self, key: &[u8]) -> Result<Option<StorageKey>, String> {
self.next_storage_key_from_root(&self.root, None, key)
}

Expand All @@ -78,7 +78,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> where H::Out:
storage_key: &[u8],
child_info: ChildInfo,
key: &[u8],
) -> Result<Option<Vec<u8>>, String> {
) -> Result<Option<StorageKey>, String> {
let child_root = match self.storage(storage_key)? {
Some(child_root) => child_root,
None => return Ok(None),
Expand All @@ -101,7 +101,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> where H::Out:
root: &H::Out,
child_info: Option<ChildInfo>,
key: &[u8],
) -> Result<Option<Vec<u8>>, String> {
) -> Result<Option<StorageKey>, String> {
let mut read_overlay = S::Overlay::default();
let eph = Ephemeral {
storage: &self.storage,
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> where H::Out:
}

/// Get the value of storage at given key.
pub fn storage(&self, key: &[u8]) -> Result<Option<Vec<u8>>, String> {
pub fn storage(&self, key: &[u8]) -> Result<Option<StorageValue>, String> {
let mut read_overlay = S::Overlay::default();
let eph = Ephemeral {
storage: &self.storage,
Expand All @@ -164,7 +164,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> where H::Out:
storage_key: &[u8],
child_info: ChildInfo,
key: &[u8],
) -> Result<Option<Vec<u8>>, String> {
) -> Result<Option<StorageValue>, String> {
let root = self.storage(storage_key)?
.unwrap_or(default_child_trie_root::<Layout<H>>(storage_key).encode());

Expand Down

0 comments on commit c8d0725

Please sign in to comment.