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:
Olaoluwa Osuntokun committed 2025-09-26 16:59:41 -07:00
1 parent fda989da9c
commit d8f6fd29f7
3 files changed
+95 -110

No files matched your search

+13 -5
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"iter"
"math"
"reflect"
"sort"
@@ -86,13 +87,20 @@ func (m *mockChannelGraphTimeSeries) HighestChanID(_ context.Context,
}
func (m *mockChannelGraphTimeSeries) UpdatesInHorizon(chain chainhash.Hash,
startTime time.Time, endTime time.Time) ([]lnwire.Message, error) {
startTime, endTime time.Time) iter.Seq2[lnwire.Message, error] {
m.horizonReq <- horizonQuery{
chain, startTime, endTime,
return func(yield func(lnwire.Message, error) bool) {
m.horizonReq <- horizonQuery{
chain, startTime, endTime,
}
msgs := <-m.horizonResp
for _, msg := range msgs {
if !yield(msg, nil) {
return
}
}
}
return <-m.horizonResp, nil
}
func (m *mockChannelGraphTimeSeries) FilterKnownChanIDs(chain chainhash.Hash,