Skip to content

Commit

Permalink
add : mutex for stateObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsharma committed Aug 4, 2023
1 parent b7efe4d commit 4d5cdae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
6 changes: 6 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"math/big"
"sort"
"sync"
"time"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 4d5cdae

Please sign in to comment.