diff --git a/core/state/journal.go b/core/state/journal.go index 7d5648153c..0409df179e 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -148,7 +148,12 @@ type ( ) func (ch createObjectChange) revert(s *StateDB) { + s.stateObjectsMu.Lock() + delete(s.stateObjects, *ch.account) + + s.stateObjectsMu.Unlock() + delete(s.stateObjectsDirty, *ch.account) RevertWrite(s, blockstm.NewAddressKey(*ch.account)) } diff --git a/core/state/statedb.go b/core/state/statedb.go index d304ccb6b6..5c1b57de06 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -22,6 +22,7 @@ import ( "fmt" "math/big" "sort" + "sync" "time" "github.com/ethereum/go-ethereum/common" @@ -78,6 +79,7 @@ type StateDB struct { stateObjectsPending map[common.Address]struct{} // State objects finalized but not yet written to the trie stateObjectsDirty map[common.Address]struct{} // State objects modified in the current execution stateObjectsDestruct map[common.Address]struct{} // State objects destructed in the block + stateObjectsMu sync.RWMutex // Block-stm related fields mvHashmap *blockstm.MVHashMap @@ -154,6 +156,7 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) stateObjectsPending: make(map[common.Address]struct{}), stateObjectsDirty: make(map[common.Address]struct{}), stateObjectsDestruct: make(map[common.Address]struct{}), + stateObjectsMu: sync.RWMutex{}, revertedKeys: make(map[blockstm.Key]struct{}), logs: make(map[common.Hash][]*types.Log), preimages: make(map[common.Hash][]byte), @@ -997,6 +1000,9 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject { } func (s *StateDB) setStateObject(object *stateObject) { + s.stateObjectsMu.Lock() + defer s.stateObjectsMu.Unlock() + s.stateObjects[object.Address()] = object }