multi: link quit can interrupt commitment signing

In this commit, we make sig job handling when singing a next commitment
non-blocking by allowing the shutdown of a channel link to prevent
further waiting on sig jobs by the channel state machine. This addresses
possible cases where the aux signer may be shut down via a separate quit
signal, so the state machine could block indefinitely on receiving an
update on a sig job.
This commit is contained in:
Jonathan Harvey-Buschel
2024-10-17 13:38:34 +02:00
committed by Oliver Gugger
parent 6edd942c70
commit 77ae7afe78
9 changed files with 256 additions and 177 deletions

View File

@@ -2252,12 +2252,14 @@ func newSingleLinkTestHarness(t *testing.T, chanAmt,
return aliceSwitch.AddLink(aliceLink)
}
go func() {
for {
select {
case <-notifyUpdateChan:
case <-aliceLink.(*channelLink).quit:
close(doneChan)
return
if chanLink, ok := aliceLink.(*channelLink); ok {
for {
select {
case <-notifyUpdateChan:
case <-chanLink.Quit:
close(doneChan)
return
}
}
}
}()
@@ -2324,7 +2326,10 @@ func handleStateUpdate(link *channelLink,
}
link.HandleChannelUpdate(remoteRev)
remoteSigs, err := remoteChannel.SignNextCommitment()
ctx, done := link.WithCtxQuitNoTimeout()
defer done()
remoteSigs, err := remoteChannel.SignNextCommitment(ctx)
if err != nil {
return err
}
@@ -2367,7 +2372,7 @@ func updateState(batchTick chan time.Time, link *channelLink,
// Trigger update by ticking the batchTicker.
select {
case batchTick <- time.Now():
case <-link.quit:
case <-link.Quit:
return fmt.Errorf("link shutting down")
}
return handleStateUpdate(link, remoteChannel)
@@ -2375,7 +2380,10 @@ func updateState(batchTick chan time.Time, link *channelLink,
// The remote is triggering the state update, emulate this by
// signing and sending CommitSig to the link.
remoteSigs, err := remoteChannel.SignNextCommitment()
ctx, done := link.WithCtxQuitNoTimeout()
defer done()
remoteSigs, err := remoteChannel.SignNextCommitment(ctx)
if err != nil {
return err
}
@@ -4931,12 +4939,14 @@ func (h *persistentLinkHarness) restartLink(
return nil, nil, err
}
go func() {
for {
select {
case <-notifyUpdateChan:
case <-aliceLink.(*channelLink).quit:
close(doneChan)
return
if chanLink, ok := aliceLink.(*channelLink); ok {
for {
select {
case <-notifyUpdateChan:
case <-chanLink.Quit:
close(doneChan)
return
}
}
}
}()
@@ -5919,7 +5929,12 @@ func TestChannelLinkFail(t *testing.T) {
// Sign a commitment that will include
// signature for the HTLC just sent.
sigs, err := remoteChannel.SignNextCommitment()
quitCtx, done := c.WithCtxQuitNoTimeout()
defer done()
sigs, err := remoteChannel.SignNextCommitment(
quitCtx,
)
if err != nil {
t.Fatalf("error signing commitment: %v",
err)
@@ -5961,7 +5976,12 @@ func TestChannelLinkFail(t *testing.T) {
// Sign a commitment that will include
// signature for the HTLC just sent.
sigs, err := remoteChannel.SignNextCommitment()
quitCtx, done := c.WithCtxQuitNoTimeout()
defer done()
sigs, err := remoteChannel.SignNextCommitment(
quitCtx,
)
if err != nil {
t.Fatalf("error signing commitment: %v",
err)