eth/handler: check for tx on chain as well

The fetcher should not fetch transactions that are already on chain.
Until now we were only checking in the txpool, but that does not
have the old transaction.
Here we extend the check to the chain as well. Still WIP, as this
check might be expensive, and there are other options to do the
same check.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2025-11-07 12:10:42 +01:00
parent 472e3a24ac
commit cc11ffd463
No known key found for this signature in database
GPG key ID: 0FE274EE8C95166E

View file

@ -179,9 +179,17 @@ func newHandler(config *handlerConfig) (*handler, error) {
addTxs := func(txs []*types.Transaction) []error {
return h.txpool.Add(txs, false)
}
hasTx := func(hash common.Hash) bool {
txpoolHas := h.txpool.Has(hash)
// check on chain as well (no need to check limbo separately, as chain checks limbo too)
_, tx := h.chain.GetCanonicalTransaction(hash)
if !txpoolHas && tx != nil {
log.Trace("handler: hasTx found tx on chain", "txhash", hash)
}
return txpoolHas || tx != nil
}
validateMeta := func(tx common.Hash, kind byte) error {
if h.txpool.Has(tx) {
if hasTx(tx) {
return txpool.ErrAlreadyKnown
}
if !h.txpool.FilterType(kind) {