Skip to content

Commit df6c08a

Browse files
rjl493456442karalabe
authored andcommitted
core, trie: decode the value for storage dump (ethereum#19943)
* core, trie: decode the value for storage dump * core/state: address comment
1 parent 8657a0d commit df6c08a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

core/state/dump.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ func (self *StateDB) dump(c collector, excludeCode, excludeStorage, excludeMissi
118118
account.Storage = make(map[common.Hash]string)
119119
storageIt := trie.NewIterator(obj.getTrie(self.db).NodeIterator(nil))
120120
for storageIt.Next() {
121-
account.Storage[common.BytesToHash(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value)
121+
_, content, _, err := rlp.Split(storageIt.Value)
122+
if err != nil {
123+
log.Error("Failed to decode the value returned by iterator", "error", err)
124+
continue
125+
}
126+
account.Storage[common.BytesToHash(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(content)
122127
}
123128
}
124129
c.onAccount(addr, account)

trie/iterator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ type Iterator struct {
3434
Err error
3535
}
3636

37-
// NewIterator creates a new key-value iterator from a node iterator
37+
// NewIterator creates a new key-value iterator from a node iterator.
38+
// Note that the value returned by the iterator is raw. If the content is encoded
39+
// (e.g. storage value is RLP-encoded), it's caller's duty to decode it.
3840
func NewIterator(it NodeIterator) *Iterator {
3941
return &Iterator{
4042
nodeIt: it,

0 commit comments

Comments
 (0)