From 65a8d807f6df3ae2e1f80d355630cc04de36ed49 Mon Sep 17 00:00:00 2001 From: Brian Schroeder Date: Wed, 1 Feb 2017 04:55:46 -0500 Subject: [PATCH] state: take write lock in GetNonce We must take a write lock here because `GetNonce` calls `StateDB.GetStateObject`, which mutates the DB's live set. --- core/state/managed_state.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/state/managed_state.go b/core/state/managed_state.go index ad73dc0dc..0d8f9dd28 100644 --- a/core/state/managed_state.go +++ b/core/state/managed_state.go @@ -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)