From 1c0a0e25f22b68f8f0a70588d985634290a0acdb Mon Sep 17 00:00:00 2001 From: Sarfaraz Nawaz Date: Tue, 4 Nov 2025 22:57:03 +0530 Subject: [PATCH 1/6] feat: Execute CommitDiff as BufferTask --- .../src/tasks/args_task.rs | 10 +- .../src/tasks/buffer_task.rs | 138 ++++++++++++------ magicblock-committor-service/src/tasks/mod.rs | 1 - .../tasks/task_visitors/persistor_visitor.rs | 81 ++++++---- .../tasks/task_visitors/utility_visitor.rs | 40 +++-- test-integration/Cargo.toml | 2 +- .../tests/02_commit_and_undelegate.rs | 4 +- .../tests/test_ix_commit_local.rs | 6 +- 8 files changed, 183 insertions(+), 99 deletions(-) diff --git a/magicblock-committor-service/src/tasks/args_task.rs b/magicblock-committor-service/src/tasks/args_task.rs index 1bd5f1e5d..3a3f643be 100644 --- a/magicblock-committor-service/src/tasks/args_task.rs +++ b/magicblock-committor-service/src/tasks/args_task.rs @@ -132,16 +132,8 @@ impl BaseTask for ArgsTask { ))) } ArgsTaskType::CommitDiff(value) => { - // TODO (snawaz): Currently, we do not support executing CommitDiff - // as BufferTask, which is why we're forcing CommitDiffTask to become CommitTask - // before converting this task into BufferTask. Once CommitDiff is supported - // by BufferTask, we do not have to do this, as it's essentially a downgrade. Ok(Box::new(BufferTask::new_preparation_required( - BufferTaskType::Commit(CommitTask { - commit_id: value.commit_id, - allow_undelegation: value.allow_undelegation, - committed_account: value.committed_account, - }), + BufferTaskType::CommitDiff(value), ))) } ArgsTaskType::BaseAction(_) diff --git a/magicblock-committor-service/src/tasks/buffer_task.rs b/magicblock-committor-service/src/tasks/buffer_task.rs index 7a1fb1890..324accedb 100644 --- a/magicblock-committor-service/src/tasks/buffer_task.rs +++ b/magicblock-committor-service/src/tasks/buffer_task.rs @@ -1,4 +1,4 @@ -use dlp::args::CommitStateFromBufferArgs; +use dlp::{args::CommitStateFromBufferArgs, compute_diff}; use magicblock_committor_program::Chunks; use magicblock_metrics::metrics::LabelValue; use solana_instruction::Instruction; @@ -11,8 +11,9 @@ use crate::tasks::TaskStrategy; use crate::{ consts::MAX_WRITE_CHUNK_SIZE, tasks::{ - visitor::Visitor, BaseTask, BaseTaskError, BaseTaskResult, CommitTask, - PreparationState, PreparationTask, TaskType, + visitor::Visitor, BaseTask, BaseTaskError, BaseTaskResult, + CommitDiffTask, CommitTask, PreparationState, PreparationTask, + TaskType, }, }; @@ -20,6 +21,7 @@ use crate::{ #[derive(Clone)] pub enum BufferTaskType { Commit(CommitTask), + CommitDiff(CommitDiffTask), // Action in the future } @@ -48,19 +50,37 @@ impl BufferTask { } fn preparation_required(task_type: &BufferTaskType) -> PreparationState { - let BufferTaskType::Commit(ref commit_task) = task_type; - let committed_data = commit_task.committed_account.account.data.clone(); - let chunks = Chunks::from_data_length( - committed_data.len(), - MAX_WRITE_CHUNK_SIZE, - ); - - PreparationState::Required(PreparationTask { - commit_id: commit_task.commit_id, - pubkey: commit_task.committed_account.pubkey, - committed_data, - chunks, - }) + match task_type { + BufferTaskType::Commit(task) => { + let data = 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, + }) + } + + BufferTaskType::CommitDiff(task) => { + let diff = compute_diff( + &task.base_account.data, + &task.committed_account.account.data, + ) + .to_vec(); + let chunks = + Chunks::from_data_length(diff.len(), MAX_WRITE_CHUNK_SIZE); + + PreparationState::Required(PreparationTask { + commit_id: task.commit_id, + pubkey: task.committed_account.pubkey, + committed_data: diff, + chunks, + }) + } + } } } @@ -69,34 +89,60 @@ impl From for BufferTaskType { fn from(value: ArgsTaskType) -> Self { match value { ArgsTaskType::Commit(task) => BufferTaskType::Commit(task), - ArgsTaskType::CommitDiff(_) => panic!("BufferTask doesn't support CommitDiff yet. Disable your tests (if any) temporarily till the next PR"), - _ => unimplemented!("Only commit task can be BufferTask currently. Fix your tests"), + ArgsTaskType::CommitDiff(task) => BufferTaskType::CommitDiff(task), + _ => unimplemented!( + "Only commit task can be BufferTask currently. Fix your tests" + ), } } } impl BaseTask for BufferTask { fn instruction(&self, validator: &Pubkey) -> Instruction { - let BufferTaskType::Commit(ref value) = self.task_type; - let commit_id_slice = value.commit_id.to_le_bytes(); - let (commit_buffer_pubkey, _) = - magicblock_committor_program::pdas::buffer_pda( - validator, - &value.committed_account.pubkey, - &commit_id_slice, - ); - - dlp::instruction_builder::commit_state_from_buffer( - *validator, - value.committed_account.pubkey, - value.committed_account.account.owner, - commit_buffer_pubkey, - CommitStateFromBufferArgs { - nonce: value.commit_id, - lamports: value.committed_account.account.lamports, - allow_undelegation: value.allow_undelegation, - }, - ) + match &self.task_type { + BufferTaskType::Commit(task) => { + let commit_id_slice = task.commit_id.to_le_bytes(); + let (commit_buffer_pubkey, _) = + magicblock_committor_program::pdas::buffer_pda( + validator, + &task.committed_account.pubkey, + &commit_id_slice, + ); + + dlp::instruction_builder::commit_state_from_buffer( + *validator, + task.committed_account.pubkey, + task.committed_account.account.owner, + commit_buffer_pubkey, + CommitStateFromBufferArgs { + nonce: task.commit_id, + lamports: task.committed_account.account.lamports, + allow_undelegation: task.allow_undelegation, + }, + ) + } + BufferTaskType::CommitDiff(task) => { + let commit_id_slice = task.commit_id.to_le_bytes(); + let (commit_buffer_pubkey, _) = + magicblock_committor_program::pdas::buffer_pda( + validator, + &task.committed_account.pubkey, + &commit_id_slice, + ); + + dlp::instruction_builder::commit_diff_from_buffer( + *validator, + task.committed_account.pubkey, + task.committed_account.account.owner, + commit_buffer_pubkey, + CommitStateFromBufferArgs { + nonce: task.commit_id, + lamports: task.committed_account.account.lamports, + allow_undelegation: task.allow_undelegation, + }, + ) + } + } } /// No further optimizations @@ -125,6 +171,7 @@ impl BaseTask for BufferTask { fn compute_units(&self) -> u32 { match self.task_type { BufferTaskType::Commit(_) => 70_000, + BufferTaskType::CommitDiff(_) => 70_000, } } @@ -136,6 +183,7 @@ impl BaseTask for BufferTask { fn task_type(&self) -> TaskType { match self.task_type { BufferTaskType::Commit(_) => TaskType::Commit, + BufferTaskType::CommitDiff(_) => TaskType::Commit, } } @@ -145,12 +193,15 @@ impl BaseTask for BufferTask { } fn reset_commit_id(&mut self, commit_id: u64) { - let BufferTaskType::Commit(commit_task) = &mut self.task_type; - if commit_id == commit_task.commit_id { - return; - } + match &mut self.task_type { + BufferTaskType::Commit(task) => { + task.commit_id = commit_id; + } + BufferTaskType::CommitDiff(task) => { + task.commit_id = commit_id; + } + }; - commit_task.commit_id = commit_id; self.preparation_state = Self::preparation_required(&self.task_type) } } @@ -159,6 +210,7 @@ impl LabelValue for BufferTask { fn value(&self) -> &str { match self.task_type { BufferTaskType::Commit(_) => "buffer_commit", + BufferTaskType::CommitDiff(_) => "buffer_commit_diff", } } } diff --git a/magicblock-committor-service/src/tasks/mod.rs b/magicblock-committor-service/src/tasks/mod.rs index ea8b5c17a..1719b84ae 100644 --- a/magicblock-committor-service/src/tasks/mod.rs +++ b/magicblock-committor-service/src/tasks/mod.rs @@ -46,7 +46,6 @@ pub enum PreparationState { Cleanup(CleanupTask), } -#[cfg(test)] #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum TaskStrategy { Args, diff --git a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs index c608f2ef9..347f67959 100644 --- a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs +++ b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs @@ -26,27 +26,40 @@ where fn visit_args_task(&mut self, task: &ArgsTask) { match self.context { PersistorContext::PersistStrategy { uses_lookup_tables } => { - let ArgsTaskType::Commit(ref commit_task) = task.task_type - else { - return; - }; - let commit_strategy = if uses_lookup_tables { CommitStrategy::ArgsWithLookupTable } else { CommitStrategy::Args }; - if let Err(err) = self.persistor.set_commit_strategy( - commit_task.commit_id, - &commit_task.committed_account.pubkey, - commit_strategy, - ) { - error!( - "Failed to persist commit strategy {}: {}", - commit_strategy.as_str(), - err - ); + match &task.task_type { + ArgsTaskType::Commit(task) => { + if let Err(err) = self.persistor.set_commit_strategy( + task.commit_id, + &task.committed_account.pubkey, + commit_strategy, + ) { + error!( + "Failed to persist commit strategy {}: {}", + commit_strategy.as_str(), + err + ); + } + } + ArgsTaskType::CommitDiff(task) => { + if let Err(err) = self.persistor.set_commit_strategy( + task.commit_id, + &task.committed_account.pubkey, + commit_strategy, + ) { + error!( + "Failed to persist commit strategy {}: {}", + commit_strategy.as_str(), + err + ); + } + } + _ => {} } } } @@ -55,23 +68,39 @@ where fn visit_buffer_task(&mut self, task: &BufferTask) { match self.context { PersistorContext::PersistStrategy { uses_lookup_tables } => { - let BufferTaskType::Commit(ref commit_task) = task.task_type; let commit_strategy = if uses_lookup_tables { CommitStrategy::FromBufferWithLookupTable } else { CommitStrategy::FromBuffer }; - if let Err(err) = self.persistor.set_commit_strategy( - commit_task.commit_id, - &commit_task.committed_account.pubkey, - commit_strategy, - ) { - error!( - "Failed to persist commit strategy {}: {}", - commit_strategy.as_str(), - err - ); + match &task.task_type { + BufferTaskType::Commit(task) => { + if let Err(err) = self.persistor.set_commit_strategy( + task.commit_id, + &task.committed_account.pubkey, + commit_strategy, + ) { + error!( + "Failed to persist commit strategy {}: {}", + commit_strategy.as_str(), + err + ); + } + } + BufferTaskType::CommitDiff(task) => { + if let Err(err) = self.persistor.set_commit_strategy( + task.commit_id, + &task.committed_account.pubkey, + commit_strategy, + ) { + error!( + "Failed to persist commit strategy {}: {}", + commit_strategy.as_str(), + err + ); + } + } } } } diff --git a/magicblock-committor-service/src/tasks/task_visitors/utility_visitor.rs b/magicblock-committor-service/src/tasks/task_visitors/utility_visitor.rs index fef7cade1..470e25341 100644 --- a/magicblock-committor-service/src/tasks/task_visitors/utility_visitor.rs +++ b/magicblock-committor-service/src/tasks/task_visitors/utility_visitor.rs @@ -19,23 +19,39 @@ impl Visitor for TaskVisitorUtils { fn visit_args_task(&mut self, task: &ArgsTask) { let Self::GetCommitMeta(commit_meta) = self; - if let ArgsTaskType::Commit(ref commit_task) = task.task_type { - *commit_meta = Some(CommitMeta { - committed_pubkey: commit_task.committed_account.pubkey, - commit_id: commit_task.commit_id, - }) - } else { - *commit_meta = None + match &task.task_type { + ArgsTaskType::Commit(task) => { + *commit_meta = Some(CommitMeta { + committed_pubkey: task.committed_account.pubkey, + commit_id: task.commit_id, + }) + } + ArgsTaskType::CommitDiff(task) => { + *commit_meta = Some(CommitMeta { + committed_pubkey: task.committed_account.pubkey, + commit_id: task.commit_id, + }) + } + _ => *commit_meta = None, } } fn visit_buffer_task(&mut self, task: &BufferTask) { let Self::GetCommitMeta(commit_meta) = self; - let BufferTaskType::Commit(ref commit_task) = task.task_type; - *commit_meta = Some(CommitMeta { - committed_pubkey: commit_task.committed_account.pubkey, - commit_id: commit_task.commit_id, - }) + match &task.task_type { + BufferTaskType::Commit(task) => { + *commit_meta = Some(CommitMeta { + committed_pubkey: task.committed_account.pubkey, + commit_id: task.commit_id, + }) + } + BufferTaskType::CommitDiff(task) => { + *commit_meta = Some(CommitMeta { + committed_pubkey: task.committed_account.pubkey, + commit_id: task.commit_id, + }) + } + } } } diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 06999a97d..41c98d722 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -58,7 +58,7 @@ magicblock-core = { path = "../magicblock-core" } magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } magicblock_magic_program_api = { package = "magicblock-magic-program-api", path = "../magicblock-magic-program-api" } magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "3edb41022" , features = [ - "no-entrypoint", + "no-entrypoint", ] } magicblock-program = { path = "../programs/magicblock" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } diff --git a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs index f2d9c7ba0..e0a6e6126 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs @@ -309,13 +309,13 @@ fn test_committing_and_undelegating_huge_order_book_account() { println!("Important: use {rng_seed} as seed to regenerate the random inputs in case of test failure"); let mut random = StdRng::seed_from_u64(rng_seed); let mut update = BookUpdate::default(); - update.bids.extend((0..random.gen_range(5..10)).map(|_| { + update.bids.extend((0..random.gen_range(5..100)).map(|_| { OrderLevel { price: random.gen_range(75000..90000), size: random.gen_range(1..10), } })); - update.asks.extend((0..random.gen_range(5..10)).map(|_| { + update.asks.extend((0..random.gen_range(5..100)).map(|_| { OrderLevel { price: random.gen_range(125000..150000), size: random.gen_range(1..10), diff --git a/test-integration/test-committor-service/tests/test_ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs index 6af953d47..2165b9151 100644 --- a/test-integration/test-committor-service/tests/test_ix_commit_local.rs +++ b/test-integration/test-committor-service/tests/test_ix_commit_local.rs @@ -337,11 +337,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_3() { async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() { commit_5_accounts_1kb( 3, - expect_strategies(&[ - // Intent fits in 1 TX only with ALT, see IntentExecutorImpl::try_unite_tasks - (CommitStrategy::FromBufferWithLookupTable, 3), - (CommitStrategy::Args, 2), - ]), + expect_strategies(&[(CommitStrategy::Args, 5)]), true, ) .await; From de67f4d79083cd75b6b0387504bd903f8cb4497c Mon Sep 17 00:00:00 2001 From: Sarfaraz Nawaz Date: Wed, 24 Dec 2025 22:54:47 +0530 Subject: [PATCH 2/6] Fix the formatting --- test-integration/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 41c98d722..06999a97d 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -58,7 +58,7 @@ magicblock-core = { path = "../magicblock-core" } magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } magicblock_magic_program_api = { package = "magicblock-magic-program-api", path = "../magicblock-magic-program-api" } magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "3edb41022" , features = [ - "no-entrypoint", + "no-entrypoint", ] } magicblock-program = { path = "../programs/magicblock" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } From ebd87ba120e7e945969df2efa4b0ef41e6b3884a Mon Sep 17 00:00:00 2001 From: Sarfaraz Nawaz Date: Wed, 5 Nov 2025 19:50:23 +0530 Subject: [PATCH 3/6] refactor: Rename optimize() -> minimize_tx_size() --- magicblock-committor-service/src/tasks/args_task.rs | 2 +- magicblock-committor-service/src/tasks/buffer_task.rs | 2 +- magicblock-committor-service/src/tasks/mod.rs | 5 +++-- .../src/tasks/task_strategist.rs | 9 +++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/magicblock-committor-service/src/tasks/args_task.rs b/magicblock-committor-service/src/tasks/args_task.rs index 3a3f643be..502a2031b 100644 --- a/magicblock-committor-service/src/tasks/args_task.rs +++ b/magicblock-committor-service/src/tasks/args_task.rs @@ -122,7 +122,7 @@ impl BaseTask for ArgsTask { } } - fn optimize( + fn minimize_tx_size( self: Box, ) -> Result, Box> { match self.task_type { diff --git a/magicblock-committor-service/src/tasks/buffer_task.rs b/magicblock-committor-service/src/tasks/buffer_task.rs index 324accedb..b3d8f4e38 100644 --- a/magicblock-committor-service/src/tasks/buffer_task.rs +++ b/magicblock-committor-service/src/tasks/buffer_task.rs @@ -146,7 +146,7 @@ impl BaseTask for BufferTask { } /// No further optimizations - fn optimize( + fn minimize_tx_size( self: Box, ) -> Result, Box> { Err(self) diff --git a/magicblock-committor-service/src/tasks/mod.rs b/magicblock-committor-service/src/tasks/mod.rs index 1719b84ae..5eab63ff7 100644 --- a/magicblock-committor-service/src/tasks/mod.rs +++ b/magicblock-committor-service/src/tasks/mod.rs @@ -66,8 +66,9 @@ pub trait BaseTask: Send + Sync + DynClone + LabelValue { /// Gets instruction for task execution fn instruction(&self, validator: &Pubkey) -> Instruction; - /// Optimizes Task strategy if possible, otherwise returns itself - fn optimize( + /// Optimize for transaction size so that more instructions can be buddled together in a single + /// transaction. Return Ok(new_tx_optimized_task), else Err(self) if task cannot be optimized. + fn minimize_tx_size( self: Box, ) -> Result, Box>; diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index edbbd74d3..271520072 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -171,7 +171,8 @@ impl TaskStrategist { persistor: &Option

, ) -> TaskStrategistResult { // Attempt optimizing tasks themselves(using buffers) - if Self::optimize_strategy(&mut tasks)? <= MAX_ENCODED_TRANSACTION_SIZE + if Self::minimize_tx_size_if_needed(&mut tasks)? + <= MAX_ENCODED_TRANSACTION_SIZE { // Persist tasks strategy if let Some(persistor) = persistor { @@ -270,7 +271,7 @@ impl TaskStrategist { /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] /// Returns size of tx after optimizations - fn optimize_strategy( + fn minimize_tx_size_if_needed( tasks: &mut [Box], ) -> Result { // Get initial transaction size @@ -325,7 +326,7 @@ impl TaskStrategist { let tmp_task = Box::new(tmp_task) as Box; std::mem::replace(&mut tasks[index], tmp_task) }; - match task.optimize() { + match task.minimize_tx_size() { // If we can decrease: // 1. Calculate new tx size & ix size // 2. Insert item's data back in the heap @@ -704,7 +705,7 @@ mod tests { Box::new(create_test_commit_task(3, 1000, 0)) as Box, // Larger task ]; - let _ = TaskStrategist::optimize_strategy(&mut tasks); + let _ = TaskStrategist::minimize_tx_size_if_needed(&mut tasks); // The larger task should have been optimized first assert!(matches!(tasks[0].strategy(), TaskStrategy::Args)); assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer)); From 694948ae3096689437b7268d157e8fc4aa4dfd9f Mon Sep 17 00:00:00 2001 From: Sarfaraz Nawaz Date: Thu, 6 Nov 2025 23:09:55 +0530 Subject: [PATCH 4/6] Address @taco-paco's feedback --- .../src/tasks/args_task.rs | 2 +- .../src/tasks/buffer_task.rs | 2 +- magicblock-committor-service/src/tasks/mod.rs | 2 +- .../src/tasks/task_strategist.rs | 14 ++++++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/magicblock-committor-service/src/tasks/args_task.rs b/magicblock-committor-service/src/tasks/args_task.rs index 502a2031b..1aec8326e 100644 --- a/magicblock-committor-service/src/tasks/args_task.rs +++ b/magicblock-committor-service/src/tasks/args_task.rs @@ -122,7 +122,7 @@ impl BaseTask for ArgsTask { } } - fn minimize_tx_size( + fn try_optimize_tx_size( self: Box, ) -> Result, Box> { match self.task_type { diff --git a/magicblock-committor-service/src/tasks/buffer_task.rs b/magicblock-committor-service/src/tasks/buffer_task.rs index b3d8f4e38..19c59b7ac 100644 --- a/magicblock-committor-service/src/tasks/buffer_task.rs +++ b/magicblock-committor-service/src/tasks/buffer_task.rs @@ -146,7 +146,7 @@ impl BaseTask for BufferTask { } /// No further optimizations - fn minimize_tx_size( + fn try_optimize_tx_size( self: Box, ) -> Result, Box> { Err(self) diff --git a/magicblock-committor-service/src/tasks/mod.rs b/magicblock-committor-service/src/tasks/mod.rs index 5eab63ff7..d8b4a178e 100644 --- a/magicblock-committor-service/src/tasks/mod.rs +++ b/magicblock-committor-service/src/tasks/mod.rs @@ -68,7 +68,7 @@ pub trait BaseTask: Send + Sync + DynClone + LabelValue { /// Optimize for transaction size so that more instructions can be buddled together in a single /// transaction. Return Ok(new_tx_optimized_task), else Err(self) if task cannot be optimized. - fn minimize_tx_size( + fn try_optimize_tx_size( self: Box, ) -> Result, Box>; diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 271520072..33bbd29e4 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -171,7 +171,7 @@ impl TaskStrategist { persistor: &Option

, ) -> TaskStrategistResult { // Attempt optimizing tasks themselves(using buffers) - if Self::minimize_tx_size_if_needed(&mut tasks)? + if Self::try_optimize_tx_size_if_needed(&mut tasks)? <= MAX_ENCODED_TRANSACTION_SIZE { // Persist tasks strategy @@ -269,9 +269,11 @@ impl TaskStrategist { ) } - /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] - /// Returns size of tx after optimizations - fn minimize_tx_size_if_needed( + /// Optimizes tasks so as to bring the transaction size within the limit [`MAX_ENCODED_TRANSACTION_SIZE`] + /// Returns Ok(size of tx after optimizations) else Err(SignerError). + /// Note that the returned size, though possibly optimized one, may still not be under + /// the limit MAX_ENCODED_TRANSACTION_SIZE. The caller needs to check and make decision accordingly. + fn try_optimize_tx_size_if_needed( tasks: &mut [Box], ) -> Result { // Get initial transaction size @@ -326,7 +328,7 @@ impl TaskStrategist { let tmp_task = Box::new(tmp_task) as Box; std::mem::replace(&mut tasks[index], tmp_task) }; - match task.minimize_tx_size() { + match task.try_optimize_tx_size() { // If we can decrease: // 1. Calculate new tx size & ix size // 2. Insert item's data back in the heap @@ -705,7 +707,7 @@ mod tests { Box::new(create_test_commit_task(3, 1000, 0)) as Box, // Larger task ]; - let _ = TaskStrategist::minimize_tx_size_if_needed(&mut tasks); + let _ = TaskStrategist::try_optimize_tx_size_if_needed(&mut tasks); // The larger task should have been optimized first assert!(matches!(tasks[0].strategy(), TaskStrategy::Args)); assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer)); From b87ac5692bd7586f439a5f20d6a8ea1240631652 Mon Sep 17 00:00:00 2001 From: Sarfaraz Nawaz Date: Wed, 5 Nov 2025 11:30:12 +0530 Subject: [PATCH 5/6] feat: Make TaskStrategy more granular --- .../src/persist/commit_persister.rs | 4 +- .../src/persist/db.rs | 4 +- .../src/persist/types/commit_strategy.rs | 36 +++++---- .../tasks/task_visitors/persistor_visitor.rs | 8 +- .../tests/test_ix_commit_local.rs | 74 +++++++++++-------- 5 files changed, 70 insertions(+), 56 deletions(-) diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 4fe800347..c522d8029 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -585,14 +585,14 @@ mod tests { persister.set_commit_id(1, &pubkey, 100).unwrap(); persister - .set_commit_strategy(100, &pubkey, CommitStrategy::Args) + .set_commit_strategy(100, &pubkey, CommitStrategy::StateArgs) .unwrap(); let updated = persister .get_commit_status_by_message(1, &pubkey) .unwrap() .unwrap(); - assert_eq!(updated.commit_strategy, CommitStrategy::Args); + assert_eq!(updated.commit_strategy, CommitStrategy::StateArgs); } #[test] diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 3d0f60fa1..d8eee2b5a 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -772,7 +772,7 @@ mod tests { commit_type: CommitType::DataAccount, created_at: 1000, commit_status: CommitStatus::Pending, - commit_strategy: CommitStrategy::Args, + commit_strategy: CommitStrategy::StateArgs, last_retried_at: 1000, retries_count: 0, } @@ -907,7 +907,7 @@ mod tests { db.insert_commit_status_rows(std::slice::from_ref(&row)) .unwrap(); - let new_strategy = CommitStrategy::FromBuffer; + let new_strategy = CommitStrategy::StateBuffer; db.set_commit_strategy(100, &row.pubkey, new_strategy) .unwrap(); diff --git a/magicblock-committor-service/src/persist/types/commit_strategy.rs b/magicblock-committor-service/src/persist/types/commit_strategy.rs index c9261f70d..f4080d3f1 100644 --- a/magicblock-committor-service/src/persist/types/commit_strategy.rs +++ b/magicblock-committor-service/src/persist/types/commit_strategy.rs @@ -4,39 +4,39 @@ use crate::persist::error::CommitPersistError; pub enum CommitStrategy { /// Args without the use of a lookup table #[default] - Args, + StateArgs, /// Args with the use of a lookup table - ArgsWithLookupTable, + StateArgsWithLookupTable, /// Buffer and chunks which has the most overhead - FromBuffer, + StateBuffer, /// Buffer and chunks with the use of a lookup table - FromBufferWithLookupTable, + StateBufferWithLookupTable, } impl CommitStrategy { pub fn args(use_lookup: bool) -> Self { if use_lookup { - Self::ArgsWithLookupTable + Self::StateArgsWithLookupTable } else { - Self::Args + Self::StateArgs } } pub fn as_str(&self) -> &str { use CommitStrategy::*; match self { - Args => "Args", - ArgsWithLookupTable => "ArgsWithLookupTable", - FromBuffer => "FromBuffer", - FromBufferWithLookupTable => "FromBufferWithLookupTable", + StateArgs => "StateArgs", + StateArgsWithLookupTable => "StateArgsWithLookupTable", + StateBuffer => "StateBuffer", + StateBufferWithLookupTable => "StateBufferWithLookupTable", } } pub fn uses_lookup(&self) -> bool { matches!( self, - CommitStrategy::ArgsWithLookupTable - | CommitStrategy::FromBufferWithLookupTable + CommitStrategy::StateArgsWithLookupTable + | CommitStrategy::StateBufferWithLookupTable ) } } @@ -45,10 +45,14 @@ impl TryFrom<&str> for CommitStrategy { type Error = CommitPersistError; fn try_from(value: &str) -> Result { match value { - "Args" => Ok(Self::Args), - "ArgsWithLookupTable" => Ok(Self::ArgsWithLookupTable), - "FromBuffer" => Ok(Self::FromBuffer), - "FromBufferWithLookupTable" => Ok(Self::FromBufferWithLookupTable), + "Args" | "StateArgs" => Ok(Self::StateArgs), + "ArgsWithLookupTable" | "StateArgsWithLookupTable" => { + Ok(Self::StateArgsWithLookupTable) + } + "FromBuffer" | "StateBuffer" => Ok(Self::StateBuffer), + "FromBufferWithLookupTable" | "StateBufferWithLookupTable" => { + Ok(Self::StateBufferWithLookupTable) + } _ => Err(CommitPersistError::InvalidCommitStrategy( value.to_string(), )), diff --git a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs index 347f67959..1ed7e1afb 100644 --- a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs +++ b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs @@ -27,9 +27,9 @@ where match self.context { PersistorContext::PersistStrategy { uses_lookup_tables } => { let commit_strategy = if uses_lookup_tables { - CommitStrategy::ArgsWithLookupTable + CommitStrategy::StateArgsWithLookupTable } else { - CommitStrategy::Args + CommitStrategy::StateArgs }; match &task.task_type { @@ -69,9 +69,9 @@ where match self.context { PersistorContext::PersistStrategy { uses_lookup_tables } => { let commit_strategy = if uses_lookup_tables { - CommitStrategy::FromBufferWithLookupTable + CommitStrategy::StateBufferWithLookupTable } else { - CommitStrategy::FromBuffer + CommitStrategy::StateBuffer }; match &task.task_type { diff --git a/test-integration/test-committor-service/tests/test_ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs index 2165b9151..5df101600 100644 --- a/test-integration/test-committor-service/tests/test_ix_commit_local.rs +++ b/test-integration/test-committor-service/tests/test_ix_commit_local.rs @@ -67,42 +67,42 @@ fn expect_strategies( #[tokio::test] async fn test_ix_commit_single_account_100_bytes() { - commit_single_account(100, CommitStrategy::Args, false).await; + commit_single_account(100, CommitStrategy::StateArgs, false).await; } #[tokio::test] async fn test_ix_commit_single_account_100_bytes_and_undelegate() { - commit_single_account(100, CommitStrategy::Args, true).await; + commit_single_account(100, CommitStrategy::StateArgs, true).await; } #[tokio::test] async fn test_ix_commit_single_account_800_bytes() { - commit_single_account(800, CommitStrategy::Args, false).await; + commit_single_account(800, CommitStrategy::StateBuffer, false).await; } #[tokio::test] async fn test_ix_commit_single_account_800_bytes_and_undelegate() { - commit_single_account(800, CommitStrategy::Args, true).await; + commit_single_account(800, CommitStrategy::StateBuffer, true).await; } #[tokio::test] async fn test_ix_commit_single_account_one_kb() { - commit_single_account(1024, CommitStrategy::Args, false).await; + commit_single_account(1024, CommitStrategy::StateBuffer, false).await; } #[tokio::test] async fn test_ix_commit_single_account_ten_kb() { - commit_single_account(10 * 1024, CommitStrategy::Args, false).await; + commit_single_account(10 * 1024, CommitStrategy::StateBuffer, false).await; } #[tokio::test] async fn test_ix_commit_order_book_change_100_bytes() { - commit_book_order_account(100, CommitStrategy::Args, false).await; + commit_book_order_account(100, CommitStrategy::StateArgs, false).await; } #[tokio::test] async fn test_ix_commit_order_book_change_679_bytes() { - commit_book_order_account(679, CommitStrategy::Args, false).await; + commit_book_order_account(679, CommitStrategy::StateArgs, false).await; } #[tokio::test] @@ -111,12 +111,12 @@ async fn test_ix_commit_order_book_change_680_bytes() { // of size 1644 (which is the max limit), but while the size of raw bytes for 679 is within // 1232 limit, the size for 680 execeds by 1 (1233). That is why we used // 681 as changed_len where CommitStrategy goes from Args to FromBuffer. - commit_book_order_account(681, CommitStrategy::FromBuffer, false).await; + commit_book_order_account(681, CommitStrategy::StateBuffer, false).await; } #[tokio::test] async fn test_ix_commit_order_book_change_10k_bytes() { - commit_book_order_account(10 * 1024, CommitStrategy::FromBuffer, false) + commit_book_order_account(10 * 1024, CommitStrategy::StateBuffer, false) .await; } @@ -264,7 +264,7 @@ async fn test_ix_commit_two_accounts_1kb_2kb() { &[1024, 2048], 1, false, - expect_strategies(&[(CommitStrategy::Args, 2)]), + expect_strategies(&[(CommitStrategy::StateArgs, 2)]), ) .await; } @@ -276,7 +276,7 @@ async fn test_ix_commit_two_accounts_512kb() { &[512, 512], 1, false, - expect_strategies(&[(CommitStrategy::Args, 2)]), + expect_strategies(&[(CommitStrategy::StateArgs, 2)]), ) .await; } @@ -288,7 +288,7 @@ async fn test_ix_commit_three_accounts_512kb() { &[512, 512, 512], 1, false, - expect_strategies(&[(CommitStrategy::Args, 3)]), + expect_strategies(&[(CommitStrategy::StateArgs, 3)]), ) .await; } @@ -300,7 +300,7 @@ async fn test_ix_commit_six_accounts_512kb() { &[512, 512, 512, 512, 512, 512], 1, false, - expect_strategies(&[(CommitStrategy::Args, 6)]), + expect_strategies(&[(CommitStrategy::StateArgs, 6)]), ) .await; } @@ -312,22 +312,25 @@ async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { &[1024, 2 * 1024, 5 * 1024, 10 * 1024], 1, false, - expect_strategies(&[(CommitStrategy::Args, 4)]), + expect_strategies(&[(CommitStrategy::StateArgs, 4)]), ) .await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_2() { - commit_20_accounts_1kb(2, expect_strategies(&[(CommitStrategy::Args, 20)])) - .await; + commit_20_accounts_1kb( + 2, + expect_strategies(&[(CommitStrategy::StateArgs, 20)]), + ) + .await; } #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_3() { commit_5_accounts_1kb( 3, - expect_strategies(&[(CommitStrategy::Args, 5)]), + expect_strategies(&[(CommitStrategy::StateArgs, 5)]), false, ) .await; @@ -337,7 +340,11 @@ async fn test_commit_5_accounts_1kb_bundle_size_3() { async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() { commit_5_accounts_1kb( 3, - expect_strategies(&[(CommitStrategy::Args, 5)]), + expect_strategies(&[ + // Intent fits in 1 TX only with ALT, see IntentExecutorImpl::try_unite_tasks + (CommitStrategy::StateBufferWithLookupTable, 3), + (CommitStrategy::StateArgs, 2), + ]), true, ) .await; @@ -348,8 +355,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4() { commit_5_accounts_1kb( 4, expect_strategies(&[ - (CommitStrategy::Args, 1), - (CommitStrategy::FromBufferWithLookupTable, 4), + (CommitStrategy::StateArgs, 1), + (CommitStrategy::StateBufferWithLookupTable, 4), ]), false, ) @@ -361,8 +368,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { commit_5_accounts_1kb( 4, expect_strategies(&[ - (CommitStrategy::Args, 1), - (CommitStrategy::FromBufferWithLookupTable, 4), + (CommitStrategy::StateArgs, 1), + (CommitStrategy::StateBufferWithLookupTable, 4), ]), true, ) @@ -373,7 +380,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() { commit_5_accounts_1kb( 5, - expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 5)]), + expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 5)]), true, ) .await; @@ -381,15 +388,18 @@ async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() { #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_3() { - commit_20_accounts_1kb(3, expect_strategies(&[(CommitStrategy::Args, 20)])) - .await; + commit_20_accounts_1kb( + 3, + expect_strategies(&[(CommitStrategy::StateArgs, 20)]), + ) + .await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_4() { commit_20_accounts_1kb( 4, - expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]), + expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]), ) .await; } @@ -399,9 +409,9 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() { commit_20_accounts_1kb( 6, expect_strategies(&[ - (CommitStrategy::FromBufferWithLookupTable, 18), + (CommitStrategy::StateBufferWithLookupTable, 18), // Two accounts don't make it into the bundles of size 6 - (CommitStrategy::Args, 2), + (CommitStrategy::StateArgs, 2), ]), ) .await; @@ -411,7 +421,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() { async fn test_commit_20_accounts_1kb_bundle_size_20() { commit_20_accounts_1kb( 20, - expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]), + expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]), ) .await; } @@ -423,7 +433,7 @@ async fn test_commit_8_accounts_1kb_bundle_size_8() { expect_strategies(&[ // Four accounts don't make it into the bundles of size 8, but // that bundle also needs lookup tables - (CommitStrategy::FromBufferWithLookupTable, 8), + (CommitStrategy::StateBufferWithLookupTable, 8), ]), ) .await; @@ -436,7 +446,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_8() { expect_strategies(&[ // Four accounts don't make it into the bundles of size 8, but // that bundle also needs lookup tables - (CommitStrategy::FromBufferWithLookupTable, 20), + (CommitStrategy::StateBufferWithLookupTable, 20), ]), ) .await; From 543381eb379ef112cff6e2c719233c0eec7b5385 Mon Sep 17 00:00:00 2001 From: Sarfaraz Nawaz Date: Sat, 27 Dec 2025 00:41:35 +0530 Subject: [PATCH 6/6] Add more members to CommitStrategy --- .../src/persist/types/commit_strategy.rs | 27 ++-- .../tasks/task_visitors/persistor_visitor.rs | 136 ++++++++++-------- .../tests/test_ix_commit_local.rs | 77 ++++++---- 3 files changed, 140 insertions(+), 100 deletions(-) diff --git a/magicblock-committor-service/src/persist/types/commit_strategy.rs b/magicblock-committor-service/src/persist/types/commit_strategy.rs index f4080d3f1..3bf007333 100644 --- a/magicblock-committor-service/src/persist/types/commit_strategy.rs +++ b/magicblock-committor-service/src/persist/types/commit_strategy.rs @@ -11,17 +11,18 @@ pub enum CommitStrategy { StateBuffer, /// Buffer and chunks with the use of a lookup table StateBufferWithLookupTable, + + /// Args without the use of a lookup table + DiffArgs, + /// Args with the use of a lookup table + DiffArgsWithLookupTable, + /// Buffer and chunks which has the most overhead + DiffBuffer, + /// Buffer and chunks with the use of a lookup table + DiffBufferWithLookupTable, } impl CommitStrategy { - pub fn args(use_lookup: bool) -> Self { - if use_lookup { - Self::StateArgsWithLookupTable - } else { - Self::StateArgs - } - } - pub fn as_str(&self) -> &str { use CommitStrategy::*; match self { @@ -29,6 +30,10 @@ impl CommitStrategy { StateArgsWithLookupTable => "StateArgsWithLookupTable", StateBuffer => "StateBuffer", StateBufferWithLookupTable => "StateBufferWithLookupTable", + DiffArgs => "DiffArgs", + DiffArgsWithLookupTable => "DiffArgsWithLookupTable", + DiffBuffer => "DiffBuffer", + DiffBufferWithLookupTable => "DiffBufferWithLookupTable", } } @@ -37,6 +42,8 @@ impl CommitStrategy { self, CommitStrategy::StateArgsWithLookupTable | CommitStrategy::StateBufferWithLookupTable + | CommitStrategy::DiffArgsWithLookupTable + | CommitStrategy::DiffBufferWithLookupTable ) } } @@ -53,6 +60,10 @@ impl TryFrom<&str> for CommitStrategy { "FromBufferWithLookupTable" | "StateBufferWithLookupTable" => { Ok(Self::StateBufferWithLookupTable) } + "DiffArgs" => Ok(Self::DiffArgs), + "DiffArgsWithLookupTable" => Ok(Self::DiffArgsWithLookupTable), + "DiffBuffer" => Ok(Self::DiffBuffer), + "DiffBufferWithLookupTable" => Ok(Self::DiffBufferWithLookupTable), _ => Err(CommitPersistError::InvalidCommitStrategy( value.to_string(), )), diff --git a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs index 1ed7e1afb..2f216c869 100644 --- a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs +++ b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs @@ -26,40 +26,45 @@ where fn visit_args_task(&mut self, task: &ArgsTask) { match self.context { PersistorContext::PersistStrategy { uses_lookup_tables } => { - let commit_strategy = if uses_lookup_tables { - CommitStrategy::StateArgsWithLookupTable - } else { - CommitStrategy::StateArgs - }; - - match &task.task_type { - ArgsTaskType::Commit(task) => { - if let Err(err) = self.persistor.set_commit_strategy( - task.commit_id, - &task.committed_account.pubkey, - commit_strategy, - ) { - error!( - "Failed to persist commit strategy {}: {}", - commit_strategy.as_str(), - err - ); - } - } - ArgsTaskType::CommitDiff(task) => { - if let Err(err) = self.persistor.set_commit_strategy( - task.commit_id, - &task.committed_account.pubkey, - commit_strategy, - ) { - error!( - "Failed to persist commit strategy {}: {}", - commit_strategy.as_str(), - err - ); + let commit_strategy = |is_diff: bool| { + if is_diff { + if uses_lookup_tables { + CommitStrategy::DiffArgsWithLookupTable + } else { + CommitStrategy::DiffArgs } + } else if uses_lookup_tables { + CommitStrategy::StateArgsWithLookupTable + } else { + CommitStrategy::StateArgs } - _ => {} + }; + + let (commit_id, pubkey, commit_strategy) = match &task.task_type + { + ArgsTaskType::Commit(task) => ( + task.commit_id, + &task.committed_account.pubkey, + commit_strategy(false), + ), + ArgsTaskType::CommitDiff(task) => ( + task.commit_id, + &task.committed_account.pubkey, + commit_strategy(true), + ), + _ => return, + }; + + if let Err(err) = self.persistor.set_commit_strategy( + commit_id, + pubkey, + commit_strategy, + ) { + error!( + "Failed to persist commit strategy {}: {}", + commit_strategy.as_str(), + err + ); } } } @@ -68,39 +73,44 @@ where fn visit_buffer_task(&mut self, task: &BufferTask) { match self.context { PersistorContext::PersistStrategy { uses_lookup_tables } => { - let commit_strategy = if uses_lookup_tables { - CommitStrategy::StateBufferWithLookupTable - } else { - CommitStrategy::StateBuffer - }; - - match &task.task_type { - BufferTaskType::Commit(task) => { - if let Err(err) = self.persistor.set_commit_strategy( - task.commit_id, - &task.committed_account.pubkey, - commit_strategy, - ) { - error!( - "Failed to persist commit strategy {}: {}", - commit_strategy.as_str(), - err - ); - } - } - BufferTaskType::CommitDiff(task) => { - if let Err(err) = self.persistor.set_commit_strategy( - task.commit_id, - &task.committed_account.pubkey, - commit_strategy, - ) { - error!( - "Failed to persist commit strategy {}: {}", - commit_strategy.as_str(), - err - ); + let commit_strategy = |is_diff: bool| { + if is_diff { + if uses_lookup_tables { + CommitStrategy::DiffBufferWithLookupTable + } else { + CommitStrategy::DiffBuffer } + } else if uses_lookup_tables { + CommitStrategy::StateBufferWithLookupTable + } else { + CommitStrategy::StateBuffer } + }; + + let (commit_id, pubkey, commit_strategy) = match &task.task_type + { + BufferTaskType::Commit(task) => ( + task.commit_id, + &task.committed_account.pubkey, + commit_strategy(false), + ), + BufferTaskType::CommitDiff(task) => ( + task.commit_id, + &task.committed_account.pubkey, + commit_strategy(true), + ), + }; + + if let Err(err) = self.persistor.set_commit_strategy( + commit_id, + pubkey, + commit_strategy, + ) { + error!( + "Failed to persist commit strategy {}: {}", + commit_strategy.as_str(), + err + ); } } } diff --git a/test-integration/test-committor-service/tests/test_ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs index 5df101600..989ae53a5 100644 --- a/test-integration/test-committor-service/tests/test_ix_commit_local.rs +++ b/test-integration/test-committor-service/tests/test_ix_commit_local.rs @@ -75,34 +75,54 @@ async fn test_ix_commit_single_account_100_bytes_and_undelegate() { commit_single_account(100, CommitStrategy::StateArgs, true).await; } +#[tokio::test] +async fn test_ix_commit_single_account_256_bytes() { + commit_single_account(256, CommitStrategy::StateArgs, false).await; +} + +#[tokio::test] +async fn test_ix_commit_single_account_257_bytes() { + commit_single_account(257, CommitStrategy::DiffArgs, false).await; +} + +#[tokio::test] +async fn test_ix_commit_single_account_256_bytes_and_undelegate() { + commit_single_account(256, CommitStrategy::StateArgs, true).await; +} + +#[tokio::test] +async fn test_ix_commit_single_account_257_bytes_and_undelegate() { + commit_single_account(257, CommitStrategy::DiffArgs, true).await; +} + #[tokio::test] async fn test_ix_commit_single_account_800_bytes() { - commit_single_account(800, CommitStrategy::StateBuffer, false).await; + commit_single_account(800, CommitStrategy::DiffArgs, false).await; } #[tokio::test] async fn test_ix_commit_single_account_800_bytes_and_undelegate() { - commit_single_account(800, CommitStrategy::StateBuffer, true).await; + commit_single_account(800, CommitStrategy::DiffArgs, true).await; } #[tokio::test] async fn test_ix_commit_single_account_one_kb() { - commit_single_account(1024, CommitStrategy::StateBuffer, false).await; + commit_single_account(1024, CommitStrategy::DiffArgs, false).await; } #[tokio::test] async fn test_ix_commit_single_account_ten_kb() { - commit_single_account(10 * 1024, CommitStrategy::StateBuffer, false).await; + commit_single_account(10 * 1024, CommitStrategy::DiffArgs, false).await; } #[tokio::test] async fn test_ix_commit_order_book_change_100_bytes() { - commit_book_order_account(100, CommitStrategy::StateArgs, false).await; + commit_book_order_account(100, CommitStrategy::DiffArgs, false).await; } #[tokio::test] async fn test_ix_commit_order_book_change_679_bytes() { - commit_book_order_account(679, CommitStrategy::StateArgs, false).await; + commit_book_order_account(679, CommitStrategy::DiffArgs, false).await; } #[tokio::test] @@ -111,12 +131,12 @@ async fn test_ix_commit_order_book_change_680_bytes() { // of size 1644 (which is the max limit), but while the size of raw bytes for 679 is within // 1232 limit, the size for 680 execeds by 1 (1233). That is why we used // 681 as changed_len where CommitStrategy goes from Args to FromBuffer. - commit_book_order_account(681, CommitStrategy::StateBuffer, false).await; + commit_book_order_account(681, CommitStrategy::DiffBuffer, false).await; } #[tokio::test] async fn test_ix_commit_order_book_change_10k_bytes() { - commit_book_order_account(10 * 1024, CommitStrategy::StateBuffer, false) + commit_book_order_account(10 * 1024, CommitStrategy::DiffBuffer, false) .await; } @@ -264,7 +284,7 @@ async fn test_ix_commit_two_accounts_1kb_2kb() { &[1024, 2048], 1, false, - expect_strategies(&[(CommitStrategy::StateArgs, 2)]), + expect_strategies(&[(CommitStrategy::DiffArgs, 2)]), ) .await; } @@ -276,7 +296,7 @@ async fn test_ix_commit_two_accounts_512kb() { &[512, 512], 1, false, - expect_strategies(&[(CommitStrategy::StateArgs, 2)]), + expect_strategies(&[(CommitStrategy::DiffArgs, 2)]), ) .await; } @@ -288,7 +308,7 @@ async fn test_ix_commit_three_accounts_512kb() { &[512, 512, 512], 1, false, - expect_strategies(&[(CommitStrategy::StateArgs, 3)]), + expect_strategies(&[(CommitStrategy::DiffArgs, 3)]), ) .await; } @@ -300,7 +320,7 @@ async fn test_ix_commit_six_accounts_512kb() { &[512, 512, 512, 512, 512, 512], 1, false, - expect_strategies(&[(CommitStrategy::StateArgs, 6)]), + expect_strategies(&[(CommitStrategy::DiffArgs, 6)]), ) .await; } @@ -312,7 +332,7 @@ async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { &[1024, 2 * 1024, 5 * 1024, 10 * 1024], 1, false, - expect_strategies(&[(CommitStrategy::StateArgs, 4)]), + expect_strategies(&[(CommitStrategy::DiffArgs, 4)]), ) .await; } @@ -321,7 +341,7 @@ async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { async fn test_commit_20_accounts_1kb_bundle_size_2() { commit_20_accounts_1kb( 2, - expect_strategies(&[(CommitStrategy::StateArgs, 20)]), + expect_strategies(&[(CommitStrategy::DiffArgs, 20)]), ) .await; } @@ -330,7 +350,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_2() { async fn test_commit_5_accounts_1kb_bundle_size_3() { commit_5_accounts_1kb( 3, - expect_strategies(&[(CommitStrategy::StateArgs, 5)]), + expect_strategies(&[(CommitStrategy::DiffArgs, 5)]), false, ) .await; @@ -342,8 +362,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() { 3, expect_strategies(&[ // Intent fits in 1 TX only with ALT, see IntentExecutorImpl::try_unite_tasks - (CommitStrategy::StateBufferWithLookupTable, 3), - (CommitStrategy::StateArgs, 2), + (CommitStrategy::DiffArgs, 5), ]), true, ) @@ -355,8 +374,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4() { commit_5_accounts_1kb( 4, expect_strategies(&[ - (CommitStrategy::StateArgs, 1), - (CommitStrategy::StateBufferWithLookupTable, 4), + (CommitStrategy::DiffArgs, 1), + (CommitStrategy::DiffBufferWithLookupTable, 4), ]), false, ) @@ -368,8 +387,8 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { commit_5_accounts_1kb( 4, expect_strategies(&[ - (CommitStrategy::StateArgs, 1), - (CommitStrategy::StateBufferWithLookupTable, 4), + (CommitStrategy::DiffArgs, 1), + (CommitStrategy::DiffBufferWithLookupTable, 4), ]), true, ) @@ -380,7 +399,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() { commit_5_accounts_1kb( 5, - expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 5)]), + expect_strategies(&[(CommitStrategy::DiffBufferWithLookupTable, 5)]), true, ) .await; @@ -390,7 +409,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() { async fn test_commit_20_accounts_1kb_bundle_size_3() { commit_20_accounts_1kb( 3, - expect_strategies(&[(CommitStrategy::StateArgs, 20)]), + expect_strategies(&[(CommitStrategy::DiffArgs, 20)]), ) .await; } @@ -399,7 +418,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_3() { async fn test_commit_20_accounts_1kb_bundle_size_4() { commit_20_accounts_1kb( 4, - expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]), + expect_strategies(&[(CommitStrategy::DiffBufferWithLookupTable, 20)]), ) .await; } @@ -409,9 +428,9 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() { commit_20_accounts_1kb( 6, expect_strategies(&[ - (CommitStrategy::StateBufferWithLookupTable, 18), + (CommitStrategy::DiffBufferWithLookupTable, 18), // Two accounts don't make it into the bundles of size 6 - (CommitStrategy::StateArgs, 2), + (CommitStrategy::DiffArgs, 2), ]), ) .await; @@ -421,7 +440,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() { async fn test_commit_20_accounts_1kb_bundle_size_20() { commit_20_accounts_1kb( 20, - expect_strategies(&[(CommitStrategy::StateBufferWithLookupTable, 20)]), + expect_strategies(&[(CommitStrategy::DiffBufferWithLookupTable, 20)]), ) .await; } @@ -433,7 +452,7 @@ async fn test_commit_8_accounts_1kb_bundle_size_8() { expect_strategies(&[ // Four accounts don't make it into the bundles of size 8, but // that bundle also needs lookup tables - (CommitStrategy::StateBufferWithLookupTable, 8), + (CommitStrategy::DiffBufferWithLookupTable, 8), ]), ) .await; @@ -446,7 +465,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_8() { expect_strategies(&[ // Four accounts don't make it into the bundles of size 8, but // that bundle also needs lookup tables - (CommitStrategy::StateBufferWithLookupTable, 20), + (CommitStrategy::DiffBufferWithLookupTable, 20), ]), ) .await;