Skip to content
Open
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
159 changes: 91 additions & 68 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ magicblock-committor-program = { path = "./magicblock-committor-program", featur
magicblock-committor-service = { path = "./magicblock-committor-service" }
magicblock-config = { path = "./magicblock-config" }
magicblock-core = { path = "./magicblock-core" }
magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "2cb491032f372", features = [
magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", branch = "snawaz/commit-finalize-from-buffer", features = [
"no-entrypoint",
] }
magicblock-ledger = { path = "./magicblock-ledger" }
Expand Down
3 changes: 3 additions & 0 deletions magicblock-committor-service/src/intent_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl metrics::LabelValue for ExecutionOutput {
}
}

#[derive(Debug)]
pub struct IntentExecutionResult {
/// Final result of Intent Execution
pub inner: IntentExecutorResult<ExecutionOutput>,
Expand Down Expand Up @@ -161,6 +162,8 @@ 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.
let commit_tasks = TaskBuilderImpl::commit_tasks(
&self.task_info_fetcher,
&intent_bundle,
Expand Down
14 changes: 14 additions & 0 deletions magicblock-committor-service/src/persist/commit_persister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ impl IntentPersisterImpl {
[
(false, intent_bundle.get_commit_intent_accounts()),
(true, intent_bundle.get_undelegate_intent_accounts()),
(false, intent_bundle.get_commit_finalize_intent_accounts()),
(
true,
intent_bundle
.get_commit_finalize_and_undelegate_intent_accounts(),
),
]
.into_iter()
.filter_map(|(undelegate, accounts)| {
Expand Down Expand Up @@ -494,6 +500,8 @@ mod tests {
MagicIntentBundle {
commit: Some(CommitType::Standalone(test_accounts())),
commit_and_undelegate: None,
commit_finalize: None,
commit_finalize_and_undelegate: None,
standalone_actions: vec![],
}
}
Expand All @@ -505,6 +513,8 @@ mod tests {
commit_action: CommitType::Standalone(test_accounts()),
undelegate_action: UndelegateType::Standalone,
}),
commit_finalize: None,
commit_finalize_and_undelegate: None,
standalone_actions: vec![],
}
}
Expand All @@ -516,6 +526,8 @@ mod tests {
commit_action: CommitType::Standalone(test_accounts()),
undelegate_action: UndelegateType::Standalone,
}),
commit_finalize: None,
commit_finalize_and_undelegate: None,
standalone_actions: vec![],
}
}
Expand All @@ -524,6 +536,8 @@ mod tests {
MagicIntentBundle {
commit: None,
commit_and_undelegate: None,
commit_finalize: None,
commit_finalize_and_undelegate: None,
standalone_actions: vec![],
}
}
Expand Down
61 changes: 56 additions & 5 deletions magicblock-committor-service/src/tasks/args_task.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use dlp::{
args::{CommitDiffArgs, CommitStateArgs},
args::{CommitDiffArgs, CommitFinalizeArgs, CommitStateArgs},
compute_diff,
instruction_builder::{
call_handler_size_budget, call_handler_v2_size_budget,
commit_diff_size_budget, commit_size_budget, finalize_size_budget,
undelegate_size_budget,
commit_diff_size_budget, commit_finalize_size_budget,
commit_size_budget, finalize_size_budget, undelegate_size_budget,
},
AccountSizeClass,
};
Expand All @@ -19,15 +19,16 @@ use crate::tasks::{
buffer_task::{BufferTask, BufferTaskType},
visitor::Visitor,
BaseActionTask, BaseActionV2Task, BaseTask, BaseTaskError, BaseTaskResult,
CommitDiffTask, CommitTask, FinalizeTask, PreparationState, TaskType,
UndelegateTask,
CommitDiffTask, CommitFinalizeTask, CommitTask, FinalizeTask,
PreparationState, TaskType, UndelegateTask,
};

