Skip to content

feat(lightning): probe LND routing fees - #1095

Draft
a1denvalu3 wants to merge 4 commits into
cashubtc:mainfrom
a1denvalu3:feat/lnd-route-fee-estimation
Draft

feat(lightning): probe LND routing fees#1095
a1denvalu3 wants to merge 4 commits into
cashubtc:mainfrom
a1denvalu3:feat/lnd-route-fee-estimation

Conversation

@a1denvalu3

@a1denvalu3 a1denvalu3 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • query LND’s EstimateRouteFee API when creating full-invoice melt quotes
  • support both the REST and gRPC LND backends
  • use the probed route fee with the configured minimum reserve as a floor
  • fall back to the existing percentage/minimum reserve when probing fails
  • keep partial-MPP quotes on the existing reserve because LND’s invoice probe estimates the full invoice
  • add real multi-hop regtest coverage usable with both LND transports

Testing

  • make check
  • pytest -q tests/lightning/test_lightning_backends_mocked.py tests/lightning/test_fee_unit_regressions.py (37 passed)
  • real cashu-regtest LND 0.21 REST: test_lnd_payment_quote_uses_probed_fee (passed)
  • real cashu-regtest LND 0.21 gRPC: test_lnd_payment_quote_uses_probed_fee (passed)

The regtest requests a 100,000 sat CLN node 2 invoice that requires a multi-hop route from LND node 3. It asserts that the returned fee is non-zero and lower than the blind percentage-based reserve.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.67%. Comparing base (1853902) to head (f30a179).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
cashu/lightning/lnd_grpc/lnd_grpc.py 72.72% 3 Missing ⚠️
cashu/lightning/lndrest.py 76.92% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1095      +/-   ##
==========================================
+ Coverage   74.63%   74.67%   +0.03%     
==========================================
  Files         115      115              
  Lines       13200    13223      +23     
==========================================
+ Hits         9852     9874      +22     
- Misses       3348     3349       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@a1denvalu3
a1denvalu3 marked this pull request as draft July 23, 2026 17:33
@a1denvalu3

Copy link
Copy Markdown
Collaborator Author

Rationale for the updated fee handling:

EstimateRouteFee explicitly returns a lower bound, so using the probe result by itself as the melt fee reserve could underquote when LND ultimately selects a different or more expensive route. The quote now adds lightning_reserve_fee_min to the probed fee, using the configured base reserve as a buffer for route changes while still producing a substantially tighter quote than the blind percentage-based reserve.

At payment time, the mint already converts the stored quote reserve to msat and passes that exact value to LND as fee_limit_msat. This makes the user-visible quote an enforced upper limit: LND rejects routes above it before settlement. The regtest now pays the probed multi-hop invoice and verifies that the actual settled fee is less than or equal to the quoted limit. If probing fails or times out, behavior still falls back to the existing configured percentage-based reserve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant