From 8d387cee907a0538891f0986408591cacfb2e022 Mon Sep 17 00:00:00 2001 From: Pierre-Marie Padiou Date: Wed, 28 Feb 2018 17:26:28 +0100 Subject: [PATCH] PaymentSucceeded adds fee in amountMsat, and contains paymentHash (#466) --- .../main/scala/fr/acinq/eclair/payment/PaymentLifecycle.scala | 4 ++-- .../src/main/scala/fr/acinq/eclair/payment/Relayer.scala | 2 +- .../scala/fr/acinq/eclair/payment/PaymentLifecycleSpec.scala | 1 + .../test/scala/fr/acinq/eclair/router/BaseRouterSpec.scala | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/payment/PaymentLifecycle.scala b/eclair-core/src/main/scala/fr/acinq/eclair/payment/PaymentLifecycle.scala index 6bf547e3c..2a383b996 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/payment/PaymentLifecycle.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/payment/PaymentLifecycle.scala @@ -20,7 +20,7 @@ case class SendPayment(amountMsat: Long, paymentHash: BinaryData, targetNodeId: case class CheckPayment(paymentHash: BinaryData) sealed trait PaymentResult -case class PaymentSucceeded(amountMsat: Long, paymentPreimage: BinaryData, route: Seq[Hop]) extends PaymentResult +case class PaymentSucceeded(amountMsat: Long, paymentHash: BinaryData, paymentPreimage: BinaryData, route: Seq[Hop]) extends PaymentResult // note: the amount includes fees sealed trait PaymentFailure case class LocalFailure(t: Throwable) extends PaymentFailure case class RemoteFailure(route: Seq[Hop], e: ErrorPacket) extends PaymentFailure @@ -72,7 +72,7 @@ class PaymentLifecycle(sourceNodeId: PublicKey, router: ActorRef, register: Acto case Event("ok", _) => stay() case Event(fulfill: UpdateFulfillHtlc, WaitingForComplete(s, c, cmd, _, _, _, _, hops)) => - reply(s, PaymentSucceeded(c.amountMsat, fulfill.paymentPreimage, hops)) + reply(s, PaymentSucceeded(cmd.amountMsat, c.paymentHash, fulfill.paymentPreimage, hops)) context.system.eventStream.publish(PaymentSent(MilliSatoshi(c.amountMsat), MilliSatoshi(cmd.amountMsat - c.amountMsat), cmd.paymentHash, fulfill.paymentPreimage)) stop(FSM.Normal) diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/payment/Relayer.scala b/eclair-core/src/main/scala/fr/acinq/eclair/payment/Relayer.scala index 673fa554d..c086f5866 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/payment/Relayer.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/payment/Relayer.scala @@ -136,7 +136,7 @@ class Relayer(nodeParams: NodeParams, register: ActorRef, paymentHandler: ActorR case ForwardFulfill(fulfill, Local(None), add) => // we sent the payment, but we probably restarted and the reference to the original sender was lost, we just publish the failure on the event stream - context.system.eventStream.publish(PaymentSucceeded(add.amountMsat, fulfill.paymentPreimage, Nil)) + context.system.eventStream.publish(PaymentSucceeded(add.amountMsat, add.paymentHash, fulfill.paymentPreimage, Nil)) case ForwardFulfill(fulfill, Local(Some(sender)), _) => sender ! fulfill diff --git a/eclair-core/src/test/scala/fr/acinq/eclair/payment/PaymentLifecycleSpec.scala b/eclair-core/src/test/scala/fr/acinq/eclair/payment/PaymentLifecycleSpec.scala index 0aaadac57..201090674 100644 --- a/eclair-core/src/test/scala/fr/acinq/eclair/payment/PaymentLifecycleSpec.scala +++ b/eclair-core/src/test/scala/fr/acinq/eclair/payment/PaymentLifecycleSpec.scala @@ -189,6 +189,7 @@ class PaymentLifecycleSpec extends BaseRouterSpec { sender.send(paymentFSM, UpdateFulfillHtlc("00" * 32, 0, "42" * 32)) val paymentOK = sender.expectMsgType[PaymentSucceeded] + assert(paymentOK.amountMsat > request.amountMsat) val PaymentSent(MilliSatoshi(request.amountMsat), feesPaid, request.paymentHash, paymentOK.paymentPreimage) = eventListener.expectMsgType[PaymentSent] assert(feesPaid.amount > 0) diff --git a/eclair-core/src/test/scala/fr/acinq/eclair/router/BaseRouterSpec.scala b/eclair-core/src/test/scala/fr/acinq/eclair/router/BaseRouterSpec.scala index cc9d11e43..29321e185 100644 --- a/eclair-core/src/test/scala/fr/acinq/eclair/router/BaseRouterSpec.scala +++ b/eclair-core/src/test/scala/fr/acinq/eclair/router/BaseRouterSpec.scala @@ -127,7 +127,6 @@ abstract class BaseRouterSpec extends TestkitBaseClass { val channels = sender.expectMsgType[Iterable[ChannelAnnouncement]] sender.send(router, 'updates) val updates = sender.expectMsgType[Iterable[ChannelUpdate]] - println(nodes.size, channels.size, updates.size) nodes.size === 6 && channels.size === 4 && updates.size === 8 }, max = 10 seconds, interval = 1 second)