@@ -271,6 +271,9 @@ impl Batcher {
271271 Ok ( ( ) )
272272 }
273273
274+ /// Listen for Ethereum new blocks.
275+ /// Retries on recoverable errors using exponential backoff
276+ /// with the maximum number of retries and a `MAX_DELAY` of 1 hour.
274277 pub async fn listen_new_blocks ( self : Arc < Self > ) -> Result < ( ) , BatcherError > {
275278 retry_function (
276279 || {
@@ -280,6 +283,7 @@ impl Batcher {
280283 DEFAULT_MIN_RETRY_DELAY ,
281284 DEFAULT_BACKOFF_FACTOR ,
282285 LISTEN_NEW_BLOCKS_MAX_TIMES ,
286+ DEFAULT_MAX_RETRY_DELAY ,
283287 )
284288 . await
285289 . map_err ( |e| e. inner ( ) )
@@ -916,7 +920,9 @@ impl Batcher {
916920 }
917921 }
918922
919- /// Gets the user nonce from Ethereum using exponential backoff.
923+ /// Gets the user nonce from Ethereum.
924+ /// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
925+ /// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
920926 async fn get_user_nonce_from_ethereum (
921927 & self ,
922928 addr : Address ,
@@ -932,6 +938,7 @@ impl Batcher {
932938 DEFAULT_MIN_RETRY_DELAY ,
933939 DEFAULT_BACKOFF_FACTOR ,
934940 DEFAULT_MAX_RETRIES ,
941+ DEFAULT_MAX_RETRY_DELAY ,
935942 )
936943 . await
937944 }
@@ -1371,6 +1378,10 @@ impl Batcher {
13711378 }
13721379 }
13731380
1381+ /// Sends a `create_new_task` transaction to Ethereum and waits for a maximum of 3 blocks for the receipt.
1382+ /// Retries up to `DEFAULT_MAX_RETRIES` times using exponential backoff on recoverable errors while trying to send the transaction:
1383+ /// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
1384+ /// `ReceiptNotFoundError` is treated as non-recoverable, and the transaction will be canceled using `cancel_create_new_task_tx` in that case.
13741385 async fn create_new_task (
13751386 & self ,
13761387 batch_merkle_root : [ u8 ; 32 ] ,
@@ -1393,6 +1404,7 @@ impl Batcher {
13931404 DEFAULT_MIN_RETRY_DELAY ,
13941405 DEFAULT_BACKOFF_FACTOR ,
13951406 DEFAULT_MAX_RETRIES ,
1407+ DEFAULT_MAX_RETRY_DELAY ,
13961408 )
13971409 . await ;
13981410 match result {
@@ -1416,11 +1428,10 @@ impl Batcher {
14161428 }
14171429
14181430 /// Sends a transaction to Ethereum with the same nonce as the previous one to override it.
1419- /// In case of a recoverable error, it will retry with an exponential backoff up to CANCEL_TRANSACTION_MAX_RETRIES times.
1420- /// A tx not included in 3 blocks will be considered an error, and will trigger a bump of the fee, with the rules on ```calculate_bumped_gas_price```
1421- /// This will do 5 bumps every 3 blocks, and then the exponential backoff will dominate, doing bumps at 8,13,24,45,89 and so on.
1422- /// Errors on ```get_gas_price``` calls inside this function are considered transient,
1423- /// so they won't stop the retries.
1431+ /// Retries on recoverable errors with exponential backoff.
1432+ /// Bumps the fee if not included in 3 blocks, using `calculate_bumped_gas_price`.
1433+ /// In the first 5 attemps, bumps the fee every 3 blocks. Then exponential backoff takes over.
1434+ /// After 2 hours (attempt 13), retries occur hourly for 1 day (33 retries).
14241435 pub async fn cancel_create_new_task_tx ( & self , old_tx_gas_price : U256 ) {
14251436 info ! ( "Cancelling createNewTask transaction..." ) ;
14261437 let iteration = Arc :: new ( Mutex :: new ( 0 ) ) ;
@@ -1458,6 +1469,7 @@ impl Batcher {
14581469 DEFAULT_MIN_RETRY_DELAY ,
14591470 DEFAULT_BACKOFF_FACTOR ,
14601471 CANCEL_TRANSACTION_MAX_RETRIES ,
1472+ DEFAULT_MAX_RETRY_DELAY ,
14611473 )
14621474 . await
14631475 {
@@ -1550,7 +1562,9 @@ impl Batcher {
15501562 Ok ( ( ) )
15511563 }
15521564
1553- /// Gets the balance of user with address `addr` from Ethereum using exponential backoff.
1565+ /// Gets the balance of user with address `addr` from Ethereum.
1566+ /// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
1567+ /// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs)
15541568 /// Returns `None` if the balance couldn't be returned
15551569 /// FIXME: This should return a `Result` instead.
15561570 async fn get_user_balance ( & self , addr : & Address ) -> Option < U256 > {
@@ -1565,12 +1579,15 @@ impl Batcher {
15651579 DEFAULT_MIN_RETRY_DELAY ,
15661580 DEFAULT_BACKOFF_FACTOR ,
15671581 DEFAULT_MAX_RETRIES ,
1582+ DEFAULT_MAX_RETRY_DELAY ,
15681583 )
15691584 . await
15701585 . ok ( )
15711586 }
15721587
1573- /// Checks if the user's balance is unlocked for a given address using exponential backoff.
1588+ /// Checks if the user's balance is unlocked for a given address.
1589+ /// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
1590+ /// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
15741591 /// Returns `false` if an error occurs during the retries.
15751592 async fn user_balance_is_unlocked ( & self , addr : & Address ) -> bool {
15761593 let Ok ( unlocked) = retry_function (
@@ -1584,6 +1601,7 @@ impl Batcher {
15841601 DEFAULT_MIN_RETRY_DELAY ,
15851602 DEFAULT_BACKOFF_FACTOR ,
15861603 DEFAULT_MAX_RETRIES ,
1604+ DEFAULT_MAX_RETRY_DELAY ,
15871605 )
15881606 . await
15891607 else {
@@ -1593,7 +1611,9 @@ impl Batcher {
15931611 unlocked
15941612 }
15951613
1596- /// Uploads the batch to s3 using exponential backoff.
1614+ /// Uploads the batch to s3.
1615+ /// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
1616+ /// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
15971617 async fn upload_batch_to_s3 (
15981618 & self ,
15991619 batch_bytes : & [ u8 ] ,
@@ -1611,6 +1631,7 @@ impl Batcher {
16111631 DEFAULT_MIN_RETRY_DELAY ,
16121632 DEFAULT_BACKOFF_FACTOR ,
16131633 DEFAULT_MAX_RETRIES ,
1634+ DEFAULT_MAX_RETRY_DELAY ,
16141635 )
16151636 . await
16161637 . map_err ( |e| BatcherError :: BatchUploadError ( e. to_string ( ) ) )
0 commit comments