Skip to content

Commit

Permalink
fix: deduplicate validate_initial_tx_gas API (#2006)
Browse files Browse the repository at this point in the history
* fix: deduplicate validate_initial_tx_gas API

* misc: apply review suggestions
  • Loading branch information
Wodann authored Jan 21, 2025
1 parent b4578fe commit 25512fd
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions crates/handler/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ where
context: &Self::Context,
) -> Result<InitialAndFloorGas, Self::Error> {
let spec = context.cfg().spec().into();
validate_initial_tx_gas::<&Self::Context, InvalidTransaction>(context, spec)
.map_err(Into::into)
validate_initial_tx_gas(context.tx(), spec).map_err(From::from)
}
}

Expand Down Expand Up @@ -333,16 +332,13 @@ where
}

/// Validate initial transaction gas.
pub fn validate_initial_tx_gas<CTX, Error>(
context: CTX,
pub fn validate_initial_tx_gas<TransactionT>(
tx: TransactionT,
spec_id: SpecId,
) -> Result<InitialAndFloorGas, Error>
) -> Result<InitialAndFloorGas, InvalidTransaction>
where
CTX: TransactionGetter + CfgGetter,
Error: From<InvalidTransaction>,
TransactionT: Transaction,
{
let spec = context.cfg().spec().into();
let tx = context.tx();
let (accounts, storages) = tx.access_list_nums().unwrap_or_default();

let gas = gas::calculate_initial_tx_gas(
Expand All @@ -356,13 +352,13 @@ where

// Additional check to see if limit is big enough to cover initial gas.
if gas.initial_gas > tx.gas_limit() {
return Err(InvalidTransaction::CallGasCostMoreThanGasLimit.into());
return Err(InvalidTransaction::CallGasCostMoreThanGasLimit);
}

// EIP-7623: Increase calldata cost
// floor gas should be less than gas limit.
if spec.is_enabled_in(SpecId::PRAGUE) && gas.floor_gas > tx.gas_limit() {
return Err(InvalidTransaction::GasFloorMoreThanGasLimit.into());
if spec_id.is_enabled_in(SpecId::PRAGUE) && gas.floor_gas > tx.gas_limit() {
return Err(InvalidTransaction::GasFloorMoreThanGasLimit);
};

Ok(gas)
Expand Down

0 comments on commit 25512fd

Please sign in to comment.