Skip to content

Commit 99dc29b

Browse files
committed
Address @taco-paco's feedback
1 parent 6970516 commit 99dc29b

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl BaseTask for ArgsTask {
122122
}
123123
}
124124

125-
fn minimize_tx_size(
125+
fn try_optimize_tx_size(
126126
self: Box<Self>,
127127
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>> {
128128
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
@@ -146,7 +146,7 @@ impl BaseTask for BufferTask {
146146
}
147147

148148
/// No further optimizations
149-
fn minimize_tx_size(
149+
fn try_optimize_tx_size(
150150
self: Box<Self>,
151151
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>> {
152152
Err(self)

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

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

6969
/// Optimize for transaction size so that more instructions can be buddled together in a single
7070
/// transaction. Return Ok(new_tx_optimized_task), else Err(self) if task cannot be optimized.
71-
fn minimize_tx_size(
71+
fn try_optimize_tx_size(
7272
self: Box<Self>,
7373
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>>;
7474

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
@@ -705,7 +707,7 @@ mod tests {
705707
Box::new(create_test_commit_task(3, 1000, 0)) as Box<dyn BaseTask>, // Larger task
706708
];
707709

708-
let _ = TaskStrategist::minimize_tx_size_if_needed(&mut tasks);
710+
let _ = TaskStrategist::try_optimize_tx_size_if_needed(&mut tasks);
709711
// The larger task should have been optimized first
710712
assert!(matches!(tasks[0].strategy(), TaskStrategy::Args));
711713
assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer));

0 commit comments

Comments
 (0)