Skip to content

Commit f8fb881

Browse files
committed
Add funding_fee field to CMD_ADD_HTLC
This commit adds the funding fee field to HTLCs, but never sets it. We update a lot of test files, but there is no functional change.
1 parent 217e659 commit f8fb881

32 files changed

Lines changed: 289 additions & 275 deletions

eclair-core/src/main/scala/fr/acinq/eclair/channel/ChannelData.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,16 @@ sealed trait HasOptionalReplyToCommand extends Command { def replyTo_opt: Option
197197
sealed trait ForbiddenCommandDuringSplice extends Command
198198
sealed trait ForbiddenCommandDuringQuiescence extends Command
199199

200-
final case class CMD_ADD_HTLC(replyTo: ActorRef, amount: MilliSatoshi, paymentHash: ByteVector32, cltvExpiry: CltvExpiry, onion: OnionRoutingPacket, nextBlindingKey_opt: Option[PublicKey], origin: Origin.Hot, commit: Boolean = false) extends HasReplyToCommand with ForbiddenCommandDuringSplice with ForbiddenCommandDuringQuiescence
200+
final case class CMD_ADD_HTLC(replyTo: ActorRef,
201+
amount: MilliSatoshi,
202+
paymentHash: ByteVector32,
203+
cltvExpiry: CltvExpiry,
204+
onion: OnionRoutingPacket,
205+
nextBlindingKey_opt: Option[PublicKey],
206+
fundingFee_opt: Option[LiquidityAds.FundingFee],
207+
origin: Origin.Hot,
208+
commit: Boolean = false) extends HasReplyToCommand with ForbiddenCommandDuringSplice with ForbiddenCommandDuringQuiescence
209+
201210
sealed trait HtlcSettlementCommand extends HasOptionalReplyToCommand with ForbiddenCommandDuringSplice with ForbiddenCommandDuringQuiescence { def id: Long }
202211
final case class CMD_FULFILL_HTLC(id: Long, r: ByteVector32, commit: Boolean = false, replyTo_opt: Option[ActorRef] = None) extends HtlcSettlementCommand
203212
final case class CMD_FAIL_HTLC(id: Long, reason: Either[ByteVector, FailureMessage], delay_opt: Option[FiniteDuration] = None, commit: Boolean = false, replyTo_opt: Option[ActorRef] = None) extends HtlcSettlementCommand

eclair-core/src/main/scala/fr/acinq/eclair/channel/Commitments.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ case class Commitments(params: ChannelParams,
854854
return Left(HtlcValueTooSmall(params.channelId, minimum = htlcMinimum, actual = cmd.amount))
855855
}
856856

857-
val add = UpdateAddHtlc(channelId, changes.localNextHtlcId, cmd.amount, cmd.paymentHash, cmd.cltvExpiry, cmd.onion, cmd.nextBlindingKey_opt)
857+
val add = UpdateAddHtlc(channelId, changes.localNextHtlcId, cmd.amount, cmd.paymentHash, cmd.cltvExpiry, cmd.onion, cmd.nextBlindingKey_opt, cmd.fundingFee_opt)
858858
// we increment the local htlc index and add an entry to the origins map
859859
val changes1 = changes.addLocalProposal(add).copy(localNextHtlcId = changes.localNextHtlcId + 1)
860860
val originChannels1 = originChannels + (add.id -> cmd.origin)

eclair-core/src/main/scala/fr/acinq/eclair/payment/PaymentPacket.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ object OutgoingPaymentPacket {
290290
payment <- recipient.buildPayloads(paymentHash, route)
291291
onion <- buildOnion(payment.payloads, paymentHash, Some(PaymentOnionCodecs.paymentOnionPayloadLength)) // BOLT 2 requires that associatedData == paymentHash
292292
} yield {
293-
val cmd = CMD_ADD_HTLC(origin.replyTo, payment.amount, paymentHash, payment.expiry, onion.packet, payment.outerBlinding_opt, origin, commit = true)
293+
val cmd = CMD_ADD_HTLC(origin.replyTo, payment.amount, paymentHash, payment.expiry, onion.packet, payment.outerBlinding_opt, fundingFee_opt = None, origin, commit = true)
294294
OutgoingPaymentPacket(cmd, route.hops.head.shortChannelId, onion.sharedSecrets)
295295
}
296296
}

