Skip to content

Commit e76d6d7

Browse files
committed
f: review comments
1 parent 929bc66 commit e76d6d7

File tree

8 files changed

+60
-20
lines changed

8 files changed

+60
-20
lines changed

src/event.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8-
use crate::payment::asynchronous::static_invoice_store::StaticInvoiceStore;
98
use crate::types::{CustomTlvRecord, DynStore, PaymentStore, Sweeper, Wallet};
109
use crate::{
1110
hex_utils, BumpTransactionEventHandler, ChannelManager, Error, Graph, PeerInfo, PeerStore,
@@ -19,6 +18,7 @@ use crate::fee_estimator::ConfirmationTarget;
1918
use crate::liquidity::LiquiditySource;
2019
use crate::logger::Logger;
2120

21+
use crate::payment::asynchronous::static_invoice_store::StaticInvoiceStore;
2222
use crate::payment::store::{
2323
PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentKind, PaymentStatus,
2424
};
@@ -1509,13 +1509,14 @@ where
15091509
.handle_persist_static_invoice(invoice, invoice_slot, recipient_id)
15101510
.await
15111511
{
1512-
Ok(_) => {},
1512+
Ok(_) => {
1513+
self.channel_manager.static_invoice_persisted(invoice_persisted_path);
1514+
},
15131515
Err(e) => {
15141516
log_error!(self.logger, "Failed to persist static invoice: {}", e);
1517+
return Err(ReplayEvent());
15151518
},
15161519
};
1517-
1518-
self.channel_manager.static_invoice_persisted(invoice_persisted_path);
15191520
}
15201521
},
15211522
LdkEvent::StaticInvoiceRequested { recipient_id, invoice_slot, reply_path } => {
@@ -1534,6 +1535,7 @@ where
15341535
Ok(None) => {},
15351536
Err(e) => {
15361537
log_error!(self.logger, "Failed to retrieve static invoice: {}", e);
1538+
return Err(ReplayEvent());
15371539
},
15381540
}
15391541
}

src/io/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) const BDK_WALLET_INDEXER_PRIMARY_NAMESPACE: &str = "bdk_wallet";
7474
pub(crate) const BDK_WALLET_INDEXER_SECONDARY_NAMESPACE: &str = "";
7575
pub(crate) const BDK_WALLET_INDEXER_KEY: &str = "indexer";
7676

