Skip to content

Commit 81cc646

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 f2830fc commit 81cc646

File tree

7 files changed

+121
-90
lines changed

7 files changed

+121
-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
@@ -2030,18 +2030,17 @@ func (s *Switch) Stop() error {
20302030

20312031
// CreateAndAddLink will create a link and then add it to the internal maps
20322032
// when given a ChannelLinkConfig and LightningChannel.
2033-
func (s *Switch) CreateAndAddLink(linkCfg ChannelLinkConfig,
2034-
lnChan *lnwallet.LightningChannel) error {
2033+
func (s *Switch) CreateAndAddLink(ctx context.Context,
2034+
linkCfg ChannelLinkConfig, lnChan *lnwallet.LightningChannel) error {
20352035

20362036
link := NewChannelLink(linkCfg, lnChan)
2037-
return s.AddLink(link)
2037+
2038+
return s.AddLink(ctx, link)
20382039
}
20392040

20402041
// AddLink is used to initiate the handling of the add link command. The
20412042
// request will be propagated and handled in the main goroutine.
2042-
func (s *Switch) AddLink(link ChannelLink) error {
2043-
ctx := context.TODO()
2044-
2043+
func (s *Switch) AddLink(ctx context.Context, link ChannelLink) error {
20452044
s.indexMtx.Lock()
20462045
defer s.indexMtx.Unlock()
20472046

0 commit comments

Comments
 (0)