Skip to content

Commit 2abd889

Browse files
Remove now-unused ServeStaticInv::inv_slot from OM
In the initially-merged version of the static invoice server protocol, the static invoice server would sometimes have to find a specific static invoice based on (recipient_id, invoice_slot) and sometime based on (recipient_id, invoice_id). This made the API harder to use in terms of how the server would index into the KVStore. We'd like to transition to the server always finding a specific invoice based on (recipient_id, invoice_slot) and get rid of the invoice_id concept. In the previous commit the server began including the invoice_slot in the ServeStaticInvoice blinded path context that gets provided back to themselves. Therefore there is no need for the recipient to redundantly include it in the ServeStaticInvoice onion message itself.
1 parent dbe3514 commit 2abd889

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

lightning/src/offers/async_receive_offer_cache.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,13 @@ impl AsyncReceiveOfferCache {
337337

338338
/// If we have any empty slots in the cache or offers that can and should be replaced with a fresh
339339
/// offer, here we return the index of the slot that needs a new offer. The index is used for
340-
/// setting [`ServeStaticInvoice::invoice_slot`] when sending the corresponding new static invoice
341-
/// to the server, so the server knows which existing persisted invoice is being replaced, if any.
340+
/// setting [`OfferPathsRequest::invoice_slot`] when requesting offer paths from the server, so
341+
/// the server can include the slot in the offer paths and reply paths that they create in
342+
/// response.
342343
///
343344
/// Returns `None` if the cache is full and no offers can currently be replaced.
344345
///
345-
/// [`ServeStaticInvoice::invoice_slot`]: crate::onion_message::async_payments::ServeStaticInvoice::invoice_slot
346+
/// [`OfferPathsRequest::invoice_slot`]: crate::onion_message::async_payments::OfferPathsRequest::invoice_slot
346347
fn needs_new_offer_idx(&self, duration_since_epoch: Duration) -> Option<usize> {
347348
// If we have any empty offer slots, return the first one we find
348349
let empty_slot_idx_opt = self.offers.iter().position(|offer_opt| offer_opt.is_none());
@@ -411,10 +412,10 @@ impl AsyncReceiveOfferCache {
411412
/// the static invoice server.
412413
pub(super) fn offers_needing_invoice_refresh(
413414
&self, duration_since_epoch: Duration,
414-
) -> impl Iterator<Item = (&Offer, Nonce, u16, &Responder)> {
415+
) -> impl Iterator<Item = (&Offer, Nonce, &Responder)> {
415416
// For any offers which are either in use or pending confirmation by the server, we should send
416417
// them a fresh invoice on each timer tick.
417-
self.offers_with_idx().filter_map(move |(idx, offer)| {
418+
self.offers_with_idx().filter_map(move |(_, offer)| {
418419
let needs_invoice_update = match offer.status {
419420
OfferStatus::Used { invoice_created_at } => {
420421
invoice_created_at.saturating_add(INVOICE_REFRESH_THRESHOLD)
@@ -426,13 +427,7 @@ impl AsyncReceiveOfferCache {
426427
OfferStatus::Ready { .. } => false,
427428
};
428429
if needs_invoice_update {
429-
let offer_slot = idx.try_into().unwrap_or(u16::MAX);
430-
Some((
431-
&offer.offer,
432-
offer.offer_nonce,
433-
offer_slot,
434-
&offer.update_static_invoice_path,
435-
))
430+
Some((&offer.offer, offer.offer_nonce, &offer.update_static_invoice_path))
436431
} else {
437432
None
438433
}

lightning/src/offers/flow.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,8 +1317,7 @@ where
13171317
let duration_since_epoch = self.duration_since_epoch();
13181318
let cache = self.async_receive_offer_cache.lock().unwrap();
13191319
for offer_and_metadata in cache.offers_needing_invoice_refresh(duration_since_epoch) {
1320-
let (offer, offer_nonce, slot_number, update_static_invoice_path) =
1321-
offer_and_metadata;
1320+
let (offer, offer_nonce, update_static_invoice_path) = offer_and_metadata;
13221321

13231322
let (invoice, forward_invreq_path) = match self.create_static_invoice_for_server(
13241323
offer,
@@ -1342,7 +1341,6 @@ where
13421341
let serve_invoice_message = ServeStaticInvoice {
13431342
invoice,
13441343
forward_invoice_request_path: forward_invreq_path,
1345-
invoice_slot: slot_number,
13461344
};
13471345
serve_static_invoice_msgs.push((
13481346
serve_invoice_message,
@@ -1517,8 +1515,7 @@ where
15171515
})
15181516
};
15191517

1520-
let serve_invoice_message =
1521-
ServeStaticInvoice { invoice, forward_invoice_request_path, invoice_slot };
1518+
let serve_invoice_message = ServeStaticInvoice { invoice, forward_invoice_request_path };
15221519
Some((serve_invoice_message, reply_path_context))
15231520
}
15241521

lightning/src/onion_message/async_payments.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ pub struct ServeStaticInvoice {
172172
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
173173
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
174174
pub forward_invoice_request_path: BlindedMessagePath,
175-
/// The "slot" in the static invoice server's database that this invoice should go into. This
176-
/// allows recipients to replace a specific invoice that is stored by the server, which is useful
177-
/// for limiting the number of invoices stored by the server while also keeping all the invoices
178-
/// persisted with the server fresh.
179-
pub invoice_slot: u16,
180175
}
181176

182177
/// Confirmation from a static invoice server that a [`StaticInvoice`] was persisted and the
@@ -251,7 +246,6 @@ impl_writeable_tlv_based!(OfferPaths, {
251246
impl_writeable_tlv_based!(ServeStaticInvoice, {
252247
(0, invoice, required),
253248
(2, forward_invoice_request_path, required),
254-
(4, invoice_slot, required),
255249
});
256250

257251
impl_writeable_tlv_based!(StaticInvoicePersisted, {});

0 commit comments

Comments
 (0)