Skip to content

Conversation

@snawaz
Copy link

@snawaz snawaz commented Oct 15, 2025

This PR does the following things:

  • Implements a new instruction MagicBlockInstruction::ScheduleCommitDiffAndUndelegate that is very similar to the existing ScheduleCommitAndUndelegate except that it invokes CommitDiff instruction in the delegation-program.
    • This is effectively an optimization that reduces the amount of data transferred when committing account changes, which improves performance and reduces costs, especially for large accounts with minimal changes between commits.
    • The diff is sent over args, not buffer account.
  • Adds test using a large OrderBook account (10 KB). I initially wanted to try a few MB, but realized currently that’s not possible yet.
    • After 13 book updates , CommitDiff was invoked (in the delegation-program) with only diff len = 286 whereas data len = 10240 (see first screenshot).
    • When there’s no diff, CommitDiff still runs with diff len = 8 (encoding the size of account on ER and the number of offset-pairs), and logs a warning (see second screenshot).
    • In the zero-diff case, we could optimize for an early return, though currently it seems we cannot.. since Finalize and Undelegate still depend on Commit running fully.
image image

Summary by CodeRabbit

  • New Features

    • Commit-diff support for scheduled commits (including diff+undelegate flows) and new instructions to trigger them
    • Order book subsystem: init, grow, update, and order-book-specific scheduling/commit paths
  • Chores

    • Switched several dependencies to local workspace paths and added test/runtime helper crates for integration tests

Copy link
Author

snawaz commented Oct 15, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Replaces git-sourced dependencies with local path dependencies; adds commit_diff support propagated through scheduling, sent commits, committor tasks, and instructions; introduces order-book data structures and CPI paths; updates test infrastructure, contexts, and several integration tests.

Changes

Cohort / File(s) Summary
Dependency Management
Cargo.toml, test-integration/Cargo.toml, test-integration/programs/schedulecommit/Cargo.toml
Replaced git-based crates with local path dependencies (delegation-program, ephemeral-rollups-sdk); added workspace/test deps rkyv and static_assertions.
Scheduled Commit Infrastructure
magicblock-accounts/src/scheduled_commits_processor.rs, programs/magicblock/src/magic_scheduled_base_intent.rs, programs/magicblock/src/schedule_transactions/process_schedule_commit.rs, programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs
Propagate commit_diff flag: add commit_diff to ScheduledBaseIntentMeta and SentCommit, add is_commit_diff() accessors, introduce CommitType::StandaloneDiff(...) and choose commit type when request_diff is set.
Instruction Definitions / Processor
magicblock-magic-program-api/src/instruction.rs, programs/magicblock/src/magicblock_processor.rs
Added ScheduleCommitDiffAndUndelegate instruction variant; extended ProcessScheduleCommitOptions with request_diff: bool; wired new instruction to call schedule commit with request_diff = true.
Committor Service Task Handling
magicblock-committor-service/src/tasks/args_task.rs, magicblock-committor-service/src/tasks/task_builder.rs, magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs, magicblock-committor-service/src/tasks/mod.rs
Added ArgsTaskType::CommitDiff(CommitTask) and commit-diff branching in task_builder; compute_diff/RPC path introduced for CommitDiff instruction generation; persistor updated to handle both Commit and CommitDiff variants; minor docs/TODO comments added.
Order Book Implementation
test-integration/programs/schedulecommit/src/order_book.rs
New zero-copy in-place OrderBook: OrderLevel, BookUpdate, OrderBookHeader, OrderBookOwned, and OrderBook<'a> with add/update/access APIs and Borsh deserialization.
Order Book API & Integration
test-integration/programs/schedulecommit/src/api.rs, test-integration/programs/schedulecommit/src/lib.rs, test-integration/programs/schedulecommit/src/utils/mod.rs
New instruction constructors for order-book (init/grow/update/schedule_commit_diff_for_order_book); delegate_account_cpi_instruction now accepts user_seed and branches to DelegateOrderBook vs DelegateCpi; added DelegateOrderBookArgs; changed AllocateAndAssignAccountArgs.size from usize to u64 and updated allocation calls.
Test Context & Utilities
test-integration/schedulecommit/client/src/schedule_commit_context.rs, test-integration/schedulecommit/client/src/verify.rs, test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs, test-integration/test-tools/src/integration_test_context.rs, test-integration/test-tools/src/scheduled_commits.rs
ScheduleCommitTestContext gains user_seed plumbing and constructors require seed; PDA derivation switched to find_program_address([user_seed, payer_ephem]); compute-budget instructions prefixed in init_committees; added fetch_and_verify_order_book_commit_result_from_logs; fetch_logs now requires an RPC client (panics if missing); improved ephemeral logs naming and debug prints.
Test Scenarios & Fixtures
test-integration/schedulecommit/test-scenarios/tests/01_commits.rs, .../02_commit_and_undelegate.rs, .../03_commits_fee_payer.rs, test-integration/test-ledger-restore/tests/08_commit_update.rs, test-integration/schedulecommit/test-scenarios/Cargo.toml, test-integration/schedulecommit/test-scenarios/tests/01_commits.rs, test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs
Updated tests to pass user_seed (e.g., b"magic_schedule_commit"); added large order-book test and helper commit_and_undelegate_order_book_account; added fee-payer tests; adjusted helper signatures and genericized asserts; added rand and borsh dev-deps; updated some return-value destructuring in ledger-restore test.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Magicblock as Magicblock Program
    participant Committor as Committor Service

    Client->>Magicblock: ScheduleCommitDiffAndUndelegate (request_diff=true)
    activate Magicblock
    Magicblock->>Magicblock: process_schedule_commit(opts.request_diff=true)
    Magicblock->>Magicblock: choose CommitType = StandaloneDiff(committed_accounts)
    Magicblock->>Magicblock: build ScheduledBaseIntent (commit_diff = true)
    Magicblock->>Magicblock: create SentCommit(commit_diff = true)
    deactivate Magicblock
    Magicblock-->>Client: ack scheduled

    Client->>Committor: pick up scheduled commit
    activate Committor
    Committor->>Committor: match ArgsTaskType
    alt commit_diff == true
        Committor->>Committor: compute_diff() via RPC -> Build CommitDiffArgs -> emit commit_diff instruction
    else
        Committor->>Committor: build CommitStateArgs -> emit commit_state instruction
    end
    deactivate Committor
    Committor-->>Client: commit processed
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas requiring extra attention:

  • order_book.rs — unsafe pointer/zero-copy invariants and Borsh integration
  • commit_diff propagation across scheduled_commits_processor, SentCommit, and committor task paths
  • user_seed PDA derivation changes in schedule_commit_context.rs (on-chain PDA compatibility)
  • delegate branching between DelegateCpi and DelegateOrderBook (api.rs / lib.rs)
  • size/type changes (usize -> u64) for allocation and account sizing

Possibly related PRs

Suggested reviewers

  • GabrielePicco
  • Dodecahedr0x
  • taco-paco

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.21% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "feat: Add ScheduleCommitDiffAndUndelegate to efficiently commit changes in delegated accounts" directly corresponds to the primary feature being implemented. The changeset indeed adds a new MagicBlockInstruction::ScheduleCommitDiffAndUndelegate variant across multiple files, implements supporting infrastructure for diff-based commits (including CommitType::StandaloneDiff and is_commit_diff() methods), and extends the processor to handle this new instruction. The title is specific and clear, avoiding vague terms, and accurately summarizes the main optimization objective: enabling efficient, diff-based account changes rather than full account data transfers. While the PR includes OrderBook functionality for testing, the title appropriately focuses on the primary instruction feature as stated in the PR objectives.

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.

@snawaz snawaz force-pushed the snawaz/commit-diff branch 6 times, most recently from 249b1aa to 2f0555f Compare October 23, 2025 15:45
@snawaz snawaz force-pushed the snawaz/commit-diff branch 2 times, most recently from 0151da0 to 5c25e73 Compare October 27, 2025 06:13
@snawaz snawaz changed the title Add ScheduleCommitDiffAndUndelegate Add MagicBlockInstruction::ScheduleCommitDiffAndUndelegate to efficiently commit changes in delegated accounts Oct 27, 2025
@snawaz snawaz changed the title Add MagicBlockInstruction::ScheduleCommitDiffAndUndelegate to efficiently commit changes in delegated accounts Add ScheduleCommitDiffAndUndelegate to efficiently commit changes in delegated accounts Oct 27, 2025
@snawaz snawaz force-pushed the snawaz/commit-diff branch 2 times, most recently from 2ae750b to 725f72c Compare October 27, 2025 09:45
@github-actions
Copy link

github-actions bot commented Oct 27, 2025

Manual Deploy Available

You can trigger a manual deploy of this PR branch to testnet:

Deploy to Testnet 🚀

Alternative: Comment /deploy on this PR to trigger deployment directly.

⚠️ Note: Manual deploy requires authorization. Only authorized users can trigger deployments.

Comment updated automatically when the PR is synchronized.

@snawaz snawaz force-pushed the snawaz/commit-diff branch from 725f72c to e5c5e15 Compare October 27, 2025 16:55
@snawaz snawaz changed the title Add ScheduleCommitDiffAndUndelegate to efficiently commit changes in delegated accounts featAdd ScheduleCommitDiffAndUndelegate to efficiently commit changes in delegated accounts Oct 27, 2025
@snawaz snawaz changed the title featAdd ScheduleCommitDiffAndUndelegate to efficiently commit changes in delegated accounts feat: Add ScheduleCommitDiffAndUndelegate to efficiently commit changes in delegated accounts Oct 27, 2025
@snawaz snawaz marked this pull request as ready for review October 28, 2025 14:52
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: 29

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
magicblock-committor-service/src/tasks/args_task.rs (1)

229-237: reset_commit_id ignores CommitDiff—update both variants.

Commit IDs must update for Commit and CommitDiff.

Apply:

-        let ArgsTaskType::Commit(commit_task) = &mut self.task_type else {
-            log::error!("reset_commit_id");
-            return;
-        };
-
-        commit_task.commit_id = commit_id;
+        match &mut self.task_type {
+            ArgsTaskType::Commit(task) | ArgsTaskType::CommitDiff(task) => {
+                task.commit_id = commit_id;
+            }
+            _ => {}
+        }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1dfd59 and e5c5e15.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • test-integration/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (28)
  • Cargo.toml (1 hunks)
  • magicblock-accounts/src/scheduled_commits_processor.rs (3 hunks)
  • magicblock-committor-service/src/tasks/args_task.rs (6 hunks)
  • magicblock-committor-service/src/tasks/mod.rs (1 hunks)
  • magicblock-committor-service/src/tasks/task_builder.rs (3 hunks)
  • magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs (1 hunks)
  • magicblock-magic-program-api/src/instruction.rs (1 hunks)
  • magicblock-rpc-client/src/lib.rs (1 hunks)
  • programs/magicblock/src/magic_scheduled_base_intent.rs (7 hunks)
  • programs/magicblock/src/magicblock_processor.rs (4 hunks)
  • programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2 hunks)
  • programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs (5 hunks)
  • test-integration/Cargo.toml (2 hunks)
  • test-integration/programs/schedulecommit-security/src/lib.rs (2 hunks)
  • test-integration/programs/schedulecommit/src/api.rs (5 hunks)
  • test-integration/programs/schedulecommit/src/lib.rs (9 hunks)
  • test-integration/programs/schedulecommit/src/order_book.rs (1 hunks)
  • test-integration/programs/schedulecommit/src/utils/mod.rs (3 hunks)
  • test-integration/schedulecommit/client/src/schedule_commit_context.rs (6 hunks)
  • test-integration/schedulecommit/client/src/verify.rs (2 hunks)
  • test-integration/schedulecommit/test-scenarios/Cargo.toml (1 hunks)
  • test-integration/schedulecommit/test-scenarios/tests/01_commits.rs (2 hunks)
  • test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs (4 hunks)
  • test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs (1 hunks)
  • test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (1 hunks)
  • test-integration/test-ledger-restore/tests/08_commit_update.rs (2 hunks)
  • test-integration/test-tools/src/integration_test_context.rs (2 hunks)
  • test-integration/test-tools/src/scheduled_commits.rs (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-26T08:49:31.543Z
Learnt from: taco-paco
PR: magicblock-labs/magicblock-validator#585
File: magicblock-committor-service/src/tasks/buffer_task.rs:111-115
Timestamp: 2025-10-26T08:49:31.543Z
Learning: In the magicblock-committor-service, compute units returned by the `compute_units()` method in task implementations (such as `BufferTask`, `ArgsTask`, etc.) represent the compute budget for a single task. Transactions can comprise multiple tasks, and the total compute budget for a transaction is computed as the sum of the compute units of all tasks included in that transaction.

Applied to files:

  • magicblock-committor-service/src/tasks/args_task.rs
🧬 Code graph analysis (15)
test-integration/test-ledger-restore/tests/08_commit_update.rs (1)
test-integration/test-ledger-restore/src/lib.rs (1)
  • setup_validator_with_local_remote (97-119)
test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs (3)
test-integration/programs/schedulecommit/src/api.rs (1)
  • schedule_commit_with_payer_cpi_instruction (214-232)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (3)
  • assert_two_committees_were_committed (68-91)
  • get_context_with_delegated_committees (16-35)
  • assert_feepayer_was_committed (94-113)
test-integration/schedulecommit/client/src/verify.rs (1)
  • fetch_and_verify_commit_result_from_logs (7-14)
test-integration/programs/schedulecommit-security/src/lib.rs (1)
test-integration/schedulecommit/test-security/tests/01_invocations.rs (1)
  • create_schedule_commit_ix (41-66)
magicblock-committor-service/src/tasks/args_task.rs (4)
magicblock-committor-service/src/tasks/mod.rs (2)
  • instruction (66-66)
  • instruction (249-255)
magicblock-committor-service/src/tasks/buffer_task.rs (2)
  • instruction (65-86)
  • new (37-45)
magicblock-committor-service/src/config.rs (1)
  • local (29-35)
magicblock-accounts/src/scheduled_commits_processor.rs (2)
  • new (66-90)
  • new (420-436)
programs/magicblock/src/magicblock_processor.rs (3)
magicblock-committor-service/src/tasks/args_task.rs (1)
  • instruction (58-160)
programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (1)
  • process_schedule_commit (34-259)
magicblock-committor-program/src/state/changeset.rs (1)
  • request_undelegation (230-232)
test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs (4)
test-integration/programs/schedulecommit/src/api.rs (4)
  • schedule_commit_and_undelegate_cpi_instruction (234-252)
  • schedule_commit_and_undelegate_cpi_with_mod_after_instruction (287-311)
  • schedule_commit_diff_instruction_for_order_book (193-212)
  • update_order_book_instruction (175-191)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (3)
  • get_context_with_delegated_committees (16-35)
  • assert_one_committee_was_committed (41-65)
  • assert_one_committee_account_was_undelegated_on_chain (190-196)
test-integration/schedulecommit/client/src/schedule_commit_context.rs (3)
  • committees (205-209)
  • ephem_blockhash (322-324)
  • ephem_client (318-320)
test-integration/schedulecommit/client/src/verify.rs (1)
  • fetch_and_verify_order_book_commit_result_from_logs (16-23)
test-integration/programs/schedulecommit/src/api.rs (2)
test-integration/programs/schedulecommit/src/order_book.rs (1)
  • new (85-94)
test-integration/programs/flexi-counter/src/state.rs (1)
  • pda (32-35)
test-integration/schedulecommit/client/src/verify.rs (2)
test-integration/test-ledger-restore/tests/08_commit_update.rs (1)
  • ctx (90-91)
test-integration/schedulecommit/test-security/tests/01_invocations.rs (1)
  • ctx (145-146)
magicblock-committor-service/src/tasks/task_builder.rs (2)
magicblock-accounts/src/scheduled_commits_processor.rs (2)
  • new (66-90)
  • new (420-436)
magicblock-committor-service/src/tasks/args_task.rs (1)
  • new (49-54)
test-integration/programs/schedulecommit/src/lib.rs (2)
test-integration/programs/schedulecommit/src/utils/mod.rs (3)
  • assert_is_signer (30-44)
  • assert_keys_equal (16-28)
  • allocate_account_and_assign_owner (58-106)
test-integration/programs/schedulecommit/src/order_book.rs (1)
  • new (85-94)
programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • committed_accounts (153-156)
test-integration/test-committor-service/tests/test_ix_commit_local.rs (1)
  • base_intent (544-549)
test-integration/schedulecommit/client/src/schedule_commit_context.rs (1)
test-integration/programs/schedulecommit/src/api.rs (3)
  • init_order_book_instruction (36-54)
  • init_payer_escrow (77-98)
  • init_account_instruction (16-34)
programs/magicblock/src/magic_scheduled_base_intent.rs (1)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • committed_accounts (153-156)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (3)
test-integration/test-ledger-restore/tests/08_commit_update.rs (1)
  • ctx (90-91)
test-integration/schedulecommit/test-security/tests/01_invocations.rs (1)
  • ctx (145-146)
test-integration/schedulecommit/client/src/schedule_commit_context.rs (3)
  • try_new (72-74)
  • ncommittees (102-121)
  • try_new_random_keys (66-71)
test-integration/schedulecommit/test-scenarios/tests/01_commits.rs (1)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (1)
  • get_context_with_delegated_committees (16-35)
⏰ 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). (4)
  • GitHub Check: run_make_ci_format
  • GitHub Check: run_make_ci_test
  • GitHub Check: run_make_ci_lint
  • GitHub Check: run_make_ci_test
🔇 Additional comments (34)
test-integration/test-ledger-restore/tests/08_commit_update.rs (1)

55-55: LGTM! Correctly updated to match new function signature.

Both call sites properly destructure the new 3-tuple return value. The _tmpdir binding is necessary to keep the TempDir alive throughout the function scope, preventing premature cleanup of the temporary directory while the validator is still using it.

Also applies to: 170-170

test-integration/programs/schedulecommit/src/utils/mod.rs (2)

53-53: LGTM: Type alignment with Solana API.

Changing size to u64 aligns with Solana's system_instruction::allocate API, which expects a u64 parameter. This improves type consistency and eliminates the need for type conversions downstream.


70-90: LGTM: Clean implementation with helpful debugging.

The changes correctly handle the type conversion:

  • Line 71: The cast to usize is necessary for Rent::minimum_balance and is safe given Solana's practical account size limits.
  • Lines 75-80: The debug log provides useful visibility into lamport requirements during account allocation.
  • Line 90: Passing size directly as u64 to system_instruction::allocate is cleaner and aligns with the API signature.
test-integration/programs/schedulecommit-security/src/lib.rs (2)

2-2: LGTM: Import addition is correct.

The CommitPolicy import is necessary for the API change on line 149.


143-150: No action required—the two CPI paths use intentionally different APIs.

The review comment's concern about consistency is based on a false premise. The code uses two fundamentally different functions from different modules:

  • Path 1 (schedule_commit_cpi_instruction): A local program API wrapper with a fixed, simplified interface
  • Path 2 (create_schedule_commit_ix): An external SDK function with extended configuration options including CommitPolicy

These are not parallel implementations requiring symmetry. The schedule_commit_cpi_instruction function does not support CommitPolicy by design—it wraps commit scheduling with hardcoded policy defaults. Adding CommitPolicy::UseFullBytes to create_schedule_commit_ix is the correct change and requires no corresponding update to schedule_commit_cpi_instruction.

Likely an incorrect or invalid review comment.

test-integration/test-tools/src/integration_test_context.rs (1)

167-171: Transaction version configuration is correct and environment-aware.

The conditional logic properly handles two distinct RPC endpoints:

  • Chain (Solana devnet): max_supported_transaction_version: Some(0) with 50 retries to handle devnet's known quirk of sometimes returning version responses instead of transaction metadata (noted at line 160-161).
  • Ephemeral (local validator): None to use default behavior on a controlled, local environment without such quirks.

Git history confirms this change is part of the current PR (commit 4c75d78). The code is correctly differentiated for each environment. No changes needed.

test-integration/test-tools/src/scheduled_commits.rs (1)

182-213: LGTM! Clear hierarchical naming for log variables.

The renaming from ephem_logs/chain_logs to ephem_logs_l1/ephem_logs_l2 improves clarity by establishing a consistent naming convention that reflects the two-level log retrieval hierarchy.

magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs (1)

29-33: LGTM: CommitDiff included in strategy persistence.

Cleanly broadens Commit to CommitDiff without changing strategy semantics.

programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2)

224-230: Diff-aware commit routing is correct; keep logs concise.

