discovery: replace chain param with ctx in UpdatesInHorizon
What changed, and why it matters
This is a small internal cleanup change in LND's gossip synchronization code. It removes an unused 'chain hash' parameter from a function and replaces it with a context parameter so database queries can be cancelled or time out properly. There is no security vulnerability here.
No security action needed. This is a routine refactoring change. Reviewers may verify that all call sites pass a sensible context and that the context is properly propagated to database queries.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors ChannelGraphTimeSeries.UpdatesInHorizon to accept context.Context instead of chainhash.Hash. The chain parameter was never used by the implementation because the channel graph is not scoped by chain. The context is passed through to graphdb.ChanUpdatesInHorizon and graphdb.NodeUpdatesInHorizon, replacing previous context.TODO() calls. This enables proper request cancellation and timeout propagation. The change is purely a code-quality and correctness improvement with no security-relevant behavior change.
Changed components
discovery/chan_series.godiscovery/syncer.godiscovery/syncer_test.goInspect captured patch +9 / −11
diff --git a/discovery/chan_series.go b/discovery/chan_series.go
index 8fa460a..72f2076 100644
--- a/discovery/chan_series.go
+++ b/discovery/chan_series.go
@@ -31,8 +31,8 @@ type ChannelGraphTimeSeries interface {
// UpdatesInHorizon returns all known channel and node updates with an
// update timestamp between the start time and end time. We'll use this
// to catch up a remote node to the set of channel updates that they
- // may have missed out on within the target chain.
- UpdatesInHorizon(chain chainhash.Hash, startTime time.Time,
+ // may have missed out on.
+ UpdatesInHorizon(ctx context.Context, startTime time.Time,
endTime time.Time) iter.Seq2[lnwire.Message, error]
// FilterKnownChanIDs takes a target chain, and a set of channel ID's,
@@ -105,18 +105,17 @@ func (c *ChanSeries) HighestChanID(ctx context.Context,
// UpdatesInHorizon returns all known channel and node updates with an update
// timestamp between the start time and end time. We'll use this to catch up a
-// remote node to the set of channel updates that they may have missed out on
-// within the target chain.
+// remote node to the set of channel updates that they may have missed out on.
//
// NOTE: This is part of the ChannelGraphTimeSeries interface.
-func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
+func (c *ChanSeries) UpdatesInHorizon(ctx context.Context,
startTime, endTime time.Time) iter.Seq2[lnwire.Message, error] {
return func(yield func(lnwire.Message, error) bool) {
// First, we'll query for all the set of channels that have an
// update that falls within the specified horizon.
chansInHorizon := c.graph.ChanUpdatesInHorizon(
- context.TODO(), graphdb.ChanUpdateRange{
+ ctx, graphdb.ChanUpdateRange{
StartTime: fn.Some(startTime),
EndTime: fn.Some(endTime),
},
@@ -185,7 +184,7 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
// update within the horizon as well. We send these second to
// ensure that they follow any active channels they have.
nodeAnnsInHorizon := c.graph.NodeUpdatesInHorizon(
- context.TODO(), graphdb.NodeUpdateRange{
+ ctx, graphdb.NodeUpdateRange{
StartTime: fn.Some(startTime),
EndTime: fn.Some(endTime),
},
diff --git a/discovery/syncer.go b/discovery/syncer.go
index 7c59cc2..834106b 100644
--- a/discovery/syncer.go
+++ b/discovery/syncer.go
@@ -1475,7 +1475,7 @@ 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 := g.cfg.channelSeries.UpdatesInHorizon(
- g.cfg.chainHash, startTime, endTime,
+ ctx, startTime, endTime,
)
// Create a pull-based iterator so we can check if there are any
diff --git a/discovery/syncer_test.go b/discovery/syncer_test.go
index cbf4c1d..368fb22 100644
--- a/discovery/syncer_test.go
+++ b/discovery/syncer_test.go
@@ -31,7 +31,6 @@ var (
)
type horizonQuery struct {
- chain chainhash.Hash
start time.Time
end time.Time
}
@@ -87,12 +86,12 @@ func (m *mockChannelGraphTimeSeries) HighestChanID(_ context.Context,
return &m.highestID, nil
}
-func (m *mockChannelGraphTimeSeries) UpdatesInHorizon(chain chainhash.Hash,
+func (m *mockChannelGraphTimeSeries) UpdatesInHorizon(_ context.Context,
startTime, endTime time.Time) iter.Seq2[lnwire.Message, error] {
return func(yield func(lnwire.Message, error) bool) {
m.horizonReq <- horizonQuery{
- chain, startTime, endTime,
+ startTime, endTime,
}
// We'll get the response from the channel, then yield it
Why this scored 15/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.