discovery+graph: update callers to use new iterator APIs
What changed, and why it matters
This is a small internal code cleanup in the Lightning Network Daemon (LND). It switches two functions to use newer memory-efficient iterator APIs and removes some redundant filtering logic. There is no indication this fixes a security bug or introduces a vulnerability; it appears to be a refactoring change.
No security action required. Treat as routine refactoring. If desired, verify that `graphdb.WithIterPublicNodesOnly()` preserves the previous public-node filtering semantics.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit updates UpdatesInHorizon in discovery/chan_series.go to consume ChanUpdatesInHorizon and NodeUpdatesInHorizon as iterators instead of collecting them into slices. It removes the fn.Collect helper usage, deletes the nodesFromChan map, and drops manual checks that skipped node announcements for nodes not present in channels and unadvertised nodes. The node filtering is now delegated to graphdb.WithIterPublicNodesOnly() passed to NodeUpdatesInHorizon. The diff is a pure refactor with no obvious security-relevant behavior change.
Changed components
discovery/chan_series.goInspect captured patch +2 / −35
diff --git a/discovery/chan_series.go b/discovery/chan_series.go
index 6c75635..081133d 100644
--- a/discovery/chan_series.go
+++ b/discovery/chan_series.go
@@ -5,7 +5,6 @@ import (
"time"
"github.com/btcsuite/btcd/chaincfg/chainhash"
- "github.com/lightningnetwork/lnd/fn/v2"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/netann"
@@ -121,12 +120,8 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
if err != nil {
return nil, err
}
- chansInHorizon := fn.Collect(chansInHorizonIter)
- // nodesFromChan records the nodes seen from the channels.
- nodesFromChan := make(map[[33]byte]struct{}, len(chansInHorizon)*2)
-
- for _, channel := range chansInHorizon {
+ for channel := range chansInHorizonIter {
// If the channel hasn't been fully advertised yet, or is a
// private channel, then we'll skip it as we can't construct a
// full authentication proof if one is requested.
@@ -187,47 +182,19 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
// Append the all the msgs to the slice.
updates = append(updates, chanUpdates...)
-
- // Record the nodes seen.
- nodesFromChan[channel.Info.NodeKey1Bytes] = struct{}{}
- nodesFromChan[channel.Info.NodeKey2Bytes] = struct{}{}
}
// Next, we'll send out all the node announcements that have an update
// within the horizon as well. We send these second to ensure that they
// follow any active channels they have.
nodeAnnsInHorizon, err := c.graph.NodeUpdatesInHorizon(
- startTime, endTime,
+ startTime, endTime, graphdb.WithIterPublicNodesOnly(),
)
if err != nil {
return nil, err
}
for nodeAnn := range nodeAnnsInHorizon {
- // If this node has not been seen in the above channels, we can
- // skip sending its NodeAnnouncement.
- if _, seen := nodesFromChan[nodeAnn.PubKeyBytes]; !seen {
- log.Debugf("Skipping forwarding as node %x not found "+
- "in channel announcement", nodeAnn.PubKeyBytes)
- continue
- }
-
- // Ensure we only forward nodes that are publicly advertised to
- // prevent leaking information about nodes.
- isNodePublic, err := c.graph.IsPublicNode(nodeAnn.PubKeyBytes)
- if err != nil {
- log.Errorf("Unable to determine if node %x is "+
- "advertised: %v", nodeAnn.PubKeyBytes, err)
- continue
- }
-
- if !isNodePublic {
- log.Tracef("Skipping forwarding announcement for "+
- "node %x due to being unadvertised",
- nodeAnn.PubKeyBytes)
- continue
- }
-
nodeUpdate, err := nodeAnn.NodeAnnouncement(true)
if err != nil {
return nil, err
Why this scored 11/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.