Repository navigation
fix: route unrefundable rent dust to the validator vault on undelegation - #274
Conversation
Since the 10x fee raise a session with no prior commit leaves 69,360 lamports of delegation rent after fees. Refunding that to a rent payer that holds no SOL would leave it rent-paying, so the runtime rejects the whole undelegate transaction with InsufficientFundsForRent and the account stays delegated on both layers. Keep the leftover in the validator fees vault whenever the rent payer cannot absorb it while staying rent-exempt. Funded rent payers are still refunded exactly as before.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. CodeRabbit Verify
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9aa57e6dee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Problem
On undelegation,
process_delegation_cleanuptakesmin(SESSION_FEE + COMMIT_FEE × commits, record + metadata rent)as fees and refunds whatever is left to the delegation rent payer.With the current fee levels that refund can be a few thousand lamports: a session with no prior commit, a 96-byte record and an 89-byte metadata (one 32-byte seed) has 3,069,360 lamports of rent, pays a 3,000,000 fee and refunds 69,360. If the rent payer holds no SOL, which is common when an app sponsors delegation and tops the payer up with exactly the rent, the refund would leave it rent-paying and the runtime rejects the whole transaction:
The undelegate then fails deterministically on every retry and the account stays delegated on the base layer while marked as undelegating on the ER.
Solution
In
close_pda_with_fees, after fees are taken, check whether the rent payer would still be rent-exempt after receiving the refund (Rent::get()for its data length). If not, add the refund to the validator fees vault instead of the rent payer. Funded rent payers keep receiving the refund exactly as before. The sysvar read only happens when there is a non-zero refund, so sessions whose fee consumes the whole rent pay no extra CU.Two regression tests in
tests/test_undelegate_rent_payer_dust.rs: