diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-16 07:14:27 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-16 07:28:24 +0800 |
commit | 3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a (patch) | |
tree | b2d4a5e7fcc1da2fd5b1aa3c139ddc7594c8646c /core/state | |
parent | 97d2954e227049a089652d91e6fb0ea1c8115cc6 (diff) | |
parent | c4678ffd77a18a9d03c888fdf242c9e5915b9f5f (diff) | |
download | dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.gz dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.bz2 dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.lz dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.xz dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.zst dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.zip |
Merge branch 'develop' into downloader-proto
Diffstat (limited to 'core/state')
-rw-r--r-- | core/state/managed_state.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/core/state/managed_state.go b/core/state/managed_state.go index 9d2fc48e7..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() @@ -52,8 +52,8 @@ func (ms *ManagedState) RemoveNonce(addr common.Address, n uint64) { // NewNonce returns the new canonical nonce for the managed account func (ms *ManagedState) NewNonce(addr common.Address) uint64 { - ms.mu.RLock() - defer ms.mu.RUnlock() + ms.mu.Lock() + defer ms.mu.Unlock() account := ms.getAccount(addr) for i, nonce := range account.nonces { @@ -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 } |