feat: move calculate_intrinsic_gas_after_merge to tx pool (#8914)

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Krishang
2024-06-19 17:40:47 +05:30
committed by GitHub
parent 5edf449633
commit a3fd112915
10 changed files with 32 additions and 36 deletions

2
Cargo.lock generated
View File

@ -7742,7 +7742,6 @@ dependencies = [
"reth-primitives-traits", "reth-primitives-traits",
"reth-static-file-types", "reth-static-file-types",
"reth-trie-common", "reth-trie-common",
"revm",
"revm-primitives", "revm-primitives",
"roaring", "roaring",
"secp256k1", "secp256k1",
@ -8334,6 +8333,7 @@ dependencies = [
"reth-provider", "reth-provider",
"reth-tasks", "reth-tasks",
"reth-tracing", "reth-tracing",
"revm",
"rustc-hash", "rustc-hash",
"schnellru", "schnellru",
"serde", "serde",

View File

@ -40,4 +40,5 @@ optimism = [
"reth-primitives/optimism", "reth-primitives/optimism",
"reth-provider/optimism", "reth-provider/optimism",
"reth-optimism-consensus/optimism", "reth-optimism-consensus/optimism",
"reth-revm/optimism",
] ]

View File

@ -66,4 +66,5 @@ optimism = [
"reth-evm-optimism/optimism", "reth-evm-optimism/optimism",
"reth-optimism-payload-builder/optimism", "reth-optimism-payload-builder/optimism",
"reth-beacon-consensus/optimism", "reth-beacon-consensus/optimism",
"reth-revm/optimism",
] ]

View File

@ -42,4 +42,5 @@ optimism = [
"reth-provider/optimism", "reth-provider/optimism",
"reth-rpc-types-compat/optimism", "reth-rpc-types-compat/optimism",
"reth-evm-optimism/optimism", "reth-evm-optimism/optimism",
] "reth-revm/optimism",
]

View File

@ -19,7 +19,6 @@ reth-ethereum-forks.workspace = true
reth-static-file-types.workspace = true reth-static-file-types.workspace = true
reth-trie-common.workspace = true reth-trie-common.workspace = true
reth-chainspec.workspace = true reth-chainspec.workspace = true
revm.workspace = true
revm-primitives = { workspace = true, features = ["serde"] } revm-primitives = { workspace = true, features = ["serde"] }
# ethereum # ethereum
@ -48,7 +47,7 @@ once_cell.workspace = true
rayon.workspace = true rayon.workspace = true
serde.workspace = true serde.workspace = true
tempfile = { workspace = true, optional = true } tempfile = { workspace = true, optional = true }
thiserror-no-std = { workspace = true , default-features = false } thiserror-no-std = { workspace = true, default-features = false }
zstd = { version = "0.13", features = ["experimental"], optional = true } zstd = { version = "0.13", features = ["experimental"], optional = true }
roaring = "0.10.2" roaring = "0.10.2"
@ -103,24 +102,15 @@ arbitrary = [
"dep:proptest-derive", "dep:proptest-derive",
"zstd-codec", "zstd-codec",
] ]
c-kzg = [ c-kzg = ["dep:c-kzg", "revm-primitives/c-kzg", "dep:tempfile", "alloy-eips/kzg"]
"dep:c-kzg",
"revm/c-kzg",
"revm-primitives/c-kzg",
"dep:tempfile",
"alloy-eips/kzg",
]
zstd-codec = ["dep:zstd"] zstd-codec = ["dep:zstd"]
optimism = [ optimism = [
"reth-chainspec/optimism", "reth-chainspec/optimism",
"reth-codecs/optimism", "reth-codecs/optimism",
"reth-ethereum-forks/optimism", "reth-ethereum-forks/optimism",
"revm/optimism", "revm-primitives/optimism",
]
alloy-compat = [
"reth-primitives-traits/alloy-compat",
"alloy-rpc-types",
] ]
alloy-compat = ["reth-primitives-traits/alloy-compat", "dep:alloy-rpc-types"]
std = ["thiserror-no-std/std"] std = ["thiserror-no-std/std"]
test-utils = ["reth-primitives-traits/test-utils"] test-utils = ["reth-primitives-traits/test-utils"]

View File

@ -1,5 +1,4 @@
use crate::{revm_primitives::AccountInfo, Account, Address, TxKind, KECCAK_EMPTY, U256}; use crate::{revm_primitives::AccountInfo, Account, KECCAK_EMPTY};
use revm::{interpreter::gas::validate_initial_tx_gas, primitives::SpecId};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::vec::Vec; use alloc::vec::Vec;
@ -27,17 +26,3 @@ pub fn into_revm_acc(reth_acc: Account) -> AccountInfo {
code: None, code: None,
} }
} }
/// Calculates the Intrinsic Gas usage for a Transaction
///
/// Caution: This only checks past the Merge hardfork.
#[inline]
pub fn calculate_intrinsic_gas_after_merge(
input: &[u8],
kind: &TxKind,
access_list: &[(Address, Vec<U256>)],
is_shanghai: bool,
) -> u64 {
let spec_id = if is_shanghai { SpecId::SHANGHAI } else { SpecId::MERGE };
validate_initial_tx_gas(spec_id, input, kind.is_create(), access_list)
}

View File

@ -36,6 +36,8 @@ tracing.workspace = true
reth-trie.workspace = true reth-trie.workspace = true
[features] [features]
default = ["std"] default = ["std", "c-kzg"]
std = [] std = []
c-kzg = ["revm/c-kzg"]
test-utils = ["dep:reth-trie"] test-utils = ["dep:reth-trie"]
optimism = ["revm/optimism"]

View File

@ -96,4 +96,5 @@ optimism = [
"reth-provider/optimism", "reth-provider/optimism",
"dep:reth-evm-optimism", "dep:reth-evm-optimism",
"reth-evm-optimism/optimism", "reth-evm-optimism/optimism",
"reth-revm/optimism",
] ]

View File

@ -19,6 +19,7 @@ reth-primitives.workspace = true
reth-fs-util.workspace = true reth-fs-util.workspace = true
reth-provider.workspace = true reth-provider.workspace = true
reth-tasks.workspace = true reth-tasks.workspace = true
revm.workspace = true
# ethereum # ethereum
alloy-rlp.workspace = true alloy-rlp.workspace = true

View File

@ -16,12 +16,12 @@ use reth_primitives::{
ETHEREUM_BLOCK_GAS_LIMIT, ETHEREUM_BLOCK_GAS_LIMIT,
}, },
kzg::KzgSettings, kzg::KzgSettings,
revm::compat::calculate_intrinsic_gas_after_merge, Address, GotExpected, InvalidTransactionError, SealedBlock, TxKind, EIP1559_TX_TYPE_ID,
GotExpected, InvalidTransactionError, SealedBlock, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID, U256,
EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID,
}; };
use reth_provider::{AccountReader, BlockReaderIdExt, StateProviderFactory}; use reth_provider::{AccountReader, BlockReaderIdExt, StateProviderFactory};
use reth_tasks::TaskSpawner; use reth_tasks::TaskSpawner;
use revm::{interpreter::gas::validate_initial_tx_gas, primitives::SpecId};
use std::{ use std::{
marker::PhantomData, marker::PhantomData,
sync::{atomic::AtomicBool, Arc}, sync::{atomic::AtomicBool, Arc},
@ -728,6 +728,20 @@ pub fn ensure_intrinsic_gas<T: PoolTransaction>(
} }
} }
/// Calculates the Intrinsic Gas usage for a Transaction
///
/// Caution: This only checks past the Merge hardfork.
#[inline]
pub fn calculate_intrinsic_gas_after_merge(
input: &[u8],
kind: &TxKind,
access_list: &[(Address, Vec<U256>)],
is_shanghai: bool,
) -> u64 {
let spec_id = if is_shanghai { SpecId::SHANGHAI } else { SpecId::MERGE };
validate_initial_tx_gas(spec_id, input, kind.is_create(), access_list)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;