/// Task that will be executed on Base layer via arguments
#[derive(Clone)]
pub enum ArgsTaskType {
Commit(CommitTask),
CommitDiff(CommitDiffTask),
CommitFinalize(CommitFinalizeTask),
Finalize(FinalizeTask),
Undelegate(UndelegateTask), // Special action really
BaseAction(BaseActionTask),
Expand Down Expand Up @@ -95,6 +96,38 @@ impl BaseTask for ArgsTask {
args,
)
}
ArgsTaskType::CommitFinalize(task) => {
let (data, data_is_diff) =
if let Some(base_account) = &task.base_account {
(
compute_diff(
base_account.data(),
task.committed_account.account.data(),
)
.to_vec(),
true,
)
} else {
(task.committed_account.account.data.clone(), false)
};

let mut args = CommitFinalizeArgs {
commit_id: task.commit_id,
lamports: task.committed_account.account.lamports,
data_is_diff: data_is_diff.into(),
allow_undelegation: task.allow_undelegation.into(),
bumps: Default::default(),
reserved_padding: Default::default(),
};

dlp::instruction_builder::commit_finalize(
*validator,
task.committed_account.pubkey,
&mut args,
&data,
)
.0
}
ArgsTaskType::Finalize(value) => {
dlp::instruction_builder::finalize(
*validator,
Expand All @@ -111,6 +144,8 @@ impl BaseTask for ArgsTask {
}
ArgsTaskType::BaseAction(value) => {
let action = &value.action;

#[allow(deprecated)]
dlp::instruction_builder::call_handler(
*validator,
action.destination_program,
Expand Down Expand Up @@ -147,6 +182,11 @@ impl BaseTask for ArgsTask {
BufferTaskType::CommitDiff(value),
)))
}
ArgsTaskType::CommitFinalize(value) => {
Ok(Box::new(BufferTask::new_preparation_required(
BufferTaskType::CommitFinalize(value),
)))
}
ArgsTaskType::BaseAction(_)
| ArgsTaskType::BaseActionV2(_)
| ArgsTaskType::Finalize(_)
Expand Down Expand Up @@ -175,6 +215,7 @@ impl BaseTask for ArgsTask {
match &self.task_type {
ArgsTaskType::Commit(_) => 70_000,
ArgsTaskType::CommitDiff(_) => 70_000,
ArgsTaskType::CommitFinalize(_) => 70_000,
ArgsTaskType::BaseAction(task) => task.action.compute_units,
ArgsTaskType::BaseActionV2(task) => task.action.compute_units,
ArgsTaskType::Undelegate(_) => 70_000,
Expand All @@ -194,6 +235,11 @@ impl BaseTask for ArgsTask {
task.committed_account.account.data.len() as u32,
))
}
ArgsTaskType::CommitFinalize(task) => {
commit_finalize_size_budget(AccountSizeClass::Dynamic(
task.committed_account.account.data.len() as u32,
))
}
ArgsTaskType::BaseAction(task) => {
// assume all other accounts are Small accounts.
let other_accounts_budget =
Expand Down Expand Up @@ -235,6 +281,7 @@ impl BaseTask for ArgsTask {
match &self.task_type {
ArgsTaskType::Commit(_) => TaskType::Commit,
ArgsTaskType::CommitDiff(_) => TaskType::Commit,
ArgsTaskType::CommitFinalize(_) => TaskType::CommitFinalize,
ArgsTaskType::BaseAction(_) | ArgsTaskType::BaseActionV2(_) => {
TaskType::Action
}
Expand All @@ -256,6 +303,9 @@ impl BaseTask for ArgsTask {
ArgsTaskType::CommitDiff(task) => {
task.commit_id = commit_id;
}
ArgsTaskType::CommitFinalize(task) => {
task.commit_id = commit_id;
}
ArgsTaskType::BaseAction(_)
| ArgsTaskType::BaseActionV2(_)
| ArgsTaskType::Finalize(_)
Expand All @@ -269,6 +319,7 @@ impl LabelValue for ArgsTask {
match self.task_type {
ArgsTaskType::Commit(_) => "args_commit",
ArgsTaskType::CommitDiff(_) => "args_commit_diff",
ArgsTaskType::CommitFinalize(_) => "args_commit_finalize",
ArgsTaskType::BaseAction(_) => "args_action",
ArgsTaskType::BaseActionV2(_) => "args_action_v2",
ArgsTaskType::Finalize(_) => "args_finalize",
Expand Down
70 changes: 66 additions & 4 deletions magicblock-committor-service/src/tasks/buffer_task.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use dlp::{
args::CommitStateFromBufferArgs,
args::{CommitFinalizeArgs, CommitStateFromBufferArgs},
compute_diff,
instruction_builder::{commit_diff_size_budget, commit_size_budget},
instruction_builder::{
commit_diff_size_budget, commit_finalize_from_buffer_size_budget,
commit_size_budget,
},
AccountSizeClass,
};
use magicblock_committor_program::Chunks;
use magicblock_metrics::metrics::LabelValue;
use solana_account::ReadableAccount;
use solana_instruction::Instruction;
use solana_pubkey::Pubkey;

Expand All @@ -17,8 +21,8 @@ use crate::{
consts::MAX_WRITE_CHUNK_SIZE,
tasks::{
visitor::Visitor, BaseTask, BaseTaskError, BaseTaskResult,
CommitDiffTask, CommitTask, PreparationState, PreparationTask,
TaskType,
CommitDiffTask, CommitFinalizeTask, CommitTask, PreparationState,
PreparationTask, TaskType,
},
};

Expand All @@ -27,6 +31,7 @@ use crate::{
pub enum BufferTaskType {
Commit(CommitTask),
CommitDiff(CommitDiffTask),
CommitFinalize(CommitFinalizeTask),
// Action in the future
}

Expand Down Expand Up @@ -85,6 +90,28 @@ impl BufferTask {
chunks,
})
}

BufferTaskType::CommitFinalize(task) => {
let data = if let Some(base_account) = &task.base_account {
compute_diff(
base_account.data(),
task.committed_account.account.data(),
)
.to_vec()
} else {
task.committed_account.account.data.clone()
};

let chunks =
Chunks::from_data_length(data.len(), MAX_WRITE_CHUNK_SIZE);

PreparationState::Required(PreparationTask {
commit_id: task.commit_id,
pubkey: task.committed_account.pubkey,
committed_data: data,
chunks,
})
}
}
}
}
Expand Down Expand Up @@ -151,6 +178,32 @@ impl BaseTask for BufferTask {
},
)
}

BufferTaskType::CommitFinalize(task) => {
let (data_buffer_pubkey, _) =
magicblock_committor_program::pdas::buffer_pda(
validator,
&task.committed_account.pubkey,
&task.commit_id.to_le_bytes(),
);

let mut args = CommitFinalizeArgs {
commit_id: task.commit_id,
lamports: task.committed_account.account.lamports,
data_is_diff: task.base_account.is_some().into(),
allow_undelegation: task.allow_undelegation.into(),
bumps: Default::default(),
reserved_padding: Default::default(),
};

dlp::instruction_builder::commit_finalize_from_buffer(
*validator,
task.committed_account.pubkey,
data_buffer_pubkey,
&mut args,
)
.0
}
}
}

