Skip to content

Commit 5ebdd17

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 1daabbf commit 5ebdd17

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
@@ -12210,7 +12210,20 @@ where
1221012210
&self, _message: HeldHtlcAvailable, _context: AsyncPaymentsContext,
1221112211
_responder: Option<Responder>
1221212212
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
12213-
None
12213+
#[cfg(async_payments)] {
12214+
match _context {
12215+
AsyncPaymentsContext::InboundPayment { nonce, hmac, path_absolute_expiry } => {
12216+
if let Err(()) = signer::verify_held_htlc_available_context(
12217+
nonce, hmac, &self.inbound_payment_key
12218+
) { return None }
12219+
if self.duration_since_epoch() > path_absolute_expiry { return None }
12220+
},
12221+
_ => return None
12222+
}
12223+
return _responder.map(|responder| (ReleaseHeldHtlc {}, responder.respond()))
12224+
}
12225+
#[cfg(not(async_payments))]
12226+
return None
1221412227
}
1221512228

1221612229
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)