Skip to content

Commit 9151362

Browse files
committed
routing: remove a context.TODO()
1 parent 9597f01 commit 9151362

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

routing/localchans/manager.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package localchans
22

33
import (
44
"bytes"
5+
"context"
56
"errors"
67
"fmt"
78
"sync"
@@ -48,7 +49,7 @@ type Manager struct {
4849
error)
4950

5051
// AddEdge is used to add edge/channel to the topology of the router.
51-
AddEdge func(edge *models.ChannelEdgeInfo) error
52+
AddEdge func(ctx context.Context, edge *models.ChannelEdgeInfo) error
5253

5354
// policyUpdateLock ensures that the database and the link do not fall
5455
// out of sync if there are concurrent fee update calls. Without it,
@@ -60,7 +61,8 @@ type Manager struct {
6061

6162
// UpdatePolicy updates the policy for the specified channels on disk and in
6263
// the active links.
63-
func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy,
64+
func (r *Manager) UpdatePolicy(ctx context.Context,
65+
newSchema routing.ChannelPolicy,
6466
createMissingEdge bool, chanPoints ...wire.OutPoint) (
6567
[]*lnrpc.FailedUpdate, error) {
6668

@@ -192,7 +194,7 @@ func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy,
192194
channel.FundingOutpoint.String())
193195

194196
info, edge, failedUpdate := r.createMissingEdge(
195-
channel, newSchema,
197+
ctx, channel, newSchema,
196198
)
197199
if failedUpdate == nil {
198200
err = processChan(info, edge)
@@ -234,7 +236,8 @@ func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy,
234236
return failedUpdates, nil
235237
}
236238

237-
func (r *Manager) createMissingEdge(channel *channeldb.OpenChannel,
239+
func (r *Manager) createMissingEdge(ctx context.Context,
240+
channel *channeldb.OpenChannel,
238241
newSchema routing.ChannelPolicy) (*models.ChannelEdgeInfo,
239242
*models.ChannelEdgePolicy, *lnrpc.FailedUpdate) {
240243

@@ -264,7 +267,7 @@ func (r *Manager) createMissingEdge(channel *channeldb.OpenChannel,
264267

265268
// Insert the edge into the database to avoid `edge not
266269
// found` errors during policy update propagation.
267-
err = r.AddEdge(info)
270+
err = r.AddEdge(ctx, info)
268271
if err != nil {
269272
log.Errorf("Attempt to add missing edge for "+
270273
"channel (%s) errored with: %v",

routing/localchans/manager_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package localchans
22

33
import (
4+
"context"
45
"encoding/hex"
56
"testing"
67
"time"
@@ -163,7 +164,7 @@ func TestManager(t *testing.T) {
163164
}, nil
164165
}
165166

166-
addEdge := func(edge *models.ChannelEdgeInfo) error {
167+
addEdge := func(_ context.Context, _ *models.ChannelEdgeInfo) error {
167168
return nil
168169
}
169170

@@ -314,7 +315,9 @@ func TestManager(t *testing.T) {
314315
channelSet = test.channelSet
315316
expectedNumUpdates = test.expectedNumUpdates
316317

317-
failedUpdates, err := manager.UpdatePolicy(test.newPolicy,
318+
failedUpdates, err := manager.UpdatePolicy(
319+
context.Background(),
320+
test.newPolicy,
318321
test.createMissingEdge,
319322
test.specifiedChanPoints...)
320323

rpcserver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7936,8 +7936,9 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context,
79367936

79377937
// With the scope resolved, we'll now send this to the local channel
79387938
// manager so it can propagate the new policy for our target channel(s).
7939-
failedUpdates, err := r.server.localChanMgr.UpdatePolicy(chanPolicy,
7940-
req.CreateMissingEdge, targetChans...)
7939+
failedUpdates, err := r.server.localChanMgr.UpdatePolicy(
7940+
ctx, chanPolicy, req.CreateMissingEdge, targetChans...,
7941+
)
79417942
if err != nil {
79427943
return nil, err
79437944
}

server.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,10 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
12241224
PropagateChanPolicyUpdate: s.authGossiper.PropagateChanPolicyUpdate,
12251225
UpdateForwardingPolicies: s.htlcSwitch.UpdateForwardingPolicies,
12261226
FetchChannel: s.chanStateDB.FetchChannel,
1227-
AddEdge: func(edge *models.ChannelEdgeInfo) error {
1228-
return s.graphBuilder.AddEdge(context.TODO(), edge)
1227+
AddEdge: func(ctx context.Context,
1228+
edge *models.ChannelEdgeInfo) error {
1229+
1230+
return s.graphBuilder.AddEdge(ctx, edge)
12291231
},
12301232
}
12311233

0 commit comments

Comments
 (0)