Skip to content

Commit 713b5fb

Browse files
Remove now-unused ServeStaticInvoice::invoice_id
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 sometimetimes based on (recipient_id, invoice_id). This made the API harder to use in terms of how the server would index into the KVStore. Over the course of the previous commits we transitioned to the server always finding a specific invoice based on (recipient_id, invoice_slot). We still have a few dangling references to invoice_id in some messages and events though, so remove those here.
1 parent bdfa74e commit 713b5fb

File tree

5 files changed

+21
-51
lines changed

5 files changed

+21
-51
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ pub enum AsyncPaymentsContext {
474474
/// An identifier for the async recipient that is requesting that a [`StaticInvoice`] be served
475475
/// on their behalf.
476476
///
477-
/// Useful when surfaced alongside the below `invoice_id` when payers send an
477+
/// Useful when surfaced alongside the below `invoice_slot` when payers send an
478478
/// [`InvoiceRequest`], to pull the specific static invoice from the database.
479479
///
480480
/// Also useful to rate limit the invoices being persisted on behalf of a particular recipient.
@@ -485,13 +485,6 @@ pub enum AsyncPaymentsContext {
485485
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
486486
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
487487
recipient_id: Vec<u8>,
488-
/// A random identifier for the specific [`StaticInvoice`] that the recipient is requesting be
489-
/// 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.
491-
///
492-
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
493-
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
494-
invoice_id: u128,
495488
/// The slot number for the specific [`StaticInvoice`] that the recipient is requesting be
496489
/// served on their behalf. Useful when surfaced alongside the above `recipient_id` when payers
497490
/// send an [`InvoiceRequest`], to pull the specific static invoice from the database. This id
@@ -600,9 +593,8 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
600593
},
601594
(5, ServeStaticInvoice) => {
602595
(0, recipient_id, required),
603-
(2, invoice_id, required),
596+
(2, invoice_slot, required),
604597
(4, path_absolute_expiry, required),
605-
(6, invoice_slot, required),
606598
},
607599
);
608600

