@@ -37,10 +37,9 @@ import fr.acinq.eclair.payment.send.MultiPartPaymentLifecycle.{PreimageReceived,
3737import fr .acinq .eclair .payment .send .PaymentInitiator .SendPaymentConfig
3838import fr .acinq .eclair .payment .send .PaymentLifecycle .SendPaymentToNode
3939import fr .acinq .eclair .payment .send ._
40+ import fr .acinq .eclair .reputation .Reputation
41+ import fr .acinq .eclair .reputation .ReputationRecorder .GetConfidence
4042import fr .acinq .eclair .router .Router .{ChannelHop , HopRelayParams , Route , RouteParams }
41- import fr .acinq .eclair .reputation .ReputationRecorder
42- import fr .acinq .eclair .reputation .ReputationRecorder .GetTrampolineConfidence
43- import fr .acinq .eclair .router .Router .RouteParams
4443import fr .acinq .eclair .router .{BalanceTooLow , RouteNotFound }
4544import fr .acinq .eclair .wire .protocol .PaymentOnion .IntermediatePayload
4645import fr .acinq .eclair .wire .protocol ._
@@ -71,29 +70,27 @@ object NodeRelay {
7170 private case class WrappedResolvedPaths (resolved : Seq [ResolvedPath ]) extends Command
7271 private case class WrappedPeerInfo (remoteFeatures_opt : Option [Features [InitFeature ]]) extends Command
7372 private case class WrappedOnTheFlyFundingResponse (result : Peer .ProposeOnTheFlyFundingResponse ) extends Command
74- private case class WrappedConfidence (confidence : Double ) extends Command
7573 // @formatter:on
7674
7775 trait OutgoingPaymentFactory {
7876 def spawnOutgoingPayFSM (context : ActorContext [NodeRelay .Command ], cfg : SendPaymentConfig , multiPart : Boolean ): ActorRef
7977 }
8078
81- case class SimpleOutgoingPaymentFactory (nodeParams : NodeParams , router : ActorRef , register : ActorRef ) extends OutgoingPaymentFactory {
79+ case class SimpleOutgoingPaymentFactory (nodeParams : NodeParams , router : ActorRef , register : ActorRef , reputationRecorder_opt : Option [typed. ActorRef [ GetConfidence ]] ) extends OutgoingPaymentFactory {
8280 val paymentFactory : PaymentInitiator .SimplePaymentFactory = PaymentInitiator .SimplePaymentFactory (nodeParams, router, register)
8381
8482 override def spawnOutgoingPayFSM (context : ActorContext [Command ], cfg : SendPaymentConfig , multiPart : Boolean ): ActorRef = {
8583 if (multiPart) {
8684 context.toClassic.actorOf(MultiPartPaymentLifecycle .props(nodeParams, cfg, publishPreimage = true , router, paymentFactory))
8785 } else {
88- context.toClassic.actorOf(PaymentLifecycle .props(nodeParams, cfg, router, register))
86+ context.toClassic.actorOf(PaymentLifecycle .props(nodeParams, cfg, router, register, reputationRecorder_opt ))
8987 }
9088 }
9189 }
9290
9391 def apply (nodeParams : NodeParams ,
9492 parent : typed.ActorRef [NodeRelayer .Command ],
9593 register : ActorRef ,
96- reputationRecorder_opt : Option [typed.ActorRef [GetTrampolineConfidence ]],
9794 relayId : UUID ,
9895 nodeRelayPacket : NodeRelayPacket ,
9996 outgoingPaymentFactory : OutgoingPaymentFactory ,
@@ -117,7 +114,7 @@ object NodeRelay {
117114 case _ : IncomingPaymentPacket .RelayToNonTrampolinePacket => None
118115 case _ : IncomingPaymentPacket .RelayToBlindedPathsPacket => None
119116 }
120- new NodeRelay (nodeParams, parent, register, reputationRecorder_opt, relayId, paymentHash, nodeRelayPacket.outerPayload.paymentSecret, context, outgoingPaymentFactory, router)
117+ new NodeRelay (nodeParams, parent, register, relayId, paymentHash, nodeRelayPacket.outerPayload.paymentSecret, context, outgoingPaymentFactory, router)
121118 .receiving(Queue .empty, nodeRelayPacket.innerPayload, nextPacket_opt, incomingPaymentHandler)
122119 }
123120 }
@@ -206,7 +203,6 @@ object NodeRelay {
206203class NodeRelay private (nodeParams : NodeParams ,
207204 parent : akka.actor.typed.ActorRef [NodeRelayer .Command ],
208205 register : ActorRef ,
209- reputationRecorder_opt : Option [typed.ActorRef [GetTrampolineConfidence ]],
210206 relayId : UUID ,
211207 paymentHash : ByteVector32 ,
212208 paymentSecret : ByteVector32 ,
@@ -344,33 +340,23 @@ class NodeRelay private(nodeParams: NodeParams,
344340 context.log.debug(" relaying trampoline payment (amountIn={} expiryIn={} amountOut={} expiryOut={} isWallet={})" , upstream.amountIn, upstream.expiryIn, amountOut, expiryOut, walletNodeId_opt.isDefined)
345341 // We only make one try when it's a direct payment to a wallet.
346342 val maxPaymentAttempts = if (walletNodeId_opt.isDefined) 1 else nodeParams.maxPaymentAttempts
347- val totalFee = upstream.amountIn - payloadOut.outgoingAmount(upstream.amountIn)
348- reputationRecorder_opt match {
349- case Some (reputationRecorder) => reputationRecorder ! GetTrampolineConfidence (context.messageAdapter(confidence => WrappedConfidence (confidence.value)), upstream, totalFee)
350- case None => context.self ! WrappedConfidence ((upstream.received.map(_.add.endorsement).min + 0.5 ) / 8 )
351- }
352- Behaviors .receiveMessagePartial {
353- rejectExtraHtlcPartialFunction orElse {
354- case WrappedConfidence (confidence) =>
355- val paymentCfg = SendPaymentConfig (relayId, relayId, None , paymentHash, recipient.nodeId, upstream, None , None , storeInDb = false , publishEvent = false , recordPathFindingMetrics = true , confidence)
356- val routeParams = computeRouteParams(nodeParams, upstream.amountIn, upstream.expiryIn, amountOut, expiryOut)
357- // If the next node is using trampoline, we assume that they support MPP.
358- val useMultiPart = recipient.features.hasFeature(Features .BasicMultiPartPayment ) || packetOut_opt.nonEmpty
359- val payFsmAdapters = {
360- context.messageAdapter[PreimageReceived ](WrappedPreimageReceived )
361- context.messageAdapter[PaymentSent ](WrappedPaymentSent )
362- context.messageAdapter[PaymentFailed ](WrappedPaymentFailed )
363- }.toClassic
364- val payment = if (useMultiPart) {
365- SendMultiPartPayment (payFsmAdapters, recipient, maxPaymentAttempts, routeParams)
366- } else {
367- SendPaymentToNode (payFsmAdapters, recipient, maxPaymentAttempts, routeParams)
368- }
369- val payFSM = outgoingPaymentFactory.spawnOutgoingPayFSM(context, paymentCfg, useMultiPart)
370- payFSM ! payment
371- sending(upstream, recipient, walletNodeId_opt, recipientFeatures_opt, payloadOut, TimestampMilli .now(), fulfilledUpstream = false )
372- }
343+ val paymentCfg = SendPaymentConfig (relayId, relayId, None , paymentHash, recipient.nodeId, upstream, None , None , storeInDb = false , publishEvent = false , recordPathFindingMetrics = true )
344+ val routeParams = computeRouteParams(nodeParams, upstream.amountIn, upstream.expiryIn, amountOut, expiryOut)
345+ // If the next node is using trampoline, we assume that they support MPP.
346+ val useMultiPart = recipient.features.hasFeature(Features .BasicMultiPartPayment ) || packetOut_opt.nonEmpty
347+ val payFsmAdapters = {
348+ context.messageAdapter[PreimageReceived ](WrappedPreimageReceived )
349+ context.messageAdapter[PaymentSent ](WrappedPaymentSent )
350+ context.messageAdapter[PaymentFailed ](WrappedPaymentFailed )
351+ }.toClassic
352+ val payment = if (useMultiPart) {
353+ SendMultiPartPayment (payFsmAdapters, recipient, maxPaymentAttempts, routeParams)
354+ } else {
355+ SendPaymentToNode (payFsmAdapters, recipient, maxPaymentAttempts, routeParams)
373356 }
357+ val payFSM = outgoingPaymentFactory.spawnOutgoingPayFSM(context, paymentCfg, useMultiPart)
358+ payFSM ! payment
359+ sending(upstream, recipient, walletNodeId_opt, recipientFeatures_opt, payloadOut, TimestampMilli .now(), fulfilledUpstream = false )
374360 }
375361
376362 /**
@@ -435,7 +421,7 @@ class NodeRelay private(nodeParams: NodeParams,
435421 case r : BlindedRecipient => r.blindedHops.headOption
436422 }
437423 val dummyRoute = Route (amountOut, Seq (dummyHop), finalHop_opt)
438- OutgoingPaymentPacket .buildOutgoingPayment(Origin .Hot (ActorRef .noSender, upstream), paymentHash, dummyRoute, recipient, 1.0 ) match {
424+ OutgoingPaymentPacket .buildOutgoingPayment(Origin .Hot (ActorRef .noSender, upstream), paymentHash, dummyRoute, recipient, 1.0 , Reputation .maxEndorsement ) match {
439425 case Left (f) =>
440426 context.log.warn(" could not create payment onion for on-the-fly funding: {}" , f.getMessage)
441427 rejectPayment(upstream, translateError(nodeParams, failures, upstream, nextPayload))
0 commit comments