mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-28 13:52:55 +02:00
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:
committed by
Oliver Gugger
parent
6edd942c70
commit
77ae7afe78
@@ -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)
|
||||
|
Reference in New Issue
Block a user