From b97f57882c146cf1299a59fde9b41aeb786c4790 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Mon, 18 Oct 2021 15:34:20 -0500 Subject: [PATCH] eth/fetcher: remove superfluous nilness-check (#23739) * eth/fetcher: fix nilness check https://github.com/ethereum/go-ethereum/issues/23738 * eth/fetcher: Use errors.Is. PR feedback from @holiman. --- eth/fetcher/tx_fetcher.go | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/eth/fetcher/tx_fetcher.go b/eth/fetcher/tx_fetcher.go index 3ba7753916..b10c0db9ee 100644 --- a/eth/fetcher/tx_fetcher.go +++ b/eth/fetcher/tx_fetcher.go @@ -18,6 +18,7 @@ package fetcher import ( "bytes" + "errors" "fmt" mrand "math/rand" "sort" @@ -277,29 +278,27 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool) ) errs := f.addTxs(txs) for i, err := range errs { - if err != nil { - // Track the transaction hash if the price is too low for us. - // Avoid re-request this transaction when we receive another - // announcement. - if err == core.ErrUnderpriced || err == core.ErrReplaceUnderpriced { - for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize { - f.underpriced.Pop() - } - f.underpriced.Add(txs[i].Hash()) + // Track the transaction hash if the price is too low for us. + // Avoid re-request this transaction when we receive another + // announcement. + if errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced) { + for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize { + f.underpriced.Pop() } - // Track a few interesting failure types - switch err { - case nil: // Noop, but need to handle to not count these + f.underpriced.Add(txs[i].Hash()) + } + // Track a few interesting failure types + switch { + case err == nil: // Noop, but need to handle to not count these - case core.ErrAlreadyKnown: - duplicate++ + case errors.Is(err, core.ErrAlreadyKnown): + duplicate++ - case core.ErrUnderpriced, core.ErrReplaceUnderpriced: - underpriced++ + case errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced): + underpriced++ - default: - otherreject++ - } + default: + otherreject++ } added = append(added, txs[i].Hash()) }