Skip to content

Commit a22819a

Browse files
prestonvanloonjagdeep sidhu
authored and
jagdeep sidhu
committed
eth/fetcher: remove superfluous nilness-check (ethereum#23739)
* eth/fetcher: fix nilness check ethereum#23738 * eth/fetcher: Use errors.Is. PR feedback from @holiman.
1 parent dc3ba2c commit a22819a

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

eth/fetcher/tx_fetcher.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package fetcher
1818

1919
import (
2020
"bytes"
21+
"errors"
2122
"fmt"
2223
mrand "math/rand"
2324
"sort"
@@ -277,29 +278,27 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool)
277278
)
278279
errs := f.addTxs(txs)
279280
for i, err := range errs {
280-
if err != nil {
281-
// Track the transaction hash if the price is too low for us.
282-
// Avoid re-request this transaction when we receive another
283-
// announcement.
284-
if err == core.ErrUnderpriced || err == core.ErrReplaceUnderpriced {
285-
for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize {
286-
f.underpriced.Pop()
287-
}
288-
f.underpriced.Add(txs[i].Hash())
281+
// Track the transaction hash if the price is too low for us.
282+
// Avoid re-request this transaction when we receive another
283+
// announcement.
284+
if errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced) {
285+
for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize {
286+
f.underpriced.Pop()
289287
}
290-
// Track a few interesting failure types
291-
switch err {
292-
case nil: // Noop, but need to handle to not count these
288+
f.underpriced.Add(txs[i].Hash())
289+
}
290+
// Track a few interesting failure types
291+
switch {
292+
case err == nil: // Noop, but need to handle to not count these
293293

294-
case core.ErrAlreadyKnown:
295-
duplicate++
294+
case errors.Is(err, core.ErrAlreadyKnown):
295+
duplicate++
296296

297-
case core.ErrUnderpriced, core.ErrReplaceUnderpriced:
298-
underpriced++
297+
case errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced):
298+
underpriced++
299299

300-
default:
301-
otherreject++
302-
}
300+
default:
301+
otherreject++
303302
}
304303
added = append(added, txs[i].Hash())
305304
}

0 commit comments

Comments
 (0)