Merge pull request #46 from bts/quorum-managed-state-concurrent-write-fix

state: take write lock in GetNonce
This commit is contained in:
Samer Falah 2017-02-02 08:36:37 -05:00 committed by GitHub
commit e521fa067d
1 changed files with 5 additions and 3 deletions

View File

@ -82,10 +82,12 @@ func (ms *ManagedState) NewNonce(addr common.Address) uint64 {
return uint64(len(account.nonces)-1) + account.nstart
}
// GetNonce returns the canonical nonce for the managed or unmanaged account
// GetNonce returns the canonical nonce for the managed or unmanaged account.
//
// Because GetNonce mutates the DB, we must take a write lock.
func (ms *ManagedState) GetNonce(addr common.Address) uint64 {
ms.mu.RLock()
defer ms.mu.RUnlock()
ms.mu.Lock()
defer ms.mu.Unlock()
if ms.hasAccount(addr) {
account := ms.getAccount(addr)