Skip to content

Commit

Permalink
Prefix AsyncPaymentsMessageHandler methods with handle_*
Browse files Browse the repository at this point in the history
"Release" is overloaded in the trait's release_pending_messages method, since
the latter releases pending async payments onion messages to the peer manager,
vs the release_held_htlc method handles the release_held_htlc onion message by
attempting to send an HTLC to the recipient.
  • Loading branch information
valentinewallace committed Sep 18, 2024
1 parent bf4528b commit 1350979
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl OffersMessageHandler for TestOffersMessageHandler {
struct TestAsyncPaymentsMessageHandler {}

impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
fn held_htlc_available(
fn handle_held_htlc_available(
&self, _message: HeldHtlcAvailable, responder: Option<Responder>,
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
let responder = match responder {
Expand All @@ -128,7 +128,7 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
};
Some((ReleaseHeldHtlc {}, responder.respond()))
}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
}

#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11226,13 +11226,13 @@ where
R::Target: Router,
L::Target: Logger,
{
fn held_htlc_available(
fn handle_held_htlc_available(
&self, _message: HeldHtlcAvailable, _responder: Option<Responder>
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
None
}

fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {
#[cfg(async_payments)] {
let AsyncPaymentsContext::OutboundPayment { payment_id, hmac, nonce } = _context;
if payment_id.verify_for_async_payment(hmac, nonce, &self.inbound_payment_key).is_err() { return }
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ impl OffersMessageHandler for IgnoringMessageHandler {
}
}
impl AsyncPaymentsMessageHandler for IgnoringMessageHandler {
fn held_htlc_available(
fn handle_held_htlc_available(
&self, _message: HeldHtlcAvailable, _responder: Option<Responder>,
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
None
}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
}
impl CustomOnionMessageHandler for IgnoringMessageHandler {
type CustomMessage = Infallible;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/onion_message/async_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const RELEASE_HELD_HTLC_TLV_TYPE: u64 = 74;
pub trait AsyncPaymentsMessageHandler {
/// Handle a [`HeldHtlcAvailable`] message. A [`ReleaseHeldHtlc`] should be returned to release
/// the held funds.
fn held_htlc_available(
fn handle_held_htlc_available(
&self, message: HeldHtlcAvailable, responder: Option<Responder>,
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)>;

/// 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, context: AsyncPaymentsContext);
fn handle_release_held_htlc(&self, message: ReleaseHeldHtlc, context: AsyncPaymentsContext);

/// Release any [`AsyncPaymentsMessage`]s that need to be sent.
///
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/onion_message/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ impl OffersMessageHandler for TestOffersMessageHandler {
struct TestAsyncPaymentsMessageHandler {}

impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
fn held_htlc_available(
fn handle_held_htlc_available(
&self, _message: HeldHtlcAvailable, _responder: Option<Responder>,
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
None
}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
}

#[derive(Clone, Debug, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/onion_message/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ where
},
#[cfg(async_payments)]
ParsedOnionMessageContents::AsyncPayments(AsyncPaymentsMessage::HeldHtlcAvailable(msg)) => {
let response_instructions = self.async_payments_handler.held_htlc_available(
let response_instructions = self.async_payments_handler.handle_held_htlc_available(
msg, responder
);
if let Some((msg, instructions)) = response_instructions {
Expand All @@ -1620,7 +1620,7 @@ where
},
None => return,
};
self.async_payments_handler.release_held_htlc(msg, context);
self.async_payments_handler.handle_release_held_htlc(msg, context);
},
ParsedOnionMessageContents::Custom(msg) => {
let context = match context {
Expand Down

0 comments on commit 1350979

Please sign in to comment.