Skip to content

fix: route unrefundable rent dust to the validator vault on undelegation - #274

Merged
GabrielePicco merged 1 commit into
mainfrom
fix/undelegate-rent-payer-dust
Nov 3, 2026
Merged

GabrielePicco merged 1 commit into
mainfrom
fix/undelegate-rent-payer-dust

Conversation

@GabrielePicco

@GabrielePicco GabrielePicco commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor
Status Type ⚠️ Core Change Issue
Ready Bug No n/a

Problem

On undelegation, process_delegation_cleanup takes min(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:

InsufficientFundsForRent { account_index: <rent payer> }

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:

  • empty rent payer: undelegate succeeds, the payer stays empty, the dust lands in the validator fees vault, protocol fee unchanged;
  • funded rent payer: behaviour unchanged, the dust is refunded to the payer.

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.
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between e616709 and 9aa57e6.

Files selected for processing: 2
  • src/processor/fast/utils/pda.rs
  • tests/test_undelegate_rent_payer_dust.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T09:09:54.916739Z 9aa57e6 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@GabrielePicco
GabrielePicco requested a review from snawaz November 3, 2026 09:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/processor/fast/utils/pda.rs Resolved

@snawaz snawaz left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Perfect fix!

Just for the context:

image

@GabrielePicco
GabrielePicco merged commit 0c551fa into main Nov 3, 2026
8 checks passed
@GabrielePicco
GabrielePicco deleted the fix/undelegate-rent-payer-dust branch November 3, 2026 09:22
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.

2 participants