Skip to content

Commit 7b4e2bb

Browse files
committed
Address @taco-paco's feedback
1 parent d04daaf commit 7b4e2bb

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl BaseTask for ArgsTask {
8989
}
9090
}
9191

92-
fn minimize_tx_size(
92+
fn try_optimize_tx_size(
9393
self: Box<Self>,
9494
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>> {
9595
match self.task_type {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl BaseTask for BufferTask {
7070
}
7171

7272
/// No further optimizations
73-
fn minimize_tx_size(
73+
fn try_optimize_tx_size(
7474
self: Box<Self>,
7575
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>> {
7676
// Since the buffer in BufferTask doesn't contribute to the size of

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub trait BaseTask: Send + Sync + DynClone + LabelValue {
7777

7878
/// Optimize for transaction size so that more instructions can be buddled together in a single
7979
/// transaction. Return Ok(new_tx_optimized_task), else Err(self) if task cannot be optimized.
80-
fn minimize_tx_size(
80+
fn try_optimize_tx_size(
8181
self: Box<Self>,
8282
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>>;
8383

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl TaskStrategist {
171171
persistor: &Option<P>,
172172
) -> TaskStrategistResult<TransactionStrategy> {
173173
// Attempt optimizing tasks themselves(using buffers)
174-
if Self::minimize_tx_size_if_needed(&mut tasks)?
174+
if Self::try_optimize_tx_size_if_needed(&mut tasks)?
175175
<= MAX_ENCODED_TRANSACTION_SIZE
176176
{
177177
// Persist tasks strategy
@@ -269,9 +269,11 @@ impl TaskStrategist {
269269
)
270270
}
271271

272-
/// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`]
273-
/// Returns size of tx after optimizations
274-
fn minimize_tx_size_if_needed(
272+
/// Optimizes tasks so as to bring the transaction size within the limit [`MAX_ENCODED_TRANSACTION_SIZE`]
273+
/// Returns Ok(size of tx after optimizations) else Err(SignerError).
274+
/// Note that the returned size, though possibly optimized one, may still not be under
275+
/// the limit MAX_ENCODED_TRANSACTION_SIZE. The caller needs to check and make decision accordingly.
276+
fn try_optimize_tx_size_if_needed(
275277
tasks: &mut [Box<dyn BaseTask>],
276278
) -> Result<usize, SignerError> {
277279
// Get initial transaction size
@@ -326,7 +328,7 @@ impl TaskStrategist {
326328
let tmp_task = Box::new(tmp_task) as Box<dyn BaseTask>;
327329
std::mem::replace(&mut tasks[index], tmp_task)
328330
};
329-
match task.minimize_tx_size() {
331+
match task.try_optimize_tx_size() {
330332
// If we can decrease:
331333
// 1. Calculate new tx size & ix size
332334
// 2. Insert item's data back in the heap
@@ -620,7 +622,7 @@ mod tests {
620622
as Box<dyn BaseTask>, // Larger task
621623
];
622624

623-
let _ = TaskStrategist::minimize_tx_size_if_needed(&mut tasks);
625+
let _ = TaskStrategist::try_optimize_tx_size_if_needed(&mut tasks);
624626
// The larger task should have been optimized first
625627
assert!(matches!(tasks[0].strategy(), TaskStrategy::Args));
626628
assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer));

0 commit comments

Comments
 (0)