Commit d310fe30 authored by Dirk McCormick's avatar Dirk McCormick

fix: ensure wantlist gauge gets decremented on disconnect

parent d39c7604
......@@ -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)
}
......
......@@ -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)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment