Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions magicblock-committor-service/src/intent_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ where

if all_committed_pubkeys.is_empty() {
// Build tasks for commit stage
// TODO (snawaz): it's actually MagicBaseIntent::BaseActions scenario, not Commit
// scenario, so the related code needs little bit of refactoring and proper renaming.
// TODO (snawaz): this is a MagicBaseIntent::BasePreActions scenario,
// not a Commit scenario, so this path still needs a small refactor.
let commit_tasks = TaskBuilderImpl::commit_tasks(
&self.task_info_fetcher,
&intent_bundle,
persister,
)
.await?;

// Standalone actions executed in single stage
// Base pre-actions execute in single stage when there are no commits.
let strategy = TaskStrategist::build_strategy(
commit_tasks,
&self.authority.pubkey(),
Expand Down
8 changes: 4 additions & 4 deletions magicblock-committor-service/src/persist/commit_persister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ mod tests {
commit_and_undelegate: None,
commit_finalize: None,
commit_finalize_and_undelegate: None,
standalone_actions: vec![],
base_pre_actions: vec![],
}
}

Expand All @@ -514,7 +514,7 @@ mod tests {
}),
commit_finalize: None,
commit_finalize_and_undelegate: None,
standalone_actions: vec![],
base_pre_actions: vec![],
}
}

Expand All @@ -527,7 +527,7 @@ mod tests {
}),
commit_finalize: None,
commit_finalize_and_undelegate: None,
standalone_actions: vec![],
base_pre_actions: vec![],
}
}

Expand All @@ -537,7 +537,7 @@ mod tests {
commit_and_undelegate: None,
commit_finalize: None,
commit_finalize_and_undelegate: None,
standalone_actions: vec![],
base_pre_actions: vec![],
}
}

Expand Down
26 changes: 16 additions & 10 deletions magicblock-committor-service/src/stubs/changeset_committor_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,12 @@ fn count_bundle_callbacks(bundle: &ScheduledIntentBundle) -> usize {
.as_ref()
.map(|ct| match ct {
CommitType::Standalone(_) => 0,
CommitType::WithBaseActions { base_actions, .. } => {
base_actions.iter().filter(|a| a.callback.is_some()).count()
}
CommitType::BasePostActions {
base_post_actions, ..
} => base_post_actions
.iter()
.filter(|a| a.callback.is_some())
.count(),
})
.unwrap_or(0);

Expand All @@ -268,27 +271,30 @@ fn count_bundle_callbacks(bundle: &ScheduledIntentBundle) -> usize {
.map(|cau| {
let from_commit_action = match &cau.commit_action {
CommitType::Standalone(_) => 0,
CommitType::WithBaseActions { base_actions, .. } => {
base_actions.iter().filter(|a| a.callback.is_some()).count()
}
CommitType::BasePostActions {
base_post_actions, ..
} => base_post_actions
.iter()
.filter(|a| a.callback.is_some())
.count(),
};
let from_undelegate = match &cau.undelegate_action {
UndelegateType::Standalone => 0,
UndelegateType::WithBaseActions(actions) => {
UndelegateType::BasePostActions(actions) => {
actions.iter().filter(|a| a.callback.is_some()).count()
}
};
from_commit_action + from_undelegate
})
.unwrap_or(0);

let from_standalone = ib
.standalone_actions
let from_base_pre_actions = ib
.base_pre_actions
.iter()
.filter(|a| a.callback.is_some())
.count();

from_commit + from_cau + from_standalone
from_commit + from_cau + from_base_pre_actions
}

fn now() -> u64 {
Expand Down
30 changes: 18 additions & 12 deletions magicblock-committor-service/src/tasks/task_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ impl TasksBuilder for TaskBuilderImpl {
persister: &Option<P>,
) -> TaskBuilderResult<Vec<BaseTaskImpl>> {
let mut tasks = Vec::new();
// Add standalone actions first
// Add Base pre-actions first.
tasks.extend(Self::create_action_tasks(
intent_bundle.standalone_actions().as_slice(),
intent_bundle.base_pre_actions().as_slice(),
));

// Fetch data necessary for task creation
Expand Down Expand Up @@ -314,16 +314,16 @@ impl TasksBuilder for TaskBuilderImpl {
CommitType::Standalone(accounts) => {
accounts.iter().map(finalize_task).collect()
}
CommitType::WithBaseActions {
CommitType::BasePostActions {
committed_accounts,
base_actions,
base_post_actions,
} => {
let mut tasks = committed_accounts
.iter()
.map(finalize_task)
.collect::<Vec<_>>();
tasks.extend(TaskBuilderImpl::create_action_tasks(
base_actions,
base_post_actions,
));
tasks
}
Expand Down Expand Up @@ -358,7 +358,7 @@ impl TasksBuilder for TaskBuilderImpl {
})
.collect::<Vec<_>>();

if let UndelegateType::WithBaseActions(actions) =
if let UndelegateType::BasePostActions(actions) =
&commit_and_undelegate.undelegate_action
{
tasks.extend(TaskBuilderImpl::create_action_tasks(actions));
Expand Down Expand Up @@ -467,11 +467,14 @@ impl<'a> CommitFinalizeBuilder<'a> {
.into()
})
.collect();
if let CommitType::WithBaseActions {
ref base_actions, ..
if let CommitType::BasePostActions {
ref base_post_actions,
..
} = commit_type
{
tasks.extend(TaskBuilderImpl::create_action_tasks(base_actions));
tasks.extend(TaskBuilderImpl::create_action_tasks(
base_post_actions,
));
}
tasks
}
Expand Down Expand Up @@ -500,11 +503,14 @@ impl<'a> CommitFinalizeAndUndelegateBuilder<'a> {
.into()
})
.collect();
if let CommitType::WithBaseActions {
ref base_actions, ..
if let CommitType::BasePostActions {
ref base_post_actions,
..
} = commit_type
{
tasks.extend(TaskBuilderImpl::create_action_tasks(base_actions));
tasks.extend(TaskBuilderImpl::create_action_tasks(
base_post_actions,
));
}
tasks
}
Expand Down
24 changes: 15 additions & 9 deletions magicblock-magic-program-api/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ pub struct BaseActionArgs {
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum CommitTypeArgs {
Standalone(Vec<u8>), // indices on accounts
WithBaseActions {
/// Commit accounts, then execute Base-layer post-actions.
BasePostActions {
committed_accounts: Vec<u8>, // indices of accounts
base_actions: Vec<BaseActionArgs>,
base_post_actions: Vec<BaseActionArgs>,
},
}

impl CommitTypeArgs {
pub fn committed_accounts_indices(&self) -> &Vec<u8> {
match self {
Self::Standalone(value) => value,
Self::WithBaseActions {
Self::BasePostActions {
committed_accounts, ..
} => committed_accounts,
}
Expand All @@ -64,7 +65,10 @@ impl CommitTypeArgs {
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum UndelegateTypeArgs {
Standalone,
WithBaseActions { base_actions: Vec<BaseActionArgs> },
/// Execute Base-layer post-actions after undelegation.
BasePostActions {
base_post_actions: Vec<BaseActionArgs>,
},
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
Expand All @@ -81,7 +85,9 @@ impl CommitAndUndelegateArgs {

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum MagicBaseIntentArgs {
BaseActions(Vec<BaseActionArgs>),
/// Execute Base-layer pre-actions before lifecycle work if present;
/// otherwise this is action-only Base work.
BasePreActions(Vec<BaseActionArgs>),
Commit(CommitTypeArgs),
CommitAndUndelegate(CommitAndUndelegateArgs),
CommitFinalize(CommitTypeArgs),
Expand All @@ -94,15 +100,15 @@ pub struct MagicIntentBundleArgs {
pub commit_and_undelegate: Option<CommitAndUndelegateArgs>,
pub commit_finalize: Option<CommitTypeArgs>,
pub commit_finalize_and_undelegate: Option<CommitAndUndelegateArgs>,
pub standalone_actions: Vec<BaseActionArgs>,
pub base_pre_actions: Vec<BaseActionArgs>,
}

impl From<MagicBaseIntentArgs> for MagicIntentBundleArgs {
fn from(value: MagicBaseIntentArgs) -> Self {
let mut this = Self::default();
match value {
MagicBaseIntentArgs::BaseActions(value) => {
this.standalone_actions.extend(value)
MagicBaseIntentArgs::BasePreActions(value) => {
this.base_pre_actions.extend(value)
}
MagicBaseIntentArgs::Commit(value) => this.commit = Some(value),
MagicBaseIntentArgs::CommitAndUndelegate(value) => {
Expand Down Expand Up @@ -160,7 +166,7 @@ impl<'a> From<&AccountInfo<'a>> for ShortAccountMeta {
pub struct AddActionCallbackArgs {
/// Flat index of the action to attach the callback to, ordered as:
/// commit actions, commit_and_undelegate commit actions,
/// commit_and_undelegate undelegate actions, standalone actions.
/// commit_and_undelegate undelegate actions, Base pre-actions.
pub action_index: u8,
pub destination_program: Pubkey,
pub discriminator: Vec<u8>,
Expand Down
4 changes: 2 additions & 2 deletions magicblock-magic-program-api/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub enum MagicBlockInstruction {
///
/// A "base intent" is an atomic unit of work executed by the validator on the Base layer,
/// such as:
/// - executing standalone base actions (`BaseActions`)
/// - executing Base pre-actions (`BasePreActions`)
/// - committing a set of accounts (`Commit`)
/// - committing and undelegating accounts, optionally with post-actions (`CommitAndUndelegate`)
///
Expand Down Expand Up @@ -136,7 +136,7 @@ pub enum MagicBlockInstruction {
///
/// A "intent bundle" is an atomic unit of work executed by the validator on the Base layer,
/// such as:
/// - standalone base actions
/// - Base pre-actions
/// - an optional `Commit`
/// - an optional `CommitAndUndelegate`
///
Expand Down
Loading
Loading