Skip to content

Commit 06f2019

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 748c04a commit 06f2019

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
@@ -368,12 +368,13 @@ impl AsyncReceiveOfferCache {
368368

369369
/// If we have any empty slots in the cache or offers that can and should be replaced with a fresh
370370
/// offer, here we return the index of the slot that needs a new offer. The index is used for
371-
/// setting [`ServeStaticInvoice::invoice_slot`] when sending the corresponding new static invoice
372-
/// to the server, so the server knows which existing persisted invoice is being replaced, if any.
371+
/// setting [`OfferPathsRequest::invoice_slot`] when requesting offer paths from the server, so
372+
/// the server can include the slot in the offer paths and reply paths that they create in
373+
/// response.
373374
///
374375
/// Returns `None` if the cache is full and no offers can currently be replaced.
375376
///
376-
/// [`ServeStaticInvoice::invoice_slot`]: crate::onion_message::async_payments::ServeStaticInvoice::invoice_slot
377+
/// [`OfferPathsRequest::invoice_slot`]: crate::onion_message::async_payments::OfferPathsRequest::invoice_slot
377378
fn needs_new_offer_idx(&self, duration_since_epoch: Duration) -> Option<usize> {
378379
// If we have any empty offer slots, return the first one we find
379380
let empty_slot_idx_opt = self.offers.iter().position(|offer_opt| offer_opt.is_none());
@@ -446,10 +447,10 @@ impl AsyncReceiveOfferCache {
446447
/// the static invoice server.
447448
pub(super) fn offers_needing_invoice_refresh(
448449
&self, duration_since_epoch: Duration,
449-
) -> impl Iterator<Item = (&Offer, Nonce, u16, &Responder)> {
450+
) -> impl Iterator<Item = (&Offer, Nonce, &Responder)> {
450451
// For any offers which are either in use or pending confirmation by the server, we should send
451452
// them a fresh invoice on each timer tick.
452-
self.offers_with_idx().filter_map(move |(idx, offer)| {
453+
self.offers_with_idx().filter_map(move |(_, offer)| {
453454
let needs_invoice_update = match offer.status {
454455
OfferStatus::Used { invoice_created_at } => {
455456
invoice_created_at.saturating_add(INVOICE_REFRESH_THRESHOLD)
@@ -461,13 +462,7 @@ impl AsyncReceiveOfferCache {
461462
OfferStatus::Ready { .. } => false,
462463
};
463464
if needs_invoice_update {
464-
let offer_slot = idx.try_into().unwrap_or(u16::MAX);
465-
Some((
466-
&offer.offer,
467-
offer.offer_nonce,
468-
offer_slot,
469-
&offer.update_static_invoice_path,
470-
))
465+
Some((&offer.offer, offer.offer_nonce, &offer.update_static_invoice_path))
471466
} else {
472467
None
473468
}

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,
@@ -1518,8 +1516,7 @@ where
15181516
})
15191517
};
15201518

1521-
let serve_invoice_message =
1522-
ServeStaticInvoice { invoice, forward_invoice_request_path, invoice_slot };
1519+
let serve_invoice_message = ServeStaticInvoice { invoice, forward_invoice_request_path };
15231520
Some((serve_invoice_message, reply_path_context))
15241521
}
15251522

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)