@@ -264,16 +264,15 @@ object LocalCommit {
264264case class RemoteCommit (index : Long , spec : CommitmentSpec , txid : TxId , remotePerCommitmentPoint : PublicKey ) {
265265 def sign (keyManager : ChannelKeyManager , params : ChannelParams , fundingTxIndex : Long , remoteFundingPubKey : PublicKey , commitInput : InputInfo , remoteNonce_opt : Option [IndividualNonce ])(implicit log : LoggingAdapter ): CommitSig = {
266266 val (remoteCommitTx, htlcTxs) = Commitment .makeRemoteTxs(keyManager, params.channelConfig, params.channelFeatures, index, params.localParams, params.remoteParams, fundingTxIndex, remoteFundingPubKey, commitInput, remotePerCommitmentPoint, spec)
267- val (sig, tlvStream) = params.commitmentFormat match {
268- case SimpleTaprootChannelsStagingCommitmentFormat =>
269- val localNonce = keyManager.verificationNonce(params.localParams.fundingKeyPath, fundingTxIndex, keyManager.keyPath(params.localParams, params.channelConfig), index)
270- val Some (remoteNonce) = remoteNonce_opt
271- val Right (localPartialSigOfRemoteTx) = keyManager.partialSign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), remoteFundingPubKey, TxOwner .Remote , localNonce, remoteNonce)
272- val tlvStream : TlvStream [CommitSigTlv ] = TlvStream (CommitSigTlv .PartialSignatureWithNonceTlv (PartialSignatureWithNonce (localPartialSigOfRemoteTx, localNonce._2)))
273- (ByteVector64 .Zeroes , tlvStream)
274- case _ =>
275- val sig = keyManager.sign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner .Remote , params.commitmentFormat)
276- (sig, TlvStream [CommitSigTlv ]())
267+ val (sig, tlvStream) = if (params.commitmentFormat.useTaproot) {
268+ val localNonce = keyManager.verificationNonce(params.localParams.fundingKeyPath, fundingTxIndex, keyManager.keyPath(params.localParams, params.channelConfig), index)
269+ val Some (remoteNonce) = remoteNonce_opt
270+ val Right (localPartialSigOfRemoteTx) = keyManager.partialSign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), remoteFundingPubKey, TxOwner .Remote , localNonce, remoteNonce)
271+ val tlvStream : TlvStream [CommitSigTlv ] = TlvStream (CommitSigTlv .PartialSignatureWithNonceTlv (PartialSignatureWithNonce (localPartialSigOfRemoteTx, localNonce._2)))
272+ (ByteVector64 .Zeroes , tlvStream)
273+ } else {
274+ val sig = keyManager.sign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner .Remote , params.commitmentFormat)
275+ (sig, TlvStream [CommitSigTlv ]())
277276 }
278277 val channelKeyPath = keyManager.keyPath(params.localParams, params.channelConfig)
279278 val sortedHtlcTxs = htlcTxs.sortBy(_.input.outPoint.index)
@@ -651,22 +650,19 @@ case class Commitment(fundingTxIndex: Long,
651650 // remote commitment will include all local proposed changes + remote acked changes
652651 val spec = CommitmentSpec .reduce(remoteCommit.spec, changes.remoteChanges.acked, changes.localChanges.proposed)
653652 val (remoteCommitTx, htlcTxs) = Commitment .makeRemoteTxs(keyManager, params.channelConfig, params.channelFeatures, remoteCommit.index + 1 , params.localParams, params.remoteParams, fundingTxIndex, remoteFundingPubKey, commitInput, remoteNextPerCommitmentPoint, spec)
654- val sig = params.commitmentFormat match {
655- case SimpleTaprootChannelsStagingCommitmentFormat =>
656- ByteVector64 .Zeroes
657- case _ =>
658- keyManager.sign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner .Remote , params.commitmentFormat)
653+ val sig = if (params.commitmentFormat.useTaproot) {
654+ ByteVector64 .Zeroes
655+ } else {
656+ keyManager.sign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner .Remote , params.commitmentFormat)
659657 }
660- val partialSig : Set [CommitSigTlv ] = params.commitmentFormat match {
661- case SimpleTaprootChannelsStagingCommitmentFormat =>
662- // we generate a new nonce each time we sign their commit tx
663- val localNonce = keyManager.signingNonce(params.localParams.fundingKeyPath, fundingTxIndex)
664- val Some (remoteNonce) = nextRemoteNonce_opt
665- val Right (psig) = keyManager.partialSign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), remoteFundingPubKey, TxOwner .Remote , localNonce, remoteNonce)
666- log.debug(s " sendCommit: creating partial sig $psig for remote commit tx ${remoteCommitTx.tx.txid} with remote nonce $remoteNonce and remoteNextPerCommitmentPoint = $remoteNextPerCommitmentPoint" )
667- Set (CommitSigTlv .PartialSignatureWithNonceTlv (PartialSignatureWithNonce (psig, localNonce._2)))
668- case _ =>
669- Set .empty
658+ val partialSig : Set [CommitSigTlv ] = if (params.commitmentFormat.useTaproot) {
659+ val localNonce = keyManager.signingNonce(params.localParams.fundingKeyPath, fundingTxIndex)
660+ val Some (remoteNonce) = nextRemoteNonce_opt
661+ val Right (psig) = keyManager.partialSign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), remoteFundingPubKey, TxOwner .Remote , localNonce, remoteNonce)
662+ log.debug(s " sendCommit: creating partial sig $psig for remote commit tx ${remoteCommitTx.tx.txid} with remote nonce $remoteNonce and remoteNextPerCommitmentPoint = $remoteNextPerCommitmentPoint" )
663+ Set (CommitSigTlv .PartialSignatureWithNonceTlv (PartialSignatureWithNonce (psig, localNonce._2)))
664+ } else {
665+ Set .empty
670666 }
671667 val sortedHtlcTxs : Seq [TransactionWithInputInfo ] = htlcTxs.sortBy(_.input.outPoint.index)
672668 val channelKeyPath = keyManager.keyPath(params.localParams, params.channelConfig)
@@ -1054,12 +1050,11 @@ case class Commitments(params: ChannelParams,
10541050 remoteNextCommitInfo match {
10551051 case Right (_) if ! changes.localHasChanges => Left (CannotSignWithoutChanges (channelId))
10561052 case Right (remoteNextPerCommitmentPoint) =>
1057- val (active1, sigs) = this .params.commitmentFormat match {
1058- case SimpleTaprootChannelsStagingCommitmentFormat =>
1059- require(active.size <= nextRemoteNonces.size, s " we have ${active.size} commitments but ${nextRemoteNonces.size} remote musig2 nonces " )
1060- active.zip(nextRemoteNonces).map { case (c, n) => c.sendCommit(keyManager, params, changes, remoteNextPerCommitmentPoint, active.size, Some (n)) } unzip
1061- case _ =>
1062- active.map(_.sendCommit(keyManager, params, changes, remoteNextPerCommitmentPoint, active.size, None )).unzip
1053+ val (active1, sigs) = if (this .params.commitmentFormat.useTaproot) {
1054+ require(active.size <= nextRemoteNonces.size, s " we have ${active.size} commitments but ${nextRemoteNonces.size} remote musig2 nonces " )
1055+ active.zip(nextRemoteNonces).map { case (c, n) => c.sendCommit(keyManager, params, changes, remoteNextPerCommitmentPoint, active.size, Some (n)) } unzip
1056+ } else {
1057+ active.map(_.sendCommit(keyManager, params, changes, remoteNextPerCommitmentPoint, active.size, None )).unzip
10631058 }
10641059 val commitments1 = copy(
10651060 changes = changes.copy(
@@ -1085,9 +1080,10 @@ case class Commitments(params: ChannelParams,
10851080 val localPerCommitmentPoint = keyManager.commitmentPoint(channelKeyPath, localCommitIndex + 1 )
10861081 // Signatures are sent in order (most recent first), calling `zip` will drop trailing sigs that are for deactivated/pruned commitments.
10871082 val active1 = active.zip(commits).map { case (commitment, commit) =>
1088- val localNonce_opt = params.commitmentFormat match {
1089- case SimpleTaprootChannelsStagingCommitmentFormat => Some (keyManager.verificationNonce(params.localParams.fundingKeyPath, commitment.fundingTxIndex, channelKeyPath, localCommitIndex + 1 ))
1090- case _ => None
1083+ val localNonce_opt = if (params.commitmentFormat.useTaproot) {
1084+ Some (keyManager.verificationNonce(params.localParams.fundingKeyPath, commitment.fundingTxIndex, channelKeyPath, localCommitIndex + 1 ))
1085+ } else {
1086+ None
10911087 }
10921088 commitment.receiveCommit(keyManager, params, changes, localPerCommitmentPoint, commit, localNonce_opt) match {
10931089 case Left (f) => return Left (f)
@@ -1097,16 +1093,15 @@ case class Commitments(params: ChannelParams,
10971093 // we will send our revocation preimage + our next revocation hash
10981094 val localPerCommitmentSecret = keyManager.commitmentSecret(channelKeyPath, localCommitIndex)
10991095 val localNextPerCommitmentPoint = keyManager.commitmentPoint(channelKeyPath, localCommitIndex + 2 )
1100- val tlvStream : TlvStream [RevokeAndAckTlv ] = params.commitmentFormat match {
1101- case SimpleTaprootChannelsStagingCommitmentFormat =>
1102- val nonces = this .active.map(c => {
1103- val n = keyManager.verificationNonce(params.localParams.fundingKeyPath, c.fundingTxIndex, channelKeyPath, localCommitIndex + 2 )
1104- log.debug(s " revokeandack: creating verification nonce ${n._2} fundingIndex = ${c.fundingTxIndex} commit index = ${localCommitIndex + 2 }" )
1105- n
1106- })
1107- TlvStream (RevokeAndAckTlv .NextLocalNoncesTlv (nonces.map(_._2).toList))
1108- case _ =>
1109- TlvStream .empty
1096+ val tlvStream : TlvStream [RevokeAndAckTlv ] = if (params.commitmentFormat.useTaproot) {
1097+ val nonces = this .active.map(c => {
1098+ val n = keyManager.verificationNonce(params.localParams.fundingKeyPath, c.fundingTxIndex, channelKeyPath, localCommitIndex + 2 )
1099+ log.debug(s " revokeandack: creating verification nonce ${n._2} fundingIndex = ${c.fundingTxIndex} commit index = ${localCommitIndex + 2 }" )
1100+ n
1101+ })
1102+ TlvStream (RevokeAndAckTlv .NextLocalNoncesTlv (nonces.map(_._2).toList))
1103+ } else {
1104+ TlvStream .empty
11101105 }
11111106 val revocation = RevokeAndAck (
11121107 channelId = channelId,
@@ -1129,7 +1124,7 @@ case class Commitments(params: ChannelParams,
11291124 remoteNextCommitInfo match {
11301125 case Right (_) => Left (UnexpectedRevocation (channelId))
11311126 case Left (_) if revocation.perCommitmentSecret.publicKey != active.head.remoteCommit.remotePerCommitmentPoint => Left (InvalidRevocation (channelId))
1132- case Left (_) if this .params.commitmentFormat == SimpleTaprootChannelsStagingCommitmentFormat && revocation.nexLocalNonces.isEmpty => Left (MissingNextLocalNonce (channelId))
1127+ case Left (_) if this .params.commitmentFormat.useTaproot && revocation.nexLocalNonces.isEmpty => Left (MissingNextLocalNonce (channelId))
11331128 case Left (_) =>
11341129 // Since htlcs are shared across all commitments, we generate the actions only once based on the first commitment.
11351130 val receivedHtlcs = changes.remoteChanges.signed.collect {
@@ -1221,9 +1216,10 @@ case class Commitments(params: ChannelParams,
12211216 active.forall { commitment =>
12221217 val localFundingKey = keyManager.fundingPublicKey(params.localParams.fundingKeyPath, commitment.fundingTxIndex).publicKey
12231218 val remoteFundingKey = commitment.remoteFundingPubKey
1224- val fundingScript = params.commitmentFormat match {
1225- case SimpleTaprootChannelsStagingCommitmentFormat => Script .write(Scripts .musig2FundingScript(localFundingKey, remoteFundingKey))
1226- case _ => Script .write(Scripts .multiSig2of2(localFundingKey, remoteFundingKey))
1219+ val fundingScript = if (params.commitmentFormat.useTaproot) {
1220+ Script .write(Scripts .musig2FundingScript(localFundingKey, remoteFundingKey))
1221+ } else {
1222+ Script .write(Scripts .multiSig2of2(localFundingKey, remoteFundingKey))
12271223 }
12281224 commitment.commitInput.redeemScriptOrScriptTree == Left (fundingScript)
12291225 }
0 commit comments