浏览代码

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.
Brian Schroeder 8 年之前
父节点
当前提交
296450451b
共有 1 个文件被更改,包括 5 次插入3 次删除
  1. 5 3
      core/state/managed_state.go

+ 5 - 3
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)