Skip to content

Commit 9cda45b

Browse files
authored
Remove sync_wallets from hot paths (#35)
sync_wallets() issues serial HTTP requests to Esplora (fee rate estimation, lightning tx sync across multiple block heights, BDK wallet sync). This blocks the NAPI thread for a few seconds via runtime.block_on(), which prevents the JS event loop from polling nextEvent() for incoming HTLCs. The 10+ second payment latency observed traces directly to this: the sender's HTLC sits unprocessed while the receiver node grinds through chain sync before the webhook handler can start its event loop. Removed sync_wallets from start_receiving, receive_payment, get_invoice, and execute_payment. Receiving HTLCs only needs a peer connection and channel manager, both provided by node.start(). Sending payments routes via the gossip graph with fee rates already cached by node.start(). LDK uses highest_seen_timestamp (set via best_block_updated) for inbound payment verification with a 2-hour grace window. A stale chain tip could cause valid payments to be rejected as expired.
1 parent 9aee191 commit 9cda45b

1 file changed

Lines changed: 1 addition & 18 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ impl MdkNode {
679679
///
680680
/// If `splice.enabled` is set on construction (the default), also spawns
681681
/// the auto-splice background task on the dedicated splice runtime.
682+
/// Start the node. Call once before polling for events.
682683
#[napi]
683684
pub fn start_receiving(&self) -> napi::Result<()> {
684685
self.node().start().map_err(|e| {
@@ -1050,11 +1051,6 @@ impl MdkNode {
10501051
return received_payments;
10511052
}
10521053

1053-
if let Err(err) = self.node().sync_wallets() {
1054-
eprintln!("[lightning-js] Failed to sync wallets: {err}");
1055-
panic!("failed to sync wallets: {err}");
1056-
}
1057-
10581054
let start_sync_at = std::time::Instant::now();
10591055
let mut last_event_time = start_sync_at;
10601056

@@ -1181,10 +1177,6 @@ impl MdkNode {
11811177
eprintln!("[lightning-js] Failed to start node for get_invoice: {err}");
11821178
panic!("failed to start node for get_invoice: {err}");
11831179
}
1184-
if let Err(err) = self.node().sync_wallets() {
1185-
eprintln!("[lightning-js] Failed to sync wallets: {err}");
1186-
panic!("failed to sync wallets: {err}");
1187-
}
11881180

11891181
let result = self.get_invoice_impl(Some(amount), description, expiry_secs);
11901182

@@ -1487,15 +1479,6 @@ impl MdkNode {
14871479
napi::Error::new(Status::GenericFailure, format!("failed to start node: {e}"))
14881480
})?;
14891481

1490-
// Sync wallets
1491-
if let Err(e) = self.node().sync_wallets() {
1492-
let _ = self.node().stop();
1493-
return Err(napi::Error::new(
1494-
Status::GenericFailure,
1495-
format!("failed to sync wallets: {e}"),
1496-
));
1497-
}
1498-
14991482
let result = self.execute_payment_impl(&payment_target, wait_secs);
15001483
let _ = self.node().stop();
15011484
result

0 commit comments

Comments
 (0)