Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Refactor TrieNode, add levelup types #98

Merged
merged 3 commits into from
Aug 29, 2019
Merged

Refactor TrieNode, add levelup types #98

merged 3 commits into from
Aug 29, 2019

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Aug 15, 2019

On a high-level this PR:

  • Adds typedefs for leveldb
  • Breaks TrieNode into 3 classes BranchNode, ExtensionNode and LeafNode. It also makes the necessary modifications in BaseTrie to make it work with this new structure.

I'm still not fully sure about the details of the new types, specially around EmbeddedNode. That might have to change.

The way some of the internal methods modify nodes is very prone to errors (I had to debug a really nasty bug), due to arrays being mutable references.

I think after this I will try to promisify some parts and make the code a bit flatter so it's easier to work with.

Update: Oh and I tested it against ethereumjs-vm, tests pass.

@lgtm-com
Copy link

lgtm-com bot commented Aug 15, 2019

This pull request introduces 3 alerts when merging de8432e into 882799e - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class
  • 1 for Useless conditional

@holgerd77
Copy link
Member

Will try to have a look at this during the next 2-3 days, can't promise though.

@holgerd77
Copy link
Member

(review from everyone else welcome!)

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Changes in the PR are somewhat hard to review or directly comment on, since there is so much code logic shifted around and re-structured. Changes - especially this 3-Class breakdown - make a lot of sense and trie node code is a lot easier to read without all these conditional switches and the code logic directly attached to the corresponding node type.

I've now spent roughly an hour following various code structure parts and checked for equivalency, everything ok so far. One question on having a trie node base class - no blocker though - would give this a go.

}

hash(): Buffer {
return keccak256(this.serialize())
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it make sense to keep TrieNode as the parent class (or eventually an abstract class) and keep generic functionality like serialize() or hash() (and eventually some more) there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried something like that but the only method that can be moved there would be hash(). serialize() seems possible on first glance, but it calls this.raw() which has a different return type based on node type (specifically BranchNode is different than the other two).

Copy link
Member

Choose a reason for hiding this comment

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

Ok.

@s1na s1na merged commit d48a38c into master Aug 29, 2019
@s1na s1na deleted the ts-improvements branch August 29, 2019 08:07
@ryanio ryanio mentioned this pull request Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants