From 92ec07d63bc06241df6b9c8cec6c9d5954a192f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 27 Feb 2020 15:03:10 +0200 Subject: [PATCH] core/state: fix an account resurrection issue --- core/state/state_object.go | 9 +-------- core/state/statedb.go | 8 ++++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/core/state/state_object.go b/core/state/state_object.go index d10caa831..26e0b08f5 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -297,18 +297,11 @@ func (s *stateObject) updateTrie(db Database) Trie { // Retrieve the snapshot storage map for the object var storage map[common.Hash][]byte if s.db.snap != nil { - // Retrieve the old storage map, if available - s.db.snapLock.RLock() + // Retrieve the old storage map, if available, create a new one otherwise storage = s.db.snapStorage[s.addrHash] - s.db.snapLock.RUnlock() - - // If no old storage map was available, create a new one if storage == nil { storage = make(map[common.Hash][]byte) - - s.db.snapLock.Lock() s.db.snapStorage[s.addrHash] = storage - s.db.snapLock.Unlock() } } // Insert all the pending updates into the trie diff --git a/core/state/statedb.go b/core/state/statedb.go index b3ea95a46..d4a91ee71 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -22,7 +22,6 @@ import ( "fmt" "math/big" "sort" - "sync" "time" "github.com/ethereum/go-ethereum/common" @@ -72,7 +71,6 @@ type StateDB struct { snap snapshot.Snapshot snapAccounts map[common.Hash][]byte snapStorage map[common.Hash]map[common.Hash][]byte - snapLock sync.RWMutex // Lock for the concurrent storage updaters // This map holds 'live' objects, which will get modified while processing a state transition. stateObjects map[common.Address]*stateObject @@ -468,6 +466,10 @@ func (s *StateDB) updateStateObject(obj *stateObject) { // If state snapshotting is active, cache the data til commit if s.snap != nil { + // If the account is an empty resurrection, unmark the storage nil-ness + if storage, ok := s.snapStorage[obj.addrHash]; storage == nil && ok { + delete(s.snapStorage, obj.addrHash) + } s.snapAccounts[obj.addrHash] = snapshot.AccountRLP(obj.data.Nonce, obj.data.Balance, obj.data.Root, obj.data.CodeHash) } } @@ -484,10 +486,8 @@ func (s *StateDB) deleteStateObject(obj *stateObject) { // If state snapshotting is active, cache the data til commit if s.snap != nil { - s.snapLock.Lock() s.snapAccounts[obj.addrHash] = nil // We need to maintain account deletions explicitly s.snapStorage[obj.addrHash] = nil // We need to maintain storage deletions explicitly - s.snapLock.Unlock() } }