Skip to content

magicblock-program modification to migrate from ScheduledCommit to ScheduledAction #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: feat/base-layer-ix/main
Choose a base branch
from

Conversation

taco-paco
Copy link
Contributor

@taco-paco taco-paco commented May 20, 2025

This PR replaces ScheduledCommit with ScheduledAction in magicblock-program but not in validator. Replacement in validator will occur in follow up PR to split effort into smaller pieces. Right now ScheduledAction is converted to ScheduledCommit in validator, so it uses an old flow

With new ephemeral-sdk user can create something like:

let builder = MagicInstructionBuilder {
    payer: ctx.accounts.payer.to_account_info(),
    magic_context: ctx.accounts.magic_context.to_account_info(),
    magic_program: ctx.accounts.magic_program.to_account_info(),
    magic_action: MagicAction::Commit(
        CommitType::WithHandler {
            commited_accounts: vec![ctx.accounts.pda1.to_account_info(), ctx.accounts.pda2.to_account_info()]
            call_handlers: vec![CallHandler {
                accounts: vec![ctx.accounts.actor_pda.to_account_info(), ctx.accounts.destination_to_account_info(), system_program]
                args: HandlerArgs {
                    data,
                    escrow_index: 1
                },
                destination_program: ctx.accounts.destination_program.to_account_info()
            }]
        }
    )
}

builder.build_and_invoke()?

Now our SDK will create MagicActionArgs from this information, so for example CallHandlerArgs will look like:

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct CallHandlerArgs {
    pub args: HandlerArgs,
    pub destination_program: u8, // index of the account
    pub accounts: Vec<u8>,       // indices of account
}

And once we get this in magicblock-program we are able to reconstruct data from indices, see MagicAction::try_from_args.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

23 file(s) reviewed, 33 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 229 to 201
fn scheduled_commits_len(&self) -> usize {
self.transaction_scheduler.scheduled_commits_len()
self.transaction_scheduler.scheduled_actions_len()
}

fn clear_scheduled_commits(&self) {
self.transaction_scheduler.clear_scheduled_commits();
self.transaction_scheduler.clear_scheduled_actions();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Method names have been updated but the trait interface still uses 'commits' terminology. This inconsistency could cause confusion.

Copy link
Contributor

@bmuddha bmuddha left a comment

Choose a reason for hiding this comment

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

Looks good overall, left a few questions and nits

pub commit_sent_transaction: Transaction,
pub request_undelegation: bool,
}
// Q: can user initiate actions on arbitrary accounts?
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rephrase the whole QA, currently it's not clear and incoherent.

pub request_undelegation: bool,
}

impl From<ScheduledCommit> for ScheduledAction {
Copy link
Contributor

@bmuddha bmuddha May 21, 2025

Choose a reason for hiding this comment

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

Does this particular transition from commit to action (which is handled by delegation program) break anything. I.e. once the new delegation program is deployed, old validator code stops working until upgraded?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or does the DLP also maintain full backward compatibility, sorry for silly questions, I haven't seen the relevant changes to DLP.

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum MagicAction {
/// Actions without commitment or undelegation
CallHandler(Vec<CallHandler>),
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any checks on how much data we can cram into this? As far as I understand this is further encoded into solana transaction which does have size limitation.

@@ -309,7 +307,9 @@ mod tests {
data: Some(vec![1, 2, 3, 4, 5]),
rent_epoch: Some(88),
};
let ix = modify_accounts_instruction(vec![modification.clone()]);
let ix = InstructionUtils::modify_accounts_instruction(vec![
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: but please turn this InstructionUtils to mod, it's so unrusty to use empty types for free functions, I know it's a matter of taste and yada-yada, but this is just a rust convention.

Pubkey,
};

pub struct InstructionUtils;
Copy link
Contributor

Choose a reason for hiding this comment

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

please turn this into module

Copy link
Contributor

@GabrielePicco GabrielePicco left a comment

Choose a reason for hiding this comment

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

Overall LGTM! Left a question


#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Handler {
pub escrow_index: u8,
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: should the handler rely on a specific hardcoded index (e.g. 255) always used for the signing/handler or are there use-cases where multiple indexes are useful?
We could otherwise slightly simplify the code

@taco-paco taco-paco force-pushed the feat/base-layer-ix/magicblock-program branch from 83e7ba8 to 882edcb Compare June 5, 2025 04:04
@taco-paco taco-paco force-pushed the feat/base-layer-ix/magicblock-program branch from 882edcb to 0073370 Compare June 5, 2025 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants