mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
eth/fetcher: protext txFromPeer against concurrent access
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
b2e6162da7
commit
041ba30ae3
1 changed files with 6 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"math"
|
||||
mrand "math/rand"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -201,6 +202,8 @@ type TxFetcher struct {
|
|||
|
||||
// txFromPeer stores where we received a transaction from
|
||||
txFromPeer map[common.Hash]string
|
||||
// should be protected by mutex
|
||||
txFromPeerMutex sync.Mutex
|
||||
|
||||
// Callbacks
|
||||
hasTx func(common.Hash) bool // Retrieves a tx from the local txpool
|
||||
|
|
@ -358,7 +361,10 @@ func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool)
|
|||
// Track a few interesting failure types
|
||||
switch {
|
||||
case err == nil:
|
||||
// protect against concurrent access to the map
|
||||
f.txFromPeerMutex.Lock()
|
||||
f.txFromPeer[batch[j].Hash()] = peer
|
||||
f.txFromPeerMutex.Unlock()
|
||||
|
||||
case errors.Is(err, txpool.ErrAlreadyKnown):
|
||||
duplicate++
|
||||
|
|
|
|||
Loading…
Reference in a new issue