@@ -70,6 +70,7 @@ use crate::ln::onion_utils::{
7070use crate::ln::script::{self, ShutdownScript};
7171use crate::ln::types::ChannelId;
7272use crate::ln::LN_MAX_MSG_LEN;
73+ use crate::offers::static_invoice::StaticInvoice;
7374use crate::routing::gossip::NodeId;
7475use crate::sign::ecdsa::EcdsaChannelSigner;
7576use crate::sign::tx_builder::{HTLCAmountDirection, NextCommitmentStats, SpecTxBuilder, TxBuilder};
@@ -8184,10 +8185,25 @@ where
81848185 /// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
81858186 /// generating an appropriate error *after* the channel state has been updated based on the
81868187 /// revoke_and_ack message.
8188+ ///
8189+ /// The static invoices will be used by us as an async sender to enqueue [`HeldHtlcAvailable`]
8190+ /// onion messages for the often-offline recipient, and the blinded reply paths the invoices are
8191+ /// paired with were created by our channel counterparty and will be used as reply paths for
8192+ /// corresponding [`ReleaseHeldHtlc`] messages.
8193+ ///
8194+ /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
8195+ /// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
81878196 pub fn revoke_and_ack<F: Deref, L: Deref>(
81888197 &mut self, msg: &msgs::RevokeAndACK, fee_estimator: &LowerBoundedFeeEstimator<F>,
81898198 logger: &L, hold_mon_update: bool,
8190- ) -> Result<(Vec<(HTLCSource, PaymentHash)>, Option<ChannelMonitorUpdate>), ChannelError>
8199+ ) -> Result<
8200+ (
8201+ Vec<(HTLCSource, PaymentHash)>,
8202+ Vec<(StaticInvoice, BlindedMessagePath)>,
8203+ Option<ChannelMonitorUpdate>,
8204+ ),
8205+ ChannelError,
8206+ >
81918207 where
81928208 F::Target: FeeEstimator,
81938209 L::Target: Logger,
@@ -8302,6 +8318,7 @@ where
83028318 let mut finalized_claimed_htlcs = Vec::new();
83038319 let mut update_fail_htlcs = Vec::new();
83048320 let mut update_fail_malformed_htlcs = Vec::new();
8321+ let mut static_invoices = Vec::new();
83058322 let mut require_commitment = false;
83068323 let mut value_to_self_msat_diff: i64 = 0;
83078324
@@ -8417,6 +8434,24 @@ where
84178434 }
84188435 }
84198436 for htlc in pending_outbound_htlcs.iter_mut() {
8437+ for (htlc_id, blinded_path) in &msg.release_htlc_message_paths {
8438+ if htlc.htlc_id != *htlc_id {
8439+ continue;
8440+ }
8441+ let static_invoice = match htlc.source.static_invoice() {
8442+ Some(inv) if htlc.hold_htlc.is_some() => inv,
8443+ _ => {
8444+ // We should only be using our counterparty's release_htlc_message_path if we
8445+ // originally configured the HTLC to be held with them until the recipient comes
8446+ // online. Otherwise, our counterparty could include paths for all of our HTLCs and
8447+ // use the responses sent to their paths to determine which of our HTLCs are async
8448+ // payments.
8449+ log_trace!(logger, "Counterparty included release_htlc_message_path for non-async payment HTLC {}", htlc_id);
8450+ continue;
8451+ },
8452+ };
8453+ static_invoices.push((static_invoice, blinded_path.clone()));
8454+ }
84208455 if let OutboundHTLCState::LocalAnnounced(_) = htlc.state {
84218456 log_trace!(
84228457 logger,
@@ -8484,9 +8519,9 @@ where
84848519 self.context
84858520 .blocked_monitor_updates
84868521 .push(PendingChannelMonitorUpdate { update: monitor_update });
8487- return Ok(($htlcs_to_fail, None));
8522+ return Ok(($htlcs_to_fail, static_invoices, None));
84888523 } else {
8489- return Ok(($htlcs_to_fail, Some(monitor_update)));
8524+ return Ok(($htlcs_to_fail, static_invoices, Some(monitor_update)));
84908525 }
84918526 };
84928527 }
0 commit comments