Skip to content

Commit ce442a5

Browse files
committed
Merge branch '0-18-3-branch-9046' into 0-18-3-branch
2 parents 3bb4d6d + 2341019 commit ce442a5

File tree

3 files changed

+231
-93
lines changed

3 files changed

+231
-93
lines changed

lnwallet/channel.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3905,6 +3905,27 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
39053905
}, nil
39063906
}
39073907

3908+
// resignMusigCommit is used to resign a commitment transaction for taproot
3909+
// channels when we need to retransmit a signature after a channel reestablish
3910+
// message. Taproot channels use musig2, which means we must use fresh nonces
3911+
// each time. After we receive the channel reestablish message, we learn the
3912+
// nonce we need to use for the remote party. As a result, we need to generate
3913+
// the partial signature again with the new nonce.
3914+
func (lc *LightningChannel) resignMusigCommit(commitTx *wire.MsgTx,
3915+
) (lnwire.OptPartialSigWithNonceTLV, error) {
3916+
3917+
remoteSession := lc.musigSessions.RemoteSession
3918+
musig, err := remoteSession.SignCommit(commitTx)
3919+
if err != nil {
3920+
var none lnwire.OptPartialSigWithNonceTLV
3921+
return none, err
3922+
}
3923+
3924+
partialSig := lnwire.MaybePartialSigWithNonce(musig.ToWireSig())
3925+
3926+
return partialSig, nil
3927+
}
3928+
39083929
// ProcessChanSyncMsg processes a ChannelReestablish message sent by the remote
39093930
// connection upon re establishment of our connection with them. This method
39103931
// will return a single message if we are currently out of sync, otherwise a
@@ -4182,12 +4203,23 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
41824203
commitUpdates = append(commitUpdates, logUpdate.UpdateMsg)
41834204
}
41844205

4206+
// If this is a taproot channel, then we need to regenerate the
4207+
// musig2 signature for the remote party, using their fresh
4208+
// nonce.
4209+
if lc.channelState.ChanType.IsTaproot() {
4210+
partialSig, err := lc.resignMusigCommit(
4211+
commitDiff.Commitment.CommitTx,
4212+
)
4213+
if err != nil {
4214+
return nil, nil, nil, err
4215+
}
4216+
4217+
commitDiff.CommitSig.PartialSig = partialSig
4218+
}
4219+
41854220
// With the batch of updates accumulated, we'll now re-send the
41864221
// original CommitSig message required to re-sync their remote
41874222
// commitment chain with our local version of their chain.
4188-
//
4189-
// TODO(roasbeef): need to re-sign commitment states w/
4190-
// fresh nonce
41914223
commitUpdates = append(commitUpdates, commitDiff.CommitSig)
41924224

41934225
// NOTE: If a revocation is not owed, then updates is empty.

0 commit comments

Comments
 (0)