Skip to content

Commit 2964504

Browse files
btsobscuren
authored andcommitted
state: take write lock in GetNonce (ethereum#3625)
We must take a write lock here because `GetNonce` calls `StateDB.GetStateObject`, which mutates the DB's live set.
1 parent 4f5f902 commit 2964504

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

core/state/managed_state.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ func (ms *ManagedState) NewNonce(addr common.Address) uint64 {
8282
return uint64(len(account.nonces)-1) + account.nstart
8383
}
8484

85-
// GetNonce returns the canonical nonce for the managed or unmanaged account
85+
// GetNonce returns the canonical nonce for the managed or unmanaged account.
86+
//
87+
// Because GetNonce mutates the DB, we must take a write lock.
8688
func (ms *ManagedState) GetNonce(addr common.Address) uint64 {
87-
ms.mu.RLock()
88-
defer ms.mu.RUnlock()
89+
ms.mu.Lock()
90+
defer ms.mu.Unlock()
8991

9092
if ms.hasAccount(addr) {
9193
account := ms.getAccount(addr)

0 commit comments

Comments
 (0)