Choosing StandaloneDiff when request_diff is true is right. Consider demoting the "StandaloneDiff" ic_msg to debug in production builds to reduce log noise.

Also applies to: 233-238


29-32: All call sites properly initialize request_diff—no corrections needed.

Verification confirms that every process_schedule_commit() invocation explicitly sets both request_undelegation and request_diff fields. All three instruction paths (ScheduleCommit, ScheduleCommitAndUndelegate, ScheduleCommitDiffAndUndelegate) pass values for request_diff, with ScheduleCommitDiffAndUndelegate correctly setting it to true to trigger the CommitType::StandaloneDiff path. No uninitialized defaults are used, and no silent routing to full-state commits can occur.

programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs (1)

29-30: LGTM: commit_diff added end-to-end with safe logging.

Field is carried into printable form and logged only as a flag. Tests initialize the new field.

Also applies to: 44-45, 71-73, 215-217, 254-255

magicblock-committor-service/src/tasks/args_task.rs (1)

197-205: Calibrate compute units for CommitDiff based on diff size.

Fixed 65_000 may be inaccurate. Once diff is precomputed, scale CU by diff length/segments or add headroom to avoid CU errors.

Based on learnings

programs/magicblock/src/magicblock_processor.rs (3)

2-2: LGTM: import added is correct.


51-54: ScheduleCommit: explicit request_diff=false is correct.


90-99: New ScheduleCommitDiffAndUndelegate path correctly flips request_diff=true.

magicblock-committor-service/src/tasks/task_builder.rs (1)

96-105: Per-account Commit vs CommitDiff task selection is correct.

programs/magicblock/src/magic_scheduled_base_intent.rs (6)

104-107: ScheduledBaseIntent::is_commit_diff added — OK.


155-164: MagicBaseIntent::is_commit_diff added — OK.


448-454: CommitType::is_commit_diff implementation — OK.


456-463: Getters updated for StandaloneDiff — OK.

Also applies to: 465-473


475-487: is_empty handles StandaloneDiff — OK.


317-323: StandaloneDiff variant already exists and is actively used in the codebase.

The review's concern assumes StandaloneDiff is a new addition that will shift bincode discriminants. However, the variant is already present in process_schedule_commit.rs (lines 225–226), indicating it exists before this PR or is not new.

If StandaloneDiff was already committed to the codebase:

  • The bincode discriminant shift already happened (or never was a concern).
  • The review comment's warning is outdated or misguided.

If the snippet shows the final state (post-changes) and StandaloneDiff was genuinely added in this PR:

  • Verify the diff shows it was inserted between existing variants (which would shift discriminants).
  • If it was appended after existing variants, discriminants remain stable and no migration is needed.

Critical finding: No backwards compatibility tests, no versioning code, and no serde external tagging exist. If persisted state truly exists and the variant order changed, this is a risk. However, the evidence suggests StandaloneDiff is not new.

Action for developer: Confirm in the PR diff that you are not reordering existing enum variants. If appending new variants after existing ones, bincode compatibility is safe. If inserting between existing variants, migration is required.

test-integration/schedulecommit/test-scenarios/Cargo.toml (1)

19-20: LGTM!

The addition of rand and borsh as workspace dev-dependencies appropriately supports the new order-book test scenarios introduced in this PR.

test-integration/schedulecommit/test-scenarios/tests/01_commits.rs (1)

30-31: LGTM!

The addition of deterministic seed b"magic_schedule_commit" improves test reproducibility by ensuring consistent PDA derivation across test runs.

test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (2)

16-35: LGTM!

The seed parameter enables deterministic test context initialization, and explicitly driving the init_committees and delegate_committees workflow steps with debug logging improves test clarity and observability.


41-47: LGTM!

Making assert_one_committee_was_committed generic over type T with appropriate trait bounds enables reuse across different account types (MainAccount, OrderBookOwned, etc.) while maintaining type safety.

test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs (2)

23-80: LGTM!

The test properly validates that attempting to commit a fee payer without escrowing lamports fails with the expected "DoesNotHaveEscrowAccount" error. The test structure and assertions are appropriate.


83-135: LGTM!

The test correctly validates the happy path where fee payer commits succeed when lamports are properly escrowed. The verification flow and assertions comprehensively check that both committees and the fee payer were committed and synchronized.

test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs (3)

55-56: LGTM!

The addition of deterministic seed b"magic_schedule_commit" ensures reproducible test behavior across runs.


110-164: LGTM!

The commit_and_undelegate_order_book_account helper follows the established pattern of other commit helpers in this file, properly constructing the update and schedule-commit-diff instructions sequence.


244-312: Excellent reproducibility design for randomized testing.

The test demonstrates best practices for randomized testing:

  • Prints the RNG seed for reproducibility
  • Includes the seed in assertion failure messages
  • Uses seeded RNG (StdRng) for deterministic behavior given a seed

This allows failures to be reproduced by rerunning with the printed seed value.

One optional enhancement: consider adding a way to override the seed via environment variable for easier failure reproduction:

let rng_seed = std::env::var("TEST_RNG_SEED")
    .ok()
    .and_then(|s| s.parse::<u64>().ok())
    .unwrap_or_else(|| OsRng.next_u64());
test-integration/programs/schedulecommit/src/lib.rs (1)

561-571: Use commit_diff for undelegate path; this looks correct.

The diff-based commit is invoked when undelegate is true; good alignment with the new optimization.

Please confirm tests cover both diff and full-commit paths (with/without undelegate).

test-integration/programs/schedulecommit/src/order_book.rs (1)

101-116: Bounds/capacity logic is good; but relies on header being valid.

Once header init is fixed in process_init_order_book, these helpers are fine for basic growth semantics.

Ensure tests cover:

  • Non-zero existing asks/bids followed by additional inserts (to exercise prefix/suffix behavior).
  • Capacity exhaustion returning None.

Also applies to: 118-138, 163-184

test-integration/schedulecommit/client/src/schedule_commit_context.rs (1)

260-267: Seed semantics are correct and consistently applied across the codebase.

The verification shows that delegate_account_cpi_instruction() explicitly branches on two supported canonical seeds:

  • b"magic_schedule_commit"ScheduleCommitInstruction::DelegateCpi
  • b"order_book"ScheduleCommitInstruction::DelegateOrderBook

All test utilities and callers supply only these supported seeds. The delegate_committees() function at lines 260-267 correctly passes &self.user_seed, and all constructors receive only canonical seeds from test callers. PDA derivation and instruction creation use consistent seed semantics.

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

♻️ Duplicate comments (22)
magicblock-rpc-client/src/lib.rs (1)

430-430: Redundant error prefix persists in log message.

The error! macro already includes ERROR level in its output. The explicit "> ERROR:" prefix creates redundancy and reduces log readability.

Apply this diff to remove the redundant prefix:

-            error!("> ERROR: {:?}", err);
+            error!("{:?}", err);

Or add context instead:

-            error!("> ERROR: {:?}", err);
+            error!("Transaction processed status failed: {:?}", err);
test-integration/test-tools/src/scheduled_commits.rs (2)

198-210: Verbose debug output concern still applies.

The past review comment regarding verbose debug output from println! with {:#?} formatting remains applicable to these new debug statements. Consider making the debug output conditional or using a more compact format.


233-235: Unnecessary clone() on Copy type.

The past review comment regarding the redundant .clone() call on Signature (which implements Copy) remains applicable. Use *sig instead of sig.clone().

test-integration/test-tools/src/integration_test_context.rs (1)

157-158: Format the panic message with label.

The panic still prints the literal rpc_client for [{}] does not exist, so the label never appears when this trips. Please inject label into the message.

-        let rpc_client =
-            rpc_client.expect("rpc_client for [{}] does not exist");
+        let rpc_client = rpc_client.unwrap_or_else(|| {
+            panic!("rpc_client for [{}] does not exist", label)
+        });
test-integration/schedulecommit/client/src/verify.rs (1)

16-23: Code duplication: consider the generic implementation suggested in the previous review.

This function duplicates fetch_and_verify_commit_result_from_logs except for the type parameter. A generic implementation with T: borsh::BorshDeserialize would eliminate this duplication.

test-integration/schedulecommit/client/src/schedule_commit_context.rs (2)

115-118: PDA derivation must match program-side seeds.

The PDA is derived using an arbitrary user_seed, which may not match the on-chain program's expected seeds (e.g., [b"order_book", book_manager] or [b"magic_schedule_commit", player]). This mismatch will cause transaction failures.


170-203: Validate user_seed explicitly to prevent silent misconfiguration.

The implicit else branch will execute for any user_seed that isn't b"magic_schedule_commit", including invalid values. Add explicit validation to fail fast with a clear error when an unsupported seed is provided.

test-integration/programs/schedulecommit/src/api.rs (1)

106-109: Derive delegated PDA with canonical seeds to match on-chain expectations.

The PDA is derived using an arbitrary user_seed, but the on-chain program expects fixed seeds like [b"magic_schedule_commit", player] or [b"order_book", book_manager]. This mismatch will cause the delegated_account to not match program-side expectations.

Cargo.toml (1)

112-112: CI/CD will fail: local path dependency not available.

The path ../delegation-program does not exist in the repository or CI environments, causing all builds to fail. Either:

  • Revert to a git-based dependency (consistent with the learning about using git branch references)
  • Make delegation-program a workspace member at the correct path
  • Update CI workflows to checkout the dependency

Verify the intended dependency resolution strategy:

#!/bin/bash
# Check if the delegation-program path exists
if [ -d "../delegation-program" ]; then
    echo "✓ Path exists locally"
    ls -la ../delegation-program/
else
    echo "✗ Path ../delegation-program does not exist"
fi

# Check for any git submodule configuration
echo ""
echo "=== Git submodules ==="
git submodule status 2>/dev/null || echo "No submodules configured"

# Check recent commits for this dependency change
echo ""
echo "=== Recent changes to delegation-program dependency ==="
git log -n 5 --oneline --all -- Cargo.toml | head -10
test-integration/Cargo.toml (1)

40-40: Critical: Local path dependencies will break CI builds.

This issue has already been flagged in previous review comments. The local paths ../../ephemeral-rollups-sdk/rust/sdk and ../../delegation-program do not exist in the CI environment and will cause build failures.

Also applies to: 60-60

test-integration/programs/schedulecommit/src/lib.rs (4)

302-309: Zero the order-book header immediately after allocation.

OrderBook::new reads bids_len/asks_len straight from account data. Leaving those bytes uninitialized means random counts, which makes the next borrow calculate bogus slices and can walk past the buffer. Please clear the header bytes right after allocation (e.g. borrow data, zero the first size_of::<OrderBookHeader>() bytes).

Apply this diff:

     allocate_account_and_assign_owner(AllocateAndAssignAccountArgs {
         payer_info: payer,
         account_info: order_book,
         owner: &crate::ID,
         signer_seeds: &[b"order_book", book_manager.key.as_ref(), &[bump]],
         size: 10 * 1024,
     })?;
 
+    {
+        let mut data = order_book.try_borrow_mut_data()?;
+        let header_len = core::mem::size_of::<OrderBookHeader>();
+        if data.len() < header_len {
+            return Err(ProgramError::AccountDataTooSmall);
+        }
+        for byte in &mut data[..header_len] {
+            *byte = 0;
+        }
+    }
+
     Ok(())

329-334: Fix the PDA assertion message.

The diagnostic still prints payer.key, so a failing check points at the wrong seed. Swap it for book_manager.key as previously requested.

Apply this diff:

     assert_keys_equal(order_book.key, &pda, || {
         format!(
             "PDA for the account ('{}') and for book_manager ('{}') is incorrect",
-            order_book.key, payer.key
+            order_book.key, book_manager.key
         )
     })?;

398-403: Update the log label.

This path is mutating an existing order book, not initializing one. Please change the msg! to say “Update order book” (or equivalent) so logs stay accurate.


424-451: Use the right error kind and require the payer to sign.

When the accounts slice is the wrong length you must emit ProgramError::NotEnoughAccountKeys; MissingRequiredSignature is misleading. More importantly, we still never verify payer.is_signer, so the CPI can run with an unsigned funder. Add assert_is_signer(payer, "payer")? before the CPI.

Apply this diff:

     let [payer, order_book_account, magic_context, magic_program] = accounts
     else {
-        return Err(ProgramError::MissingRequiredSignature);
+        return Err(ProgramError::NotEnoughAccountKeys);
     };
 
+    assert_is_signer(payer, "payer")?;
+
     commit_diff_and_undelegate_accounts(
         payer,
         vec![order_book_account],
         magic_context,
         magic_program,
test-integration/programs/schedulecommit/src/order_book.rs (3)

45-55: deserialize still aliases immutable data mutably (UB).

slice::from_raw_parts_mut on book_bytes forges a &mut [u8] from shared data, violating Rust’s aliasing rules and instantly triggering undefined behaviour. Please replace this with a safe path—e.g. copy into an owned buffer or implement a parser that reads header/levels straight from the immutable slice.


85-93: OrderBook::new assumes alignment that account data does not guarantee.

Casting header_bytes.as_ptr() to *mut OrderBookHeader (and the level pointer to *mut OrderLevel) requires 4/8‑byte alignment, but Solana account data is byte-aligned. The moment you dereference those pointers you trigger UB. Rework this to treat the buffer as raw bytes and read/write fields with from_le_bytes/to_le_bytes instead of typed references.


140-178: Typed slices over account data remain unsafe.

slice::from_raw_parts(_ as *mut OrderLevel, ...) for bids/asks/buffer helpers creates slices of OrderLevel out of unaligned memory. That’s the same UB called out earlier. Please keep the backing store as [u8], then decode/encode each OrderLevel by copying 16 bytes into a local array and using u64::from_le_bytes / u64::to_le_bytes.

magicblock-magic-program-api/src/instruction.rs (1)

111-111: Add documentation for ScheduleCommitDiffAndUndelegate.

This issue was already identified in a previous review. The variant lacks documentation while all sibling variants include doc comments describing the instruction purpose and account references.

magicblock-committor-service/src/tasks/args_task.rs (3)

75-103: Stop hard-coding the RPC endpoint in CommitDiff.

ChainConfig::local(ComputeBudgetConfig::new(1_000_000)) forces every CommitDiff task to dial http://localhost:7799 with Processed commitment and re-create an RPC client each time instruction() is called. In production that URI does not exist, so we immediately fall back to commit_state and never ship a diff; plus every call repeats the network fetch we already warned about. Inject the real ChainConfig/RpcClient from the service (or precompute/cache the diff during task construction) so instruction() stays pure and uses the configured endpoint. Prior feedback on this remains unresolved.


115-116: Do not log raw diff payloads.

Dumping the entire diff at warn level leaks account data and explodes log volume. Log only bounded metadata (e.g., commit_id, pubkey, diff length) instead.

-                log::warn!("DIFF computed: {:?}", args.diff);
+                log::debug!(
+                    "commit_diff computed: commit_id={} pubkey={} len={}",
+                    value.commit_id,
+                    value.committed_account.pubkey,
+                    args.diff.len()
+                );

171-173: Remove the CommitDiff panic in optimize().

optimize() is part of the normal pipeline; panicking here will abort the worker whenever a CommitDiff task flows through. Return Err(self) (mirroring the other variants) so the caller can fall back cleanly.

-            ArgsTaskType::CommitDiff(_) => {
-                panic!("ArgsTaskType::CommitDiff not handled")
-            }
+            ArgsTaskType::CommitDiff(_) => Err(self),
programs/magicblock/src/magicblock_processor.rs (1)

38-38: Avoid logging entire MagicBlockInstruction payloads.

ic_msg!(..., "{:?}", instruction) dumps the full enum—including the diff bytes you just added—on every invocation. That inflates CU cost and spams logs, an issue we already called out earlier. Drop the log or gate it behind a debug-only feature flag so mainnet builds don’t emit the payload.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5c5e15 and 693af7f.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • test-integration/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (28)
  • Cargo.toml (1 hunks)
  • magicblock-accounts/src/scheduled_commits_processor.rs (3 hunks)
  • magicblock-committor-service/src/tasks/args_task.rs (6 hunks)
  • magicblock-committor-service/src/tasks/mod.rs (1 hunks)
  • magicblock-committor-service/src/tasks/task_builder.rs (3 hunks)
  • magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs (1 hunks)
  • magicblock-magic-program-api/src/instruction.rs (1 hunks)
  • magicblock-rpc-client/src/lib.rs (1 hunks)
  • programs/magicblock/src/magic_scheduled_base_intent.rs (7 hunks)
  • programs/magicblock/src/magicblock_processor.rs (4 hunks)
  • programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2 hunks)
  • programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs (5 hunks)
  • test-integration/Cargo.toml (2 hunks)
  • test-integration/programs/schedulecommit-security/src/lib.rs (2 hunks)
  • test-integration/programs/schedulecommit/src/api.rs (5 hunks)
  • test-integration/programs/schedulecommit/src/lib.rs (9 hunks)
  • test-integration/programs/schedulecommit/src/order_book.rs (1 hunks)
  • test-integration/programs/schedulecommit/src/utils/mod.rs (3 hunks)
  • test-integration/schedulecommit/client/src/schedule_commit_context.rs (6 hunks)
  • test-integration/schedulecommit/client/src/verify.rs (2 hunks)
  • test-integration/schedulecommit/test-scenarios/Cargo.toml (1 hunks)
  • test-integration/schedulecommit/test-scenarios/tests/01_commits.rs (2 hunks)
  • test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs (4 hunks)
  • test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs (1 hunks)
  • test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (1 hunks)
  • test-integration/test-ledger-restore/tests/08_commit_update.rs (2 hunks)
  • test-integration/test-tools/src/integration_test_context.rs (2 hunks)
  • test-integration/test-tools/src/scheduled_commits.rs (3 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-10-14T09:56:14.047Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 564
File: test-integration/programs/flexi-counter/src/processor/call_handler.rs:122-125
Timestamp: 2025-10-14T09:56:14.047Z
Learning: The file test-integration/programs/flexi-counter/src/processor/call_handler.rs contains a test smart contract used for integration testing, not production code.

Applied to files:

  • test-integration/test-tools/src/integration_test_context.rs
  • test-integration/programs/schedulecommit/src/utils/mod.rs
  • test-integration/test-ledger-restore/tests/08_commit_update.rs
  • test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs
📚 Learning: 2025-10-21T14:00:54.642Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579

Applied to files:

  • magicblock-committor-service/src/tasks/mod.rs
  • test-integration/programs/schedulecommit/src/utils/mod.rs
  • magicblock-committor-service/src/tasks/args_task.rs
  • test-integration/programs/schedulecommit/src/api.rs
  • test-integration/programs/schedulecommit/src/lib.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
📚 Learning: 2025-10-26T16:54:39.084Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 587
File: test-manual/Cargo.toml:0-0
Timestamp: 2025-10-26T16:54:39.084Z
Learning: In the magicblock-validator repository, use git branch references (not commit hashes or tags) for the helius-laserstream dependency to allow automatic updates when the branch is pushed to.

Applied to files:

  • test-integration/Cargo.toml
  • Cargo.toml
📚 Learning: 2025-10-26T08:49:31.543Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 585
File: magicblock-committor-service/src/tasks/buffer_task.rs:111-115
Timestamp: 2025-10-26T08:49:31.543Z
Learning: In the magicblock-committor-service, compute units returned by the `compute_units()` method in task implementations (such as `BufferTask`, `ArgsTask`, etc.) represent the compute budget for a single task. Transactions can comprise multiple tasks, and the total compute budget for a transaction is computed as the sum of the compute units of all tasks included in that transaction.

Applied to files:

  • magicblock-committor-service/src/tasks/args_task.rs
🧬 Code graph analysis (15)
test-integration/programs/schedulecommit-security/src/lib.rs (1)
test-integration/schedulecommit/test-security/tests/01_invocations.rs (1)
  • create_schedule_commit_ix (41-66)
magicblock-committor-service/src/tasks/task_builder.rs (2)
magicblock-committor-service/src/tasks/args_task.rs (1)
  • new (49-54)
magicblock-accounts/src/scheduled_commits_processor.rs (2)
  • new (66-90)
  • new (420-436)
programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • committed_accounts (153-156)
test-integration/test-committor-service/tests/test_ix_commit_local.rs (1)
  • base_intent (544-549)
test-integration/schedulecommit/client/src/verify.rs (2)
test-integration/test-ledger-restore/tests/08_commit_update.rs (1)
  • ctx (90-91)
test-integration/schedulecommit/test-security/tests/01_invocations.rs (1)
  • ctx (145-146)
programs/magicblock/src/magicblock_processor.rs (3)
magicblock-committor-service/src/tasks/args_task.rs (1)
  • instruction (58-160)
programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (1)
  • process_schedule_commit (34-259)
magicblock-committor-program/src/state/changeset.rs (1)
  • request_undelegation (230-232)
test-integration/schedulecommit/test-scenarios/tests/01_commits.rs (1)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (1)
  • get_context_with_delegated_committees (16-35)
magicblock-committor-service/src/tasks/args_task.rs (3)
magicblock-committor-service/src/tasks/mod.rs (2)
  • instruction (66-66)
  • instruction (249-255)
magicblock-committor-service/src/tasks/buffer_task.rs (1)
  • instruction (65-86)
magicblock-committor-service/src/config.rs (1)
  • local (29-35)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (3)
test-integration/test-ledger-restore/tests/08_commit_update.rs (1)
  • ctx (90-91)
test-integration/schedulecommit/test-security/tests/01_invocations.rs (1)
  • ctx (145-146)
test-integration/schedulecommit/client/src/schedule_commit_context.rs (3)
  • try_new (72-74)
  • ncommittees (102-121)
  • try_new_random_keys (66-71)
programs/magicblock/src/magic_scheduled_base_intent.rs (1)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • committed_accounts (153-156)
test-integration/schedulecommit/client/src/schedule_commit_context.rs (2)
test-integration/programs/schedulecommit/src/api.rs (3)
  • init_order_book_instruction (36-54)
  • init_payer_escrow (77-98)
  • init_account_instruction (16-34)
test-integration/test-tools/src/integration_test_context.rs (1)
  • try_new (113-115)
test-integration/test-ledger-restore/tests/08_commit_update.rs (1)
test-integration/test-ledger-restore/src/lib.rs (1)
  • setup_validator_with_local_remote (97-119)
test-integration/programs/schedulecommit/src/api.rs (2)
test-integration/programs/schedulecommit/src/order_book.rs (1)
  • new (85-94)
test-integration/programs/flexi-counter/src/state.rs (1)
  • pda (32-35)
test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs (4)
test-integration/test-runner/bin/run_tests.rs (1)
  • run_test (777-796)
test-integration/programs/schedulecommit/src/api.rs (1)
  • schedule_commit_with_payer_cpi_instruction (214-232)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (4)
  • assert_two_committees_synchronized_count (139-169)
  • assert_two_committees_were_committed (68-91)
  • get_context_with_delegated_committees (16-35)
  • assert_feepayer_was_committed (94-113)
test-integration/schedulecommit/client/src/verify.rs (1)
  • fetch_and_verify_commit_result_from_logs (7-14)
test-integration/programs/schedulecommit/src/lib.rs (2)
test-integration/programs/schedulecommit/src/utils/mod.rs (3)
  • assert_is_signer (30-44)
  • assert_keys_equal (16-28)
  • allocate_account_and_assign_owner (58-106)
test-integration/programs/schedulecommit/src/order_book.rs (1)
  • new (85-94)
test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs (4)
test-integration/programs/schedulecommit/src/api.rs (3)
  • schedule_commit_and_undelegate_cpi_with_mod_after_instruction (287-311)
  • schedule_commit_diff_instruction_for_order_book (193-212)
  • update_order_book_instruction (175-191)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (3)
  • get_context_with_delegated_committees (16-35)
  • assert_one_committee_was_committed (41-65)
  • assert_one_committee_account_was_undelegated_on_chain (190-196)
test-integration/schedulecommit/client/src/schedule_commit_context.rs (3)
  • committees (205-209)
  • ephem_blockhash (322-324)
  • ephem_client (318-320)
test-integration/schedulecommit/client/src/verify.rs (1)
  • fetch_and_verify_order_book_commit_result_from_logs (16-23)
⏰ 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). (3)
  • GitHub Check: run_make_ci_test
  • GitHub Check: run_make_ci_lint
  • GitHub Check: run_make_ci_test
🔇 Additional comments (20)
test-integration/programs/schedulecommit/src/utils/mod.rs (3)

49-55: LGTM: Type alignment with Solana API.

Changing size from usize to u64 correctly aligns with Solana's system_instruction::allocate signature, which expects space: u64.


75-79: LGTM: Helpful debug logging.

The added logging for lamport requirements and payer balance aids in troubleshooting account allocation issues during testing.


90-90: Critical fix: Correct system_instruction::allocate signature.

The updated call now correctly provides both required arguments (pubkey and space) to system_instruction::allocate. The previous implementation appears to have been missing the pubkey argument, which would not match the function signature: pub fn allocate(pubkey: &Pubkey, space: u64) -> Instruction.

test-integration/test-tools/src/scheduled_commits.rs (1)

182-213: Variable renaming improves clarity.

The renaming of log variables to ephem_logs_l1 and ephem_logs_l2 clearly distinguishes the two-level log fetching process, and the updated error context at line 206 now correctly references the first-level logs. These changes enhance code readability.

test-integration/programs/schedulecommit-security/src/lib.rs (2)

2-2: LGTM!

The CommitPolicy import is correctly added to support the new argument at line 149.


143-150: Ignore this review comment. The original comment incorrectly assumes that schedule_commit_cpi_instruction and create_schedule_commit_ix should be consistent, but they are two distinct functions from different crates with different purposes:

  • schedule_commit_cpi_instruction (from program_schedulecommit::api) is a local CPI helper that does not accept a CommitPolicy parameter
  • create_schedule_commit_ix (from ephemeral_rollups_sdk::ephem) is an SDK function that accepts CommitPolicy as a parameter

The two functions have intentionally different signatures. There is no test inconsistency to address.

Likely an incorrect or invalid review comment.

test-integration/test-ledger-restore/tests/08_commit_update.rs (1)

55-61: No issues found—code is correct as written.

The TempDir returned by setup_validator_with_local_remote is created specifically for temporary config storage during validator initialization (written in start_magicblock_validator_with_config_struct at line 225: fs::write(&config_path, config_toml)). After the validator process is spawned, this directory is no longer needed and is safely dropped. The actual ledger directory is managed separately by the main _tmpdir at line 42 of the test, which persists for the entire test duration. The binding to _tmpdir with an underscore prefix correctly signals that this return value is intentionally unused beyond validator initialization.

test-integration/programs/schedulecommit/src/api.rs (3)

36-54: LGTM!

The init_order_book_instruction follows the standard instruction builder pattern with appropriate account metadata.


56-75: LGTM!

The grow_order_book_instruction correctly constructs the instruction with the additional_space parameter.


175-212: LGTM!

Both update_order_book_instruction and schedule_commit_diff_instruction_for_order_book follow correct instruction builder patterns with appropriate account metadata.

test-integration/schedulecommit/test-scenarios/tests/01_commits.rs (1)

30-31: LGTM! Deterministic seed ensures reproducible test contexts.

The hard-coded seed b"magic_schedule_commit" provides deterministic PDA derivation and context initialization, which improves test reliability and debugging.

Also applies to: 84-85

test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs (2)

82-135: LGTM! Fee payer escrow test properly verifies expected behavior.

The test correctly verifies that with proper escrow setup, the fee payer commit succeeds and all expected assertions pass.


34-41: Fix struct field destructuring: payer_ephem field and ephem_blockhash retrieval.

The code attempts to destructure non-existent struct fields:

  • Line 35: payer field doesn't exist in ScheduleCommitTestContextFields — should be payer_ephem: payer
  • Line 39: ephem_blockhash is not a struct field — must be fetched separately via ephem_client.get_latest_blockhash().unwrap()
  • Lines 58, 112: Remove dereference (*) from ephem_blockhash once corrected

See 01_commits.rs (lines 34, 54) for the correct pattern.

Also applies to: 88-95, 112

⛔ Skipped due to learnings
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579
programs/magicblock/src/magic_scheduled_base_intent.rs (3)

104-106: LGTM!

The is_commit_diff() method correctly delegates to the base intent, following the same pattern as the existing is_undelegate() method.


155-163: LGTM!

The is_commit_diff() method correctly handles all MagicBaseIntent variants, properly delegating to the underlying CommitType for both Commit and CommitAndUndelegate cases.


458-458: LGTM!

The accessor methods correctly handle the new StandaloneDiff variant, treating it identically to Standalone since both contain Vec<CommittedAccount>.

Also applies to: 468-468, 480-482

magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs (2)

29-33: LGTM!

The match correctly handles both Commit and CommitDiff variants identically, as both contain CommitTask and should be persisted the same way.


59-59: ****

The review comment is incorrect. BufferTaskType intentionally has only a single Commit variant because it represents buffer-based commit operations. CommitDiff is a separate task variant that belongs exclusively to ArgsTaskType and is handled through a different code path.

Evidence:

  • ArgsTaskType includes CommitDiff(CommitTask), but BufferTaskType does not
  • ArgsTaskType::CommitDiff explicitly panics with "ArgsTaskType::CommitDiff not handled" when attempting conversion, indicating CommitDiff is intentionally not converted to BufferTask
  • The refutable pattern at line 59 is safe because BufferTaskType can only ever contain a single variant

No code changes are needed; the refutable pattern is correct as implemented.

Likely an incorrect or invalid review comment.

programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2)

31-31: LGTM!

The request_diff field addition cleanly extends the options structure to control diff-based commit scheduling.


231-238: LGTM!

The commit_action is correctly used in both the undelegation and non-undelegation paths, enabling diff-based commits for both scenarios while preserving existing semantics.


let required_lamports = rent
.minimum_balance(size)
.minimum_balance(size as usize)
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider checked conversion for defensive coding.

The unchecked as usize cast could theoretically truncate if size exceeds usize::MAX on 32-bit systems. While unlikely in practice (Solana programs run in 64-bit environments and this is test code), a checked conversion would be more robust.

Optional: apply this diff for defensive coding:

-    let required_lamports = rent
-        .minimum_balance(size as usize)
-        .max(1)
-        .saturating_sub(account_info.lamports());
+    let required_lamports = rent
+        .minimum_balance(
+            size.try_into()
+                .map_err(|_| ProgramError::InvalidAccountData)?,
+        )
+        .max(1)
+        .saturating_sub(account_info.lamports());

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In test-integration/programs/schedulecommit/src/utils/mod.rs around line 71, the
code uses an unchecked cast `.minimum_balance(size as usize)` which can truncate
on platforms where size > usize::MAX; replace the unchecked cast with a checked
conversion (e.g., use usize::try_from(size) or size.try_into()) and handle the
Result by propagating an error or returning a sensible failure (or using
unwrap_or with a safe fallback) so conversion failures are handled defensively
instead of silently truncating.

@snawaz snawaz force-pushed the snawaz/commit-diff branch from 693af7f to 99f2e8f Compare October 31, 2025 14:19
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

♻️ Duplicate comments (8)
test-integration/Cargo.toml (1)

40-40: ⚠️ Path dependency concerns from prior review remain unresolved.

The migration from git-based to local path dependencies for ephemeral-rollups-sdk and magicblock-delegation-program still poses the same critical CI/CD risks flagged in the previous review: these paths do not exist in the repository, CI workflows do not clone them, and builds will fail in CI/CD and for contributors without manual setup.

The prior review's recommendations still apply:

  1. Update CI to clone both external repositories, OR
  2. Switch back to git-based references, OR
  3. Add clear setup documentation with exact clone commands and relative paths

Also applies to: 60-60

magicblock-committor-service/src/tasks/args_task.rs (2)

228-234: reset_commit_id must handle CommitDiff variant.

The current implementation only updates the commit_id for Commit tasks and silently returns for CommitDiff. When a CommitDiff task is recycled, the stale commit_id will remain, causing desynced submissions.

Apply this fix to handle both variants:

 fn reset_commit_id(&mut self, commit_id: u64) {
-    // TODO (snawaz): handle CommitDiff as well? what is it about?
-    let ArgsTaskType::Commit(commit_task) = &mut self.task_type else {
-        return;
-    };
-
-    commit_task.commit_id = commit_id;
+    match &mut self.task_type {
+        ArgsTaskType::Commit(task) | ArgsTaskType::CommitDiff(task) => {
+            task.commit_id = commit_id;
+        }
+        _ => {
+            // Only Commit and CommitDiff tasks have commit_id
+        }
+    }
 }

74-122: Network I/O inside instruction() remains a major concern.

The instruction() method performs RPC calls and diff computation on every invocation, which is expensive and risky:

  • instruction() may be called multiple times (e.g., via involved_accounts), multiplying RPC calls
  • TOCTOU: base-chain account can change between diff calculation and transaction submission
  • Coupling to network hinders testing and determinism

Per previous discussion, this is acknowledged as temporary and will be addressed in subsequent PRs. Consider tracking this technical debt.

programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (1)

224-228: Consider enhancing observability as previously suggested.

The conditional logic correctly selects the commit type based on request_diff. However, a past review comment suggests improving the log messages to include the number of committed accounts and the flag value for better operational visibility.

test-integration/programs/schedulecommit/src/order_book.rs (2)

99-119: Unaligned typed reference to OrderBookHeader remains a critical issue.

Line 114 creates a typed reference &mut OrderBookHeader via raw pointer cast. While alignment is asserted at runtime (lines 102-110), Solana account data does not guarantee alignment for arbitrary types. This is undefined behavior if the account data is not aligned to align_of::<OrderBookHeader>().

The assertion will catch misalignment at runtime, but the proper fix is to avoid typed references entirely. Consider reading/writing the header fields as raw bytes using little-endian encoding.


165-178: Typed slices over potentially unaligned memory (OrderLevel).

Lines 166 and 173-174 use slice::from_raw_parts to create typed slices of OrderLevel (which contains u64 fields requiring 8-byte alignment). Account data alignment is not guaranteed by Solana, leading to undefined behavior on read.

Per previous review: store levels as raw bytes and provide accessors that read/write fields via u64::from_le_bytes/to_le_bytes, or use a packed representation without taking references to fields.

test-integration/programs/schedulecommit/src/lib.rs (2)

280-311: Critical: OrderBook header is never initialized.

After allocate_account_and_assign_owner returns (line 308), the account data contains uninitialized memory. Subsequent calls to OrderBook::new will read uninitialized bids_len and asks_len values, causing undefined behavior.

Apply this fix immediately after allocation:

     allocate_account_and_assign_owner(AllocateAndAssignAccountArgs {
         payer_info: payer,
         account_info: order_book,
         owner: &crate::ID,
         signer_seeds: &[b"order_book", book_manager.key.as_ref(), &[bump]],
         size: 10 * 1024,
     })?;
 
+    // Initialize header to zero
+    let mut data = order_book.try_borrow_mut_data()?;
+    let header_size = core::mem::size_of::<OrderBookHeader>();
+    for b in &mut data[..header_size] {
+        *b = 0;
+    }
 
     Ok(())

329-334: Incorrect identifier in PDA assertion error message.

Line 332 incorrectly references payer.key in the error message, which should be book_manager.key to accurately reflect the PDA derivation.

Apply this fix:

     assert_keys_equal(order_book.key, &pda, || {
         format!(
             "PDA for the account ('{}') and for book_manager ('{}') is incorrect",
-            order_book.key, payer.key
+            order_book.key, book_manager.key
         )
     })?;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 693af7f and 99f2e8f.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • test-integration/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • magicblock-committor-service/src/tasks/args_task.rs (6 hunks)
  • programs/magicblock/src/magic_scheduled_base_intent.rs (7 hunks)
  • programs/magicblock/src/magicblock_processor.rs (2 hunks)
  • programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2 hunks)
  • test-integration/Cargo.toml (4 hunks)
  • test-integration/programs/schedulecommit/Cargo.toml (1 hunks)
  • test-integration/programs/schedulecommit/src/lib.rs (9 hunks)
  • test-integration/programs/schedulecommit/src/order_book.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-21T14:00:54.642Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579

Applied to files:

  • magicblock-committor-service/src/tasks/args_task.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • test-integration/programs/schedulecommit/src/lib.rs
📚 Learning: 2025-10-26T08:49:31.543Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 585
File: magicblock-committor-service/src/tasks/buffer_task.rs:111-115
Timestamp: 2025-10-26T08:49:31.543Z
Learning: In the magicblock-committor-service, compute units returned by the `compute_units()` method in task implementations (such as `BufferTask`, `ArgsTask`, etc.) represent the compute budget for a single task. Transactions can comprise multiple tasks, and the total compute budget for a transaction is computed as the sum of the compute units of all tasks included in that transaction.

Applied to files:

  • magicblock-committor-service/src/tasks/args_task.rs
🧬 Code graph analysis (5)
magicblock-committor-service/src/tasks/args_task.rs (3)
magicblock-committor-service/src/tasks/mod.rs (2)
  • instruction (66-66)
  • instruction (249-255)
magicblock-committor-service/src/tasks/buffer_task.rs (1)
  • instruction (65-86)
magicblock-committor-service/src/config.rs (1)
  • local (29-35)
programs/magicblock/src/magicblock_processor.rs (1)
programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (1)
  • process_schedule_commit (34-258)
programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • committed_accounts (153-156)
test-integration/test-committor-service/tests/test_ix_commit_local.rs (1)
  • base_intent (544-549)
programs/magicblock/src/magic_scheduled_base_intent.rs (1)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • committed_accounts (153-156)
test-integration/programs/schedulecommit/src/lib.rs (2)
test-integration/programs/schedulecommit/src/utils/mod.rs (3)
  • assert_is_signer (30-44)
  • assert_keys_equal (16-28)
  • allocate_account_and_assign_owner (58-106)
test-integration/programs/schedulecommit/src/order_book.rs (1)
  • new (99-119)
🔇 Additional comments (11)
test-integration/Cargo.toml (1)

72-72: Now let me check the codebase for actual usage of these dependencies to confirm they are necessary:

Based on my verification, I can now generate the rewritten review comment:


Both dependencies are compatible with Solana 2.2 and appropriate for this PR.

rkyv 0.7.45 supports no_std and no_alloc configurations, making it suitable for Solana on-chain programs. It supports no-std builds for targets without a standard library and no-alloc builds for targets where allocations cannot be made. The Solana VM guarantees that account data is byte-aligned to a multiple of 8, which enables rkyv's zero-copy deserialization to function safely on account data. static_assertions 1.1.0 is a stable, widely-adopted crate (225,914,390 downloads all time) providing compile-time assertion macros useful for validating account structure layouts and sizes—a common pattern in Solana programs.

No further verification needed.

test-integration/programs/schedulecommit/Cargo.toml (1)

11-12: LGTM! Dependencies properly support order book implementation.

The additions of rkyv and static_assertions are well-utilized in order_book.rs for alignment guarantees and compile-time size/alignment checks.

programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (1)

31-31: LGTM! New field enables diff-based commit path.

The request_diff flag properly controls whether to use CommitType::StandaloneDiff or CommitType::Standalone, enabling the optimization for large accounts with small changes.

programs/magicblock/src/magicblock_processor.rs (2)

44-59: LGTM! Existing instructions properly default to non-diff path.

Both ScheduleCommit and ScheduleCommitAndUndelegate correctly set request_diff: false to maintain existing behavior.


85-92: LGTM! New instruction variant correctly enables diff-based commit with undelegation.

The ScheduleCommitDiffAndUndelegate instruction properly sets both request_undelegation: true and request_diff: true, mirroring ScheduleCommitAndUndelegate behavior while enabling the diff optimization.

test-integration/programs/schedulecommit/src/order_book.rs (1)

48-75: LGTM! Mutable aliasing UB resolved with aligned copy.

The implementation now safely copies the input buffer into rkyv::AlignedVec before creating mutable references, avoiding the undefined behavior from the previous approach. The comment clearly explains the rationale.

magicblock-committor-service/src/tasks/args_task.rs (2)

171-172: LGTM! CommitDiff correctly returns Err(self) in optimize().

Returning Err(self) for CommitDiff is correct since the diff is already optimized by design—it sends only the differences rather than full account data. Converting to BufferTask would be counterproductive.

Per previous discussion, this is the correct semantic since CommitDiff is already using the most efficient data transfer strategy.


196-203: LGTM! Compute units appropriately set for CommitDiff.

The 65,000 compute units for CommitDiff (vs 70,000 for Commit) reflects the reduced work from transmitting only the diff. This aligns with the test observation showing lower CU usage.

Based on learnings: these are compute units per task, and transactions may comprise multiple tasks.

test-integration/programs/schedulecommit/src/lib.rs (3)

203-203: LGTM! Type change to u64 is appropriate.

Changing MainAccount::SIZE from usize to u64 aligns with the size parameter type in allocate_account_and_assign_owner (line 255) and Solana's account size conventions.


398-414: LGTM! Log message and signer check are correct.

Line 402 now uses the accurate log message "Update orderbook", and line 407 properly validates that the payer is a signer before allowing the update.


419-439: LGTM! Handler correctly uses diff-based commit with undelegation.

The implementation properly:

  • Returns NotEnoughAccountKeys when accounts are missing (line 426)
  • Validates payer is a signer (line 429)
  • Invokes commit_diff_and_undelegate_accounts for the optimized diff path (line 431)

Comment on lines 448 to 450
pub fn is_commit_diff(&self) -> bool {
matches!(self, Self::StandaloneDiff(_))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

StandaloneDiff never gets constructed
Right now CommitType::try_from_args still only hydrates the Standalone and WithBaseActions variants, so anything decoded from instruction data—including the new ScheduleCommitDiffAndUndelegate path—can never produce CommitType::StandaloneDiff. As a result every is_commit_diff() added above will keep returning false, and the runtime will continue down the full-commit path instead of the diff path. Please extend try_from_args to recognize the new CommitTypeArgs::StandaloneDiff payload and build a CommitType::StandaloneDiff (including wiring up the diff bytes into the CommittedAccount representation). Without that, the new instruction can’t function.

🤖 Prompt for AI Agents
In programs/magicblock/src/magic_scheduled_base_intent.rs around lines 448-450,
the is_commit_diff() variant StandaloneDiff is never constructed because
CommitType::try_from_args only builds Standalone and WithBaseActions; update
try_from_args to recognize CommitTypeArgs::StandaloneDiff payload and construct
CommitType::StandaloneDiff accordingly, including extracting and storing the
diff bytes into the CommittedAccount representation (or equivalent field) used
by StandaloneDiff, and preserve existing handling for other variants; ensure
proper error handling for missing/invalid diff bytes and update any tests or
match arms that assume the previous behavior.

@snawaz snawaz force-pushed the snawaz/commit-diff branch from 99f2e8f to 7eaaa13 Compare October 31, 2025 14:50
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
magicblock-committor-service/src/tasks/args_task.rs (1)

228-235: Critical: reset_commit_id silently ignores CommitDiff tasks.

When a CommitDiff task is recycled, the current code silently returns without updating its commit_id (line 230-232), leaving stale IDs that will cause:

  • Desynchronization with actual commit state
  • Failed submissions with wrong nonce
  • Data integrity issues

A past review correctly identified this issue.

Apply this fix to handle both Commit and CommitDiff:

     fn reset_commit_id(&mut self, commit_id: u64) {
-        // TODO (snawaz): handle CommitDiff as well? what is it about?
-        let ArgsTaskType::Commit(commit_task) = &mut self.task_type else {
-            return;
-        };
-
-        commit_task.commit_id = commit_id;
+        match &mut self.task_type {
+            ArgsTaskType::Commit(task) | ArgsTaskType::CommitDiff(task) => {
+                task.commit_id = commit_id;
+            }
+            _ => {
+                // Other task types don't have commit_id
+            }
+        }
     }
♻️ Duplicate comments (7)
programs/magicblock/src/magic_scheduled_base_intent.rs (1)

389-446: CRITICAL: try_from_args cannot construct StandaloneDiff.

The try_from_args method only handles CommitTypeArgs::Standalone and CommitTypeArgs::WithBaseActions, but does not handle CommitTypeArgs::StandaloneDiff. This means:

  1. Code paths using try_from_args (e.g., process_schedule_base_intent) cannot construct CommitType::StandaloneDiff
  2. Only process_schedule_commit can create it programmatically
  3. Any attempt to deserialize CommitTypeArgs::StandaloneDiff from instruction data will fail

This creates a critical inconsistency where the StandaloneDiff variant cannot be fully utilized across all code paths.

The method needs a new match arm similar to:

 pub fn try_from_args(
     args: CommitTypeArgs,
     context: &ConstructionContext<'_, '_>,
 ) -> Result<CommitType, InstructionError> {
     match args {
         CommitTypeArgs::Standalone(accounts) => {
             // ... existing code ...
             Ok(CommitType::Standalone(committed_accounts))
         }
+        CommitTypeArgs::StandaloneDiff(accounts) => {
+            let committed_accounts_ref = Self::extract_commit_accounts(
+                &accounts,
+                context.transaction_context,
+            )?;
+            Self::validate_accounts(&committed_accounts_ref, context)?;
+            let committed_accounts = committed_accounts_ref
+                .into_iter()
+                .map(|el| {
+                    let mut committed_account: CommittedAccount = el.into();
+                    committed_account.account.owner = context
+                        .parent_program_id
+                        .unwrap_or(committed_account.account.owner);
+                    committed_account
+                })
+                .collect();
+            Ok(CommitType::StandaloneDiff(committed_accounts))
+        }
         CommitTypeArgs::WithBaseActions { ... } => {
             // ... existing code ...
         }
     }
 }

Based on past review comment.

programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (1)

224-228: Add observability logging for commit type selection.

The conditional logic correctly selects the commit type, but lacks logging to indicate which path was taken. This makes debugging and auditing more difficult.

Based on past review comment, consider adding:

 let commit_action = if opts.request_diff {
+    ic_msg!(
+        invoke_context,
+        "ScheduleCommit: using StandaloneDiff for {} accounts",
+        committed_accounts.len()
+    );
     CommitType::StandaloneDiff(committed_accounts)
 } else {
+    ic_msg!(
+        invoke_context,
+        "ScheduleCommit: using Standalone for {} accounts",
+        committed_accounts.len()
+    );
     CommitType::Standalone(committed_accounts)
 };
magicblock-committor-service/src/tasks/args_task.rs (1)

74-122: Network I/O in instruction() confirmed as unresolved; improve fallback logging.

The RPC-in-instruction issue is genuine and remains present despite the past review claiming it was addressed in commit 99f2e8f (which does not exist in the repository).

Confirmed concerns:

  • instruction() called multiple times per task: The method is invoked from delivery_preparator.rs (line 377, mapped over cleanup_tasks), tasks/utils.rs (line 58, mapped over tasks), and task_strategist.rs (line 217, in optimization loop). Each call triggers RPC I/O on the base-chain, multiplying network overhead and creating TOCTOU race conditions.

  • ChainConfig hardcoded locally (line 76): ChainConfig is properly injected into the service/processor but ArgsTask hardcodes ChainConfig::local() instead of receiving injected config. This remains unresolved.

  • Fallback log incomplete (line 90): The message contains a typo ("commmit_id" with 3 m's) and is missing the pubkey context for debugging. Improve clarity:

-                        log::warn!("Fallback to commit_state and send full-bytes, as rpc failed to fetch the delegated-account from base chain, commmit_id: {} , error: {}", value.commit_id, e);
+                        log::warn!(
+                            "Fallback to commit_state for account {}: RPC fetch failed, commit_id={} - {}",
+                            value.committed_account.pubkey,
+                            value.commit_id,
+                            e
+                        );

The architectural concerns about performing RPC I/O during instruction building should be addressed, and the config injection pattern needs to be established.

test-integration/programs/schedulecommit/src/lib.rs (3)

280-311: Header remains uninitialized after allocation—subsequent reads are undefined.

After allocate_account_and_assign_owner, the header fields (bids_len, asks_len) are still uninitialized. Any call to OrderBook::new on this account will read garbage.

Apply this fix to zero the header immediately after allocation:

     allocate_account_and_assign_owner(AllocateAndAssignAccountArgs {
         payer_info: payer,
         account_info: order_book,
         owner: &crate::ID,
         signer_seeds: &[b"order_book", book_manager.key.as_ref(), &[bump]],
         size: 10 * 1024,
     })?;
 
+    // Initialize header to zero
+    let mut data = order_book.try_borrow_mut_data()?;
+    data[..core::mem::size_of::<OrderBookHeader>()].fill(0);
 
     Ok(())

329-334: Error message references wrong key.

The PDA assertion message incorrectly shows payer.key instead of book_manager.key, making debugging harder.

     assert_keys_equal(order_book.key, &pda, || {
         format!(
             "PDA for the account ('{}') and for book_manager ('{}') is incorrect",
-            order_book.key, payer.key
+            order_book.key, book_manager.key
         )
     })?;

402-402: Inconsistent log message casing.

Message says "Update orderbook" but other logs use "OrderBook" with capital letters and space for consistency.

-    msg!("Update orderbook");
+    msg!("Update order book");
test-integration/Cargo.toml (1)

40-40: Local path dependencies will break CI/CD builds.

These local path dependencies point to repositories outside the current codebase (../../ephemeral-rollups-sdk and ../../delegation-program) that are not cloned by the CI workflow. This will cause build failures for all contributors and in continuous integration.

Choose one of the following solutions:

  1. Revert to git-based dependencies (recommended for now):
-ephemeral-rollups-sdk = { path = "../../ephemeral-rollups-sdk/rust/sdk"}
+ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "..." }
  1. Update CI to clone required repositories before build steps in .github/workflows/ci-test-integration.yml

  2. Document the local setup in README with explicit clone instructions if local paths are intended for development only

Based on learnings: This appears to be a transition to local development setup but lacks the corresponding CI infrastructure updates.

Also applies to: 60-60

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99f2e8f and 7eaaa13.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • test-integration/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • magicblock-committor-service/src/tasks/args_task.rs (6 hunks)
  • programs/magicblock/src/magic_scheduled_base_intent.rs (7 hunks)
  • programs/magicblock/src/magicblock_processor.rs (2 hunks)
  • programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2 hunks)
  • test-integration/Cargo.toml (4 hunks)
  • test-integration/programs/schedulecommit/Cargo.toml (1 hunks)
  • test-integration/programs/schedulecommit/src/lib.rs (9 hunks)
  • test-integration/programs/schedulecommit/src/order_book.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-21T14:00:54.642Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 578
File: magicblock-aperture/src/requests/websocket/account_subscribe.rs:18-27
Timestamp: 2025-10-21T14:00:54.642Z
Learning: In magicblock-aperture account_subscribe handler (src/requests/websocket/account_subscribe.rs), the RpcAccountInfoConfig fields data_slice, commitment, and min_context_slot are currently ignored—only encoding is applied. This is tracked as technical debt in issue #579: https://github.com/magicblock-labs/magicblock-validator/issues/579

Applied to files:

  • magicblock-committor-service/src/tasks/args_task.rs
  • test-integration/programs/schedulecommit/src/lib.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
📚 Learning: 2025-10-26T08:49:31.543Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 585
File: magicblock-committor-service/src/tasks/buffer_task.rs:111-115
Timestamp: 2025-10-26T08:49:31.543Z
Learning: In the magicblock-committor-service, compute units returned by the `compute_units()` method in task implementations (such as `BufferTask`, `ArgsTask`, etc.) represent the compute budget for a single task. Transactions can comprise multiple tasks, and the total compute budget for a transaction is computed as the sum of the compute units of all tasks included in that transaction.

Applied to files:

  • magicblock-committor-service/src/tasks/args_task.rs
🧬 Code graph analysis (5)
magicblock-committor-service/src/tasks/args_task.rs (4)
magicblock-committor-service/src/tasks/mod.rs (2)
  • instruction (66-66)
  • instruction (249-255)
magicblock-committor-service/src/tasks/buffer_task.rs (2)
  • instruction (65-86)
  • new (37-45)
magicblock-committor-service/src/config.rs (1)
  • local (29-35)
magicblock-accounts/src/scheduled_commits_processor.rs (2)
  • new (66-90)
  • new (420-436)
programs/magicblock/src/magic_scheduled_base_intent.rs (1)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • committed_accounts (153-156)
programs/magicblock/src/magicblock_processor.rs (1)
programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (1)
  • process_schedule_commit (34-258)
programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (2)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • committed_accounts (153-156)
test-integration/test-committor-service/tests/test_ix_commit_local.rs (1)
  • base_intent (544-549)
test-integration/programs/schedulecommit/src/lib.rs (2)
test-integration/programs/schedulecommit/src/utils/mod.rs (3)
  • assert_is_signer (30-44)
  • assert_keys_equal (16-28)
  • allocate_account_and_assign_owner (58-106)
test-integration/programs/schedulecommit/src/order_book.rs (1)
  • new (105-125)
⏰ 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). (3)
  • GitHub Check: run_make_ci_format
  • GitHub Check: run_make_ci_test
  • GitHub Check: run_make_ci_test
🔇 Additional comments (14)
programs/magicblock/src/schedule_transactions/process_schedule_commit.rs (1)

29-32: Field addition looks correct.

The new request_diff field is properly scoped as pub(crate) and the Default trait will initialize it to false, maintaining backward compatibility.

programs/magicblock/src/magicblock_processor.rs (2)

44-51: ScheduleCommit handler correctly configured.

The handler properly sets request_diff: false to maintain the existing full-commit behavior for standard commits.


85-92: New instruction handler correctly implemented.

The ScheduleCommitDiffAndUndelegate handler properly enables both undelegation and diff-based commits by setting both flags to true. The implementation follows the established pattern from the other handlers.

programs/magicblock/src/magic_scheduled_base_intent.rs (4)

104-106: Delegation method correctly implemented.

The is_commit_diff() method appropriately delegates to the underlying base_intent, following the established pattern for other query methods in this struct.


155-163: Commit diff detection logic is correct.

The method correctly returns false for BaseActions and properly delegates to the commit-related variants to determine if differential commits are enabled.


317-327: StandaloneDiff variant added correctly.

The new variant follows the same structure as Standalone, holding Vec<CommittedAccount>. Note that full account data is stored here; the actual diff computation likely occurs downstream during commit processing.


448-484: Accessor methods properly handle StandaloneDiff.

All match expressions are now exhaustive and correctly handle the new StandaloneDiff variant. The is_commit_diff() method correctly returns true only for StandaloneDiff, and the accessor methods treat it consistently with Standalone.

magicblock-committor-service/src/tasks/args_task.rs (4)

1-24: LGTM: Imports support the CommitDiff feature.

All new imports are necessary for the RPC client setup, diff computation, and configuration.


30-30: LGTM: CommitDiff variant added.

Reusing CommitTask for the CommitDiff variant is appropriate since they share the same data requirements.


171-172: LGTM: Returning Err(self) for CommitDiff is correct.

The past review discussion thoroughly analyzed this and concluded that CommitDiff should return Err(self) (no optimization) because:

  • CommitDiff is already optimized by design—it transmits only the diff (e.g., 286 bytes) vs. full account data (10,240 bytes per your test)
  • Converting CommitDiff to BufferTask would be counterproductive and defeat its purpose
  • Err(self) correctly signals "no further optimization possible"

Suggestion: The TODO on line 171 can be resolved and removed based on the past review's analysis.


199-199: LGTM: Compute units appropriately reduced for CommitDiff.

The 65,000 compute unit allocation (5k less than Commit's 70k) aligns with your test observations and reflects the reduced data processing for diff-based commits.

test-integration/programs/schedulecommit/src/lib.rs (1)

419-439: LGTM—signer validation and error handling are now correct.

The function now properly returns NotEnoughAccountKeys when the accounts array doesn't match, and validates that payer is a signer before proceeding with the CPI call.

test-integration/programs/schedulecommit/Cargo.toml (1)

11-12: LGTM—dependencies appropriately support zero-copy OrderBook.

The rkyv crate provides AlignedVec for safe buffer allocation, and static_assertions enables compile-time layout verification. Both are correctly utilized in order_book.rs.

test-integration/Cargo.toml (1)

72-72: LGTM—workspace dependencies properly declared.

The rkyv and static_assertions crates are correctly added at the workspace level, enabling their use across integration test crates for zero-copy structures and compile-time assertions.

Also applies to: 91-91

Comment on lines 214 to 216
// TODO (snawaz): What should we use here? Commit (in the sense of "category of task"), or add a
// new variant "CommitDiff" to indicate a specific instruction?
ArgsTaskType::CommitDiff(_) => TaskType::Commit,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Design decision needed: Should CommitDiff map to TaskType::Commit or have its own variant?

The TODO raises a valid question. The answer depends on how TaskType is used:

  • Use TaskType::Commit (current approach) if TaskType represents operational categories and you want CommitDiff to be treated identically to Commit for scheduling, metrics, and logging purposes.

  • Add TaskType::CommitDiff if you need to distinguish them for:

    • Separate metrics/monitoring (track commit vs. commit-diff usage)
    • Different retry/error handling strategies
    • Granular observability

Run this script to see how TaskType is used across the codebase:

Based on the results, decide whether granular tracking justifies a separate variant.


🏁 Script executed:

#!/bin/bash
# Check how TaskType enum is used - pattern matching, metrics, logging, etc.

# Find TaskType definition
echo "=== TaskType definition ==="
ast-grep --pattern 'enum TaskType { $$$ }'

echo -e "\n=== TaskType usage in match expressions ==="
rg -nP --type=rust -C3 'match.*task_type\(\)|TaskType::' -g '!target/**'

echo -e "\n=== TaskType in metrics/logging ==="
rg -nP --type=rust -C2 'TaskType::(Commit|Finalize|Undelegate|Action)' -g '!target/**' | head -50

Length of output: 44482


🏁 Script executed:

#!/bin/bash
# Find TaskType enum definition
echo "=== Find TaskType enum definition ==="
rg -nP --type=rust 'enum\s+TaskType' -A 10

echo -e "\n=== Check how commit_tasks from partition are used ==="
rg -nP --type=rust -B 5 -A 10 'partition.*TaskType::Commit' | head -60

echo -e "\n=== Look for uses of partition results ==="
rg -nP --type=rust -A 20 'partition\(.*task_type.*==' -g '!target/**' | head -80

Length of output: 4450


🏁 Script executed:

#!/bin/bash
# Understand CommitDiff purpose and usage
echo "=== CommitDiff creation context in task_builder ==="
rg -nP --type=rust -B 8 -A 3 'ArgsTaskType::CommitDiff' magicblock-committor-service/src/tasks/task_builder.rs

echo -e "\n=== CommitDiff instruction generation ==="
rg -nP --type=rust -B 3 -A 15 'ArgsTaskType::CommitDiff\(value\) =>' magicblock-committor-service/src/tasks/args_task.rs | head -40

echo -e "\n=== How commit_diff parameter is determined ==="
rg -nP --type=rust -B 20 'commit_diff' magicblock-committor-service/src/tasks/task_builder.rs | grep -A 20 -B 20 'commit_diff'

Length of output: 4220


Add TaskType::CommitDiff variant to distinguish commit-diff tasks from regular commits.

The TODO identifies a legitimate design concern. CommitDiff and Commit have fundamentally different execution models:

  • Commit: Direct instruction, convertible to BufferTask, optimizable with lookup tables (70k compute units)
  • CommitDiff: RPC-based account fetching, cannot buffer, standalone execution (65k compute units)

Currently both map to TaskType::Commit, which masks this distinction and creates two problems:

  1. Incorrect optimization path: The partition at intent_executor/mod.rs:394 groups them together, and CommitDiff tasks may be treated as candidates for lookup table optimization despite being fundamentally different.

  2. Loss of semantic clarity: The conversion logic at args_task.rs:172 explicitly rejects CommitDiff for buffering, indicating they shouldn't follow the same execution path as regular Commit tasks.

Action: Add CommitDiff as a distinct TaskType variant to align the type system with the actual execution semantics, enabling proper task routing, metrics, and optimization decisions.

🤖 Prompt for AI Agents
In magicblock-committor-service/src/tasks/args_task.rs around lines 214 to 216,
the match arm mapping ArgsTaskType::CommitDiff to TaskType::Commit collapses two
different execution models; add a new TaskType::CommitDiff variant and change
this arm to return TaskType::CommitDiff, then search and update all switch/match
sites and type usages (e.g., intent_executor/mod.rs:394 partition logic,
args_task.rs:172 conversion path, routing/metrics/optimization checks) to handle
TaskType::CommitDiff separately so commit-diff tasks are not treated as
bufferable/lookup-table-optimizable Commit tasks.

@snawaz snawaz marked this pull request as draft November 2, 2025 12:23
…fficiently commit changes in delegated accounts
@snawaz snawaz force-pushed the snawaz/commit-diff branch from 7eaaa13 to c05f313 Compare November 2, 2025 13:10
@snawaz snawaz force-pushed the snawaz/commit-diff branch 2 times, most recently from d10afb6 to 5f0081c Compare November 3, 2025 05:46
@snawaz snawaz force-pushed the snawaz/commit-diff branch from 5f0081c to a4e8ee8 Compare November 3, 2025 06:40
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.

3 participants