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