-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Make HashDB generic #8739
Make HashDB generic #8739
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
|
|
||
| /// 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.
| } | ||
|
|
||
| /// 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?
| } | ||
|
|
||
| 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
| } | ||
| } | ||
|
|
||
| // 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. |
ordian
left a comment
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-trieusable 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
HashDBtrait – the basis of the various Trie DB types – is made generic over the hashing algorithm and output format by introducing a newHashertrait and threading it throughout the crates using it.With the
NodeCodectrait we encapsulate the information needed to encode/decode a trie node. TheNodeCodectrait is generic over theHasheras well.The concrete implementations we need in Parity for Keccak-256 and RLP, are provided in two new mini-crates:
keccak-hasherandpatricia-trie-ethereum. Here we also provide type aliases forResultandTrieError.Benchmark compared to master: