Skip to content

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

Merged
ovitrif merged 2 commits intomasterfrom
fix/invoice-msat-precision
Apr 2, 2026
Merged

fix: round up sub-satoshi invoice amounts to prevent underpayment#85
ovitrif merged 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.

@ovitrif ovitrif self-requested a review April 2, 2026 15:22
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

@ovitrif ovitrif merged commit c902b5b into master Apr 2, 2026
3 of 4 checks passed
@ovitrif ovitrif deleted the fix/invoice-msat-precision branch April 2, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants