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

Commit

Permalink
fix: reduce receive contention
Browse files Browse the repository at this point in the history
This means we need to frequently re-take this lock, but it also means we
don't hold it while calling other functions that might block (e.g.,
while pushing jobs).
  • Loading branch information
Stebalien committed Oct 21, 2021
1 parent 462f628 commit 10d1b2c
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 10d1b2c

Please sign in to comment.