Skip to content

Commit 37b712e

Browse files
committed
core/state: better detection of dirty storage mismatches
1 parent 1861642 commit 37b712e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

core/state/statedb_test.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,16 +584,6 @@ func forEachStorage(s *StateDB, addr common.Address, cb func(key, value common.H
584584
}
585585
}
586586
}
587-
// Now visit any remaining dirty storage which is not in trie
588-
for key, value := range so.dirtyStorage {
589-
if visited[key] {
590-
continue
591-
}
592-
if !cb(key, value) {
593-
return nil
594-
}
595-
}
596-
597587
return nil
598588
}
599589

@@ -628,6 +618,26 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
628618
forEachStorage(checkstate, addr, func(key, value common.Hash) bool {
629619
return checkeq("GetState("+key.Hex()+")", checkstate.GetState(addr, key), value)
630620
})
621+
other := checkstate.getStateObject(addr)
622+
// Check dirty storage which is not in trie
623+
if !maps.Equal(obj.dirtyStorage, other.dirtyStorage) {
624+
print := func(dirty map[common.Hash]common.Hash) string {
625+
var keys []common.Hash
626+
out := new(strings.Builder)
627+
for key := range dirty {
628+
keys = append(keys, key)
629+
}
630+
slices.SortFunc(keys, common.Hash.Cmp)
631+
for i, key := range keys {
632+
fmt.Fprintf(out, " %d. %v %v\n", i, key, dirty[key])
633+
}
634+
return out.String()
635+
}
636+
return fmt.Errorf("dirty storage err, have\n%v\nwant\n%v",
637+
print(obj.dirtyStorage),
638+
print(other.dirtyStorage))
639+
}
640+
631641
}
632642
// Check transient storage.
633643
{

0 commit comments

Comments
 (0)