Skip to content

Commit de3784e

Browse files
Release async payment HTLCs held upstream via OM
If we receive a message that an HTLC is being held upstream for us, send a reply onion message back releasing it since we are online to receive the corresponding payment.
1 parent a8da2a7 commit de3784e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12184,7 +12184,20 @@ where
1218412184
&self, _message: HeldHtlcAvailable, _context: AsyncPaymentsContext,
1218512185
_responder: Option<Responder>
1218612186
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
12187-
None
12187+
#[cfg(async_payments)] {
12188+
match _context {
12189+
AsyncPaymentsContext::InboundPayment { nonce, hmac, path_absolute_expiry } => {
12190+
if let Err(()) = signer::verify_held_htlc_available_context(
12191+
nonce, hmac, &self.inbound_payment_key
12192+
) { return None }
12193+
if self.duration_since_epoch() > path_absolute_expiry { return None }
12194+
},
12195+
_ => return None
12196+
}
12197+
return _responder.map(|responder| (ReleaseHeldHtlc {}, responder.respond()))
12198+
}
12199+
#[cfg(not(async_payments))]
12200+
return None
1218812201
}
1218912202

1219012203
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {

lightning/src/offers/signer.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,10 @@ pub(crate) fn hmac_for_held_htlc_available_context(
501501

502502
Hmac::from_engine(hmac)
503503
}
504+
505+
#[cfg(async_payments)]
506+
pub(crate) fn verify_held_htlc_available_context(
507+
nonce: Nonce, hmac: Hmac<Sha256>, expanded_key: &ExpandedKey,
508+
) -> Result<(), ()> {
509+
if hmac_for_held_htlc_available_context(nonce, expanded_key) == hmac { Ok(()) } else { Err(()) }
510+
}

0 commit comments

Comments
 (0)