-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(rpc): handle dedicated eth_simulate errors #20099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
65f8fb3
2cffc84
65c4ad2
8c7312f
8eca363
cb6cf78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| //! Helper traits to wrap generic l1 errors, in network specific error type configured in | ||
| //! `reth_rpc_eth_api::EthApiTypes`. | ||
|
|
||
| use crate::{EthApiError, RevertError}; | ||
| use crate::{simulate::EthSimulateError, EthApiError, RevertError}; | ||
| use alloy_primitives::Bytes; | ||
| use reth_errors::ProviderError; | ||
| use reth_evm::{ConfigureEvm, EvmErrorFor, HaltReasonFor}; | ||
|
|
@@ -74,6 +74,32 @@ pub trait AsEthApiError { | |
|
|
||
| false | ||
| } | ||
|
|
||
| /// Returns [`EthSimulateError`] if this error maps to a simulate-specific error code. | ||
| fn as_simulate_error(&self) -> Option<EthSimulateError> { | ||
|
Comment on lines
+78
to
+79
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, this should actually work |
||
| let err = self.as_err()?; | ||
| match err { | ||
| EthApiError::InvalidTransaction(tx_err) => match tx_err { | ||
| RpcInvalidTransactionError::NonceTooLow { tx, state } => { | ||
| Some(EthSimulateError::NonceTooLow { tx: *tx, state: *state }) | ||
| } | ||
| RpcInvalidTransactionError::NonceTooHigh => Some(EthSimulateError::NonceTooHigh), | ||
| RpcInvalidTransactionError::FeeCapTooLow => { | ||
| Some(EthSimulateError::BaseFeePerGasTooLow) | ||
| } | ||
| RpcInvalidTransactionError::GasTooLow => Some(EthSimulateError::IntrinsicGasTooLow), | ||
| RpcInvalidTransactionError::InsufficientFunds { cost, balance } => { | ||
| Some(EthSimulateError::InsufficientFunds { cost: *cost, balance: *balance }) | ||
| } | ||
| RpcInvalidTransactionError::SenderNoEOA => Some(EthSimulateError::SenderNotEOA), | ||
| RpcInvalidTransactionError::MaxInitCodeSizeExceeded => { | ||
| Some(EthSimulateError::MaxInitCodeSizeExceeded) | ||
| } | ||
| _ => None, | ||
| }, | ||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl AsEthApiError for EthApiError { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,7 +23,7 @@ use reth_storage_api::noop::NoopProvider; | |||||||||||||||||||||||||||||||
| use revm::{ | ||||||||||||||||||||||||||||||||
| context::Block, | ||||||||||||||||||||||||||||||||
| context_interface::result::ExecutionResult, | ||||||||||||||||||||||||||||||||
| primitives::{Address, Bytes, TxKind}, | ||||||||||||||||||||||||||||||||
| primitives::{Address, Bytes, TxKind, U256}, | ||||||||||||||||||||||||||||||||
| Database, | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -36,12 +36,67 @@ pub enum EthSimulateError { | |||||||||||||||||||||||||||||||
| /// Max gas limit for entire operation exceeded. | ||||||||||||||||||||||||||||||||
| #[error("Client adjustable limit reached")] | ||||||||||||||||||||||||||||||||
| GasLimitReached, | ||||||||||||||||||||||||||||||||
| /// Block number in sequence did not increase. | ||||||||||||||||||||||||||||||||
| #[error("Block number in sequence did not increase")] | ||||||||||||||||||||||||||||||||
| BlockNumberInvalid, | ||||||||||||||||||||||||||||||||
| /// Block timestamp in sequence did not increase or stay the same. | ||||||||||||||||||||||||||||||||
| #[error("Block timestamp in sequence did not increase")] | ||||||||||||||||||||||||||||||||
| BlockTimestampInvalid, | ||||||||||||||||||||||||||||||||
| /// Transaction nonce is too low. | ||||||||||||||||||||||||||||||||
| #[error("nonce too low: next nonce {state}, tx nonce {tx}")] | ||||||||||||||||||||||||||||||||
| NonceTooLow { | ||||||||||||||||||||||||||||||||
| /// Transaction nonce. | ||||||||||||||||||||||||||||||||
| tx: u64, | ||||||||||||||||||||||||||||||||
| /// Current state nonce. | ||||||||||||||||||||||||||||||||
| state: u64, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| /// Transaction nonce is too high. | ||||||||||||||||||||||||||||||||
| #[error("nonce too high")] | ||||||||||||||||||||||||||||||||
| NonceTooHigh, | ||||||||||||||||||||||||||||||||
| /// Transaction's baseFeePerGas is too low. | ||||||||||||||||||||||||||||||||
| #[error("max fee per gas less than block base fee")] | ||||||||||||||||||||||||||||||||
| BaseFeePerGasTooLow, | ||||||||||||||||||||||||||||||||
| /// Not enough gas provided to pay for intrinsic gas. | ||||||||||||||||||||||||||||||||
| #[error("intrinsic gas too low")] | ||||||||||||||||||||||||||||||||
| IntrinsicGasTooLow, | ||||||||||||||||||||||||||||||||
| /// Insufficient funds to pay for gas fees and value. | ||||||||||||||||||||||||||||||||
| #[error("insufficient funds for gas * price + value: have {balance} want {cost}")] | ||||||||||||||||||||||||||||||||
| InsufficientFunds { | ||||||||||||||||||||||||||||||||
| /// Transaction cost. | ||||||||||||||||||||||||||||||||
| cost: U256, | ||||||||||||||||||||||||||||||||
| /// Sender balance. | ||||||||||||||||||||||||||||||||
| balance: U256, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| /// Sender is not an EOA. | ||||||||||||||||||||||||||||||||
| #[error("sender is not an EOA")] | ||||||||||||||||||||||||||||||||
| SenderNotEOA, | ||||||||||||||||||||||||||||||||
| /// Max init code size exceeded. | ||||||||||||||||||||||||||||||||
| #[error("max initcode size exceeded")] | ||||||||||||||||||||||||||||||||
| MaxInitCodeSizeExceeded, | ||||||||||||||||||||||||||||||||
| /// `MovePrecompileToAddress` referenced itself in replacement. | ||||||||||||||||||||||||||||||||
| #[error("MovePrecompileToAddress referenced itself")] | ||||||||||||||||||||||||||||||||
| PrecompileSelfReference, | ||||||||||||||||||||||||||||||||
| /// Multiple `MovePrecompileToAddress` referencing the same address. | ||||||||||||||||||||||||||||||||
| #[error("Multiple MovePrecompileToAddress referencing the same address")] | ||||||||||||||||||||||||||||||||
| PrecompileDuplicateAddress, | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| impl EthSimulateError { | ||||||||||||||||||||||||||||||||
| const fn error_code(&self) -> i32 { | ||||||||||||||||||||||||||||||||
| /// Returns the JSON-RPC error code for a `eth_simulateV1` error. | ||||||||||||||||||||||||||||||||
| pub const fn error_code(&self) -> i32 { | ||||||||||||||||||||||||||||||||
| match self { | ||||||||||||||||||||||||||||||||
| Self::NonceTooLow { .. } => -38010, | ||||||||||||||||||||||||||||||||
| Self::NonceTooHigh => -38011, | ||||||||||||||||||||||||||||||||
| Self::BaseFeePerGasTooLow => -38012, | ||||||||||||||||||||||||||||||||
| Self::IntrinsicGasTooLow => -38013, | ||||||||||||||||||||||||||||||||
| Self::InsufficientFunds { .. } => -38014, | ||||||||||||||||||||||||||||||||
| Self::BlockGasLimitExceeded => -38015, | ||||||||||||||||||||||||||||||||
| Self::BlockNumberInvalid => -38020, | ||||||||||||||||||||||||||||||||
| Self::BlockTimestampInvalid => -38021, | ||||||||||||||||||||||||||||||||
| Self::PrecompileSelfReference => -38022, | ||||||||||||||||||||||||||||||||
| Self::PrecompileDuplicateAddress => -38023, | ||||||||||||||||||||||||||||||||
| Self::SenderNotEOA => -38024, | ||||||||||||||||||||||||||||||||
| Self::MaxInitCodeSizeExceeded => -38025, | ||||||||||||||||||||||||||||||||
|
Comment on lines
+88
to
+99
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be also great to check if any of those codes should apply here reth/crates/rpc/rpc-eth-types/src/error/mod.rs Lines 695 to 709 in 7e6a59b
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i agree, let me take a look at it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually i think we can leave it like this, there's nothing else to be added here pub const fn error_code(&self) -> i32 {
match self {
Self::InvalidChainId |
Self::GasTooLow |
Self::GasTooHigh |
Self::GasRequiredExceedsAllowance { .. } |
...
}
}the generic json-rpc codes stay at |
||||||||||||||||||||||||||||||||
| Self::GasLimitReached => -38026, | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't too bad either