Skip to content

Commit 00150d6

Browse files
committed
htlcswitch: add context to AddLink
And hence remove the context.TODO that was previously left there. Leave a TODO in the peer package for a later PR.
1 parent 1d0c8de commit 00150d6

File tree

7 files changed

+119
-90
lines changed

7 files changed

+119
-90
lines changed

htlcswitch/link_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,7 @@ func newSingleLinkTestHarness(t *testing.T, chanAmt,
22532253

22542254
aliceLink := NewChannelLink(aliceCfg, aliceLc.channel)
22552255
start := func() error {
2256-
return aliceSwitch.AddLink(aliceLink)
2256+
return aliceSwitch.AddLink(context.Background(), aliceLink)
22572257
}
22582258
go func() {
22592259
if chanLink, ok := aliceLink.(*channelLink); ok {
@@ -4944,9 +4944,11 @@ func (h *persistentLinkHarness) restartLink(
49444944
}
49454945

49464946
aliceLink := NewChannelLink(aliceCfg, aliceChannel)
4947-
if err := h.hSwitch.AddLink(aliceLink); err != nil {
4947+
err := h.hSwitch.AddLink(context.Background(), aliceLink)
4948+
if err != nil {
49484949
return nil, nil, err
49494950
}
4951+
49504952
go func() {
49514953
if chanLink, ok := aliceLink.(*channelLink); ok {
49524954
for {

htlcswitch/switch.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -2028,18 +2028,17 @@ func (s *Switch) Stop() error {
20282028

20292029
// CreateAndAddLink will create a link and then add it to the internal maps
20302030
// when given a ChannelLinkConfig and LightningChannel.
2031-
func (s *Switch) CreateAndAddLink(linkCfg ChannelLinkConfig,
2032-
lnChan *lnwallet.LightningChannel) error {
2031+
func (s *Switch) CreateAndAddLink(ctx context.Context,
2032+
linkCfg ChannelLinkConfig, lnChan *lnwallet.LightningChannel) error {
20332033

20342034
link := NewChannelLink(linkCfg, lnChan)
2035-
return s.AddLink(link)
2035+
2036+
return s.AddLink(ctx, link)
20362037
}
20372038

20382039
// AddLink is used to initiate the handling of the add link command. The
20392040
// request will be propagated and handled in the main goroutine.
2040-
func (s *Switch) AddLink(link ChannelLink) error {
2041-
ctx := context.TODO()
2042-
2041+
func (s *Switch) AddLink(ctx context.Context, link ChannelLink) error {
20432042
s.indexMtx.Lock()
20442043
defer s.indexMtx.Unlock()
20452044

0 commit comments

Comments
 (0)