state: fixed mutex lockes
This commit is contained in:
parent
474aa924ca
commit
8310bcda61
|
@ -37,7 +37,7 @@ func (ms *ManagedState) SetState(statedb *StateDB) {
|
||||||
|
|
||||||
// RemoveNonce removed the nonce from the managed state and all future pending nonces
|
// RemoveNonce removed the nonce from the managed state and all future pending nonces
|
||||||
func (ms *ManagedState) RemoveNonce(addr common.Address, n uint64) {
|
func (ms *ManagedState) RemoveNonce(addr common.Address, n uint64) {
|
||||||
if ms.HasAccount(addr) {
|
if ms.hasAccount(addr) {
|
||||||
ms.mu.Lock()
|
ms.mu.Lock()
|
||||||
defer ms.mu.Unlock()
|
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
|
// GetNonce returns the canonical nonce for the managed or unmanged account
|
||||||
func (ms *ManagedState) GetNonce(addr common.Address) uint64 {
|
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)
|
account := ms.getAccount(addr)
|
||||||
return uint64(len(account.nonces)) + account.nstart
|
return uint64(len(account.nonces)) + account.nstart
|
||||||
} else {
|
} else {
|
||||||
|
@ -77,6 +80,9 @@ func (ms *ManagedState) GetNonce(addr common.Address) uint64 {
|
||||||
|
|
||||||
// SetNonce sets the new canonical nonce for the managed state
|
// SetNonce sets the new canonical nonce for the managed state
|
||||||
func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64) {
|
func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64) {
|
||||||
|
ms.mu.Lock()
|
||||||
|
defer ms.mu.Unlock()
|
||||||
|
|
||||||
so := ms.GetOrNewStateObject(addr)
|
so := ms.GetOrNewStateObject(addr)
|
||||||
so.SetNonce(nonce)
|
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
|
// HasAccount returns whether the given address is managed or not
|
||||||
func (ms *ManagedState) HasAccount(addr common.Address) bool {
|
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()]
|
_, ok := ms.accounts[addr.Str()]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue