From b05946953ff8acbef1053a475fff9a4ef8eb80de Mon Sep 17 00:00:00 2001 From: ia Date: Sat, 2 Jun 2018 19:35:59 +0200 Subject: [PATCH 1/2] problem: concurrent rw on state db stateobjects map solution: use mutex lock fixes #284, again --- core/state/statedb.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/state/statedb.go b/core/state/statedb.go index bc46ea010..6226975a4 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -349,12 +349,15 @@ 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, err := self.trie.TryGet(addr[:]) From 476a39f26ca7b0960f47abb623b92ca19d467664 Mon Sep 17 00:00:00 2001 From: ia Date: Mon, 4 Jun 2018 17:51:27 +0200 Subject: [PATCH 2/2] problem: bad fit for scoped conditional value --- core/state/statedb.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 6226975a4..01887a9b7 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -350,14 +350,14 @@ func (self *StateDB) deleteStateObject(stateObject *StateObject) { 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() + obj := self.stateObjects[addr] + self.lock.Unlock() + if obj != nil { if obj.deleted { return nil } return obj } - self.lock.Unlock() // Load the object from the database. enc, err := self.trie.TryGet(addr[:]) @@ -371,7 +371,7 @@ func (self *StateDB) getStateObject(addr common.Address) (stateObject *StateObje return nil } // Insert into the live set. - obj := newObject(self, addr, data, self.MarkStateObjectDirty) + obj = newObject(self, addr, data, self.MarkStateObjectDirty) self.setStateObject(obj) return obj }