Skip to content

Commit fda989d

Browse files
committed
discovery+graph: update callers to use new iterator APIs
In this commit, we update all callers of NodeUpdatesInHorizon and ChanUpdatesInHorizon to use the new iterator-based APIs. The changes use fn.Collect to maintain existing behavior while benefiting from the memory efficiency of iterators when possible.
1 parent 32528af commit fda989d

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

discovery/chan_series.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
"github.com/btcsuite/btcd/chaincfg/chainhash"
8-
"github.com/lightningnetwork/lnd/fn/v2"
98
graphdb "github.com/lightningnetwork/lnd/graph/db"
109
"github.com/lightningnetwork/lnd/lnwire"
1110
"github.com/lightningnetwork/lnd/netann"
@@ -121,12 +120,8 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
121120
if err != nil {
122121
return nil, err
123122
}
124-
chansInHorizon := fn.Collect(chansInHorizonIter)
125123

126-
// nodesFromChan records the nodes seen from the channels.
127-
nodesFromChan := make(map[[33]byte]struct{}, len(chansInHorizon)*2)
128-
129-
for _, channel := range chansInHorizon {
124+
for channel := range chansInHorizonIter {
130125
// If the channel hasn't been fully advertised yet, or is a
131126
// private channel, then we'll skip it as we can't construct a
132127
// full authentication proof if one is requested.
@@ -187,47 +182,19 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
187182

188183
// Append the all the msgs to the slice.
189184
updates = append(updates, chanUpdates...)
190-
191-
// Record the nodes seen.
192-
nodesFromChan[channel.Info.NodeKey1Bytes] = struct{}{}
193-
nodesFromChan[channel.Info.NodeKey2Bytes] = struct{}{}
194185
}
195186

196187
// Next, we'll send out all the node announcements that have an update
197188
// within the horizon as well. We send these second to ensure that they
198189
// follow any active channels they have.
199190
nodeAnnsInHorizon, err := c.graph.NodeUpdatesInHorizon(
200-
startTime, endTime,
191+
startTime, endTime, graphdb.WithIterPublicNodesOnly(),
201192
)
202193
if err != nil {
203194
return nil, err
204195
}
205196

206197
for nodeAnn := range nodeAnnsInHorizon {
207-
// If this node has not been seen in the above channels, we can
208-
// skip sending its NodeAnnouncement.
209-
if _, seen := nodesFromChan[nodeAnn.PubKeyBytes]; !seen {
210-
log.Debugf("Skipping forwarding as node %x not found "+
211-
"in channel announcement", nodeAnn.PubKeyBytes)
212-
continue
213-
}
214-
215-
// Ensure we only forward nodes that are publicly advertised to
216-
// prevent leaking information about nodes.
217-
isNodePublic, err := c.graph.IsPublicNode(nodeAnn.PubKeyBytes)
218-
if err != nil {
219-
log.Errorf("Unable to determine if node %x is "+
220-
"advertised: %v", nodeAnn.PubKeyBytes, err)
221-
continue
222-
}
223-
224-
if !isNodePublic {
225-
log.Tracef("Skipping forwarding announcement for "+
226-
"node %x due to being unadvertised",
227-
nodeAnn.PubKeyBytes)
228-
continue
229-
}
230-
231198
nodeUpdate, err := nodeAnn.NodeAnnouncement(true)
232199
if err != nil {
233200
return nil, err

0 commit comments

Comments
 (0)