From 1ad27dbb4f67e8403bdcbed4a80c8d93559ac2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=83=20Elliot=20Shepherd?= Date: Fri, 26 Aug 2016 14:23:42 +1000 Subject: [PATCH] Terrible horrible no good very bad fix for #2950 --- core/state/managed_state.go | 17 +++++++++++++++++ core/state/state_object.go | 6 ++++-- eth/api_backend.go | 5 +---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/core/state/managed_state.go b/core/state/managed_state.go index f8e2f2b876..6a1514508e 100644 --- a/core/state/managed_state.go +++ b/core/state/managed_state.go @@ -82,6 +82,23 @@ func (ms *ManagedState) NewNonce(addr common.Address) uint64 { return uint64(len(account.nonces)-1) + account.nstart } +// GetNextNonce returns the canonical nonce for the managed or unmanaged account and increments it by one +func (ms *ManagedState) GetNextNonce(addr common.Address) uint64 { + ms.mu.Lock() + defer ms.mu.Unlock() + + var nonce uint64 + + if ms.hasAccount(addr) { + account := ms.getAccount(addr) + nonce = uint64(len(account.nonces)) + account.nstart + } else { + nonce = ms.StateDB.GetNonce(addr) + } + ms.StateDB.SetNonce(addr, nonce+1) + return nonce +} + // GetNonce returns the canonical nonce for the managed or unmanaged account func (ms *ManagedState) GetNonce(addr common.Address) uint64 { ms.mu.RLock() diff --git a/core/state/state_object.go b/core/state/state_object.go index 769c63d42d..84a37e9833 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -229,8 +229,10 @@ func (self *StateObject) SetCode(code []byte) { } func (self *StateObject) SetNonce(nonce uint64) { - self.nonce = nonce - self.dirty = true + if nonce > self.nonce { + self.nonce = nonce + self.dirty = true + } } func (self *StateObject) Nonce() uint64 { diff --git a/eth/api_backend.go b/eth/api_backend.go index efcdb33619..bab6f4e7ae 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -136,10 +136,7 @@ func (b *EthApiBackend) GetPoolTransaction(txHash common.Hash) *types.Transactio } func (b *EthApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) { - b.eth.txMu.Lock() - defer b.eth.txMu.Unlock() - - return b.eth.txPool.State().GetNonce(addr), nil + return b.eth.txPool.State().GetNextNonce(addr), nil } func (b *EthApiBackend) Stats() (pending int, queued int) {