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

fix: ensure wantlist gauge gets decremented on disconnect #332

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/peermanager/peerwantmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ func (pwm *peerWantManager) addPeer(p peer.ID) {

// RemovePeer removes a peer and its associated wants from tracking
func (pwm *peerWantManager) removePeer(p peer.ID) {
pws, ok := pwm.peerWants[p]
if !ok {
return
}

// Decrement the gauge by the number of pending want-blocks to the peer
for range pws.wantBlocks.Keys() {
pwm.wantBlockGauge.Dec()
}

delete(pwm.peerWants, p)
}

Expand Down
6 changes: 6 additions & 0 deletions internal/peermanager/peerwantmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,10 @@ func TestStats(t *testing.T) {
if g.count != 3 {
t.Fatal("Expected 3 want-blocks", g.count)
}

pwm.removePeer(p0)

if g.count != 0 {
t.Fatal("Expected all want-blocks to be removed with peer", g.count)
}
}