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: add max_gas_limit to ChainSpec #9473

Merged
merged 5 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions crates/chainspec/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
15 changes: 13 additions & 2 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand Down Expand Up @@ -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,
}
Expand All @@ -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,
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/consensus/auto-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/beacon/src/engine/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions crates/engine/tree/src/backfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/tree/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 3 additions & 2 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions crates/rpc/rpc-eth-api/src/helpers/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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.
///
Expand Down
8 changes: 3 additions & 5 deletions crates/rpc/rpc/src/eth/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/rpc/src/eth/helpers/state.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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()
}

Expand Down
8 changes: 4 additions & 4 deletions crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions examples/bsc-p2p/src/chainspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions examples/polygon-p2p/src/chain_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading