discovery: convert UpdatesInHorizon to return iter.Seq2[lnwire.Message, error]
In this commit, we complete the iterator conversion work started in PR 10128 by threading the iterator pattern through to the higher-level UpdatesInHorizon method. This change converts the method from returning a fully materialized slice of messages to returning a lazy iterator that yields messages on demand. The new signature uses iter.Seq2 to allow error propagation during iteration, eliminating the need for a separate error return value. This approach enables callers to handle errors as they occur during iteration rather than failing upfront. The implementation now lazily processes channel and node updates, yielding them as they're generated rather than accumulating them in memory. This maintains the same ordering guarantees (channels before nodes) while significantly reducing memory pressure when dealing with large update sets during gossip synchronization.
This commit is contained in:
3 files changed
+95
-110
No files matched your search
+3
-14
@@ -1442,23 +1442,12 @@ func (g *GossipSyncer) ApplyGossipFilter(ctx context.Context,
|
||||
|
||||
// Now that the remote peer has applied their filter, we'll query the
|
||||
// database for all the messages that are beyond this filter.
|
||||
newUpdatestoSend, err := g.cfg.channelSeries.UpdatesInHorizon(
|
||||
newUpdatestoSend := g.cfg.channelSeries.UpdatesInHorizon(
|
||||
g.cfg.chainHash, startTime, endTime,
|
||||
)
|
||||
if err != nil {
|
||||
returnSema()
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("GossipSyncer(%x): applying new remote update horizon: "+
|
||||
"start=%v, end=%v, backlog_size=%v", g.cfg.peerPub[:],
|
||||
startTime, endTime, len(newUpdatestoSend))
|
||||
|
||||
// If we don't have any to send, then we can return early.
|
||||
if len(newUpdatestoSend) == 0 {
|
||||
returnSema()
|
||||
return nil
|
||||
}
|
||||
"start=%v, end=%v", g.cfg.peerPub[:], startTime, endTime)
|
||||
|
||||
// Set the atomic flag to indicate we're starting to send the backlog.
|
||||
// If the swap fails, it means another goroutine is already active, so
|
||||
@@ -1478,7 +1467,7 @@ func (g *GossipSyncer) ApplyGossipFilter(ctx context.Context,
|
||||
defer returnSema()
|
||||
defer g.isSendingBacklog.Store(false)
|
||||
|
||||
for _, msg := range newUpdatestoSend {
|
||||
for msg := range newUpdatestoSend {
|
||||
err := g.sendToPeerSync(ctx, msg)
|
||||
switch {
|
||||
case err == ErrGossipSyncerExiting:
|
||||
|
||||
Reference in new issue
Block a user