mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46: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"
|
"math"
|
||||||
mrand "math/rand"
|
mrand "math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -201,6 +202,8 @@ type TxFetcher struct {
|
||||||
|
|
||||||
// txFromPeer stores where we received a transaction from
|
// txFromPeer stores where we received a transaction from
|
||||||
txFromPeer map[common.Hash]string
|
txFromPeer map[common.Hash]string
|
||||||
|
// should be protected by mutex
|
||||||
|
txFromPeerMutex sync.Mutex
|
||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
hasTx func(common.Hash) bool // Retrieves a tx from the local txpool
|
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
|
// Track a few interesting failure types
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
|
// protect against concurrent access to the map
|
||||||
|
f.txFromPeerMutex.Lock()
|
||||||
f.txFromPeer[batch[j].Hash()] = peer
|
f.txFromPeer[batch[j].Hash()] = peer
|
||||||
|
f.txFromPeerMutex.Unlock()
|
||||||
|
|
||||||
case errors.Is(err, txpool.ErrAlreadyKnown):
|
case errors.Is(err, txpool.ErrAlreadyKnown):
|
||||||
duplicate++
|
duplicate++
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue