@@ -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