Skip to content

Commit 92ec07d

Browse files
committed
core/state: fix an account resurrection issue
1 parent 06d4470 commit 92ec07d

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

‎core/state/state_object.go‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,11 @@ func (s *stateObject) updateTrie(db Database) Trie {
297297
// Retrieve the snapshot storage map for the object
298298
var storage map[common.Hash][]byte
299299
if s.db.snap != nil {
300-
// Retrieve the old storage map, if available
301-
s.db.snapLock.RLock()
300+
// Retrieve the old storage map, if available, create a new one otherwise
302301
storage = s.db.snapStorage[s.addrHash]
303-
s.db.snapLock.RUnlock()
304-
305-
// If no old storage map was available, create a new one
306302
if storage == nil {
307303
storage = make(map[common.Hash][]byte)
308-
309-
s.db.snapLock.Lock()
310304
s.db.snapStorage[s.addrHash] = storage
311-
s.db.snapLock.Unlock()
312305
}
313306
}
314307
// Insert all the pending updates into the trie

‎core/state/statedb.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"math/big"
2424
"sort"
25-
"sync"
2625
"time"
2726

2827
"github.com/ethereum/go-ethereum/common"
@@ -72,7 +71,6 @@ type StateDB struct {
7271
snap snapshot.Snapshot
7372
snapAccounts map[common.Hash][]byte
7473
snapStorage map[common.Hash]map[common.Hash][]byte
75-
snapLock sync.RWMutex // Lock for the concurrent storage updaters
7674

7775
// This map holds 'live' objects, which will get modified while processing a state transition.
7876
stateObjects map[common.Address]*stateObject
@@ -468,6 +466,10 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
468466

469467
// If state snapshotting is active, cache the data til commit
470468
if s.snap != nil {
469+
// If the account is an empty resurrection, unmark the storage nil-ness
470+
if storage, ok := s.snapStorage[obj.addrHash]; storage == nil && ok {
471+
delete(s.snapStorage, obj.addrHash)
472+
}
471473
s.snapAccounts[obj.addrHash] = snapshot.AccountRLP(obj.data.Nonce, obj.data.Balance, obj.data.Root, obj.data.CodeHash)
472474
}
473475
}
@@ -484,10 +486,8 @@ func (s *StateDB) deleteStateObject(obj *stateObject) {
484486

485487
// If state snapshotting is active, cache the data til commit
486488
if s.snap != nil {
487-
s.snapLock.Lock()
488489
s.snapAccounts[obj.addrHash] = nil // We need to maintain account deletions explicitly
489490
s.snapStorage[obj.addrHash] = nil // We need to maintain storage deletions explicitly
490-
s.snapLock.Unlock()
491491
}
492492
}
493493

0 commit comments

Comments
 (0)