feat: add call_handler_v2 support for ScheduleIntentBundle actions#946
feat: add call_handler_v2 support for ScheduleIntentBundle actions#946
Conversation
Manual Deploy AvailableYou can trigger a manual deploy of this PR branch to testnet: Alternative: Comment
Comment updated automatically when the PR is synchronized. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughUpdated dependency revisions in Cargo.toml entries. Added Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
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 (2)
programs/magicblock/src/magic_scheduled_base_intent.rs (2)
542-550: 🧹 Nitpick | 🔵 TrivialThe
source_programfield is correctly placed and typed, but consider field ordering.The new field is inserted between
destination_programandescrow_authority. For serialization safety (as noted above), appending it as the last field would be less risky. Functionally, theOption<Pubkey>type is appropriate —Nonefor legacy,Some(pubkey)for v2.Safer field ordering
pub struct BaseAction { pub compute_units: u32, pub destination_program: Pubkey, - pub source_program: Option<Pubkey>, pub escrow_authority: Pubkey, pub data_per_program: ProgramArgs, pub account_metas_per_program: Vec<ShortAccountMeta>, + pub source_program: Option<Pubkey>, }This would require updating all construction sites, but avoids breaking positional deserialization if
BaseActionis ever read by old code.
575-596:⚠️ Potential issue | 🟠 MajorVerify serialization compatibility for the new
source_programfield inBaseAction.Adding
source_program: Option<Pubkey>in the middle of a#[derive(Serialize, Deserialize)]struct changes the serialized layout forbincode. SinceBaseActionis nested insideScheduledIntentBundlewithinMagicIntentBundle, which is persisted viaMagicContexton-chain state using bincode serialization, any in-flight scheduled intents serialized before this change would fail to deserialize after an upgrade.The code includes a backward compatibility mechanism via the
securefield (settingsource_programtoNonewhenfalse), but this does not address the binary format incompatibility for already-persisted data.If upgrades are atomic with no in-flight intents surviving, this is acceptable. Otherwise, consider:
- Appending the field at the end of the struct instead of inserting it in the middle to preserve binary compatibility.
- Ensuring all pending intents are drained before deploying this change.
🤖 Fix all issues with AI agents
In `@magicblock-committor-service/src/tasks/mod.rs`:
- Around line 169-173: BaseActionV2Task is missing a Debug impl which hampers
diagnostics; add Debug to its derives by updating the struct declaration for
BaseActionV2Task to derive(Debug, Clone). Ensure the types used in the struct
(BaseAction and Pubkey) already implement Debug (or make them implement/derive
Debug if necessary) so the derived Debug for BaseActionV2Task compiles cleanly.
Valid concern, I think we can do it as the last time, we can kill connection couple slots prior to shutdown and the MagicContext will be emptied |
… only within same smart contract
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@programs/magicblock/src/magic_scheduled_base_intent.rs`:
- Around line 575-593: The two branches currently return the same error variant
InstructionError::UnsupportedProgramId for different failure cases (missing CPI
vs cross-program call); update the second branch (the else that checks
args.destination_program == parent_program_id) to return a distinct error
variant or a custom/clearer InstructionError (e.g.,
InstructionError::IncorrectProgramId or a new variant) so callers can
distinguish the "not scheduled via CPI" failure (left as UnsupportedProgramId)
from the "cross-program prohibition for v1" failure; change the Err(...) in the
else branch referencing args.destination_program and parent_program_id
accordingly and keep the existing ic_msg! logs.
# Conflicts: # test-integration/Cargo.lock
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
programs/magicblock/src/magicblock_processor.rs (1)
75-86: 🧹 Nitpick | 🔵 TrivialBare boolean literals obscure the intent of
secureat the call site.Both call sites pass an unnamed
true/falsewithout any indication of what the flag controls. A reader must navigate toprocess_schedule_intent_bundleto learn thatsecuregovernscall_handler_v2selection andsource_programpopulation. A brief inline comment — or ideally a named constant — would make the distinction self-evident.🔍 Suggested clarification
- ScheduleBaseIntent(args) => process_schedule_intent_bundle( - signers, - invoke_context, - args.into(), - false, - ), - ScheduleIntentBundle(args) => process_schedule_intent_bundle( - signers, - invoke_context, - args, - true, - ), + // Legacy variant: use call_handler (no source_program) + ScheduleBaseIntent(args) => process_schedule_intent_bundle( + signers, + invoke_context, + args.into(), + false, // secure = false: legacy call_handler path + ), + // V2 variant: use call_handler_v2 (passes source_program) + ScheduleIntentBundle(args) => process_schedule_intent_bundle( + signers, + invoke_context, + args, + true, // secure = true: call_handler_v2 path + ),Additionally, the name
secureis semantically misleading — it sounds like a security/auth flag rather than a V2-handler selector. A name likeuse_v2_handlerorpass_source_programwould better express the actual branching behaviour. This applies to the function parameter inprograms/magicblock/src/schedule_transactions/process_schedule_intent_bundle.rs(line 31) and theConstructionContextfield.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@programs/magicblock/src/magicblock_processor.rs` around lines 75 - 86, Call sites to process_schedule_intent_bundle (ScheduleBaseIntent and ScheduleIntentBundle) currently pass bare true/false which obscures that the flag controls V2 handler selection and source_program population; update the API and calls to use a clearer name (e.g. rename the parameter secure to use_v2_handler or pass_source_program in process_schedule_intent_bundle and the corresponding ConstructionContext field) and replace the anonymous literals at the two call sites with the appropriate named constant or explicit inline comment so the intent is obvious (change ScheduleBaseIntent(...) to pass the false-named constant/comment and ScheduleIntentBundle(...) to pass the true-named constant/comment and update all references to the renamed parameter/field accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@programs/magicblock/src/magicblock_processor.rs`:
- Around line 75-86: Call sites to process_schedule_intent_bundle
(ScheduleBaseIntent and ScheduleIntentBundle) currently pass bare true/false
which obscures that the flag controls V2 handler selection and source_program
population; update the API and calls to use a clearer name (e.g. rename the
parameter secure to use_v2_handler or pass_source_program in
process_schedule_intent_bundle and the corresponding ConstructionContext field)
and replace the anonymous literals at the two call sites with the appropriate
named constant or explicit inline comment so the intent is obvious (change
ScheduleBaseIntent(...) to pass the false-named constant/comment and
ScheduleIntentBundle(...) to pass the true-named constant/comment and update all
references to the renamed parameter/field accordingly).
* master: hotfix: integration tests (#983) hotfix: integration tests (#982) chore: revert offset change (#981) fix: stop setting loaded accounts data size limit (#980) Fix: flaky ledger reset integration test (#977) Feat: tui interface for the validator (#972) fix: slack ready-for-review reviewer display (#978) fix: SetLoadedAccountsDataSize (#976) feat: add call_handler_v2 support for ScheduleIntentBundle actions (#946) feat: implement ephemeral accounts (#915) fix: prevent overrides on subscription updates (#970) fix: ignore error on delete in fat truncation. Case when the disk is … (#924)
* master: (42 commits) chore: CI on self-hosted runner (#975) fix: handle failed Intents due to 5xx errors from server (#1005) feat: implement StreamManager for gRPC subscription management (#985) chore: improve delegation error messages and reuse chainslot across retries (#994) release: 0.8.1 (#998) Create RELEASE_PROCESS.md (#997) fix: wait for valid blockhash (#992) feat: Add ScheduleCommitFinalize to program-api only (#989) release: 0.8.0 (#979) hotfix: integration tests (#983) hotfix: integration tests (#982) chore: revert offset change (#981) fix: stop setting loaded accounts data size limit (#980) Fix: flaky ledger reset integration test (#977) Feat: tui interface for the validator (#972) fix: slack ready-for-review reviewer display (#978) fix: SetLoadedAccountsDataSize (#976) feat: add call_handler_v2 support for ScheduleIntentBundle actions (#946) feat: implement ephemeral accounts (#915) fix: prevent overrides on subscription updates (#970) ...
Summary
call_handler_v2support for base actions scheduled viaScheduleIntentBundle, passingsource_programto the delegation programScheduleBaseIntent(legacy) continues usingcall_handlerfor backward compatibility withexisting deployed contracts
BaseAction.source_programis nowOption<Pubkey>, set based on which instruction variant wasused
BaseActionV2Taskin the committor service to selectcall_handler_v2at the typelevel, avoiding runtime flag checks
Compatibility
Testing
Checklist
Summary by CodeRabbit
New Features
Bug Fixes
Chores