Skip to content

Commit c44bdbb

Browse files
committed
feat: use SetLoadedAccountsDataSizeLimit for tx containing DLP ix
1 parent e9f100a commit c44bdbb

9 files changed

Lines changed: 111 additions & 25 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ magicblock-committor-program = { path = "./magicblock-committor-program", featur
9898
magicblock-committor-service = { path = "./magicblock-committor-service" }
9999
magicblock-config = { path = "./magicblock-config" }
100100
magicblock-core = { path = "./magicblock-core" }
101-
magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "3edb41022", features = [
101+
magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "2e52f858d86ec7420d187368cb1fd1edfccb9e2b", features = [
102+
# magicblock-delegation-program = { path = "../delegation-program", features = [
102103
"no-entrypoint",
103104
] }
104105
magicblock-ledger = { path = "./magicblock-ledger" }

magicblock-committor-service/src/tasks/args_task.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
use dlp::{
22
args::{CallHandlerArgs, CommitDiffArgs, CommitStateArgs},
33
compute_diff,
4+
instruction_builder::{
5+
commit_diff_from_buffer_size_budget, commit_diff_size_budget,
6+
commit_size_budget, finalize_size_budget, undelegate_size_budget,
7+
},
8+
AccountSizeClass,
49
};
510
use magicblock_metrics::metrics::LabelValue;
11+
use rand::seq::IndexedRandom;
612
use solana_account::ReadableAccount;
713
use solana_instruction::{AccountMeta, Instruction};
814
use solana_pubkey::Pubkey;
@@ -177,6 +183,28 @@ impl BaseTask for ArgsTask {
177183
}
178184
}
179185

186+
fn accounts_size_budget(&self) -> u32 {
187+
match &self.task_type {
188+
ArgsTaskType::Commit(task) => {
189+
commit_size_budget(AccountSizeClass::Dynamic(
190+
task.committed_account.account.data.len() as u32,
191+
))
192+
}
193+
ArgsTaskType::CommitDiff(task) => {
194+
commit_diff_size_budget(AccountSizeClass::Dynamic(
195+
task.committed_account.account.data.len() as u32,
196+
))
197+
}
198+
ArgsTaskType::BaseAction(_) => 0,
199+
ArgsTaskType::Undelegate(_) => {
200+
undelegate_size_budget(AccountSizeClass::Huge)
201+
}
202+
ArgsTaskType::Finalize(_) => {
203+
finalize_size_budget(AccountSizeClass::Huge)
204+
}
205+
}
206+
}
207+
180208
#[cfg(test)]
181209
fn strategy(&self) -> TaskStrategy {
182210
TaskStrategy::Args

magicblock-committor-service/src/tasks/buffer_task.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use dlp::args::CommitStateFromBufferArgs;
1+
use dlp::{
2+
args::CommitStateFromBufferArgs, instruction_builder::commit_size_budget,
3+
AccountSizeClass,
4+
};
25
use magicblock_committor_program::Chunks;
36
use magicblock_metrics::metrics::LabelValue;
47
use solana_instruction::Instruction;
@@ -128,6 +131,14 @@ impl BaseTask for BufferTask {
128131
}
129132
}
130133

