Skip to content

fix: avoid msat truncation when paying invoices with built-in amounts#879

Open
ben-kaufman wants to merge 4 commits intomasterfrom
fix/msat-invoice-precision
Open

fix: avoid msat truncation when paying invoices with built-in amounts#879
ben-kaufman wants to merge 4 commits intomasterfrom
fix/msat-invoice-precision

Conversation

@ben-kaufman
Copy link
Copy Markdown
Contributor

Summary

  • Bump bitkit-core from 0.1.38 to v0.1.56 which rounds up sub-satoshi invoice amounts (ceiling division instead of floor)
  • Stop overriding the amount for invoices that already have one — pass null so LDK uses the invoice's native msat precision instead of our truncated sats value converted back to msat
  • Only pass the amount for zero-amount invoices where the user specifies it

Test plan

  • E2E: pay invoices created with lnd.addInvoice({ valueMsat }) using amounts 222538, 222222, 500500 msat
  • Verify zero-amount invoice flow still works
  • Verify LNURL pay flow still works
  • Verify quickpay flow still works

Depends on synonymdev/bitkit-core#85
Closes #877

🤖 Generated with Claude Code

Bump bitkit-core to v0.1.56 which rounds up sub-satoshi invoice amounts.

Additionally, stop overriding the amount for invoices that already have
one. Pass null so LDK uses the invoice's native msat precision instead
of our truncated sats value converted back to msat. Only pass the amount
for zero-amount invoices where the user specifies it.

Closes #877
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@claude

This comment has been minimized.

@ovitrif ovitrif added this to the 2.2.0 milestone Apr 1, 2026
Copy link
Copy Markdown
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

utAck
Will test too

@piotr-iohk
Copy link
Copy Markdown
Collaborator

Observations from testing:

1) The fix rounds up to full sats precision for the payment and display amount, so ln invoice with 500500 msats becomes 501 sats payment. In bitkit RN it seems that the displayed number of sats for such invoice still remains 500 - seems that, perhaps, Bitkit RN behind the scenes falls back to msats precision for the payment and just displays the floor sats amount. Just want to make sure we want that behaviour and not follow the Bitkit RN.
See example, for the 500500 invoice for Bitkit RN (left) and Bitkit android native:
Invoice generated with:

$ ./bitcoin-cli getlninvoice --msat 500500

from synonymdev/bitkit-e2e-tests#141.

Screen.Recording.2026-04-02.at.12.58.54.mov

2) There is an issue with lnurl-pay and and lnurl-withdrawal.

For testing on local regtest, more utility commands for bitcoin-cli can be used, added in synonymdev/bitkit-e2e-tests#141.

  LNURL (requires LNURL server, default: http://localhost:30001):
    startlnurlserver [--port N]        Start LNURL server using current e2e Bitcoin/LND
    stoplnurlserver                    Stop LNURL server container
    checklnurl                         Diagnose LNURL health, routing, and adb reverse
    getlnurlpay --msat N               Create LNURL-pay with fixed msat amount
    getlnurlwithdraw --msat N          Create LNURL-withdraw with fixed msat amount

$ ./bitcoin-cli startlnurlserver
$ ./bitcoin-cli checklnurl
$ ./bitcoin-cli getlnurlpay --msat 500500 
$ ./bitcoin-cli getlnurlwithdraw --msat 500500 

⚠️ lnurl-pay with msat precision shows 0 amount and cannot be paid. (Works on bitkit RN). The video is for lnurl-pay with 500500 msats $ ./bitcoin-cli getlnurlpay --msat 500500 - Bitkit RN on the left.

Screen.Recording.2026-04-02.at.13.53.59.mov

⚠️ lnurl-withdrawal with msat precision produces error toast. Video for $ ./bitcoin-cli getlnurlwithdraw --msat 500500 (note that lnurl-withdrawal with msat precision also doesn't seem to work properly on Bitkit RN - no error toast there, but the request not working)

Screen.Recording.2026-04-02.at.14.26.12.mov

@ovitrif ovitrif self-requested a review April 2, 2026 17:24
@claude
Copy link
Copy Markdown

claude bot commented Apr 2, 2026

Code review

1 issue found.


Missing CHANGELOG.md entry

This PR has a fix: prefix but does not include an update to CHANGELOG.md. Per CLAUDE.md:

ALWAYS add an entry under ## [Unreleased] in CHANGELOG.md for feat: and fix: PRs

Please add an entry under ## [Unreleased]### Fixed, for example:

### Fixed
- Avoid msat truncation when paying invoices with built-in amounts #879

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.

[Bug]: msat-precision invoices fail to send (regular BOLT11 + LNURL pay/withdraw)

3 participants