fixup: use RLock on txFromPeer

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2025-05-07 11:14:11 +02:00
parent 041ba30ae3
commit b405ad180c
No known key found for this signature in database
GPG key ID: 0FE274EE8C95166E

View file

@ -203,7 +203,7 @@ 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 // should be protected by mutex
txFromPeerMutex sync.Mutex txFromPeerMutex sync.RWMutex
// 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
@ -1047,6 +1047,8 @@ func rotateStrings(slice []string, n int) {
} }
func (f *TxFetcher) TxFromPeer(hash common.Hash) (string, bool) { func (f *TxFetcher) TxFromPeer(hash common.Hash) (string, bool) {
f.txFromPeerMutex.RLock()
defer f.txFromPeerMutex.RUnlock()
provenance, ok := f.txFromPeer[hash] provenance, ok := f.txFromPeer[hash]
return provenance, ok return provenance, ok
} }