Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions batcher/aligned-batcher/src/eth/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::{
},
};
use aligned_sdk::core::constants::{
DEFAULT_BACKOFF_FACTOR, DEFAULT_MAX_RETRIES, DEFAULT_MAX_RETRY_DELAY, DEFAULT_MIN_RETRY_DELAY,
GAS_PRICE_INCREMENT_PERCENTAGE_PER_ITERATION, OVERRIDE_GAS_PRICE_PERCENTAGE_MULTIPLIER,
PERCENTAGE_DIVIDER,
ETHEREUM_CALL_BACKOFF_FACTOR, ETHEREUM_CALL_MAX_RETRIES, ETHEREUM_CALL_MAX_RETRY_DELAY,
ETHEREUM_CALL_MIN_RETRY_DELAY, GAS_PRICE_INCREMENT_PERCENTAGE_PER_ITERATION,
OVERRIDE_GAS_PRICE_PERCENTAGE_MULTIPLIER, PERCENTAGE_DIVIDER,
};
use ethers::prelude::*;
use ethers::providers::{Http, Provider};
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn calculate_bumped_gas_price(
}

/// Gets the current nonce from Ethereum.
/// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
/// Retries on recoverable errors using exponential backoff up to `ETHEREUM_CALL_MAX_RETRIES` times:
/// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
pub async fn get_current_nonce(
eth_http_provider: &Provider<Http>,
Expand All @@ -71,10 +71,10 @@ pub async fn get_current_nonce(
) -> Result<U256, ProviderError> {
retry_function(
|| get_current_nonce_retryable(eth_http_provider, eth_http_provider_fallback, addr),
DEFAULT_MIN_RETRY_DELAY,
DEFAULT_BACKOFF_FACTOR,
DEFAULT_MAX_RETRIES,
DEFAULT_MAX_RETRY_DELAY,
ETHEREUM_CALL_MIN_RETRY_DELAY,
ETHEREUM_CALL_BACKOFF_FACTOR,
ETHEREUM_CALL_MAX_RETRIES,
ETHEREUM_CALL_MAX_RETRY_DELAY,
)
.await
.map_err(|e| {
Expand All @@ -84,18 +84,18 @@ pub async fn get_current_nonce(
}

/// Gets the current gas price from Ethereum.
/// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
/// Retries on recoverable errors using exponential backoff up to `ETHEREUM_CALL_MAX_RETRIES` times:
/// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
pub async fn get_gas_price(
eth_http_provider: &Provider<Http>,
eth_http_provider_fallback: &Provider<Http>,
) -> Result<U256, ProviderError> {
retry_function(
|| get_gas_price_retryable(eth_http_provider, eth_http_provider_fallback),
DEFAULT_MIN_RETRY_DELAY,
DEFAULT_BACKOFF_FACTOR,
DEFAULT_MAX_RETRIES,
DEFAULT_MAX_RETRY_DELAY,
ETHEREUM_CALL_MIN_RETRY_DELAY,
ETHEREUM_CALL_BACKOFF_FACTOR,
ETHEREUM_CALL_MAX_RETRIES,
ETHEREUM_CALL_MAX_RETRY_DELAY,
)
.await
.map_err(|e| {
Expand Down
73 changes: 37 additions & 36 deletions batcher/aligned-batcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ use std::net::SocketAddr;
use std::sync::Arc;

use aligned_sdk::core::constants::{
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, AGGREGATOR_GAS_COST, CANCEL_TRANSACTION_MAX_RETRIES,
CONSTANT_GAS_COST, DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER, DEFAULT_BACKOFF_FACTOR,
DEFAULT_MAX_FEE_PER_PROOF, DEFAULT_MAX_RETRIES, DEFAULT_MAX_RETRY_DELAY,
DEFAULT_MIN_RETRY_DELAY, GAS_PRICE_PERCENTAGE_MULTIPLIER, MIN_FEE_PER_PROOF,
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, AGGREGATOR_GAS_COST, BUMP_BACKOFF_FACTOR,
BUMP_MAX_RETRIES, BUMP_MAX_RETRY_DELAY, BUMP_MIN_RETRY_DELAY, CONSTANT_GAS_COST,
DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER, DEFAULT_MAX_FEE_PER_PROOF,
ETHEREUM_CALL_BACKOFF_FACTOR, ETHEREUM_CALL_MAX_RETRIES, ETHEREUM_CALL_MAX_RETRY_DELAY,
ETHEREUM_CALL_MIN_RETRY_DELAY, GAS_PRICE_PERCENTAGE_MULTIPLIER, MIN_FEE_PER_PROOF,
PERCENTAGE_DIVIDER, RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER,
};
use aligned_sdk::core::types::{
Expand Down Expand Up @@ -280,10 +281,10 @@ impl Batcher {
let app = self.clone();
async move { app.listen_new_blocks_retryable().await }
},
DEFAULT_MIN_RETRY_DELAY,
DEFAULT_BACKOFF_FACTOR,
ETHEREUM_CALL_MIN_RETRY_DELAY,
ETHEREUM_CALL_BACKOFF_FACTOR,
LISTEN_NEW_BLOCKS_MAX_TIMES,
DEFAULT_MAX_RETRY_DELAY,
ETHEREUM_CALL_MAX_RETRY_DELAY,
)
.await
.map_err(|e| e.inner())
Expand Down Expand Up @@ -908,7 +909,7 @@ impl Batcher {
}

/// Gets the user nonce from Ethereum.
/// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
/// Retries on recoverable errors using exponential backoff up to `ETHEREUM_CALL_MAX_RETRIES` times:
/// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
async fn get_user_nonce_from_ethereum(
&self,
Expand All @@ -922,10 +923,10 @@ impl Batcher {
addr,
)
},
DEFAULT_MIN_RETRY_DELAY,
DEFAULT_BACKOFF_FACTOR,
DEFAULT_MAX_RETRIES,
DEFAULT_MAX_RETRY_DELAY,
ETHEREUM_CALL_MIN_RETRY_DELAY,
ETHEREUM_CALL_BACKOFF_FACTOR,
ETHEREUM_CALL_MAX_RETRIES,
ETHEREUM_CALL_MAX_RETRY_DELAY,
)
.await
}
Expand Down Expand Up @@ -1366,7 +1367,7 @@ impl Batcher {
}

/// Sends a `create_new_task` transaction to Ethereum and waits for a maximum of 3 blocks for the receipt.
/// Retries up to `DEFAULT_MAX_RETRIES` times using exponential backoff on recoverable errors while trying to send the transaction:
/// Retries up to `ETHEREUM_CALL_MAX_RETRIES` times using exponential backoff on recoverable errors while trying to send the transaction:
/// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
/// `ReceiptNotFoundError` is treated as non-recoverable, and the transaction will be canceled using `cancel_create_new_task_tx` in that case.
async fn create_new_task(
Expand All @@ -1388,10 +1389,10 @@ impl Batcher {
&self.payment_service_fallback,
)
},
DEFAULT_MIN_RETRY_DELAY,
DEFAULT_BACKOFF_FACTOR,
DEFAULT_MAX_RETRIES,
DEFAULT_MAX_RETRY_DELAY,
ETHEREUM_CALL_MIN_RETRY_DELAY,
ETHEREUM_CALL_BACKOFF_FACTOR,
ETHEREUM_CALL_MAX_RETRIES,
ETHEREUM_CALL_MAX_RETRY_DELAY,
)
.await;
match result {
Expand Down Expand Up @@ -1453,10 +1454,10 @@ impl Batcher {
)
.await
},
DEFAULT_MIN_RETRY_DELAY,
DEFAULT_BACKOFF_FACTOR,
CANCEL_TRANSACTION_MAX_RETRIES,
DEFAULT_MAX_RETRY_DELAY,
BUMP_MIN_RETRY_DELAY,
BUMP_BACKOFF_FACTOR,
BUMP_MAX_RETRIES,
BUMP_MAX_RETRY_DELAY,
)
.await
{
Expand Down Expand Up @@ -1550,7 +1551,7 @@ impl Batcher {
}

/// Gets the balance of user with address `addr` from Ethereum.
/// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
/// Retries on recoverable errors using exponential backoff up to `ETHEREUM_CALL_MAX_RETRIES` times:
/// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs)
/// Returns `None` if the balance couldn't be returned
/// FIXME: This should return a `Result` instead.
Expand All @@ -1563,17 +1564,17 @@ impl Batcher {
addr,
)
},
DEFAULT_MIN_RETRY_DELAY,
DEFAULT_BACKOFF_FACTOR,
DEFAULT_MAX_RETRIES,
DEFAULT_MAX_RETRY_DELAY,
ETHEREUM_CALL_MIN_RETRY_DELAY,
ETHEREUM_CALL_BACKOFF_FACTOR,
ETHEREUM_CALL_MAX_RETRIES,
ETHEREUM_CALL_MAX_RETRY_DELAY,
)
.await
.ok()
}

/// Checks if the user's balance is unlocked for a given address.
/// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
/// Retries on recoverable errors using exponential backoff up to `ETHEREUM_CALL_MAX_RETRIES` times:
/// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
/// Returns `false` if an error occurs during the retries.
async fn user_balance_is_unlocked(&self, addr: &Address) -> bool {
Expand All @@ -1585,10 +1586,10 @@ impl Batcher {
addr,
)
},
DEFAULT_MIN_RETRY_DELAY,
DEFAULT_BACKOFF_FACTOR,
DEFAULT_MAX_RETRIES,
DEFAULT_MAX_RETRY_DELAY,
ETHEREUM_CALL_MIN_RETRY_DELAY,
ETHEREUM_CALL_BACKOFF_FACTOR,
ETHEREUM_CALL_MAX_RETRIES,
ETHEREUM_CALL_MAX_RETRY_DELAY,
)
.await
else {
Expand All @@ -1599,7 +1600,7 @@ impl Batcher {
}

/// Uploads the batch to s3.
/// Retries on recoverable errors using exponential backoff up to `DEFAULT_MAX_RETRIES` times:
/// Retries on recoverable errors using exponential backoff up to `ETHEREUM_CALL_MAX_RETRIES` times:
/// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
async fn upload_batch_to_s3(
&self,
Expand All @@ -1615,10 +1616,10 @@ impl Batcher {
&self.s3_bucket_name,
)
},
DEFAULT_MIN_RETRY_DELAY,
DEFAULT_BACKOFF_FACTOR,
DEFAULT_MAX_RETRIES,
DEFAULT_MAX_RETRY_DELAY,
ETHEREUM_CALL_MIN_RETRY_DELAY,
ETHEREUM_CALL_BACKOFF_FACTOR,
ETHEREUM_CALL_MAX_RETRIES,
ETHEREUM_CALL_MAX_RETRY_DELAY,
)
.await
.map_err(|e| BatcherError::BatchUploadError(e.to_string()))
Expand Down
17 changes: 11 additions & 6 deletions batcher/aligned-sdk/src/core/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// Batcher ///
pub const GAS_PRICE_INCREMENT_PERCENTAGE_PER_ITERATION: usize = 5;
pub const CANCEL_TRANSACTION_MAX_RETRIES: usize = 33; // ~ 1 day
pub const AGGREGATOR_GAS_COST: u128 = 400_000;
pub const BATCHER_SUBMISSION_BASE_GAS_COST: u128 = 125_000;
pub const ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF: u128 = 13_000;
Expand All @@ -27,8 +26,14 @@ pub const MAX_FEE_BATCH_PROOF_NUMBER: usize = 32;
/// This corresponds to the number of proofs to compute for a default max_fee.
pub const MAX_FEE_DEFAULT_PROOF_NUMBER: usize = 10;

/// retry
pub const DEFAULT_MIN_RETRY_DELAY: u64 = 500; // milliseconds
pub const DEFAULT_MAX_RETRIES: usize = 5;
pub const DEFAULT_BACKOFF_FACTOR: f32 = 2.0;
pub const DEFAULT_MAX_RETRY_DELAY: u64 = 3600; // seconds
/// Ethereum calls retry constants
pub const ETHEREUM_CALL_MIN_RETRY_DELAY: u64 = 500; // milliseconds
pub const ETHEREUM_CALL_MAX_RETRIES: usize = 5;
pub const ETHEREUM_CALL_BACKOFF_FACTOR: f32 = 2.0;
pub const ETHEREUM_CALL_MAX_RETRY_DELAY: u64 = 3600; // seconds

/// Ethereum transaction retry constants
pub const BUMP_MIN_RETRY_DELAY: u64 = 500; // milliseconds
pub const BUMP_MAX_RETRIES: usize = 33; // ~ 1 day
pub const BUMP_BACKOFF_FACTOR: f32 = 2.0;
pub const BUMP_MAX_RETRY_DELAY: u64 = 3600; // seconds
Loading