Skip to content

Commit a71243b

Browse files
mablrmattsse
andauthored
refactor(anvil): simplify determine_base_gas_by_kind logic (#12787)
Don't convert tx request to typed tx, just inspect tx kind and authorizations list len. Co-authored-by: Matthias Seitz <[email protected]>
1 parent 84a34f4 commit a71243b

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

crates/anvil/src/eth/api.rs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,33 +3618,16 @@ fn ensure_return_ok(exit: InstructionResult, out: &Option<Output>) -> Result<Byt
36183618

36193619
/// Determines the minimum gas needed for a transaction depending on the transaction kind.
36203620
fn determine_base_gas_by_kind(request: &WithOtherFields<TransactionRequest>) -> u128 {
3621-
match transaction_request_to_typed(request.clone()) {
3622-
Some(request) => match request {
3623-
FoundryTypedTx::Legacy(req) => match req.to {
3624-
TxKind::Call(_) => MIN_TRANSACTION_GAS,
3625-
TxKind::Create => MIN_CREATE_GAS,
3626-
},
3627-
FoundryTypedTx::Eip1559(req) => match req.to {
3628-
TxKind::Call(_) => MIN_TRANSACTION_GAS,
3629-
TxKind::Create => MIN_CREATE_GAS,
3630-
},
3631-
FoundryTypedTx::Eip7702(req) => {
3632-
MIN_TRANSACTION_GAS
3633-
+ req.authorization_list.len() as u128 * PER_EMPTY_ACCOUNT_COST as u128
3634-
}
3635-
FoundryTypedTx::Eip2930(req) => match req.to {
3636-
TxKind::Call(_) => MIN_TRANSACTION_GAS,
3637-
TxKind::Create => MIN_CREATE_GAS,
3638-
},
3639-
FoundryTypedTx::Eip4844(_) => MIN_TRANSACTION_GAS,
3640-
FoundryTypedTx::Deposit(req) => match req.to {
3641-
TxKind::Call(_) => MIN_TRANSACTION_GAS,
3642-
TxKind::Create => MIN_CREATE_GAS,
3643-
},
3644-
},
3645-
// Tighten the gas limit upwards if we don't know the transaction type to avoid deployments
3646-
// failing.
3647-
_ => MIN_CREATE_GAS,
3621+
match request.kind() {
3622+
Some(TxKind::Call(_)) => {
3623+
MIN_TRANSACTION_GAS
3624+
+ request.inner().authorization_list.as_ref().map_or(0, |auths_list| {
3625+
auths_list.len() as u128 * PER_EMPTY_ACCOUNT_COST as u128
3626+
})
3627+
}
3628+
Some(TxKind::Create) => MIN_CREATE_GAS,
3629+
// Tighten the gas limit upwards if we don't know the tx kind to avoid deployments failing.
3630+
None => MIN_CREATE_GAS,
36483631
}
36493632
}
36503633

0 commit comments

Comments
 (0)