Commit 29645045 authored by Brian Schroeder's avatar Brian Schroeder Committed by Jeffrey Wilcke

state: take write lock in GetNonce (#3625)

We must take a write lock here because `GetNonce` calls
`StateDB.GetStateObject`, which mutates the DB's live set.
parent 4f5f9022
...@@ -82,10 +82,12 @@ func (ms *ManagedState) NewNonce(addr common.Address) uint64 { ...@@ -82,10 +82,12 @@ func (ms *ManagedState) NewNonce(addr common.Address) uint64 {
return uint64(len(account.nonces)-1) + account.nstart 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 { func (ms *ManagedState) GetNonce(addr common.Address) uint64 {
ms.mu.RLock() ms.mu.Lock()
defer ms.mu.RUnlock() defer ms.mu.Unlock()
if ms.hasAccount(addr) { if ms.hasAccount(addr) {
account := ms.getAccount(addr) account := ms.getAccount(addr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment