Skip to content

[0.2] Reject offer_amount of 0 as invalid per BOLT 12#4488

Merged
TheBlueMatt merged 1 commit into
lightningdevkit:0.2from
TheBlueMatt:2026-03-4324-0.2
Mar 17, 2026
Merged

[0.2] Reject offer_amount of 0 as invalid per BOLT 12#4488
TheBlueMatt merged 1 commit into
lightningdevkit:0.2from
TheBlueMatt:2026-03-4324-0.2

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Per the spec clarification in lightning/bolts#1316:

  • Writers MUST set offer_amount greater than zero when present
  • Readers MUST NOT respond to offers where offer_amount is zero

Reject amount_msats(0) in the builder with InvalidAmount, and reject parsed offers with amount=0 (with or without currency) during TLV deserialization.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Backport of a06c446

Conflicts resolved in:

  • lightning/src/offers/offer.rs

Compared to the upstream commit, this instead allows downstream code to pass a 0 amount but converts it to no-amount to ensure upgraded readers of the built offer will accept it. This avoids changing the API in a backport.

Backport of #4324

@ldk-reviews-bot

ldk-reviews-bot commented Mar 17, 2026

Copy link
Copy Markdown

I've assigned @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Comment thread lightning/src/offers/offer.rs Outdated
@ldk-claude-review-bot

ldk-claude-review-bot commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator

No new issues found beyond the previously noted misleading test comment at line 1710. The logic changes are correct: deserialization properly rejects zero amounts (with and without currency), and the builder's silent 0→None conversion integrates cleanly with downstream checks (e.g., the description auto-set at build line 416).

@ldk-reviews-bot ldk-reviews-bot requested a review from jkczyz March 17, 2026 13:04
@codecov

codecov Bot commented Mar 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.87097% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (0695da9) to head (cb5cdd8).
⚠️ Report is 2 commits behind head on 0.2.

Files with missing lines Patch % Lines
lightning/src/offers/offer.rs 83.87% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              0.2    #4488   +/-   ##
=======================================
  Coverage   86.11%   86.11%           
=======================================
  Files         156      156           
  Lines       99922    99952   +30     
  Branches    99922    99952   +30     
=======================================
+ Hits        86051    86077   +26     
- Misses      11377    11382    +5     
+ Partials     2494     2493    -1     
Flag Coverage Δ
tests 86.11% <83.87%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Per the spec clarification in lightning/bolts#1316:
- Writers MUST set offer_amount greater than zero when present
- Readers MUST NOT respond to offers where offer_amount is zero

Reject amount_msats(0) in the builder with InvalidAmount, and reject
parsed offers with amount=0 (with or without currency) during TLV
deserialization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Backport of a06c446

Conflicts resolved in:
 * lightning/src/offers/offer.rs

Compared to the upstream commit, this instead allows downstream
code to pass a 0 amount but converts it to no-amount to ensure
upgraded readers of the built offer will accept it. This avoids
changing the API in a backport.
@TheBlueMatt TheBlueMatt merged commit 1fca0ab into lightningdevkit:0.2 Mar 17, 2026
22 of 25 checks passed
Comment on lines +405 to +407
if amount_msats == 0 {
$self.offer.amount = None;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IIUC, newly created Offers will be fine. But they won't be able to parse previously created Offers or corresponding InvoiceRequests that used Some(0) for the amount.

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.

5 participants