Skip to content

Commit 8d342d3

Browse files
aathanAAEvalir
authored
Pass details on GasTooHigh (#5489)
* Pass details on GasTooHigh * Update anvil/src/eth/backend/mem/mod.rs * chore: fmt/clippy --------- Co-authored-by: AA <aa@aa> Co-authored-by: evalir <hi@enriqueortiz.dev>
1 parent 9a4bb7f commit 8d342d3

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

anvil/src/eth/api.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ impl EthApi {
20532053

20542054
// Exceptional case: init used too much gas, we need to increase the gas limit and try
20552055
// again
2056-
if let Err(BlockchainError::InvalidTransaction(InvalidTransactionError::GasTooHigh)) =
2056+
if let Err(BlockchainError::InvalidTransaction(InvalidTransactionError::GasTooHigh(_))) =
20572057
ethres
20582058
{
20592059
// if price or limit was included in the request then we can execute the request
@@ -2125,8 +2125,9 @@ impl EthApi {
21252125

21262126
// Exceptional case: init used too much gas, we need to increase the gas limit and try
21272127
// again
2128-
if let Err(BlockchainError::InvalidTransaction(InvalidTransactionError::GasTooHigh)) =
2129-
ethres
2128+
if let Err(BlockchainError::InvalidTransaction(InvalidTransactionError::GasTooHigh(
2129+
_,
2130+
))) = ethres
21302131
{
21312132
// increase the lowest gas limit
21322133
lowest_gas_limit = mid_gas_limit;

anvil/src/eth/backend/mem/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
time::{utc_from_secs, TimeManager},
1414
validate::TransactionValidator,
1515
},
16-
error::{BlockchainError, InvalidTransactionError},
16+
error::{BlockchainError, ErrDetail, InvalidTransactionError},
1717
fees::{FeeDetails, FeeManager},
1818
macros::node_info,
1919
pool::transactions::PoolTransaction,
@@ -2180,7 +2180,9 @@ impl TransactionValidator for Backend {
21802180
// Check gas limit, iff block gas limit is set.
21812181
if !env.cfg.disable_block_gas_limit && tx.gas_limit() > env.block.gas_limit.into() {
21822182
warn!(target: "backend", "[{:?}] gas too high", tx.hash());
2183-
return Err(InvalidTransactionError::GasTooHigh)
2183+
return Err(InvalidTransactionError::GasTooHigh(ErrDetail {
2184+
detail: String::from("tx.gas_limit > env.block.gas_limit"),
2185+
}))
21842186
}
21852187

21862188
// check nonce

anvil/src/eth/error.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ pub enum FeeHistoryError {
119119
InvalidBlockRange,
120120
}
121121

122+
#[derive(Debug)]
123+
pub struct ErrDetail {
124+
pub detail: String,
125+
}
126+
122127
/// An error due to invalid transaction
123128
#[derive(thiserror::Error, Debug)]
124129
pub enum InvalidTransactionError {
@@ -150,8 +155,8 @@ pub enum InvalidTransactionError {
150155
#[error("intrinsic gas too low")]
151156
GasTooLow,
152157
/// returned if the transaction gas exceeds the limit
153-
#[error("intrinsic gas too high")]
154-
GasTooHigh,
158+
#[error("intrinsic gas too high -- {}",.0.detail)]
159+
GasTooHigh(ErrDetail),
155160
/// Thrown to ensure no one is able to specify a transaction with a tip higher than the total
156161
/// fee cap.
157162
#[error("max priority fee per gas higher than max fee per gas")]
@@ -185,8 +190,16 @@ impl From<revm::primitives::InvalidTransaction> for InvalidTransactionError {
185190
InvalidTransactionError::TipAboveFeeCap
186191
}
187192
InvalidTransaction::GasPriceLessThanBasefee => InvalidTransactionError::FeeCapTooLow,
188-
InvalidTransaction::CallerGasLimitMoreThanBlock => InvalidTransactionError::GasTooHigh,
189-
InvalidTransaction::CallGasCostMoreThanGasLimit => InvalidTransactionError::GasTooHigh,
193+
InvalidTransaction::CallerGasLimitMoreThanBlock => {
194+
InvalidTransactionError::GasTooHigh(ErrDetail {
195+
detail: String::from("CallerGasLimitMoreThanBlock"),
196+
})
197+
}
198+
InvalidTransaction::CallGasCostMoreThanGasLimit => {
199+
InvalidTransactionError::GasTooHigh(ErrDetail {
200+
detail: String::from("CallGasCostMoreThanGasLimit"),
201+
})
202+
}
190203
InvalidTransaction::RejectCallerWithCode => InvalidTransactionError::SenderNoEOA,
191204
InvalidTransaction::LackOfFundForGasLimit { .. } => {
192205
InvalidTransactionError::InsufficientFunds
@@ -272,7 +285,15 @@ impl<T: Serialize> ToRpcResponseResult for Result<T> {
272285
data: serde_json::to_value(data).ok(),
273286
}
274287
}
275-
InvalidTransactionError::GasTooLow | InvalidTransactionError::GasTooHigh => {
288+
InvalidTransactionError::GasTooLow => {
289+
// <https://eips.ethereum.org/EIPS/eip-1898>
290+
RpcError {
291+
code: ErrorCode::ServerError(-32000),
292+
message: err.to_string().into(),
293+
data: None,
294+
}
295+
}
296+
InvalidTransactionError::GasTooHigh(_) => {
276297
// <https://eips.ethereum.org/EIPS/eip-1898>
277298
RpcError {
278299
code: ErrorCode::ServerError(-32000),

0 commit comments

Comments
 (0)