Skip to content

fix: round up sub-satoshi invoice amounts to prevent underpayment#85

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

fix: round up sub-satoshi invoice amounts to prevent underpayment#85
ben-kaufman wants to merge 2 commits intomasterfrom
fix/invoice-msat-precision

Conversation

@ben-kaufman
Copy link
Copy Markdown
Collaborator

Summary

  • Lightning invoices with millisatoshi precision (e.g. 18557538 msat = 18557.538 sats) were truncated by floor division to 18557 sats, causing sendUsingAmount to send 18557000 msat — less than the invoice requires — and LDK to reject the payment.
  • Changed amount_satoshis from floor (/ 1000) to ceiling (div_ceil(1000)) so the sats value always covers the invoice's msat amount.
  • Added unit tests covering the original failure, sub-satoshi remainders (above/below/equal .5), exact sat amounts, and boundary cases.

Test plan

  • cargo test scanner — 19 tests pass
  • E2E: pay invoices created with lnd.addInvoice({ valueMsat }) using amounts 222538, 222222, 500500 msat
  • Verify exact-sat invoices are unaffected

Closes synonymdev/bitkit-ios#511
Closes synonymdev/bitkit-android#877

🤖 Generated with Claude Code

Lightning invoices can have millisatoshi precision (e.g. 18557538 msat =
18557.538 sats). The previous floor division (/ 1000) truncated this to
18557 sats, causing payments to fail when the app converted back to msat
(18557000 < 18557538 required).

Use ceiling division (div_ceil) so amount_satoshis is always sufficient
to cover the invoice's msat amount.

Closes synonymdev/bitkit-ios#511
Closes synonymdev/bitkit-android#877
@claude
Copy link
Copy Markdown

claude bot commented Apr 1, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

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

Labels

None yet

Projects

None yet

1 participant