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
Changes from 1 commit
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
83 changes: 33 additions & 50 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10943,6 +10943,35 @@ where
let secp_ctx = &self.secp_ctx;
let expanded_key = &self.inbound_payment_key;

macro_rules! handle_pay_invoice_res {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this a separate commit? Why not just squash the macro into the previous commit instead of having non-DRY code at all?

($res: expr, $invoice: expr, $logger: expr) => {{
let error = match $res {
Err(Bolt12PaymentError::UnknownRequiredFeatures) => {
log_trace!(
$logger, "Invoice requires unknown features: {:?}",
$invoice.invoice_features()
);
InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures)
},
Err(Bolt12PaymentError::SendingFailed(e)) => {
log_trace!($logger, "Failed paying invoice: {:?}", e);
InvoiceError::from_string(format!("{:?}", e))
},
Err(Bolt12PaymentError::UnexpectedInvoice)
| Err(Bolt12PaymentError::DuplicateInvoice)
| Ok(()) => return None,
};

match responder {
Some(responder) => return Some((OffersMessage::InvoiceError(error), responder.respond())),
None => {
log_trace!($logger, "No reply path to send error: {:?}", error);
return None
},
}
}}
}

match message {
OffersMessage::InvoiceRequest(invoice_request) => {
let responder = match responder {
Expand Down Expand Up @@ -11069,32 +11098,8 @@ where
return None;
}

let error = match self.send_payment_for_verified_bolt12_invoice(
&invoice, payment_id,
) {
Err(Bolt12PaymentError::UnknownRequiredFeatures) => {
log_trace!(
logger, "Invoice requires unknown features: {:?}",
invoice.invoice_features()
);
InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures)
},
Err(Bolt12PaymentError::SendingFailed(e)) => {
log_trace!(logger, "Failed paying invoice: {:?}", e);
InvoiceError::from_string(format!("{:?}", e))
},
Err(Bolt12PaymentError::UnexpectedInvoice)
| Err(Bolt12PaymentError::DuplicateInvoice)
| Ok(()) => return None,
};

match responder {
Some(responder) => Some((OffersMessage::InvoiceError(error), responder.respond())),
None => {
log_trace!(logger, "No reply path to send error: {:?}", error);
None
},
}
let res = self.send_payment_for_verified_bolt12_invoice(&invoice, payment_id);
handle_pay_invoice_res!(res, invoice, logger);
},
#[cfg(async_payments)]
OffersMessage::StaticInvoice(invoice) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we need to support manually_handle_bolt12_invoices here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is gonna take some extra work because Event::InvoiceReceived currently contains a Bolt12Invoice (i.e. not a static invoice), tracking this on #2298.

Expand All @@ -11107,30 +11112,8 @@ where
},
_ => return None
};
// TODO: DRY this with the above regular invoice error handling
let error = match self.initiate_async_payment(&invoice, payment_id) {
Err(Bolt12PaymentError::UnknownRequiredFeatures) => {
log_trace!(
self.logger, "Invoice requires unknown features: {:?}",
invoice.invoice_features()
);
InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures)
},
Err(Bolt12PaymentError::SendingFailed(e)) => {
log_trace!(self.logger, "Failed paying invoice: {:?}", e);
InvoiceError::from_string(format!("{:?}", e))
},
Err(Bolt12PaymentError::UnexpectedInvoice)
| Err(Bolt12PaymentError::DuplicateInvoice)
| Ok(()) => return None,
};
match responder {
Some(responder) => Some((OffersMessage::InvoiceError(error), responder.respond())),
None => {
log_trace!(self.logger, "No reply path to send error: {:?}", error);
None
},
}
let res = self.initiate_async_payment(&invoice, payment_id);
handle_pay_invoice_res!(res, invoice, self.logger);
},
OffersMessage::InvoiceError(invoice_error) => {
let payment_hash = match context {
Expand Down