Skip to content

use update_chain_tip() instead of sync_wallets() for invoice creation#29

Merged
martinsaposnic merged 1 commit intomainfrom
mdk-536
Feb 18, 2026
Merged

use update_chain_tip() instead of sync_wallets() for invoice creation#29
martinsaposnic merged 1 commit intomainfrom
mdk-536

Conversation

@f3r10
Copy link
Contributor

@f3r10 f3r10 commented Feb 17, 2026

Replace the expensive start() + sync_wallets() + stop() cycle in
get_invoice() with the lightweight update_chain_tip() (~200ms vs seconds).
Also add update_chain_tip() calls to get_invoice_with_scid() and
get_variable_amount_jit_invoice_with_scid().

  • Add updateChainTip() NAPI binding and type declaration
  • Simplify get_invoice() to use update_chain_tip() (non-fatal on error)
  • Add chain tip update to scid-based invoice methods

moneydevkit/ldk-node@4974e8f

@f3r10 f3r10 requested a review from martinsaposnic February 17, 2026 12:31
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cdf53ec2d2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +798 to 801
if let Err(err) = self.node.update_chain_tip() {
eprintln!("[lightning-js] Failed to update chain tip for get_invoice: {err}");
// Non-fatal: invoice will still work if timestamp is recent enough (2h buffer)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate chain-tip update failures before issuing invoices

This code swallows update_chain_tip() failures even though the surrounding comment says the chain tip is needed for correct invoice-expiry calculation; when tip refresh fails after the node has been offline (for example during a temporary chain-source outage), invoice creation can proceed with stale chain time and produce invoices that are already near expiry or invalid for the requested expiry_secs. The previous start()+sync_wallets() flow failed fast in this scenario, so this should return an error (or fall back to a stronger sync) instead of continuing silently.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2h buffer means it's fine if the node was recently active, but if esplora is down AND the last persisted state is >2h old, we'd silently issue near-expired or invalid invoices. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be performed during pings right so it is likely that the state will remain fresh. Maybe we can also leverage that to detect issues here since I think we are using the ping as a healthcheck right? So if the ping syncs are failing we should notify ourselves.

@martinsaposnic martinsaposnic merged commit 66091bc into main Feb 18, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments