@@ -32,6 +32,7 @@ import fr.acinq.eclair.blockchain.fee.FeeratePerKw
3232import fr .acinq .eclair .blockchain .{CurrentBlockHeight , CurrentFeerates , OnChainChannelFunder , OnchainPubkeyCache }
3333import fr .acinq .eclair .channel ._
3434import fr .acinq .eclair .channel .fsm .Channel
35+ import fr .acinq .eclair .crypto .Sphinx
3536import fr .acinq .eclair .db .PendingCommandsDb
3637import fr .acinq .eclair .io .MessageRelay .Status
3738import fr .acinq .eclair .io .Monitoring .{Metrics , Tags }
@@ -44,7 +45,7 @@ import fr.acinq.eclair.remote.EclairInternalsSerializer.RemoteTypes
4445import fr .acinq .eclair .router .Router
4546import fr .acinq .eclair .wire .protocol
4647import fr .acinq .eclair .wire .protocol .FailureMessageCodecs .createBadOnionFailure
47- import fr .acinq .eclair .wire .protocol .{AddFeeCredit , ChannelTlv , CurrentFeeCredit , Error , FailureReason , HasChannelId , HasTemporaryChannelId , LightningMessage , LiquidityAds , NodeAddress , OnTheFlyFundingFailureMessage , OnionMessage , OnionRoutingPacket , RecommendedFeerates , RoutingMessage , SpliceInit , TemporaryChannelFailure , TlvStream , TxAbort , UnknownMessage , Warning , WillAddHtlc , WillFailHtlc , WillFailMalformedHtlc }
48+ import fr .acinq .eclair .wire .protocol .{AddFeeCredit , ChannelTlv , CurrentFeeCredit , Error , FailureReason , HasChannelId , HasTemporaryChannelId , LightningMessage , LiquidityAds , NodeAddress , OnTheFlyFundingFailureMessage , OnionMessage , OnionRoutingPacket , RecommendedFeerates , RoutingMessage , SpliceInit , TlvStream , TxAbort , UnknownMessage , Warning , WillAddHtlc , WillFailHtlc , WillFailMalformedHtlc }
4849
4950/**
5051 * This actor represents a logical peer. There is one [[Peer ]] per unique remote node id at all time.
@@ -267,27 +268,27 @@ class Peer(val nodeParams: NodeParams,
267268 status.timer.cancel()
268269 val timer = context.system.scheduler.scheduleOnce(nodeParams.onTheFlyFundingConfig.proposalTimeout, self, OnTheFlyFundingTimeout (cmd.paymentHash))(context.dispatcher)
269270 pending.copy(
270- proposed = pending.proposed :+ OnTheFlyFunding .Proposal (htlc, cmd.upstream),
271+ proposed = pending.proposed :+ OnTheFlyFunding .Proposal (htlc, cmd.upstream, cmd.onionSharedSecrets ),
271272 status = OnTheFlyFunding .Status .Proposed (timer)
272273 )
273274 case status : OnTheFlyFunding .Status .AddedToFeeCredit =>
274275 log.info(" received extra payment for on-the-fly funding that was added to fee credit (payment_hash={}, amount={})" , cmd.paymentHash, cmd.amount)
275- val proposal = OnTheFlyFunding .Proposal (htlc, cmd.upstream)
276+ val proposal = OnTheFlyFunding .Proposal (htlc, cmd.upstream, cmd.onionSharedSecrets )
276277 proposal.createFulfillCommands(status.preimage).foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
277278 pending.copy(proposed = pending.proposed :+ proposal)
278279 case status : OnTheFlyFunding .Status .Funded =>
279280 log.info(" rejecting extra payment for on-the-fly funding that has already been funded with txId={} (payment_hash={}, amount={})" , status.txId, cmd.paymentHash, cmd.amount)
280281 // The payer is buggy and is paying the same payment_hash multiple times. We could simply claim that
281282 // extra payment for ourselves, but we're nice and instead immediately fail it.
282- val proposal = OnTheFlyFunding .Proposal (htlc, cmd.upstream)
283- proposal.createFailureCommands(None ).foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
283+ val proposal = OnTheFlyFunding .Proposal (htlc, cmd.upstream, cmd.onionSharedSecrets )
284+ proposal.createFailureCommands(None )(log) .foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
284285 pending
285286 }
286287 case None =>
287288 self ! Peer .OutgoingMessage (htlc, d.peerConnection)
288289 Metrics .OnTheFlyFunding .withTag(Tags .OnTheFlyFundingState , Tags .OnTheFlyFundingStates .Proposed ).increment()
289290 val timer = context.system.scheduler.scheduleOnce(nodeParams.onTheFlyFundingConfig.proposalTimeout, self, OnTheFlyFundingTimeout (cmd.paymentHash))(context.dispatcher)
290- OnTheFlyFunding .Pending (Seq (OnTheFlyFunding .Proposal (htlc, cmd.upstream)), OnTheFlyFunding .Status .Proposed (timer))
291+ OnTheFlyFunding .Pending (Seq (OnTheFlyFunding .Proposal (htlc, cmd.upstream, cmd.onionSharedSecrets )), OnTheFlyFunding .Status .Proposed (timer))
291292 }
292293 pendingOnTheFlyFunding += (htlc.paymentHash -> pending)
293294 stay()
@@ -303,7 +304,7 @@ class Peer(val nodeParams: NodeParams,
303304 case msg : WillFailHtlc => FailureReason .EncryptedDownstreamFailure (msg.reason)
304305 case msg : WillFailMalformedHtlc => FailureReason .LocalFailure (createBadOnionFailure(msg.onionHash, msg.failureCode))
305306 }
306- htlc.createFailureCommands(Some (failure)).foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
307+ htlc.createFailureCommands(Some (failure))(log) .foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
307308 val proposed1 = pending.proposed.filterNot(_.htlc.id == msg.id)
308309 if (proposed1.isEmpty) {
309310 Metrics .OnTheFlyFunding .withTag(Tags .OnTheFlyFundingState , Tags .OnTheFlyFundingStates .Rejected ).increment()
@@ -335,7 +336,7 @@ class Peer(val nodeParams: NodeParams,
335336 pending.status match {
336337 case _ : OnTheFlyFunding .Status .Proposed =>
337338 log.warning(" on-the-fly funding proposal timed out for payment_hash={}" , timeout.paymentHash)
338- pending.createFailureCommands().foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
339+ pending.createFailureCommands(log ).foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
339340 Metrics .OnTheFlyFunding .withTag(Tags .OnTheFlyFundingState , Tags .OnTheFlyFundingStates .Expired ).increment()
340341 pendingOnTheFlyFunding -= timeout.paymentHash
341342 self ! Peer .OutgoingMessage (Warning (s " on-the-fly funding proposal timed out for payment_hash= ${timeout.paymentHash}" ), d.peerConnection)
@@ -584,14 +585,14 @@ class Peer(val nodeParams: NodeParams,
584585 case _ : OnTheFlyFunding .Status .Proposed =>
585586 log.warning(" proposed will_add_htlc expired for payment_hash={}" , paymentHash)
586587 Metrics .OnTheFlyFunding .withTag(Tags .OnTheFlyFundingState , Tags .OnTheFlyFundingStates .Timeout ).increment()
587- pending.createFailureCommands().foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
588+ pending.createFailureCommands(log ).foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
588589 case _ : OnTheFlyFunding .Status .AddedToFeeCredit =>
589590 // Nothing to do, we already fulfilled the upstream HTLCs.
590591 log.debug(" forgetting will_add_htlc added to fee credit for payment_hash={}" , paymentHash)
591592 case _ : OnTheFlyFunding .Status .Funded =>
592593 log.warning(" funded will_add_htlc expired for payment_hash={}, our peer may be malicious" , paymentHash)
593594 Metrics .OnTheFlyFunding .withTag(Tags .OnTheFlyFundingState , Tags .OnTheFlyFundingStates .Timeout ).increment()
594- pending.createFailureCommands().foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
595+ pending.createFailureCommands(log ).foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
595596 nodeParams.db.liquidity.removePendingOnTheFlyFunding(remoteNodeId, paymentHash)
596597 }
597598 }
@@ -675,7 +676,7 @@ class Peer(val nodeParams: NodeParams,
675676 // We emit a relay event: since we waited for on-chain funding before relaying the payment, the timestamps
676677 // won't be accurate, but everything else is.
677678 pending.proposed.foreach {
678- case OnTheFlyFunding .Proposal (htlc, upstream) => upstream match {
679+ case OnTheFlyFunding .Proposal (htlc, upstream, _ ) => upstream match {
679680 case _ : Upstream .Local => ()
680681 case u : Upstream .Hot .Channel =>
681682 val incoming = PaymentRelayed .IncomingPart (u.add.amountMsat, u.add.channelId, u.receivedAt)
@@ -810,7 +811,7 @@ class Peer(val nodeParams: NodeParams,
810811 case status : OnTheFlyFunding .Status .Proposed =>
811812 log.info(" cancelling on-the-fly funding for payment_hash={}" , paymentHash)
812813 status.timer.cancel()
813- pending.createFailureCommands().foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
814+ pending.createFailureCommands(log ).foreach { case (channelId, cmd) => PendingCommandsDb .safeSend(register, nodeParams.db.pendingCommands, channelId, cmd) }
814815 true
815816 // We keep proposals that have been added to fee credit until we reach the HTLC expiry or we restart. This
816817 // guarantees that our peer cannot concurrently add to their fee credit a payment for which we've signed a
@@ -983,7 +984,7 @@ object Peer {
983984 case class SpawnChannelNonInitiator (open : Either [protocol.OpenChannel , protocol.OpenDualFundedChannel ], channelConfig : ChannelConfig , channelType : SupportedChannelType , addFunding_opt : Option [LiquidityAds .AddFunding ], localParams : LocalParams , peerConnection : ActorRef )
984985
985986 /** If [[Features.OnTheFlyFunding ]] is supported and we're connected, relay a funding proposal to our peer. */
986- case class ProposeOnTheFlyFunding (replyTo : typed.ActorRef [ProposeOnTheFlyFundingResponse ], amount : MilliSatoshi , paymentHash : ByteVector32 , expiry : CltvExpiry , onion : OnionRoutingPacket , nextPathKey_opt : Option [PublicKey ], upstream : Upstream .Hot )
987+ case class ProposeOnTheFlyFunding (replyTo : typed.ActorRef [ProposeOnTheFlyFundingResponse ], amount : MilliSatoshi , paymentHash : ByteVector32 , expiry : CltvExpiry , onion : OnionRoutingPacket , onionSharedSecrets : Seq [ Sphinx . SharedSecret ], nextPathKey_opt : Option [PublicKey ], upstream : Upstream .Hot )
987988
988989 sealed trait ProposeOnTheFlyFundingResponse
989990 object ProposeOnTheFlyFundingResponse {
0 commit comments