Skip to content

Commit 73aae02

Browse files
authored
Revert "core/state: clear out cached state data when reset occurs (ethereum#27376)"
This reverts commit f60b50e.
1 parent 65f16cd commit 73aae02

File tree

3 files changed

+1
-69
lines changed

3 files changed

+1
-69
lines changed

core/state/journal.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ type (
9393
account *common.Address
9494
prev *stateObject
9595
prevdestruct bool
96-
prevAccount []byte
97-
prevStorage map[common.Hash][]byte
9896
}
9997
suicideChange struct {
10098
account *common.Address
@@ -162,12 +160,6 @@ func (ch resetObjectChange) revert(s *StateDB) {
162160
if !ch.prevdestruct {
163161
delete(s.stateObjectsDestruct, ch.prev.address)
164162
}
165-
if ch.prevAccount != nil {
166-
s.snapAccounts[ch.prev.addrHash] = ch.prevAccount
167-
}
168-
if ch.prevStorage != nil {
169-
s.snapStorage[ch.prev.addrHash] = ch.prevStorage
170-
}
171163
}
172164

173165
func (ch resetObjectChange) dirtied() *common.Address {

core/state/statedb.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -627,34 +627,11 @@ func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject)
627627
if prev == nil {
628628
s.journal.append(createObjectChange{account: &addr})
629629
} else {
630-
// The original account should be marked as destructed and all cached
631-
// account and storage data should be cleared as well. Note, it must
632-
// be done here, otherwise the destruction event of original one will
633-
// be lost.
634630
_, prevdestruct := s.stateObjectsDestruct[prev.address]
635631
if !prevdestruct {
636632
s.stateObjectsDestruct[prev.address] = struct{}{}
637633
}
638-
var (
639-
account []byte
640-
storage map[common.Hash][]byte
641-
)
642-
// There may be some cached account/storage data already since IntermediateRoot
643-
// will be called for each transaction before byzantium fork which will always
644-
// cache the latest account/storage data.
645-
if s.snap != nil {
646-
account = s.snapAccounts[prev.addrHash]
647-
storage = s.snapStorage[prev.addrHash]
648-
delete(s.snapAccounts, prev.addrHash)
649-
delete(s.snapStorage, prev.addrHash)
650-
}
651-
s.journal.append(resetObjectChange{
652-
account: &addr,
653-
prev: prev,
654-
prevdestruct: prevdestruct,
655-
prevAccount: account,
656-
prevStorage: storage,
657-
})
634+
s.journal.append(resetObjectChange{account: &addr, prev: prev, prevdestruct: prevdestruct})
658635
}
659636
s.setStateObject(newobj)
660637
if prev != nil && !prev.deleted {

core/state/statedb_test.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ import (
3131

3232
"github.com/ethereum/go-ethereum/common"
3333
"github.com/ethereum/go-ethereum/core/rawdb"
34-
"github.com/ethereum/go-ethereum/core/state/snapshot"
3534
"github.com/ethereum/go-ethereum/core/types"
36-
"github.com/ethereum/go-ethereum/crypto"
37-
"github.com/ethereum/go-ethereum/trie"
3835
)
3936

4037
// Tests that updating a state trie does not leak any database writes prior to
@@ -1001,37 +998,3 @@ func TestStateDBTransientStorage(t *testing.T) {
1001998
t.Fatalf("transient storage mismatch: have %x, want %x", got, value)
1002999
}
10031000
}
1004-
1005-
func TestResetObject(t *testing.T) {
1006-
var (
1007-
disk = rawdb.NewMemoryDatabase()
1008-
tdb = trie.NewDatabase(disk)
1009-
db = NewDatabaseWithNodeDB(disk, tdb)
1010-
snaps, _ = snapshot.New(snapshot.Config{CacheSize: 10}, disk, tdb, types.EmptyRootHash)
1011-
state, _ = New(types.EmptyRootHash, db, snaps)
1012-
addr = common.HexToAddress("0x1")
1013-
slotA = common.HexToHash("0x1")
1014-
slotB = common.HexToHash("0x2")
1015-
)
1016-
// Initialize account with balance and storage in first transaction.
1017-
state.SetBalance(addr, big.NewInt(1))
1018-
state.SetState(addr, slotA, common.BytesToHash([]byte{0x1}))
1019-
state.IntermediateRoot(true)
1020-
1021-
// Reset account and mutate balance and storages
1022-
state.CreateAccount(addr)
1023-
state.SetBalance(addr, big.NewInt(2))
1024-
state.SetState(addr, slotB, common.BytesToHash([]byte{0x2}))
1025-
root, _ := state.Commit(true)
1026-
1027-
// Ensure the original account is wiped properly
1028-
snap := snaps.Snapshot(root)
1029-
slot, _ := snap.Storage(crypto.Keccak256Hash(addr.Bytes()), crypto.Keccak256Hash(slotA.Bytes()))
1030-
if len(slot) != 0 {
1031-
t.Fatalf("Unexpected storage slot")
1032-
}
1033-
slot, _ = snap.Storage(crypto.Keccak256Hash(addr.Bytes()), crypto.Keccak256Hash(slotB.Bytes()))
1034-
if !bytes.Equal(slot, []byte{0x2}) {
1035-
t.Fatalf("Unexpected storage slot value %v", slot)
1036-
}
1037-
}

0 commit comments

Comments
 (0)