@@ -70,6 +70,7 @@ use crate::ln::onion_utils::{
70
70
use crate::ln::script::{self, ShutdownScript};
71
71
use crate::ln::types::ChannelId;
72
72
use crate::ln::LN_MAX_MSG_LEN;
73
+ use crate::offers::static_invoice::StaticInvoice;
73
74
use crate::routing::gossip::NodeId;
74
75
use crate::sign::ecdsa::EcdsaChannelSigner;
75
76
use crate::sign::tx_builder::{HTLCAmountDirection, NextCommitmentStats, SpecTxBuilder, TxBuilder};
@@ -8184,10 +8185,25 @@ where
8184
8185
/// waiting on this revoke_and_ack. The generation of this new commitment_signed may also fail,
8185
8186
/// generating an appropriate error *after* the channel state has been updated based on the
8186
8187
/// 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
8187
8196
pub fn revoke_and_ack<F: Deref, L: Deref>(
8188
8197
&mut self, msg: &msgs::RevokeAndACK, fee_estimator: &LowerBoundedFeeEstimator<F>,
8189
8198
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
+ >
8191
8207
where
8192
8208
F::Target: FeeEstimator,
8193
8209
L::Target: Logger,
@@ -8302,6 +8318,7 @@ where
8302
8318
let mut finalized_claimed_htlcs = Vec::new();
8303
8319
let mut update_fail_htlcs = Vec::new();
8304
8320
let mut update_fail_malformed_htlcs = Vec::new();
8321
+ let mut static_invoices = Vec::new();
8305
8322
let mut require_commitment = false;
8306
8323
let mut value_to_self_msat_diff: i64 = 0;
8307
8324
@@ -8417,6 +8434,24 @@ where
8417
8434
}
8418
8435
}
8419
8436
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
+ }
8420
8455
if let OutboundHTLCState::LocalAnnounced(_) = htlc.state {
8421
8456
log_trace!(
8422
8457
logger,
@@ -8484,9 +8519,9 @@ where
8484
8519
self.context
8485
8520
.blocked_monitor_updates
8486
8521
.push(PendingChannelMonitorUpdate { update: monitor_update });
8487
- return Ok(($htlcs_to_fail, None));
8522
+ return Ok(($htlcs_to_fail, static_invoices, None));
8488
8523
} else {
8489
- return Ok(($htlcs_to_fail, Some(monitor_update)));
8524
+ return Ok(($htlcs_to_fail, static_invoices, Some(monitor_update)));
8490
8525
}
8491
8526
};
8492
8527
}
0 commit comments