瀏覽代碼

fix(fortuna): catch contract error in simulation (#2854)

Tejas Badadare 4 月之前
父節點
當前提交
b508485920
共有 1 個文件被更改,包括 14 次插入2 次删除
  1. 14 2
      apps/fortuna/src/eth_utils/utils.rs

+ 14 - 2
apps/fortuna/src/eth_utils/utils.rs

@@ -8,7 +8,7 @@ use {
     ethers::{
     ethers::{
         contract::{ContractCall, ContractError},
         contract::{ContractCall, ContractError},
         middleware::Middleware,
         middleware::Middleware,
-        providers::ProviderError,
+        providers::{MiddlewareError, ProviderError},
         signers::Signer,
         signers::Signer,
         types::{
         types::{
             transaction::eip2718::TypedTransaction, TransactionReceipt, TransactionRequest, U256,
             transaction::eip2718::TypedTransaction, TransactionReceipt, TransactionRequest, U256,
@@ -253,7 +253,19 @@ pub async fn submit_tx<T: Middleware + NonceManaged + 'static>(
     client
     client
         .fill_transaction(&mut transaction, None)
         .fill_transaction(&mut transaction, None)
         .await
         .await
-        .map_err(|e| backoff::Error::transient(SubmitTxError::GasPriceEstimateError(e)))?;
+        .map_err(|e| {
+            // If there is revert data, the contract reverted during gas usage estimation.
+            if let Some(e) = e.as_error_response() {
+                if let Some(e) = e.as_revert_data() {
+                    return backoff::Error::transient(SubmitTxError::GasUsageEstimateError(
+                        ContractError::Revert(e.clone()),
+                    ));
+                }
+            }
+
+            // If there is no revert data, there was likely an error during gas price polling.
+            backoff::Error::transient(SubmitTxError::GasPriceEstimateError(e))
+        })?;
 
 
     // Apply the fee escalation policy. Note: the unwrap_or_default should never default as we have a gas oracle
     // Apply the fee escalation policy. Note: the unwrap_or_default should never default as we have a gas oracle
     // in the client that sets the gas price.
     // in the client that sets the gas price.