mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/state, eth: fix dump-flaw
This commit is contained in:
parent
1a35e349c2
commit
87aa2e5aef
2 changed files with 14 additions and 12 deletions
|
|
@ -161,6 +161,7 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
|
||||||
} else {
|
} else {
|
||||||
addr = common.BytesToAddress(addrBytes)
|
addr = common.BytesToAddress(addrBytes)
|
||||||
address = &addr
|
address = &addr
|
||||||
|
account.Address = address
|
||||||
}
|
}
|
||||||
obj := newObject(s, addr, &data)
|
obj := newObject(s, addr, &data)
|
||||||
if !conf.SkipCode {
|
if !conf.SkipCode {
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,13 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dumper = spew.ConfigState{Indent: " "}
|
var dumper = spew.ConfigState{Indent: " "}
|
||||||
|
|
||||||
func accountRangeTest(t *testing.T, trie *state.Trie, statedb *state.StateDB, start common.Hash, requestedNum int, expectedNum int) state.IteratorDump {
|
func accountRangeTest(t *testing.T, trie *state.Trie, statedb *state.StateDB, start common.Hash, requestedNum int, expectedNum int) state.Dump {
|
||||||
result := statedb.IteratorDump(&state.DumpConfig{
|
result := statedb.RawDump(&state.DumpConfig{
|
||||||
SkipCode: true,
|
SkipCode: true,
|
||||||
SkipStorage: true,
|
SkipStorage: true,
|
||||||
OnlyWithAddresses: false,
|
OnlyWithAddresses: false,
|
||||||
|
|
@ -47,12 +48,12 @@ func accountRangeTest(t *testing.T, trie *state.Trie, statedb *state.StateDB, st
|
||||||
if len(result.Accounts) != expectedNum {
|
if len(result.Accounts) != expectedNum {
|
||||||
t.Fatalf("expected %d results, got %d", expectedNum, len(result.Accounts))
|
t.Fatalf("expected %d results, got %d", expectedNum, len(result.Accounts))
|
||||||
}
|
}
|
||||||
for address := range result.Accounts {
|
for addr, acc := range result.Accounts {
|
||||||
if address == (common.Address{}) {
|
if strings.HasSuffix(addr, "pre") || acc.Address == nil {
|
||||||
t.Fatalf("empty address returned")
|
t.Fatalf("account without prestate (address) returned: %v", addr)
|
||||||
}
|
}
|
||||||
if !statedb.Exist(address) {
|
if !statedb.Exist(*acc.Address) {
|
||||||
t.Fatalf("account not found in state %s", address.Hex())
|
t.Fatalf("account not found in state %s", acc.Address.Hex())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
@ -92,16 +93,16 @@ func TestAccountRange(t *testing.T) {
|
||||||
secondResult := accountRangeTest(t, &trie, sdb, common.BytesToHash(firstResult.Next), AccountRangeMaxResults, AccountRangeMaxResults)
|
secondResult := accountRangeTest(t, &trie, sdb, common.BytesToHash(firstResult.Next), AccountRangeMaxResults, AccountRangeMaxResults)
|
||||||
|
|
||||||
hList := make([]common.Hash, 0)
|
hList := make([]common.Hash, 0)
|
||||||
for addr1 := range firstResult.Accounts {
|
for addr1, acc := range firstResult.Accounts {
|
||||||
// If address is empty, then it makes no sense to compare
|
// If address is non-available, then it makes no sense to compare
|
||||||
// them as they might be two different accounts.
|
// them as they might be two different accounts.
|
||||||
if addr1 == (common.Address{}) {
|
if acc.Address == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, duplicate := secondResult.Accounts[addr1]; duplicate {
|
if _, duplicate := secondResult.Accounts[addr1]; duplicate {
|
||||||
t.Fatalf("pagination test failed: results should not overlap")
|
t.Fatalf("pagination test failed: results should not overlap")
|
||||||
}
|
}
|
||||||
hList = append(hList, crypto.Keccak256Hash(addr1.Bytes()))
|
hList = append(hList, crypto.Keccak256Hash(acc.Address.Bytes()))
|
||||||
}
|
}
|
||||||
// Test to see if it's possible to recover from the middle of the previous
|
// Test to see if it's possible to recover from the middle of the previous
|
||||||
// set and get an even split between the first and second sets.
|
// set and get an even split between the first and second sets.
|
||||||
|
|
@ -140,7 +141,7 @@ func TestEmptyAccountRange(t *testing.T) {
|
||||||
st.Commit(0, true)
|
st.Commit(0, true)
|
||||||
st, _ = state.New(types.EmptyRootHash, statedb, nil)
|
st, _ = state.New(types.EmptyRootHash, statedb, nil)
|
||||||
|
|
||||||
results := st.IteratorDump(&state.DumpConfig{
|
results := st.RawDump(&state.DumpConfig{
|
||||||
SkipCode: true,
|
SkipCode: true,
|
||||||
SkipStorage: true,
|
SkipStorage: true,
|
||||||
OnlyWithAddresses: true,
|
OnlyWithAddresses: true,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue