|
1 | 1 | use std::collections::HashSet; |
2 | 2 |
|
| 3 | +use dlp::DLP_PROGRAM_DATA_SIZE_CLASS; |
3 | 4 | use solana_compute_budget_interface::ComputeBudgetInstruction; |
4 | 5 | use solana_hash::Hash; |
5 | 6 | use solana_instruction::Instruction; |
@@ -66,6 +67,7 @@ impl TransactionUtils { |
66 | 67 | let budget_instructions = Self::budget_instructions( |
67 | 68 | Self::tasks_compute_units(tasks), |
68 | 69 | compute_unit_price, |
| 70 | + Self::tasks_accounts_size_budget(tasks), |
69 | 71 | ); |
70 | 72 | let ixs = Self::tasks_instructions(&authority.pubkey(), tasks); |
71 | 73 | Self::assemble_tx_raw( |
@@ -127,16 +129,38 @@ impl TransactionUtils { |
127 | 129 | tasks.iter().map(|task| task.as_ref().compute_units()).sum() |
128 | 130 | } |
129 | 131 |
|
| 132 | + pub fn tasks_accounts_size_budget( |
| 133 | + tasks: &[impl AsRef<dyn BaseTask>], |
| 134 | + ) -> u32 { |
| 135 | + if tasks.is_empty() { |
| 136 | + return 0; |
| 137 | + } |
| 138 | + |
| 139 | + let total_budget: u32 = tasks |
| 140 | + .iter() |
| 141 | + .map(|task| task.as_ref().accounts_size_budget()) |
| 142 | + .sum(); |
| 143 | + |
| 144 | + // DLP_PROGRAM_DATA_SIZE_CLASS has been added N times, once for each task. |
| 145 | + // We need to add it once only, so minus (N-1) times. |
| 146 | + total_budget |
| 147 | + - (tasks.len() as u32 - 1) |
| 148 | + * DLP_PROGRAM_DATA_SIZE_CLASS.size_budget() |
| 149 | + } |
| 150 | + |
130 | 151 | pub fn budget_instructions( |
131 | 152 | compute_units: u32, |
132 | 153 | 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 = |
| 154 | + accounts_size_budget: u32, |
| 155 | + ) -> [Instruction; 3] { |
| 156 | + [ |
| 157 | + ComputeBudgetInstruction::set_compute_unit_limit(compute_units), |
137 | 158 | ComputeBudgetInstruction::set_compute_unit_price( |
138 | 159 | compute_unit_price, |
139 | | - ); |
140 | | - [compute_budget_ix, compute_unit_price_ix] |
| 160 | + ), |
| 161 | + ComputeBudgetInstruction::set_loaded_accounts_data_size_limit( |
| 162 | + accounts_size_budget, |
| 163 | + ), |
| 164 | + ] |
141 | 165 | } |
142 | 166 | } |
0 commit comments