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
24 commits
Select commit Hold shift + click to select a range
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
Remove NoTransaction.
  • Loading branch information
cheme committed Aug 21, 2020
commit a9aa27cf2c76aedd696f5053a2b60d9e459b9c95
108 changes: 0 additions & 108 deletions primitives/state-machine/src/trie_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ pub struct TrieBackend<S: TrieBackendStorage<H>, H: Hasher> {
pub (crate) essence: TrieBackendEssence<S, H>,
}

/// Patricia trie-based backend.
/// This is a variant of `TrieBackend` that produce no transactions content.
pub struct TrieBackendNoTransaction<S: TrieBackendStorage<H>, H: Hasher> (
pub TrieBackend<S, H>,
);

impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackend<S, H> where H::Out: Codec {
/// Create new trie-based backend.
pub fn new(storage: S, root: H::Out) -> Self {
Expand Down Expand Up @@ -81,12 +75,6 @@ impl<S: TrieBackendStorage<H>, H: Hasher> sp_std::fmt::Debug for TrieBackend<S,
}
}

impl<S: TrieBackendStorage<H>, H: Hasher> sp_std::fmt::Debug for TrieBackendNoTransaction<S, H> {
fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result {
write!(f, "TrieBackendNoTransaction")
}
}

impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
H::Out: Ord + Codec,
{
Expand Down Expand Up @@ -260,102 +248,6 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
}
}

impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackendNoTransaction<S, H> where
H::Out: Ord + Codec,
{
type Error = crate::DefaultError;
type Transaction = S::Overlay;
type TrieBackendStorage = S;

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

fn child_storage(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<StorageValue>, Self::Error> {
self.0.child_storage(child_info, key)
}

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

fn next_child_storage_key(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<StorageKey>, Self::Error> {
self.0.next_child_storage_key(child_info, key)
}

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

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

fn for_keys_in_child_storage<F: FnMut(&[u8])>(
&self,
child_info: &ChildInfo,
f: F,
) {
self.0.for_keys_in_child_storage(child_info, f)
}

fn for_child_keys_with_prefix<F: FnMut(&[u8])>(
&self,
child_info: &ChildInfo,
prefix: &[u8],
f: F,
) {
self.0.for_child_keys_with_prefix(child_info, prefix, f)
}

fn pairs(&self) -> Vec<(StorageKey, StorageValue)> {
self.0.pairs()
}

fn keys(&self, prefix: &[u8]) -> Vec<StorageKey> {
self.0.keys(prefix)
}

fn storage_root<'a>(
&self,
delta: impl Iterator<Item=(&'a [u8], Option<&'a [u8]>)>,
) -> (H::Out, Self::Transaction) where H::Out: Ord {
self.0.storage_root(delta)
}

fn child_storage_root<'a>(
&self,
child_info: &ChildInfo,
delta: impl Iterator<Item=(&'a [u8], Option<&'a [u8]>)>,
) -> (H::Out, bool, Self::Transaction) where H::Out: Ord {
self.0.child_storage_root(child_info, delta)
}

fn as_trie_backend(&mut self) -> Option<&TrieBackend<Self::TrieBackendStorage, H>> {
self.0.as_trie_backend()
}

fn register_overlay_stats(&mut self, stats: &crate::stats::StateMachineStats) {
self.0.register_overlay_stats(stats)
}

fn usage_info(&self) -> crate::UsageInfo {
self.0.usage_info()
}

fn wipe(&self) -> Result<(), Self::Error> {
self.0.wipe()
}
}

#[cfg(test)]
pub mod tests {
use std::{collections::HashSet, iter};
Expand Down
12 changes: 5 additions & 7 deletions primitives/state-machine/src/witness_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_std::{any::{TypeId, Any}};
use sp_std::boxed::Box;
use sp_std::vec::Vec;
use sp_trie::MemoryDB;
use crate::trie_backend::{TrieBackend, TrieBackendNoTransaction};
use crate::trie_backend::TrieBackend;
use crate::ext::{ExtInner, ExtInnerMut};
use crate::overlayed_changes::{OverlayedChanges, NoExtrinsics};
use crate::{StorageValue, StorageKey};
Expand All @@ -34,7 +34,7 @@ pub struct WitnessExt<H: Hasher> {
/// The overlayed changes to write to.
pub overlay: OverlayedChanges<NoExtrinsics>,
/// The storage backend to read from.
pub backend: TrieBackendNoTransaction<MemoryDB<H>, H>,
pub backend: TrieBackend<MemoryDB<H>, H>,
}

impl<H: Hasher> WitnessExt<H>
Expand All @@ -45,13 +45,13 @@ impl<H: Hasher> WitnessExt<H>
/// Create a new backend.
pub fn new(db: MemoryDB<H>, root: H::Out) -> Self {
WitnessExt {
backend: TrieBackendNoTransaction(TrieBackend::new(db, root)),
backend: TrieBackend::new(db, root),
overlay: OverlayedChanges::<NoExtrinsics>::default(),
}
}

/// Access methods for `ExtInnerMut`.
fn ext_inner_mut(&mut self) -> ExtInnerMut<H, TrieBackendNoTransaction<MemoryDB<H>, H>, NoExtrinsics> {
fn ext_inner_mut(&mut self) -> ExtInnerMut<H, TrieBackend<MemoryDB<H>, H>, NoExtrinsics> {
ExtInnerMut {
overlay: &mut self.overlay,
backend: &self.backend,
Expand All @@ -61,7 +61,7 @@ impl<H: Hasher> WitnessExt<H>
}

/// Access methods for `ExtInner`.
fn ext_inner(&self) -> ExtInner<H, TrieBackendNoTransaction<MemoryDB<H>, H>, NoExtrinsics> {
fn ext_inner(&self) -> ExtInner<H, TrieBackend<MemoryDB<H>, H>, NoExtrinsics> {
ExtInner {
overlay: &self.overlay,
backend: &self.backend,
Expand All @@ -71,8 +71,6 @@ impl<H: Hasher> WitnessExt<H>
}
}



impl<H> Externalities for WitnessExt<H>
where
H: Hasher,
Expand Down