From 91513623b559ab6bb116104816f6e25f6a6861d2 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 18 Jun 2025 14:28:10 +0200 Subject: [PATCH] routing: remove a context.TODO() --- routing/localchans/manager.go | 13 ++++++++----- routing/localchans/manager_test.go | 7 +++++-- rpcserver.go | 5 +++-- server.go | 6 ++++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/routing/localchans/manager.go b/routing/localchans/manager.go index 492f8f18c..a75758e88 100644 --- a/routing/localchans/manager.go +++ b/routing/localchans/manager.go @@ -2,6 +2,7 @@ package localchans import ( "bytes" + "context" "errors" "fmt" "sync" @@ -48,7 +49,7 @@ type Manager struct { error) // AddEdge is used to add edge/channel to the topology of the router. - AddEdge func(edge *models.ChannelEdgeInfo) error + AddEdge func(ctx context.Context, edge *models.ChannelEdgeInfo) error // policyUpdateLock ensures that the database and the link do not fall // out of sync if there are concurrent fee update calls. Without it, @@ -60,7 +61,8 @@ type Manager struct { // UpdatePolicy updates the policy for the specified channels on disk and in // the active links. -func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy, +func (r *Manager) UpdatePolicy(ctx context.Context, + newSchema routing.ChannelPolicy, createMissingEdge bool, chanPoints ...wire.OutPoint) ( []*lnrpc.FailedUpdate, error) { @@ -192,7 +194,7 @@ func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy, channel.FundingOutpoint.String()) info, edge, failedUpdate := r.createMissingEdge( - channel, newSchema, + ctx, channel, newSchema, ) if failedUpdate == nil { err = processChan(info, edge) @@ -234,7 +236,8 @@ func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy, return failedUpdates, nil } -func (r *Manager) createMissingEdge(channel *channeldb.OpenChannel, +func (r *Manager) createMissingEdge(ctx context.Context, + channel *channeldb.OpenChannel, newSchema routing.ChannelPolicy) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *lnrpc.FailedUpdate) { @@ -264,7 +267,7 @@ func (r *Manager) createMissingEdge(channel *channeldb.OpenChannel, // Insert the edge into the database to avoid `edge not // found` errors during policy update propagation. - err = r.AddEdge(info) + err = r.AddEdge(ctx, info) if err != nil { log.Errorf("Attempt to add missing edge for "+ "channel (%s) errored with: %v", diff --git a/routing/localchans/manager_test.go b/routing/localchans/manager_test.go index d428a846b..40da6fd04 100644 --- a/routing/localchans/manager_test.go +++ b/routing/localchans/manager_test.go @@ -1,6 +1,7 @@ package localchans import ( + "context" "encoding/hex" "testing" "time" @@ -163,7 +164,7 @@ func TestManager(t *testing.T) { }, nil } - addEdge := func(edge *models.ChannelEdgeInfo) error { + addEdge := func(_ context.Context, _ *models.ChannelEdgeInfo) error { return nil } @@ -314,7 +315,9 @@ func TestManager(t *testing.T) { channelSet = test.channelSet expectedNumUpdates = test.expectedNumUpdates - failedUpdates, err := manager.UpdatePolicy(test.newPolicy, + failedUpdates, err := manager.UpdatePolicy( + context.Background(), + test.newPolicy, test.createMissingEdge, test.specifiedChanPoints...) diff --git a/rpcserver.go b/rpcserver.go index 48b5b3bc4..7140731a6 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -7936,8 +7936,9 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context, // With the scope resolved, we'll now send this to the local channel // manager so it can propagate the new policy for our target channel(s). - failedUpdates, err := r.server.localChanMgr.UpdatePolicy(chanPolicy, - req.CreateMissingEdge, targetChans...) + failedUpdates, err := r.server.localChanMgr.UpdatePolicy( + ctx, chanPolicy, req.CreateMissingEdge, targetChans..., + ) if err != nil { return nil, err } diff --git a/server.go b/server.go index ce728caf5..677e978ae 100644 --- a/server.go +++ b/server.go @@ -1224,8 +1224,10 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr, PropagateChanPolicyUpdate: s.authGossiper.PropagateChanPolicyUpdate, UpdateForwardingPolicies: s.htlcSwitch.UpdateForwardingPolicies, FetchChannel: s.chanStateDB.FetchChannel, - AddEdge: func(edge *models.ChannelEdgeInfo) error { - return s.graphBuilder.AddEdge(context.TODO(), edge) + AddEdge: func(ctx context.Context, + edge *models.ChannelEdgeInfo) error { + + return s.graphBuilder.AddEdge(ctx, edge) }, }