-
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): introduce HashDB
interface and integrate into TrieDB
with added iterators
#4315
base: refactor/client-db
Are you sure you want to change the base?
Conversation
HashDB
interface and integrate into TrieDB
, with added iteratorsHashDB
interface and integrate into TrieDB
and added iterators
HashDB
interface and integrate into TrieDB
and added iteratorsHashDB
interface and integrate into TrieDB
with added iterators
183d6d7
to
a81ff1b
Compare
9877caa
to
a81ff1b
Compare
HashDB
interface and integrate into TrieDB
with added iteratorsHashDB
interface and integrate into TrieDB
with added iterators
e2449c1
to
95f5c35
Compare
…B, update tests, add required iterators, bug fixes.
95f5c35
to
a907f8a
Compare
// are referenced by the key to look them up in the trie. As multiple different tries can have | ||
// different values under the same key, it is up to the cache implementation to ensure that the | ||
// different values under the same key, it up to the cache implementation to ensure that the |
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.
Wasn't the "is" here correct?
@@ -358,15 +359,16 @@ type inspectResult struct { | |||
changed bool | |||
} | |||
|
|||
// inspect inspects the given node `stored` and calls the `inspector` function | |||
// inspect inspects the given node stored and calls the inspector function | |||
// then returns the new node and a boolean indicating if the node has changed | |||
func (t *TrieDB[H, Hasher]) inspect( | |||
stored StoredNode, | |||
key *nibbles.Nibbles, | |||
inspector func(Node, *nibbles.Nibbles) (action, error), | |||
) (*inspectResult, error) { | |||
// shallow copy since key will change offset through inspector |
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.
// shallow copy since key will change offset through inspector |
assuming key.Clone()
does not return a shallow copy
@@ -108,9 +109,9 @@ func (vr newValueRef[H]) equal(other nodeValue) bool { | |||
} | |||
|
|||
func NewValue[H hash.Hash](data []byte, threshold int) nodeValue { | |||
if len(data) >= threshold { | |||
if len(data) > threshold { |
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.
good catch, do we have a test for this?
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.
LGTM
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]>
Changes
hashdb.HashDB
hashdb.HashDB
is an interface introduced around a persistent store where the hash of the inserted value is used as the key. This interface is found prominently in substrate, and is used as the underlying storage oftriedb.TrieDB
. The integration of this interface as the underlying storage is included with the changes.hashdb.Prefix
is introduced to represent prefix partials where there could be an existence of a padded byte. This is useful to represent nibble offset for a partial key.memorydb.MemoryDB
memorydb.MemoryDB
is an implementation ofHashDB
with generic type parameters for theHash
,Hasher
,Key
, andKeyFunction
. Variations ofmemorydb.MemoryDB
using different key functions where the prefix is actually used vs not used are found in the substrate primitives and are used in PR #4318. One key feature that is of note is that values are actually reference counted, and not actually removed unless an equal amount of removes to the amount of gets.triedb.TrieDBIterator
andtriedb.TrieDBKeyIterator
These two iterator types are introduced and used in PR #4318. They are simply exported iterators that will iterate through the pairs (key, values) or just the keys in lexographic order.
triedb.TrieDB.LookupFirstDescendant
This method is required to for
TrieBackend
work in PR #4318. It will look up the first descendant node from a given key.Tests
go test -tags integration github.com/ChainSafe/gossamer
Issues
contributes to #3901