chanfitness: only process online events for peers with channels
What changed, and why it matters
This change fixes a minor logic bug in LND's channel-fitness monitoring. Previously, the code would create a monitoring entry for any peer that came online, even if there was no open channel with that peer. Now it ignores online events from peers that do not have an open channel. This is a correctness and resource-usage improvement, not a security vulnerability.
No security action required. Treat as a normal bug fix or resource-usage improvement. Reviewers may optionally verify that ignoring non-channel peer events does not break channel-fitness metrics.
Security signals we found
No security-relevant signals present
Change is a correctness/resource fix, not a vulnerability patch
Evidence from the diff
In chanfitness/chaneventstore.go, peerEvent() previously called getPeerMonitor(), which would lazily create a peer monitor for any peer. The patch changes peerEvent() to look up c.peers[peer] directly and silently ignore the event if the peer has no entry, which only happens when there is no open channel. The log level was also changed from Error to Trace. This prevents spurious monitor creation and error logging for non-channel peers.
Changed components
chanfitness/chaneventstore.gopeerEvent() functionInspect captured patch +8 / −5
diff --git a/chanfitness/chaneventstore.go b/chanfitness/chaneventstore.go
index 29a1df9..fe7ca40 100644
--- a/chanfitness/chaneventstore.go
+++ b/chanfitness/chaneventstore.go
@@ -313,12 +313,15 @@ func (c *ChannelEventStore) closeChannel(channelPoint wire.OutPoint,
}
}
-// peerEvent creates a peer monitor for a peer if we do not currently have
-// one, and adds an online event to it.
+// peerEvent adds an online event to a peer's monitor. If the peer is not
+// yet known to the event store, the event is ignored. A peer is only known to
+// the event store if we have an open channel with them.
func (c *ChannelEventStore) peerEvent(peer route.Vertex, online bool) {
- peerMonitor, err := c.getPeerMonitor(peer)
- if err != nil {
- log.Error("could not create monitor: %v", err)
+ peerMonitor, ok := c.peers[peer]
+ if !ok {
+ log.Tracef("Ignore peer event (online=%v) from non-channel "+
+ "peer: %v", online, peer)
+
return
}
Why this scored 16/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.