@@ -194,17 +194,17 @@ object LocalCommit {
194194 def fromCommitSig (params : ChannelParams , commitKeys : LocalCommitmentKeys , fundingTxId : TxId ,
195195 fundingKey : PrivateKey , remoteFundingPubKey : PublicKey , commitInput : InputInfo ,
196196 commit : CommitSig , localCommitIndex : Long , spec : CommitmentSpec ): Either [ChannelException , LocalCommit ] = {
197- val (localCommitTx, htlcTxs) = Commitment .makeLocalTxs(params, commitKeys, localCommitIndex, fundingKey, remoteFundingPubKey, commitInput, spec)
198- if (! localCommitTx.checkSig(commit.signature, remoteFundingPubKey, TxOwner .Remote , params.commitmentFormat)) {
197+ val (( localCommitTx, redeemInfo) , htlcTxs) = Commitment .makeLocalTxs(params, commitKeys, localCommitIndex, fundingKey, remoteFundingPubKey, commitInput, spec)
198+ if (! localCommitTx.checkSig(commit.signature, redeemInfo, remoteFundingPubKey, TxOwner .Remote , params.commitmentFormat)) {
199199 return Left (InvalidCommitmentSignature (params.channelId, fundingTxId, localCommitIndex, localCommitTx.tx))
200200 }
201- val sortedHtlcTxs = htlcTxs.sortBy(_.input.outPoint.index)
201+ val sortedHtlcTxs = htlcTxs.sortBy(_._1. input.outPoint.index)
202202 if (commit.htlcSignatures.size != sortedHtlcTxs.size) {
203203 return Left (HtlcSigCountMismatch (params.channelId, sortedHtlcTxs.size, commit.htlcSignatures.size))
204204 }
205205 val htlcTxsAndRemoteSigs = sortedHtlcTxs.zip(commit.htlcSignatures).toList.map {
206- case (htlcTx : HtlcTx , remoteSig) =>
207- if (! htlcTx.checkSig(remoteSig, commitKeys.theirHtlcPublicKey, TxOwner .Remote , params.commitmentFormat)) {
206+ case (( htlcTx : HtlcTx , redeemInfo : RedeemInfo ) , remoteSig) =>
207+ if (! htlcTx.checkSig(remoteSig, redeemInfo, commitKeys.theirHtlcPublicKey, TxOwner .Remote , params.commitmentFormat)) {
208208 return Left (InvalidHtlcSignature (params.channelId, htlcTx.tx.txid))
209209 }
210210 HtlcTxAndRemoteSig (htlcTx, remoteSig)
@@ -218,10 +218,10 @@ case class RemoteCommit(index: Long, spec: CommitmentSpec, txid: TxId, remotePer
218218 def sign (params : ChannelParams , channelKeys : ChannelKeys , fundingTxIndex : Long , remoteFundingPubKey : PublicKey , commitInput : InputInfo ): CommitSig = {
219219 val fundingKey = channelKeys.fundingKey(fundingTxIndex)
220220 val commitKeys = RemoteCommitmentKeys (params, channelKeys, remotePerCommitmentPoint)
221- val (remoteCommitTx, htlcTxs) = Commitment .makeRemoteTxs(params, commitKeys, index, fundingKey, remoteFundingPubKey, commitInput, spec)
222- val sig = remoteCommitTx.sign(fundingKey, TxOwner .Remote , params.commitmentFormat, Map .empty)
223- val sortedHtlcTxs = htlcTxs.sortBy(_.input.outPoint.index)
224- val htlcSigs = sortedHtlcTxs.map(_ .sign(commitKeys.ourHtlcKey, TxOwner .Remote , params.commitmentFormat, Map .empty))
221+ val (( remoteCommitTx, redeemInfo) , htlcTxs) = Commitment .makeRemoteTxs(params, commitKeys, index, fundingKey, remoteFundingPubKey, commitInput, spec)
222+ val sig = remoteCommitTx.sign(fundingKey, redeemInfo, TxOwner .Remote , params.commitmentFormat, Map .empty)
223+ val sortedHtlcTxs = htlcTxs.sortBy(_._1. input.outPoint.index)
224+ val htlcSigs = sortedHtlcTxs.map{ case (tx, redeemInfo) => tx .sign(commitKeys.ourHtlcKey, redeemInfo, TxOwner .Remote , params.commitmentFormat, Map .empty) }
225225 CommitSig (params.channelId, sig, htlcSigs.toList)
226226 }
227227}
@@ -625,11 +625,11 @@ case class Commitment(fundingTxIndex: Long,
625625 // remote commitment will include all local proposed changes + remote acked changes
626626 val spec = CommitmentSpec .reduce(remoteCommit.spec, changes.remoteChanges.acked, changes.localChanges.proposed)
627627 val fundingKey = channelKeys.fundingKey(fundingTxIndex)
628- val (remoteCommitTx, htlcTxs) = Commitment .makeRemoteTxs(params, commitKeys, remoteCommit.index + 1 , fundingKey, remoteFundingPubKey, commitInput, spec)
629- val sig = remoteCommitTx.sign(fundingKey, TxOwner .Remote , params.commitmentFormat, Map .empty)
628+ val (( remoteCommitTx, redeemInfo) , htlcTxs) = Commitment .makeRemoteTxs(params, commitKeys, remoteCommit.index + 1 , fundingKey, remoteFundingPubKey, commitInput, spec)
629+ val sig = remoteCommitTx.sign(fundingKey, redeemInfo, TxOwner .Remote , params.commitmentFormat, Map .empty)
630630
631- val sortedHtlcTxs : Seq [ TransactionWithInputInfo ] = htlcTxs.sortBy(_.input.outPoint.index)
632- val htlcSigs = sortedHtlcTxs.map(_ .sign(commitKeys.ourHtlcKey, TxOwner .Remote , params.commitmentFormat, Map .empty))
631+ val sortedHtlcTxs = htlcTxs.sortBy(_._1 .input.outPoint.index)
632+ val htlcSigs = sortedHtlcTxs.map { case (tx, redeemInfo) => tx .sign(commitKeys.ourHtlcKey, redeemInfo, TxOwner .Remote , params.commitmentFormat, Map .empty) }
633633
634634 // NB: IN/OUT htlcs are inverted because this is the remote commit
635635 log.info(s " built remote commit number= ${remoteCommit.index + 1 } toLocalMsat= ${spec.toLocal.toLong} toRemoteMsat= ${spec.toRemote.toLong} htlc_in={} htlc_out={} feeratePerKw= ${spec.commitTxFeerate} txid= ${remoteCommitTx.tx.txid} fundingTxId= $fundingTxId" , spec.htlcs.collect(DirectedHtlc .outgoing).map(_.id).mkString(" ," ), spec.htlcs.collect(DirectedHtlc .incoming).map(_.id).mkString(" ," ))
@@ -664,7 +664,8 @@ case class Commitment(fundingTxIndex: Long,
664664 def fullySignedLocalCommitTx (params : ChannelParams , channelKeys : ChannelKeys ): CommitTx = {
665665 val unsignedCommitTx = localCommit.commitTxAndRemoteSig.commitTx
666666 val fundingKey = channelKeys.fundingKey(fundingTxIndex)
667- val localSig = unsignedCommitTx.sign(fundingKey, TxOwner .Local , params.commitmentFormat, Map .empty)
667+ val redeemInfo = Helpers .Funding .makeFundingRedeemInfo(fundingKey.publicKey, remoteFundingPubKey, params.commitmentFormat)
668+ val localSig = unsignedCommitTx.sign(fundingKey, redeemInfo, TxOwner .Local , params.commitmentFormat, Map .empty)
668669 val RemoteSignature .FullSignature (remoteSig) = localCommit.commitTxAndRemoteSig.remoteSig
669670 val commitTx = unsignedCommitTx.addSigs(fundingKey.publicKey, remoteFundingPubKey, localSig, remoteSig)
670671 // We verify the remote signature when receiving their commit_sig, so this check should always pass.
@@ -681,11 +682,12 @@ object Commitment {
681682 localFundingKey : PrivateKey ,
682683 remoteFundingPubKey : PublicKey ,
683684 commitmentInput : InputInfo ,
684- spec : CommitmentSpec ): (CommitTx , Seq [HtlcTx ]) = {
685+ spec : CommitmentSpec ): (( CommitTx , RedeemInfo ), Seq [( HtlcTx , RedeemInfo ) ]) = {
685686 val outputs = makeCommitTxOutputs(localFundingKey.publicKey, remoteFundingPubKey, commitKeys.publicKeys, params.localParams.paysCommitTxFees, params.localParams.dustLimit, params.remoteParams.toSelfDelay, spec, params.commitmentFormat)
686687 val commitTx = makeCommitTx(commitmentInput, commitTxNumber, commitKeys.ourPaymentBasePoint, params.remoteParams.paymentBasepoint, params.localParams.isChannelOpener, outputs)
688+ val redeemInfo = Helpers .Funding .makeFundingRedeemInfo(localFundingKey.publicKey, remoteFundingPubKey, params.commitmentFormat)
687689 val htlcTxs = makeHtlcTxs(commitTx.tx, outputs, params.commitmentFormat)
688- (commitTx, htlcTxs)
690+ (commitTx -> redeemInfo , htlcTxs)
689691 }
690692
691693 def makeRemoteTxs (params : ChannelParams ,
@@ -694,11 +696,12 @@ object Commitment {
694696 localFundingKey : PrivateKey ,
695697 remoteFundingPubKey : PublicKey ,
696698 commitmentInput : InputInfo ,
697- spec : CommitmentSpec ): (CommitTx , Seq [HtlcTx ]) = {
699+ spec : CommitmentSpec ): (( CommitTx , RedeemInfo ), Seq [( HtlcTx , RedeemInfo ) ]) = {
698700 val outputs = makeCommitTxOutputs(remoteFundingPubKey, localFundingKey.publicKey, commitKeys.publicKeys, ! params.localParams.paysCommitTxFees, params.remoteParams.dustLimit, params.localParams.toSelfDelay, spec, params.commitmentFormat)
699701 val commitTx = makeCommitTx(commitmentInput, commitTxNumber, params.remoteParams.paymentBasepoint, commitKeys.ourPaymentBasePoint, ! params.localParams.isChannelOpener, outputs)
702+ val redeemInfo = Helpers .Funding .makeFundingRedeemInfo(localFundingKey.publicKey, remoteFundingPubKey, params.commitmentFormat)
700703 val htlcTxs = makeHtlcTxs(commitTx.tx, outputs, params.commitmentFormat)
701- (commitTx, htlcTxs)
704+ (commitTx -> redeemInfo , htlcTxs)
702705 }
703706}
704707
@@ -1131,11 +1134,8 @@ case class Commitments(params: ChannelParams,
11311134 active.forall { commitment =>
11321135 val localFundingKey = channelKeys.fundingKey(commitment.fundingTxIndex).publicKey
11331136 val remoteFundingKey = commitment.remoteFundingPubKey
1134- val fundingScript = Scripts .multiSig2of2(localFundingKey, remoteFundingKey)
1135- commitment.commitInput.redeemInfo match {
1136- case RedeemInfo .SegwitV0 (redeemScript) => redeemScript == fundingScript
1137- case _ => false
1138- }
1137+ val redeemInfo = Helpers .Funding .makeFundingRedeemInfo(localFundingKey, remoteFundingKey, params.commitmentFormat)
1138+ commitment.commitInput.txOut.publicKeyScript == Script .write(redeemInfo.publicKeyScript)
11391139 }
11401140 }
11411141
0 commit comments