This commit is contained in:
☃ Elliot Shepherd 2016-09-24 04:38:05 +00:00 committed by GitHub
commit eade4d53fa
3 changed files with 22 additions and 6 deletions

View file

@ -82,6 +82,23 @@ func (ms *ManagedState) NewNonce(addr common.Address) uint64 {
return uint64(len(account.nonces)-1) + account.nstart 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 // GetNonce returns the canonical nonce for the managed or unmanaged account
func (ms *ManagedState) GetNonce(addr common.Address) uint64 { func (ms *ManagedState) GetNonce(addr common.Address) uint64 {
ms.mu.RLock() ms.mu.RLock()

View file

@ -226,9 +226,11 @@ func (self *StateObject) SetCode(code []byte) {
} }
func (self *StateObject) SetNonce(nonce uint64) { func (self *StateObject) SetNonce(nonce uint64) {
if nonce > self.nonce {
self.nonce = nonce self.nonce = nonce
self.dirty = true self.dirty = true
} }
}
func (self *StateObject) Nonce() uint64 { func (self *StateObject) Nonce() uint64 {
return self.nonce return self.nonce

View file

@ -140,10 +140,7 @@ func (b *EthApiBackend) GetPoolTransaction(hash common.Hash) *types.Transaction
} }
func (b *EthApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) { func (b *EthApiBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) {
b.eth.txMu.Lock() return b.eth.txPool.State().GetNextNonce(addr), nil
defer b.eth.txMu.Unlock()
return b.eth.txPool.State().GetNonce(addr), nil
} }
func (b *EthApiBackend) Stats() (pending int, queued int) { func (b *EthApiBackend) Stats() (pending int, queued int) {