mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/fetcher: use mutex for accessing underpriced
This commit is contained in:
parent
49b077e9ce
commit
4a148a4a5e
1 changed files with 8 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"fmt"
|
||||
mrand "math/rand"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -150,6 +151,7 @@ type TxFetcher struct {
|
|||
drop chan *txDrop
|
||||
quit chan struct{}
|
||||
|
||||
underpricedMu sync.Mutex
|
||||
underpriced map[common.Hash]int64 // Transactions discarded as too cheap (don't re-fetch)
|
||||
|
||||
// Stage 1: Waiting lists for newly discovered transactions that might be
|
||||
|
|
@ -229,6 +231,9 @@ func (f *TxFetcher) Notify(peer string, hashes []common.Hash) error {
|
|||
duplicate, underpriced int64
|
||||
)
|
||||
isUnderpriced := func(hash common.Hash) bool {
|
||||
f.underpricedMu.Lock()
|
||||
defer f.underpricedMu.Unlock()
|
||||
|
||||
prevTime, ok := f.underpriced[hash]
|
||||
if ok && prevTime+maxTxUnderpricedTimeout < time.Now().Unix() {
|
||||
delete(f.underpriced, hash)
|
||||
|
|
@ -311,6 +316,7 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool)
|
|||
// Avoid re-request this transaction when we receive another
|
||||
// announcement.
|
||||
if errors.Is(err, txpool.ErrUnderpriced) || errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||
f.underpricedMu.Lock()
|
||||
// If the set is to big, delete a pseudorandom element
|
||||
for hash := range f.underpriced {
|
||||
if len(f.underpriced) < maxTxUnderpricedSetSize {
|
||||
|
|
@ -320,6 +326,7 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool)
|
|||
}
|
||||
// add the underpriced transaction to the set
|
||||
f.underpriced[batch[j].Hash()] = batch[j].Time().Unix()
|
||||
f.underpricedMu.Unlock()
|
||||
}
|
||||
// Track a few interesting failure types
|
||||
switch {
|
||||
|
|
|
|||
Loading…
Reference in a new issue