Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lnwallet: aux signer batching fixes #9074

Open
wants to merge 5 commits into
base: 0-19-staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contractcourt/chain_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {

// With the HTLC added, we'll now manually initiate a state transition
// from Alice to Bob.
_, err = aliceChannel.SignNextCommitment()
_, err = aliceChannel.SignNextCommitment(nil)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the previous unit test in place, should we also add a test case where the aux signer doesn't send any responses at all but we can still shut down when sending on this new quit channel?

if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions htlcswitch/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ func (l *channelLink) syncChanStates() error {
// party, so we'll process the message in order to determine
// if we need to re-transmit any messages to the remote party.
msgsToReSend, openedCircuits, closedCircuits, err =
l.channel.ProcessChanSyncMsg(remoteChanSyncMsg)
l.channel.ProcessChanSyncMsg(l.quit, remoteChanSyncMsg)
if err != nil {
return err
}
Expand Down Expand Up @@ -2541,7 +2541,7 @@ func (l *channelLink) updateCommitTx() error {
return nil
}

newCommit, err := l.channel.SignNextCommitment()
newCommit, err := l.channel.SignNextCommitment(l.quit)
if err == lnwallet.ErrNoWindow {
l.cfg.PendingCommitTicker.Resume()
l.log.Trace("PendingCommitTicker resumed")
Expand Down
2 changes: 1 addition & 1 deletion htlcswitch/link_isolated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (l *linkTestContext) receiveHtlcAliceToBob() {
func (l *linkTestContext) sendCommitSigBobToAlice(expHtlcs int) {
l.t.Helper()

sigs, err := l.bobChannel.SignNextCommitment()
sigs, err := l.bobChannel.SignNextCommitment(nil)
if err != nil {
l.t.Fatalf("error signing commitment: %v", err)
}
Expand Down
12 changes: 8 additions & 4 deletions htlcswitch/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@ func handleStateUpdate(link *channelLink,
}
link.HandleChannelUpdate(remoteRev)

remoteSigs, err := remoteChannel.SignNextCommitment()
remoteSigs, err := remoteChannel.SignNextCommitment(link.quit)
if err != nil {
return err
}
Expand Down Expand Up @@ -2363,7 +2363,7 @@ 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()
remoteSigs, err := remoteChannel.SignNextCommitment(link.quit)
if err != nil {
return err
}
Expand Down Expand Up @@ -5892,7 +5892,9 @@ func TestChannelLinkFail(t *testing.T) {

// Sign a commitment that will include
// signature for the HTLC just sent.
sigs, err := remoteChannel.SignNextCommitment()
sigs, err := remoteChannel.SignNextCommitment(
c.quit,
)
if err != nil {
t.Fatalf("error signing commitment: %v",
err)
Expand Down Expand Up @@ -5934,7 +5936,9 @@ func TestChannelLinkFail(t *testing.T) {

// Sign a commitment that will include
// signature for the HTLC just sent.
sigs, err := remoteChannel.SignNextCommitment()
sigs, err := remoteChannel.SignNextCommitment(
c.quit,
)
if err != nil {
t.Fatalf("error signing commitment: %v",
err)
Expand Down
28 changes: 23 additions & 5 deletions lnwallet/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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
Expand Down Expand Up @@ -4526,7 +4530,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(
quit <-chan struct{}) (*NewCommitState, error) {

lc.Lock()
defer lc.Unlock()

Expand Down Expand Up @@ -4693,7 +4699,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 <-quit:
return nil, errQuit
case jobResp = <-htlcSigJob.Resp:
}

// If an error occurred, then we'll cancel any other active
// jobs.
Expand All @@ -4709,7 +4721,13 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
}

auxHtlcSigJob := auxSigBatch[i]
auxJobResp := <-auxHtlcSigJob.Resp
var auxJobResp AuxSigJobResp

select {
case <-quit:
return nil, errQuit
case auxJobResp = <-auxHtlcSigJob.Resp:
}

// If an error occurred, then we'll cancel any other active
// jobs.
Expand Down Expand Up @@ -4802,7 +4820,7 @@ func (lc *LightningChannel) resignMusigCommit(commitTx *wire.MsgTx,
// 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(
func (lc *LightningChannel) ProcessChanSyncMsg(quit <-chan struct{},
msg *lnwire.ChannelReestablish) ([]lnwire.Message, []models.CircuitKey,
[]models.CircuitKey, error) {

Expand Down Expand Up @@ -4966,7 +4984,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(quit)
switch {

// If we signed this state, then we'll accumulate
Expand Down
Loading
Loading