Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #536 from ipfs/fix/receive-contention
Browse files Browse the repository at this point in the history
fix: reduce receive contention
  • Loading branch information
Stebalien authored Oct 26, 2021
2 parents 462f628 + 10d1b2c commit 1ab28b8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/decision/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,18 @@ func (e *Engine) ReceiveFrom(from peer.ID, blks []blocks.Block) {
// Check each peer to see if it wants one of the blocks we received
var work bool
missingWants := make(map[peer.ID][]cid.Cid)
e.lock.RLock()
for _, b := range blks {
k := b.Cid()

for _, p := range e.peerLedger.Peers(k) {
e.lock.RLock()
peers := e.peerLedger.Peers(k)
e.lock.RUnlock()

for _, p := range peers {
e.lock.RLock()
ledger, ok := e.ledgerMap[p]
e.lock.RUnlock()

if !ok {
// This can happen if the peer has disconnected while we're processing this list.
log.Debugw("failed to find peer in ledger", "peer", p)
Expand Down Expand Up @@ -718,7 +724,6 @@ func (e *Engine) ReceiveFrom(from peer.ID, blks []blocks.Block) {
e.updateMetrics()
}
}
e.lock.RUnlock()

// If we found missing wants (e.g., because the peer disconnected, we have some races here)
// remove them from the list. Unfortunately, we still have to re-check because the user
Expand Down

0 comments on commit 1ab28b8

Please sign in to comment.