eclair-core/src/main/scala/fr/acinq/eclair/payment/relay/ChannelRelay.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class ChannelRelay private(nodeParams: NodeParams,
335335
RelayFailure(CMD_FAIL_HTLC(r.add.id, Right(ChannelDisabled(update.messageFlags, update.channelFlags, Some(update))), commit = true))
336336
case None =>
337337
val origin = Origin.Hot(addResponseAdapter.toClassic, upstream)
338-
RelaySuccess(outgoingChannel.channelId, CMD_ADD_HTLC(addResponseAdapter.toClassic, r.amountToForward, r.add.paymentHash, r.outgoingCltv, r.nextPacket, nextBlindingKey_opt, origin, commit = true))
338+
RelaySuccess(outgoingChannel.channelId, CMD_ADD_HTLC(addResponseAdapter.toClassic, r.amountToForward, r.add.paymentHash, r.outgoingCltv, r.nextPacket, nextBlindingKey_opt, fundingFee_opt = None, origin, commit = true))
339339
}
340340
}
341341

eclair-core/src/main/scala/fr/acinq/eclair/wire/protocol/LightningMessageTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ object UpdateAddHtlc {
379379
cltvExpiry: CltvExpiry,
380380
onionRoutingPacket: OnionRoutingPacket,
381381
blinding_opt: Option[PublicKey],
382-
fundingFee_opt: Option[LiquidityAds.FundingFee] = None): UpdateAddHtlc = {
382+
fundingFee_opt: Option[LiquidityAds.FundingFee]): UpdateAddHtlc = {
383383
val tlvs = Set(
384384
blinding_opt.map(UpdateAddHtlcTlv.BlindingPoint),
385385
fundingFee_opt.map(UpdateAddHtlcTlv.FundingFeeTlv),

eclair-core/src/test/scala/fr/acinq/eclair/channel/CommitmentsSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class CommitmentsSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
409409
test("can receive availableForReceive") { f =>
410410
for (isInitiator <- Seq(true, false)) {
411411
val c = CommitmentsSpec.makeCommitments(31000000 msat, 702000000 msat, FeeratePerKw(2679 sat), 546 sat, isInitiator)
412-
val add = UpdateAddHtlc(randomBytes32(), c.changes.remoteNextHtlcId, c.availableBalanceForReceive, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None)
412+
val add = UpdateAddHtlc(randomBytes32(), c.changes.remoteNextHtlcId, c.availableBalanceForReceive, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None, None)
413413
c.receiveAdd(add, feerates, feeConfNoMismatch)
414414
}
415415
}
@@ -460,14 +460,14 @@ class CommitmentsSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
460460
// Add some initial HTLCs to the pending list (bigger commit tx).
461461
for (_ <- 1 to t.pendingHtlcs) {
462462
val amount = Random.nextInt(maxPendingHtlcAmount.toLong.toInt).msat.max(1 msat)
463-
val add = UpdateAddHtlc(randomBytes32(), c.changes.remoteNextHtlcId, amount, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None)
463+
val add = UpdateAddHtlc(randomBytes32(), c.changes.remoteNextHtlcId, amount, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None, None)
464464
c.receiveAdd(add, feerates, feeConfNoMismatch) match {
465465
case Right(cc) => c = cc
466466
case Left(e) => ignore(s"$t -> could not setup initial htlcs: $e")
467467
}
468468
}
469469
if (c.availableBalanceForReceive > 0.msat) {
470-
val add = UpdateAddHtlc(randomBytes32(), c.changes.remoteNextHtlcId, c.availableBalanceForReceive, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None)
470+
val add = UpdateAddHtlc(randomBytes32(), c.changes.remoteNextHtlcId, c.availableBalanceForReceive, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None, None)
471471
c.receiveAdd(add, feerates, feeConfNoMismatch) match {
472472
case Right(_) => ()
473473
case Left(e) => fail(s"$t -> $e")

eclair-core/src/test/scala/fr/acinq/eclair/channel/DustExposureSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import org.scalatest.funsuite.AnyFunSuiteLike
2626
class DustExposureSpec extends AnyFunSuiteLike {
2727

2828
def createHtlc(id: Long, amount: MilliSatoshi): UpdateAddHtlc = {
29-
UpdateAddHtlc(ByteVector32.Zeroes, id, amount, randomBytes32(), CltvExpiry(500), TestConstants.emptyOnionPacket, None)
29+
UpdateAddHtlc(ByteVector32.Zeroes, id, amount, randomBytes32(), CltvExpiry(500), TestConstants.emptyOnionPacket, None, None)
3030
}
3131

3232
test("compute dust exposure") {

eclair-core/src/test/scala/fr/acinq/eclair/channel/HelpersSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ class HelpersSpec extends TestKitBaseClass with AnyFunSuiteLike with ChannelStat
6868
awaitCond(bob.stateName == NORMAL)
6969
// We have two identical HTLCs (MPP):
7070
val (_, htlca1a) = addHtlc(15_000_000 msat, alice, bob, alice2bob, bob2alice)
71-
val aliceMppCmd = CMD_ADD_HTLC(TestProbe().ref, 15_000_000 msat, htlca1a.paymentHash, htlca1a.cltvExpiry, htlca1a.onionRoutingPacket, None, Origin.Hot(TestProbe().ref, Upstream.Local(UUID.randomUUID())))
71+
val aliceMppCmd = CMD_ADD_HTLC(TestProbe().ref, 15_000_000 msat, htlca1a.paymentHash, htlca1a.cltvExpiry, htlca1a.onionRoutingPacket, None, None, Origin.Hot(TestProbe().ref, Upstream.Local(UUID.randomUUID())))
7272
val htlca1b = addHtlc(aliceMppCmd, alice, bob, alice2bob, bob2alice)
7373
val (ra2, htlca2) = addHtlc(16_000_000 msat, alice, bob, alice2bob, bob2alice)
7474
addHtlc(500_000 msat, alice, bob, alice2bob, bob2alice) // below dust
7575
crossSign(alice, bob, alice2bob, bob2alice)
7676
// We have two identical HTLCs (MPP):
7777
val (_, htlcb1a) = addHtlc(17_000_000 msat, bob, alice, bob2alice, alice2bob)
78-
val bobMppCmd = CMD_ADD_HTLC(TestProbe().ref, 17_000_000 msat, htlcb1a.paymentHash, htlcb1a.cltvExpiry, htlcb1a.onionRoutingPacket, None, Origin.Hot(TestProbe().ref, Upstream.Local(UUID.randomUUID())))
78+
val bobMppCmd = CMD_ADD_HTLC(TestProbe().ref, 17_000_000 msat, htlcb1a.paymentHash, htlcb1a.cltvExpiry, htlcb1a.onionRoutingPacket, None, None, Origin.Hot(TestProbe().ref, Upstream.Local(UUID.randomUUID())))
7979
val htlcb1b = addHtlc(bobMppCmd, bob, alice, bob2alice, alice2bob)
8080
val (rb2, htlcb2) = addHtlc(18_000_000 msat, bob, alice, bob2alice, alice2bob)
8181
addHtlc(400_000 msat, bob, alice, bob2alice, alice2bob) // below dust

eclair-core/src/test/scala/fr/acinq/eclair/channel/states/e/NormalQuiescentStateSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class NormalQuiescentStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteL
148148
// initiator should reject commands that change the commitment once it became quiescent
149149
val sender1, sender2, sender3 = TestProbe()
150150
val cmds = Seq(
151-
CMD_ADD_HTLC(sender1.ref, 1_000_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, localOrigin(sender1.ref)),
151+
CMD_ADD_HTLC(sender1.ref, 1_000_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, None, localOrigin(sender1.ref)),
152152
CMD_UPDATE_FEE(FeeratePerKw(100 sat), replyTo_opt = Some(sender2.ref)),
153153
CMD_CLOSE(sender3.ref, None, None)
154154
)
@@ -164,7 +164,7 @@ class NormalQuiescentStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteL
164164
// both should reject commands that change the commitment while quiescent
165165
val sender1, sender2, sender3 = TestProbe()
166166
val cmds = Seq(
167-
CMD_ADD_HTLC(sender1.ref, 1_000_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, localOrigin(sender1.ref)),
167+
CMD_ADD_HTLC(sender1.ref, 1_000_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, None, localOrigin(sender1.ref)),
168168
CMD_UPDATE_FEE(FeeratePerKw(100 sat), replyTo_opt = Some(sender2.ref)),
169169
CMD_CLOSE(sender3.ref, None, None)
170170
)
@@ -352,7 +352,7 @@ class NormalQuiescentStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteL
352352
import f._
353353
initiateQuiescence(f, sendInitialStfu = true)
354354
// have to build a htlc manually because eclair would refuse to accept this command as it's forbidden
355-
val forbiddenMsg = UpdateAddHtlc(channelId = randomBytes32(), id = 5656, amountMsat = 50000000 msat, cltvExpiry = CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), paymentHash = randomBytes32(), onionRoutingPacket = TestConstants.emptyOnionPacket, blinding_opt = None)
355+
val forbiddenMsg = UpdateAddHtlc(channelId = randomBytes32(), id = 5656, amountMsat = 50000000 msat, cltvExpiry = CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), paymentHash = randomBytes32(), onionRoutingPacket = TestConstants.emptyOnionPacket, blinding_opt = None, fundingFee_opt = None)
356356
// both parties will respond to a forbidden msg while quiescent with a warning (and disconnect)
357357
bob2alice.forward(alice, forbiddenMsg)
358358
alice2bob.expectMsg(Warning(channelId(alice), ForbiddenDuringSplice(channelId(alice), "UpdateAddHtlc").getMessage))

eclair-core/src/test/scala/fr/acinq/eclair/channel/states/e/NormalSplicesStateSpec.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ class NormalSplicesStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLik
707707

708708
val sender = TestProbe()
709709
// command for a large payment (larger than local balance pre-slice)
710-
val cmd = CMD_ADD_HTLC(sender.ref, 1_000_000_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, localOrigin(sender.ref))
710+
val cmd = CMD_ADD_HTLC(sender.ref, 1_000_000_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, None, localOrigin(sender.ref))
711711
// first attempt at payment fails (not enough balance)
712712
alice ! cmd
713713
sender.expectMsgType[RES_ADD_FAILED[_]]
@@ -959,7 +959,7 @@ class NormalSplicesStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLik
959959
import f._
960960
initiateSplice(f, spliceIn_opt = Some(SpliceIn(500_000 sat)))
961961
val sender = TestProbe()
962-
alice ! CMD_ADD_HTLC(sender.ref, 500_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, localOrigin(sender.ref))
962+
alice ! CMD_ADD_HTLC(sender.ref, 500_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, None, localOrigin(sender.ref))
963963
sender.expectMsgType[RES_SUCCESS[CMD_ADD_HTLC]]
964964
alice2bob.expectMsgType[UpdateAddHtlc]
965965
alice2bob.forward(bob)
@@ -988,7 +988,7 @@ class NormalSplicesStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLik
988988
import f._
989989
initiateSplice(f, spliceIn_opt = Some(SpliceIn(500_000 sat)))
990990
val sender = TestProbe()
991-
alice ! CMD_ADD_HTLC(sender.ref, 500_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, localOrigin(sender.ref))
991+
alice ! CMD_ADD_HTLC(sender.ref, 500_000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, None, localOrigin(sender.ref))
992992
sender.expectMsgType[RES_SUCCESS[CMD_ADD_HTLC]]
993993
alice2bob.expectMsgType[UpdateAddHtlc]
994994
alice2bob.forward(bob)
@@ -1022,7 +1022,7 @@ class NormalSplicesStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLik
10221022
val cmd = CMD_SPLICE(sender.ref, spliceIn_opt = Some(SpliceIn(500_000 sat, pushAmount = 0 msat)), spliceOut_opt = None, requestFunding_opt = None)
10231023
alice ! cmd
10241024
alice2bob.expectMsgType[SpliceInit]
1025-
alice ! CMD_ADD_HTLC(sender.ref, 500000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, localOrigin(sender.ref))
1025+
alice ! CMD_ADD_HTLC(sender.ref, 500000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, None, localOrigin(sender.ref))
10261026
sender.expectMsgType[RES_ADD_FAILED[_]]
10271027
alice2bob.expectNoMessage(100 millis)
10281028
}
@@ -1037,7 +1037,7 @@ class NormalSplicesStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLik
10371037
bob2alice.expectMsgType[SpliceAck]
10381038
bob2alice.forward(alice)
10391039
alice2bob.expectMsgType[TxAddInput]
1040-
alice ! CMD_ADD_HTLC(sender.ref, 500000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, localOrigin(sender.ref))
1040+
alice ! CMD_ADD_HTLC(sender.ref, 500000 msat, randomBytes32(), CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket, None, None, localOrigin(sender.ref))
10411041
sender.expectMsgType[RES_ADD_FAILED[_]]
10421042
alice2bob.expectNoMessage(100 millis)
10431043
}
@@ -1079,7 +1079,7 @@ class NormalSplicesStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLik
10791079
alice2bob.expectMsgType[TxAddInput]
10801080

10811081
// have to build a htlc manually because eclair would refuse to accept this command as it's forbidden
1082-
val fakeHtlc = UpdateAddHtlc(channelId = randomBytes32(), id = 5656, amountMsat = 50000000 msat, cltvExpiry = CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), paymentHash = randomBytes32(), onionRoutingPacket = TestConstants.emptyOnionPacket, blinding_opt = None)
1082+
val fakeHtlc = UpdateAddHtlc(channelId = randomBytes32(), id = 5656, amountMsat = 50000000 msat, cltvExpiry = CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), paymentHash = randomBytes32(), onionRoutingPacket = TestConstants.emptyOnionPacket, blinding_opt = None, fundingFee_opt = None)
10831083
bob2alice.forward(alice, fakeHtlc)
10841084
// alice returns a warning and schedules a disconnect after receiving UpdateAddHtlc
10851085
alice2bob.expectMsg(Warning(channelId(alice), ForbiddenDuringSplice(channelId(alice), "UpdateAddHtlc").getMessage))

0 commit comments

Comments
 (0)