This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Use parity-common to make substrate generic over hasher and trie encoding codec #297
Merged
Merged
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
45e0ee8
Genric over hasher
dvdplm eb26a69
WIP start adding NodeCodec
dvdplm acf8284
Add codec to TrieBackend
dvdplm 90707dc
Typechecks
dvdplm 4ccc851
Fix error type
dvdplm 21b7892
Cleanup
dvdplm 6b2fa02
Tests build (and fail)
dvdplm f331b0c
Fix tests: don't use MemoryDB::default()
dvdplm f0f2413
Lockfile
dvdplm 87740d7
Address grumbles
dvdplm a34f614
Teach environmental! about generics
dvdplm c7503ad
Add Finder artifacts
dvdplm 711da4f
whitespace
dvdplm a70f4a0
Merge branch 'refactor/environmental-generic-traits' into refactor/su…
dvdplm b4f210a
Add a toy impl of Hasher and plug it in to Externalities
dvdplm 3b5f60b
Use `uint` and `fixed-hash` from `parity-common`
dvdplm 1aeb495
lock file updates
dvdplm f7c30f4
Merge branch 'master' into refactor/substrate-state-machine-generic
dvdplm 80c96a1
Make hashes Encodable/Decodable
dvdplm e3277ac
lock file updates
dvdplm d38216b
Impl FromIterator for TestExternalities so we can collect() and use map!
dvdplm 5f19c7b
Use rustc-hex from crates
dvdplm 848ce8f
Fix tests in runtime-io
dvdplm 1358bb9
Merge branch 'master' into refactor/substrate-state-machine-generic
dvdplm 9b8f417
lockfile shenanigans
dvdplm ca01909
Add a BlakeHasher impl
dvdplm 9e42668
Use BlakeHasher in runtime-io
dvdplm 0f77d2b
lockfile updates
dvdplm 402c35c
ws
dvdplm 85b5fe1
Add a Blake2/RLP-flavoured NodeCodec
dvdplm 56649b6
Use Blake-flavoured Hasher and NodeCodec
dvdplm 5e5e61e
lockfile
dvdplm fc14711
Implement PartialEq and Default for TestExternalities
dvdplm 05d8200
Add note about limitations of environmental!
dvdplm 65c4f64
Make it compile, but this is probably broken
dvdplm 56f9ef6
Derive Debug so tests in executor can work
dvdplm eac3f25
Make executor use BlakeHasher
dvdplm f3422c5
ws
dvdplm aa40b78
WIP make client generic
dvdplm 54a2b66
typechecks
dvdplm 277aadd
cleanup
dvdplm 02a302a
client tests pass
dvdplm dae069b
Fix client/db
dvdplm 7a93cf7
cleanup
dvdplm 6329abb
Fix network
dvdplm dc7fc67
Fix rpc
dvdplm d7c0935
Fix service
dvdplm a553f31
Make TestExternalities work better au lieu d'un HashMap
dvdplm 9bfe799
Fix tests in council
dvdplm e4cefb3
Fix tests in contract
dvdplm 6277110
Fix tests in council
dvdplm adc13a2
Fix democracy
dvdplm 252bbd8
Add comment about odd-looking reexports in tests
dvdplm c94018c
Don't need to load branch
dvdplm c49609d
Fix staking
dvdplm 0fb6dc1
Fix session
dvdplm 6ebfc7f
Some polkadot fixes and lockfile
dvdplm 056bffd
Fix executive
dvdplm ccb61a9
Merge branch 'master' into refactor/substrate-state-machine-generic
dvdplm f565cf9
fixup lockfile
dvdplm d11d578
Fix polkadot/api
dvdplm c7334b2
Fix polkadot/service
dvdplm b6bde9a
Fix polkadot/runtime tests
dvdplm 08f25d3
Merge branch 'master' into refactor/substrate-state-machine-generic
dvdplm 9b139b2
Fix tests in test-runtime
dvdplm 0c82f95
Test fixes
dvdplm 50b4b12
Fix missing component in the `std` feature
dvdplm 111f9fd
Use PhantomData and Result from core
dvdplm 1276733
Fix paths
dvdplm 334e008
load heapsize on wasm
dvdplm 2faff87
implement `HeapSizeOf` for wasm
dvdplm 751fe9e
Add toy impl of `blake2_256` for no_std
dvdplm 81d7278
lockfile
dvdplm dd551a6
Merge branch 'master' into refactor/substrate-state-machine-generic
dvdplm dcd9541
Use kvdb* from parity-common and fix errors
dvdplm 2370a16
rebuilt lockfile
dvdplm 0d4a4fe
Add dummy impl of `on_advance_round` for rhododendron::Context
dvdplm 6367815
Fix build after merge
dvdplm cf7e338
Add HeapSizeOf bound where needed
dvdplm af1b17e
Sort out dependencies for no_std
dvdplm ca89697
Add HeapSizeOf bound where needed
dvdplm da711ef
use temp branch pending PR merges
dvdplm 3b206c2
Remove unneeded tests
dvdplm 8064c6d
Lock file and wasm artifacts
dvdplm 0066026
lockfile
dvdplm bfcf5df
Use magic commit for libp2p
dvdplm 35b29ba
Cleanup
dvdplm 04b7065
Implement blake2_256 for no_std
dvdplm 8152a78
Back on parity-common master
dvdplm cafe669
Merge branch 'master' into refactor/substrate-state-machine-generic
dvdplm 11ea517
missing type params
dvdplm 4d14020
Merge branch 'master' into refactor/substrate-state-machine-generic
gavofyork 19d07db
Update Cargo.lock
gavofyork 60df8c1
whitespace
dvdplm 6833f7b
Merge branch 'refactor/substrate-state-machine-generic' of github.com…
dvdplm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
WIP start adding NodeCodec
- Loading branch information
commit eb26a6939825f7579ee5516d13c85af85ccb2a01
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,26 +17,28 @@ | |
| //! Proving state machine backend. | ||
|
|
||
| use std::cell::RefCell; | ||
| use std::marker::PhantomData; | ||
| use hashdb::{Hasher, HashDB}; | ||
| use memorydb::MemoryDB; | ||
| use patricia_trie::{TrieDB, TrieError, Trie, Recorder}; | ||
| use patricia_trie::{TrieDB, Trie, Recorder, NodeCodec}; | ||
| use trie_backend::{TrieBackend, Ephemeral}; | ||
| use {Error, ExecutionError, Backend, TryIntoTrieBackend}; | ||
| use rlp::Encodable; | ||
|
|
||
| /// Patricia trie-based backend which also tracks all touched storage trie values. | ||
| /// These can be sent to remote node and used as a proof of execution. | ||
| pub struct ProvingBackend<H: Hasher> { | ||
| pub struct ProvingBackend<H: Hasher, C: NodeCodec<H>> { | ||
| backend: TrieBackend<H>, | ||
| proof_recorder: RefCell<Recorder<H::Out>>, | ||
| marker: PhantomData<C> // TODO: try to remove this if possible | ||
| } | ||
|
|
||
| impl<H: Hasher> ProvingBackend<H> { | ||
| impl<H: Hasher, C: NodeCodec<H>> ProvingBackend<H, C> { | ||
| /// Create new proving backend. | ||
| pub fn new(backend: TrieBackend<H>) -> Self { | ||
| ProvingBackend { | ||
| backend, | ||
| proof_recorder: RefCell::new(Recorder::new()), | ||
| proof_recorder: RefCell::new(Recorder::new()), marker: PhantomData | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -50,9 +52,10 @@ impl<H: Hasher> ProvingBackend<H> { | |
| } | ||
| } | ||
|
|
||
| impl<H> Backend<H> for ProvingBackend<H> | ||
| impl<H, C> Backend<H, C> for ProvingBackend<H, C> | ||
| where | ||
| H: Hasher, | ||
| C: NodeCodec<H>, | ||
| H::Out: Ord + Encodable | ||
| { | ||
| type Error = String; | ||
|
|
@@ -64,14 +67,16 @@ where | |
| self.backend.backend_storage(), | ||
| &mut read_overlay, | ||
| ); | ||
| let map_e = |e: Box<TrieError<H::Out, Self::Error>>| format!("Trie lookup error: {}", e); | ||
| // let map_e = |e: Box<TrieError<H::Out, Self::Error>>| format!("Trie lookup error: {}", e); | ||
| let map_e = |e| format!("Trie lookup error: {}", e); | ||
|
|
||
| let mut proof_recorder = self.proof_recorder.try_borrow_mut() | ||
| .expect("only fails when already borrowed; storage() is non-reentrant; qed"); | ||
| TrieDB::new(&eph, &self.backend.root()).map_err(map_e)? | ||
| TrieDB::<H, C>::new(&eph, &self.backend.root()).map_err(map_e)? | ||
| .get_with(key, &mut *proof_recorder).map(|x| x.map(|val| val.to_vec())).map_err(map_e) | ||
| } | ||
|
|
||
| // TODO: "error[E0283]: type annotations required: cannot resolve `_: patricia_trie::NodeCodec<H>`"/"note: required because of the requirements on the impl of `backend::Backend<H, _>` for `trie_backend::TrieBackend<H>`") | ||
|
||
| fn for_keys_with_prefix<F: FnMut(&[u8])>(&self, prefix: &[u8], f: F) { | ||
| self.backend.for_keys_with_prefix(prefix, f) | ||
| } | ||
|
|
@@ -87,14 +92,21 @@ where | |
| } | ||
| } | ||
|
|
||
| impl<H: Hasher> TryIntoTrieBackend<H> for ProvingBackend<H> { | ||
| impl<H: Hasher, C: NodeCodec<H>> TryIntoTrieBackend<H, C> for ProvingBackend<H, C> { | ||
| fn try_into_trie_backend(self) -> Option<TrieBackend<H>> { | ||
| None | ||
| } | ||
| } | ||
|
|
||
| /// Create proof check backend. | ||
| pub fn create_proof_check_backend<H: Hasher>(root: H::Out, proof: Vec<Vec<u8>>) -> Result<TrieBackend<H>, Box<Error>> { | ||
| pub fn create_proof_check_backend<H, C>( | ||
| root: H::Out, | ||
| proof: Vec<Vec<u8>> | ||
| ) -> Result<TrieBackend<H>, Box<Error>> | ||
| where | ||
| H: Hasher, | ||
| C: NodeCodec<H>, | ||
| { | ||
| let mut db = MemoryDB::new(); | ||
| for item in proof { | ||
| db.insert(&item); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Curious: why did you opt for an underscore here?
Uh oh!
There was an error while loading. Please reload this page.
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 real good reason. I keep going back and forth on how to name my phantoms, so I end up being inconsistent. Sometimes I like
marker, sometimes I name it for what it contains, sometimes with a_prefix to signal to the reader "never mind this, it's there to make the code compile and is not relevant".I'd like to have a rule to follow here. What do you use?
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.
Clippy states that underscore-prefixed names are expected to be in there for compile-passing-purposes only and aren't actually used. Which is the case here, and combined with a proper descriptive name, I think this is totally the appropriate way to do it, @dvdplm :) .
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.
"compile-passing-purposes" – rofl