134+
fn accounts_size_budget(&self) -> u32 {
135+
match self.task_type {
136+
BufferTaskType::Commit(_) => {
137+
commit_size_budget(AccountSizeClass::Huge)
138+
}
139+
}
140+
}
141+
131142
#[cfg(test)]
132143
fn strategy(&self) -> TaskStrategy {
133144
TaskStrategy::Buffer

magicblock-committor-service/src/tasks/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ pub trait BaseTask: Send + Sync + DynClone + LabelValue {
8585
/// Returns [`Task`] budget
8686
fn compute_units(&self) -> u32;
8787

88+
/// Returns the max accounts-data-size that can be used with SetLoadedAccountsDataSizeLimit
89+
fn accounts_size_budget(&self) -> u32;
90+
8891
/// Returns current [`TaskStrategy`]
8992
#[cfg(test)]
9093
fn strategy(&self) -> TaskStrategy;

magicblock-committor-service/src/tasks/task_strategist.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,12 @@ impl TaskStrategist {
224224
let placeholder = Keypair::new();
225225
// Gather all involved keys in tx
226226
let budgets = TransactionUtils::tasks_compute_units(tasks);
227-
let budget_instructions =
228-
TransactionUtils::budget_instructions(budgets, u64::default());
227+
let size_budgets = TransactionUtils::tasks_accounts_size_budget(tasks);
228+
let budget_instructions = TransactionUtils::budget_instructions(
229+
budgets,
230+
u64::default(),
231+
size_budgets,
232+
);
229233
let unique_involved_pubkeys = TransactionUtils::unique_involved_pubkeys(
230234
tasks,
231235
&placeholder.pubkey(),
@@ -258,8 +262,12 @@ impl TaskStrategist {
258262
tasks: &[Box<dyn BaseTask>],
259263
) -> Vec<Pubkey> {
260264
let budgets = TransactionUtils::tasks_compute_units(tasks);
261-
let budget_instructions =
262-
TransactionUtils::budget_instructions(budgets, u64::default());
265+
let size_budgets = TransactionUtils::tasks_accounts_size_budget(tasks);
266+
let budget_instructions = TransactionUtils::budget_instructions(
267+
budgets,
268+
u64::default(),
269+
size_budgets,
270+
);
263271

264272
TransactionUtils::unique_involved_pubkeys(
265273
tasks,

magicblock-committor-service/src/tasks/utils.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl TransactionUtils {
6666
let budget_instructions = Self::budget_instructions(
6767
Self::tasks_compute_units(tasks),
6868
compute_unit_price,
69+
Self::tasks_accounts_size_budget(tasks),
6970
);
7071
let ixs = Self::tasks_instructions(&authority.pubkey(), tasks);
7172
Self::assemble_tx_raw(
@@ -127,16 +128,28 @@ impl TransactionUtils {
127128
tasks.iter().map(|task| task.as_ref().compute_units()).sum()
128129
}
129130

131+
pub fn tasks_accounts_size_budget(
132+
tasks: &[impl AsRef<dyn BaseTask>],
133+
) -> u32 {
134+
tasks
135+
.iter()
136+
.map(|task| task.as_ref().accounts_size_budget())
137+
.sum()
138+
}
139+
130140
pub fn budget_instructions(
131141
compute_units: u32,
132142
compute_unit_price: u64,
133-
) -> [Instruction; 2] {
134-
let compute_budget_ix =
135-
ComputeBudgetInstruction::set_compute_unit_limit(compute_units);
136-
let compute_unit_price_ix =
143+
accounts_size_budget: u32,
144+
) -> [Instruction; 3] {
145+
[
146+
ComputeBudgetInstruction::set_compute_unit_limit(compute_units),
137147
ComputeBudgetInstruction::set_compute_unit_price(
138148
compute_unit_price,
139-
);
140-
[compute_budget_ix, compute_unit_price_ix]
149+
),
150+
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
151+
accounts_size_budget,
152+
),
153+
]
141154
}
142155
}

test-integration/Cargo.lock

Lines changed: 25 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-integration/test-committor-service/tests/test_ix_commit_local.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ async fn test_ix_commit_order_book_change_100_bytes() {
101101
}
102102

103103
#[tokio::test]
104-
async fn test_ix_commit_order_book_change_679_bytes() {
105-
commit_book_order_account(679, CommitStrategy::Args, false).await;
104+
async fn test_ix_commit_order_book_change_671_bytes() {
105+
commit_book_order_account(671, CommitStrategy::Args, false).await;
106106
}
107107

108108
#[tokio::test]
109-
async fn test_ix_commit_order_book_change_680_bytes() {
110-
// We cannot use 680 as changed_len because that both 679 and 680 produce encoded tx
111-
// of size 1644 (which is the max limit), but while the size of raw bytes for 679 is within
112-
// 1232 limit, the size for 680 execeds by 1 (1233). That is why we used
113-
// 681 as changed_len where CommitStrategy goes from Args to FromBuffer.
114-
commit_book_order_account(681, CommitStrategy::FromBuffer, false).await;
109+
async fn test_ix_commit_order_book_change_673_bytes() {
110+
// We cannot use 672 as changed_len because that both 671 and 672 produce encoded tx
111+
// of size 1644 (which is the max limit), but while the size of raw bytes for 671 is within
112+
// 1232 limit, the size for 672 execeds by 1 (1233). That is why we used
113+
// 673 as changed_len where CommitStrategy goes from Args to FromBuffer.
114+
commit_book_order_account(673, CommitStrategy::FromBuffer, false).await;
115115
}
116116

117117
#[tokio::test]

0 commit comments

Comments
 (0)