Skip to content

Commit e787740

Browse files
Expose async offer cache API to OffersMessageFlow users
We want the OffersMessageFlow to be usable by non-ChannelManager users, so expose the required methods to enable that. Also a few corresponding docs tweaks.
1 parent 15fb61e commit e787740

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

lightning/src/offers/async_receive_offer_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl AsyncReceiveOfferCache {
153153
///
154154
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
155155
#[cfg(async_payments)]
156-
pub fn set_paths_to_static_invoice_server(
156+
pub(crate) fn set_paths_to_static_invoice_server(
157157
&mut self, paths_to_static_invoice_server: Vec<BlindedMessagePath>,
158158
) -> Result<(), ()> {
159159
if paths_to_static_invoice_server.is_empty() {
@@ -211,7 +211,7 @@ impl AsyncReceiveOfferCache {
211211
///
212212
// We need to re-persist the cache if a fresh offer was just marked as used to ensure we continue
213213
// to keep this offer's invoice updated and don't replace it with the server.
214-
pub fn get_async_receive_offer(
214+
pub(crate) fn get_async_receive_offer(
215215
&mut self, duration_since_epoch: Duration,
216216
) -> Result<(Offer, bool), ()> {
217217
self.prune_expired_offers(duration_since_epoch, false);

lightning/src/offers/flow.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ where
153153
/// If we are an async recipient, on startup we'll interactively build offers and static invoices
154154
/// with an always-online node that will serve static invoices on our behalf. Once the offer is
155155
/// built and the static invoice is confirmed as persisted by the server, the underlying
156-
/// [`AsyncReceiveOfferCache`] should be persisted so we remember the offers we've built.
157-
pub(crate) fn with_async_payments_offers_cache(
156+
/// [`AsyncReceiveOfferCache`] should be persisted using
157+
/// [`Self::writeable_async_receive_offer_cache`] so we remember the offers we've built.
158+
pub fn with_async_payments_offers_cache(
158159
mut self, async_receive_offer_cache: AsyncReceiveOfferCache,
159160
) -> Self {
160161
self.paths_to_static_invoice_server =
@@ -170,7 +171,7 @@ where
170171
/// This method only needs to be called once when the server first takes on the recipient as a
171172
/// client, or when the paths change, e.g. if the paths are set to expire at a particular time.
172173
#[cfg(async_payments)]
173-
pub(crate) fn set_paths_to_static_invoice_server(
174+
pub fn set_paths_to_static_invoice_server(
174175
&self, paths_to_static_invoice_server: Vec<BlindedMessagePath>,
175176
) -> Result<(), ()> {
176177
// Store the paths in the async receive cache so they are persisted with the cache, but also
@@ -286,7 +287,7 @@ where
286287
///
287288
/// Errors if blinded path creation fails or the provided `recipient_id` is larger than 1KiB.
288289
#[cfg(async_payments)]
289-
pub(crate) fn blinded_paths_for_async_recipient(
290+
pub fn blinded_paths_for_async_recipient(
290291
&self, recipient_id: Vec<u8>, relative_expiry: Option<Duration>,
291292
peers: Vec<MessageForwardNode>,
292293
) -> Result<Vec<BlindedMessagePath>, ()> {
@@ -1113,9 +1114,11 @@ where
11131114
Ok(())
11141115
}
11151116

1116-
/// Forwards a [`StaticInvoice`] over the provided `responder`.
1117+
/// Forwards a [`StaticInvoice`] over the provided [`Responder`] in response to an
1118+
/// [`InvoiceRequest`] that we as a static invoice server received on behalf of an often-offline
1119+
/// recipient.
11171120
#[cfg(async_payments)]
1118-
pub(crate) fn enqueue_static_invoice(
1121+
pub fn enqueue_static_invoice(
11191122
&self, invoice: StaticInvoice, responder: Responder,
11201123
) -> Result<(), Bolt12SemanticError> {
11211124
let duration_since_epoch = self.duration_since_epoch();
@@ -1226,8 +1229,11 @@ where
12261229
/// Retrieve an [`Offer`] for receiving async payments as an often-offline recipient. Will only
12271230
/// return an offer if [`Self::set_paths_to_static_invoice_server`] was called and we succeeded in
12281231
/// interactively building a [`StaticInvoice`] with the static invoice server.
1232+
///
1233+
/// Returns the requested offer as well as a bool indicating whether the cache needs to be
1234+
/// persisted using [`Self::writeable_async_receive_offer_cache`].
12291235
#[cfg(async_payments)]
1230-
pub(crate) fn get_async_receive_offer(&self) -> Result<(Offer, bool), ()> {
1236+
pub fn get_async_receive_offer(&self) -> Result<(Offer, bool), ()> {
12311237
let mut cache = self.async_receive_offer_cache.lock().unwrap();
12321238
cache.get_async_receive_offer(self.duration_since_epoch())
12331239
}
@@ -1249,7 +1255,7 @@ where
12491255
///
12501256
/// Errors if we failed to create blinded reply paths when sending an [`OfferPathsRequest`] message.
12511257
#[cfg(async_payments)]
1252-
pub(crate) fn check_refresh_async_receive_offer_cache<ES: Deref, R: Deref>(
1258+
pub fn check_refresh_async_receive_offer_cache<ES: Deref, R: Deref>(
12531259
&self, peers: Vec<MessageForwardNode>, usable_channels: Vec<ChannelDetails>, entropy: ES,
12541260
router: R, timer_tick_occurred: bool,
12551261
) -> Result<(), ()>
@@ -1385,7 +1391,7 @@ where
13851391
/// wants us (the static invoice server) to serve [`StaticInvoice`]s to payers on their behalf.
13861392
/// Sends out [`OfferPaths`] onion messages in response.
13871393
#[cfg(async_payments)]
1388-
pub(crate) fn handle_offer_paths_request<ES: Deref>(
1394+
pub fn handle_offer_paths_request<ES: Deref>(
13891395
&self, context: AsyncPaymentsContext, peers: Vec<MessageForwardNode>, entropy_source: ES,
13901396
) -> Option<(OfferPaths, MessageContext)>
13911397
where
@@ -1448,7 +1454,7 @@ where
14481454
/// Returns `None` if we have enough offers cached already, verification of `message` fails, or we
14491455
/// fail to create blinded paths.
14501456
#[cfg(async_payments)]
1451-
pub(crate) fn handle_offer_paths<ES: Deref, R: Deref>(
1457+
pub fn handle_offer_paths<ES: Deref, R: Deref>(
14521458
&self, message: OfferPaths, context: AsyncPaymentsContext, responder: Responder,
14531459
peers: Vec<MessageForwardNode>, usable_channels: Vec<ChannelDetails>, entropy: ES,
14541460
router: R,
@@ -1599,7 +1605,7 @@ where
15991605
/// the static invoice from the database.
16001606
///
16011607
/// Errors if the [`ServeStaticInvoice::invoice`] is expired or larger than
1602-
/// [`MAX_STATIC_INVOICE_SIZE_BYTES`], or if blinded path verification fails.
1608+
/// [`MAX_STATIC_INVOICE_SIZE_BYTES`].
16031609
///
16041610
/// [`ServeStaticInvoice::invoice`]: crate::onion_message::async_payments::ServeStaticInvoice::invoice
16051611
#[cfg(async_payments)]
@@ -1641,17 +1647,18 @@ where
16411647
}
16421648

16431649
/// Handles an incoming [`StaticInvoicePersisted`] onion message from the static invoice server.
1644-
/// Returns a bool indicating whether the async receive offer cache needs to be re-persisted.
1650+
/// Returns a bool indicating whether the async receive offer cache needs to be re-persisted using
1651+
/// [`Self::writeable_async_receive_offer_cache`].
16451652
///
16461653
/// [`StaticInvoicePersisted`]: crate::onion_message::async_payments::StaticInvoicePersisted
16471654
#[cfg(async_payments)]
1648-
pub(crate) fn handle_static_invoice_persisted(&self, context: AsyncPaymentsContext) -> bool {
1655+
pub fn handle_static_invoice_persisted(&self, context: AsyncPaymentsContext) -> bool {
16491656
let mut cache = self.async_receive_offer_cache.lock().unwrap();
16501657
cache.static_invoice_persisted(context, self.duration_since_epoch())
16511658
}
16521659

1653-
/// Get the `AsyncReceiveOfferCache` for persistence.
1654-
pub(crate) fn writeable_async_receive_offer_cache(&self) -> impl Writeable + '_ {
1655-
&self.async_receive_offer_cache
1660+
/// Get the [`AsyncReceiveOfferCache`] for persistence.
1661+
pub fn writeable_async_receive_offer_cache(&self) -> impl Writeable + '_ {
1662+
self.async_receive_offer_cache.encode()
16561663
}
16571664
}

lightning/src/offers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
pub mod offer;
1717
pub mod flow;
1818

19-
pub(crate) mod async_receive_offer_cache;
19+
pub mod async_receive_offer_cache;
2020
pub mod invoice;
2121
pub mod invoice_error;
2222
mod invoice_macros;

0 commit comments

Comments
 (0)