Skip to content

Commit 3be6ad6

Browse files
committed
fix(state): Change StorageState.Entries() to expect a block hash
1 parent 1b1c4d6 commit 3be6ad6

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

dot/rpc/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type StorageAPI interface {
2323
GetStorage(bhash *common.Hash, key []byte) ([]byte, error)
2424
GetStorageChild(root *common.Hash, keyToChild []byte) (trie.Trie, error)
2525
GetStorageFromChild(root *common.Hash, keyToChild, key []byte) ([]byte, error)
26-
Entries(root *common.Hash) (map[string][]byte, error)
26+
Entries(bhash *common.Hash) (map[string][]byte, error)
2727
GetStateRootFromBlock(bhash *common.Hash) (*common.Hash, error)
2828
GetKeysWithPrefix(root *common.Hash, prefix []byte) ([][]byte, error)
2929
RegisterStorageObserver(observer state.Observer)

dot/rpc/modules/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type StorageAPI interface {
2121
GetStorage(bhash *common.Hash, key []byte) ([]byte, error)
2222
GetStorageChild(root *common.Hash, keyToChild []byte) (trie.Trie, error)
2323
GetStorageFromChild(root *common.Hash, keyToChild, key []byte) ([]byte, error)
24-
Entries(root *common.Hash) (map[string][]byte, error)
24+
Entries(bhash *common.Hash) (map[string][]byte, error)
2525
GetStateRootFromBlock(bhash *common.Hash) (*common.Hash, error)
2626
GetKeysWithPrefix(root *common.Hash, prefix []byte) ([][]byte, error)
2727
RegisterStorageObserver(observer state.Observer)

dot/rpc/modules/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (sm *StateModule) GetPairs(_ *http.Request, req *StatePairRequest, res *Sta
207207
}
208208

209209
if req.Prefix == nil || *req.Prefix == "" || *req.Prefix == "0x" {
210-
pairs, err := sm.storageAPI.Entries(stateRootHash)
210+
pairs, err := sm.storageAPI.Entries(req.Bhash)
211211
if err != nil {
212212
return err
213213
}

dot/state/inmemory_storage.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,18 @@ func (s *InmemoryStorageState) StorageRoot() (common.Hash, error) {
242242
return header.StateRoot, nil
243243
}
244244

245-
// Entries returns Entries from the trie with the given state root
246-
func (s *InmemoryStorageState) Entries(root *common.Hash) (map[string][]byte, error) {
245+
// Entries returns Entries from the trie for the given block hash
246+
func (s *InmemoryStorageState) Entries(bhash *common.Hash) (map[string][]byte, error) {
247+
if bhash == nil {
248+
b := s.blockState.BestBlockHash()
249+
bhash = &b
250+
}
251+
252+
root, err := s.GetStateRootFromBlock(bhash)
253+
if err != nil {
254+
return nil, err
255+
}
256+
247257
tr, err := s.loadTrie(root)
248258
if err != nil {
249259
return nil, err

dot/state/inmemory_storage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestStorage_LoadFromDB(t *testing.T) {
143143

144144
storage.blockState.GetTries().delete(root)
145145

146-
entries, err := storage.Entries(&root)
146+
entries, err := storage.Entries(&hash)
147147
require.NoError(t, err)
148148
require.Equal(t, 5, len(entries))
149149
}

dot/state/storage_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type StorageState interface {
2020
GenerateTrieProof(stateRoot common.Hash, keys [][]byte) ([][]byte, error)
2121
GetStorage(bhash *common.Hash, key []byte) ([]byte, error)
2222
StorageRoot() (common.Hash, error)
23-
Entries(root *common.Hash) (map[string][]byte, error) // should be overhauled to iterate
23+
Entries(bhash *common.Hash) (map[string][]byte, error) // should be overhauled to iterate
2424
GetKeysWithPrefix(root *common.Hash, prefix []byte) ([][]byte, error)
2525
GetStorageChild(root *common.Hash, keyToChild []byte) (trie.Trie, error)
2626
GetStorageFromChild(root *common.Hash, keyToChild, key []byte) ([]byte, error)

0 commit comments

Comments
 (0)