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
24 changes: 23 additions & 1 deletion batcher/aligned-batcher/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,8 @@ use ethers::contract::ContractError;
use ethers::signers::Signer;
use retry::batcher_retryables::{
cancel_create_new_task_retryable, create_new_task_retryable, get_user_balance_retryable,
get_user_nonce_from_ethereum_retryable, user_balance_is_unlocked_retryable,
get_user_nonce_from_ethereum_retryable, simulate_create_new_task_retryable,
user_balance_is_unlocked_retryable,
};
use retry::{retry_function, RetryError};
use tokio::time::timeout;
Expand DownExpand Up@@ -1479,6 +1480,27 @@ impl Batcher {
proof_submitters: Vec<Address>,
fee_params: CreateNewTaskFeeParams,
) -> Result<TransactionReceipt, BatcherError> {
// First, we simulate the tx
retry_function(
|| {
simulate_create_new_task_retryable(
batch_merkle_root,
batch_data_pointer.clone(),
proof_submitters.clone(),
fee_params.clone(),
&self.payment_service,
&self.payment_service_fallback,
)
},
ETHEREUM_CALL_MIN_RETRY_DELAY,
ETHEREUM_CALL_BACKOFF_FACTOR,
ETHEREUM_CALL_MAX_RETRIES,
ETHEREUM_CALL_MAX_RETRY_DELAY,
)
.await
.map_err(|e| e.inner())?;

// Then, we send the real tx
let result = retry_function(
|| {
create_new_task_retryable(
Expand Down
57 changes: 57 additions & 0 deletions batcher/aligned-batcher/src/retry/batcher_retryables.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,6 +175,63 @@ pub async fn create_new_task_retryable(
.ok_or(RetryError::Permanent(BatcherError::ReceiptNotFoundError))
}

pub async fn simulate_create_new_task_retryable(
batch_merkle_root: [u8; 32],
batch_data_pointer: String,
proofs_submitters: Vec<Address>,
fee_params: CreateNewTaskFeeParams,
payment_service: &BatcherPaymentService,
payment_service_fallback: &BatcherPaymentService,
) -> Result<(), RetryError<BatcherError>> {
info!("Simulating task for: 0x{}", hex::encode(batch_merkle_root));
let simulation_fallback;
let simulation = payment_service
.create_new_task(
batch_merkle_root,
batch_data_pointer.clone(),
proofs_submitters.clone(),
fee_params.fee_for_aggregator,
fee_params.fee_per_proof,
fee_params.respond_to_task_fee_limit,
)
.gas_price(fee_params.gas_price);
// sends an `eth_call` request to the node
match simulation.call().await {
Ok(_) => Ok(()),
Err(ContractError::Revert(err)) => {
// Since transaction was reverted, we don't want to retry with fallback.
warn!("Simulated transaction reverted {:?}", err);
Err(RetryError::Permanent(BatcherError::TransactionSendError(
TransactionSendError::from(err),
)))
}
_ => {
simulation_fallback = payment_service_fallback
.create_new_task(
batch_merkle_root,
batch_data_pointer,
proofs_submitters,
fee_params.fee_for_aggregator,
fee_params.fee_per_proof,
fee_params.respond_to_task_fee_limit,
)
.gas_price(fee_params.gas_price);
match simulation_fallback.call().await {
Ok(_) => Ok(()),
Err(ContractError::Revert(err)) => {
warn!("Simulated transaction reverted {:?}", err);
Err(RetryError::Permanent(BatcherError::TransactionSendError(
TransactionSendError::from(err),
)))
}
Err(err) => Err(RetryError::Transient(BatcherError::TransactionSendError(
TransactionSendError::Generic(err.to_string()),
))),
}
}
}
}

pub async fn cancel_create_new_task_retryable(
batcher_signer: &SignerMiddlewareT,
batcher_signer_fallback: &SignerMiddlewareT,
Expand Down