diff options
author | Péter Szilágyi <peterke@gmail.com> | 2019-03-26 17:00:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-26 17:00:35 +0800 |
commit | b8b4fb004c89d0d59276216ca73583f3ef608bba (patch) | |
tree | a2b3553b42426f6127ff403e9ba6ead765bc95d2 | |
parent | f03402232cd7bcc558b70a20df5b326b1d71e1ad (diff) | |
parent | 650ad19c2d3679c8ab8601f6772bee690293b30c (diff) | |
download | go-tangerine-b8b4fb004c89d0d59276216ca73583f3ef608bba.tar go-tangerine-b8b4fb004c89d0d59276216ca73583f3ef608bba.tar.gz go-tangerine-b8b4fb004c89d0d59276216ca73583f3ef608bba.tar.bz2 go-tangerine-b8b4fb004c89d0d59276216ca73583f3ef608bba.tar.lz go-tangerine-b8b4fb004c89d0d59276216ca73583f3ef608bba.tar.xz go-tangerine-b8b4fb004c89d0d59276216ca73583f3ef608bba.tar.zst go-tangerine-b8b4fb004c89d0d59276216ca73583f3ef608bba.zip |
Merge pull request #19308 from holiman/fix_reset_txpool
core: make txpool handle reorg due to setHead
-rw-r--r-- | core/tx_pool.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/core/tx_pool.go b/core/tx_pool.go index 552d3692b..305dfcc22 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -387,11 +387,26 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) { } else { // Reorg seems shallow enough to pull in all transactions into memory var discarded, included types.Transactions - var ( rem = pool.chain.GetBlock(oldHead.Hash(), oldHead.Number.Uint64()) add = pool.chain.GetBlock(newHead.Hash(), newHead.Number.Uint64()) ) + if rem == nil { + // This can happen if a setHead is performed, where we simply discard the old + // head from the chain. + // If that is the case, we don't have the lost transactions any more, and + // there's nothing to add + if newNum < oldNum { + // If the reorg ended up on a lower number, it's indicative of setHead being the cause + log.Debug("Skipping transaction reset caused by setHead", + "old", oldHead.Hash(), "oldnum", oldNum, "new", newHead.Hash(), "newnum", newNum) + } else { + // If we reorged to a same or higher number, then it's not a case of setHead + log.Warn("Transaction pool reset with missing oldhead", + "old", oldHead.Hash(), "oldnum", oldNum, "new", newHead.Hash(), "newnum", newNum) + } + return + } for rem.NumberU64() > add.NumberU64() { discarded = append(discarded, rem.Transactions()...) if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil { |