Skip to content

Commit 87aa2e5

Browse files
committed
core/state, eth: fix dump-flaw
1 parent 1a35e34 commit 87aa2e5

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

core/state/dump.go

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
161161
} else {
162162
addr = common.BytesToAddress(addrBytes)
163163
address = &addr
164+
account.Address = address
164165
}
165166
obj := newObject(s, addr, &data)
166167
if !conf.SkipCode {

eth/api_debug_test.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ import (
3131
"github.com/ethereum/go-ethereum/crypto"
3232
"github.com/ethereum/go-ethereum/trie"
3333
"golang.org/x/exp/slices"
34+
"strings"
3435
)
3536

3637
var dumper = spew.ConfigState{Indent: " "}
3738

38-
func accountRangeTest(t *testing.T, trie *state.Trie, statedb *state.StateDB, start common.Hash, requestedNum int, expectedNum int) state.IteratorDump {
39-
result := statedb.IteratorDump(&state.DumpConfig{
39+
func accountRangeTest(t *testing.T, trie *state.Trie, statedb *state.StateDB, start common.Hash, requestedNum int, expectedNum int) state.Dump {
40+
result := statedb.RawDump(&state.DumpConfig{
4041
SkipCode: true,
4142
SkipStorage: true,
4243
OnlyWithAddresses: false,
@@ -47,12 +48,12 @@ func accountRangeTest(t *testing.T, trie *state.Trie, statedb *state.StateDB, st
4748
if len(result.Accounts) != expectedNum {
4849
t.Fatalf("expected %d results, got %d", expectedNum, len(result.Accounts))
4950
}
50-
for address := range result.Accounts {
51-
if address == (common.Address{}) {
52-
t.Fatalf("empty address returned")
51+
for addr, acc := range result.Accounts {
52+
if strings.HasSuffix(addr, "pre") || acc.Address == nil {
53+
t.Fatalf("account without prestate (address) returned: %v", addr)
5354
}
54-
if !statedb.Exist(address) {
55-
t.Fatalf("account not found in state %s", address.Hex())
55+
if !statedb.Exist(*acc.Address) {
56+
t.Fatalf("account not found in state %s", acc.Address.Hex())
5657
}
5758
}
5859
return result
@@ -92,16 +93,16 @@ func TestAccountRange(t *testing.T) {
9293
secondResult := accountRangeTest(t, &trie, sdb, common.BytesToHash(firstResult.Next), AccountRangeMaxResults, AccountRangeMaxResults)
9394

9495
hList := make([]common.Hash, 0)
95-
for addr1 := range firstResult.Accounts {
96-
// If address is empty, then it makes no sense to compare
96+
for addr1, acc := range firstResult.Accounts {
97+
// If address is non-available, then it makes no sense to compare
9798
// them as they might be two different accounts.
98-
if addr1 == (common.Address{}) {
99+
if acc.Address == nil {
99100
continue
100101
}
101102
if _, duplicate := secondResult.Accounts[addr1]; duplicate {
102103
t.Fatalf("pagination test failed: results should not overlap")
103104
}
104-
hList = append(hList, crypto.Keccak256Hash(addr1.Bytes()))
105+
hList = append(hList, crypto.Keccak256Hash(acc.Address.Bytes()))
105106
}
106107
// Test to see if it's possible to recover from the middle of the previous
107108
// set and get an even split between the first and second sets.
@@ -140,7 +141,7 @@ func TestEmptyAccountRange(t *testing.T) {
140141
st.Commit(0, true)
141142
st, _ = state.New(types.EmptyRootHash, statedb, nil)
142143

143-
results := st.IteratorDump(&state.DumpConfig{
144+
results := st.RawDump(&state.DumpConfig{
144145
SkipCode: true,
145146
SkipStorage: true,
146147
OnlyWithAddresses: true,

0 commit comments

Comments
 (0)