Skip to content

Commit

Permalink
problem: concurent map r/w for stateobject
Browse files Browse the repository at this point in the history
solution: sync locks for getStateObject and setStateObject

This is an initial hotfix for ethereumproject#284.

--
Note: StateDB uses stateObjects and stateObjectsDirty as maps,
apparently without any sync locks for granular actions (only statedb New, Reset, copy)

This seems like a red flag to me.
ETHF also doesn't use granular locks for map r/w's.

TODO: research this more.
  • Loading branch information
whilei committed Jun 30, 2017
1 parent abad7d5 commit 98fa7e4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,16 @@ func (self *StateDB) deleteStateObject(stateObject *StateObject) {
// Retrieve a state object given my the address. Returns nil if not found.
func (self *StateDB) GetStateObject(addr common.Address) (stateObject *StateObject) {
// Prefer 'live' objects.
self.lock.Lock()
if obj := self.stateObjects[addr]; obj != nil {
self.lock.Unlock()
if obj.deleted {

return nil
}
return obj
}
self.lock.Unlock()

// Load the object from the database.
enc := self.trie.Get(addr[:])
Expand All @@ -396,7 +400,9 @@ func (self *StateDB) GetStateObject(addr common.Address) (stateObject *StateObje
}

func (self *StateDB) setStateObject(object *StateObject) {
self.lock.Lock()
self.stateObjects[object.Address()] = object
self.lock.Unlock()
}

// Retrieve a state object or create a new state object if nil
Expand Down

0 comments on commit 98fa7e4

Please sign in to comment.