From fc7204ca2557b7fa1c50d77f3c0de089aaa6d709 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 30 Mar 2026 08:16:34 +0200 Subject: [PATCH] graph/db: remove ChannelGraph horizon wrappers, use VersionedGraph The ChannelGraph.NodeUpdatesInHorizon and ChannelGraph.ChanUpdatesInHorizon methods were only used in tests. All production callers already use VersionedGraph (which supplies the gossip version from its embedded field). Remove the ChannelGraph wrappers and update tests to instantiate a VersionedGraph via NewVersionedGraph(MakeTestGraph(t), v1) instead, dropping the explicit version parameter from horizon calls. --- graph/db/graph.go | 18 --------------- graph/db/graph_test.go | 50 +++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 46 deletions(-) diff --git a/graph/db/graph.go b/graph/db/graph.go index 8e2ebc90a..2e2554bc0 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -721,15 +721,6 @@ func (c *ChannelGraph) ForEachNodeCacheable(ctx context.Context, return c.db.ForEachNodeCacheable(ctx, v, cb, reset) } -// NodeUpdatesInHorizon returns all known lightning nodes with updates within -// the passed range for the given gossip version. -func (c *ChannelGraph) NodeUpdatesInHorizon(ctx context.Context, - v lnwire.GossipVersion, r NodeUpdateRange, - opts ...IteratorOption) iter.Seq2[*models.Node, error] { - - return c.db.NodeUpdatesInHorizon(ctx, v, r, opts...) -} - // HasV1Node determines if the graph has a vertex identified by the target node // in the V1 graph. func (c *ChannelGraph) HasV1Node(ctx context.Context, @@ -783,15 +774,6 @@ func (c *ChannelGraph) HighestChanID(ctx context.Context, return c.db.HighestChanID(ctx, v) } -// ChanUpdatesInHorizon returns all known channel edges with at least one -// policy update within the specified range for the given gossip version. -func (c *ChannelGraph) ChanUpdatesInHorizon(ctx context.Context, - v lnwire.GossipVersion, r ChanUpdateRange, - opts ...IteratorOption) iter.Seq2[ChannelEdge, error] { - - return c.db.ChanUpdatesInHorizon(ctx, v, r, opts...) -} - // FilterChannelRange returns channel IDs within the passed block height range // for the given gossip version. func (c *ChannelGraph) FilterChannelRange(ctx context.Context, diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index 81aef9114..2d7a0c93d 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -2435,12 +2435,12 @@ func TestChanUpdatesInHorizon(t *testing.T) { t.Parallel() ctx := t.Context() - graph := MakeTestGraph(t) + graph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1) // If we issue an arbitrary query before any channel updates are // inserted in the database, we should get zero results. chanIter := graph.ChanUpdatesInHorizon( - ctx, lnwire.GossipVersion1, ChanUpdateRange{ + ctx, ChanUpdateRange{ StartTime: fn.Some(time.Unix(999, 0)), EndTime: fn.Some(time.Unix(9999, 0)), }, @@ -2550,7 +2550,7 @@ func TestChanUpdatesInHorizon(t *testing.T) { } for _, queryCase := range queryCases { respIter := graph.ChanUpdatesInHorizon( - ctx, lnwire.GossipVersion1, ChanUpdateRange{ + ctx, ChanUpdateRange{ StartTime: fn.Some(queryCase.start), EndTime: fn.Some(queryCase.end), }, @@ -2582,7 +2582,7 @@ func TestNodeUpdatesInHorizon(t *testing.T) { t.Parallel() ctx := t.Context() - graph := MakeTestGraph(t) + graph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1) startTime := time.Unix(1234, 0) endTime := startTime @@ -2590,7 +2590,7 @@ func TestNodeUpdatesInHorizon(t *testing.T) { // If we issue an arbitrary query before we insert any nodes into the // database, then we shouldn't get any results back. nodeUpdatesIter := graph.NodeUpdatesInHorizon( - ctx, lnwire.GossipVersion1, NodeUpdateRange{ + ctx, NodeUpdateRange{ StartTime: fn.Some(time.Unix(999, 0)), EndTime: fn.Some(time.Unix(9999, 0)), }, @@ -2668,7 +2668,7 @@ func TestNodeUpdatesInHorizon(t *testing.T) { } for _, queryCase := range queryCases { iter := graph.NodeUpdatesInHorizon( - ctx, lnwire.GossipVersion1, NodeUpdateRange{ + ctx, NodeUpdateRange{ StartTime: fn.Some(queryCase.start), EndTime: fn.Some(queryCase.end), }, @@ -2691,7 +2691,7 @@ func testNodeUpdatesWithBatchSize(t *testing.T, ctx context.Context, batchSize int) { // Create a fresh graph for each test. - testGraph := MakeTestGraph(t) + testGraph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1) // Add 25 nodes with increasing timestamps. startTime := time.Unix(1234567890, 0) @@ -2805,8 +2805,7 @@ func testNodeUpdatesWithBatchSize(t *testing.T, ctx context.Context, for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { iter := testGraph.NodeUpdatesInHorizon( - ctx, lnwire.GossipVersion1, - NodeUpdateRange{ + ctx, NodeUpdateRange{ StartTime: fn.Some(tc.start), EndTime: fn.Some(tc.end), }, @@ -2865,7 +2864,7 @@ func TestNodeUpdatesInHorizonEarlyTermination(t *testing.T) { t.Parallel() ctx := t.Context() - graph := MakeTestGraph(t) + graph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1) // We'll start by creating 100 nodes, each with an update time spaced // one hour apart. @@ -2882,8 +2881,7 @@ func TestNodeUpdatesInHorizonEarlyTermination(t *testing.T) { for _, stopAt := range terminationPoints { t.Run(fmt.Sprintf("StopAt%d", stopAt), func(t *testing.T) { iter := graph.NodeUpdatesInHorizon( - ctx, lnwire.GossipVersion1, - NodeUpdateRange{ + ctx, NodeUpdateRange{ StartTime: fn.Some(startTime), EndTime: fn.Some( startTime.Add(200 * time.Hour), @@ -2925,7 +2923,9 @@ func TestChanUpdatesInHorizonBoundaryConditions(t *testing.T) { t.Run(testName, func(t *testing.T) { // Create a fresh graph for each test, then add two new // nodes to the graph. - graph := MakeTestGraph(t) + graph := NewVersionedGraph( + MakeTestGraph(t), lnwire.GossipVersion1, + ) node1 := createTestVertex(t, lnwire.GossipVersion1) node2 := createTestVertex(t, lnwire.GossipVersion1) require.NoError(t, graph.AddNode(ctx, node1)) @@ -2977,8 +2977,7 @@ func TestChanUpdatesInHorizonBoundaryConditions(t *testing.T) { // Now we'll run the main query, and verify that we get // back the expected number of channels. iter := graph.ChanUpdatesInHorizon( - ctx, lnwire.GossipVersion1, - ChanUpdateRange{ + ctx, ChanUpdateRange{ StartTime: fn.Some(startTime), EndTime: fn.Some( startTime.Add(26 * time.Hour), @@ -3005,7 +3004,7 @@ func TestNodeUpdatesInHorizonExclusiveEnd(t *testing.T) { t.Parallel() ctx := t.Context() - graph := MakeTestGraph(t) + graph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1) // Create three nodes at timestamps 100, 200, and 300. timestamps := []int64{100, 200, 300} @@ -3065,8 +3064,7 @@ func TestNodeUpdatesInHorizonExclusiveEnd(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { iter := graph.NodeUpdatesInHorizon( - ctx, lnwire.GossipVersion1, - NodeUpdateRange{ + ctx, NodeUpdateRange{ StartTime: fn.Some(tc.start), EndTime: fn.Some(tc.end), }, @@ -3086,7 +3084,7 @@ func TestChanUpdatesInHorizonExclusiveEnd(t *testing.T) { t.Parallel() ctx := t.Context() - graph := MakeTestGraph(t) + graph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1) node1 := createTestVertex(t, lnwire.GossipVersion1) node2 := createTestVertex(t, lnwire.GossipVersion1) @@ -3163,8 +3161,7 @@ func TestChanUpdatesInHorizonExclusiveEnd(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { iter := graph.ChanUpdatesInHorizon( - ctx, lnwire.GossipVersion1, - ChanUpdateRange{ + ctx, ChanUpdateRange{ StartTime: fn.Some(tc.start), EndTime: fn.Some(tc.end), }, @@ -3441,7 +3438,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) { ctx := t.Context() - graph := MakeTestGraph(t) + graph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1) node1 := createTestVertex(t, lnwire.GossipVersion1) require.NoError(t, graph.AddNode(ctx, node1)) @@ -3609,8 +3606,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) { } _, _, err := graph.HasChannelEdge( - ctx, lnwire.GossipVersion1, - channel.id.ToUint64(), + ctx, channel.id.ToUint64(), ) return err @@ -3641,8 +3637,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) { fn: func() error { now := time.Now() iter := graph.ChanUpdatesInHorizon( - ctx, lnwire.GossipVersion1, - ChanUpdateRange{ + ctx, ChanUpdateRange{ StartTime: fn.Some( now.Add(-time.Hour), ), @@ -3672,8 +3667,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) { } err := graph.DeleteChannelEdges( - ctx, lnwire.GossipVersion1, - strictPruning, markZombie, + ctx, strictPruning, markZombie, chanIDs..., ) if err != nil &&