Skip to content

Implement read-only StorageState functionality to translation shim type #4467

@timwu20

Description

@timwu20

Issue Summary

From design doc:

The following StorageState methods are relatively easy to implement in the translation shim by utilizing db.Backend.
internal/client/db/backend.go

GetStorage(root *common.Hash, key []byte) ([]byte, error)
GetStorageByBlockHash(bhash *common.Hash, key []byte) ([]byte, error)
GetKeysWithPrefix(root *common.Hash, prefix []byte) ([][]byte, error)
GetStorageChild(root *common.Hash, keyToChild []byte) (trie.Trie, error)
GetStorageFromChild(root *common.Hash, keyToChild, key []byte) ([]byte, error)
GetStateRootFromBlock(bhash *common.Hash) (*common.Hash, error)

StorageRoot() (common.Hash, error) 

Entries(root *common.Hash) (map[string][]byte, error)

LoadCode(hash *common.Hash) ([]byte, error)
LoadCodeHash(hash *common.Hash) (common.Hash, error)

GetStorageXXX methods are easily accessible by translating and implementing the StorageProvider trait for Client internal/client/client.go

GetStateRootFromBlock can be retrieved from already introduced HeaderBackend interface which db.Backend implements. Same for StorageRoot.

Entries should be refactored to utilize an iterator where Entries is called. I propose refactoring this method to return a PairsIter which iterates through the keys and values.

LoadCode and LoadCodeHash should be trivially implemented by accessing the state trie for a given hash and retrieving the entry with key ":code".

Acceptance Criteria

  • Introduce StorageProvider interface and implement it
  • Implement GetXXX methods
  • Implement StorageRoot method
  • Revise Entries function call to return iterator. (removed from scope)
  • Update all references to Entries to use iterator.
  • Implement LoadCode and LoadCodeHash.
  • Unit tests.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions