Skip to content

chore: remove vec length bytes from new instructions#1802

Merged
ananas-block merged 12 commits intomainfrom
jorrit/chore-optimize-instruction-data
Jun 15, 2025
Merged

chore: remove vec length bytes from new instructions#1802
ananas-block merged 12 commits intomainfrom
jorrit/chore-optimize-instruction-data

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Jun 14, 2025

Issue

  • new instructions invoke_cpi_with_read_only and invoke_cpi_with_account_info skipped 4 borsh vector length bytes of the instruction data. This is an unnecessary inefficiency.

Solution

  • remove the instruction_data[0..4] statements in the system program and adjust indexing (parse_light_transaction) accordingly.
  • The program and indexing relevant changes are commented with critical, other changes are changes to adapt tests.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected instruction data handling by adjusting discriminator lengths and serialization logic across multiple modules, ensuring consistent and accurate instruction parsing.
    • Fixed buffer slicing and deserialization offsets in both Rust and JavaScript code for improved compatibility and reliability.
  • Tests

    • Updated test cases and enabled conditional test compilation to reflect changes in instruction data formats and discriminator lengths.
  • Chores

    • Updated installation script to use a new revision of a Rust dependency.
  • Style

    • Minor formatting improvements in type definition files.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 14, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The updates adjust instruction deserialization offsets, discriminator lengths, and function signatures for typed instruction data across several Solana-related Rust programs. Manual instruction construction and invocation replace higher-level CPI abstractions in one test program. Serialization steps are streamlined and conditionalized, while feature flags are enabled for certain tests.

Changes

File(s) Change Summary
anchor-programs/system/src/lib.rs Expanded imports; changed invoke_cpi_with_read_only to accept a strongly typed input instead of Vec<u8>.
program-libs/compressed-account/src/indexer_event/parse.rs Adjusted instruction data slice offsets for deserialization; updated cases to skip 4 bytes after discriminator.
program-tests/create-address-test-program/src/lib.rs Replaced CPI context and call with manual instruction construction and invocation using signer seeds.
program-tests/sdk-pinocchio-test/tests/test.rs Enabled test code by uncommenting the #![cfg(feature = "test-sbf")] attribute.
program-tests/system-cpi-v2-test/tests/invoke_cpi_with_read_only.rs Shortened instruction discriminator arrays from 12 to 8 bytes in test transaction logic.
programs/compressed-token/src/process_transfer.rs Deferred or eliminated serialization of input struct based on feature flags; streamlined CPI preparation logic.
programs/system/src/lib.rs Removed slicing of first 4 bytes from instruction data before deserialization in two functions.
program-tests/system-cpi-test/src/create_pda.rs Changed invoke_cpi_with_read_only call to pass structured input directly instead of serialized bytes.
program-tests/system-cpi-v2-test/tests/event.rs Prefixed serialized instruction data with discriminator bytes before creating invoke CPI instruction.
forester/tests/address_v2_test.rs Prefixed serialized instruction data with discriminator bytes before creating invoke CPI instruction.
program-tests/utils/src/e2e_test_env.rs Prefixed serialized instruction data with discriminator bytes before creating invoke CPI instruction.
js/compressed-token/src/types.ts Removed a blank line between type declarations; no functional changes.
js/stateless.js/src/programs/system/layout.ts Added import of new discriminator constant; updated buffer slicing offset for decoding instruction data.
js/stateless.js/tests/unit/utils/conversion.test.ts Corrected test data by removing initial bytes to match updated deserialization offset.
scripts/install.sh Updated Git commit revision hash for Rust package "photon" installation.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ProgramA
    participant ProgramB

    Caller->>ProgramA: Call invoke_cpi_with_read_only(ctx, typed_inputs)
    ProgramA->>ProgramB: Construct Instruction with 8-byte discriminator + typed data
    ProgramA->>ProgramB: Invoke instruction (possibly with signer seeds)
    ProgramB-->>ProgramA: Process result
    ProgramA-->>Caller: Return result
Loading

Possibly related PRs

Suggested reviewers

  • sergeytimoshin
  • SwenSchaeferjohann

Poem

In bytes and types, we hop along,
Discriminators now eight bytes strong.
Serialization comes just in time,
CPI calls in perfect rhyme.
Feature flags now let tests run—
Hooray for code! The work is done.
🐇✨


📜 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 0b5508e and 3c51f17.

📒 Files selected for processing (1)
  • program-libs/compressed-account/src/indexer_event/parse.rs (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🔭 Outside diff range comments (1)
program-libs/compressed-account/src/indexer_event/parse.rs (1)

288-315: 🛠️ Refactor suggestion

Offset-handling now mixed between variants – risk of silent deserialization bugs

After switching to

let instruction = instruction.split_at(8).1;

you correctly drop the 8-byte discriminator, but the later branches treat the remaining buffer inconsistently:

  • DISCRIMINATOR_INVOKE / DISCRIMINATOR_INVOKE_CPI skip an additional 4 bytes (instruction[4..]).
  • DISCRIMINATOR_INVOKE_CPI_WITH_READ_ONLY / INVOKE_CPI_WITH_ACCOUNT_INFO_INSTRUCTION pass the buffer unshifted.

That implicit “4-byte length prefix” assumption is now replicated three times and can easily drift again. Consider:

- let instruction = instruction.split_at(8).1;
+ const LEN_PREFIX_BYTES: usize = 4;
+ let payload = &instruction[8..];

and then slice explicitly with &payload[LEN_PREFIX_BYTES..] in the affected branches (or zero in the others). Even better: introduce a small helper (fn payload_after_len(buf: &[u8]) -> Result<&[u8], ParseError>) to centralise the rule.

This removes magic numbers, hard-to-spot divergence, and future-proofs the parser.

🧹 Nitpick comments (2)
program-tests/system-cpi-v2-test/tests/invoke_cpi_with_read_only.rs (1)

3022-3025: Shorten instruction discriminators to 8 bytes and fix typo.

You’ve updated both discriminator arrays to 8 bytes to align with the new deserialization offset.

  • Confirm that there are no remaining 12-byte discriminators elsewhere in the codebase.
  • Correct the inline comment typo from “INSTRUCTIOM” to “INSTRUCTION.”
program-tests/create-address-test-program/src/lib.rs (1)

152-157: Minor: drop second anchor_lang::solana_program::log::sol_log_compute_units()

You log compute units both before and after instruction creation; the second call (immediately before the invoke) is still useful, but the first call (line 121) already prints the pre-CPI value. If both are required, consider naming them ("before_cpi" / "after_cpi") to ease log parsing.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4dae0f2 and 7958244.

📒 Files selected for processing (7)
  • anchor-programs/system/src/lib.rs (2 hunks)
  • program-libs/compressed-account/src/indexer_event/parse.rs (2 hunks)
  • program-tests/create-address-test-program/src/lib.rs (1 hunks)
  • program-tests/sdk-pinocchio-test/tests/test.rs (1 hunks)
  • program-tests/system-cpi-v2-test/tests/invoke_cpi_with_read_only.rs (1 hunks)
  • programs/compressed-token/src/process_transfer.rs (1 hunks)
  • programs/system/src/lib.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • programs/system/src/lib.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
programs/compressed-token/src/process_transfer.rs (3)
anchor-programs/system/src/lib.rs (1)
  • invoke_cpi_with_read_only (35-40)
programs/system/src/lib.rs (1)
  • invoke_cpi_with_read_only (133-147)
program-libs/compressed-account/src/instruction_data/with_readonly.rs (1)
  • from (49-68)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: test-2-foresters
  • GitHub Check: test-double-registration
  • GitHub Check: test-state-photon-batched
  • GitHub Check: test-address-batched
  • GitHub Check: test-e2e
  • GitHub Check: test-state-batched
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: system-programs (system-cpi-test-v2, ["cargo-test-sbf -p system-cpi-v2-test"])
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: Test sdk-libs
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: Test program-libs
  • GitHub Check: lint
  • GitHub Check: stateless-js
🔇 Additional comments (3)
program-tests/sdk-pinocchio-test/tests/test.rs (1)

1-1: Enable test module behind test-sbf feature.

You’ve uncommented the crate-level attribute to gate these tests under the test-sbf feature. Please verify that:

  • The test-sbf feature is declared in the Cargo.toml for this workspace.
  • CI/test runners enable --features test-sbf when executing these tests.
programs/compressed-token/src/process_transfer.rs (1)

458-458: Anchor CPI now uses typed inputs – confirm feature parity

Good catch updating the call to
light_system_program::cpi::invoke_cpi_with_read_only(cpi_ctx, inputs_struct).
Ensure that every caller of this function in the codebase migrated from the old Vec<u8> signature; otherwise you will have build-time type errors that CI will catch.

anchor-programs/system/src/lib.rs (1)

10-13: 👍 Moved to strongly-typed CPI inputs

Switching to explicit InstructionDataInvokeCpiWithReadOnly / ...WithAccountInfo improves type-safety and avoids the previous Vec<u8> foot-gun. No further concerns here.

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)
program-tests/system-cpi-test/src/create_pda.rs (1)

377-441: Avoid shadowing inputs_struct for readability

Inside the read-only branch you 1) build a mutable inputs_struct: InstructionDataInvokeCpi (lines 271-280) and 2) immediately shadow it with a new inputs_struct: InstructionDataInvokeCpiWithReadOnly (line 378).
Shadowing two structs with the same name but different types increases cognitive load.

-        let inputs_struct = InstructionDataInvokeCpiWithReadOnly {
+        let read_only_inputs = InstructionDataInvokeCpiWithReadOnly {
@@
-        light_system_program::cpi::invoke_cpi_with_read_only(cpi_ctx, inputs_struct)?;
+        light_system_program::cpi::invoke_cpi_with_read_only(cpi_ctx, read_only_inputs)?;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7958244 and 5d01d61.

📒 Files selected for processing (3)
  • js/compressed-token/src/types.ts (0 hunks)
  • program-tests/system-cpi-test/src/create_pda.rs (1 hunks)
  • programs/compressed-token/src/process_transfer.rs (1 hunks)
💤 Files with no reviewable changes (1)
  • js/compressed-token/src/types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • programs/compressed-token/src/process_transfer.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
program-tests/system-cpi-test/src/create_pda.rs (2)
anchor-programs/system/src/lib.rs (1)
  • invoke_cpi_with_read_only (35-40)
programs/system/src/lib.rs (1)
  • invoke_cpi_with_read_only (133-147)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: system-programs (system-cpi-test-v2, ["cargo-test-sbf -p system-cpi-v2-test"])
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: test-state-photon-batched
  • GitHub Check: test-2-foresters
  • GitHub Check: test-state-batched
  • GitHub Check: test-double-registration
  • GitHub Check: test-e2e
  • GitHub Check: test-address-batched
  • GitHub Check: lint
  • GitHub Check: stateless-js
  • GitHub Check: Test sdk-libs
  • GitHub Check: Test program-libs
  • GitHub Check: Test concurrent-merkle-tree
🔇 Additional comments (1)
program-tests/system-cpi-test/src/create_pda.rs (1)

441-441:

Details

✅ Verification successful

Confirm new CPI helper signature & serialization path

The call now forwards the typed InstructionDataInvokeCpiWithReadOnly struct instead of a serialized Vec<u8>.
This is correct only if every re-export (light_system_program::cpi::invoke_cpi_with_read_only) has already been updated to accept the typed value. The on-chain programs/system helper still takes &[u8], while the Anchor‐generated wrapper takes the struct, so a mismatch in crate versions will surface as a compile error.


🏁 Script executed:

#!/bin/bash
# Locate all `invoke_cpi_with_read_only` definitions and verify their parameter types
rg -A4 -n $'fn invoke_cpi_with_read_only' | sed -n '1,120p'

Length of output: 792


#!/bin/bash

List top‐level directories to locate the light_system_program crate

find . -maxdepth 2 -type d

Search for all references to light_system_program in the codebase

rg -n "light_system_program" || echo "No references found"


#!/bin/bash

Locate workspace and member crates

find . -maxdepth 3 -type f -name "Cargo.toml"

Find workspace reference to light_system_program

grep -R "light_system_program" -n Cargo.toml

Inspect the light_system_program crate root for cpi module declaration

sed -n '1,200p' crates/light_system_program/src/lib.rs

Inspect the cpi module file for invoke_cpi_with_read_only signature

if [[ -f crates/light_system_program/src/cpi.rs ]]; then
sed -n '1,200p' crates/light_system_program/src/cpi.rs
else
sed -n '1,200p' crates/light_system_program/src/cpi/mod.rs
fi


🏁 Script executed:

#!/bin/bash
# List all references to light_system_program to locate the crate path and usages
rg -n "light_system_program" -n .

# Inspect the cpi helper in the light_system_program crate (adjust path if needed)
if [[ -f crates/light-system-program/src/cpi.rs ]]; then
  sed -n '1,200p' crates/light-system-program/src/cpi.rs
elif [[ -d crates/light-system-program/src/cpi ]]; then
  sed -n '1,200p' crates/light-system-program/src/cpi/mod.rs
fi

Length of output: 36608


CPI helper signature confirmed – no changes needed

  • In anchor-programs/system/src/lib.rs, invoke_cpi_with_read_only now takes a typed InstructionDataInvokeCpiWithReadOnly.
  • The on-chain helper in programs/system/src/lib.rs still expects raw &[u8], and the Anchor wrapper serializes the struct under the hood.
  • Your call in program-tests/system-cpi-test/src/create_pda.rs:441 correctly passes the typed struct to the wrapper.
  • Just ensure your on-chain program and client (Anchor wrapper) dependencies stay on matching versions to avoid compilation mismatches.

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 (2)
program-tests/system-cpi-v2-test/tests/event.rs (2)

5-5: Unused Discriminator import – please remove or use

Discriminator is imported but never referenced in this module, which will trigger the unused_imports lint (or a hard error if #![deny(warnings)] is active anywhere in the workspace).
Drop the import or leverage InvokeCpiWithReadOnly::discriminator() instead of hard-coding the byte array below.


725-729: Avoid extra allocations & unwrap() in instruction-data assembly

  1. [vec1, vec2].concat() allocates twice: once for each Vec::to_vec() and once more for concat().
  2. ix_data.try_to_vec().unwrap() will panic on serialization failure, masking bugs.

A small refactor eliminates both issues:

-        [
-            light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR.to_vec(),
-            ix_data.try_to_vec().unwrap(),
-        ]
-        .concat(),
+        {
+            // start with the 8-byte discriminator and append the serialized payload
+            let mut data =
+                light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR.to_vec();
+            data.extend(
+                ix_data
+                    .try_to_vec()
+                    .expect("`ix_data` Borsh serialization should not fail"),
+            );
+            data
+        },

Benefits: single allocation, clearer failure message, and it gives you an obvious hook (?) if you later choose to propagate the error instead of panicking.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d01d61 and f25a9c0.

📒 Files selected for processing (2)
  • program-tests/create-address-test-program/src/lib.rs (1 hunks)
  • program-tests/system-cpi-v2-test/tests/event.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • program-tests/create-address-test-program/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: test-2-foresters
  • GitHub Check: test-double-registration
  • GitHub Check: test-state-batched
  • GitHub Check: test-state-photon-batched
  • GitHub Check: test-e2e
  • GitHub Check: test-address-batched
  • GitHub Check: stateless-js
  • GitHub Check: Test program-libs
  • GitHub Check: Test sdk-libs
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: lint
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: system-programs (system-cpi-test-v2, ["cargo-test-sbf -p system-cpi-v2-test"])
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])

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: 1

🧹 Nitpick comments (2)
js/stateless.js/tests/unit/utils/conversion.test.ts (1)

84-88: Prefer using the real discriminator constant instead of hard-coded bytes

The first eight bytes in the fixture represent the discriminator but are currently hard-coded as [1, 0, 0, 0, 1, 0, 0, 0], which does not match the canonical
INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR ([86, 47, 163, 166, 21, 223, 92, 8]).
Using the actual constant makes the test self-documenting and ensures it breaks if the discriminator ever changes.

-        // first 8 bytes are skipped.
-        const data = [
-            1, 0, 0, 0, 1, 0, 0, 0,
+        // prepend the actual discriminator, then the serialized body
+        const data = [
+            ...INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR,

(remember to import { INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR } from '../../../src/constants';)

forester/tests/address_v2_test.rs (1)

398-403: Reduce needless allocations when prefixing the discriminator

[ … ].concat() allocates two intermediate Vec<u8> instances (one from
DISCRIMINATOR.to_vec(), one from concat()).
You can build the vector in a single pass and avoid the extra copy:

-    [
-        light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR.to_vec(),
-        ix_data.try_to_vec()?,
-    ]
-    .concat(),
+    {
+        let mut bytes = Vec::with_capacity(
+            light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR.len()
+                + ix_data.try_to_vec()?.len(),
+        );
+        bytes.extend_from_slice(
+            &light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR,
+        );
+        bytes.extend(ix_data.try_to_vec()?);
+        bytes
+    },

Not critical for tests, but keeps memory churn down if this path is exercised often.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f25a9c0 and 3b3df54.

📒 Files selected for processing (5)
  • anchor-programs/system/src/lib.rs (2 hunks)
  • forester/tests/address_v2_test.rs (1 hunks)
  • js/stateless.js/src/programs/system/layout.ts (2 hunks)
  • js/stateless.js/tests/unit/utils/conversion.test.ts (1 hunks)
  • program-tests/utils/src/e2e_test_env.rs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • program-tests/utils/src/e2e_test_env.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • anchor-programs/system/src/lib.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
js/stateless.js/src/programs/system/layout.ts (1)
js/stateless.js/src/constants.ts (1)
  • INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR (46-48)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: test-2-foresters
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: test-double-registration
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: test-address-batched
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: test-state-batched
  • GitHub Check: system-programs (system-cpi-test-v2, ["cargo-test-sbf -p system-cpi-v2-test"])
  • GitHub Check: test-state-photon-batched
  • GitHub Check: test-e2e
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: stateless-js
  • GitHub Check: Test sdk-libs
  • GitHub Check: lint
  • GitHub Check: Test program-libs
  • GitHub Check: Test concurrent-merkle-tree

instruction_data: &[u8],
) -> Result<()> {
msg!("invoke_cpi_with_account_info");
let instruction_data = &instruction_data[4..];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

critical

data.extend_from_slice(
&light_compressed_account::discriminators::DISCRIMINATOR_INVOKE_CPI_WITH_READ_ONLY,
);
data.extend_from_slice(&(inputs.len() as u32).to_le_bytes());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

critical

let accounts = accounts.split_at(11).1;
let data = crate::instruction_data::invoke_cpi::InstructionDataInvokeCpi::deserialize(
&mut &instruction[..],
&mut &instruction[4..],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

critical for indexing.
Here we are eliminating skip vec size bytes for the new instructions and keeping it for the old instructions.

accounts: &[AccountInfo],
instruction_data: &[u8],
) -> Result<()> {
let instruction_data = &instruction_data[4..];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

critical

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.

LGTM overall. do we still have a test with a caller program using the old invoke_cpi with the 4 bytes?

Co-authored-by: Swen Schäferjohann <42959314+SwenSchaeferjohann@users.noreply.github.com>
@ananas-block ananas-block merged commit 55ee3cd into main Jun 15, 2025
24 of 25 checks passed
@ananas-block ananas-block deleted the jorrit/chore-optimize-instruction-data branch June 15, 2025 14:34
@coderabbitai coderabbitai bot mentioned this pull request Jun 30, 2025
@coderabbitai coderabbitai bot mentioned this pull request Sep 21, 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