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
23 changes: 17 additions & 6 deletions magicblock-accounts/src/remote_scheduled_commits_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use magicblock_committor_service::{
};
use magicblock_processor::execute_transaction::execute_legacy_transaction;
use magicblock_program::{
register_scheduled_commit_sent, FeePayerAccount, Pubkey, SentCommit,
TransactionScheduler,
register_scheduled_commit_sent, FeePayerAccount, Pubkey, ScheduledCommit,
SentCommit, TransactionScheduler,
};
use magicblock_transaction_status::TransactionStatusSender;
use solana_sdk::{
Expand Down Expand Up @@ -47,8 +47,19 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor {
IAP: InternalAccountProvider,
CC: ChangesetCommittor,
{
let scheduled_commits =
self.transaction_scheduler.take_scheduled_commits();
let scheduled_actions =
self.transaction_scheduler.take_scheduled_actions();

// TODO(edwin): remove once actions are supported
let scheduled_commits: Vec<ScheduledCommit> = scheduled_actions
.into_iter()
.filter_map(|action| {
action
.try_into()
.inspect_err(|err| error!("Unexpected action: {:?}", err))
.ok()
})
.collect();

if scheduled_commits.is_empty() {
return Ok(());
Expand Down Expand Up @@ -182,11 +193,11 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor {
}

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();
}
Comment on lines 195 to 201
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.

}

Expand Down
2 changes: 1 addition & 1 deletion magicblock-api/src/magic_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,4 +868,4 @@ fn try_get_remote_accounts_and_rpc_config(
Some(CommitmentLevel::Confirmed),
);
Ok((accounts_config, remote_rpc_config))
}
}
8 changes: 4 additions & 4 deletions magicblock-api/src/tickers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use magicblock_core::magic_program;
use magicblock_ledger::Ledger;
use magicblock_metrics::metrics;
use magicblock_processor::execute_transaction::execute_legacy_transaction;
use magicblock_program::{
magicblock_instruction::accept_scheduled_commits, MagicContext,
};
use magicblock_program::{instruction_utils::InstructionUtils, MagicContext};
use magicblock_transaction_status::TransactionStatusSender;
use solana_sdk::account::ReadableAccount;
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -54,7 +52,9 @@ pub fn init_slot_ticker(
if MagicContext::has_scheduled_commits(magic_context_acc.data()) {
// 1. Send the transaction to move the scheduled commits from the MagicContext
// to the global ScheduledCommit store
let tx = accept_scheduled_commits(bank.last_blockhash());
let tx = InstructionUtils::accept_scheduled_commits(
bank.last_blockhash(),
);
if let Err(err) = execute_legacy_transaction(
tx,
&bank,
Expand Down
4 changes: 1 addition & 3 deletions magicblock-mutator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ pub mod transactions;

pub use cluster::*;
pub use fetch::transaction_to_clone_pubkey_from_cluster;
pub use magicblock_program::magicblock_instruction::{
modify_accounts, AccountModification,
};
pub use magicblock_program::magicblock_instruction::AccountModification;
19 changes: 12 additions & 7 deletions magicblock-mutator/src/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use magicblock_program::{
magicblock_instruction::{
modify_accounts, modify_accounts_instruction, AccountModification,
},
validator,
instruction_utils::InstructionUtils,
magicblock_instruction::AccountModification, validator,
};
use solana_sdk::{
account::Account, bpf_loader_upgradeable, hash::Hash, pubkey::Pubkey,
Expand Down Expand Up @@ -35,7 +33,10 @@ pub fn transaction_to_clone_regular_account(
}
}
// We only need a single transaction with a single mutation in this case
modify_accounts(vec![account_modification], recent_blockhash)
InstructionUtils::modify_accounts(
vec![account_modification],
recent_blockhash,
)
}

pub fn transaction_to_clone_program(
Expand All @@ -61,10 +62,14 @@ pub fn transaction_to_clone_program(
// If the program does not exist yet, we just need to update it's data and don't
// need to explicitly update using the BPF loader's Upgrade IX
if !needs_upgrade {
return modify_accounts(account_modifications, recent_blockhash);
return InstructionUtils::modify_accounts(
account_modifications,
recent_blockhash,
);
}
// First dump the necessary set of account to our bank/ledger
let modify_ix = modify_accounts_instruction(account_modifications);
let modify_ix =
InstructionUtils::modify_accounts_instruction(account_modifications);
// The validator is marked as the upgrade authority of all program accounts
let validator_pubkey = &validator::validator_authority_id();
// Then we run the official BPF upgrade IX to notify the system of the new program
Expand Down
42 changes: 42 additions & 0 deletions programs/magicblock/src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct HandlerArgs {
pub escrow_index: u8,
pub data: Vec<u8>,
}

#[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
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum CommitTypeArgs {
Standalone(Vec<u8>), // indices on accounts
WithHandler {
committed_accounts: Vec<u8>, // indices of accounts
call_handlers: Vec<CallHandlerArgs>,
},
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum UndelegateTypeArgs {
Standalone,
WithHandler { call_handlers: Vec<CallHandlerArgs> },
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct CommitAndUndelegateArgs {
pub commit_type: CommitTypeArgs,
pub undelegate_type: UndelegateTypeArgs,
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum MagicActionArgs {
L1Action(Vec<CallHandlerArgs>),
Commit(CommitTypeArgs),
CommitAndUndelegate(CommitAndUndelegateArgs),
}
49 changes: 49 additions & 0 deletions programs/magicblock/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use num_derive::{FromPrimitive, ToPrimitive};
use serde::Serialize;
use solana_sdk::decode_error::DecodeError;
use thiserror::Error;

// -----------------
// Program CustomError Codes
// -----------------
Expand All @@ -6,3 +11,47 @@ pub mod custom_error_codes {
pub const UNABLE_TO_UNLOCK_SENT_COMMITS: u32 = 10_001;
pub const CANNOT_FIND_SCHEDULED_COMMIT: u32 = 10_002;
}

#[derive(
Error, Debug, Serialize, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive,
)]
pub enum MagicBlockProgramError {
#[error("need at least one account to modify")]
NoAccountsToModify,

#[error("number of accounts to modify needs to match number of account modifications")]
AccountsToModifyNotMatchingAccountModifications,

#[error("The account modification for the provided key is missing.")]
AccountModificationMissing,

#[error("first account needs to be MagicBlock authority")]
FirstAccountNeedsToBeMagicBlockAuthority,

#[error("MagicBlock authority needs to be owned by system program")]
MagicBlockAuthorityNeedsToBeOwnedBySystemProgram,

#[error("The account resolution for the provided key failed.")]
AccountDataResolutionFailed,

#[error("The account data for the provided key is missing both from in-memory and ledger storage.")]
AccountDataMissing,

#[error("The account data for the provided key is missing from in-memory and we are not replaying the ledger.")]
AccountDataMissingFromMemory,

#[error("Tried to persist data that could not be resolved.")]
AttemptedToPersistUnresolvedData,

#[error("Tried to persist data that was resolved from storage.")]
AttemptedToPersistDataFromStorage,

#[error("Encountered an error when persisting account modification data.")]
FailedToPersistAccountModData,
}

impl<T> DecodeError<T> for MagicBlockProgramError {
fn type_of() -> &'static str {
"MagicBlockProgramError"
}
}
3 changes: 3 additions & 0 deletions programs/magicblock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ mod magic_context;
mod mutate_accounts;
mod schedule_transactions;
pub use magic_context::{FeePayerAccount, MagicContext, ScheduledCommit};
pub mod args;
mod magic_schedule_action;
pub mod magicblock_instruction;
pub mod magicblock_processor;
#[cfg(test)]
Expand All @@ -16,3 +18,4 @@ pub use schedule_transactions::{
process_scheduled_commit_sent, register_scheduled_commit_sent,
transaction_scheduler::TransactionScheduler, SentCommit,
};
pub use utils::instruction_utils;
Loading