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

Add static invoice creation utils to ChannelManager #3408

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9612,6 +9612,7 @@ where
let retryable_invoice_request = RetryableInvoiceRequest {
invoice_request: invoice_request.clone(),
nonce,
needs_retry: true,
};
self.pending_outbound_payments
.add_new_awaiting_invoice(
Expand Down Expand Up @@ -11452,7 +11453,7 @@ where
.pending_outbound_payments
.release_invoice_requests_awaiting_invoice()
{
let RetryableInvoiceRequest { invoice_request, nonce } = retryable_invoice_request;
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
let hmac = payment_id.hmac_for_offer_payment(nonce, &self.inbound_payment_key);
let context = MessageContext::Offers(OffersContext::OutboundPayment {
payment_id,
Expand Down Expand Up @@ -11787,6 +11788,7 @@ where
let retryable_invoice_request = RetryableInvoiceRequest {
invoice_request: invoice_request.clone(),
nonce,
needs_retry: true,
};
self.pending_outbound_payments
.received_offer(payment_id, Some(retryable_invoice_request))
Expand Down
19 changes: 14 additions & 5 deletions lightning/src/ln/outbound_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,16 @@ pub(crate) enum PendingOutboundPayment {
},
}

#[derive(Clone)]
pub(crate) struct RetryableInvoiceRequest {
pub(crate) invoice_request: InvoiceRequest,
pub(crate) nonce: Nonce,
pub(super) needs_retry: bool,
}
Comment on lines 138 to 142
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth not holding on to these for offers that don't support async payments? Can't recall if we can tell from the offer or if it isn't known until the static invoice is received.

Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC there is nothing in the offers, just at the invoice request level.


impl_writeable_tlv_based!(RetryableInvoiceRequest, {
(0, invoice_request, required),
(1, needs_retry, (default_value, true)),
(2, nonce, required),
});

Expand Down Expand Up @@ -746,7 +749,12 @@ pub(super) struct OutboundPayments {
impl OutboundPayments {
pub(super) fn new(pending_outbound_payments: HashMap<PaymentId, PendingOutboundPayment>) -> Self {
let has_invoice_requests = pending_outbound_payments.values().any(|payment| {
matches!(payment, PendingOutboundPayment::AwaitingInvoice { retryable_invoice_request: Some(_), .. })
matches!(
payment,
PendingOutboundPayment::AwaitingInvoice {
retryable_invoice_request: Some(invreq), ..
} if invreq.needs_retry
)
});

Self {
Expand Down Expand Up @@ -2217,11 +2225,12 @@ impl OutboundPayments {
.iter_mut()
.filter_map(|(payment_id, payment)| {
if let PendingOutboundPayment::AwaitingInvoice {
retryable_invoice_request, ..
retryable_invoice_request: Some(invreq), ..
} = payment {
retryable_invoice_request.take().map(|retryable_invoice_request| {
(*payment_id, retryable_invoice_request)
})
if invreq.needs_retry {
invreq.needs_retry = false;
Some((*payment_id, invreq.clone()))
} else { None }
} else {
None
}
Expand Down