Skip to content
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

Merged
merged 9 commits into from
Nov 13, 2024

Conversation

timwu20
Copy link
Contributor

@timwu20 timwu20 commented Nov 4, 2024

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 of triedb.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 of HashDB with generic type parameters for the Hash, Hasher, Key, and KeyFunction. Variations of memorydb.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 and triedb.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

@timwu20 timwu20 changed the title refactor(pkg/trie/triedb): Introduce HashDB interface and integrate into TrieDB, with added iterators refactor(pkg/trie/triedb): Introduce HashDB interface and integrate into TrieDB and added iterators Nov 4, 2024
@timwu20 timwu20 changed the base branch from development to refactor/client-db November 4, 2024 22:59
@timwu20 timwu20 changed the title refactor(pkg/trie/triedb): Introduce HashDB interface and integrate into TrieDB and added iterators refactor(pkg/trie/triedb): Introduce HashDB interface and integrate into TrieDB with added iterators Nov 4, 2024
@timwu20 timwu20 force-pushed the tim/triedb-iterators-hashdb branch 3 times, most recently from 183d6d7 to a81ff1b Compare November 5, 2024 14:29
@timwu20 timwu20 marked this pull request as ready for review November 5, 2024 20:09
@timwu20 timwu20 force-pushed the tim/triedb-iterators-hashdb branch from 9877caa to a81ff1b Compare November 5, 2024 20:39
@timwu20 timwu20 changed the title refactor(pkg/trie/triedb): Introduce HashDB interface and integrate into TrieDB with added iterators refactor(pkg/trie/triedb): introduce HashDB interface and integrate into TrieDB with added iterators Nov 5, 2024
@timwu20 timwu20 force-pushed the tim/triedb-iterators-hashdb branch from e2449c1 to 95f5c35 Compare November 6, 2024 03:04
@timwu20 timwu20 changed the base branch from refactor/client-db to tim/refactor-triedb-caching-base November 6, 2024 03:04
@timwu20 timwu20 changed the base branch from tim/refactor-triedb-caching-base to tim/refactor-client-db-base November 6, 2024 03:05
@timwu20 timwu20 changed the base branch from tim/refactor-client-db-base to refactor/client-db November 6, 2024 14:40
@timwu20 timwu20 force-pushed the tim/triedb-iterators-hashdb branch from 95f5c35 to a907f8a Compare November 6, 2024 14:46
internal/hash-db/hash_db.go Outdated Show resolved Hide resolved
internal/hash-db/hash_db.go Outdated Show resolved Hide resolved
pkg/trie/triedb/cache.go Outdated Show resolved Hide resolved
pkg/trie/triedb/triedb.go Outdated Show resolved Hide resolved
pkg/trie/triedb/triedb.go Show resolved Hide resolved
pkg/trie/triedb/triedb.go Outdated Show resolved Hide resolved
Copy link
Contributor

@dimartiro dimartiro left a comment

Choose a reason for hiding this comment

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

LGTM

@timwu20 timwu20 merged commit d5898f6 into refactor/client-db Nov 13, 2024
24 checks passed
@timwu20 timwu20 deleted the tim/triedb-iterators-hashdb branch November 13, 2024 07:43
timwu20 added a commit that referenced this pull request Dec 12, 2024
… into `TrieDB` with added iterators (#4315)

Co-authored-by: Haiko Schol <[email protected]>
timwu20 added a commit that referenced this pull request Dec 13, 2024
… into `TrieDB` with added iterators (#4315)

Co-authored-by: Haiko Schol <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants