Skip to content

Conversation

@snawaz
Copy link
Contributor

@snawaz snawaz commented Oct 15, 2025

This PR does the following things:

  • Adds support for CommitDiff. So now when a commit is scheduled, it triggers either CommitState or CommitDiff in the delegation-program, depending on the account size and the COMMIT_STATE_SIZE_THRESHOLD.
    • CommitDiff is effectively an optimization that reduces the amount of data transferred when committing small changes in large accounts, which improves performance and reduces costs.
    • 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.

Update dlp.so

Updated test-integration/schedulecommit/elfs/dlp.so to use latest version of DLP with CommitDiff ix.

Changes in the existing tests.

Two kinds of changes:

  • Since it is CommitTask which decides the exact DLP instruction CommitState or CommitDiff, and many tests which earlier used to get executed as BufferTask, will now be executed as ArgsTask because large accounts with small changes can be executed as ArgsTask as long as the transaction size stays within limit. So made the related changes in the tests.

  • For some tests, I made the following change:

    -#[tokio::test]
    +#[tokio::test(flavor = "multi_thread", worker_threads = 2)]

    It is because now CommitTask::new() uses blocking RpcClient to fetch account from the base chain, so the tests fail because they run in a single-threaded environment, giving this error:

    can call blocking only when running on the multi-threaded runtime

    Using multi_thread with 2 threads makes the tests work again.

Screenshots

image image

Summary by CodeRabbit

  • New Features

    • Order-book support: init/grow/update/delegate order-book accounts, schedule diffs/commits, and new OrderBook types/APIs.
    • Commit-diff and size-aware strategy: threshold-based selection, optional base-account fetching, and parallel base-account retrieval.
    • Selectable user-seed modes to choose delegation/init behavior (OrderBook vs default).
    • TaskBuilderImpl and task-creation API to produce size-aware commit tasks.
  • Tests

    • Expanded integration/unit tests covering order-book flows, diff/size boundaries, strategies, and concurrent task creation.
  • Chores

    • Workspace dependency updates and new test dependencies.

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

Copy link
Contributor Author

snawaz commented Oct 15, 2025

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

@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)

@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

@snawaz snawaz marked this pull request as draft November 2, 2025 12:23
@snawaz snawaz force-pushed the snawaz/commit-diff branch from 7eaaa13 to c05f313 Compare November 2, 2025 13:10
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 (1)
test-integration/programs/schedulecommit/src/order_book.rs (1)

142-145: Consider failing loudly on capacity exhaustion to maintain test invariants.

The current implementation silently ignores failures from add_bids and add_asks, which can leave the order book in a partially updated state if capacity is exhausted mid-update (e.g., bids succeed but asks fail). For test code, this could mask capacity planning issues.

Since you stated "It's a test. So let it panic!" in a previous review, consider unwrapping the results to make capacity issues immediately visible:

 pub fn update_from(&mut self, updates: BookUpdate) {
-    self.add_bids(&updates.bids);
-    self.add_asks(&updates.asks);
+    self.add_bids(&updates.bids)
+        .expect("insufficient capacity for bids in update");
+    self.add_asks(&updates.asks)
+        .expect("insufficient capacity for asks in update");
 }

This ensures test failures are loud rather than leaving the book in an inconsistent state.

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

137-137: Base account fetch errors silently fall back to CommitState.

Using unwrap_or_default() means any error fetching base accounts is silently ignored, and all affected accounts will use CommitState instead of CommitDiff. This matches the PR's intent that CommitDiff is an optimization, not a requirement.

Consider adding a debug/warn log when the fallback occurs to aid troubleshooting:

🔎 Optional: Add warning log on fallback
-        let base_accounts = base_accounts.unwrap_or_default();
+        let base_accounts = match base_accounts {
+            Ok(accounts) => accounts,
+            Err(err) => {
+                log::warn!(
+                    "Failed to fetch base accounts for CommitDiff (intent_id={}): {}; falling back to CommitState",
+                    base_intent.id, err
+                );
+                Default::default()
+            }
+        };
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 333f137 and aad2791.

📒 Files selected for processing (6)
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
  • magicblock-committor-service/src/tasks/task_builder.rs
  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • test-integration/test-committor-service/tests/common.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • test-integration/test-committor-service/tests/common.rs
🧰 Additional context used
🧠 Learnings (11)
📚 Learning: 2025-12-03T09:33:48.707Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: test-integration/test-committor-service/tests/test_ix_commit_local.rs:867-881
Timestamp: 2025-12-03T09:33:48.707Z
Learning: Repo: magicblock-labs/magicblock-validator PR: 639
Context: test-integration/test-committor-service/tests/test_ix_commit_local.rs (ix_commit_local)
Learning: The PhotonIndexer used for compressed account fetches (get_compressed_account) has built‑in retry logic (defaults to ~10 attempts), so tests should not add separate retry loops around compressed fetches unless there’s a specific need.

Applied to files:

  • magicblock-committor-service/src/tasks/task_builder.rs
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
📚 Learning: 2025-12-03T09:36:01.527Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/src/remote_account_provider/mod.rs:1350-1353
Timestamp: 2025-12-03T09:36:01.527Z
Learning: Repo: magicblock-labs/magicblock-validator
File: magicblock-chainlink/src/remote_account_provider/mod.rs
Context: consolidate_fetched_remote_accounts
Learning: For unexpected result counts (>2), the project prefers logging an error and returning an empty Vec over panicking; acceptable during development per maintainer (Dodecahedr0x).

Applied to files:

  • magicblock-committor-service/src/tasks/task_builder.rs
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.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/intent_executor/task_info_fetcher.rs
  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
📚 Learning: 2025-11-07T13:20:13.793Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: magicblock-processor/src/scheduler/coordinator.rs:227-238
Timestamp: 2025-11-07T13:20:13.793Z
Learning: In magicblock-processor's ExecutionCoordinator (scheduler/coordinator.rs), the `account_contention` HashMap intentionally does not call `shrink_to_fit()`. Maintaining slack capacity is beneficial for performance by avoiding frequent reallocations during high transaction throughput. As long as empty entries are removed from the map (which `clear_account_contention` does), the capacity overhead is acceptable.

Applied to files:

  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
📚 Learning: 2025-11-07T14:20:31.457Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs:457-495
Timestamp: 2025-11-07T14:20:31.457Z
Learning: In magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs, the unsubscribe closure returned by PubSubConnection::account_subscribe(...) resolves to () (unit), not a Result. Downstream code should not attempt to inspect an unsubscribe result and can optionally wrap it in a timeout to guard against hangs.

Applied to files:

  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
  • magicblock-committor-service/src/tasks/task_strategist.rs
📚 Learning: 2025-11-19T09:34:37.917Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: test-integration/test-chainlink/tests/ix_remote_account_provider.rs:62-63
Timestamp: 2025-11-19T09:34:37.917Z
Learning: In test-integration/test-chainlink/tests/ix_remote_account_provider.rs and similar test files, the `_fwd_rx` receiver returned by `init_remote_account_provider()` is intentionally kept alive (but unused) to prevent "receiver dropped" errors on the sender side. The pattern `let (remote_account_provider, _fwd_rx) = init_remote_account_provider().await;` should NOT be changed to `let (remote_account_provider, _) = ...` because dropping the receiver would cause send() operations to fail.

Applied to files:

  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
📚 Learning: 2025-10-26T16:53:29.820Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 587
File: magicblock-chainlink/src/remote_account_provider/mod.rs:134-0
Timestamp: 2025-10-26T16:53:29.820Z
Learning: In magicblock-chainlink/src/remote_account_provider/mod.rs, the `Endpoint::separate_pubsub_url_and_api_key()` method uses `split_once("?api-key=")` because the api-key parameter is always the only query parameter right after `?`. No additional query parameter parsing is needed for this use case.

Applied to files:

  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
📚 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:

  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
📚 Learning: 2025-11-20T17:25:23.444Z
Learnt from: JMirval
Repo: magicblock-labs/magicblock-validator PR: 656
File: programs/guinea/src/lib.rs:33-33
Timestamp: 2025-11-20T17:25:23.444Z
Learning: In the magicblock-validator codebase, task IDs (task_id) are i64 values that can be negative. The task scheduler is designed to handle any i64 value including negative task IDs. Task IDs are randomly generated using rand::random() which produces values across the full i64 range. No validation is needed to restrict task IDs to positive values.

Applied to files:

  • magicblock-committor-service/src/tasks/task_strategist.rs
📚 Learning: 2025-11-21T13:56:03.885Z
Learnt from: snawaz
Repo: magicblock-labs/magicblock-validator PR: 575
File: test-integration/programs/schedulecommit/src/utils/mod.rs:71-71
Timestamp: 2025-11-21T13:56:03.885Z
Learning: In Solana programs (BPF runtime), defensive checked conversions to `usize` (e.g., `try_into()`) are unnecessary when casting from `u64`. Solana exclusively runs in 64-bit environments where `usize` is 64 bits, so truncation is not a concern and simple `as usize` casts are appropriate.

Applied to files:

  • test-integration/programs/schedulecommit/src/order_book.rs
📚 Learning: 2025-11-21T10:22:07.520Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 661
File: magicblock-committor-service/src/intent_executor/single_stage_executor.rs:20-28
Timestamp: 2025-11-21T10:22:07.520Z
Learning: In magicblock-committor-service's SingleStageExecutor and TwoStageExecutor (single_stage_executor.rs and two_stage_executor.rs), the fields transaction_strategy, junk, and patched_errors are intentionally public because these executors are designed to be used independently outside of the IntentExecutor scope, and callers need access to these execution reports for cleanup and error handling.

Applied to files:

  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
🧬 Code graph analysis (4)
magicblock-committor-service/src/tasks/task_builder.rs (2)
magicblock-committor-service/src/intent_executor/task_info_fetcher.rs (3)
  • fetch_next_commit_ids (24-27)
  • fetch_next_commit_ids (166-233)
  • new (58-65)
magicblock-committor-service/src/tasks/args_task.rs (1)
  • new (42-47)
magicblock-committor-service/src/intent_executor/task_info_fetcher.rs (1)
test-integration/test-committor-service/tests/common.rs (2)
  • get_base_accounts (146-163)
  • new (53-56)
magicblock-committor-service/src/tasks/task_strategist.rs (3)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • create_commit_task (54-82)
magicblock-committor-service/src/tasks/args_task.rs (2)
  • new (42-47)
  • strategy (181-183)
magicblock-committor-service/src/tasks/buffer_task.rs (2)
  • new (40-48)
  • strategy (132-134)
test-integration/test-committor-service/tests/test_transaction_preparator.rs (3)
test-integration/test-committor-service/tests/common.rs (2)
  • new (53-56)
  • create_commit_task (175-191)
magicblock-committor-service/src/tasks/buffer_task.rs (1)
  • new (40-48)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • create_commit_task (54-82)
⏰ 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: Build Project
  • GitHub Check: run_make_ci_lint
  • GitHub Check: run_make_ci_test
🔇 Additional comments (12)
test-integration/programs/schedulecommit/src/order_book.rs (1)

1-231: LGTM! Previous critical issues have been successfully addressed.

The implementation now includes proper safeguards:

  • Alignment validation in try_new (lines 109-120) prevents UB from unaligned typed references
  • Capacity bounds checking (lines 128-133) ensures header lengths never exceed backing storage
  • Mutable aliasing issue resolved with mut book_bytes binding (line 64)

The unsafe slice operations in bids(), asks_reversed(), and the internal helpers are now safe because all invariants are established and validated at construction time in try_new.

The remaining_capacity arithmetic is correct given Solana's 10MB account limit, as previously discussed.

magicblock-committor-service/src/intent_executor/task_info_fetcher.rs (2)

40-44: Trait method addition looks correct.

The new get_base_accounts method extends the TaskInfoFetcher trait to support batch fetching of base accounts for CommitDiff optimization. The signature is appropriate for the use case.


273-290: Implementation is correct and handles missing accounts gracefully.

The implementation correctly:

  • Fetches accounts in a single batched RPC call
  • Filters out None values for accounts that don't exist
  • Maps errors appropriately

One observation: unlike fetch_metadata_with_retries, this method has no retry logic. Per previous review discussions, base account fetching is treated as best-effort (falling back to CommitState if unavailable), so this is acceptable behavior.

test-integration/test-committor-service/tests/test_transaction_preparator.rs (2)

38-43: Test now uses TaskBuilderImpl for task construction.

Using TaskBuilderImpl::create_commit_task ensures the test exercises the actual task creation logic and respects the COMMIT_STATE_SIZE_THRESHOLD invariants. Passing None for base_account correctly produces a CommitTask (not CommitDiff) since this test uses small account data.


93-102: The From<ArgsTaskType> implementation for BufferTaskType is correctly implemented.

The .task_type.into() pattern extracts ArgsTaskType from the ArgsTask and converts it to BufferTaskType via the From implementation defined in magicblock-committor-service/src/tasks/buffer_task.rs:68. Since the test uses create_commit_task() which produces a Commit variant, the conversion succeeds and constructs valid buffer tasks.

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

45-51: Threshold constant is well-documented.

The COMMIT_STATE_SIZE_THRESHOLD of 256 bytes is a reasonable choice for distinguishing small accounts (that benefit from CommitState's simplicity) from larger accounts (that benefit from CommitDiff's reduced data transfer). The comment clearly explains the rationale.


54-82: Task creation logic correctly implements CommitDiff selection.

The method properly:

  1. Checks if the account size exceeds COMMIT_STATE_SIZE_THRESHOLD before using base_account
  2. Creates CommitDiffTask only when a valid base_account is available for large accounts
  3. Falls back to CommitTask for small accounts or when no base account exists

The .into() conversion at the end cleanly wraps the ArgsTaskType into an ArgsTask.


152-158: Task creation loop is correct; TODO for future optimization is valid.

The TODO notes that remove() could be used instead of get().cloned() if accounts are guaranteed unique, which would avoid cloning. This is a reasonable future optimization but the current implementation is correct and safe.

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

419-425: MockInfoFetcher correctly returns empty map for base accounts.

Returning Ok(Default::default()) simulates the scenario where no base accounts are found on-chain, which causes all commit tasks to use CommitState. This is appropriate for existing tests that don't specifically test CommitDiff behavior.


429-468: Test helper correctly scaffolds diff-based commit task creation.

The create_test_commit_task helper:

  • Creates a CommitTask when diff_len == 0 (no base account)
  • Creates a CommitDiffTask when diff_len > 0 by generating a modified base_account
  • Uses wrapping_add(1) to create realistic byte differences

The assertion at line 455 guards against test misconfiguration. This enables comprehensive testing of both commit paths.


561-620: New tests comprehensively cover threshold-based optimization decisions.

These tests verify the key optimization scenarios:

  1. Large account, small diff (line 565): Uses Args strategy because CommitDiff instruction is small
  2. Large account, threshold+1 diff (line 585): Still uses Args - diff is small enough
  3. Large account, large diff (line 604): Falls back to Buffer strategy when diff exceeds capacity

The tests exercise the new CommitDiff path through TaskBuilderImpl::create_commit_task and verify that the strategy selection correctly considers the encoded instruction size, not just raw data size.


502-517: Existing tests correctly updated with diff_len=0 parameter.

All existing tests that previously tested CommitState behavior now explicitly pass diff_len=0, preserving their original semantics while adapting to the new helper signature.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

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

119-125: Minor inconsistency: >= vs > threshold comparison.

The diffable_pubkeys filter uses >= (line 122: account.account.data.len() >= COMMIT_STATE_SIZE_THRESHOLD), but create_commit_task uses > (line 61: account.account.data.len() > COMMIT_STATE_SIZE_THRESHOLD).

This means accounts with exactly 256 bytes will have their base account fetched but then ignored. Consider aligning both comparisons:

🔎 Proposed fix (use consistent `>` comparison)
         let diffable_pubkeys = accounts
             .iter()
             .filter(|account| {
-                account.account.data.len() >= COMMIT_STATE_SIZE_THRESHOLD
+                account.account.data.len() > COMMIT_STATE_SIZE_THRESHOLD
             })
             .map(|account| account.pubkey)
             .collect::<Vec<_>>();
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 333f137 and 5050443.

📒 Files selected for processing (6)
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
  • magicblock-committor-service/src/tasks/task_builder.rs
  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • test-integration/test-committor-service/tests/common.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
🧰 Additional context used
🧠 Learnings (8)
📚 Learning: 2025-12-03T09:33:48.707Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: test-integration/test-committor-service/tests/test_ix_commit_local.rs:867-881
Timestamp: 2025-12-03T09:33:48.707Z
Learning: Repo: magicblock-labs/magicblock-validator PR: 639
Context: test-integration/test-committor-service/tests/test_ix_commit_local.rs (ix_commit_local)
Learning: The PhotonIndexer used for compressed account fetches (get_compressed_account) has built‑in retry logic (defaults to ~10 attempts), so tests should not add separate retry loops around compressed fetches unless there’s a specific need.

Applied to files:

  • magicblock-committor-service/src/tasks/task_builder.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/test-committor-service/tests/common.rs
📚 Learning: 2025-12-03T09:36:01.527Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/src/remote_account_provider/mod.rs:1350-1353
Timestamp: 2025-12-03T09:36:01.527Z
Learning: Repo: magicblock-labs/magicblock-validator
File: magicblock-chainlink/src/remote_account_provider/mod.rs
Context: consolidate_fetched_remote_accounts
Learning: For unexpected result counts (>2), the project prefers logging an error and returning an empty Vec over panicking; acceptable during development per maintainer (Dodecahedr0x).

Applied to files:

  • magicblock-committor-service/src/tasks/task_builder.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/test-committor-service/tests/common.rs
📚 Learning: 2025-11-07T13:09:52.253Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: test-kit/src/lib.rs:275-0
Timestamp: 2025-11-07T13:09:52.253Z
Learning: In test-kit, the transaction scheduler in ExecutionTestEnv is not expected to shut down during tests. Therefore, using `.unwrap()` in test helper methods like `schedule_transaction` is acceptable and will not cause issues in the test environment.

Applied to files:

  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
📚 Learning: 2025-11-21T10:22:07.520Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 661
File: magicblock-committor-service/src/intent_executor/single_stage_executor.rs:20-28
Timestamp: 2025-11-21T10:22:07.520Z
Learning: In magicblock-committor-service's SingleStageExecutor and TwoStageExecutor (single_stage_executor.rs and two_stage_executor.rs), the fields transaction_strategy, junk, and patched_errors are intentionally public because these executors are designed to be used independently outside of the IntentExecutor scope, and callers need access to these execution reports for cleanup and error handling.

Applied to files:

  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
  • test-integration/test-committor-service/tests/common.rs
📚 Learning: 2025-11-07T14:20:31.457Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs:457-495
Timestamp: 2025-11-07T14:20:31.457Z
Learning: In magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs, the unsubscribe closure returned by PubSubConnection::account_subscribe(...) resolves to () (unit), not a Result. Downstream code should not attempt to inspect an unsubscribe result and can optionally wrap it in a timeout to guard against hangs.

Applied to files:

  • magicblock-committor-service/src/tasks/task_strategist.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/task_strategist.rs
📚 Learning: 2025-11-20T17:25:23.444Z
Learnt from: JMirval
Repo: magicblock-labs/magicblock-validator PR: 656
File: programs/guinea/src/lib.rs:33-33
Timestamp: 2025-11-20T17:25:23.444Z
Learning: In the magicblock-validator codebase, task IDs (task_id) are i64 values that can be negative. The task scheduler is designed to handle any i64 value including negative task IDs. Task IDs are randomly generated using rand::random() which produces values across the full i64 range. No validation is needed to restrict task IDs to positive values.

Applied to files:

  • magicblock-committor-service/src/tasks/task_strategist.rs
📚 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-committor-service/tests/common.rs
🧬 Code graph analysis (4)
magicblock-committor-service/src/tasks/task_builder.rs (3)
test-integration/test-committor-service/tests/common.rs (4)
  • create_commit_task (175-191)
  • fetch_next_commit_ids (126-131)
  • get_base_accounts (146-163)
  • new (53-56)
magicblock-committor-service/src/intent_executor/task_info_fetcher.rs (5)
  • fetch_next_commit_ids (24-27)
  • fetch_next_commit_ids (166-233)
  • get_base_accounts (41-44)
  • get_base_accounts (273-290)
  • new (58-65)
magicblock-committor-service/src/tasks/args_task.rs (1)
  • new (42-47)
test-integration/test-committor-service/tests/test_transaction_preparator.rs (2)
magicblock-committor-service/src/tasks/buffer_task.rs (1)
  • new (40-48)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • create_commit_task (54-82)
magicblock-committor-service/src/tasks/task_strategist.rs (3)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • create_commit_task (54-82)
magicblock-committor-service/src/tasks/args_task.rs (1)
  • strategy (181-183)
magicblock-committor-service/src/tasks/buffer_task.rs (1)
  • strategy (132-134)
test-integration/test-committor-service/tests/common.rs (1)
magicblock-committor-service/src/intent_executor/task_info_fetcher.rs (4)
  • new (58-65)
  • get_base_accounts (41-44)
  • get_base_accounts (273-290)
  • pubkeys (112-123)
⏰ 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). (2)
  • GitHub Check: run_make_ci_test
  • GitHub Check: Build Project
🔇 Additional comments (19)
test-integration/test-committor-service/tests/test_transaction_preparator.rs (4)

6-11: Import changes look correct.

The imports now reflect the shift to using TaskBuilderImpl for commit task creation. The removal of direct CommitTask import and addition of TaskBuilderImpl aligns with the PR's goal of centralizing task creation logic.


37-47: Correct usage of TaskBuilderImpl::create_commit_task.

The test properly uses the new task creation API with None for base_account, which will produce a CommitTask (not CommitDiff) since the account data is small (5 bytes, well below the 256-byte threshold).


93-122: Buffer task construction pattern is correct.

The .task_type.into() pattern properly extracts ArgsTaskType from the created ArgsTask and converts it to BufferTaskType for the BufferTask::new_preparation_required call. This aligns with the BufferTask::new signature shown in the relevant code snippets.


194-215: Consistent task creation pattern maintained.

The BufferTask construction follows the same pattern established in the previous test, ensuring consistency across the test suite.

test-integration/test-committor-service/tests/common.rs (4)

13-14: Import additions are correct.

The new imports for TaskInfoFetcherError and TaskInfoFetcherResult are required for implementing the get_base_accounts trait method.


115-119: Good helper extraction for MockTaskInfoFetcher creation.

Centralizing MockTaskInfoFetcher construction in create_task_info_fetcher reduces duplication and ensures the mock is consistently initialized with the RPC client across all tests.


122-122: Struct change to hold RPC client is appropriate.

Converting MockTaskInfoFetcher to a tuple struct with MagicblockRpcClient is necessary for the get_base_accounts implementation to make actual RPC calls in integration tests.


146-163: get_base_accounts implementation mirrors production code correctly.

The implementation follows the same pattern as CacheTaskInfoFetcher::get_base_accounts shown in the relevant code snippets: calling get_multiple_accounts, mapping errors to TaskInfoFetcherError::MagicBlockRpcClientError, and building a HashMap by filtering out None results.

magicblock-committor-service/src/tasks/task_strategist.rs (6)

292-292: Debug log removal is good.

Past review comments flagged debug println! statements; this removal addresses that feedback.


377-393: Import additions support new test functionality.

The system_program and COMMIT_STATE_SIZE_THRESHOLD imports are required for the updated test helper and new threshold-based test scenarios.


419-425: Mock returns empty base accounts, but new tests cover diff path directly.

The MockInfoFetcher::get_base_accounts returns an empty map, which means tests using TaskBuilderImpl::commit_tasks won't create CommitDiff tasks. However, the new tests (lines 561-620) correctly test the diff path by calling create_test_commit_task directly with a base_account, bypassing the fetcher and validating create_commit_task logic.


429-468: Test helper correctly supports both CommitState and CommitDiff paths.

The create_test_commit_task helper:

  • Creates a CommittedAccount with data_size bytes
  • When diff_len > 0, creates a base_account with the first diff_len bytes mutated
  • Passes the appropriate base_account (Some or None) to TaskBuilderImpl::create_commit_task

This design allows testing the threshold-based task type selection in create_commit_task.


561-620: New threshold-based tests validate diff optimization correctly.

These tests verify the strategy selection based on diff size:

  • Lines 561-578: Large account (66KB) with small diff (256 bytes) → TaskStrategy::Args (fits in transaction)
  • Lines 580-598: Large account with diff just above threshold (257 bytes) → TaskStrategy::Args (still fits)
  • Lines 600-620: Large account with large diff (1024 bytes) → TaskStrategy::Buffer (too large, needs buffer)

The tests correctly validate that CommitDiff tasks are optimized to buffers only when the encoded diff exceeds transaction size limits.


505-505: Existing tests correctly updated with diff_len=0.

All pre-existing tests now pass diff_len=0 to create_test_commit_task, preserving their original behavior of testing the CommitState path.

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

9-13: Import additions are appropriate.

The new imports for Account, CommitDiffTask, and CommitTask are required for the create_commit_task implementation.


45-51: Threshold constant is well-documented.

The COMMIT_STATE_SIZE_THRESHOLD of 256 bytes is appropriately documented with rationale for the choice. Making it pub enables its use in tests for threshold-based validation.


53-83: create_commit_task implementation is correct and clean.

The function properly:

  1. Only considers base_account for accounts larger than the threshold (line 61: >)
  2. Creates CommitDiffTask when base_account is available
  3. Falls back to CommitTask otherwise
  4. Converts to ArgsTask via .into()

This ensures small accounts always use the simpler CommitState path regardless of whether base data is available.


137-143: Graceful fallback on base account fetch failure.

When get_base_accounts fails, the code logs a warning and falls back to an empty map, causing all tasks to use CommitState instead of CommitDiff. This is appropriate degradation behavior that prioritizes commit success over optimization.


154-164: Task creation loop correctly uses the new API.

The loop properly:

  1. Retrieves commit_id from the fetched map (with expect for invariant violation)
  2. Clones base_account from the map when available
  3. Delegates to create_commit_task for task type selection

The TODO about using remove() instead of get().cloned() is a reasonable future optimization if account uniqueness can be guaranteed.

@magicblock-labs magicblock-labs deleted a comment from coderabbitai bot Dec 23, 2025
@snawaz snawaz force-pushed the snawaz/commit-diff branch from 5050443 to 252862d Compare December 23, 2025 22:23
coderabbitai[bot]

This comment was marked as spam.

@magicblock-labs magicblock-labs deleted a comment from coderabbitai bot Dec 24, 2025
@magicblock-labs magicblock-labs deleted a comment from coderabbitai bot Dec 24, 2025
Copy link
Contributor

@taco-paco taco-paco left a comment

Choose a reason for hiding this comment

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

LGTM!

@snawaz snawaz force-pushed the snawaz/commit-diff branch from 252862d to 3406ed9 Compare December 24, 2025 09:47
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/test-committor-service/tests/utils/instructions.rs (1)

2-4: Remove unused Signer import; order-book helper looks good

The InitOrderBookAndDelegateIxs struct and init_order_book_account_and_delegate_ixs helper correctly derive the order_book PDA, build the init and delegate instructions, and wire UserSeeds::OrderBook.

However, use test_kit::Signer; is unused and will cause unused_import lints; please drop it unless you plan to call trait methods from this module.

The println!("schedulecommit ID: {}", ID); is test‑only; if you want it to respect log levels, consider switching to debug!, but that’s optional.

Also applies to: 54-94

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

71-90: Authorization inconsistency: grow_order_book_instruction should require book_manager signature.

Line 80 marks book_manager as read-only non-signer (false), while init_order_book_instruction (line 59) marks it as a signer (true). This allows any payer to grow another entity's order book without authorization.

If book_manager should authorize growth (consistent with initialization), update line 80 to require a signature and add the corresponding on-chain validation in process_grow_order_book.


197-213: Missing book_manager authorization in update_order_book_instruction.

Similar to past feedback, this function omits the book_manager account. Since order books are PDAs derived from [b"order_book", book_manager.key], the conceptual owner should authorize updates.

Consider adding book_manager as a parameter and account meta, then validate authorization on-chain in process_update_order_book.


215-234: Missing book_manager authorization in schedule_commit_diff_instruction_for_order_book.

As with update_order_book_instruction, this function lacks the book_manager account, allowing anyone to schedule commits for any order book.

Add book_manager as a parameter and validate authorization on-chain in process_schedulecommit_for_orderbook.

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

307-341: Missing signer validation for book_manager in process_init_order_book.

Line 318 validates payer is a signer, but there's no corresponding check for book_manager. The instruction builder in api.rs (line 59) marks book_manager as a signer, but this handler never validates it.

Add assert_is_signer(book_manager, "book_manager")?; after line 318 to ensure authorization is checked before account creation.


343-385: Error message typo: should reference book_manager, not payer.

Line 362 incorrectly references payer.key in the PDA validation error message. It should reference book_manager.key to match the PDA derivation logic.

🔎 Proposed 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
         )
     })?;

390-423: Missing signer validation for payer in process_delegate_order_book.

The handler calls delegate_account (which creates accounts and transfers lamports) without first validating that payer is a signer. Add an explicit signer check before the CPI to provide clear error messages when the payer flag is missing.

🔎 Proposed fix
     let [payer, order_book, owner_program, buffer, delegation_record, delegation_metadata, delegation_program, system_program] =
         accounts
     else {
         return Err(ProgramError::NotEnoughAccountKeys);
     };
 
+    assert_is_signer(payer, "payer")?;
+
     let seeds_no_bump = [b"order_book", args.book_manager.as_ref()];

449-469: Missing PDA and ownership validation in process_schedulecommit_for_orderbook.

The handler schedules a commit for order_book_account without verifying:

  • The account is the expected PDA derived from the appropriate seeds.
  • The account is owned by this program.

This allows committing arbitrary accounts via this instruction. Add explicit validation to verify ownership and optionally validate the PDA derivation if book_manager can be passed as an account or in instruction data.

🔎 Recommended validation
     let [payer, order_book_account, magic_context, magic_program] = accounts
     else {
         return Err(ProgramError::NotEnoughAccountKeys);
     };
 
     assert_is_signer(payer, "payer")?;
 
+    // Validate order_book_account is owned by this program
+    if order_book_account.owner != &crate::ID {
+        msg!("order_book_account must be owned by this program");
+        return Err(ProgramError::IllegalOwner);
+    }
+
+    // Note: Full PDA validation would require book_manager to be passed
+    // as an account or in instruction data
+
     commit_and_undelegate_accounts(
🧹 Nitpick comments (5)
magicblock-committor-service/src/intent_executor/task_info_fetcher.rs (1)

273-290: Implementation looks correct.

The batched RPC call with proper error wrapping and filter_map to exclude missing accounts is well-structured. Consider whether an empty pubkeys slice should short-circuit to avoid an unnecessary RPC call (similar to fetch_metadata_with_retries at line 73-75), though this is a minor optimization.

🔎 Optional: Early return for empty pubkeys
 async fn get_base_accounts(
     &self,
     pubkeys: &[Pubkey],
 ) -> TaskInfoFetcherResult<HashMap<Pubkey, Account>> {
+    if pubkeys.is_empty() {
+        return Ok(HashMap::new());
+    }
     self.rpc_client
         .get_multiple_accounts(pubkeys, None)
test-integration/test-committor-service/tests/test_delivery_preparator.rs (2)

90-95: Unnecessary join_all for synchronous operations.

The closure |data| async { ... } doesn't perform any async I/O—create_commit_task and BufferTask::new_preparation_required are synchronous. Wrapping them in async {} and using join_all adds overhead without concurrency benefit.

🔎 Simpler synchronous collection
-    let buffer_tasks = join_all(datas.iter().map(|data| async {
-        let task = BufferTaskType::Commit(create_commit_task(data.as_slice()));
-        Box::new(BufferTask::new_preparation_required(task))
-            as Box<dyn BaseTask>
-    }))
-    .await;
+    let buffer_tasks: Vec<Box<dyn BaseTask>> = datas
+        .iter()
+        .map(|data| {
+            let task = BufferTaskType::Commit(create_commit_task(data.as_slice()));
+            Box::new(BufferTask::new_preparation_required(task)) as Box<dyn BaseTask>
+        })
+        .collect();

166-170: Same observation: join_all wraps synchronous code.

Similar to above—ArgsTask::from(task) is synchronous, so join_all provides no concurrency benefit here.

test-integration/test-committor-service/tests/test_ix_commit_local.rs (1)

34-41: Order-book commit helper and strategy tests are sound; watch undelegate semantics later

The new order-book flow (init_and_delegate_order_book_on_chain + commit_book_order_account) correctly:

  • funds the validator auth,
  • starts the committor service,
  • initializes and delegates an order-book account,
  • mutates exactly changed_len bytes before committing, and
  • verifies the chosen CommitStrategy for diff‑vs‑buffer scenarios.

The single/multi‑account tests updated to prefer CommitStrategy::Args are consistent with a diff‑first planner.

One caveat for future extensions: commit_book_order_account accepts undelegate, but all current call sites pass false. If you later add order‑book tests with undelegate = true, ix_commit_local’s expected_owner logic (which currently assumes flexi‑counter for undelegated accounts) will need to be extended to handle schedulecommit‑owned order‑book accounts.

Also applies to: 68-121, 188-251

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

41-47: Generic trait bounds remain unused but acceptable.

As noted in previous reviews, the trait bounds BorshDeserialize, PartialEq, and Eq on line 46 are not used by the function body. However, since this has been previously discussed and deferred, leaving them as-is for now is acceptable. Consider removing unused bounds in a future cleanup PR.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 252862d and 3406ed9.

⛔ Files ignored due to path filters (3)
  • Cargo.lock is excluded by !**/*.lock
  • test-integration/Cargo.lock is excluded by !**/*.lock
  • test-integration/schedulecommit/elfs/dlp.so is excluded by !**/*.so
📒 Files selected for processing (30)
  • Cargo.toml
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
  • magicblock-committor-service/src/tasks/args_task.rs
  • magicblock-committor-service/src/tasks/buffer_task.rs
  • magicblock-committor-service/src/tasks/mod.rs
  • magicblock-committor-service/src/tasks/task_builder.rs
  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/Cargo.toml
  • test-integration/programs/schedulecommit/Cargo.toml
  • test-integration/programs/schedulecommit/src/api.rs
  • test-integration/programs/schedulecommit/src/lib.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • test-integration/programs/schedulecommit/src/utils/mod.rs
  • test-integration/schedulecommit/client/src/schedule_commit_context.rs
  • test-integration/schedulecommit/client/src/verify.rs
  • test-integration/schedulecommit/test-scenarios/Cargo.toml
  • test-integration/schedulecommit/test-scenarios/tests/01_commits.rs
  • test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs
  • test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs
  • test-integration/schedulecommit/test-security/tests/01_invocations.rs
  • test-integration/test-committor-service/Cargo.toml
  • test-integration/test-committor-service/tests/common.rs
  • test-integration/test-committor-service/tests/test_delivery_preparator.rs
  • test-integration/test-committor-service/tests/test_ix_commit_local.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
  • test-integration/test-committor-service/tests/utils/instructions.rs
  • test-integration/test-committor-service/tests/utils/transactions.rs
  • test-integration/test-ledger-restore/tests/08_commit_update.rs
  • test-integration/test-tools/src/integration_test_context.rs
  • test-integration/test-tools/src/scheduled_commits.rs
🚧 Files skipped from review as they are similar to previous changes (5)
  • test-integration/test-tools/src/scheduled_commits.rs
  • test-integration/programs/schedulecommit/Cargo.toml
  • test-integration/test-tools/src/integration_test_context.rs
  • test-integration/programs/schedulecommit/src/utils/mod.rs
  • Cargo.toml
🧰 Additional context used
🧠 Learnings (21)
📚 Learning: 2025-12-03T09:33:48.707Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: test-integration/test-committor-service/tests/test_ix_commit_local.rs:867-881
Timestamp: 2025-12-03T09:33:48.707Z
Learning: Repo: magicblock-labs/magicblock-validator PR: 639
Context: test-integration/test-committor-service/tests/test_ix_commit_local.rs (ix_commit_local)
Learning: The PhotonIndexer used for compressed account fetches (get_compressed_account) has built‑in retry logic (defaults to ~10 attempts), so tests should not add separate retry loops around compressed fetches unless there’s a specific need.

Applied to files:

  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/schedulecommit/client/src/verify.rs
  • test-integration/test-ledger-restore/tests/08_commit_update.rs
  • test-integration/schedulecommit/test-security/tests/01_invocations.rs
  • test-integration/schedulecommit/test-scenarios/tests/01_commits.rs
  • magicblock-committor-service/src/tasks/mod.rs
  • test-integration/test-committor-service/tests/common.rs
  • test-integration/test-committor-service/tests/test_delivery_preparator.rs
  • magicblock-committor-service/src/tasks/args_task.rs
  • test-integration/Cargo.toml
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
  • test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs
  • magicblock-committor-service/src/tasks/task_builder.rs
  • test-integration/test-committor-service/tests/test_ix_commit_local.rs
  • test-integration/schedulecommit/client/src/schedule_commit_context.rs
  • test-integration/test-committor-service/tests/utils/transactions.rs
  • test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
📚 Learning: 2025-12-03T09:36:01.527Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: magicblock-chainlink/src/remote_account_provider/mod.rs:1350-1353
Timestamp: 2025-12-03T09:36:01.527Z
Learning: Repo: magicblock-labs/magicblock-validator
File: magicblock-chainlink/src/remote_account_provider/mod.rs
Context: consolidate_fetched_remote_accounts
Learning: For unexpected result counts (>2), the project prefers logging an error and returning an empty Vec over panicking; acceptable during development per maintainer (Dodecahedr0x).

Applied to files:

  • magicblock-committor-service/src/tasks/task_strategist.rs
  • test-integration/test-ledger-restore/tests/08_commit_update.rs
  • magicblock-committor-service/src/tasks/mod.rs
  • test-integration/test-committor-service/tests/common.rs
  • test-integration/programs/schedulecommit/src/api.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
  • magicblock-committor-service/src/tasks/task_builder.rs
  • test-integration/test-committor-service/tests/test_ix_commit_local.rs
  • test-integration/test-committor-service/tests/utils/transactions.rs
  • test-integration/programs/schedulecommit/src/lib.rs
  • test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
📚 Learning: 2025-11-07T14:20:31.457Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs:457-495
Timestamp: 2025-11-07T14:20:31.457Z
Learning: In magicblock-chainlink/src/remote_account_provider/chain_pubsub_client.rs, the unsubscribe closure returned by PubSubConnection::account_subscribe(...) resolves to () (unit), not a Result. Downstream code should not attempt to inspect an unsubscribe result and can optionally wrap it in a timeout to guard against hangs.

Applied to files:

  • magicblock-committor-service/src/tasks/task_strategist.rs
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.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/task_strategist.rs
  • magicblock-committor-service/src/tasks/mod.rs
  • test-integration/programs/schedulecommit/src/api.rs
  • magicblock-committor-service/src/tasks/args_task.rs
  • test-integration/test-committor-service/tests/test_ix_commit_local.rs
  • test-integration/schedulecommit/client/src/schedule_commit_context.rs
  • test-integration/programs/schedulecommit/src/lib.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
📚 Learning: 2025-11-20T17:25:23.444Z
Learnt from: JMirval
Repo: magicblock-labs/magicblock-validator PR: 656
File: programs/guinea/src/lib.rs:33-33
Timestamp: 2025-11-20T17:25:23.444Z
Learning: In the magicblock-validator codebase, task IDs (task_id) are i64 values that can be negative. The task scheduler is designed to handle any i64 value including negative task IDs. Task IDs are randomly generated using rand::random() which produces values across the full i64 range. No validation is needed to restrict task IDs to positive values.

Applied to files:

  • magicblock-committor-service/src/tasks/task_strategist.rs
📚 Learning: 2025-11-07T13:09:52.253Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: test-kit/src/lib.rs:275-0
Timestamp: 2025-11-07T13:09:52.253Z
Learning: In test-kit, the transaction scheduler in ExecutionTestEnv is not expected to shut down during tests. Therefore, using `.unwrap()` in test helper methods like `schedule_transaction` is acceptable and will not cause issues in the test environment.

Applied to files:

  • test-integration/schedulecommit/client/src/verify.rs
  • test-integration/schedulecommit/test-scenarios/tests/01_commits.rs
  • magicblock-committor-service/src/tasks/buffer_task.rs
  • magicblock-committor-service/src/tasks/mod.rs
  • test-integration/test-committor-service/tests/test_delivery_preparator.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
  • test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs
  • test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs
📚 Learning: 2025-11-19T09:34:37.917Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 621
File: test-integration/test-chainlink/tests/ix_remote_account_provider.rs:62-63
Timestamp: 2025-11-19T09:34:37.917Z
Learning: In test-integration/test-chainlink/tests/ix_remote_account_provider.rs and similar test files, the `_fwd_rx` receiver returned by `init_remote_account_provider()` is intentionally kept alive (but unused) to prevent "receiver dropped" errors on the sender side. The pattern `let (remote_account_provider, _fwd_rx) = init_remote_account_provider().await;` should NOT be changed to `let (remote_account_provider, _) = ...` because dropping the receiver would cause send() operations to fail.

Applied to files:

  • test-integration/test-ledger-restore/tests/08_commit_update.rs
  • magicblock-committor-service/src/tasks/buffer_task.rs
  • magicblock-committor-service/src/tasks/mod.rs
  • test-integration/test-committor-service/tests/test_delivery_preparator.rs
  • test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs
  • test-integration/test-committor-service/tests/test_ix_commit_local.rs
  • test-integration/test-committor-service/tests/utils/transactions.rs
  • test-integration/programs/schedulecommit/src/lib.rs
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
📚 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-ledger-restore/tests/08_commit_update.rs
  • magicblock-committor-service/src/tasks/mod.rs
  • test-integration/Cargo.toml
  • test-integration/test-committor-service/tests/test_ix_commit_local.rs
  • test-integration/test-committor-service/tests/utils/transactions.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
📚 Learning: 2025-11-19T12:55:48.931Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: test-integration/test-tools/src/validator.rs:193-197
Timestamp: 2025-11-19T12:55:48.931Z
Learning: In the magicblock-validator codebase, when constructing arguments for the light CLI test validator in start_light_validator_with_config (test-integration/test-tools/src/validator.rs), the shlex::split approach is necessary because the light CLI does not handle whitespaces properly in validator arguments. The string concatenation + shlex parsing pattern should not be refactored to direct argument construction in this specific case.

Applied to files:

  • test-integration/test-ledger-restore/tests/08_commit_update.rs
📚 Learning: 2025-11-07T13:20:13.793Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: magicblock-processor/src/scheduler/coordinator.rs:227-238
Timestamp: 2025-11-07T13:20:13.793Z
Learning: In magicblock-processor's ExecutionCoordinator (scheduler/coordinator.rs), the `account_contention` HashMap intentionally does not call `shrink_to_fit()`. Maintaining slack capacity is beneficial for performance by avoiding frequent reallocations during high transaction throughput. As long as empty entries are removed from the map (which `clear_account_contention` does), the capacity overhead is acceptable.

Applied to files:

  • magicblock-committor-service/src/tasks/mod.rs
  • test-integration/schedulecommit/client/src/schedule_commit_context.rs
  • test-integration/programs/schedulecommit/src/lib.rs
  • test-integration/programs/schedulecommit/src/order_book.rs
  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
📚 Learning: 2025-12-01T16:02:05.367Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 703
File: magicblock-chainlink/src/submux/mod.rs:652-654
Timestamp: 2025-12-01T16:02:05.367Z
Learning: In magicblock-chainlink/src/submux/mod.rs, the subscribe_program method intentionally adds program_id to program_subs before attempting the subscription. This ensures that even if the initial subscription fails or only partially succeeds across clients, the reconnection logic will retry the subscription. This is a deliberate design pattern for resilience in the multi-client architecture and should not be "fixed" to remove entries on failure.

Applied to files:

  • magicblock-committor-service/src/tasks/mod.rs
📚 Learning: 2025-11-04T10:48:00.070Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: magicblock-processor/src/scheduler/mod.rs:217-219
Timestamp: 2025-11-04T10:48:00.070Z
Learning: In magicblock-validator, the codebase uses a pattern where types containing non-Send/non-Sync fields (like Rc<RefCell<...>>) are marked with unsafe impl Send when they are guaranteed to be confined to a single thread through careful API design and thread spawning patterns.

Applied to files:

  • magicblock-committor-service/src/tasks/mod.rs
📚 Learning: 2025-11-07T18:19:48.996Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 614
File: test-integration/programs/schedulecommit/Cargo.toml:19-20
Timestamp: 2025-11-07T18:19:48.996Z
Learning: In Solana programs (crates depending on solana-program), the empty feature flags `custom-heap = []` and `custom-panic = []` are standard declarations required to avoid compiler warnings. These should not be flagged as unused features in Cargo.toml files for Solana program crates.

Applied to files:

  • test-integration/test-committor-service/Cargo.toml
  • test-integration/Cargo.toml
📚 Learning: 2025-11-21T10:22:07.520Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 661
File: magicblock-committor-service/src/intent_executor/single_stage_executor.rs:20-28
Timestamp: 2025-11-21T10:22:07.520Z
Learning: In magicblock-committor-service's SingleStageExecutor and TwoStageExecutor (single_stage_executor.rs and two_stage_executor.rs), the fields transaction_strategy, junk, and patched_errors are intentionally public because these executors are designed to be used independently outside of the IntentExecutor scope, and callers need access to these execution reports for cleanup and error handling.

Applied to files:

  • test-integration/test-committor-service/tests/common.rs
  • test-integration/test-committor-service/tests/test_delivery_preparator.rs
  • test-integration/test-committor-service/tests/test_transaction_preparator.rs
  • test-integration/test-committor-service/tests/test_ix_commit_local.rs
  • test-integration/test-committor-service/tests/utils/transactions.rs
📚 Learning: 2025-11-24T14:21:00.996Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: Cargo.toml:58-58
Timestamp: 2025-11-24T14:21:00.996Z
Learning: In the magicblock-validator codebase, magicblock-api/Cargo.toml intentionally uses borsh = "1.5.3" (instead of the workspace version 0.10.4) because it needs to deserialize types from the magic-domain-program external dependency, which requires borsh 1.5.x compatibility. This is an intentional exception for interoperability with the magic domain program.

Applied to files:

  • test-integration/test-committor-service/tests/test_delivery_preparator.rs
  • test-integration/Cargo.toml
  • test-integration/programs/schedulecommit/src/lib.rs
  • test-integration/schedulecommit/test-scenarios/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
📚 Learning: 2025-11-21T13:56:03.885Z
Learnt from: snawaz
Repo: magicblock-labs/magicblock-validator PR: 575
File: test-integration/programs/schedulecommit/src/utils/mod.rs:71-71
Timestamp: 2025-11-21T13:56:03.885Z
Learning: In Solana programs (BPF runtime), defensive checked conversions to `usize` (e.g., `try_into()`) are unnecessary when casting from `u64`. Solana exclusively runs in 64-bit environments where `usize` is 64 bits, so truncation is not a concern and simple `as usize` casts are appropriate.

Applied to files:

  • test-integration/Cargo.toml
  • 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
📚 Learning: 2025-11-20T08:57:07.217Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 650
File: magicblock-chainlink/src/submux/subscription_task.rs:13-99
Timestamp: 2025-11-20T08:57:07.217Z
Learning: In the magicblock-validator repository, avoid posting review comments that merely confirm code is correct or matches intended behavior without providing actionable feedback, suggestions for improvement, or identifying potential issues. Such confirmatory comments are considered unhelpful noise by the maintainers.

Applied to files:

  • test-integration/Cargo.toml
📚 Learning: 2025-11-21T11:03:26.756Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 664
File: magicblock-chainlink/src/testing/mod.rs:342-370
Timestamp: 2025-11-21T11:03:26.756Z
Learning: In the magicblock-validator codebase, avoid leaving review comments that merely acknowledge code is correct or well-structured when there is no actionable suggestion, improvement, or issue to flag. Only comment when there is something specific to recommend, fix, or clarify.

Applied to files:

  • test-integration/Cargo.toml
📚 Learning: 2025-10-26T16:53:29.820Z
Learnt from: thlorenz
Repo: magicblock-labs/magicblock-validator PR: 587
File: magicblock-chainlink/src/remote_account_provider/mod.rs:134-0
Timestamp: 2025-10-26T16:53:29.820Z
Learning: In magicblock-chainlink/src/remote_account_provider/mod.rs, the `Endpoint::separate_pubsub_url_and_api_key()` method uses `split_once("?api-key=")` because the api-key parameter is always the only query parameter right after `?`. No additional query parameter parsing is needed for this use case.

Applied to files:

  • magicblock-committor-service/src/intent_executor/task_info_fetcher.rs
🧬 Code graph analysis (14)
magicblock-committor-service/src/tasks/task_strategist.rs (4)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • create_commit_task (54-82)
magicblock-committor-service/src/tasks/args_task.rs (2)
  • new (42-47)
  • strategy (181-183)
magicblock-committor-service/src/tasks/buffer_task.rs (2)
  • new (40-48)
  • strategy (132-134)
magicblock-committor-service/src/tasks/mod.rs (1)
  • strategy (90-90)
test-integration/test-ledger-restore/tests/08_commit_update.rs (2)
test-integration/schedulecommit/test-security/tests/01_invocations.rs (1)
  • ctx (148-149)
test-integration/test-ledger-restore/src/lib.rs (1)
  • setup_validator_with_local_remote (104-118)
test-integration/schedulecommit/test-scenarios/tests/01_commits.rs (2)
test-integration/programs/schedulecommit/src/api.rs (2)
  • pda_and_bump (404-408)
  • schedule_commit_cpi_instruction (177-195)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (1)
  • get_context_with_delegated_committees (16-35)
magicblock-committor-service/src/tasks/buffer_task.rs (1)
magicblock-committor-service/src/tasks/args_task.rs (2)
  • from (36-38)
  • value (210-218)
test-integration/test-committor-service/tests/test_delivery_preparator.rs (2)
test-integration/test-committor-service/tests/common.rs (2)
  • create_commit_task (175-191)
  • new (53-56)
magicblock-committor-service/src/tasks/buffer_task.rs (2)
  • new (40-48)
  • new_preparation_required (33-38)
test-integration/test-committor-service/tests/utils/instructions.rs (1)
test-integration/programs/schedulecommit/src/api.rs (2)
  • init_order_book_instruction (51-69)
  • delegate_account_cpi_instruction (115-164)
test-integration/test-committor-service/tests/test_transaction_preparator.rs (3)
test-integration/test-committor-service/tests/common.rs (2)
  • new (53-56)
  • create_commit_task (175-191)
magicblock-committor-service/src/tasks/buffer_task.rs (1)
  • new (40-48)
magicblock-committor-service/src/tasks/task_builder.rs (1)
  • create_commit_task (54-82)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (2)
test-integration/schedulecommit/test-security/tests/01_invocations.rs (1)
  • ctx (148-149)
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/test-committor-service/tests/test_ix_commit_local.rs (1)
test-integration/test-committor-service/tests/utils/transactions.rs (2)
  • init_and_delegate_order_book_on_chain (240-298)
  • fund_validator_auth_and_ensure_validator_fees_vault (301-342)
test-integration/schedulecommit/client/src/schedule_commit_context.rs (2)
test-integration/programs/schedulecommit/src/order_book.rs (1)
  • try_new (106-140)
test-integration/test-tools/src/integration_test_context.rs (1)
  • try_new (116-118)
test-integration/test-committor-service/tests/utils/transactions.rs (1)
test-integration/test-committor-service/tests/utils/instructions.rs (2)
  • init_account_and_delegate_ixs (21-52)
  • init_order_book_account_and_delegate_ixs (61-94)
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-109)
test-integration/programs/schedulecommit/src/order_book.rs (1)
  • try_new (106-140)
test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs (3)
test-integration/programs/schedulecommit/src/api.rs (2)
  • schedule_commit_diff_instruction_for_order_book (215-234)
  • set_count_instruction (371-379)
test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs (2)
  • get_context_with_delegated_committees (16-35)
  • assert_one_committee_was_committed (41-65)
test-integration/schedulecommit/client/src/verify.rs (1)
  • fetch_and_verify_order_book_commit_result_from_logs (16-23)
magicblock-committor-service/src/intent_executor/task_info_fetcher.rs (2)
test-integration/test-committor-service/tests/common.rs (2)
  • get_base_accounts (146-163)
  • new (53-56)
magicblock-rpc-client/src/lib.rs (1)
  • new (243-245)
⏰ 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: Build Project
  • GitHub Check: run_make_ci_test
  • GitHub Check: run_make_ci_lint
🔇 Additional comments (36)
test-integration/test-committor-service/Cargo.toml (1)

26-26: LGTM! Consistent dev-dependency addition.

The new program-schedulecommit dev-dependency follows the same pattern as program-flexi-counter (line 25) and correctly uses the no-entrypoint feature, which is standard for Solana programs used as library dependencies in tests.

Verified that:

  • The test-integration workspace Cargo.toml defines program-schedulecommit at programs/schedulecommit
  • The program-schedulecommit crate exports the no-entrypoint feature
  • This dependency is actively used in test files (e.g., test_ix_commit_local.rs)
test-integration/test-ledger-restore/tests/08_commit_update.rs (1)

55-61: LGTM! Proper TempDir binding prevents premature cleanup.

Binding _tmpdir (instead of _) ensures the TempDir stays alive for the function scope, preventing the temporary directory from being deleted while the validator is still running.

Also applies to: 170-176

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

19-20: LGTM!

Adding rand and borsh as workspace dev-dependencies appropriately supports the new OrderBook test scaffolding introduced in this PR.

test-integration/Cargo.toml (1)

40-40: LGTM!

Dependency updates look appropriate:

  • ephemeral-rollups-sdk placement normalized
  • magicblock-delegation-program rev bump aligns with CommitDiff support
  • rkyv and static_assertions additions support test serialization needs

Also applies to: 60-62, 74-74, 93-93

magicblock-committor-service/src/intent_executor/task_info_fetcher.rs (1)

41-44: LGTM! Clean trait extension for batch account fetching.

The new get_base_accounts method provides efficient batch retrieval for the CommitDiff optimization path.

test-integration/test-committor-service/tests/utils/transactions.rs (3)

16-19: LGTM!

Import additions properly expose the new InitOrderBookAndDelegateIxs for order book test setup.


124-134: Pragmatic CommitState/CommitDiff handling.

The inline comment clearly explains why searching for "CommitState" also matches "CommitDiff"—this accommodates the optimizer's choice without forcing test updates. This trade-off is reasonable given the PR context.


238-298: LGTM! New order book initialization helper.

The function follows the established pattern from init_and_delegate_account_on_chain and correctly handles the two-phase init + delegate flow with the book_manager keypair as an additional signer.

test-integration/test-committor-service/tests/test_delivery_preparator.rs (1)

2-2: Import added for join_all.

test-integration/schedulecommit/test-security/tests/01_invocations.rs (2)

1-1: LGTM!

Import addition for UserSeeds alongside existing imports.


30-36: Correctly propagates UserSeeds to test context constructors.

The UserSeeds::MagicScheduleCommit parameter is now consistently passed to both try_new and try_new_random_keys, aligning with the broader API changes for seed-driven delegation flows.

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

7-8: LGTM!

The cfg guard correctly limits this import to test/dev contexts.


67-76: Temporary test scaffolding acknowledged.

Per prior discussion, the panic! for CommitDiff is intentional—this variant should not reach this code path in current tests, and the message clearly indicates this is temporary until the next PR adds proper support. The cfg guard ensures this doesn't affect production code.

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

2-23: Order-book verify helper correctly mirrors existing API

The added OrderBookOwned import and fetch_and_verify_order_book_commit_result_from_logs helper cleanly mirror the existing MainAccount-based function and keep call sites explicit. No changes needed.

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

17-17: CommitDiffTask and TaskBuilderImpl exposure look consistent

Importing Account, defining CommitDiffTask with base_account: Account, and re‑exporting TaskBuilderImpl align with the new diff‑based commit flow and match the builder API. Struct fields and derives are appropriate; no further changes needed.

Also applies to: 32-33, 111-117

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

13-19: Order-book diff commit flow and randomized test are well wired

The new order-book path (commit_and_undelegate_order_book_account plus test_committing_and_undelegating_huge_order_book_account) correctly uses UserSeeds::OrderBook, wires update_order_book_instruction and schedule_commit_diff_instruction_for_order_book, and validates that the committed OrderBookOwned exactly matches the generated BookUpdate (with reproducible RNG seeding). Existing helpers updated to pass UserSeeds::MagicScheduleCommit remain consistent with the new API.

Also applies to: 113-167, 300-362, 741-744

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

5-11: UserSeeds integration in commit tests is consistent

Passing UserSeeds::MagicScheduleCommit to both get_context_with_delegated_committees and delegate_account_cpi_instruction keeps PDA derivation and delegation semantics in sync with the updated schedulecommit API. The tests remain logically identical while being explicit about the user seed in use.

Also applies to: 45-52, 101-107, 222-239

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

377-392: Diff-aware strategist tests correctly exercise COMMIT_STATE_SIZE_THRESHOLD behavior

The updated test scaffolding—MockInfoFetcher with get_base_accounts, create_test_commit_task feeding TaskBuilderImpl::create_commit_task, and the new diff‑size‑sensitive tests—does a good job of validating that:

  • small diffs on large accounts stay on the Args/CommitDiff path, and
  • only when the diff becomes large do we fall back to buffer‑based commits.

This keeps TaskStrategist’s optimization decisions aligned with COMMIT_STATE_SIZE_THRESHOLD and the real commit task builder. No changes needed.

Also applies to: 396-425, 428-468, 503-559, 561-620, 700-711, 713-751, 753-853

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

45-51: LGTM! Threshold constant is well-documented.

The 256-byte threshold is a reasonable choice for distinguishing small accounts that benefit from full-state commits versus larger accounts that benefit from differential commits. The documentation clearly explains the rationale.


53-83: LGTM! Task selection logic is sound.

The method correctly:

  • Applies the threshold to determine when differential commits are beneficial.
  • Gracefully falls back to full-state commits when base_account is unavailable or account is too small.
  • Uses field initialization shorthand for cleaner code.

113-143: LGTM! Parallel fetching optimizes latency.

The implementation efficiently:

  • Fetches commit IDs and base accounts concurrently using tokio::join!.
  • Filters accounts by threshold to avoid unnecessary base account fetches.
  • Handles errors appropriately: propagates commit ID failures (required) while gracefully degrading to full-state commits when base account fetches fail.

154-164: LGTM! Task creation integrates cleanly with the factory method.

The code correctly:

  • Retrieves commit IDs with appropriate error handling.
  • Clones base accounts from the map (reasonable since the map is only used here).
  • Delegates task creation to create_commit_task for consistent behavior.

The TODO comment about using .remove() is a valid micro-optimization for the future if duplicate accounts are confirmed to never occur.

test-integration/test-committor-service/tests/test_transaction_preparator.rs (1)

38-43: LGTM! Tests consistently use the factory method.

All test cases now create commit tasks via TaskBuilderImpl::create_commit_task(...), ensuring tests exercise the same code path as production. Passing None for base_account is appropriate for these tests, which focus on transaction preparation rather than differential commits.

Also applies to: 94-101, 106-111, 195-202

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

16-34: LGTM! UserSeeds integration is clean.

The function signature now accepts user_seed and correctly propagates it to the context constructors. The explicit init and delegate calls with transaction hash logging are helpful for debugging test scenarios.

test-integration/test-committor-service/tests/common.rs (2)

116-119: LGTM! Helper method simplifies test fixture usage.

The create_task_info_fetcher helper correctly constructs an Arc<MockTaskInfoFetcher> wrapping the test RPC client, centralizing the fetcher creation logic for test code.


122-122: LGTM! MockTaskInfoFetcher implementation is correct.

The implementation:

  • Correctly delegates to the inner MagicblockRpcClient for account fetches.
  • Maps RPC errors to the appropriate TaskInfoFetcherError variant.
  • Filters out None accounts and zips the results into a HashMap keyed by pubkey.

This aligns with the production CacheTaskInfoFetcher implementation pattern.

Also applies to: 146-163

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

66-80: LGTM! UserSeeds integration is consistent.

The constructors now accept user_seed and store it in the context. The PDA derivation at lines 115-118 correctly uses user_seed.bytes() and payer_ephem.pubkey(), matching the on-chain PDA derivation pattern in the program.

Also applies to: 115-118


166-208: LGTM! Order-book initialization branch is correct.

The init_committees method:

  • Adds compute budget instructions for sufficient CU allocation.
  • Branches on user_seed to call the appropriate initialization instruction (MainAccount vs OrderBook).
  • The commented-out grow_order_book code (lines 193-206) documents future work but doesn't impede functionality.

The implementation aligns with the program's instruction handlers.


265-275: LGTM! Delegation correctly passes user_seed.

The delegate_committees method now passes self.user_seed to delegate_account_cpi_instruction, ensuring the CPI instruction derives the correct PDA and uses the appropriate delegation variant (DelegateCpi vs DelegateOrderBook).

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

16-29: LGTM! UserSeeds enum improves type safety.

The enum-based approach is cleaner and safer than passing raw byte slices. The bytes() helper provides a single source of truth for seed values.

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

822-841: LGTM! Undelegate handler gracefully supports multiple account layouts.

The updated logic:

  • Attempts to deserialize as MainAccount first (matching the discriminant size).
  • Falls back to OrderBook for other sizes.
  • Logs deserialization failures without failing the transaction (helpful for debugging).

This flexible approach allows undelegation to work across different account types.

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

10-20: LGTM! Compile-time assertions document alignment requirements.

The const_assert! macros (lines 19-20, 34-35) document the expected alignment and size of OrderLevel and OrderBookHeader. This helps catch unintended layout changes at compile time.

Also applies to: 28-35


55-82: LGTM! Custom deserializer safely handles alignment.

The BorshDeserialize implementation:

  • Uses rkyv::AlignedVec to ensure proper alignment before constructing the OrderBook.
  • Copies the input bytes to avoid aliasing violations (appropriate for test code).
  • Converts via the safe try_new constructor, which validates alignment and capacity.

This approach avoids undefined behavior while providing a convenient deserialization path for test code.


106-140: LGTM! Runtime validation prevents undefined behavior.

The try_new method includes critical safety checks:

  • Lines 109-120: Validates alignment of header and levels to prevent misaligned pointer dereferences.
  • Lines 126-133: Validates that header lengths don't exceed capacity, preventing out-of-bounds slice construction in bids() and asks_reversed().

These guards ensure the unsafe operations in this type are sound and will fail cleanly if given malformed data.


142-184: LGTM! Update methods correctly manage bidirectional growth.

The update_from, add_bids, and add_asks methods:

  • Check remaining capacity before growing (preventing buffer overflows).
  • Use unsafe helpers to access uninitialized slots (appropriate for zero-copy pattern).
  • Correctly implement the bidirectional growth model (bids from left, asks from right in reverse order).

The implementation is sound given the validation in try_new.


186-199: LGTM! Accessor methods are safe given validation.

The bids() and asks_reversed() methods use slice::from_raw_parts to create typed slices over the order levels. These operations are safe because:

  • try_new validates alignment.
  • try_new validates that bids_len + asks_len <= capacity.
  • The layout ensures no overlap between bids and asks regions.

The comment at line 191 correctly notes that asks_reversed() returns entries in reverse order (latest first).

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

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

67-85: Consider caching the computed diff if instruction() may be called multiple times.

The diff is computed on-demand each time instruction() is called. While compute_diff is a pure computation (no I/O), it still involves iterating through the account data. If instruction() can be invoked multiple times for the same task (e.g., during serialization, logging, or retries), the diff would be recomputed unnecessarily.

Consider computing the diff once during task construction and storing it in CommitDiffTask, then referencing the cached value here. This would eliminate redundant computation while keeping the instruction builder clean.

💡 Potential optimization approach

Add a diff: Vec<u8> field to CommitDiffTask and compute it once during task creation, then reference it here:

 ArgsTaskType::CommitDiff(value) => {
     let args = CommitDiffArgs {
         nonce: value.commit_id,
         lamports: value.committed_account.account.lamports,
-        diff: compute_diff(
-            value.base_account.data(),
-            value.committed_account.account.data(),
-        )
-        .to_vec(),
+        diff: value.diff.clone(),
         allow_undelegation: value.allow_undelegation,
     };

188-188: Consider whether CommitDiff warrants a distinct TaskType variant.

Mapping CommitDiff to TaskType::Commit groups two operations with different characteristics:

  • Commit: Full state transfer, directly optimizable to BufferTask
  • CommitDiff: Differential update, downgrades to Commit before BufferTask conversion (lines 134-146)

While grouping them may simplify current logic, a distinct TaskType::CommitDiff would:

  • Make the execution model differences explicit
  • Enable separate metrics/monitoring for diff vs. full commits
  • Align type semantics with actual behavior

This aligns with your TODO comment expressing uncertainty about the correct approach. Consider confirming with reviewers whether the semantic distinction justifies a separate variant.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3406ed9 and f092b0b.

📒 Files selected for processing (1)
  • magicblock-committor-service/src/tasks/args_task.rs
🧰 Additional context used
🧠 Learnings (3)
📚 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
📚 Learning: 2025-12-03T09:33:48.707Z
Learnt from: Dodecahedr0x
Repo: magicblock-labs/magicblock-validator PR: 639
File: test-integration/test-committor-service/tests/test_ix_commit_local.rs:867-881
Timestamp: 2025-12-03T09:33:48.707Z
Learning: Repo: magicblock-labs/magicblock-validator PR: 639
Context: test-integration/test-committor-service/tests/test_ix_commit_local.rs (ix_commit_local)
Learning: The PhotonIndexer used for compressed account fetches (get_compressed_account) has built‑in retry logic (defaults to ~10 attempts), so tests should not add separate retry loops around compressed fetches unless there’s a specific need.

Applied to files:

  • magicblock-committor-service/src/tasks/args_task.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
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: run_make_ci_lint
🔇 Additional comments (4)
magicblock-committor-service/src/tasks/args_task.rs (4)

1-27: LGTM!

The imports and type definitions are clean and appropriate for adding CommitDiff support. The new ArgsTaskType::CommitDiff variant extends the enum naturally.


134-146: Temporary downgrade is acceptable given planned follow-up work.

The TODO clearly documents that this downgrade from CommitDiff to CommitTask is temporary until BufferTask supports CommitDiff. This is a reasonable intermediate state, and the explicit comment ensures the technical debt is tracked.


200-212: LGTM!

reset_commit_id now correctly handles both Commit and CommitDiff variants. This addresses the previous critical issue where CommitDiff tasks would retain stale commit IDs during recycling or retries.


219-219: LGTM!

The label value "args_commit_diff" follows the existing naming pattern and enables proper metrics tracking for CommitDiff tasks.

@snawaz snawaz added this pull request to the merge queue Dec 24, 2025
Merged via the queue into master with commit eb17e8a Dec 24, 2025
19 checks passed
@snawaz snawaz deleted the snawaz/commit-diff branch December 24, 2025 10:46
thlorenz added a commit that referenced this pull request Dec 24, 2025
* master:
  feat: Add support for `CommitDiff` to efficiently commit small changes in large delegated accounts (#575)
  feat: speedup ChainPubsubClientImpl creation by connecting them asynchronously (#775)
Dodecahedr0x pushed a commit that referenced this pull request Dec 30, 2025
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.

4 participants