@@ -6,6 +6,7 @@ open DotNetLightning.Utils.Aether
66open DotNetLightning.Chain
77open DotNetLightning.Crypto
88open DotNetLightning.Transactions
9+ open DotNetLightning.Transactions .Transactions
910open DotNetLightning.Serialization
1011open DotNetLightning.Serialization .Msgs
1112open NBitcoin
@@ -1230,7 +1231,7 @@ and Channel = {
12301231 let htlcSigs =
12311232 sortedHTLCTXs
12321233 |> List.map(
1233- ( fun htlc -> channelPrivKeys.SignHtlcTx htlc.Value remoteNextPerCommitmentPoint)
1234+ ( fun htlc -> signHtlcTx htlc channelPrivKeys remoteNextPerCommitmentPoint)
12341235 >> fst
12351236 >> ( fun txSig -> txSig.Signature)
12361237 )
@@ -1311,29 +1312,30 @@ and Channel = {
13111312 let sortedHTLCTXs = Commitments.Helpers.sortBothHTLCs htlcTimeoutTxs htlcSuccessTxs
13121313 do ! Commitments.checkSignatureCountMismatch sortedHTLCTXs msg
13131314
1314- let _localHTLCSigs , sortedHTLCTXs =
1315- let localHtlcSigsAndHTLCTxs =
1316- sortedHTLCTXs |> List.map ( fun htlc ->
1317- channelPrivKeys.SignHtlcTx htlc.Value localPerCommitmentPoint
1318- )
1319- localHtlcSigsAndHTLCTxs |> List.map ( fst ), localHtlcSigsAndHTLCTxs |> List.map ( snd ) |> Seq.cast < IHTLCTx > |> List.ofSeq
1315+ let htlcTxsAndSignatures =
1316+ sortedHTLCTXs
1317+ |> List.zip ( msg.HTLCSignatures )
1318+ |> List.map ( fun ( remoteSig , htlc ) ->
1319+ htlc , signHtlcTx htlc channelPrivKeys localPerCommitmentPoint |> fst , remoteSig
1320+ )
13201321
13211322 let remoteHTLCPubKey = localPerCommitmentPoint.DeriveHtlcPubKey remoteChannelKeys.HtlcBasepoint
13221323
1323- let checkHTLCSig ( htlc : IHTLCTx , remoteECDSASig : LNECDSASignature ): Result < _ , _ > =
1324- let remoteS = TransactionSignature( remoteECDSASig.Value, SigHash.All)
1324+ let checkHTLCSig ( htlc : IHTLCTx , localSignature : TransactionSignature , remoteECDSASig : LNECDSASignature ): Result < _ , _ > =
1325+ let remoteSignature = TransactionSignature( remoteECDSASig.Value, SigHash.All)
13251326 match htlc with
13261327 | : ? HTLCTimeoutTx ->
1327- ( Transactions.checkTxFinalized ( htlc.Value) ( 0 ) ( seq [( remoteHTLCPubKey.RawPubKey(), remoteS)]))
1328+ ( htlc :?> HTLCTimeoutTx ). Finalize ( localSignature , remoteSignature )
1329+ |> Result.map( FinalizedTx)
13281330 |> Result.map( box)
13291331 // we cannot check that htlc-success tx are spendable because we need the payment preimage; thus we only check the remote sig
13301332 | : ? HTLCSuccessTx ->
1331- ( Transactions.checkSigAndAdd ( htlc) ( remoteS ) ( remoteHTLCPubKey.RawPubKey() ))
1333+ Transactions.checkSigAndAdd htlc remoteSignature ( remoteHTLCPubKey.RawPubKey())
13321334 |> Result.map( box)
13331335 | _ -> failwith " Unreachable!"
13341336
13351337 let! txList =
1336- List.zip sortedHTLCTXs msg.HTLCSignatures
1338+ htlcTxsAndSignatures
13371339 |> List.map( checkHTLCSig)
13381340 |> List.sequenceResultA
13391341 |> expectTransactionErrors
0 commit comments