Pass context into held_htlc_available message handling.

Useful for using the payment_id within to look up the corresponding outbound
async payment so we know we can safely release the HTLCs to the now-onlinen
recipient.
This commit is contained in:
Valentine Wallace 2024-07-10 13:58:53 -04:00
parent a3216acb7d
commit e162278bc8
No known key found for this signature in database
GPG key ID: FD3E106A2CE099B4
6 changed files with 21 additions and 10 deletions

View file

@ -5,7 +5,9 @@ use bitcoin::secp256k1::ecdsa::RecoverableSignature;
use bitcoin::secp256k1::schnorr;
use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
use lightning::blinded_path::message::{BlindedMessagePath, MessageContext, OffersContext};
use lightning::blinded_path::message::{
AsyncPaymentsContext, BlindedMessagePath, MessageContext, OffersContext,
};
use lightning::blinded_path::EmptyNodeIdLookUp;
use lightning::ln::features::InitFeatures;
use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler};
@ -129,7 +131,7 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
responder.respond(),
))
}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
}
#[derive(Debug)]

View file

@ -33,7 +33,7 @@ use bitcoin::secp256k1::Secp256k1;
use bitcoin::{secp256k1, Sequence};
use crate::events::FundingInfo;
use crate::blinded_path::message::{MessageContext, OffersContext};
use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext};
use crate::blinded_path::NodeIdLookUp;
use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode};
use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
@ -11094,7 +11094,7 @@ where
None
}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> {
Vec::new()

View file

@ -18,7 +18,7 @@
use bitcoin::constants::ChainHash;
use bitcoin::secp256k1::{self, Secp256k1, SecretKey, PublicKey};
use crate::blinded_path::message::OffersContext;
use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext};
use crate::sign::{NodeSigner, Recipient};
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
use crate::ln::types::ChannelId;
@ -152,7 +152,7 @@ impl AsyncPaymentsMessageHandler for IgnoringMessageHandler {
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
None
}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
}
impl CustomOnionMessageHandler for IgnoringMessageHandler {
type CustomMessage = Infallible;

View file

@ -9,6 +9,7 @@
//! Message handling for async payments.
use crate::blinded_path::message::AsyncPaymentsContext;
use crate::io;
use crate::ln::msgs::DecodeError;
use crate::onion_message::messenger::{MessageSendInstructions, Responder, ResponseInstruction};
@ -32,7 +33,7 @@ pub trait AsyncPaymentsMessageHandler {
/// Handle a [`ReleaseHeldHtlc`] message. If authentication of the message succeeds, an HTLC
/// should be released to the corresponding payee.
fn release_held_htlc(&self, message: ReleaseHeldHtlc);
fn release_held_htlc(&self, message: ReleaseHeldHtlc, context: AsyncPaymentsContext);
/// Release any [`AsyncPaymentsMessage`]s that need to be sent.
///

View file

@ -10,7 +10,7 @@
//! Onion message testing and test utilities live here.
use crate::blinded_path::EmptyNodeIdLookUp;
use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext, OffersContext};
use crate::blinded_path::message::{AsyncPaymentsContext, BlindedMessagePath, MessageForwardNode, MessageContext, OffersContext};
use crate::events::{Event, EventsProvider};
use crate::ln::features::{ChannelFeatures, InitFeatures};
use crate::ln::msgs::{self, DecodeError, OnionMessageHandler};
@ -87,7 +87,7 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
None
}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
}
#[derive(Clone, Debug, PartialEq)]

View file

@ -1612,7 +1612,15 @@ where
},
#[cfg(async_payments)]
ParsedOnionMessageContents::AsyncPayments(AsyncPaymentsMessage::ReleaseHeldHtlc(msg)) => {
self.async_payments_handler.release_held_htlc(msg);
let context = match context {
Some(MessageContext::AsyncPayments(context)) => context,
Some(_) => {
debug_assert!(false, "Checked in peel_onion_message");
return
},
None => return,
};
self.async_payments_handler.release_held_htlc(msg, context);
},
ParsedOnionMessageContents::Custom(msg) => {
let context = match context {