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

Commit

Permalink
Do not export a Keccak impl of MemoryDB
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdplm committed Jun 20, 2018
1 parent f1be1a1 commit b48e2c8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
6 changes: 3 additions & 3 deletions ethcore/src/json_tests/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ use ethjson;
use trie::{TrieFactory, TrieSpec};
use ethtrie::RlpCodec;
use ethereum_types::H256;
use memorydb::KeccakMemoryDB;

use memorydb::MemoryDB;
use keccak_hasher::KeccakHasher;

fn test_trie(json: &[u8], trie: TrieSpec) -> Vec<String> {
let tests = ethjson::trie::Test::load(json).unwrap();
let factory = TrieFactory::<_, RlpCodec>::new(trie);
let mut result = vec![];

for (name, test) in tests.into_iter() {
let mut memdb = KeccakMemoryDB::new();
let mut memdb = MemoryDB<KeccakHasher>::new();
let mut root = H256::default();
let mut t = factory.create(&mut memdb, &mut root);

Expand Down
18 changes: 7 additions & 11 deletions ethcore/src/state/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::sync::Arc;
use state::Account;
use parking_lot::Mutex;
use ethereum_types::{Address, H256};
use memorydb::KeccakMemoryDB;
use memorydb::MemoryDB;
use hashdb::{AsHashDB, HashDB, DBValue};
use keccak_hasher::KeccakHasher;

Expand Down Expand Up @@ -76,12 +76,12 @@ pub trait Backend: Send {
// TODO: when account lookup moved into backends, this won't rely as tenuously on intended
// usage.
#[derive(Clone, PartialEq)]
pub struct ProofCheck(KeccakMemoryDB);
pub struct ProofCheck(MemoryDB<KeccakHasher>);

impl ProofCheck {
/// Create a new `ProofCheck` backend from the given state items.
pub fn new(proof: &[DBValue]) -> Self {
let mut db = KeccakMemoryDB::new();
let mut db = MemoryDB::<KeccakHasher>::new();
for item in proof { db.insert(item); }
ProofCheck(db)
}
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Backend for ProofCheck {
/// This doesn't cache anything or rely on the canonical state caches.
pub struct Proving<H: AsHashDB<KeccakHasher>> {
base: H, // state we're proving values from.
changed: KeccakMemoryDB, // changed state via insertions.
changed: MemoryDB<KeccakHasher>, // changed state via insertions.
proof: Mutex<HashSet<DBValue>>,
}

Expand Down Expand Up @@ -183,13 +183,9 @@ impl<H: AsHashDB<KeccakHasher> + Send + Sync> HashDB<KeccakHasher> for Proving<H
}

impl<H: AsHashDB<KeccakHasher> + Send + Sync> Backend for Proving<H> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher> {
self
}
fn as_hashdb(&self) -> &HashDB<KeccakHasher> { self }

fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher> {
self
}
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher> { self }

fn add_to_account_cache(&mut self, _: Address, _: Option<Account>, _: bool) { }

Expand All @@ -214,7 +210,7 @@ impl<H: AsHashDB<KeccakHasher>> Proving<H> {
pub fn new(base: H) -> Self {
Proving {
base: base,
changed: KeccakMemoryDB::new(),
changed: MemoryDB::<KeccakHasher>::new(),
proof: Mutex::new(HashSet::new()),
}
}
Expand Down
4 changes: 2 additions & 2 deletions util/memorydb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ heapsize = "0.4"
hashdb = { version = "0.2.0", path = "../hashdb" }
plain_hasher = { path = "../plain_hasher" }
rlp = { version = "0.2.1", path = "../rlp" }
keccak-hasher = { path = "../keccak-hasher" }

[dev-dependencies]
tiny-keccak = "1.4.2"
ethereum-types = "0.3"
ethereum-types = "0.3"
keccak-hasher = { path = "../keccak-hasher" }
6 changes: 1 addition & 5 deletions util/memorydb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
extern crate elastic_array;
extern crate hashdb;
extern crate heapsize;
extern crate keccak_hasher;
extern crate plain_hasher;
extern crate rlp;
#[cfg(test)] extern crate keccak_hasher;
#[cfg(test)] extern crate tiny_keccak;
#[cfg(test)] extern crate ethereum_types;

use hashdb::{HashDB, Hasher, DBValue, AsHashDB};
use keccak_hasher::KeccakHasher;
use heapsize::HeapSizeOf;
use plain_hasher::H256FastMap;
use rlp::NULL_RLP;
Expand Down Expand Up @@ -85,9 +84,6 @@ pub struct MemoryDB<H: Hasher> {
data: H256FastMap<H, (DBValue, i32)>,
}

/// Convenience type for crates that need a `MemoryDB` with Keccak hashes
pub type KeccakMemoryDB = MemoryDB<KeccakHasher>;

impl<H: Hasher> MemoryDB<H> {
/// Create a new instance of the memory DB.
pub fn new() -> MemoryDB<H> {
Expand Down
1 change: 0 additions & 1 deletion util/patricia_trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl<T, E> error::Error for TrieError<T, E> where T: std::fmt::Debug, E: std::er
match *self {
TrieError::InvalidStateRoot(_) => "Invalid state root",
TrieError::IncompleteDatabase(_) => "Incomplete database",
// TrieError::DecoderError(_, ref err_string) => err_string,
TrieError::DecoderError(_, ref err) => err.description(),
}
}
Expand Down

0 comments on commit b48e2c8

Please sign in to comment.