chore: add optimism rpc errors (#5821)

Co-authored-by: psychiller <pscyhiller@protonmail.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
psychiller
2023-12-20 11:04:42 +05:30
committed by GitHub
parent 282f4ffb9f
commit 92e5b2dafb
2 changed files with 20 additions and 6 deletions

View File

@ -44,6 +44,8 @@ use revm::{
#[cfg(feature = "optimism")]
use crate::eth::api::optimism::OptimismTxMeta;
#[cfg(feature = "optimism")]
use crate::eth::error::OptimismEthApiError;
#[cfg(feature = "optimism")]
use reth_revm::optimism::RethL1BlockInfo;
#[cfg(feature = "optimism")]
use revm::L1BlockInfo;
@ -966,10 +968,10 @@ where
&envelope_buf,
tx.is_deposit(),
)
.map_err(|_| EthApiError::InternalEthError)?;
.map_err(|_| EthApiError::Optimism(OptimismEthApiError::L1BlockFeeError))?;
let inner_l1_data_gas = l1_block_info
.l1_data_gas(&self.inner.provider.chain_spec(), block_timestamp, &envelope_buf)
.map_err(|_| EthApiError::InternalEthError)?;
.map_err(|_| EthApiError::Optimism(OptimismEthApiError::L1BlockGasError))?;
(Some(inner_l1_fee), Some(inner_l1_data_gas))
} else {
(None, None)
@ -996,7 +998,7 @@ where
target = "rpc::eth",
"Failed to serialize transaction for forwarding to sequencer"
);
EthApiError::InternalEthError
EthApiError::Optimism(OptimismEthApiError::InvalidSequencerTransaction)
})?;
self.inner
@ -1006,7 +1008,7 @@ where
.body(body)
.send()
.await
.map_err(|_| EthApiError::InternalEthError)?;
.map_err(|err| EthApiError::Optimism(OptimismEthApiError::HttpError(err)))?;
}
Ok(())
}

View File

@ -113,9 +113,18 @@ pub enum OptimismEthApiError {
/// Wrapper around a [hyper::Error].
#[error(transparent)]
HyperError(#[from] hyper::Error),
/// Wrapper around an [http::Error].
/// Wrapper around an [reqwest::Error].
#[error(transparent)]
HttpError(#[from] http::Error),
HttpError(#[from] reqwest::Error),
/// Thrown when serializing transaction to forward to sequencer
#[error("invalid sequencer transaction")]
InvalidSequencerTransaction,
/// Thrown when calculating L1 gas fee
#[error("failed to calculate l1 gas fee")]
L1BlockFeeError,
/// Thrown when calculating L1 gas used
#[error("failed to calculate l1 gas used")]
L1BlockGasError,
}
impl From<EthApiError> for ErrorObject<'static> {
@ -156,6 +165,9 @@ impl From<EthApiError> for ErrorObject<'static> {
EthApiError::Optimism(err) => match err {
OptimismEthApiError::HyperError(err) => internal_rpc_err(err.to_string()),
OptimismEthApiError::HttpError(err) => internal_rpc_err(err.to_string()),
OptimismEthApiError::InvalidSequencerTransaction |
OptimismEthApiError::L1BlockFeeError |
OptimismEthApiError::L1BlockGasError => internal_rpc_err(err.to_string()),
},
}
}