add : mutex for stateObjects

This commit is contained in:
Shivam Sharma 2023-08-04 14:52:00 +05:30
parent b7efe4d3c2
commit 4d5cdae2e6
2 changed files with 11 additions and 0 deletions

View file

@ -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))
}

View file

@ -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
}