-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Conversation
Add associated const to Hasher for the fast-path Make HashDB impl for MemoryDB generic Make H256FastMap generic (eew)
Make AsHashDB generic
Bump version to 0.2.0 **NOTE** Hard coded to use `KeccakHasher`
…eric * origin/master: Fix local transactions policy. (#8691) Shutdown the Snapshot Service early (#8658) network-devp2p: handle UselessPeer disconnect (#8686) Fix compilation error on nightly rust (#8707) Add a test for decoding corrupt data (#8713) Update dev chain (#8717) Remove unused imports (#8722)
util/hashdb/src/lib.rs
Outdated
|
||
/// `HashDB` value type. | ||
pub type DBValue = ElasticArray128<u8>; | ||
|
||
/// Trait modelling datastore keyed by a 32-byte Keccak hash. | ||
pub trait HashDB: AsHashDB + Send + Sync { | ||
pub trait HashDB: Send + Sync { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I best fit in AsHashDB
in this? It takes a Hasher
now (see below), but not sure how to make pass the type argument.
util/patricia_trie/src/triedb.rs
Outdated
}, | ||
IterStep::Descend(Err(e)) => { | ||
return Some(Err(e)) | ||
IterStep::Descend::<H::Out>(Err(e)) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help needed here.
@@ -154,6 +156,7 @@ impl<'a> NibbleSlice<'a> { | |||
} | |||
|
|||
/// Encode while nibble slice in prefixed hex notation, noting whether it `is_leaf`. | |||
#[inline(always)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is non-trivial and so I'd probably annotate it #[inline]
so LLVM can make the choice to inline or not itself. #[inline(always)]
is only for really trivial functions that are really hot but you have profiled to see are not being inlined automatically (like len
below) and should be used with care. Although if you've benchmarked this and found that the (always)
is necessary then ignore this comment, of course!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did show up in the traces and looked suspicious, but now that I try again it doesn't seem to make any difference at all so dialing back to just #[inline]
makes sense. :)
ethcore/src/state/account.rs
Outdated
use trie::recorder::Recorder; | ||
|
||
// pub fn prove_storage(&self, db: &HashDB<KeccakHasher>, storage_key: H256) -> Result<(Vec<Bytes>, H256), Box<TrieError<<KeccakHasher as Hasher>::Out>>> { | ||
// pub fn prove_storage(&self, db: &HashDB<KeccakHasher>, storage_key: H256) -> Result<(Vec<Bytes>, H256), Box<TrieError>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obsolete?
AccountDB { | ||
db: db, | ||
address_hash: address_hash, | ||
} | ||
} | ||
} | ||
|
||
impl<'db> HashDB for AccountDB<'db>{ | ||
impl<'db> AsHashDB<KeccakHasher> for AccountDB<'db> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether it is possible to eliminate this boilerplate, due to super-trait upcasting still being an unresolved issue in rust (https://github.com/rust-lang/rust/issues/5665). But maybe we can ease that pain by using a macro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can file a refactor issue but I wouldn't call this a blocker for this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added here: #9022
ethcore/src/state_db.rs
Outdated
@@ -309,13 +311,15 @@ impl StateDB { | |||
} | |||
} | |||
|
|||
// TODO: needed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used in ethcore/src/client/client.rs:1688:52.
ethcore/src/state_db.rs
Outdated
self.db.as_hashdb() | ||
} | ||
|
||
// TODO: needed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used in ethcore/src/client/client.rs:613:62.
util/patricia_trie/src/triedbmut.rs
Outdated
let node = Node::from_rlp(&node_rlp, &*self.db, &mut self.storage); | ||
fn cache(&mut self, hash: H::Out) -> Result<StorageHandle, H::Out, C::Error> { | ||
let node_encoded = self.db.get(&hash).ok_or_else(|| TrieError::IncompleteDatabase(hash))?; | ||
// let node_encoded = self.db.get(&hash).ok_or_else(|| Box::new(TrieError::IncompleteDatabase(hash)))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obsolete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this one's actually wrong, good catch.
LGTM after a merge and some extra whitespace cleanup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo unresolved conflicts
@dvdplm please resolve conflicts 💪 |
…rp_sync_on_light_client * 'master' of https://github.com/paritytech/parity: Never drop local transactions from different senders. (openethereum#9002) Precise HTTP or WebSockets for JSON-RPC options (openethereum#9027) Recently rejected cache for transaction queue (openethereum#9005) Make HashDB generic (openethereum#8739) Only return error log for rustls (openethereum#9025) Update Changelogs for 1.10.8 and 1.11.5 (openethereum#9012)
The aim of this PR is to make
patricia-trie
usable from Polkadot by making it generic over both the hashing algorithm and the encoding scheme (currently Keccak-256 and RLP).Part of #7019 and #8620
The
HashDB
trait – the basis of the various Trie DB types – is made generic over the hashing algorithm and output format by introducing a newHasher
trait and threading it throughout the crates using it.With the
NodeCodec
trait we encapsulate the information needed to encode/decode a trie node. TheNodeCodec
trait is generic over theHasher
as well.The concrete implementations we need in Parity for Keccak-256 and RLP, are provided in two new mini-crates:
keccak-hasher
andpatricia-trie-ethereum
. Here we also provide type aliases forResult
andTrieError
.Benchmark compared to master: