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:
1 parent
6edd942c70
commit
77ae7afe78
9 files changed
+256
-177
No files matched your search
+26
-5
@@ -3,6 +3,7 @@ package lnwallet
|
||||
import (
|
||||
"bytes"
|
||||
"cmp"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -138,6 +139,10 @@ var (
|
||||
// errNoPartialSig is returned when a partial signature is required,
|
||||
// but none is found.
|
||||
errNoPartialSig = errors.New("no partial signature found")
|
||||
|
||||
// errQuit is returned when a quit signal was received, interrupting the
|
||||
// current operation.
|
||||
errQuit = errors.New("received quit signal")
|
||||
)
|
||||
|
||||
// ErrCommitSyncLocalDataLoss is returned in the case that we receive a valid
|
||||
@@ -3893,7 +3898,9 @@ type NewCommitState struct {
|
||||
// for the remote party's commitment are also returned.
|
||||
//
|
||||
//nolint:funlen
|
||||
func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
|
||||
func (lc *LightningChannel) SignNextCommitment(
|
||||
ctx context.Context) (*NewCommitState, error) {
|
||||
|
||||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
|
||||
@@ -4059,7 +4066,13 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
|
||||
auxSigs := make([]fn.Option[tlv.Blob], 0, len(auxSigBatch))
|
||||
for i := range sigBatch {
|
||||
htlcSigJob := sigBatch[i]
|
||||
jobResp := <-htlcSigJob.Resp
|
||||
var jobResp SignJobResp
|
||||
|
||||
select {
|
||||
case jobResp = <-htlcSigJob.Resp:
|
||||
case <-ctx.Done():
|
||||
return nil, errQuit
|
||||
}
|
||||
|
||||
// If an error occurred, then we'll cancel any other active
|
||||
// jobs.
|
||||
@@ -4075,7 +4088,13 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
|
||||
}
|
||||
|
||||
auxHtlcSigJob := auxSigBatch[i]
|
||||
auxJobResp := <-auxHtlcSigJob.Resp
|
||||
var auxJobResp AuxSigJobResp
|
||||
|
||||
select {
|
||||
case auxJobResp = <-auxHtlcSigJob.Resp:
|
||||
case <-ctx.Done():
|
||||
return nil, errQuit
|
||||
}
|
||||
|
||||
// If an error occurred, then we'll cancel any other active
|
||||
// jobs.
|
||||
@@ -4169,7 +4188,9 @@ func (lc *LightningChannel) resignMusigCommit(
|
||||
// previous commitment txn. This allows the link to clear its mailbox of those
|
||||
// circuits in case they are still in memory, and ensure the switch's circuit
|
||||
// map has been updated by deleting the closed circuits.
|
||||
func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
//
|
||||
//nolint:funlen
|
||||
func (lc *LightningChannel) ProcessChanSyncMsg(ctx context.Context,
|
||||
msg *lnwire.ChannelReestablish) ([]lnwire.Message, []models.CircuitKey,
|
||||
[]models.CircuitKey, error) {
|
||||
|
||||
@@ -4333,7 +4354,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
// revocation, but also initiate a state transition to re-sync
|
||||
// them.
|
||||
if lc.OweCommitment() {
|
||||
newCommit, err := lc.SignNextCommitment()
|
||||
newCommit, err := lc.SignNextCommitment(ctx)
|
||||
switch {
|
||||
|
||||
// If we signed this state, then we'll accumulate
|
||||
|
||||
Reference in new issue
Block a user