Expand Down Expand Up @@ -181,6 +234,7 @@ impl BaseTask for BufferTask {
match self.task_type {
BufferTaskType::Commit(_) => 70_000,
BufferTaskType::CommitDiff(_) => 70_000,
BufferTaskType::CommitFinalize(_) => 70_000,
}
}

Expand All @@ -192,6 +246,9 @@ impl BaseTask for BufferTask {
BufferTaskType::CommitDiff(_) => {
commit_diff_size_budget(AccountSizeClass::Huge)
}
BufferTaskType::CommitFinalize(_) => {
commit_finalize_from_buffer_size_budget(AccountSizeClass::Huge)
}
}
}

Expand All @@ -204,6 +261,7 @@ impl BaseTask for BufferTask {
match self.task_type {
BufferTaskType::Commit(_) => TaskType::Commit,
BufferTaskType::CommitDiff(_) => TaskType::Commit,
BufferTaskType::CommitFinalize(_) => TaskType::CommitFinalize,
}
}

Expand All @@ -220,6 +278,9 @@ impl BaseTask for BufferTask {
BufferTaskType::CommitDiff(task) => {
task.commit_id = commit_id;
}
BufferTaskType::CommitFinalize(task) => {
task.commit_id = commit_id;
}
};

self.preparation_state = Self::preparation_required(&self.task_type)
Expand All @@ -231,6 +292,7 @@ impl LabelValue for BufferTask {
match self.task_type {
BufferTaskType::Commit(_) => "buffer_commit",
BufferTaskType::CommitDiff(_) => "buffer_commit_diff",
BufferTaskType::CommitFinalize(_) => "buffer_commit_finalize",
}
}
}
9 changes: 9 additions & 0 deletions magicblock-committor-service/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub use task_builder::TaskBuilderImpl;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum TaskType {
Commit,
CommitFinalize,
Finalize,
Undelegate,
Action,
Expand Down Expand Up @@ -123,6 +124,14 @@ pub struct CommitDiffTask {
pub base_account: Account,
}

#[derive(Clone, Debug)]
pub struct CommitFinalizeTask {
pub commit_id: u64,
pub allow_undelegation: bool,
pub base_account: Option<Account>, // None implies commit-full-bytes else commit-diff
pub committed_account: CommittedAccount,
}

#[derive(Clone, Debug)]
pub struct UndelegateTask {
pub delegated_account: Pubkey,
Expand Down
Loading