@@ -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 ._
@@ -70,29 +69,27 @@ object NodeRelay {
7069 private case class WrappedResolvedPaths (resolved : Seq [ResolvedPath ]) extends Command
7170 private case class WrappedPeerInfo (remoteFeatures_opt : Option [Features [InitFeature ]]) extends Command
7271 private case class WrappedOnTheFlyFundingResponse (result : Peer .ProposeOnTheFlyFundingResponse ) extends Command
73- private case class WrappedConfidence (confidence : Double ) extends Command
7472 // @formatter:on
7573
7674 trait OutgoingPaymentFactory {
7775 def spawnOutgoingPayFSM (context : ActorContext [NodeRelay .Command ], cfg : SendPaymentConfig , multiPart : Boolean ): ActorRef
7876 }
7977
80- case class SimpleOutgoingPaymentFactory (nodeParams : NodeParams , router : ActorRef , register : ActorRef ) extends OutgoingPaymentFactory {
78+ case class SimpleOutgoingPaymentFactory (nodeParams : NodeParams , router : ActorRef , register : ActorRef , reputationRecorder_opt : Option [typed. ActorRef [ GetConfidence ]] ) extends OutgoingPaymentFactory {
8179 val paymentFactory : PaymentInitiator .SimplePaymentFactory = PaymentInitiator .SimplePaymentFactory (nodeParams, router, register)
8280
8381 override def spawnOutgoingPayFSM (context : ActorContext [Command ], cfg : SendPaymentConfig , multiPart : Boolean ): ActorRef = {
8482 if (multiPart) {
8583 context.toClassic.actorOf(MultiPartPaymentLifecycle .props(nodeParams, cfg, publishPreimage = true , router, paymentFactory))
8684 } else {
87- context.toClassic.actorOf(PaymentLifecycle .props(nodeParams, cfg, router, register))
85+ context.toClassic.actorOf(PaymentLifecycle .props(nodeParams, cfg, router, register, reputationRecorder_opt ))
8886 }
8987 }
9088 }
9189
9290 def apply (nodeParams : NodeParams ,
9391 parent : typed.ActorRef [NodeRelayer .Command ],
9492 register : ActorRef ,
95- reputationRecorder_opt : Option [typed.ActorRef [GetTrampolineConfidence ]],
9693 relayId : UUID ,
9794 nodeRelayPacket : NodeRelayPacket ,
9895 outgoingPaymentFactory : OutgoingPaymentFactory ,
@@ -116,7 +113,7 @@ object NodeRelay {
116113 case _ : IncomingPaymentPacket .RelayToNonTrampolinePacket => None
117114 case _ : IncomingPaymentPacket .RelayToBlindedPathsPacket => None
118115 }
119- new NodeRelay (nodeParams, parent, register, reputationRecorder_opt, relayId, paymentHash, nodeRelayPacket.outerPayload.paymentSecret, context, outgoingPaymentFactory, router)
116+ new NodeRelay (nodeParams, parent, register, relayId, paymentHash, nodeRelayPacket.outerPayload.paymentSecret, context, outgoingPaymentFactory, router)
120117 .receiving(Queue .empty, nodeRelayPacket.innerPayload, nextPacket_opt, incomingPaymentHandler)
121118 }
122119 }
@@ -205,7 +202,6 @@ object NodeRelay {
205202class NodeRelay private (nodeParams : NodeParams ,
206203 parent : akka.actor.typed.ActorRef [NodeRelayer .Command ],
207204 register : ActorRef ,
208- reputationRecorder_opt : Option [typed.ActorRef [GetTrampolineConfidence ]],
209205 relayId : UUID ,
210206 paymentHash : ByteVector32 ,
211207 paymentSecret : ByteVector32 ,
@@ -343,33 +339,23 @@ class NodeRelay private(nodeParams: NodeParams,
343339 context.log.debug(" relaying trampoline payment (amountIn={} expiryIn={} amountOut={} expiryOut={} isWallet={})" , upstream.amountIn, upstream.expiryIn, amountOut, expiryOut, walletNodeId_opt.isDefined)
344340 // We only make one try when it's a direct payment to a wallet.
345341 val maxPaymentAttempts = if (walletNodeId_opt.isDefined) 1 else nodeParams.maxPaymentAttempts
346- val totalFee = upstream.amountIn - payloadOut.outgoingAmount(upstream.amountIn)
347- reputationRecorder_opt match {
348- case Some (reputationRecorder) => reputationRecorder ! GetTrampolineConfidence (context.messageAdapter(confidence => WrappedConfidence (confidence.value)), upstream, totalFee)
349- case None => context.self ! WrappedConfidence ((upstream.received.map(_.add.endorsement).min + 0.5 ) / 8 )
350- }
351- Behaviors .receiveMessagePartial {
352- rejectExtraHtlcPartialFunction orElse {
353- case WrappedConfidence (confidence) =>
354- val paymentCfg = SendPaymentConfig (relayId, relayId, None , paymentHash, recipient.nodeId, upstream, None , None , storeInDb = false , publishEvent = false , recordPathFindingMetrics = true , confidence)
355- val routeParams = computeRouteParams(nodeParams, upstream.amountIn, upstream.expiryIn, amountOut, expiryOut)
356- // If the next node is using trampoline, we assume that they support MPP.
357- val useMultiPart = recipient.features.hasFeature(Features .BasicMultiPartPayment ) || packetOut_opt.nonEmpty
358- val payFsmAdapters = {
359- context.messageAdapter[PreimageReceived ](WrappedPreimageReceived )
360- context.messageAdapter[PaymentSent ](WrappedPaymentSent )
361- context.messageAdapter[PaymentFailed ](WrappedPaymentFailed )
362- }.toClassic
363- val payment = if (useMultiPart) {
364- SendMultiPartPayment (payFsmAdapters, recipient, maxPaymentAttempts, routeParams)
365- } else {
366- SendPaymentToNode (payFsmAdapters, recipient, maxPaymentAttempts, routeParams)
367- }
368- val payFSM = outgoingPaymentFactory.spawnOutgoingPayFSM(context, paymentCfg, useMultiPart)
369- payFSM ! payment
370- sending(upstream, recipient, walletNodeId_opt, recipientFeatures_opt, payloadOut, TimestampMilli .now(), fulfilledUpstream = false )
371- }
342+ val paymentCfg = SendPaymentConfig (relayId, relayId, None , paymentHash, recipient.nodeId, upstream, None , None , storeInDb = false , publishEvent = false , recordPathFindingMetrics = true )
343+ val routeParams = computeRouteParams(nodeParams, upstream.amountIn, upstream.expiryIn, amountOut, expiryOut)
344+ // If the next node is using trampoline, we assume that they support MPP.
345+ val useMultiPart = recipient.features.hasFeature(Features .BasicMultiPartPayment ) || packetOut_opt.nonEmpty
346+ val payFsmAdapters = {
347+ context.messageAdapter[PreimageReceived ](WrappedPreimageReceived )
348+ context.messageAdapter[PaymentSent ](WrappedPaymentSent )
349+ context.messageAdapter[PaymentFailed ](WrappedPaymentFailed )
350+ }.toClassic
351+ val payment = if (useMultiPart) {
352+ SendMultiPartPayment (payFsmAdapters, recipient, maxPaymentAttempts, routeParams)
353+ } else {
354+ SendPaymentToNode (payFsmAdapters, recipient, maxPaymentAttempts, routeParams)
372355 }
356+ val payFSM = outgoingPaymentFactory.spawnOutgoingPayFSM(context, paymentCfg, useMultiPart)
357+ payFSM ! payment
358+ sending(upstream, recipient, walletNodeId_opt, recipientFeatures_opt, payloadOut, TimestampMilli .now(), fulfilledUpstream = false )
373359 }
374360
375361 /**
@@ -434,7 +420,7 @@ class NodeRelay private(nodeParams: NodeParams,
434420 case r : BlindedRecipient => r.blindedHops.headOption
435421 }
436422 val dummyRoute = Route (amountOut, Seq (dummyHop), finalHop_opt)
437- OutgoingPaymentPacket .buildOutgoingPayment(Origin .Hot (ActorRef .noSender, upstream), paymentHash, dummyRoute, recipient, 1.0 ) match {
423+ OutgoingPaymentPacket .buildOutgoingPayment(Origin .Hot (ActorRef .noSender, upstream), paymentHash, dummyRoute, recipient, 1.0 , Reputation .maxEndorsement ) match {
438424 case Left (f) =>
439425 context.log.warn(" could not create payment onion for on-the-fly funding: {}" , f.getMessage)
440426 rejectPayment(upstream, translateError(nodeParams, failures, upstream, nextPayload))
0 commit comments