ソースを参照

core/state: fix an account resurrection issue

Péter Szilágyi 5 年 前
コミット
92ec07d63b
2 ファイル変更5 行追加12 行削除
  1. 1 8
      core/state/state_object.go
  2. 4 4
      core/state/statedb.go

+ 1 - 8
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

+ 4 - 4
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()
 	}
 }