@@ -1428,28 +1428,12 @@ impl Batcher {
14281428 let batch_merkle_root_hex = hex:: encode ( batch_merkle_root) ;
14291429 info ! ( "Batch merkle root: 0x{}" , batch_merkle_root_hex) ;
14301430 let file_name = batch_merkle_root_hex. clone ( ) + ".json" ;
1431-
1432- info ! ( "Uploading batch to S3..." ) ;
1433- self . upload_batch_to_s3 ( batch_bytes, & file_name) . await ?;
1434-
1435- if let Err ( e) = self
1436- . telemetry
1437- . task_uploaded_to_s3 ( & batch_merkle_root_hex)
1438- . await
1439- {
1440- warn ! ( "Failed to send task status to telemetry: {:?}" , e) ;
1441- } ;
1442- info ! ( "Batch sent to S3 with name: {}" , file_name) ;
1443-
1444- info ! ( "Uploading batch to contract" ) ;
14451431 let batch_data_pointer: String = "" . to_owned ( ) + & self . download_endpoint + "/" + & file_name;
14461432
14471433 let num_proofs_in_batch = leaves. len ( ) ;
1448-
14491434 let gas_per_proof = ( CONSTANT_GAS_COST
14501435 + ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * num_proofs_in_batch as u128 )
14511436 / num_proofs_in_batch as u128 ;
1452-
14531437 let fee_per_proof = U256 :: from ( gas_per_proof) * gas_price;
14541438 let fee_for_aggregator = ( U256 :: from ( AGGREGATOR_GAS_COST )
14551439 * gas_price
@@ -1465,12 +1449,31 @@ impl Batcher {
14651449 respond_to_task_fee_limit,
14661450 ) ;
14671451
1468- let proof_submitters = finalized_batch. iter ( ) . map ( |entry| entry. sender ) . collect ( ) ;
1452+ let proof_submitters: Vec < Address > =
1453+ finalized_batch. iter ( ) . map ( |entry| entry. sender ) . collect ( ) ;
1454+
1455+ self . simulate_create_new_task (
1456+ * batch_merkle_root,
1457+ batch_data_pointer. clone ( ) ,
1458+ proof_submitters. clone ( ) ,
1459+ fee_params. clone ( ) ,
1460+ )
1461+ . await ?;
14691462
14701463 self . metrics
14711464 . gas_price_used_on_latest_batch
14721465 . set ( gas_price. as_u64 ( ) as i64 ) ;
14731466
1467+ info ! ( "Uploading batch to S3..." ) ;
1468+ self . upload_batch_to_s3 ( batch_bytes, & file_name) . await ?;
1469+ if let Err ( e) = self
1470+ . telemetry
1471+ . task_uploaded_to_s3 ( & batch_merkle_root_hex)
1472+ . await
1473+ {
1474+ warn ! ( "Failed to send task status to telemetry: {:?}" , e) ;
1475+ } ;
1476+ info ! ( "Batch sent to S3 with name: {}" , file_name) ;
14741477 if let Err ( e) = self
14751478 . telemetry
14761479 . task_created (
@@ -1483,6 +1486,7 @@ impl Batcher {
14831486 warn ! ( "Failed to send task status to telemetry: {:?}" , e) ;
14841487 } ;
14851488
1489+ info ! ( "Submitting batch to contract" ) ;
14861490 match self
14871491 . create_new_task (
14881492 * batch_merkle_root,
@@ -1520,27 +1524,6 @@ impl Batcher {
15201524 proof_submitters : Vec < Address > ,
15211525 fee_params : CreateNewTaskFeeParams ,
15221526 ) -> Result < TransactionReceipt , BatcherError > {
1523- // First, we simulate the tx
1524- retry_function (
1525- || {
1526- simulate_create_new_task_retryable (
1527- batch_merkle_root,
1528- batch_data_pointer. clone ( ) ,
1529- proof_submitters. clone ( ) ,
1530- fee_params. clone ( ) ,
1531- & self . payment_service ,
1532- & self . payment_service_fallback ,
1533- )
1534- } ,
1535- ETHEREUM_CALL_MIN_RETRY_DELAY ,
1536- ETHEREUM_CALL_BACKOFF_FACTOR ,
1537- ETHEREUM_CALL_MAX_RETRIES ,
1538- ETHEREUM_CALL_MAX_RETRY_DELAY ,
1539- )
1540- . await
1541- . map_err ( |e| e. inner ( ) ) ?;
1542-
1543- // Then, we send the real tx
15441527 let result = retry_function (
15451528 || {
15461529 create_new_task_retryable (
@@ -1579,6 +1562,37 @@ impl Batcher {
15791562 }
15801563 }
15811564
1565+ /// Simulates the `create_new_task` transaction by sending an `eth_call` to the RPC node.
1566+ /// This function does not mutate the state but verifies if it will revert under the given conditions.
1567+ async fn simulate_create_new_task (
1568+ & self ,
1569+ batch_merkle_root : [ u8 ; 32 ] ,
1570+ batch_data_pointer : String ,
1571+ proof_submitters : Vec < Address > ,
1572+ fee_params : CreateNewTaskFeeParams ,
1573+ ) -> Result < ( ) , BatcherError > {
1574+ retry_function (
1575+ || {
1576+ simulate_create_new_task_retryable (
1577+ batch_merkle_root,
1578+ batch_data_pointer. clone ( ) ,
1579+ proof_submitters. clone ( ) ,
1580+ fee_params. clone ( ) ,
1581+ & self . payment_service ,
1582+ & self . payment_service_fallback ,
1583+ )
1584+ } ,
1585+ ETHEREUM_CALL_MIN_RETRY_DELAY ,
1586+ ETHEREUM_CALL_BACKOFF_FACTOR ,
1587+ ETHEREUM_CALL_MAX_RETRIES ,
1588+ ETHEREUM_CALL_MAX_RETRY_DELAY ,
1589+ )
1590+ . await
1591+ . map_err ( |e| e. inner ( ) ) ?;
1592+
1593+ Ok ( ( ) )
1594+ }
1595+
15821596 /// Sends a transaction to Ethereum with the same nonce as the previous one to override it.
15831597 /// Retries on recoverable errors with exponential backoff.
15841598 /// Bumps the fee if not included in 6 blocks, using `calculate_bumped_gas_price`.
0 commit comments