77-
// Static invoices will be persisted at "static_invoices/<sha256(recipient_id)>/<invoice_slot>".
78-
//
79-
// Example: static_invoices/039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81/001f
80-
pub(crate) const STATIC_INVOICES_PRIMARY_NAMESPACE: &str = "static_invoices";
77+
/// [`StaticInvoice`]s will be persisted under this key.
78+
///
79+
/// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
80+
pub(crate) const STATIC_INVOICE_STORE_PRIMARY_NAMESPACE: &str = "static_invoices";

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ impl Node {
826826
Bolt12Payment::new(
827827
Arc::clone(&self.channel_manager),
828828
Arc::clone(&self.payment_store),
829-
self.config.async_payment_services_enabled,
829+
Arc::clone(&self.config),
830830
Arc::clone(&self.is_running),
831831
Arc::clone(&self.logger),
832832
)

src/payment/asynchronous/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
// This file is Copyright its original authors, visible in version control history.
2+
//
3+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5+
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6+
// accordance with one or both of these licenses.
7+
18
mod rate_limiter;
29
pub(crate) mod static_invoice_store;

src/payment/asynchronous/rate_limiter.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// This file is Copyright its original authors, visible in version control history.
2+
//
3+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5+
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6+
// accordance with one or both of these licenses.
7+
8+
//! [`RateLimiter`] to control the rate of requests from users.
9+
110
use std::collections::HashMap;
211
use std::time::{Duration, Instant};
312

src/payment/asynchronous/static_invoice_store.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
// This file is Copyright its original authors, visible in version control history.
2+
//
3+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5+
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6+
// accordance with one or both of these licenses.
7+
8+
//! Store implementation for [`StaticInvoice`]s.
9+
110
use crate::hex_utils;
2-
use crate::io::STATIC_INVOICES_PRIMARY_NAMESPACE;
11+
use crate::io::STATIC_INVOICE_STORE_PRIMARY_NAMESPACE;
312
use crate::payment::asynchronous::rate_limiter::RateLimiter;
413
use crate::types::DynStore;
514

@@ -57,7 +66,7 @@ impl StaticInvoiceStore {
5766
let (secondary_namespace, key) = Self::get_storage_location(invoice_slot, recipient_id);
5867

5968
self.kv_store
60-
.read(STATIC_INVOICES_PRIMARY_NAMESPACE, &secondary_namespace, &key)
69+
.read(STATIC_INVOICE_STORE_PRIMARY_NAMESPACE, &secondary_namespace, &key)
6170
.and_then(|data| {
6271
data.try_into().map(Some).map_err(|e| {
6372
lightning::io::Error::new(
@@ -87,7 +96,10 @@ impl StaticInvoiceStore {
8796
let mut buf = Vec::new();
8897
invoice.write(&mut buf)?;
8998

90-
self.kv_store.write(STATIC_INVOICES_PRIMARY_NAMESPACE, &secondary_namespace, &key, buf)
99+
// Static invoices will be persisted at "static_invoices/<sha256(recipient_id)>/<invoice_slot>".
100+
//
101+
// Example: static_invoices/039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81/00001
102+
self.kv_store.write(STATIC_INVOICE_STORE_PRIMARY_NAMESPACE, &secondary_namespace, &key, buf)
91103
}
92104

93105
fn get_storage_location(invoice_slot: u16, recipient_id: &[u8]) -> (String, String) {

src/payment/bolt12.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//!
1010
//! [BOLT 12]: https://github.com/lightning/bolts/blob/master/12-offer-encoding.md
1111
12-
use crate::config::LDK_PAYMENT_RETRY_TIMEOUT;
12+
use crate::config::{Config, LDK_PAYMENT_RETRY_TIMEOUT};
1313
use crate::error::Error;
1414
use crate::ffi::{maybe_deref, maybe_wrap};
1515
use crate::logger::{log_error, log_info, LdkLogger, Logger};
@@ -57,16 +57,16 @@ pub struct Bolt12Payment {
5757
channel_manager: Arc<ChannelManager>,
5858
payment_store: Arc<PaymentStore>,
5959
is_running: Arc<RwLock<bool>>,
60-
async_payment_services_enabled: bool,
60+
config: Arc<Config>,
6161
logger: Arc<Logger>,
6262
}
6363

6464
impl Bolt12Payment {
6565
pub(crate) fn new(
6666
channel_manager: Arc<ChannelManager>, payment_store: Arc<PaymentStore>,
67-
async_payment_services_enabled: bool, is_running: Arc<RwLock<bool>>, logger: Arc<Logger>,
67+
config: Arc<Config>, is_running: Arc<RwLock<bool>>, logger: Arc<Logger>,
6868
) -> Self {
69-
Self { channel_manager, payment_store, async_payment_services_enabled, is_running, logger }
69+
Self { channel_manager, payment_store, config, is_running, logger }
7070
}
7171

7272
/// Send a payment given an offer.
@@ -462,6 +462,8 @@ impl Bolt12Payment {
462462
///
463463
/// Useful for posting offers to receive payments later, such as posting an offer on a website.
464464
///
465+
/// **Caution**: Async payments support is considered experimental.
466+
///
465467
/// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
466468
/// [`Offer`]: lightning::offers::offer::Offer
467469
pub fn receive_async(&self) -> Result<Offer, Error> {
@@ -474,6 +476,8 @@ impl Bolt12Payment {
474476
/// Sets the [`BlindedMessagePath`]s that we will use as an async recipient to interactively build [`Offer`]s with a
475477
/// static invoice server, so the server can serve [`StaticInvoice`]s to payers on our behalf when we're offline.
476478
///
479+
/// **Caution**: Async payments support is considered experimental.
480+
///
477481
/// [`Offer`]: lightning::offers::offer::Offer
478482
/// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
479483
#[cfg(not(feature = "uniffi"))]
@@ -488,6 +492,8 @@ impl Bolt12Payment {
488492
/// Sets the [`BlindedMessagePath`]s that we will use as an async recipient to interactively build [`Offer`]s with a
489493
/// static invoice server, so the server can serve [`StaticInvoice`]s to payers on our behalf when we're offline.
490494
///
495+
/// **Caution**: Async payments support is considered experimental.
496+
///
491497
/// [`Offer`]: lightning::offers::offer::Offer
492498
/// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
493499
#[cfg(feature = "uniffi")]
@@ -503,6 +509,8 @@ impl Bolt12Payment {
503509
/// [`BlindedMessagePath`]s for an async recipient to communicate with this node and interactively
504510
/// build [`Offer`]s and [`StaticInvoice`]s for receiving async payments.
505511
///
512+
/// **Caution**: Async payments support is considered experimental.
513+
///
506514
/// [`Offer`]: lightning::offers::offer::Offer
507515
/// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
508516
#[cfg(not(feature = "uniffi"))]
@@ -515,6 +523,8 @@ impl Bolt12Payment {
515523
/// [`BlindedMessagePath`]s for an async recipient to communicate with this node and interactively
516524
/// build [`Offer`]s and [`StaticInvoice`]s for receiving async payments.
517525
///
526+
/// **Caution**: Async payments support is considered experimental.
527+
///
518528
/// [`Offer`]: lightning::offers::offer::Offer
519529
/// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
520530
#[cfg(feature = "uniffi")]
@@ -531,7 +541,7 @@ impl Bolt12Payment {
531541
fn blinded_paths_for_async_recipient_internal(
532542
&self, recipient_id: Vec<u8>,
533543
) -> Result<Vec<BlindedMessagePath>, Error> {
534-
if !self.async_payment_services_enabled {
544+
if !self.config.async_payment_services_enabled {
535545
return Err(Error::AsyncPaymentServicesDisabled);
536546
}
537547

tests/integration_tests_rust.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,17 +1135,17 @@ fn static_invoice_server() {
11351135
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
11361136
let chain_source = TestChainSource::Esplora(&electrsd);
11371137

1138-
let mut config_sender = random_config(true);
1138+
let config_sender = random_config(true);
11391139
let node_sender = setup_node(&chain_source, config_sender, None);
11401140

1141-
let mut config_sender_lsp = random_config(true);
1141+
let config_sender_lsp = random_config(true);
11421142
let node_sender_lsp = setup_node(&chain_source, config_sender_lsp, None);
11431143

11441144
let mut config_receiver_lsp = random_config(true);
11451145
config_receiver_lsp.node_config.async_payment_services_enabled = true;
11461146
let node_receiver_lsp = setup_node(&chain_source, config_receiver_lsp, None);
11471147

1148-
let mut config_receiver = random_config(true);
1148+
let config_receiver = random_config(true);
11491149
let node_receiver = setup_node(&chain_source, config_receiver, None);
11501150

11511151
let address_sender = node_sender.onchain_payment().new_address().unwrap();

0 commit comments

Comments
 (0)