-
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
base: main
Are you sure you want to change the base?
feat(rpc): handle dedicated eth_simulate errors #20099
Conversation
b851b3e to
cf00024
Compare
1f3f9e6 to
8c7312f
Compare
mattsse
left a comment
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.
I think this should do it
wdyt @klkvr
| /// Returns [`EthSimulateError`] if this error maps to a simulate-specific error code. | ||
| fn as_simulate_error(&self) -> Option<EthSimulateError> { |
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.
okay, this should actually work
| let map_err = |e: EthApiError| -> Self::Error { | ||
| match e.as_simulate_error() { | ||
| Some(sim_err) => Self::Error::from_eth_err(EthApiError::other(sim_err)), | ||
| None => Self::Error::from_eth_err(e), | ||
| } | ||
| }; |
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
klkvr
left a comment
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 makes sense, though I think it's likely that there are some error code fixes that not only apply to simulateV1
| 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, |
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.
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
| /// Returns the rpc error code for this error. | |
| pub const fn error_code(&self) -> i32 { | |
| match self { | |
| Self::InvalidChainId | | |
| Self::GasTooLow | | |
| Self::GasTooHigh | | |
| Self::GasRequiredExceedsAllowance { .. } | | |
| Self::NonceTooLow { .. } | | |
| Self::NonceTooHigh { .. } | | |
| Self::FeeCapTooLow | | |
| Self::FeeCapVeryHigh => EthRpcErrorCode::InvalidInput.code(), | |
| Self::Revert(_) => EthRpcErrorCode::ExecutionError.code(), | |
| _ => EthRpcErrorCode::TransactionRejected.code(), | |
| } | |
| } |
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.
i agree, let me take a look at it
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.
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 RpcInvalidTransactionError and the conversion for (if needed) is handled by as_simulate_error(). the ones that don't match are specific
solves #20054 by:
EthSimulateErrorfollowing execution-apis and geth/ethapi/errorsAsEthApiErrorwith as_simulate_error() to match RpcInvalidTransactionError counterpartssimulate_v1using this new method