aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorBrian Schroeder <bts@gmail.com>2017-02-01 17:55:46 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2017-02-01 17:55:46 +0800
commit296450451b090393b2dd11d057c5b72cb4d92356 (patch)
tree2ad668507fa331bec04b43714c3e0056860a298b /core
parent4f5f90222f06f87729a1f05f09472857fa9a32a7 (diff)
downloadgo-tangerine-296450451b090393b2dd11d057c5b72cb4d92356.tar.gz
go-tangerine-296450451b090393b2dd11d057c5b72cb4d92356.tar.zst
go-tangerine-296450451b090393b2dd11d057c5b72cb4d92356.zip
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.
Diffstat (limited to 'core')
-rw-r--r--core/state/managed_state.go8
1 files 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)