Skip to content

fix: apply reward routing budget to payouts - #2479

Open
keshav0479 wants to merge 5 commits into
RoboSats:mainfrom
keshav0479:fix/rewards-routing-budget-payment
Open

keshav0479 wants to merge 5 commits into
RoboSats:mainfrom
keshav0479:fix/rewards-routing-budget-payment

Conversation

@keshav0479

@keshav0479 keshav0479 commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Related to #1382. Follow-up to #2038 and #2364.

Reward invoice validation honored the submitted routing budget, but the actual payout still used the coordinator's default cap. Store the reward budget on the LNPayment and use that same absolute cap for validation and LND/CLN payment requests. Explicit budgets are deducted from the invoice amount; omitted or null budgets preserve the full reward amount and the default fee cap.

Preserve rewards credited during a withdrawal. Successful payouts increment claimed rewards without clearing new credits; confirmed failures restore the full reserved balance. Pending or unknown outcomes keep the reservation. Atomic reward credits and scoped robot settings/identity writes prevent stale objects from overwriting balances.

Widen the budget and paid-fee columns with migration 0060. A 100,000,000-sat accumulated balance with a 100,000-ppm budget needs a 10,000,000-sat cap, which overflowed the old budget column before payment. Both the cap and a fee at that cap now fit, so the returned fee can also be saved after success.

Update the reward tests to use the shared decoded-invoice format and import LND outside the CLN import mocks.

Correct the frontend fetch tests to accept the production minifier's optional HTML opening tag. The doctype, status, title, and bundle checks remain in place.

How tested

  • Coordinator CI: all 260 tests passed with LND v0.21.2-beta and all 260 with CLN v25.09.3, including live regtest trade flows. Python lint and all four CodeQL jobs passed on the same head.
  • python manage.py test api.tests --verbosity 2 --noinput: 171 tests passed with LND selected, using PostgreSQL and Redis.
  • LNVENDOR=CLN python manage.py test api.tests --shuffle 2479 --verbosity 2 --noinput: 171 tests passed.
  • 36 additional checks through generated gRPC clients, a loopback protocol server, real PGP signatures, and the reward view in a clean production dependency install. Covered both vendors, custom/default/zero caps, private route boundaries, large caps and fees, failed/pending payments, and credits during payment.
  • 20 rounds of eight simultaneous PostgreSQL withdrawals: exactly one payment per round. Checked stale login/settings writes and credits during payment on separate connections.
  • PostgreSQL migration upgrade and rollback with existing values, and python manage.py makemigrations --check --dry-run.
  • Repository lint with CI's Ruff 0.13.1, formatting of edited files, and git diff --check.
  • Frontend fetch tests against the exact current-main build artifact: two failures reproduced on base, both corrected tests passed.

The local gRPC server checks the application and wire requests; the passing coordinator CI suites cover live Lightning trade flows and HTLC settlement.

@KoalaSat

Copy link
Copy Markdown
Member

Ey @keshav0479 sorry for taking this long but the recent security fixed caused conflicts with this PR

@keshav0479
keshav0479 force-pushed the fix/rewards-routing-budget-payment branch from 7e7b24d to 8399975 Compare September 18, 2026 18:31
@keshav0479
keshav0479 requested a review from a team as a code owner September 18, 2026 18:31
@keshav0479

Copy link
Copy Markdown
Contributor Author

@KoalaSat updated this one too , now it should be fine

This branch has not been deployed

No deployments
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.

3 participants