core, trie: decode the value for storage dump #19943 (#1189)

* core, trie: decode the value for storage dump

* core/state: address comment

Co-authored-by: gary rong <garyrong0905@gmail.com>
This commit is contained in:
Daniel Liu 2025-07-28 16:52:06 +08:00 committed by GitHub
parent cf5766177a
commit 77522e51ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -116,7 +116,12 @@ func (s *StateDB) dump(c collector, excludeCode, excludeStorage, excludeMissingP
account.Storage = make(map[common.Hash]string)
storageIt := trie.NewIterator(obj.getTrie(s.db).NodeIterator(nil))
for storageIt.Next() {
account.Storage[common.BytesToHash(s.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value)
_, content, _, err := rlp.Split(storageIt.Value)
if err != nil {
log.Error("Failed to decode the value returned by iterator", "error", err)
continue
}
account.Storage[common.BytesToHash(s.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(content)
}
}
c.onAccount(addr, account)

View file

@ -35,7 +35,7 @@ type Iterator struct {
Err error
}
// NewIterator creates a new key-value iterator from a Node iterator.
// NewIterator creates a new key-value iterator from a node iterator.
// Note that the value returned by the iterator is raw. If the content is encoded
// (e.g. storage value is RLP-encoded), it's caller's duty to decode it.
func NewIterator(it NodeIterator) *Iterator {