@@ -26,7 +26,7 @@ import fr.acinq.eclair._
26
26
import fr .acinq .eclair .blockchain .fee .{ConfirmationTarget , FeeratePerKw }
27
27
import fr .acinq .eclair .channel .Helpers .Funding
28
28
import fr .acinq .eclair .crypto .keymanager .{LocalCommitmentKeys , RemoteCommitmentKeys }
29
- import fr .acinq .eclair .transactions .CommitmentOutput .{ InHtlc , OutHtlc }
29
+ import fr .acinq .eclair .transactions .CommitmentOutput .OutHtlc
30
30
import fr .acinq .eclair .transactions .Scripts ._
31
31
import fr .acinq .eclair .transactions .Transactions .AnchorOutputsCommitmentFormat .anchorAmount
32
32
import fr .acinq .eclair .transactions .Transactions ._
@@ -174,9 +174,10 @@ class TransactionsSpec extends AnyFunSuite with Logging {
174
174
val redeemScript = htlcReceived(localKeys.publicKeys, htlc.paymentHash, htlc.cltvExpiry, DefaultCommitmentFormat )
175
175
val pubKeyScript = write(pay2wsh(redeemScript))
176
176
val commitTx = Transaction (version = 2 , txIn = Nil , txOut = TxOut (htlc.amountMsat.truncateToSatoshi, pubKeyScript) :: Nil , lockTime = 0 )
177
- val Right (htlcPenaltyTx) = makeHtlcPenaltyTx(remoteKeys, commitTx, 0 , Script .write(redeemScript), localDustLimit, finalPubKeyScript, feeratePerKw)
177
+ val htlcPenaltyTxs = makeHtlcPenaltyTxs(remoteKeys, commitTx, Seq ((htlc.paymentHash, htlc.cltvExpiry)), localDustLimit, finalPubKeyScript, feeratePerKw, DefaultCommitmentFormat )
178
+ assert(htlcPenaltyTxs.size == 1 )
178
179
// we use dummy signatures to compute the weight
179
- val weight = htlcPenaltyTx .addSigs(remoteKeys, PlaceHolderSig ).tx.weight()
180
+ val weight = htlcPenaltyTxs.head .addSigs(remoteKeys, PlaceHolderSig ).tx.weight()
180
181
assert(htlcPenaltyWeight == weight)
181
182
}
182
183
{
@@ -414,16 +415,15 @@ class TransactionsSpec extends AnyFunSuite with Logging {
414
415
assert(claimHtlcDelayedPenaltyTx1 == Seq (Left (AmountBelowDustLimit )))
415
416
}
416
417
{
417
- // remote spends offered HTLC output with revocation key
418
- val script = Script .write(Scripts .htlcOffered(remoteKeys.publicKeys, htlc1.paymentHash, DefaultCommitmentFormat ))
419
- val Some (htlcOutputIndex) = outputs.zipWithIndex.find {
420
- case (CommitmentOutputLink (_, _, OutHtlc (OutgoingHtlc (someHtlc))), _) => someHtlc.id == htlc1.id
421
- case _ => false
422
- }.map(_._2)
423
- val Right (htlcPenaltyTx) = makeHtlcPenaltyTx(remoteKeys, commitTx.tx, htlcOutputIndex, script, localDustLimit, finalPubKeyScript, feeratePerKw)
424
- val sig = htlcPenaltyTx.sign(localRevocationPriv, TxOwner .Local , DefaultCommitmentFormat , Map .empty)
425
- val signed = htlcPenaltyTx.addSigs(remoteKeys, sig)
426
- assert(checkSpendable(signed).isSuccess)
418
+ // remote spends HTLC outputs with revocation key
419
+ val htlcs = spec.htlcs.map(_.add).map(add => (add.paymentHash, add.cltvExpiry)).toSeq
420
+ val htlcPenaltyTxs = makeHtlcPenaltyTxs(remoteKeys, commitTx.tx, htlcs, localDustLimit, finalPubKeyScript, feeratePerKw, DefaultCommitmentFormat )
421
+ assert(htlcPenaltyTxs.size == 4 ) // the first 4 htlcs are above the dust limit
422
+ htlcPenaltyTxs.foreach(htlcPenaltyTx => {
423
+ val sig = htlcPenaltyTx.sign(localRevocationPriv, TxOwner .Local , DefaultCommitmentFormat , Map .empty)
424
+ val signed = htlcPenaltyTx.addSigs(remoteKeys, sig)
425
+ assert(checkSpendable(signed).isSuccess)
426
+ })
427
427
}
428
428
{
429
429
// remote spends htlc2's htlc-success tx with revocation key
@@ -435,18 +435,6 @@ class TransactionsSpec extends AnyFunSuite with Logging {
435
435
val claimHtlcDelayedPenaltyTx1 = makeClaimHtlcDelayedOutputPenaltyTxs(remoteKeys, htlcSuccessTxs(0 ).tx, localDustLimit, toLocalDelay, finalPubKeyScript, feeratePerKw)
436
436
assert(claimHtlcDelayedPenaltyTx1 == Seq (Left (AmountBelowDustLimit )))
437
437
}
438
- {
439
- // remote spends received HTLC output with revocation key
440
- val script = Script .write(Scripts .htlcReceived(remoteKeys.publicKeys, htlc2.paymentHash, htlc2.cltvExpiry, DefaultCommitmentFormat ))
441
- val Some (htlcOutputIndex) = outputs.zipWithIndex.find {
442
- case (CommitmentOutputLink (_, _, InHtlc (IncomingHtlc (someHtlc))), _) => someHtlc.id == htlc2.id
443
- case _ => false
444
- }.map(_._2)
445
- val Right (htlcPenaltyTx) = makeHtlcPenaltyTx(remoteKeys, commitTx.tx, htlcOutputIndex, script, localDustLimit, finalPubKeyScript, feeratePerKw)
446
- val sig = htlcPenaltyTx.sign(localRevocationPriv, TxOwner .Local , DefaultCommitmentFormat , Map .empty)
447
- val signed = htlcPenaltyTx.addSigs(remoteKeys, sig)
448
- assert(checkSpendable(signed).isSuccess)
449
- }
450
438
}
451
439
452
440
test(" generate valid commitment with some outputs that don't materialize (anchor outputs)" ) {
@@ -748,30 +736,15 @@ class TransactionsSpec extends AnyFunSuite with Logging {
748
736
assert(claimed.map(_.input.outPoint).toSet.size == 3 )
749
737
}
750
738
{
751
- // remote spends offered htlc output with revocation key
752
- val script = Script .write(Scripts .htlcOffered(remoteKeys.publicKeys, htlc1.paymentHash, UnsafeLegacyAnchorOutputsCommitmentFormat ))
753
- val Some (htlcOutputIndex) = commitTxOutputs.zipWithIndex.find {
754
- case (CommitmentOutputLink (_, _, OutHtlc (OutgoingHtlc (someHtlc))), _) => someHtlc.id == htlc1.id
755
- case _ => false
756
- }.map(_._2)
757
- val Right (htlcPenaltyTx) = makeHtlcPenaltyTx(remoteKeys, commitTx.tx, htlcOutputIndex, script, localDustLimit, finalPubKeyScript, feeratePerKw)
758
- val sig = htlcPenaltyTx.sign(localRevocationPriv, TxOwner .Local , UnsafeLegacyAnchorOutputsCommitmentFormat , Map .empty)
759
- val signed = htlcPenaltyTx.addSigs(remoteKeys, sig)
760
- assert(checkSpendable(signed).isSuccess)
761
- }
762
- {
763
- // remote spends received htlc output with revocation key
764
- for (htlc <- Seq (htlc2a, htlc2b)) {
765
- val script = Script .write(Scripts .htlcReceived(remoteKeys.publicKeys, htlc.paymentHash, htlc.cltvExpiry, UnsafeLegacyAnchorOutputsCommitmentFormat ))
766
- val Some (htlcOutputIndex) = commitTxOutputs.zipWithIndex.find {
767
- case (CommitmentOutputLink (_, _, InHtlc (IncomingHtlc (someHtlc))), _) => someHtlc.id == htlc.id
768
- case _ => false
769
- }.map(_._2)
770
- val Right (htlcPenaltyTx) = makeHtlcPenaltyTx(remoteKeys, commitTx.tx, htlcOutputIndex, script, localDustLimit, finalPubKeyScript, feeratePerKw)
739
+ // remote spends htlc outputs with revocation key
740
+ val htlcs = spec.htlcs.map(_.add).map(add => (add.paymentHash, add.cltvExpiry)).toSeq
741
+ val htlcPenaltyTxs = makeHtlcPenaltyTxs(remoteKeys, commitTx.tx, htlcs, localDustLimit, finalPubKeyScript, feeratePerKw, UnsafeLegacyAnchorOutputsCommitmentFormat )
742
+ assert(htlcPenaltyTxs.size == 5 ) // the first 5 htlcs are above the dust limit
743
+ htlcPenaltyTxs.foreach(htlcPenaltyTx => {
771
744
val sig = htlcPenaltyTx.sign(localRevocationPriv, TxOwner .Local , UnsafeLegacyAnchorOutputsCommitmentFormat , Map .empty)
772
745
val signed = htlcPenaltyTx.addSigs(remoteKeys, sig)
773
746
assert(checkSpendable(signed).isSuccess)
774
- }
747
+ })
775
748
}
776
749
}
777
750
0 commit comments