Skip to content

Commit b120a03

Browse files
committed
f: add async services flag
1 parent 050d890 commit b120a03

File tree

6 files changed

+51
-31
lines changed

6 files changed

+51
-31
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dictionary Config {
1313
u64 probing_liquidity_limit_multiplier;
1414
AnchorChannelsConfig? anchor_channels_config;
1515
RouteParametersConfig? route_parameters;
16+
boolean async_payment_services_enabled;
1617
};
1718

1819
dictionary AnchorChannelsConfig {
@@ -318,6 +319,7 @@ enum NodeError {
318319
"LiquiditySourceUnavailable",
319320
"LiquidityFeeTooHigh",
320321
"InvalidBlindedPaths",
322+
"AsyncPaymentServicesDisabled",
321323
};
322324

323325
dictionary NodeStatus {

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ pub struct Config {
179179
/// **Note:** If unset, default parameters will be used, and you will be able to override the
180180
/// parameters on a per-payment basis in the corresponding method calls.
181181
pub route_parameters: Option<RouteParametersConfig>,
182+
/// Whether to enable the static invoice service to support async payment reception for clients.
183+
pub async_payment_services_enabled: bool,
182184
}
183185

184186
impl Default for Config {
@@ -193,6 +195,7 @@ impl Default for Config {
193195
anchor_channels_config: Some(AnchorChannelsConfig::default()),
194196
route_parameters: None,
195197
node_alias: None,
198+
async_payment_services_enabled: false,
196199
}
197200
}
198201
}

src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ pub enum Error {
122122
LiquidityFeeTooHigh,
123123
/// The given blinded paths are invalid.
124124
InvalidBlindedPaths,
125+
/// Asynchronous payment services are disabled.
126+
AsyncPaymentServicesDisabled,
125127
}
126128

127129
impl fmt::Display for Error {
@@ -196,6 +198,9 @@ impl fmt::Display for Error {
196198
write!(f, "The given operation failed due to the LSP's required opening fee being too high.")
197199
},
198200
Self::InvalidBlindedPaths => write!(f, "The given blinded paths are invalid."),
201+
Self::AsyncPaymentServicesDisabled => {
202+
write!(f, "Asynchronous payment services are disabled.")
203+
},
199204
}
200205
}
201206
}

src/event.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ where
458458
runtime: Arc<Runtime>,
459459
logger: L,
460460
config: Arc<Config>,
461-
static_invoice_store: StaticInvoiceStore,
461+
static_invoice_store: Option<StaticInvoiceStore>,
462462
}
463463

464464
impl<L: Deref + Clone + Sync + Send + 'static> EventHandler<L>
@@ -472,7 +472,7 @@ where
472472
output_sweeper: Arc<Sweeper>, network_graph: Arc<Graph>,
473473
liquidity_source: Option<Arc<LiquiditySource<Arc<Logger>>>>,
474474
payment_store: Arc<PaymentStore>, peer_store: Arc<PeerStore<L>>,
475-
static_invoice_store: StaticInvoiceStore, runtime: Arc<Runtime>, logger: L,
475+
static_invoice_store: Option<StaticInvoiceStore>, runtime: Arc<Runtime>, logger: L,
476476
config: Arc<Config>,
477477
) -> Self {
478478
Self {
@@ -1504,37 +1504,38 @@ where
15041504
recipient_id,
15051505
invoice_persisted_path,
15061506
} => {
1507-
match self
1508-
.static_invoice_store
1509-
.handle_persist_static_invoice(invoice, invoice_slot, recipient_id)
1510-
.await
1511-
{
1512-
Ok(_) => {},
1513-
Err(e) => {
1514-
log_error!(self.logger, "Failed to persist static invoice: {}", e);
1515-
},
1516-
};
1507+
if let Some(store) = self.static_invoice_store.as_ref() {
1508+
match store
1509+
.handle_persist_static_invoice(invoice, invoice_slot, recipient_id)
1510+
.await
1511+
{
1512+
Ok(_) => {},
1513+
Err(e) => {
1514+
log_error!(self.logger, "Failed to persist static invoice: {}", e);
1515+
},
1516+
};
15171517

1518-
self.channel_manager.static_invoice_persisted(invoice_persisted_path);
1518+
self.channel_manager.static_invoice_persisted(invoice_persisted_path);
1519+
}
15191520
},
15201521
LdkEvent::StaticInvoiceRequested { recipient_id, invoice_slot, reply_path } => {
1521-
let invoice = self
1522-
.static_invoice_store
1523-
.handle_static_invoice_requested(&recipient_id, invoice_slot)
1524-
.await;
1525-
1526-
match invoice {
1527-
Ok(Some(invoice)) => {
1528-
if let Err(e) =
1529-
self.channel_manager.send_static_invoice(invoice, reply_path)
1530-
{
1531-
log_error!(self.logger, "Failed to send static invoice: {:?}", e);
1532-
}
1533-
},
1534-
Ok(None) => {},
1535-
Err(e) => {
1536-
log_error!(self.logger, "Failed to retrieve static invoice: {}", e);
1537-
},
1522+
if let Some(store) = self.static_invoice_store.as_ref() {
1523+
let invoice =
1524+
store.handle_static_invoice_requested(&recipient_id, invoice_slot).await;
1525+
1526+
match invoice {
1527+
Ok(Some(invoice)) => {
1528+
if let Err(e) =
1529+
self.channel_manager.send_static_invoice(invoice, reply_path)
1530+
{
1531+
log_error!(self.logger, "Failed to send static invoice: {:?}", e);
1532+
}
1533+
},
1534+
Ok(None) => {},
1535+
Err(e) => {
1536+
log_error!(self.logger, "Failed to retrieve static invoice: {}", e);
1537+
},
1538+
}
15381539
}
15391540
},
15401541
LdkEvent::FundingTransactionReadyForSigning { .. } => {

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,11 @@ impl Node {
502502
Arc::clone(&self.logger),
503503
));
504504

505-
let static_invoice_store = StaticInvoiceStore::new(Arc::clone(&self.kv_store));
505+
let static_invoice_store = if self.config.async_payment_services_enabled {
506+
Some(StaticInvoiceStore::new(Arc::clone(&self.kv_store)))
507+
} else {
508+
None
509+
};
506510

507511
let event_handler = Arc::new(EventHandler::new(
508512
Arc::clone(&self.event_queue),
@@ -1506,6 +1510,10 @@ impl Node {
15061510
pub fn blinded_paths_for_async_recipient(
15071511
&self, recipient_id: Vec<u8>,
15081512
) -> Result<Vec<u8>, Error> {
1513+
if !self.config.async_payment_services_enabled {
1514+
return Err(Error::AsyncPaymentServicesDisabled);
1515+
}
1516+
15091517
let paths = self
15101518
.channel_manager
15111519
.blinded_paths_for_async_recipient(recipient_id, None)

tests/integration_tests_rust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ fn static_invoice_server() {
11451145

11461146
let mut config_receiver_lsp = random_config(true);
11471147
config_receiver_lsp.node_config.storage_dir_path = "/tmp/node_receiver_lsp".into();
1148+
config_receiver_lsp.node_config.async_payment_services_enabled = true;
11481149
let node_receiver_lsp = setup_node(&chain_source, config_receiver_lsp, None);
11491150

11501151
let mut config_receiver = random_config(true);

0 commit comments

Comments
 (0)