Skip to content

Conversation

@GabrielePicco
Copy link
Contributor

@GabrielePicco GabrielePicco commented Jan 6, 2026

Description

Allow delegation of not existing accounts by making them rent exempt

Summary by CodeRabbit

  • Bug Fixes
    • Delegated accounts that are newly-created with zero balance/data now automatically receive a rent-exemption transfer to prevent unintended deletion and improve account reliability during delegation.

✏️ Tip: You can customize this high-level summary in your review settings.

@GabrielePicco GabrielePicco requested a review from snawaz January 6, 2026 15:59
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2026

Walkthrough

Adds a new public constant RENT_EXCEPTION_ZERO_BYTES_LAMPORTS = 890880 and updates the fast delegate processor to import system instructions and transfer that amount from the payer to delegated accounts whose lamports and data length are both zero.

Changes

Cohort / File(s) Summary
Constants
src/consts.rs
Added public constant RENT_EXCEPTION_ZERO_BYTES_LAMPORTS: u64 = 890880 (placed after DELEGATION_PROGRAM_DATA_ID).
Fast delegate processor
src/processor/fast/delegate.rs
Imported pinocchio_system::instructions as system and the new constant; added runtime check and system::transfer + invoke to fund delegated accounts with zero lamports and zero data length.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is minimal and lacks required sections (Problem, Solution, Deploy Notes) from the repository template. Expand the description to include Problem section explaining why existing account delegation fails, Solution section detailing the rent-exemption approach, and Deploy Notes if applicable.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding support for delegation of non-existing accounts.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/allow-delegation-of-not-existing-accounts

📜 Recent review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf1e0e9 and 5911649.

📒 Files selected for processing (1)
  • src/processor/fast/delegate.rs
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-15T11:45:25.802Z
Learnt from: snawaz
Repo: magicblock-labs/delegation-program PR: 107
File: src/entrypoint.rs:141-144
Timestamp: 2025-10-15T11:45:25.802Z
Learning: In the delegation-program codebase, prefer using `log!` (from pinocchio_log) over `msg!` for error and panic scenarios in the entrypoint code, as per maintainer preference.

Applied to files:

  • src/processor/fast/delegate.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (1)
src/processor/fast/delegate.rs (1)

10-10: LGTM: Imports are correctly added.

The system instructions import and the rent exemption constant are properly used in the rent exemption logic below.

Also applies to: 13-13


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI Agents
In @src/consts.rs:
- Line 39: Replace the hardcoded RENT_EXCEPTION_ZERO_BYTES_LAMPORTS used in the
rent-exemption check for the delegated account with a dynamic calculation based
on the account's actual size: compute the minimum balance using
Rent::default().minimum_balance(delegated_account.data_len()) and use that value
when verifying or funding rent exemption (instead of the zero-byte constant) in
the rent-check logic that handles the delegated_account after data is copied
from the buffer.

In @src/processor/fast/delegate.rs:
- Around line 229-237: The rent-exemption flow is incorrect: don’t
unconditionally use RENT_EXCEPTION_ZERO_BYTES_LAMPORTS or capture
delegated_account.lamports() before determining final data size; instead, move
the rent calculation and potential top-up before updating the delegation record
and after you know the final data length (i.e., after copying data into the
buffer but before persisting the delegation state), compute required_rent using
the Rent sysvar (Rent::from_account_info or Rent::get()/fallback for tests)
based on delegated_account.data_len(), invoke a transfer only for (required_rent
- delegated_account.lamports()) when positive, and finally store the actual
lamports balance (delegated_account.lamports() post-top-up) into the delegation
record instead of the pre-top-up value to avoid state inconsistency.
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 467bdd9 and cf1e0e9.

📒 Files selected for processing (2)
  • src/consts.rs
  • src/processor/fast/delegate.rs
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-29T10:43:00.068Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/delegation-program PR: 90
File: tests/test_protocol_claim_fees.rs:30-30
Timestamp: 2025-10-29T10:43:00.068Z
Learning: In Solana test files using solana_program_test, use Rent::default() instead of Rent::get() because the Rent sysvar is not available in the test context. Rent::get() is only available in on-chain program execution.

Applied to files:

  • src/consts.rs
📚 Learning: 2025-10-15T11:45:25.802Z
Learnt from: snawaz
Repo: magicblock-labs/delegation-program PR: 107
File: src/entrypoint.rs:141-144
Timestamp: 2025-10-15T11:45:25.802Z
Learning: In the delegation-program codebase, prefer using `log!` (from pinocchio_log) over `msg!` for error and panic scenarios in the entrypoint code, as per maintainer preference.

Applied to files:

  • src/processor/fast/delegate.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: lint
🔇 Additional comments (1)
src/processor/fast/delegate.rs (1)

10-10: LGTM: Imports added for rent exemption feature.

The imports of system instructions and the rent exemption constant are correctly added to support the new functionality.

Also applies to: 13-13

@GabrielePicco GabrielePicco merged commit adddad7 into main Jan 6, 2026
4 checks passed
@GabrielePicco GabrielePicco deleted the fix/allow-delegation-of-not-existing-accounts branch January 6, 2026 21:43
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