@@ -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
@@ -1245,7 +1246,7 @@ and Channel = {
12451246 let htlcSigs =
12461247 sortedHTLCTXs
12471248 |> List.map(
1248- ( fun htlc -> channelPrivKeys.SignHtlcTx htlc.Value remoteNextPerCommitmentPoint)
1249+ ( fun htlc -> signHtlcTx htlc channelPrivKeys remoteNextPerCommitmentPoint)
12491250 >> fst
12501251 >> ( fun txSig -> txSig.Signature)
12511252 )
@@ -1326,29 +1327,30 @@ and Channel = {
13261327 let sortedHTLCTXs = Commitments.Helpers.sortBothHTLCs htlcTimeoutTxs htlcSuccessTxs
13271328 do ! Commitments.checkSignatureCountMismatch sortedHTLCTXs msg
13281329
1329- let _localHTLCSigs , sortedHTLCTXs =
1330- let localHtlcSigsAndHTLCTxs =
1331- sortedHTLCTXs |> List.map ( fun htlc ->
1332- channelPrivKeys.SignHtlcTx htlc.Value localPerCommitmentPoint
1333- )
1334- localHtlcSigsAndHTLCTxs |> List.map ( fst ), localHtlcSigsAndHTLCTxs |> List.map ( snd ) |> Seq.cast < IHTLCTx > |> List.ofSeq
1330+ let htlcTxsAndSignatures =
1331+ sortedHTLCTXs
1332+ |> List.zip ( msg.HTLCSignatures )
1333+ |> List.map ( fun ( remoteSig , htlc ) ->
1334+ htlc , signHtlcTx htlc channelPrivKeys localPerCommitmentPoint |> fst , remoteSig
1335+ )
13351336
13361337 let remoteHTLCPubKey = localPerCommitmentPoint.DeriveHtlcPubKey remoteChannelKeys.HtlcBasepoint
13371338
1338- let checkHTLCSig ( htlc : IHTLCTx , remoteECDSASig : LNECDSASignature ): Result < _ , _ > =
1339- let remoteS = TransactionSignature( remoteECDSASig.Value, SigHash.All)
1339+ let checkHTLCSig ( htlc : IHTLCTx , localSignature : TransactionSignature , remoteECDSASig : LNECDSASignature ): Result < _ , _ > =
1340+ let remoteSignature = TransactionSignature( remoteECDSASig.Value, SigHash.All)
13401341 match htlc with
13411342 | : ? HTLCTimeoutTx ->
1342- ( Transactions.checkTxFinalized ( htlc.Value) ( 0 ) ( seq [( remoteHTLCPubKey.RawPubKey(), remoteS )]))
1343+ ( Transactions.checkTxFinalized ( htlc.Value) ( 0 ) ( seq [( remoteHTLCPubKey.RawPubKey(), remoteSignature )]))
13431344 |> Result.map( box)
13441345 // we cannot check that htlc-success tx are spendable because we need the payment preimage; thus we only check the remote sig
13451346 | : ? HTLCSuccessTx ->
1346- ( Transactions.checkSigAndAdd ( htlc) ( remoteS) ( remoteHTLCPubKey.RawPubKey()))
1347+ ( htlc :?> HTLCTimeoutTx ). Finalize ( localSignature , remoteSignature )
1348+ |> Result.map( FinalizedTx)
13471349 |> Result.map( box)
13481350 | _ -> failwith " Unreachable!"
13491351
13501352 let! txList =
1351- List.zip sortedHTLCTXs msg.HTLCSignatures
1353+ htlcTxsAndSignatures
13521354 |> List.map( checkHTLCSig)
13531355 |> List.sequenceResultA
13541356 |> expectTransactionErrors
0 commit comments