Skip to content

Commit bdfa74e

Browse files
Replace StaticInvoiceReq::invoice_id with ::inv_slot
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. Previously, when an invoice request would come in for the server on behalf of the often-offline recipient, they would need to find the static invoice based on the recipient_id and invoice_id. However, previous commits have now led to the server being able to use the invoice_slot in the initial offer paths that they create, which we do here, obviating the need for them to create their own randomly-generated invoice_id. The final dangling references to the invoice_id will be removed in the next commit.
1 parent 73c6572 commit bdfa74e

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub enum OffersContext {
353353
StaticInvoiceRequested {
354354
/// An identifier for the async recipient for whom we as a static invoice server are serving
355355
/// [`StaticInvoice`]s. Used paired with the
356-
/// [`OffersContext::StaticInvoiceRequested::invoice_id`] when looking up a corresponding
356+
/// [`OffersContext::StaticInvoiceRequested::invoice_slot`] when looking up a corresponding
357357
/// [`StaticInvoice`] to return to the payer if the recipient is offline. This id was previously
358358
/// provided via [`AsyncPaymentsContext::ServeStaticInvoice::recipient_id`].
359359
///
@@ -364,15 +364,15 @@ pub enum OffersContext {
364364
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
365365
recipient_id: Vec<u8>,
366366

367-
/// A random unique identifier for a specific [`StaticInvoice`] that the recipient previously
367+
/// The slot number for a specific [`StaticInvoice`] that the recipient previously
368368
/// requested be served on their behalf. Useful when paired with the
369369
/// [`OffersContext::StaticInvoiceRequested::recipient_id`] to pull that specific invoice from
370370
/// the database when payers send an [`InvoiceRequest`]. This id was previously
371-
/// provided via [`AsyncPaymentsContext::ServeStaticInvoice::invoice_id`].
371+
/// provided via [`AsyncPaymentsContext::ServeStaticInvoice::invoice_slot`].
372372
///
373373
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
374374
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
375-
invoice_id: u128,
375+
invoice_slot: u16,
376376

377377
/// The time as duration since the Unix epoch at which this path expires and messages sent over
378378
/// it should be ignored.
@@ -487,16 +487,16 @@ pub enum AsyncPaymentsContext {
487487
recipient_id: Vec<u8>,
488488
/// A random identifier for the specific [`StaticInvoice`] that the recipient is requesting be
489489
/// served on their behalf. Useful when surfaced alongside the above `recipient_id` when payers
490-
/// send an [`InvoiceRequest`], to pull the specific static invoice from the database. This id
491-
/// will be provided back to us as the static invoice server via
492-
/// [`OffersContext::StaticInvoiceRequested::invoice_id`].
490+
/// send an [`InvoiceRequest`], to pull the specific static invoice from the database.
493491
///
494492
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
495493
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
496494
invoice_id: u128,
497495
/// The slot number for the specific [`StaticInvoice`] that the recipient is requesting be
498496
/// served on their behalf. Useful when surfaced alongside the above `recipient_id` when payers
499-
/// send an [`InvoiceRequest`], to pull the specific static invoice from the database.
497+
/// send an [`InvoiceRequest`], to pull the specific static invoice from the database. This id
498+
/// will be provided back to us as the static invoice server via
499+
/// [`OffersContext::StaticInvoiceRequested::invoice_slot`].
500500
///
501501
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
502502
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
@@ -574,7 +574,7 @@ impl_writeable_tlv_based_enum!(OffersContext,
574574
},
575575
(3, StaticInvoiceRequested) => {
576576
(0, recipient_id, required),
577-
(2, invoice_id, required),
577+
(2, invoice_slot, required),
578578
(4, path_absolute_expiry, required),
579579
},
580580
);

lightning/src/events/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ pub enum Event {
16881688
/// them via [`ChannelManager::set_paths_to_static_invoice_server`].
16891689
///
16901690
/// If we previously persisted a [`StaticInvoice`] from an [`Event::PersistStaticInvoice`] that
1691-
/// matches the below `recipient_id` and `invoice_id`, that invoice should be retrieved now
1691+
/// matches the below `recipient_id` and `invoice_slot`, that invoice should be retrieved now
16921692
/// and forwarded to the payer via [`ChannelManager::send_static_invoice`].
16931693
///
16941694
/// [`ChannelManager::blinded_paths_for_async_recipient`]: crate::ln::channelmanager::ChannelManager::blinded_paths_for_async_recipient
@@ -1697,13 +1697,13 @@ pub enum Event {
16971697
/// [`ChannelManager::send_static_invoice`]: crate::ln::channelmanager::ChannelManager::send_static_invoice
16981698
StaticInvoiceRequested {
16991699
/// An identifier for the recipient previously surfaced in
1700-
/// [`Event::PersistStaticInvoice::recipient_id`]. Useful when paired with the `invoice_id` to
1700+
/// [`Event::PersistStaticInvoice::recipient_id`]. Useful when paired with the `invoice_slot` to
17011701
/// retrieve the [`StaticInvoice`] requested by the payer.
17021702
recipient_id: Vec<u8>,
1703-
/// A random identifier for the invoice being requested, previously surfaced in
1704-
/// [`Event::PersistStaticInvoice::invoice_id`]. Useful when paired with the `recipient_id` to
1703+
/// The slot number for the invoice being requested, previously surfaced in
1704+
/// [`Event::PersistStaticInvoice::invoice_slot`]. Useful when paired with the `recipient_id` to
17051705
/// retrieve the [`StaticInvoice`] requested by the payer.
1706-
invoice_id: u128,
1706+
invoice_slot: u16,
17071707
/// The path over which the [`StaticInvoice`] will be sent to the payer, which should be
17081708
/// provided to [`ChannelManager::send_static_invoice`] along with the invoice.
17091709
///

lightning/src/ln/async_payments_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn pass_async_payments_oms(
209209
let mut events = always_online_recipient_counterparty.node.get_and_clear_pending_events();
210210
assert_eq!(events.len(), 1);
211211
let reply_path = match events.pop().unwrap() {
212-
Event::StaticInvoiceRequested { recipient_id: ev_id, invoice_id: _, reply_path } => {
212+
Event::StaticInvoiceRequested { recipient_id: ev_id, invoice_slot: _, reply_path } => {
213213
assert_eq!(recipient_id, ev_id);
214214
reply_path
215215
},
@@ -573,7 +573,7 @@ fn ignore_unexpected_static_invoice() {
573573
let mut events = nodes[1].node.get_and_clear_pending_events();
574574
assert_eq!(events.len(), 1);
575575
let reply_path = match events.pop().unwrap() {
576-
Event::StaticInvoiceRequested { recipient_id: ev_id, invoice_id: _, reply_path } => {
576+
Event::StaticInvoiceRequested { recipient_id: ev_id, invoice_slot: _, reply_path } => {
577577
assert_eq!(recipient_id, ev_id);
578578
reply_path
579579
},

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14317,9 +14317,9 @@ where
1431714317

1431814318
let invoice_request = match self.flow.verify_invoice_request(invoice_request, context) {
1431914319
Ok(InvreqResponseInstructions::SendInvoice(invoice_request)) => invoice_request,
14320-
Ok(InvreqResponseInstructions::SendStaticInvoice { recipient_id, invoice_id }) => {
14320+
Ok(InvreqResponseInstructions::SendStaticInvoice { recipient_id, invoice_slot }) => {
1432114321
self.pending_events.lock().unwrap().push_back((Event::StaticInvoiceRequested {
14322-
recipient_id, invoice_id, reply_path: responder
14322+
recipient_id, invoice_slot, reply_path: responder
1432314323
}, None));
1432414324

1432514325
return None

lightning/src/offers/flow.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ pub enum InvreqResponseInstructions {
395395
/// the invoice request since it is now verified.
396396
SendInvoice(VerifiedInvoiceRequest),
397397
/// We are a static invoice server and should respond to this invoice request by retrieving the
398-
/// [`StaticInvoice`] corresponding to the `recipient_id` and `invoice_id` and calling
398+
/// [`StaticInvoice`] corresponding to the `recipient_id` and `invoice_slot` and calling
399399
/// `OffersMessageFlow::enqueue_static_invoice`.
400400
///
401401
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
@@ -404,8 +404,8 @@ pub enum InvreqResponseInstructions {
404404
///
405405
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
406406
recipient_id: Vec<u8>,
407-
/// An identifier for the specific invoice being requested by the payer.
408-
invoice_id: u128,
407+
/// The slot number for the specific invoice being requested by the payer.
408+
invoice_slot: u16,
409409
},
410410
}
411411

@@ -435,7 +435,7 @@ where
435435
Some(OffersContext::InvoiceRequest { nonce }) => Some(nonce),
436436
Some(OffersContext::StaticInvoiceRequested {
437437
recipient_id,
438-
invoice_id,
438+
invoice_slot,
439439
path_absolute_expiry,
440440
}) => {
441441
if path_absolute_expiry < self.duration_since_epoch() {
@@ -444,7 +444,7 @@ where
444444

445445
return Ok(InvreqResponseInstructions::SendStaticInvoice {
446446
recipient_id,
447-
invoice_id,
447+
invoice_slot,
448448
});
449449
},
450450
_ => return Err(()),
@@ -1401,7 +1401,7 @@ where
14011401
let context = MessageContext::Offers(OffersContext::StaticInvoiceRequested {
14021402
recipient_id: recipient_id.clone(),
14031403
path_absolute_expiry,
1404-
invoice_id,
1404+
invoice_slot: request.invoice_slot,
14051405
});
14061406

14071407
match self.create_blinded_paths(peers, context) {

0 commit comments

Comments
 (0)