lightning/src/events/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,18 +1661,11 @@ pub enum Event {
16611661
/// [`ChannelManager::blinded_paths_for_async_recipient`].
16621662
///
16631663
/// When an [`Event::StaticInvoiceRequested`] comes in for the invoice, this id will be surfaced
1664-
/// and can be used alongside the `invoice_id` to retrieve the invoice from the database.
1664+
/// and can be used alongside the `invoice_slot` to retrieve the invoice from the database.
16651665
///
16661666
///[`ChannelManager::blinded_paths_for_async_recipient`]: crate::ln::channelmanager::ChannelManager::blinded_paths_for_async_recipient
16671667
recipient_id: Vec<u8>,
1668-
/// A random identifier for the invoice. When an [`Event::StaticInvoiceRequested`] comes in for
1669-
/// the invoice, this id will be surfaced and can be used alongside the `recipient_id` to
1670-
/// retrieve the invoice from the database.
1671-
///
1672-
/// Note that this id will remain the same for all invoice updates corresponding to a particular
1673-
/// offer that the recipient has cached.
1674-
invoice_id: u128,
1675-
/// Once the [`StaticInvoice`], `invoice_slot` and `invoice_id` are persisted,
1668+
/// Once the [`StaticInvoice`] and `invoice_slot` are persisted,
16761669
/// [`ChannelManager::static_invoice_persisted`] should be called with this responder to confirm
16771670
/// to the recipient that their [`Offer`] is ready to be used for async payments.
16781671
///

lightning/src/ln/async_payments_tests.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ use core::time::Duration;
6666
struct StaticInvoiceServerFlowResult {
6767
invoice: StaticInvoice,
6868
invoice_slot: u16,
69-
invoice_id: u128,
7069

7170
// Returning messages that were sent along the way allows us to test handling duplicate messages.
7271
offer_paths_request: msgs::OnionMessage,
@@ -148,16 +147,15 @@ fn pass_static_invoice_server_messages(
148147
// that the static invoice should be persisted.
149148
let mut events = server.node.get_and_clear_pending_events();
150149
assert_eq!(events.len(), 1);
151-
let (invoice, invoice_slot, invoice_id, ack_path) = match events.pop().unwrap() {
150+
let (invoice, invoice_slot, ack_path) = match events.pop().unwrap() {
152151
Event::PersistStaticInvoice {
153152
invoice,
154153
invoice_persisted_path,
155154
recipient_id: ev_id,
156155
invoice_slot,
157-
invoice_id,
158156
} => {
159157
assert_eq!(recipient_id, ev_id);
160-
(invoice, invoice_slot, invoice_id, invoice_persisted_path)
158+
(invoice, invoice_slot, invoice_persisted_path)
161159
},
162160
_ => panic!(),
163161
};
@@ -183,7 +181,6 @@ fn pass_static_invoice_server_messages(
183181
static_invoice_persisted_message: invoice_persisted_om,
184182
invoice,
185183
invoice_slot,
186-
invoice_id,
187184
}
188185
}
189186

@@ -1626,13 +1623,13 @@ fn limit_serve_static_invoice_requests() {
16261623

16271624
// Build the target number of offers interactively with the static invoice server.
16281625
let mut offer_paths_req = None;
1629-
let mut invoice_ids = new_hash_set();
1626+
let mut invoice_slots = new_hash_set();
16301627
for expected_inv_slot in 0..TEST_MAX_CACHED_OFFERS_TARGET {
16311628
let flow_res = pass_static_invoice_server_messages(server, recipient, recipient_id.clone());
16321629
assert_eq!(flow_res.invoice_slot, expected_inv_slot as u16);
16331630

16341631
offer_paths_req = Some(flow_res.offer_paths_request);
1635-
invoice_ids.insert(flow_res.invoice_id);
1632+
invoice_slots.insert(flow_res.invoice_slot);
16361633

16371634
// Trigger a cache refresh
16381635
recipient.node.timer_tick_occurred();
@@ -1641,8 +1638,8 @@ fn limit_serve_static_invoice_requests() {
16411638
recipient.node.flow.test_get_async_receive_offers().len(),
16421639
TEST_MAX_CACHED_OFFERS_TARGET
16431640
);
1644-
// Check that all invoice ids are unique.
1645-
assert_eq!(invoice_ids.len(), TEST_MAX_CACHED_OFFERS_TARGET);
1641+
// Check that all invoice slot numbers are unique.
1642+
assert_eq!(invoice_slots.len(), TEST_MAX_CACHED_OFFERS_TARGET);
16461643

16471644
// Force allowing more offer paths request attempts so we can check that the recipient will not
16481645
// attempt to build any further offers.
@@ -1822,16 +1819,15 @@ fn refresh_static_invoices_for_used_offers() {
18221819
Event::PersistStaticInvoice {
18231820
invoice,
18241821
invoice_slot,
1825-
invoice_id,
18261822
invoice_persisted_path,
18271823
recipient_id: ev_id,
18281824
} => {
18291825
assert_ne!(original_invoice, invoice);
18301826
assert_eq!(recipient_id, ev_id);
18311827
assert_eq!(invoice_slot, flow_res.invoice_slot);
1832-
// When we update the invoice corresponding to a specific offer, the invoice_id stays the
1828+
// When we update the invoice corresponding to a specific offer, the invoice_slot stays the
18331829
// same.
1834-
assert_eq!(invoice_id, flow_res.invoice_id);
1830+
assert_eq!(invoice_slot, flow_res.invoice_slot);
18351831
(invoice, invoice_persisted_path)
18361832
},
18371833
_ => panic!(),

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14445,9 +14445,8 @@ where
1444514445
responder: Option<Responder>,
1444614446
) -> Option<(OfferPaths, ResponseInstruction)> {
1444714447
let peers = self.get_peers_for_blinded_path();
14448-
let entropy = &*self.entropy_source;
1444914448
let (message, reply_path_context) =
14450-
match self.flow.handle_offer_paths_request(&message, context, peers, entropy) {
14449+
match self.flow.handle_offer_paths_request(&message, context, peers) {
1445114450
Some(msg) => msg,
1445214451
None => return None,
1445314452
};
@@ -14490,9 +14489,9 @@ where
1449014489
None => return,
1449114490
};
1449214491

14493-
let (recipient_id, invoice_slot, invoice_id) =
14492+
let (recipient_id, invoice_slot) =
1449414493
match self.flow.verify_serve_static_invoice_message(&message, context) {
14495-
Ok((recipient_id, inv_slot, inv_id)) => (recipient_id, inv_slot, inv_id),
14494+
Ok((recipient_id, inv_slot)) => (recipient_id, inv_slot),
1449614495
Err(()) => return,
1449714496
};
1449814497

@@ -14502,7 +14501,6 @@ where
1450214501
invoice: message.invoice,
1450314502
invoice_slot,
1450414503
recipient_id,
14505-
invoice_id,
1450614504
invoice_persisted_path: responder,
1450714505
},
1450814506
None,

lightning/src/offers/flow.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,13 +1371,10 @@ where
13711371
/// Handles an incoming [`OfferPathsRequest`] onion message from an often-offline recipient who
13721372
/// wants us (the static invoice server) to serve [`StaticInvoice`]s to payers on their behalf.
13731373
/// Sends out [`OfferPaths`] onion messages in response.
1374-
pub fn handle_offer_paths_request<ES: Deref>(
1374+
pub fn handle_offer_paths_request(
13751375
&self, request: &OfferPathsRequest, context: AsyncPaymentsContext,
1376-
peers: Vec<MessageForwardNode>, entropy_source: ES,
1377-
) -> Option<(OfferPaths, MessageContext)>
1378-
where
1379-
ES::Target: EntropySource,
1380-
{
1376+
peers: Vec<MessageForwardNode>,
1377+
) -> Option<(OfferPaths, MessageContext)> {
13811378
let duration_since_epoch = self.duration_since_epoch();
13821379

13831380
let recipient_id = match context {
@@ -1390,10 +1387,6 @@ where
13901387
_ => return None,
13911388
};
13921389

1393-
let mut random_bytes = [0u8; 16];
1394-
random_bytes.copy_from_slice(&entropy_source.get_secure_random_bytes()[..16]);
1395-
let invoice_id = u128::from_be_bytes(random_bytes);
1396-
13971390
// Create the blinded paths that will be included in the async recipient's offer.
13981391
let (offer_paths, paths_expiry) = {
13991392
let path_absolute_expiry =
@@ -1418,7 +1411,6 @@ where
14181411
duration_since_epoch.saturating_add(DEFAULT_ASYNC_RECEIVE_OFFER_EXPIRY);
14191412
MessageContext::AsyncPayments(AsyncPaymentsContext::ServeStaticInvoice {
14201413
recipient_id,
1421-
invoice_id,
14221414
invoice_slot: request.invoice_slot,
14231415
path_absolute_expiry,
14241416
})
@@ -1577,7 +1569,7 @@ where
15771569
/// wants us as a static invoice server to serve the [`ServeStaticInvoice::invoice`] to payers on
15781570
/// their behalf.
15791571
///
1580-
/// On success, returns `(recipient_id, invoice_id)` for use in persisting and later retrieving
1572+
/// On success, returns `(recipient_id, invoice_slot)` for use in persisting and later retrieving
15811573
/// the static invoice from the database.
15821574
///
15831575
/// Errors if the [`ServeStaticInvoice::invoice`] is expired or larger than
@@ -1586,7 +1578,7 @@ where
15861578
/// [`ServeStaticInvoice::invoice`]: crate::onion_message::async_payments::ServeStaticInvoice::invoice
15871579
pub fn verify_serve_static_invoice_message(
15881580
&self, message: &ServeStaticInvoice, context: AsyncPaymentsContext,
1589-
) -> Result<(Vec<u8>, u16, u128), ()> {
1581+
) -> Result<(Vec<u8>, u16), ()> {
15901582
if message.invoice.is_expired_no_std(self.duration_since_epoch()) {
15911583
return Err(());
15921584
}
@@ -1596,15 +1588,14 @@ where
15961588
match context {
15971589
AsyncPaymentsContext::ServeStaticInvoice {
15981590
recipient_id,
1599-
invoice_id,
16001591
invoice_slot,
16011592
path_absolute_expiry,
16021593
} => {
16031594
if self.duration_since_epoch() > path_absolute_expiry {
16041595
return Err(());
16051596
}
16061597

1607-
return Ok((recipient_id, invoice_slot, invoice_id));
1598+
return Ok((recipient_id, invoice_slot));
16081599
},
16091600
_ => return Err(()),
16101601
};

0 commit comments

Comments
 (0)