From 77522e51ec95d9d6faa084027f0a5aa73d1bf8bd Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Mon, 28 Jul 2025 16:52:06 +0800 Subject: [PATCH] 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 --- core/state/dump.go | 7 ++++++- trie/iterator.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/state/dump.go b/core/state/dump.go index 500c8aee39..116e238908 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -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) diff --git a/trie/iterator.go b/trie/iterator.go index 6c4da9b6ba..dc8b98c102 100644 --- a/trie/iterator.go +++ b/trie/iterator.go @@ -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 {