core: reset txpool state on sethead (#22247)
fixes an issue where local transactions that were included in the chain before a SetHead were rejected if resubmitted, since the txpool had not reset the state to the current (older) state.
This commit is contained in:
parent
83e4c49e2b
commit
3512b41c5c
@ -1137,17 +1137,17 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
|
|||||||
// head from the chain.
|
// head from the chain.
|
||||||
// If that is the case, we don't have the lost transactions any more, and
|
// If that is the case, we don't have the lost transactions any more, and
|
||||||
// there's nothing to add
|
// there's nothing to add
|
||||||
if newNum < oldNum {
|
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
|
// 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",
|
log.Warn("Transaction pool reset with missing oldhead",
|
||||||
"old", oldHead.Hash(), "oldnum", oldNum, "new", newHead.Hash(), "newnum", newNum)
|
"old", oldHead.Hash(), "oldnum", oldNum, "new", newHead.Hash(), "newnum", newNum)
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 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)
|
||||||
|
// We still need to update the current state s.th. the lost transactions can be readded by the user
|
||||||
|
} else {
|
||||||
for rem.NumberU64() > add.NumberU64() {
|
for rem.NumberU64() > add.NumberU64() {
|
||||||
discarded = append(discarded, rem.Transactions()...)
|
discarded = append(discarded, rem.Transactions()...)
|
||||||
if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil {
|
if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil {
|
||||||
@ -1177,6 +1177,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
|
|||||||
reinject = types.TxDifference(discarded, included)
|
reinject = types.TxDifference(discarded, included)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Initialize the internal state to the current head
|
// Initialize the internal state to the current head
|
||||||
if newHead == nil {
|
if newHead == nil {
|
||||||
newHead = pool.chain.CurrentBlock().Header() // Special case during testing
|
newHead = pool.chain.CurrentBlock().Header() // Special case during testing
|
||||||
|
Loading…
Reference in New Issue
Block a user