Skip to content

Commit f19be9a

Browse files
committed
Address @taco-paco's feedback
1 parent 9c5d78b commit f19be9a

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
@@ -84,7 +84,7 @@ impl BaseTask for ArgsTask {
8484
}
8585
}
8686

87-
fn minimize_tx_size(
87+
fn try_optimize_tx_size(
8888
self: Box<Self>,
8989
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>> {
9090
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
@@ -69,7 +69,7 @@ impl BaseTask for BufferTask {
6969
}
7070

7171
/// No further optimizations
72-
fn minimize_tx_size(
72+
fn try_optimize_tx_size(
7373
self: Box<Self>,
7474
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>> {
7575
// 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
@@ -75,7 +75,7 @@ pub trait BaseTask: Send + Sync + DynClone {
7575

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

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl TaskStrategist {
5353
persistor: &Option<P>,
5454
) -> TaskStrategistResult<TransactionStrategy> {
5555
// Attempt optimizing tasks themselves(using buffers)
56-
if Self::minimize_tx_size_if_needed(&mut tasks)?
56+
if Self::try_optimize_tx_size_if_needed(&mut tasks)?
5757
<= MAX_ENCODED_TRANSACTION_SIZE
5858
{
5959
// Persist tasks strategy
@@ -151,9 +151,11 @@ impl TaskStrategist {
151151
)
152152
}
153153

154-
/// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`]
155-
/// Returns size of tx after optimizations
156-
fn minimize_tx_size_if_needed(
154+
/// Optimizes tasks so as to bring the transaction size within the limit [`MAX_ENCODED_TRANSACTION_SIZE`]
155+
/// Returns Ok(size of tx after optimizations) else Err(SignerError).
156+
/// Note that the returned size, though possibly optimized one, may still not be under
157+
/// the limit MAX_ENCODED_TRANSACTION_SIZE. The caller needs to check and make decision accordingly.
158+
fn try_optimize_tx_size_if_needed(
157159
tasks: &mut [Box<dyn BaseTask>],
158160
) -> Result<usize, SignerError> {
159161
// Get initial transaction size
@@ -208,7 +210,7 @@ impl TaskStrategist {
208210
let tmp_task = Box::new(tmp_task) as Box<dyn BaseTask>;
209211
std::mem::replace(&mut tasks[index], tmp_task)
210212
};
211-
match task.minimize_tx_size() {
213+
match task.try_optimize_tx_size() {
212214
// If we can decrease:
213215
// 1. Calculate new tx size & ix size
214216
// 2. Insert item's data back in the heap
@@ -457,7 +459,7 @@ mod tests {
457459
Box::new(create_test_commit_task(3, 1000)) as Box<dyn BaseTask>, // Larger task
458460
];
459461

460-
let _ = TaskStrategist::minimize_tx_size_if_needed(&mut tasks);
462+
let _ = TaskStrategist::try_optimize_tx_size_if_needed(&mut tasks);
461463
// The larger task should have been optimized first
462464
assert!(matches!(tasks[0].strategy(), TaskStrategy::Args));
463465
assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer));

0 commit comments

Comments
 (0)