Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support paying static invoices #3140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
732ee14
Tweak debug_assert message for parsed onion messages.
valentinewallace Jul 12, 2024
a3216ac
Add MessageContext for async payments.
valentinewallace Jul 10, 2024
e162278
Pass context into held_htlc_available message handling.
valentinewallace Jul 10, 2024
3d5d64a
Store AsyncPaymentsMessages for later sending
valentinewallace Jun 13, 2024
cff6e34
Support checking that a static invoice matches an outbound invreq.
valentinewallace Jun 13, 2024
ad63a70
Support creating PaymentParameters from static invoices.
valentinewallace Jun 13, 2024
c3ed4a2
Store async payment data in PendingOutboundPayment.
valentinewallace Jul 10, 2024
7fb16ea
Pass full message context into ChanMan blinded path util.
valentinewallace Jul 10, 2024
c976e4c
Release pending async payments to PeerManager.
valentinewallace Aug 29, 2024
b6f4479
Support initiating an async payment to a static invoice.
valentinewallace Aug 29, 2024
28269a7
DRY handling when initiating payment to BOLT 12 invoice.
valentinewallace Aug 29, 2024
e4d7681
Error on static invoice with unknown required features.
valentinewallace Aug 29, 2024
8569830
Set max path len on receipt of static invoice.
valentinewallace Aug 29, 2024
69356e7
Split off send_payment_for_bolt12_invoice_internal util.
valentinewallace Sep 4, 2024
0297a1e
Support sending async payments as an always-online sender.
valentinewallace Sep 4, 2024
985e6ac
Timeout expired outbound async payments.
valentinewallace Jun 20, 2024
6d415b1
Support abandoning pending outbound async payments.
valentinewallace Jun 20, 2024
7dd1787
Correct docs on payment id in RecentPaymentDetails.
valentinewallace Aug 20, 2024
c4f3e25
Don't trigger manager persistence on unexpected release_htlc message.
valentinewallace Aug 29, 2024
5a7f523
Rename Payment{Hash,Id} hmac creation/verification methods for offers.
valentinewallace Sep 5, 2024
615eefb
Verify inbound ReleaseHeldHtlc messages via hmac.
valentinewallace Sep 5, 2024
26d1582
Add new Bolt12PaymentError for failed blinded path creation.
valentinewallace Sep 6, 2024
4bcf53e
Document PendingOutboundPayment::{Static}InvoiceReceived semantics.
valentinewallace Sep 10, 2024
6e27aec
Remove payment_release_secret from async payments messages.
valentinewallace Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -124,12 +126,9 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
Some(resp) => resp,
None => return None,
};
Some((
ReleaseHeldHtlc { payment_release_secret: message.payment_release_secret },
responder.respond(),
))
Some((ReleaseHeldHtlc {}, responder.respond()))
}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
}

#[derive(Debug)]
Expand Down
44 changes: 44 additions & 0 deletions lightning/src/blinded_path/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ pub enum MessageContext {
///
/// [`OffersMessage`]: crate::onion_message::offers::OffersMessage
Offers(OffersContext),
/// Context specific to an [`AsyncPaymentsMessage`].
///
/// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage
AsyncPayments(AsyncPaymentsContext),
/// Context specific to a [`CustomOnionMessageHandler::CustomMessage`].
///
/// [`CustomOnionMessageHandler::CustomMessage`]: crate::onion_message::messenger::CustomOnionMessageHandler::CustomMessage
Expand Down Expand Up @@ -363,9 +367,41 @@ pub enum OffersContext {
},
}

/// Contains data specific to an [`AsyncPaymentsMessage`].
///
/// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage
#[derive(Clone, Debug)]
pub enum AsyncPaymentsContext {
/// Context contained within the reply [`BlindedMessagePath`] we put in outbound
/// [`HeldHtlcAvailable`] messages, provided back to us in corresponding [`ReleaseHeldHtlc`]
/// messages.
///
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
OutboundPayment {
/// ID used when payment to the originating [`Offer`] was initiated. Useful for us to identify
/// which of our pending outbound payments should be released to its often-offline payee.
///
/// [`Offer`]: crate::offers::offer::Offer
payment_id: PaymentId,
/// A nonce used for authenticating that a [`ReleaseHeldHtlc`] message is valid for a preceding
/// [`HeldHtlcAvailable`] message.
///
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
nonce: Nonce,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't have commits that rewrite things done earlier in the same PR.

/// Authentication code for the [`PaymentId`].
///
/// Prevents the recipient from being able to deanonymize us by creating a blinded path to us
/// containing the expected [`PaymentId`].
hmac: Hmac<Sha256>,
},
}

impl_writeable_tlv_based_enum!(MessageContext,
{0, Offers} => (),
{1, Custom} => (),
{2, AsyncPayments} => (),
);

impl_writeable_tlv_based_enum!(OffersContext,
Expand All @@ -384,6 +420,14 @@ impl_writeable_tlv_based_enum!(OffersContext,
},
);

impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
(0, OutboundPayment) => {
(0, payment_id, required),
(2, nonce, required),
(4, hmac, required),
},
);

/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
secp_ctx: &Secp256k1<T>, intermediate_nodes: &[MessageForwardNode],
Expand Down
Loading
Loading