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

feat(primitives/state-machine) TrieBackend implementation #4318

Merged
merged 8 commits into from
Nov 14, 2024

Conversation

timwu20
Copy link
Contributor

@timwu20 timwu20 commented Nov 5, 2024

Changes

statemachine.Backend

statemachine.Backend is the interface that statemachine.TrieBackend implements. It is used to read from state which is backed by TrieDB, as well as iteration through iterators, and calculate state roots.

statemachine.TrieBackend

statemachine.TrieBackend implements the statemachine.Backend interface. The constructor NewTrieBackend takes as parameters an implementation of the TrieCacheProvider interface as well as an optional recorder.Recorder for node recording and eventual state proof generation. The storage that is read from is an implementation of TrieBackendStorage with an associated root hash to look up.

statemachine.ephemeral

ephemeral is private type to facilitate overlayed changes provided by a trie.PrefixedMemoryDB as the overlay level, while fetching from the underlying TrieBackendStorage when the hash isn't found in the overlay. This implements HashDB and is used as a n ephemeral storage layer for TrieBackend.

statemachine.MemoryDBTrieBackend

MemoryDBTrieBackend is a helper type that creates a TrieBackend where a trie.PrefixedMemoryDB is used as underlying storage. Currently only used in tests but I've exported it for now since it will be used in future work.

trie.SharedTrieCache

SharedTrieCache is used to hold all the trie nodes and values for all operations to the state. Within SharedTrieCache consists of both sharedNodeCache and sharedValueCache instances. There should only be one instance of a SharedTrieCache for a node.

trie.LocalTrieCache

SharedTrieCache.LocalTrieCache() is used to create a LocalTrieCache instance which will get merged back to the parent SharedTrieCache after state changes are processed and LocalTrieCache.Commit() is called.

trie.TrieCache

LocalTrieCache.TrieCache(storageRoot H) is used to create a TrieCache instance which implements triedb.TrieCache interface. TrieCache.MergeInto(ltc *LocalTrieCache, storageRoot H) is used to merge it back to the LocalTrieCache.

costlru.LRU

costlru.LRU is a wrapper around freelru.LRU to constrain the LRU based on the cost. The cost used in the various caches is byte size.

recorder.Recorder

Recorder is used to generate a compatible triedb.TrieRecorder using the private trieRecorder type. The recorder supports transactions which can be rolled back.

Tests

go test -tags integration github.com/ChainSafe/gossamer

Issues

closes #3901 #3836

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.

nits but LGTM

go.mod Outdated Show resolved Hide resolved
internal/cost-lru/cost_lru.go Show resolved Hide resolved
Base automatically changed from tim/triedb-iterators-hashdb to refactor/client-db November 13, 2024 07:43
@timwu20 timwu20 merged commit 23dd486 into refactor/client-db Nov 14, 2024
24 checks passed
@timwu20 timwu20 deleted the tim/trie-backend branch November 14, 2024 17:56
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.

2 participants