Skip to content
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

feat: move calculate_intrinsic_gas_after_merge to tx pool #8914

Merged
merged 10 commits into from
Jun 19, 2024
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/optimism/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ optimism = [
"reth-primitives/optimism",
"reth-provider/optimism",
"reth-optimism-consensus/optimism",
"reth-revm/optimism",
]
1 change: 1 addition & 0 deletions crates/optimism/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ optimism = [
"reth-evm-optimism/optimism",
"reth-optimism-payload-builder/optimism",
"reth-beacon-consensus/optimism",
"reth-revm/optimism",
]
3 changes: 2 additions & 1 deletion crates/optimism/payload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ optimism = [
"reth-provider/optimism",
"reth-rpc-types-compat/optimism",
"reth-evm-optimism/optimism",
]
"reth-revm/optimism",
]
18 changes: 4 additions & 14 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ reth-ethereum-forks.workspace = true
reth-static-file-types.workspace = true
reth-trie-common.workspace = true
reth-chainspec.workspace = true
revm.workspace = true
revm-primitives = { workspace = true, features = ["serde"] }

# ethereum
Expand Down Expand Up @@ -48,7 +47,7 @@ once_cell.workspace = true
rayon.workspace = true
serde.workspace = 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 }
roaring = "0.10.2"

Expand Down Expand Up @@ -103,24 +102,15 @@ arbitrary = [
"dep:proptest-derive",
"zstd-codec",
]
c-kzg = [
"dep:c-kzg",
"revm/c-kzg",
"revm-primitives/c-kzg",
"dep:tempfile",
"alloy-eips/kzg",
]
c-kzg = ["dep:c-kzg", "revm-primitives/c-kzg", "dep:tempfile", "alloy-eips/kzg"]
zstd-codec = ["dep:zstd"]
optimism = [
"reth-chainspec/optimism",
"reth-codecs/optimism",
"reth-ethereum-forks/optimism",
"revm/optimism",
]
alloy-compat = [
"reth-primitives-traits/alloy-compat",
"alloy-rpc-types",
"revm-primitives/optimism",
]
alloy-compat = ["reth-primitives-traits/alloy-compat", "dep:alloy-rpc-types"]
std = ["thiserror-no-std/std"]
test-utils = ["reth-primitives-traits/test-utils"]

Expand Down
17 changes: 1 addition & 16 deletions crates/primitives/src/revm/compat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{revm_primitives::AccountInfo, Account, Address, TxKind, KECCAK_EMPTY, U256};
use revm::{interpreter::gas::validate_initial_tx_gas, primitives::SpecId};
use crate::{revm_primitives::AccountInfo, Account, KECCAK_EMPTY};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
Expand Down Expand Up @@ -27,17 +26,3 @@ pub fn into_revm_acc(reth_acc: Account) -> AccountInfo {
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)
}
4 changes: 3 additions & 1 deletion crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ tracing.workspace = true
reth-trie.workspace = true

[features]
default = ["std"]
default = ["std", "c-kzg"]
std = []
c-kzg = ["revm/c-kzg"]
test-utils = ["dep:reth-trie"]
optimism = ["revm/optimism"]
1 change: 1 addition & 0 deletions crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ optimism = [
"reth-provider/optimism",
"dep:reth-evm-optimism",
"reth-evm-optimism/optimism",
"reth-revm/optimism",
]
1 change: 1 addition & 0 deletions crates/transaction-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ reth-primitives.workspace = true
reth-fs-util.workspace = true
reth-provider.workspace = true
reth-tasks.workspace = true
revm.workspace = true

# ethereum
alloy-rlp.workspace = true
Expand Down
20 changes: 17 additions & 3 deletions crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use reth_primitives::{
ETHEREUM_BLOCK_GAS_LIMIT,
},
kzg::KzgSettings,
revm::compat::calculate_intrinsic_gas_after_merge,
GotExpected, InvalidTransactionError, SealedBlock, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID,
EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID,
Address, GotExpected, InvalidTransactionError, SealedBlock, TxKind, EIP1559_TX_TYPE_ID,
EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID, U256,
};
use reth_provider::{AccountReader, BlockReaderIdExt, StateProviderFactory};
use reth_tasks::TaskSpawner;
use revm::{interpreter::gas::validate_initial_tx_gas, primitives::SpecId};
use std::{
marker::PhantomData,
sync::{atomic::AtomicBool, Arc},
Expand Down Expand Up @@ -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)]
mod tests {
use super::*;
Expand Down
Loading