aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-14 18:47:54 +0800
committerobscuren <geffobscura@gmail.com>2015-04-14 18:47:54 +0800
commit8310bcda6100cc703f5c1e22e0122ad7476d689d (patch)
treee8d8df21095eea52682f9dae59d18a8891e453fb /core
parent474aa924ca525da2fb43f888c6d527f39d07c261 (diff)
downloadgo-tangerine-8310bcda6100cc703f5c1e22e0122ad7476d689d.tar.gz
go-tangerine-8310bcda6100cc703f5c1e22e0122ad7476d689d.tar.zst
go-tangerine-8310bcda6100cc703f5c1e22e0122ad7476d689d.zip
state: fixed mutex lockes
Diffstat (limited to 'core')
-rw-r--r--core/state/managed_state.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/core/state/managed_state.go b/core/state/managed_state.go
index 97d098039..9e6be9980 100644
--- a/core/state/managed_state.go
+++ b/core/state/managed_state.go
@@ -37,7 +37,7 @@ func (ms *ManagedState) SetState(statedb *StateDB) {
// RemoveNonce removed the nonce from the managed state and all future pending nonces
func (ms *ManagedState) RemoveNonce(addr common.Address, n uint64) {
- if ms.HasAccount(addr) {
+ if ms.hasAccount(addr) {
ms.mu.Lock()
defer ms.mu.Unlock()
@@ -67,7 +67,10 @@ func (ms *ManagedState) NewNonce(addr common.Address) uint64 {
// GetNonce returns the canonical nonce for the managed or unmanged account
func (ms *ManagedState) GetNonce(addr common.Address) uint64 {
- if ms.HasAccount(addr) {
+ ms.mu.RLock()
+ defer ms.mu.RUnlock()
+
+ if ms.hasAccount(addr) {
account := ms.getAccount(addr)
return uint64(len(account.nonces)) + account.nstart
} else {
@@ -77,6 +80,9 @@ func (ms *ManagedState) GetNonce(addr common.Address) uint64 {
// SetNonce sets the new canonical nonce for the managed state
func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64) {
+ ms.mu.Lock()
+ defer ms.mu.Unlock()
+
so := ms.GetOrNewStateObject(addr)
so.SetNonce(nonce)
@@ -85,6 +91,12 @@ func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64) {
// HasAccount returns whether the given address is managed or not
func (ms *ManagedState) HasAccount(addr common.Address) bool {
+ ms.mu.RLock()
+ defer ms.mu.RUnlock()
+ return ms.hasAccount(addr)
+}
+
+func (ms *ManagedState) hasAccount(addr common.Address) bool {
_, ok := ms.accounts[addr.Str()]
return ok
}