forked from cerc-io/plugeth
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.
This commit is contained in:
parent
60d3cc8b77
commit
b97f57882c
@ -18,6 +18,7 @@ package fetcher
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
mrand "math/rand"
|
mrand "math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
@ -277,30 +278,28 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool)
|
|||||||
)
|
)
|
||||||
errs := f.addTxs(txs)
|
errs := f.addTxs(txs)
|
||||||
for i, err := range errs {
|
for i, err := range errs {
|
||||||
if err != nil {
|
|
||||||
// Track the transaction hash if the price is too low for us.
|
// Track the transaction hash if the price is too low for us.
|
||||||
// Avoid re-request this transaction when we receive another
|
// Avoid re-request this transaction when we receive another
|
||||||
// announcement.
|
// announcement.
|
||||||
if err == core.ErrUnderpriced || err == core.ErrReplaceUnderpriced {
|
if errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced) {
|
||||||
for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize {
|
for f.underpriced.Cardinality() >= maxTxUnderpricedSetSize {
|
||||||
f.underpriced.Pop()
|
f.underpriced.Pop()
|
||||||
}
|
}
|
||||||
f.underpriced.Add(txs[i].Hash())
|
f.underpriced.Add(txs[i].Hash())
|
||||||
}
|
}
|
||||||
// Track a few interesting failure types
|
// Track a few interesting failure types
|
||||||
switch err {
|
switch {
|
||||||
case nil: // Noop, but need to handle to not count these
|
case err == nil: // Noop, but need to handle to not count these
|
||||||
|
|
||||||
case core.ErrAlreadyKnown:
|
case errors.Is(err, core.ErrAlreadyKnown):
|
||||||
duplicate++
|
duplicate++
|
||||||
|
|
||||||
case core.ErrUnderpriced, core.ErrReplaceUnderpriced:
|
case errors.Is(err, core.ErrUnderpriced) || errors.Is(err, core.ErrReplaceUnderpriced):
|
||||||
underpriced++
|
underpriced++
|
||||||
|
|
||||||
default:
|
default:
|
||||||
otherreject++
|
otherreject++
|
||||||
}
|
}
|
||||||
}
|
|
||||||
added = append(added, txs[i].Hash())
|
added = append(added, txs[i].Hash())
|
||||||
}
|
}
|
||||||
if direct {
|
if direct {
|
||||||
|
Loading…
Reference in New Issue
Block a user