@@ -154,13 +154,14 @@ pub(crate) fn try_build_batch(
154154 gas_price : U256 ,
155155 max_batch_byte_size : usize ,
156156 max_batch_proof_qty : usize ,
157+ constant_gas_cost : u128 ,
157158) -> Result < Vec < BatchQueueEntry > , BatcherError > {
158159 let mut finalized_batch = batch_queue;
159160 let mut batch_size = calculate_batch_size ( & finalized_batch) ?;
160161
161162 while let Some ( ( entry, _) ) = finalized_batch. peek ( ) {
162163 let batch_len = finalized_batch. len ( ) ;
163- let fee_per_proof = calculate_fee_per_proof ( batch_len, gas_price) ;
164+ let fee_per_proof = calculate_fee_per_proof ( batch_len, gas_price, constant_gas_cost ) ;
164165
165166 // if batch is not acceptable:
166167 if batch_size > max_batch_byte_size
@@ -197,8 +198,8 @@ pub(crate) fn try_build_batch(
197198 Ok ( finalized_batch. clone ( ) . into_sorted_vec ( ) )
198199}
199200
200- fn calculate_fee_per_proof ( batch_len : usize , gas_price : U256 ) -> U256 {
201- let gas_per_proof = ( crate :: CONSTANT_GAS_COST
201+ fn calculate_fee_per_proof ( batch_len : usize , gas_price : U256 , constant_gas_cost : u128 ) -> U256 {
202+ let gas_per_proof = ( constant_gas_cost
202203 + crate :: ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * batch_len as u128 )
203204 / batch_len as u128 ;
204205
@@ -207,6 +208,7 @@ fn calculate_fee_per_proof(batch_len: usize, gas_price: U256) -> U256 {
207208
208209#[ cfg( test) ]
209210mod test {
211+ use aligned_sdk:: core:: constants:: DEFAULT_CONSTANT_GAS_COST ;
210212 use aligned_sdk:: core:: types:: ProvingSystemId ;
211213 use aligned_sdk:: core:: types:: VerificationData ;
212214 use ethers:: types:: Address ;
@@ -303,7 +305,14 @@ mod test {
303305 batch_queue. push ( entry_3, batch_priority_3) ;
304306
305307 let gas_price = U256 :: from ( 1 ) ;
306- let finalized_batch = try_build_batch ( batch_queue, gas_price, 5000000 , 50 ) . unwrap ( ) ;
308+ let finalized_batch = try_build_batch (
309+ batch_queue. clone ( ) ,
310+ gas_price,
311+ 5000000 ,
312+ 50 ,
313+ DEFAULT_CONSTANT_GAS_COST ,
314+ )
315+ . unwrap ( ) ;
307316
308317 assert_eq ! (
309318 finalized_batch[ 0 ] . nonced_verification_data. max_fee,
@@ -408,7 +417,14 @@ mod test {
408417 batch_queue. push ( entry_3, batch_priority_3) ;
409418
410419 let gas_price = U256 :: from ( 1 ) ;
411- let finalized_batch = try_build_batch ( batch_queue. clone ( ) , gas_price, 5000000 , 50 ) . unwrap ( ) ;
420+ let finalized_batch = try_build_batch (
421+ batch_queue. clone ( ) ,
422+ gas_price,
423+ 5000000 ,
424+ 50 ,
425+ DEFAULT_CONSTANT_GAS_COST ,
426+ )
427+ . unwrap ( ) ;
412428
413429 // All entries from the batch queue should be in
414430 // the finalized batch.
@@ -511,7 +527,14 @@ mod test {
511527 batch_queue. push ( entry_3. clone ( ) , batch_priority_3. clone ( ) ) ;
512528
513529 let gas_price = U256 :: from ( 1 ) ;
514- let finalized_batch = try_build_batch ( batch_queue. clone ( ) , gas_price, 5000000 , 2 ) . unwrap ( ) ;
530+ let finalized_batch = try_build_batch (
531+ batch_queue. clone ( ) ,
532+ gas_price,
533+ 5000000 ,
534+ 2 ,
535+ DEFAULT_CONSTANT_GAS_COST ,
536+ )
537+ . unwrap ( ) ;
515538
516539 // One Entry from the batch_queue should not be in the finalized batch
517540 // Particularly, nonce_3 is not in the finalized batch
@@ -614,7 +637,14 @@ mod test {
614637 batch_queue. push ( entry_3, batch_priority_3) ;
615638
616639 let gas_price = U256 :: from ( 1 ) ;
617- let finalized_batch = try_build_batch ( batch_queue. clone ( ) , gas_price, 5000000 , 50 ) . unwrap ( ) ;
640+ let finalized_batch = try_build_batch (
641+ batch_queue. clone ( ) ,
642+ gas_price,
643+ 5000000 ,
644+ 50 ,
645+ DEFAULT_CONSTANT_GAS_COST ,
646+ )
647+ . unwrap ( ) ;
618648
619649 // All entries from the batch queue should be in
620650 // the finalized batch.
@@ -723,7 +753,14 @@ mod test {
723753 batch_queue. push ( entry_3, batch_priority_3) ;
724754
725755 let gas_price = U256 :: from ( 1 ) ;
726- let finalized_batch = try_build_batch ( batch_queue. clone ( ) , gas_price, 5000000 , 50 ) . unwrap ( ) ;
756+ let finalized_batch = try_build_batch (
757+ batch_queue. clone ( ) ,
758+ gas_price,
759+ 5000000 ,
760+ 50 ,
761+ DEFAULT_CONSTANT_GAS_COST ,
762+ )
763+ . unwrap ( ) ;
727764
728765 // All but one entries from the batch queue should be in the finalized batch.
729766 assert_eq ! ( batch_queue. len( ) , 3 ) ;
@@ -832,8 +869,14 @@ mod test {
832869 // The max batch len is 2, so the algorithm should stop at the second entry.
833870 let max_batch_proof_qty = 2 ;
834871
835- let finalized_batch =
836- try_build_batch ( batch_queue. clone ( ) , gas_price, 5000000 , max_batch_proof_qty) . unwrap ( ) ;
872+ let finalized_batch = try_build_batch (
873+ batch_queue. clone ( ) ,
874+ gas_price,
875+ 5000000 ,
876+ max_batch_proof_qty,
877+ DEFAULT_CONSTANT_GAS_COST ,
878+ )
879+ . unwrap ( ) ;
837880
838881 assert_eq ! ( batch_queue. len( ) , 3 ) ;
839882 assert_eq ! ( finalized_batch. len( ) , 2 ) ;
0 commit comments