diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 5974d1a030a0..845115cb0022 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -1380,7 +1380,7 @@ mod tests { #[cfg(feature = "optimism")] use reth_primitives::proofs::calculate_receipt_root_optimism; use reth_primitives::{ - constants::{EIP1559_INITIAL_BASE_FEE, EMPTY_ROOT_HASH, ETHEREUM_BLOCK_GAS_LIMIT}, + constants::{EIP1559_INITIAL_BASE_FEE, EMPTY_ROOT_HASH}, keccak256, proofs::calculate_transaction_root, revm_primitives::AccountInfo, @@ -1599,7 +1599,7 @@ mod tests { number, parent_hash: parent.unwrap_or_default(), gas_used: body.len() as u64 * 21_000, - gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, + gas_limit: chain_spec.max_gas_limit, mix_hash: B256::random(), base_fee_per_gas: Some(EIP1559_INITIAL_BASE_FEE), transactions_root, diff --git a/crates/chainspec/src/constants.rs b/crates/chainspec/src/constants.rs index 7026e76ff438..7ddc55b76bfc 100644 --- a/crates/chainspec/src/constants.rs +++ b/crates/chainspec/src/constants.rs @@ -7,3 +7,11 @@ pub(crate) const MAINNET_DEPOSIT_CONTRACT: DepositContract = DepositContract::ne 11052984, b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"), ); + +/// Max gas limit on Base Sepolia: +#[cfg(feature = "optimism")] +pub(crate) const BASE_SEPOLIA_MAX_GAS_LIMIT: u64 = 45_000_000; + +/// Max gas limit on Base: +#[cfg(feature = "optimism")] +pub(crate) const BASE_MAINNET_MAX_GAS_LIMIT: u64 = 97_500_000; diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index da12fd3ef1cf..a5706422222c 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -14,8 +14,8 @@ use reth_ethereum_forks::{ use reth_network_peers::NodeRecord; use reth_primitives_traits::{ constants::{ - DEV_GENESIS_HASH, EIP1559_INITIAL_BASE_FEE, EMPTY_WITHDRAWALS, HOLESKY_GENESIS_HASH, - MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH, + DEV_GENESIS_HASH, EIP1559_INITIAL_BASE_FEE, EMPTY_WITHDRAWALS, ETHEREUM_BLOCK_GAS_LIMIT, + HOLESKY_GENESIS_HASH, MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH, }, Header, SealedHeader, }; @@ -51,6 +51,7 @@ pub static MAINNET: Lazy> = Lazy::new(|| { b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"), )), base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, prune_delete_limit: 20000, }; spec.genesis.config.dao_fork_support = true; @@ -74,6 +75,7 @@ pub static SEPOLIA: Lazy> = Lazy::new(|| { b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"), )), base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, prune_delete_limit: 10000, }; spec.genesis.config.dao_fork_support = true; @@ -95,6 +97,7 @@ pub static HOLESKY: Lazy> = Lazy::new(|| { b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"), )), base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, prune_delete_limit: 10000, }; spec.genesis.config.dao_fork_support = true; @@ -141,6 +144,7 @@ pub static OP_MAINNET: Lazy> = Lazy::new(|| { ] .into(), ), + max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, prune_delete_limit: 10000, ..Default::default() } @@ -166,6 +170,7 @@ pub static OP_SEPOLIA: Lazy> = Lazy::new(|| { ] .into(), ), + max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, prune_delete_limit: 10000, ..Default::default() } @@ -191,6 +196,7 @@ pub static BASE_SEPOLIA: Lazy> = Lazy::new(|| { ] .into(), ), + max_gas_limit: crate::constants::BASE_SEPOLIA_MAX_GAS_LIMIT, prune_delete_limit: 10000, ..Default::default() } @@ -216,6 +222,7 @@ pub static BASE_MAINNET: Lazy> = Lazy::new(|| { ] .into(), ), + max_gas_limit: crate::constants::BASE_MAINNET_MAX_GAS_LIMIT, prune_delete_limit: 10000, ..Default::default() } @@ -298,6 +305,9 @@ pub struct ChainSpec { /// The parameters that configure how a block's base fee is computed pub base_fee_params: BaseFeeParamsKind, + /// The maximum gas limit + pub max_gas_limit: u64, + /// The delete limit for pruner, per run. pub prune_delete_limit: usize, } @@ -312,6 +322,7 @@ impl Default for ChainSpec { hardforks: Default::default(), deposit_contract: Default::default(), base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + max_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, prune_delete_limit: MAINNET.prune_delete_limit, } } diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index 2fd93e7caab6..c37277c068e3 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -22,9 +22,9 @@ use reth_engine_primitives::EngineTypes; use reth_execution_errors::{BlockExecutionError, BlockValidationError}; use reth_execution_types::ExecutionOutcome; use reth_primitives::{ - constants::ETHEREUM_BLOCK_GAS_LIMIT, eip4844::calculate_excess_blob_gas, proofs, Block, - BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithSenders, Bloom, Header, - Requests, SealedBlock, SealedHeader, TransactionSigned, Withdrawals, B256, U256, + eip4844::calculate_excess_blob_gas, proofs, Block, BlockBody, BlockHash, BlockHashOrNumber, + BlockNumber, BlockWithSenders, Bloom, Header, Requests, SealedBlock, SealedHeader, + TransactionSigned, Withdrawals, B256, U256, }; use reth_provider::{BlockReaderIdExt, StateProviderFactory, StateRootProvider}; use reth_revm::database::StateProviderDatabase; @@ -293,7 +293,7 @@ impl StorageInner { logs_bloom: Default::default(), difficulty: U256::from(2), number: self.best_block + 1, - gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, + gas_limit: chain_spec.max_gas_limit, gas_used: 0, timestamp, mix_hash: Default::default(), diff --git a/crates/consensus/beacon/src/engine/sync.rs b/crates/consensus/beacon/src/engine/sync.rs index 76a6d0e81552..aa1c9aa66690 100644 --- a/crates/consensus/beacon/src/engine/sync.rs +++ b/crates/consensus/beacon/src/engine/sync.rs @@ -417,7 +417,7 @@ mod tests { use reth_chainspec::{ChainSpecBuilder, MAINNET}; use reth_db::{mdbx::DatabaseEnv, test_utils::TempDatabase}; use reth_network_p2p::{either::Either, test_utils::TestFullBlockClient}; - use reth_primitives::{constants::ETHEREUM_BLOCK_GAS_LIMIT, BlockBody, Header, SealedHeader}; + use reth_primitives::{BlockBody, Header, SealedHeader}; use reth_provider::{ test_utils::create_test_provider_factory_with_chain_spec, ExecutionOutcome, }; @@ -618,7 +618,7 @@ mod tests { let client = TestFullBlockClient::default(); let header = Header { base_fee_per_gas: Some(7), - gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, + gas_limit: chain_spec.max_gas_limit, ..Default::default() } .seal_slow(); diff --git a/crates/engine/tree/src/backfill.rs b/crates/engine/tree/src/backfill.rs index 24153bed24c0..f575bff81234 100644 --- a/crates/engine/tree/src/backfill.rs +++ b/crates/engine/tree/src/backfill.rs @@ -212,7 +212,7 @@ mod tests { use reth_chainspec::{ChainSpecBuilder, MAINNET}; use reth_db::{mdbx::DatabaseEnv, test_utils::TempDatabase}; use reth_network_p2p::test_utils::TestFullBlockClient; - use reth_primitives::{constants::ETHEREUM_BLOCK_GAS_LIMIT, BlockNumber, Header, B256}; + use reth_primitives::{BlockNumber, Header, B256}; use reth_stages::ExecOutput; use reth_stages_api::StageCheckpoint; use reth_tasks::TokioTaskExecutor; @@ -239,13 +239,13 @@ mod tests { checkpoint: StageCheckpoint::new(BlockNumber::from(pipeline_done_after)), done: true, })])) - .build(chain_spec); + .build(chain_spec.clone()); let pipeline_sync = PipelineSync::new(pipeline, Box::::default()); let client = TestFullBlockClient::default(); let header = Header { base_fee_per_gas: Some(7), - gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, + gas_limit: chain_spec.max_gas_limit, ..Default::default() } .seal_slow(); diff --git a/crates/engine/tree/src/download.rs b/crates/engine/tree/src/download.rs index b8ebb8415c8d..de588c2c93f5 100644 --- a/crates/engine/tree/src/download.rs +++ b/crates/engine/tree/src/download.rs @@ -274,7 +274,7 @@ mod tests { use reth_beacon_consensus::EthBeaconConsensus; use reth_chainspec::{ChainSpecBuilder, MAINNET}; use reth_network_p2p::test_utils::TestFullBlockClient; - use reth_primitives::{constants::ETHEREUM_BLOCK_GAS_LIMIT, Header}; + use reth_primitives::Header; use std::{future::poll_fn, sync::Arc}; struct TestHarness { @@ -295,7 +295,7 @@ mod tests { let client = TestFullBlockClient::default(); let header = Header { base_fee_per_gas: Some(7), - gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, + gas_limit: chain_spec.max_gas_limit, ..Default::default() } .seal_slow(); diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index a7be685ef3a6..c7b491243864 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -113,7 +113,8 @@ where let base_fee = initialized_block_env.basefee.to::(); let block_number = initialized_block_env.number.to::(); - let block_gas_limit = initialized_block_env.gas_limit.try_into().unwrap_or(u64::MAX); + let block_gas_limit = + initialized_block_env.gas_limit.try_into().unwrap_or(chain_spec.max_gas_limit); // apply eip-4788 pre block contract call pre_block_beacon_root_contract_call( @@ -280,7 +281,8 @@ where debug!(target: "payload_builder", id=%attributes.id, parent_hash = ?parent_block.hash(), parent_number = parent_block.number, "building new payload"); let mut cumulative_gas_used = 0; let mut sum_blob_gas_used = 0; - let block_gas_limit: u64 = initialized_block_env.gas_limit.try_into().unwrap_or(u64::MAX); + let block_gas_limit: u64 = + initialized_block_env.gas_limit.try_into().unwrap_or(chain_spec.max_gas_limit); let base_fee = initialized_block_env.basefee.to::(); let mut executed_txs = Vec::new(); diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 93b8c9606132..47f3cd4457af 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -111,7 +111,8 @@ where let base_fee = initialized_block_env.basefee.to::(); let block_number = initialized_block_env.number.to::(); - let block_gas_limit: u64 = initialized_block_env.gas_limit.try_into().unwrap_or(u64::MAX); + let block_gas_limit: u64 = + initialized_block_env.gas_limit.try_into().unwrap_or(chain_spec.max_gas_limit); // apply eip-4788 pre block contract call pre_block_beacon_root_contract_call( @@ -255,9 +256,9 @@ where debug!(target: "payload_builder", id=%attributes.payload_attributes.payload_id(), parent_hash = ?parent_block.hash(), parent_number = parent_block.number, "building new payload"); let mut cumulative_gas_used = 0; - let block_gas_limit: u64 = attributes - .gas_limit - .unwrap_or_else(|| initialized_block_env.gas_limit.try_into().unwrap_or(u64::MAX)); + let block_gas_limit: u64 = attributes.gas_limit.unwrap_or_else(|| { + initialized_block_env.gas_limit.try_into().unwrap_or(chain_spec.max_gas_limit) + }); let base_fee = initialized_block_env.basefee.to::(); let mut executed_txs = Vec::with_capacity(attributes.transactions.len()); diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index bcdc0f95493a..643f935a2061 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -126,7 +126,7 @@ impl Call for OpEthApi { } impl LoadState for OpEthApi { - fn provider(&self) -> impl StateProviderFactory { + fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider { LoadState::provider(&self.inner) } diff --git a/crates/rpc/rpc-eth-api/src/helpers/call.rs b/crates/rpc/rpc-eth-api/src/helpers/call.rs index 4ee669691be8..2b4a277bd5a0 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/call.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/call.rs @@ -10,7 +10,7 @@ use reth_primitives::{ }, Bytes, TransactionSignedEcRecovered, TxKind, B256, U256, }; -use reth_provider::StateProvider; +use reth_provider::{ChainSpecProvider, StateProvider}; use reth_revm::{database::StateProviderDatabase, db::CacheDB, DatabaseRef}; use reth_rpc_eth_types::{ cache::db::{StateCacheDbRefMutWrapper, StateProviderTraitObjWrapper}, @@ -572,7 +572,8 @@ pub trait Call: LoadState + SpawnBlocking { } // We can now normalize the highest gas limit to a u64 - let mut highest_gas_limit: u64 = highest_gas_limit.try_into().unwrap_or(u64::MAX); + let mut highest_gas_limit: u64 = + highest_gas_limit.try_into().unwrap_or(self.provider().chain_spec().max_gas_limit); // If the provided gas limit is less than computed cap, use that env.tx.gas_limit = env.tx.gas_limit.min(highest_gas_limit); diff --git a/crates/rpc/rpc-eth-api/src/helpers/state.rs b/crates/rpc/rpc-eth-api/src/helpers/state.rs index 4b0d629259a9..0da2a49c3b18 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/state.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/state.rs @@ -5,7 +5,9 @@ use futures::Future; use reth_errors::RethError; use reth_evm::ConfigureEvmEnv; use reth_primitives::{Address, BlockId, Bytes, Header, B256, U256}; -use reth_provider::{BlockIdReader, StateProvider, StateProviderBox, StateProviderFactory}; +use reth_provider::{ + BlockIdReader, ChainSpecProvider, StateProvider, StateProviderBox, StateProviderFactory, +}; use reth_rpc_eth_types::{ EthApiError, EthResult, EthStateCache, PendingBlockEnv, RpcInvalidTransactionError, }; @@ -126,7 +128,7 @@ pub trait LoadState { /// Returns a handle for reading state from database. /// /// Data access in default trait method implementations. - fn provider(&self) -> impl StateProviderFactory; + fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider; /// Returns a handle for reading data from memory. /// diff --git a/crates/rpc/rpc/src/eth/core.rs b/crates/rpc/rpc/src/eth/core.rs index 36030741ff3e..3cff3b0096c7 100644 --- a/crates/rpc/rpc/src/eth/core.rs +++ b/crates/rpc/rpc/src/eth/core.rs @@ -315,10 +315,7 @@ mod tests { use reth_chainspec::BaseFeeParams; use reth_evm_ethereum::EthEvmConfig; use reth_network_api::noop::NoopNetwork; - use reth_primitives::{ - constants::ETHEREUM_BLOCK_GAS_LIMIT, Block, BlockNumberOrTag, Header, TransactionSigned, - B256, U64, - }; + use reth_primitives::{Block, BlockNumberOrTag, Header, TransactionSigned, B256, U64}; use reth_provider::{ test_utils::{MockEthProvider, NoopProvider}, BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory, @@ -352,13 +349,14 @@ mod tests { let fee_history_cache = FeeHistoryCache::new(cache.clone(), FeeHistoryCacheConfig::default()); + let gas_cap = provider.chain_spec().max_gas_limit; EthApi::new( provider.clone(), testing_pool(), NoopNetwork::default(), cache.clone(), GasPriceOracle::new(provider, Default::default(), cache), - ETHEREUM_BLOCK_GAS_LIMIT, + gas_cap, DEFAULT_ETH_PROOF_WINDOW, BlockingTaskPool::build().expect("failed to build tracing pool"), fee_history_cache, diff --git a/crates/rpc/rpc/src/eth/helpers/state.rs b/crates/rpc/rpc/src/eth/helpers/state.rs index 0eff4245e283..b291eb8a2016 100644 --- a/crates/rpc/rpc/src/eth/helpers/state.rs +++ b/crates/rpc/rpc/src/eth/helpers/state.rs @@ -1,6 +1,6 @@ //! Contains RPC handler implementations specific to state. -use reth_provider::StateProviderFactory; +use reth_provider::{ChainSpecProvider, StateProviderFactory}; use reth_transaction_pool::TransactionPool; use reth_rpc_eth_api::helpers::{EthState, LoadState, SpawnBlocking}; @@ -19,11 +19,11 @@ where impl LoadState for EthApi where - Provider: StateProviderFactory, + Provider: StateProviderFactory + ChainSpecProvider, Pool: TransactionPool, { #[inline] - fn provider(&self) -> impl StateProviderFactory { + fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider { self.inner.provider() } diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index f393519b2103..d7ed3e725d3e 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -11,9 +11,9 @@ use crate::{ }; use reth_chainspec::{ChainSpec, EthereumHardforks}; use reth_primitives::{ - constants::{eip4844::MAX_BLOBS_PER_BLOCK, ETHEREUM_BLOCK_GAS_LIMIT}, - GotExpected, InvalidTransactionError, SealedBlock, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, - EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID, LEGACY_TX_TYPE_ID, + constants::eip4844::MAX_BLOBS_PER_BLOCK, GotExpected, InvalidTransactionError, SealedBlock, + EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID, + LEGACY_TX_TYPE_ID, }; use reth_provider::{AccountReader, BlockReaderIdExt, StateProviderFactory}; use reth_tasks::TaskSpawner; @@ -479,8 +479,8 @@ impl EthTransactionValidatorBuilder { /// - EIP-4844 pub fn new(chain_spec: Arc) -> Self { Self { + block_gas_limit: chain_spec.max_gas_limit, chain_spec, - block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, minimum_priority_fee: None, additional_tasks: 1, kzg_settings: EnvKzgSettings::Default, diff --git a/examples/bsc-p2p/src/chainspec.rs b/examples/bsc-p2p/src/chainspec.rs index 0c4cbe1ed961..92bf2f10a317 100644 --- a/examples/bsc-p2p/src/chainspec.rs +++ b/examples/bsc-p2p/src/chainspec.rs @@ -22,6 +22,7 @@ pub(crate) fn bsc_chain_spec() -> Arc { )]), deposit_contract: None, base_fee_params: reth_chainspec::BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + max_gas_limit: 140_000_000, prune_delete_limit: 0, } .into() diff --git a/examples/polygon-p2p/src/chain_cfg.rs b/examples/polygon-p2p/src/chain_cfg.rs index 92256a1be1c3..90bfaab35dcc 100644 --- a/examples/polygon-p2p/src/chain_cfg.rs +++ b/examples/polygon-p2p/src/chain_cfg.rs @@ -27,6 +27,7 @@ pub(crate) fn polygon_chain_spec() -> Arc { ]), deposit_contract: None, base_fee_params: reth_chainspec::BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()), + max_gas_limit: 30_000_000, prune_delete_limit: 0, } .into()