Skip to content

Commit

Permalink
htlcswitch: add awareness of new partial sig fields and musig2 nonces
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Jul 24, 2023
1 parent 56bd190 commit 4fd63b6
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions htlcswitch/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync/atomic"
"time"

"github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btclog"
Expand Down Expand Up @@ -772,6 +773,26 @@ func (l *channelLink) syncChanStates() error {
}
}

// Before we process the ChanSync message, if this is a taproot
// channel, then we'll init our musig2 nonces state.
if chanState.ChanType.IsTaproot() {
l.log.Infof("initializing musig2 nonces")

if remoteChanSyncMsg.LocalNonce == nil {
return fmt.Errorf("remote nonce is nil")
}

syncMsg := remoteChanSyncMsg
remoteNonce := &musig2.Nonces{
PubNonce: *syncMsg.LocalNonce,
}
err := l.channel.InitRemoteMusigNonces(remoteNonce)
if err != nil {
return fmt.Errorf("unable to init musig2 "+
"nonces: %w", err)
}
}

// In any case, we'll then process their ChanSync message.
l.log.Info("received re-establishment message from remote side")

Expand Down Expand Up @@ -1936,8 +1957,9 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
// chain, validate this new commitment, closing the link if
// invalid.
err = l.channel.ReceiveNewCommitment(&lnwallet.CommitSigs{
CommitSig: msg.CommitSig,
HtlcSigs: msg.HtlcSigs,
CommitSig: msg.CommitSig,
HtlcSigs: msg.HtlcSigs,
PartialSig: msg.PartialSig,
})
if err != nil {
// If we were unable to reconstruct their proposed
Expand Down Expand Up @@ -2315,9 +2337,10 @@ func (l *channelLink) updateCommitTx() error {
}

commitSig := &lnwire.CommitSig{
ChanID: l.ChanID(),
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
ChanID: l.ChanID(),
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
PartialSig: newCommit.PartialSig,
}
l.cfg.Peer.SendMessage(false, commitSig)

Expand Down

0 comments on commit 4fd63b6

Please sign in to comment.