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

reduce number of constraints for triedb types #9043

Merged
merged 4 commits into from
Jul 5, 2018
Merged

reduce number of constraints for triedb types #9043

merged 4 commits into from
Jul 5, 2018

Conversation

debris
Copy link
Collaborator

@debris debris commented Jul 4, 2018

No description provided.

@debris debris added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Jul 4, 2018

// NOTE: what we'd really like here is:
// `impl<H: Hasher> NodeCodec<H> for RlpNodeCodec<H> where H::Out: Decodable`
// but due to the current limitations of Rust const evaluation we can't
// do `const HASHED_NULL_NODE: H::Out = H::Out( … … )`. Perhaps one day soon?
impl NodeCodec<KeccakHasher> for RlpNodeCodec<KeccakHasher> {
impl NodeCodec<H256> for RlpNodeCodec<H256> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RlpNodeCodec can is no longer tied to KeccakHasher

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a problem, because now the HASHED_NULL_NODE will be defined but wrong for all non-keccak hashers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

@debris debris requested a review from dvdplm July 4, 2018 11:49
Copy link
Collaborator

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at that, much better! :)

(Whitespace grumbles)

where C: NodeCodec<H>
fn from_encoded<C, H>(data: &[u8], db: &HashDB<H>, storage: &mut NodeStorage<H::Out>) -> Self
where C: NodeCodec<H::Out>,
H: Hasher<Out = I>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd whitespace

where C: NodeCodec<H>
fn inline_or_hash<C, H>(node: &[u8], db: &HashDB<H>, storage: &mut NodeStorage<H::Out>) -> NodeHandle<H::Out>
where C: NodeCodec<H::Out>,
H: Hasher<Out = I>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odd whitespace

@dvdplm dvdplm added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jul 4, 2018
@dvdplm dvdplm requested a review from rphmeier July 4, 2018 14:43
@dvdplm
Copy link
Collaborator

dvdplm commented Jul 4, 2018

@rphmeier ptal, this helps with the parity-common stuff I'm working on, would be great to get it merged quickly.

C: NodeCodec<H> + 'db
where
H: Hasher + 'db,
C: NodeCodec<H::Out> + 'db
Copy link
Collaborator Author

@debris debris Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in next pr, it would be good to also remove these constrains from struct declaration, cause they are redundant

@rphmeier rphmeier added A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Jul 4, 2018
@rphmeier
Copy link
Contributor

rphmeier commented Jul 4, 2018

just in case it gets hidden: the H256 type can correspond to many different hashers, but the const HASHED_NULL_NODE is still a keccak256 hash. This is the main reason it was generic over Hasher in the first place.

@debris
Copy link
Collaborator Author

debris commented Jul 4, 2018

I reverted NodeCodec changes... haven't found a workaround for issue mentioned by @rphmeier

@debris debris added A0-pleasereview 🤓 Pull request needs code review. and removed A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. labels Jul 4, 2018
@5chdn 5chdn added this to the 1.12 milestone Jul 5, 2018
Copy link
Collaborator

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the new form I guess it's not superclear to me that this is an improvement, but I'm curious to learn why we should do this! :)

@@ -160,14 +165,14 @@ enum Action<H: Hasher> {
}

// post-insert action. Same as action without delete
enum InsertAction<H: Hasher> {
enum InsertAction<H> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education, why is it better to have the type param be unbounded like this? Knowing that H is a Hasher::Out is – to my eyes at least – helpful to understand what is going on, so curious about the reasoning here.

Copy link
Collaborator Author

@debris debris Jul 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education, why is it better to have the type param be unbounded like this?

It's more simple. It's easier to write unit tests and integrate it with other parts of the code. We don't need bounded types at all. std does not use them. Only the impl are bounded

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense. I think rob pointed me to https://rust-lang-nursery.github.io/api-guidelines/future-proofing.html#c-struct-bounds at one time.

@@ -77,36 +79,38 @@ enum Node<H: Hasher> {
Branch(Box<[Option<NodeHandle<H>>; 16]>, Option<DBValue>)
}

impl<H: Hasher> Node<H> {
impl<I> Node<I> where I: AsRef<[u8]> + AsMut<[u8]> + Default + HeapSizeOf + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does I stand for "item" or what was the thinking here? Maybe O for "Out" would help the reader get the right association?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is just an arbitrary uppercase character, I can change it to O if it makes it more readable :)

@dvdplm dvdplm merged commit 802d684 into master Jul 5, 2018
@debris debris deleted the triedb branch July 5, 2018 15:15
@debris debris added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jul 5, 2018
ordian added a commit to ordian/parity that referenced this pull request Jul 9, 2018
…rp_sync_on_light_client

* 'master' of https://github.com/paritytech/parity:
  Fixes for misbehavior reporting in AuthorityRound (openethereum#8998)
  A last bunch of txqueue performance optimizations (openethereum#9024)
  reduce number of constraints for triedb types (openethereum#9043)
  bump fs-swap to 0.2.3 so it is compatible with osx 10.11 again (openethereum#9050)
  Recursive test (openethereum#9042)
  Introduce more optional features in ethcore (openethereum#9020)
  Update ETSC bootnodes (openethereum#9038)
  Optimize pending transactions filter (openethereum#9026)
  eip160/eip161 spec: u64 -> BlockNumber (openethereum#9044)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants