Skip to content

fix: add realloc to cpi context account reinit ix#2034

Merged
ananas-block merged 1 commit intomainfrom
jorrit/test-remaining-cpi-context-account-capacity
Nov 10, 2025
Merged

fix: add realloc to cpi context account reinit ix#2034
ananas-block merged 1 commit intomainfrom
jorrit/test-remaining-cpi-context-account-capacity

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Nov 5, 2025

Changes:

  • realloc cpi context account to 14020 bytes from 20kb
  • add remaining cpi context account capacity assert to reinit cpi context account test

Context:

  • at 20kb size cpi context accounts have 12,968 bytes remaining capacity for output account data
  • these bytes are necessary to store compressed account data used in the cpi context
  • 12,968 bytes is greater than the light system program -> account compression program cpi can hold which is a footgun
  • with the realloc to 14020 bytes we reduce the remaining capacity to 6,500 that should work in most cases.
  • cpi context can support up to 30 output accounts with max 6,500 bytes account data eg 216 bytes per compressed account, or a number of smaller and bigger compressed accounts
  • The account data is stored to be exposed in the light system program -> account compression program cpi for the indexer.

Summary by CodeRabbit

  • New Features

    • Added account remaining-capacity reporting for clearer state visibility
  • Bug Fixes

    • Verify ownership before account resize to prevent unintended data truncation; preserve pre-read state during reinitialization
  • Chores

    • Switched CPI context account sizing to versioned constants (V1 deprecated, V2 active) and updated defaults
    • Expanded and enabled feature-gated tests to validate sizing and related flows

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

Walkthrough

Split the single CPI context size constant into a deprecated V1 alias and a new V2 constant; updated code to prefer V2, added an ownership check and pre-read before resizing the CPI context account, added a remaining_capacity() accessor, and enabled/adjusted several tests (including test-sbf gating and V1/V2 size assertions).

Changes

Cohort / File(s) Summary
Constants (versioning)
program-libs/batched-merkle-tree/src/constants.rs
Removed DEFAULT_CPI_CONTEXT_ACCOUNT_SIZE; added deprecated DEFAULT_CPI_CONTEXT_ACCOUNT_SIZE_V1 = 20 * 1024 + 8 and new DEFAULT_CPI_CONTEXT_ACCOUNT_SIZE_V2 = 14020.
Init flow & migration
program-libs/batched-merkle-tree/src/initialize_state_tree.rs, programs/system/src/accounts/init_context_account.rs
Switched usages to DEFAULT_CPI_CONTEXT_ACCOUNT_SIZE_V2; in init_context_account.rs added ownership verification, pre-read of associated_merkle_tree before resize, then resize to V2 and reinitialize using pre-read data.
Account API
programs/system/src/cpi_context/state.rs
Added pub fn remaining_capacity(&self) -> usize to ZCpiContextAccount2<'a>.
Registry default size
programs/registry/src/protocol_config/state.rs
Replaced hardcoded 20 * 1024 + 8 with DEFAULT_CPI_CONTEXT_ACCOUNT_SIZE_V2 in Default and testnet_default.
Tests: feature gating enabled
program-tests/compressed-token-test/tests/mint/failing.rs, program-tests/system-cpi-test/tests/test_cpi_context_event.rs, sdk-tests/sdk-pinocchio-v1-test/tests/test.rs, sdk-tests/sdk-token-test/tests/test.rs
Uncommented #![cfg(feature = "test-sbf")] to enable conditional compilation under test-sbf.
Tests: V1/V2 assertions & capacity
program-tests/system-test/tests/test_re_init_cpi_account.rs
Added references to V1/V2 sizes; assert pre-reinit size equals V1, post-reinit equals V2, and check remaining_capacity() equals expected value (6500).
Tests: insert size checks
program-libs/compressed-account/src/instruction_data/insert_into_queues.rs
Added unit tests exercising required_size_for_capacity across several capacity scenarios (printing/verifying sizes).

Sequence Diagram(s)

sequenceDiagram
  participant Handler as init_context_account handler
  participant CPI as cpi_context_account
  participant AMT as associated_merkle_tree

  Handler->>CPI: verify ownership
  Note right of CPI `#DDEEFF`: Ownership must be valid\nbefore any resize/truncation
  Handler->>CPI: read associated_merkle_tree (pre-read)
  Handler->>CPI: resize account to DEFAULT_CPI_CONTEXT_ACCOUNT_SIZE_V2
  Note right of Handler `#EFEFEF`: Uses V2 size constant\nand pre-read data to avoid loss
  Handler->>CPI: write/init with pre-read associated_merkle_tree
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to ordering and error handling in programs/system/src/accounts/init_context_account.rs (ownership check → pre-read → resize → reinit).
  • Verify deprecation annotation and numeric values in program-libs/batched-merkle-tree/src/constants.rs.
  • Confirm remaining_capacity() behavior and tests expecting 6500 in program-tests/system-test/tests/test_re_init_cpi_account.rs.

Possibly related PRs

  • chore: pre release #2014 — Introduces versioned V1/V2 constants and coordinated changes across batched-merkle-tree, registry, and system CPI/context code (closely related).

Suggested reviewers

  • sergeytimoshin
  • SwenSchaeferjohann

Poem

🐰 I hopped from V1 to V2 with a twitch,
Pre-read the roots before any glitch,
Sizes split neat, the constants set right,
Tests woke up and fluffed through the night,
A carrot of code — small, snug, and spry.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references 'realloc' and 'cpi context account reinit', which aligns with the primary change of reallocating the CPI context account from ~20 KB to 14,020 bytes, though it could be more specific about the size reduction.
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 jorrit/test-remaining-cpi-context-account-capacity

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 668d75e and 4da1aaa.

📒 Files selected for processing (11)
  • program-libs/batched-merkle-tree/src/constants.rs (1 hunks)
  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs (5 hunks)
  • program-libs/compressed-account/src/instruction_data/insert_into_queues.rs (1 hunks)
  • program-tests/compressed-token-test/tests/mint/failing.rs (1 hunks)
  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs (1 hunks)
  • program-tests/system-test/tests/test_re_init_cpi_account.rs (4 hunks)
  • programs/registry/src/protocol_config/state.rs (3 hunks)
  • programs/system/src/accounts/init_context_account.rs (2 hunks)
  • programs/system/src/cpi_context/state.rs (1 hunks)
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs (1 hunks)
  • sdk-tests/sdk-token-test/tests/test.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
  • programs/system/src/cpi_context/state.rs
  • program-libs/compressed-account/src/instruction_data/insert_into_queues.rs
  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • program-tests/compressed-token-test/tests/mint/failing.rs
🧰 Additional context used
📓 Path-based instructions (1)
sdk-tests/sdk-token-test/**/tests/**/*.rs

📄 CodeRabbit inference engine (sdk-tests/sdk-token-test/CLAUDE.md)

Every test should only contain functional integration tests

Files:

  • sdk-tests/sdk-token-test/tests/test.rs
🧠 Learnings (30)
📓 Common learnings
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Context structs for wrapper instructions must include standard accounts: optional registered_forester_pda (mut), authority Signer, cpi_authority with seeds/bump for CPI_AUTHORITY_PDA_SEED, registered_program_pda, target program handle, log_wrapper, and mutable target_account.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : CPI processing functions must derive PDA signer seeds as [CPI_AUTHORITY_PDA_SEED, bump] and use CpiContext::new_with_signer with cpi_authority as the authority account and mapped target accounts.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Each new operation module must define an Anchor context struct (e.g., NewOperationContext) with required accounts and a process_<operation> function that prepares signer seeds, maps accounts to the target program, and executes the CPI.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : Pass the data Vec<u8> through unchanged from the wrapper to the target program CPI; the target program performs deserialization.
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/**/Cargo.toml : Define features solana, pinocchio, and test-only in Cargo.toml; default build should enable none

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/{solana.rs,pinocchio.rs,test_account_info.rs} : Gate SDK-specific implementations with #[cfg(feature = "solana"|"pinocchio"|"test-only")]

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/registry/src/protocol_config/state.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/account_info_trait.rs : Ensure the crate compiles with no features enabled by keeping trait definitions free of SDK-specific dependencies

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • programs/registry/src/protocol_config/state.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/test_account_info.rs : Use the mock AccountInfo implementation under the test-only feature for unit tests

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Ensure serialization compatibility across Anchor, Pinocchio, and Borsh for core account types used by dependent programs

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/registry/src/protocol_config/state.rs
  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-15T03:46:43.242Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-token-test/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:43.242Z
Learning: Run tests with: cargo test-sbf -p sdk-token-test --test <test-file-name>

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/{solana.rs,pinocchio.rs,test_account_info.rs} : Provide SDK-specific AccountInfoTrait implementations in account_info/{solana.rs,pinocchio.rs,test_account_info.rs}

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/src/create_associated_token_account.rs : Create Associated Token Account instruction must validate that the config state is ACTIVE only

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/src/create_token_account.rs : Create Token Account instruction must validate that the config state is ACTIVE only

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/!(account_info)/**/*.rs : Use AccountInfoTrait for runtime-agnostic account handling; avoid direct solana-program or pinocchio AccountInfo in general logic

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/lib.rs : Wrapper instruction handlers must: (1) load the target account metadata; (2) call check_forester with correct authority, target, forester PDA (optional), and computed work_units; (3) delegate via a CPI using a PDA signer.

Applied to files:

  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-15T03:46:43.242Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-token-test/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:43.242Z
Learning: Applies to sdk-tests/sdk-token-test/**/tests/**/*.rs : Every test should only contain functional integration tests

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/**/*.rs : Validate account type with 8-byte discriminators using check_discriminator before deserialization

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Context structs for wrapper instructions must include standard accounts: optional registered_forester_pda (mut), authority Signer, cpi_authority with seeds/bump for CPI_AUTHORITY_PDA_SEED, registered_program_pda, target program handle, log_wrapper, and mutable target_account.

Applied to files:

  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/registry/src/protocol_config/state.rs
  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : CPI processing functions must derive PDA signer seeds as [CPI_AUTHORITY_PDA_SEED, bump] and use CpiContext::new_with_signer with cpi_authority as the authority account and mapped target accounts.

Applied to files:

  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/registry/src/protocol_config/state.rs
  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/discriminator.rs : Define and keep discriminator constants and the Discriminator trait in discriminator.rs for compile-time verification

Applied to files:

  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/mod.rs : Export each new operation module by adding pub mod <operation>; and re-export with pub use <operation>::*.

Applied to files:

  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/registry/src/protocol_config/state.rs
  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : Pass the data Vec<u8> through unchanged from the wrapper to the target program CPI; the target program performs deserialization.

Applied to files:

  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/registry/src/protocol_config/state.rs
  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Provide default initialization for the CToken V1 config in CompressibleConfig

Applied to files:

  • program-libs/batched-merkle-tree/src/constants.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Each new operation module must define an Anchor context struct (e.g., NewOperationContext) with required accounts and a process_<operation> function that prepares signer seeds, maps accounts to the target program, and executes the CPI.

Applied to files:

  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/registry/src/protocol_config/state.rs
  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/packed_accounts.rs : For dynamic account sets, use PackedAccounts for index-based access with bounds checks instead of manual indexing

Applied to files:

  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/registry/src/protocol_config/state.rs
  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/checks.rs : Expose and maintain account validation helpers (check_owner, check_program, check_mut/non_mut, check_signer, check_discriminator, set_discriminator, check_pda_seeds, check_account_balance_is_rent_exempt, account_info_init) in checks.rs

Applied to files:

  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Maintain CompressibleConfig account structure with Anchor/Borsh/Pod (Pinocchio/Pod) serialization and related state validation methods (validate_active, validate_not_inactive) in src/config.rs

Applied to files:

  • programs/registry/src/protocol_config/state.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/lib.rs : Load accounts according to type before check_forester: batched via BatchedMerkleTreeAccount::type_from_account_info(); regular via ctx.accounts.account.load()?.metadata; use custom deserialization when required.

Applied to files:

  • programs/registry/src/protocol_config/state.rs
  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_iterator.rs : Use AccountIterator for sequential account retrieval to get precise file:line:column error locations; avoid manual index handling

Applied to files:

  • programs/registry/src/protocol_config/state.rs
  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/lib.rs : Instruction handlers must compute work_units by operation type: batch operations use account.queue_batches.batch_size; single operations use DEFAULT_WORK_V1; custom operations compute based on complexity.

Applied to files:

  • programs/registry/src/protocol_config/state.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/**/*.rs : On account initialization, call account_info_init to set the 8-byte discriminator

Applied to files:

  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-11T21:59:52.712Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:52.712Z
Learning: Applies to program-libs/account-checks/docs/**/DISCRIMINATOR.md : DISCRIMINATOR.md must document 8-byte discriminators, the Discriminator trait, constant arrays for compile-time checks, and integration with account initialization

Applied to files:

  • programs/system/src/accounts/init_context_account.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/error.rs : Maintain stable mapping of AccountError to ProgramError, including Pinocchio code mapping (1–11), in error.rs

Applied to files:

  • programs/system/src/accounts/init_context_account.rs
🧬 Code graph analysis (2)
programs/system/src/accounts/init_context_account.rs (2)
program-libs/batched-merkle-tree/src/merkle_tree.rs (3)
  • BatchedMerkleTreeAccount (1080-1080)
  • BatchedMerkleTreeAccount (1090-1090)
  • BatchedMerkleTreeAccount (1100-1100)
program-libs/account-checks/src/checks.rs (1)
  • check_owner (135-143)
program-tests/system-test/tests/test_re_init_cpi_account.rs (1)
programs/system/src/cpi_context/state.rs (1)
  • remaining_capacity (78-80)
⏰ 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). (13)
  • GitHub Check: system-programs (sdk-libs, light-sdk-macros light-sdk light-program-test light-client light-compr...
  • GitHub Check: system-programs (token test, ["cargo-test-sbf -p sdk-token-test"])
  • GitHub Check: system-programs (native, ["cargo-test-sbf -p sdk-native-test", "cargo-test-sbf -p sdk-v1-native-t...
  • GitHub Check: system-programs (anchor & pinocchio, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -p sdk...
  • GitHub Check: cli-v1
  • GitHub Check: cli-v2
  • GitHub Check: stateless-js-v2
  • GitHub Check: stateless-js-v1
  • GitHub Check: Forester e2e test
  • GitHub Check: lint
  • GitHub Check: Test program-libs-slow
  • GitHub Check: Test batched-merkle-tree-simulate
  • GitHub Check: Test program-libs-fast
🔇 Additional comments (1)
programs/system/src/accounts/init_context_account.rs (1)

77-90: Solid guard before shrinking the account. Validating ownership on Line 78 before calling resize keeps us from accidentally reallocating someone else’s CPI context account; nice defensive addition.


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.

@ananas-block ananas-block changed the title test: add remaining cpi context account capacity assert fix: add realloc to cpi context account reinit ix Nov 5, 2025
@ananas-block ananas-block force-pushed the jorrit/test-remaining-cpi-context-account-capacity branch from 606091d to 704742b Compare November 5, 2025 17:37
@ananas-block ananas-block marked this pull request as ready for review November 5, 2025 17:37
@ananas-block ananas-block force-pushed the jorrit/test-remaining-cpi-context-account-capacity branch 2 times, most recently from 5e7d403 to 668d75e Compare November 5, 2025 18:36
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: 0

🧹 Nitpick comments (1)
programs/system/src/accounts/init_context_account.rs (1)

80-86: Consider adding discriminator validation before deserialization.

The pre-read of associated_merkle_tree before resizing is critical and correctly implemented to prevent data loss from truncation. However, consider adding discriminator validation before attempting to deserialize the account data, similar to how init_cpi_context_account validates the discriminator of associated_merkle_tree (lines 44-48).

Add discriminator validation before deserialization:

 // Read associated_merkle_tree BEFORE resizing (in case resize truncates data)
 let associated_merkle_tree = {
     let data = cpi_context_account.try_borrow_data()?;
+    
+    // Validate discriminator
+    let mut discriminator_bytes = [0u8; 8];
+    discriminator_bytes.copy_from_slice(&data[0..8]);
+    if discriminator_bytes != CpiContextAccount::LIGHT_DISCRIMINATOR {
+        return Err(SystemProgramError::InvalidDiscriminator.into());
+    }
+    
     CpiContextAccount::deserialize(&mut &data[8..])
         .map_err(|_| ProgramError::BorshIoError)?
         .associated_merkle_tree
 };

This would provide better error messages and prevent deserialization attempts on invalid account data.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e7d403 and 668d75e.

📒 Files selected for processing (11)
  • program-libs/batched-merkle-tree/src/constants.rs (1 hunks)
  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs (5 hunks)
  • program-libs/compressed-account/src/instruction_data/insert_into_queues.rs (1 hunks)
  • program-tests/compressed-token-test/tests/mint/failing.rs (1 hunks)
  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs (1 hunks)
  • program-tests/system-test/tests/test_re_init_cpi_account.rs (4 hunks)
  • programs/registry/src/protocol_config/state.rs (1 hunks)
  • programs/system/src/accounts/init_context_account.rs (2 hunks)
  • programs/system/src/cpi_context/state.rs (1 hunks)
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs (1 hunks)
  • sdk-tests/sdk-token-test/tests/test.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • program-tests/system-cpi-test/tests/test_cpi_context_event.rs
  • program-tests/system-test/tests/test_re_init_cpi_account.rs
  • program-tests/compressed-token-test/tests/mint/failing.rs
  • program-libs/batched-merkle-tree/src/constants.rs
  • programs/system/src/cpi_context/state.rs
  • program-libs/compressed-account/src/instruction_data/insert_into_queues.rs
🧰 Additional context used
📓 Path-based instructions (1)
sdk-tests/sdk-token-test/**/tests/**/*.rs

📄 CodeRabbit inference engine (sdk-tests/sdk-token-test/CLAUDE.md)

Every test should only contain functional integration tests

Files:

  • sdk-tests/sdk-token-test/tests/test.rs
🧠 Learnings (29)
📓 Common learnings
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : CPI processing functions must derive PDA signer seeds as [CPI_AUTHORITY_PDA_SEED, bump] and use CpiContext::new_with_signer with cpi_authority as the authority account and mapped target accounts.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Context structs for wrapper instructions must include standard accounts: optional registered_forester_pda (mut), authority Signer, cpi_authority with seeds/bump for CPI_AUTHORITY_PDA_SEED, registered_program_pda, target program handle, log_wrapper, and mutable target_account.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Each new operation module must define an Anchor context struct (e.g., NewOperationContext) with required accounts and a process_<operation> function that prepares signer seeds, maps accounts to the target program, and executes the CPI.
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : Pass the data Vec<u8> through unchanged from the wrapper to the target program CPI; the target program performs deserialization.

Applied to files:

  • programs/registry/src/protocol_config/state.rs
  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • programs/system/src/accounts/init_context_account.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Provide default initialization for the CToken V1 config in CompressibleConfig

Applied to files:

  • programs/registry/src/protocol_config/state.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/**/*.rs : CPI processing functions must derive PDA signer seeds as [CPI_AUTHORITY_PDA_SEED, bump] and use CpiContext::new_with_signer with cpi_authority as the authority account and mapped target accounts.

Applied to files:

  • programs/registry/src/protocol_config/state.rs
  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Context structs for wrapper instructions must include standard accounts: optional registered_forester_pda (mut), authority Signer, cpi_authority with seeds/bump for CPI_AUTHORITY_PDA_SEED, registered_program_pda, target program handle, log_wrapper, and mutable target_account.

Applied to files:

  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Ensure serialization compatibility across Anchor, Pinocchio, and Borsh for core account types used by dependent programs

Applied to files:

  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • programs/system/src/accounts/init_context_account.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/lib.rs : Load accounts according to type before check_forester: batched via BatchedMerkleTreeAccount::type_from_account_info(); regular via ctx.accounts.account.load()?.metadata; use custom deserialization when required.

Applied to files:

  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • programs/system/src/accounts/init_context_account.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/mod.rs : Export each new operation module by adding pub mod <operation>; and re-export with pub use <operation>::*.

Applied to files:

  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/**/*.rs : On account initialization, call account_info_init to set the 8-byte discriminator

Applied to files:

  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/!(account_info)/**/*.rs : Use AccountInfoTrait for runtime-agnostic account handling; avoid direct solana-program or pinocchio AccountInfo in general logic

Applied to files:

  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • sdk-tests/sdk-token-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/account_info_trait.rs : Ensure the crate compiles with no features enabled by keeping trait definitions free of SDK-specific dependencies

Applied to files:

  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • sdk-tests/sdk-token-test/tests/test.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/account_compression_cpi/*.rs : Each new operation module must define an Anchor context struct (e.g., NewOperationContext) with required accounts and a process_<operation> function that prepares signer seeds, maps accounts to the target program, and executes the CPI.

Applied to files:

  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-15T03:46:26.767Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/registry/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:26.767Z
Learning: Applies to programs/registry/src/lib.rs : Instruction handlers must compute work_units by operation type: batch operations use account.queue_batches.batch_size; single operations use DEFAULT_WORK_V1; custom operations compute based on complexity.

Applied to files:

  • program-libs/batched-merkle-tree/src/initialize_state_tree.rs
📚 Learning: 2025-10-15T03:46:43.242Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-token-test/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:43.242Z
Learning: Run tests with: cargo test-sbf -p sdk-token-test --test <test-file-name>

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/**/Cargo.toml : Define features solana, pinocchio, and test-only in Cargo.toml; default build should enable none

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-15T03:46:43.242Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: sdk-tests/sdk-token-test/CLAUDE.md:0-0
Timestamp: 2025-10-15T03:46:43.242Z
Learning: Applies to sdk-tests/sdk-token-test/**/tests/**/*.rs : Every test should only contain functional integration tests

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/{solana.rs,pinocchio.rs,test_account_info.rs} : Gate SDK-specific implementations with #[cfg(feature = "solana"|"pinocchio"|"test-only")]

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/test_account_info.rs : Use the mock AccountInfo implementation under the test-only feature for unit tests

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_info/{solana.rs,pinocchio.rs,test_account_info.rs} : Provide SDK-specific AccountInfoTrait implementations in account_info/{solana.rs,pinocchio.rs,test_account_info.rs}

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/src/create_token_account.rs : Create Token Account instruction must validate that the config state is ACTIVE only

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
📚 Learning: 2025-10-16T06:33:55.362Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:55.362Z
Learning: Applies to programs/compressed-token/program/src/create_associated_token_account.rs : Create Associated Token Account instruction must validate that the config state is ACTIVE only

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/**/*.rs : Validate account type with 8-byte discriminators using check_discriminator before deserialization

Applied to files:

  • sdk-tests/sdk-token-test/tests/test.rs
  • programs/system/src/accounts/init_context_account.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/checks.rs : Expose and maintain account validation helpers (check_owner, check_program, check_mut/non_mut, check_signer, check_discriminator, set_discriminator, check_pda_seeds, check_account_balance_is_rent_exempt, account_info_init) in checks.rs

Applied to files:

  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/packed_accounts.rs : For dynamic account sets, use PackedAccounts for index-based access with bounds checks instead of manual indexing

Applied to files:

  • programs/system/src/accounts/init_context_account.rs
  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/discriminator.rs : Define and keep discriminator constants and the Discriminator trait in discriminator.rs for compile-time verification

Applied to files:

  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-11T21:59:52.712Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:52.712Z
Learning: Applies to program-libs/account-checks/docs/**/DISCRIMINATOR.md : DISCRIMINATOR.md must document 8-byte discriminators, the Discriminator trait, constant arrays for compile-time checks, and integration with account initialization

Applied to files:

  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/error.rs : Maintain stable mapping of AccountError to ProgramError, including Pinocchio code mapping (1–11), in error.rs

Applied to files:

  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-11T21:59:25.222Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/CLAUDE.md:0-0
Timestamp: 2025-10-11T21:59:25.222Z
Learning: Applies to program-libs/account-checks/src/account_iterator.rs : Use AccountIterator for sequential account retrieval to get precise file:line:column error locations; avoid manual index handling

Applied to files:

  • programs/system/src/accounts/init_context_account.rs
📚 Learning: 2025-10-16T06:33:19.426Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-10-16T06:33:19.426Z
Learning: Applies to program-libs/compressible/src/config.rs : Maintain CompressibleConfig account structure with Anchor/Borsh/Pod (Pinocchio/Pod) serialization and related state validation methods (validate_active, validate_not_inactive) in src/config.rs

Applied to files:

  • sdk-tests/sdk-pinocchio-v1-test/tests/test.rs
🧬 Code graph analysis (1)
programs/system/src/accounts/init_context_account.rs (1)
program-libs/account-checks/src/checks.rs (1)
  • check_owner (135-143)
⏰ 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). (21)
  • GitHub Check: stateless-js-v2
  • GitHub Check: stateless-js-v1
  • GitHub Check: lint
  • GitHub Check: Test program-libs-slow
  • GitHub Check: Test batched-merkle-tree-simulate
  • GitHub Check: Test program-libs-fast
  • GitHub Check: cli-v2
  • GitHub Check: programs (system-cpi-test-v2-functional-account-infos, ["cargo-test-sbf -p system-cpi-v2-test -- ...
  • GitHub Check: programs (light-system-program-compression, ["cargo-test-sbf -p system-test -- test_with_compress...
  • GitHub Check: programs (system-cpi-test-v2-functional-read-only, ["cargo-test-sbf -p system-cpi-v2-test -- func...
  • GitHub Check: programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test", "cargo test -p light-system-prog...
  • GitHub Check: programs (compressed-token-and-e2e, ["cargo-test-sbf -p compressed-token-test --test v1", "cargo-...
  • GitHub Check: programs (account-compression-and-registry, ["cargo-test-sbf -p account-compression-test", "cargo...
  • GitHub Check: programs (compressed-token-batched-tree, ["cargo-test-sbf -p compressed-token-test -- test_transf...
  • GitHub Check: programs (light-system-program-address, ["cargo-test-sbf -p system-test -- test_with_address", "c...
  • GitHub Check: cli-v1
  • GitHub Check: system-programs (anchor & pinocchio, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -p sdk...
  • GitHub Check: Forester e2e test
  • GitHub Check: system-programs (token test, ["cargo-test-sbf -p sdk-token-test"])
  • GitHub Check: system-programs (native, ["cargo-test-sbf -p sdk-native-test", "cargo-test-sbf -p sdk-v1-native-t...
  • GitHub Check: system-programs (sdk-libs, light-sdk-macros light-sdk light-program-test light-client light-compr...
🔇 Additional comments (8)
sdk-tests/sdk-pinocchio-v1-test/tests/test.rs (1)

1-1: LGTM! Test-sbf feature gate enabled correctly.

The conditional compilation attribute is now active, allowing these tests to run with cargo test-sbf.

sdk-tests/sdk-token-test/tests/test.rs (1)

1-1: LGTM! Test-sbf feature gate enabled correctly.

The conditional compilation attribute is now active, consistent with the other SDK test modules in this PR.

programs/registry/src/protocol_config/state.rs (2)

60-60: Default CPI context size updated to V2.

The default cpi_context_size has been correctly updated to 14020 bytes, aligning with the PR objective to reduce the CPI context account size.


83-83: Verify testnet_default keeping the old CPI context size is intentional.

The testnet_default() function retains the old size of 20488 bytes while the standard default() uses the new 14020 bytes. This creates a divergence between environments that could lead to confusion or compatibility issues.

Please confirm:

  1. Is this intentional for backwards compatibility with existing testnet deployments?
  2. Are there migration plans for testnet to adopt the new V2 size?
  3. Could this divergence cause issues with code that expects consistent CPI context sizes across environments?
program-libs/batched-merkle-tree/src/initialize_state_tree.rs (1)

11-11: LGTM: Consistent migration to V2 CPI context size constant.

All usages of the CPI context size have been consistently updated to use DEFAULT_CPI_CONTEXT_ACCOUNT_SIZE_V2, including the default implementation and all test utilities. This ensures uniform behavior across initialization paths.

Also applies to: 50-50, 297-297, 317-317, 337-337

programs/system/src/accounts/init_context_account.rs (3)

6-8: LGTM: Import updated for V2 constant.

The import correctly includes DEFAULT_CPI_CONTEXT_ACCOUNT_SIZE_V2 alongside BatchedMerkleTreeAccount, supporting the new resize logic.


77-78: Good: Owner check added before realloc.

Adding the owner check before any modification operations prevents unauthorized accounts from reinitializing the CPI context account, which is a critical security improvement.


88-89: All realloc concerns are verified and correctly implemented.

The code properly handles the account size reduction:

  1. Size reduction is handled correctly: The associated_merkle_tree is read before resizing (lines 80-86), then the account is resized to 14020 bytes (line 89), and reinitialized with the preserved value (lines 91-93).

  2. Essential data fits within 14020 bytes: The test assertion at line 133 confirms that after reinitialization, remaining_capacity() == 6500, verifying all required data is properly allocated and the structure deserializes correctly.

  3. Remaining capacity calculation is correct: The constants show V1 size was 20488 bytes and V2 is 14020 bytes. The test explicitly validates that the remaining capacity equals 6500 bytes as per PR objectives, confirming the overhead calculation accounts for all metadata properly.

Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann left a comment

Choose a reason for hiding this comment

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

just one comment

@ananas-block ananas-block force-pushed the jorrit/test-remaining-cpi-context-account-capacity branch from 668d75e to 31f07f9 Compare November 7, 2025 22:29
@ananas-block ananas-block force-pushed the jorrit/test-remaining-cpi-context-account-capacity branch from 31f07f9 to 4da1aaa Compare November 7, 2025 22:30
@ananas-block ananas-block merged commit b81407f into main Nov 10, 2025
32 checks passed
@ananas-block ananas-block deleted the jorrit/test-remaining-cpi-context-account-capacity branch November 10, 2025 00:07
ananas-block added a commit that referenced this pull request Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants