Skip to content

Commit dbe3514

Browse files
Track invoice_slot in ServeStaticInvoice context
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. As part of this series of commits, include the invoice_slot in the ServeStaticInvoice blinded path context that the server creates when sending an offer_paths message. This is possible due to a previous commit including the invoice_slot in the initial offer_paths_request from the recipient, and lays the groundwork for removing the invoice_id field from this blinded path context.
1 parent 14b6ff6 commit dbe3514

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@ pub enum AsyncPaymentsContext {
494494
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
495495
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
496496
invoice_id: u128,
497+
/// The slot number for the specific [`StaticInvoice`] that the recipient is requesting be
498+
/// 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.
500+
///
501+
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
502+
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
503+
invoice_slot: u16,
497504
/// The time as duration since the Unix epoch at which this path expires and messages sent over
498505
/// it should be ignored.
499506
///
@@ -595,6 +602,7 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
595602
(0, recipient_id, required),
596603
(2, invoice_id, required),
597604
(4, path_absolute_expiry, required),
605+
(6, invoice_slot, required),
598606
},
599607
);
600608

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14441,13 +14441,13 @@ where
1444114441
L::Target: Logger,
1444214442
{
1444314443
fn handle_offer_paths_request(
14444-
&self, _message: OfferPathsRequest, context: AsyncPaymentsContext,
14444+
&self, message: OfferPathsRequest, context: AsyncPaymentsContext,
1444514445
responder: Option<Responder>,
1444614446
) -> Option<(OfferPaths, ResponseInstruction)> {
1444714447
let peers = self.get_peers_for_blinded_path();
1444814448
let entropy = &*self.entropy_source;
1444914449
let (message, reply_path_context) =
14450-
match self.flow.handle_offer_paths_request(context, peers, entropy) {
14450+
match self.flow.handle_offer_paths_request(&message, context, peers, entropy) {
1445114451
Some(msg) => msg,
1445214452
None => return None,
1445314453
};
@@ -14490,17 +14490,17 @@ where
1449014490
None => return,
1449114491
};
1449214492

14493-
let (recipient_id, invoice_id) =
14493+
let (recipient_id, invoice_slot, invoice_id) =
1449414494
match self.flow.verify_serve_static_invoice_message(&message, context) {
14495-
Ok((recipient_id, inv_id)) => (recipient_id, inv_id),
14495+
Ok((recipient_id, inv_slot, inv_id)) => (recipient_id, inv_slot, inv_id),
1449614496
Err(()) => return,
1449714497
};
1449814498

1449914499
let mut pending_events = self.pending_events.lock().unwrap();
1450014500
pending_events.push_back((
1450114501
Event::PersistStaticInvoice {
1450214502
invoice: message.invoice,
14503-
invoice_slot: message.invoice_slot,
14503+
invoice_slot,
1450414504
recipient_id,
1450514505
invoice_id,
1450614506
invoice_persisted_path: responder,

lightning/src/offers/flow.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,8 @@ where
13741374
/// wants us (the static invoice server) to serve [`StaticInvoice`]s to payers on their behalf.
13751375
/// Sends out [`OfferPaths`] onion messages in response.
13761376
pub fn handle_offer_paths_request<ES: Deref>(
1377-
&self, context: AsyncPaymentsContext, peers: Vec<MessageForwardNode>, entropy_source: ES,
1377+
&self, request: &OfferPathsRequest, context: AsyncPaymentsContext,
1378+
peers: Vec<MessageForwardNode>, entropy_source: ES,
13781379
) -> Option<(OfferPaths, MessageContext)>
13791380
where
13801381
ES::Target: EntropySource,
@@ -1420,6 +1421,7 @@ where
14201421
MessageContext::AsyncPayments(AsyncPaymentsContext::ServeStaticInvoice {
14211422
recipient_id,
14221423
invoice_id,
1424+
invoice_slot: request.invoice_slot,
14231425
path_absolute_expiry,
14241426
})
14251427
};
@@ -1587,7 +1589,7 @@ where
15871589
/// [`ServeStaticInvoice::invoice`]: crate::onion_message::async_payments::ServeStaticInvoice::invoice
15881590
pub fn verify_serve_static_invoice_message(
15891591
&self, message: &ServeStaticInvoice, context: AsyncPaymentsContext,
1590-
) -> Result<(Vec<u8>, u128), ()> {
1592+
) -> Result<(Vec<u8>, u16, u128), ()> {
15911593
if message.invoice.is_expired_no_std(self.duration_since_epoch()) {
15921594
return Err(());
15931595
}
@@ -1598,13 +1600,14 @@ where
15981600
AsyncPaymentsContext::ServeStaticInvoice {
15991601
recipient_id,
16001602
invoice_id,
1603+
invoice_slot,
16011604
path_absolute_expiry,
16021605
} => {
16031606
if self.duration_since_epoch() > path_absolute_expiry {
16041607
return Err(());
16051608
}
16061609

1607-
return Ok((recipient_id, invoice_id));
1610+
return Ok((recipient_id, invoice_slot, invoice_id));
16081611
},
16091612
_ => return Err(()),
16101613
};

0 commit comments

Comments
 (0)