feat: add max_gas_limit to ChainSpec (#9473)

This commit is contained in:
joshieDo
2024-07-12 16:12:15 +02:00
committed by GitHub
parent 5097ae7cff
commit b4363e2b48
17 changed files with 63 additions and 38 deletions

View File

@ -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,

View File

@ -7,3 +7,11 @@ pub(crate) const MAINNET_DEPOSIT_CONTRACT: DepositContract = DepositContract::ne
11052984,
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
);
/// Max gas limit on Base Sepolia: <https://sepolia.basescan.org/block/12506483>
#[cfg(feature = "optimism")]
pub(crate) const BASE_SEPOLIA_MAX_GAS_LIMIT: u64 = 45_000_000;
/// Max gas limit on Base: <https://basescan.org/block/16995982>
#[cfg(feature = "optimism")]
pub(crate) const BASE_MAINNET_MAX_GAS_LIMIT: u64 = 97_500_000;

View File

@ -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<Arc<ChainSpec>> = 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<Arc<ChainSpec>> = 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<Arc<ChainSpec>> = 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<Arc<ChainSpec>> = 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<Arc<ChainSpec>> = 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<Arc<ChainSpec>> = 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<Arc<ChainSpec>> = 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,
}
}

View File

@ -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(),

View File

@ -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();

View File

@ -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::<TokioTaskExecutor>::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();

View File

@ -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();

View File

@ -113,7 +113,8 @@ where
let base_fee = initialized_block_env.basefee.to::<u64>();
let block_number = initialized_block_env.number.to::<u64>();
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::<u64>();
let mut executed_txs = Vec::new();

View File

@ -111,7 +111,8 @@ where
let base_fee = initialized_block_env.basefee.to::<u64>();
let block_number = initialized_block_env.number.to::<u64>();
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::<u64>();
let mut executed_txs = Vec::with_capacity(attributes.transactions.len());

View File

@ -126,7 +126,7 @@ impl<Eth: Call> Call for OpEthApi<Eth> {
}
impl<Eth: LoadState> LoadState for OpEthApi<Eth> {
fn provider(&self) -> impl StateProviderFactory {
fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider {
LoadState::provider(&self.inner)
}

View File

@ -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);

View File

@ -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.
///

View File

@ -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,

View File

@ -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<Provider, Pool, Network, EvmConfig> LoadState for EthApi<Provider, Pool, Network, EvmConfig>
where
Provider: StateProviderFactory,
Provider: StateProviderFactory + ChainSpecProvider,
Pool: TransactionPool,
{
#[inline]
fn provider(&self) -> impl StateProviderFactory {
fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider {
self.inner.provider()
}

View File

@ -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<ChainSpec>) -> 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,

View File

@ -22,6 +22,7 @@ pub(crate) fn bsc_chain_spec() -> Arc<ChainSpec> {
)]),
deposit_contract: None,
base_fee_params: reth_chainspec::BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
max_gas_limit: 140_000_000,
prune_delete_limit: 0,
}
.into()

View File

@ -27,6 +27,7 @@ pub(crate) fn polygon_chain_spec() -> Arc<ChainSpec> {
]),
deposit_contract: None,
base_fee_params: reth_chainspec::BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
max_gas_limit: 30_000_000,
prune_delete_limit: 0,
}
.into()