-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use parity-common to make substrate generic over hasher and trie encoding codec #297
Conversation
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.
Minor changes and questions. Aside from that LGTM.
inner: Arc<HashMap<Vec<u8>, Vec<u8>>>, | ||
_hasher: PhantomData<H>, |
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?
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
substrate/state-machine/src/ext.rs
Outdated
@@ -123,7 +136,7 @@ impl<'a, B: 'a> Externalities for Ext<'a, B> | |||
42 | |||
} | |||
|
|||
fn storage_root(&mut self) -> [u8; 32] { | |||
fn storage_root(&mut self) -> H::Out where H::Out: Ord + Encodable { |
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 know this line isn't super long, however I think it reduces readability complexity if we had the where
in the second line
} | ||
|
||
impl<H: Hasher> TestExternalities<H> { | ||
#[cfg(test)] |
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.
is this #[cfg]
necessary?
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 think it's wrong. TestExternalities
is exported (and re-exported again in runtime-io
) so I think it needs to be pub
. Good catch.
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.
…and this change will break things in other crates. I don't think this PR can be merged as-is.
.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>`") |
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.
Also comments shouldn't be longer than 100chars, please wrap :) .
@@ -4,7 +4,7 @@ version = "0.1.0" | |||
authors = ["Parity Technologies <[email protected]>"] | |||
|
|||
[dependencies] | |||
ethcore-crypto = { git = "https://github.com/paritytech/parity.git", default_features = false } | |||
parity-crypto = { git = "https://github.com/paritytech/parity-common.git", default_features = false } |
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.
You missed renaming an import, see travis test.
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.
fixed, thanks!
…bstrate-state-machine-generic * refactor/environmental-generic-traits: whitespace Teach environmental! about generics Validator side of the collation protocol. (#295) Improve Wasm extern errors and increase heap (#299) Issue 212 - refactor Checkable trait to be more generic (#287) Fix for nightly 2018-07-10 (#296) PoC-2 tweaks (#293)
Closes #292 |
* master: README: fixed typo in docker run command (#518) Merge *_at methods. (#515) New flags to listen to all interfaces (#495) If contract reaches max depth, return Err (#503) Some networking cleanups (#504) Derivable Encode & Decode (#509) substrate: return Option in all storage related RPC methods (#510) Build with locked Cargo.lock on CI (#514) Place call data into a newly allocated pages (#502)
Haven't followed this PR from the beginning, but I wonder - why there are still direct requirements for |
Block: BlockT, | ||
H: Hasher, |
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.
reason for not integrating H
and C
into BlockT
?
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.
Not sure I understand what you mean here. You mean something like this?
pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'static {
type Extrinsic: Member + Codec;
type Header: Header<Hash=Self::Hash>;
type Hash: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]>;
type Hasher: Hasher<Out=<Self::Hash>::Output>;
type NodeCodec: NodeCodec<Self::Hasher>;
…
There is some significant overlap between the hashdb::Hasher
and substrate own Hash
trait and when talking this over with @rphmeier his idea was to get this in first and refine/unify further down the line. Not sure if Block
is the proper unification point but might very well be?
fn is_empty_node(data: &[u8]) -> bool { | ||
Rlp::new(data).is_empty() | ||
} | ||
fn empty_node() -> ElasticArray1024<u8> { |
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.
get them spaces out of here!!!!
|
||
fn branch_node<I>(children: I, value: Option<ElasticArray128<u8>>) -> ElasticArray1024<u8> | ||
where I: IntoIterator<Item=Option<ChildReference<<BlakeHasher as Hasher>::Out>>> | ||
{ |
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.
gah the indenting is borked. spaces!
two concerns:
this makes previously quite readable and concise code bloated and boilerplatey. |
Up to a point yes, the goal is to make things generic but the main motivating force was to share code with
That line can not not use concrete types, and this somewhat limits the extent to which the rest can be generic. I am sure I've missed places that could be generic and instead went for concrete types (do holler if you spot some!). The result is "a lot of BlakeHasher" all over. I think this can be alleviated in many places with some convenience types but I'd like to address that in a separate PR. I think it is easier to get good review feedback with all the nastiness laid bare and then sweep stuff under the rug in a a phase 2. If you disagree I'm happy to do it right away. |
…:paritytech/polkadot into refactor/substrate-state-machine-generic * 'refactor/substrate-state-machine-generic' of github.com:paritytech/polkadot: Update Cargo.lock Remove safe-mix (#521)
ok - make an issue for it and i guess we can revisit. |
…paritytech#297) * Make `polkadot-parachain` call `validate_block` instead of `validate` Also switch to rust 2018 in the crate * Use `rstd` * Make `load_params` a pointer
* from 8 to 25 * bump spec version * Update runtime/src/lib.rs
As part of the effort to extract and use common code between
parity-ethereum
andpolkadot
, this PR introduces the crates inparity-common
which in turn means switch to using generics for the hash type and node encoder and add concrete impls (BlakeHasher
andBlakeRlpCodec
).Part of the code is completely generic, e.g.
state-machine
, whereas other parts useBlakeHasher
andBlakeRlpCodec
to build concrete types. The exact layering of which parts are generic and which aren't is not very well thought out and feedback on how to improve that is most welcome.