diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-08-26 00:04:40 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-09-02 19:15:40 +0800 |
commit | b4a52513915d5a39ac055fc38cafed70098eb698 (patch) | |
tree | 1217ca54edf4fc72734dc00bf09d4a827106bd82 /core/tx_pool.go | |
parent | a183ea29f9313cb1d00ed8f73bfbc4ae51e9cb04 (diff) | |
download | go-tangerine-b4a52513915d5a39ac055fc38cafed70098eb698.tar.gz go-tangerine-b4a52513915d5a39ac055fc38cafed70098eb698.tar.zst go-tangerine-b4a52513915d5a39ac055fc38cafed70098eb698.zip |
core: abstract out a sorted transaction hash map
Diffstat (limited to 'core/tx_pool.go')
-rw-r--r-- | core/tx_pool.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/core/tx_pool.go b/core/tx_pool.go index 58d304f00..f8b11a7ce 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -154,7 +154,8 @@ func (pool *TxPool) resetState() { // Update all accounts to the latest known pending nonce for addr, list := range pool.pending { - pool.pendingState.SetNonce(addr, list.last+1) + txs := list.Flatten() // Heavy but will be cached and is needed by the miner anyway + pool.pendingState.SetNonce(addr, txs[len(txs)-1].Nonce()+1) } // Check the queue and move transactions over to the pending if possible // or remove those that have become invalid @@ -366,7 +367,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T // Set the potentially new pending nonce and notify any subsystems of the new tx pool.beats[addr] = time.Now() - pool.pendingState.SetNonce(addr, list.last+1) + pool.pendingState.SetNonce(addr, tx.Nonce()+1) go pool.eventMux.Post(TxPreEvent{tx}) } @@ -439,19 +440,20 @@ func (pool *TxPool) removeTx(hash common.Hash) { // Remove the transaction from the pending lists and reset the account nonce if pending := pool.pending[addr]; pending != nil { if removed, invalids := pending.Remove(tx); removed { - // If no more transactions are left, remove the list and reset the nonce + // If no more transactions are left, remove the list if pending.Empty() { delete(pool.pending, addr) delete(pool.beats, addr) - - pool.pendingState.SetNonce(addr, tx.Nonce()) } else { - // Otherwise update the nonce and postpone any invalidated transactions - pool.pendingState.SetNonce(addr, pending.last) + // Otherwise postpone any invalidated transactions for _, tx := range invalids { pool.enqueueTx(tx.Hash(), tx) } } + // Update the account nonce if needed + if nonce := tx.Nonce(); pool.pendingState.GetNonce(addr) > nonce { + pool.pendingState.SetNonce(addr, tx.Nonce()) + } } } // Transaction is in the future queue |