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

Introduce interface for TrieState, implement TrieState with new translation shim type from Externalities to TrieState. #4464

Open
timwu20 opened this issue Jan 14, 2025 · 0 comments

Comments

@timwu20
Copy link
Contributor

timwu20 commented Jan 14, 2025

Issue Summary

Taken from design doc:

The TrieState() method defined in StorageState is responsible for retrieving the state trie for a given block hash. It retrieves the Trie associated to the block hash and returns a *rtstorage.TrieState. This method is almost exclusively called before calling Instance.SetContextStorage to be able track storage changes by a runtime instance. There are methods in TrieState that handle storage changes as well as starting, rolling back, and committing transactions. The changes are handled through storageDiff currently, which keep all the changes in memory before commiting, and applying them to a new in-memory trie to compute the state root. StoreTrie is explicitly called to persist the trie in InmemoryStorageState to be accessible later.

Given that storing a block and it's associated storage changes are handled in one BlockImportOperation, we should remove the StoreTrie method entirely from StorageState. Rather BlockState.AddBlock should accept an introduced OverlayedChanges type analagous to the substrate primitive. I propose creating an interface around TrieState first. Second, we create a new type that implements TrieState which combines the read-only TrieBackend of the block hash, as well as the OverlayedChanges type that can be extracted before calling AddBlock. This new TrieState will be passed into the runtime instance. This introduced implementation of TrieState is analagous to the substrate primitive sp_statemachine::ext::Ext and the analgous trait to the TrieState interface is sp_externalities::Externalities. By following this approach, it should limit the amount of changes within the wazero runtime instance code.

Acceptance Criteria

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

No branches or pull requests

1 participant