-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(pkg/trie/triedb): implement generics, refactor nibbles, revise iterator #4221
Conversation
6759481
to
cc55742
Compare
895baf8
to
1a55c3e
Compare
665a370
to
9c82571
Compare
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.
A few comments but overall ok!
Thanks for spending time working on this changes Tim! I tried to keep the TrieDB
as simple as possible but it seems that it wasn't enough 💔
You did all the heavy lifting @dimartiro! The fact that I have something to integrate with and contribute to is a testament to your hard work. 💪 |
cc81983
to
e428890
Compare
94949b5
to
4d95a0a
Compare
…, remove caching temporarily
Co-authored-by: Haiko Schol <[email protected]>
Co-authored-by: Haiko Schol <[email protected]>
Co-authored-by: Haiko Schol <[email protected]>
Co-authored-by: Haiko Schol <[email protected]>
dddbecc
to
1ffda9a
Compare
Changes
hash.Hash
andhash.Hasher
interface constraints intotriedb
package.runtime.Hash
andruntime.Hasher
already ondevelopment
.hash.H256
for the hash andruntime.BlakeTwo256
as the hasher.triedb
. IntroducesNibbleSlice
,Nibbles
, andLeftNibbles
. Each of these introduced types has their own distinct public interface and are used in different components withintriedb
.Nibbles
is analogous totrie_db::nibble::NibbleSlice
. Primarily used to avoid costly slice manipulation and unnecessary copying of underlying bytes. Able to represent different nibble starting points, but not mutable to be able to reconstruct full keys.NibbleSlice
is analogous totrie_db::nibble::NibbleVec
. Mutable in the sense you can push and pop nibbles as well as truncate. Used to reconstruct full keys.LeftNibbles
is analogous totrie_db::nibble::LeftNibbleSlice
. Used in proof generation and verification. SinceNibbleSlice
andNibbles
are right aligned it makes it more expensive to truncate.LeftNibbles
left aligns the nibbles which facilitates faster truncation.TrieDBRawIterator
which is imported by the state machine primitives in substrate. This is embedded in other types to be able to iterate and return expected types. TherawItem
introduced that is returned byrawIterator.nextRawItem
includes the partial key asNibbleSlice
, hash of the node, and an in-memory type that fulfills thecodec.EncodedNode
interface (Branch
orLeaf
).Notes
Cache
interface to avoid too many code changes to how we constructTrieDB
s and the options we provide it.triedb
package.Tests
go test -tags integration github.com/ChainSafe/gossamer
Issues
contributes to #4157