mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix(builder): desired block gas limit (#13351)
This commit is contained in:
@ -22,12 +22,12 @@ use reth_consensus_common::validation::{
|
||||
validate_header_base_fee, validate_header_extradata, validate_header_gas,
|
||||
};
|
||||
use reth_primitives::{BlockWithSenders, NodePrimitives, Receipt, SealedBlock, SealedHeader};
|
||||
use reth_primitives_traits::{constants::MINIMUM_GAS_LIMIT, BlockBody};
|
||||
use reth_primitives_traits::{
|
||||
constants::{GAS_LIMIT_BOUND_DIVISOR, MINIMUM_GAS_LIMIT},
|
||||
BlockBody,
|
||||
};
|
||||
use std::{fmt::Debug, sync::Arc, time::SystemTime};
|
||||
|
||||
/// The bound divisor of the gas limit, used in update calculations.
|
||||
pub const GAS_LIMIT_BOUND_DIVISOR: u64 = 1024;
|
||||
|
||||
mod validation;
|
||||
pub use validation::validate_block_post_execution;
|
||||
|
||||
|
||||
@ -154,7 +154,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
|
||||
self.chain_spec.base_fee_params_at_timestamp(attributes.timestamp),
|
||||
);
|
||||
|
||||
let mut gas_limit = U256::from(parent.gas_limit);
|
||||
let mut gas_limit = U256::from(attributes.gas_limit);
|
||||
|
||||
// If we are on the London fork boundary, we need to multiply the parent's gas limit by the
|
||||
// elasticity multiplier to get the new gas limit.
|
||||
|
||||
@ -27,7 +27,6 @@ reth-consensus.workspace = true
|
||||
reth-beacon-consensus.workspace = true
|
||||
reth-rpc.workspace = true
|
||||
reth-node-api.workspace = true
|
||||
reth-node-core.workspace = true
|
||||
reth-chainspec.workspace = true
|
||||
reth-primitives.workspace = true
|
||||
reth-revm = { workspace = true, features = ["std"] }
|
||||
@ -43,7 +42,7 @@ eyre.workspace = true
|
||||
reth-chainspec.workspace = true
|
||||
reth-db.workspace = true
|
||||
reth-exex.workspace = true
|
||||
reth-node-api.workspace = true
|
||||
reth-node-core.workspace = true
|
||||
reth-payload-primitives.workspace = true
|
||||
reth-e2e-test-utils.workspace = true
|
||||
reth-rpc-eth-api.workspace = true
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
//! Ethereum Node types config.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
|
||||
use reth_beacon_consensus::EthBeaconConsensus;
|
||||
use reth_chainspec::ChainSpec;
|
||||
@ -24,7 +22,6 @@ use reth_node_builder::{
|
||||
rpc::{EngineValidatorBuilder, RpcAddOns},
|
||||
BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig, PayloadTypes,
|
||||
};
|
||||
use reth_node_core::version::default_extra_data_bytes;
|
||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||
use reth_primitives::{EthPrimitives, PooledTransactionsElement};
|
||||
use reth_provider::{CanonStateSubscriptions, EthStorage};
|
||||
@ -35,6 +32,7 @@ use reth_transaction_pool::{
|
||||
TransactionValidationTaskExecutor,
|
||||
};
|
||||
use reth_trie_db::MerklePatriciaTrie;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{EthEngineTypes, EthEvmConfig};
|
||||
|
||||
@ -230,24 +228,9 @@ where
|
||||
}
|
||||
|
||||
/// A basic ethereum payload service.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct EthereumPayloadBuilder {
|
||||
/// Payload builder configuration.
|
||||
config: EthereumBuilderConfig,
|
||||
}
|
||||
|
||||
impl Default for EthereumPayloadBuilder {
|
||||
fn default() -> Self {
|
||||
Self { config: EthereumBuilderConfig::new(default_extra_data_bytes()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl EthereumPayloadBuilder {
|
||||
/// Create new ethereum payload builder.
|
||||
pub const fn new(config: EthereumBuilderConfig) -> Self {
|
||||
Self { config }
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Default, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct EthereumPayloadBuilder;
|
||||
|
||||
impl EthereumPayloadBuilder {
|
||||
/// A helper method initializing [`PayloadBuilderService`] with the given EVM config.
|
||||
@ -270,9 +253,11 @@ impl EthereumPayloadBuilder {
|
||||
PayloadBuilderAttributes = EthPayloadBuilderAttributes,
|
||||
>,
|
||||
{
|
||||
let payload_builder =
|
||||
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(evm_config, self.config);
|
||||
let conf = ctx.payload_builder_config();
|
||||
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
|
||||
evm_config,
|
||||
EthereumBuilderConfig::new(conf.extradata_bytes()).with_gas_limit(conf.gas_limit()),
|
||||
);
|
||||
|
||||
let payload_job_config = BasicPayloadJobGeneratorConfig::default()
|
||||
.interval(conf.interval())
|
||||
|
||||
@ -14,6 +14,7 @@ workspace = true
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-primitives.workspace = true
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-revm.workspace = true
|
||||
reth-transaction-pool.workspace = true
|
||||
reth-payload-builder.workspace = true
|
||||
|
||||
@ -1,16 +1,26 @@
|
||||
use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT;
|
||||
use alloy_primitives::Bytes;
|
||||
use reth_primitives_traits::constants::GAS_LIMIT_BOUND_DIVISOR;
|
||||
|
||||
/// Settings for the Ethereum builder.
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
pub struct EthereumBuilderConfig {
|
||||
/// Block extra data.
|
||||
pub extra_data: Bytes,
|
||||
/// Desired gas limit.
|
||||
pub desired_gas_limit: u64,
|
||||
}
|
||||
|
||||
impl EthereumBuilderConfig {
|
||||
/// Create new payload builder config.
|
||||
pub const fn new(extra_data: Bytes) -> Self {
|
||||
Self { extra_data }
|
||||
Self { extra_data, desired_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT }
|
||||
}
|
||||
|
||||
/// Set desired gas limit.
|
||||
pub const fn with_gas_limit(mut self, desired_gas_limit: u64) -> Self {
|
||||
self.desired_gas_limit = desired_gas_limit;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,4 +29,19 @@ impl EthereumBuilderConfig {
|
||||
pub fn extra_data(&self) -> Bytes {
|
||||
self.extra_data.clone()
|
||||
}
|
||||
|
||||
/// Returns the gas limit for the next block based
|
||||
/// on parent and desired gas limits.
|
||||
pub fn gas_limit(&self, parent_gas_limit: u64) -> u64 {
|
||||
calculate_block_gas_limit(parent_gas_limit, self.desired_gas_limit)
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculate the gas limit for the next block based on parent and desired gas limits.
|
||||
/// Ref: <https://github.com/ethereum/go-ethereum/blob/88cbfab332c96edfbe99d161d9df6a40721bd786/core/block_validator.go#L166>
|
||||
pub fn calculate_block_gas_limit(parent_gas_limit: u64, desired_gas_limit: u64) -> u64 {
|
||||
let delta = (parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR).saturating_sub(1);
|
||||
let min_gas_limit = parent_gas_limit - delta;
|
||||
let max_gas_limit = parent_gas_limit + delta;
|
||||
desired_gas_limit.clamp(min_gas_limit, max_gas_limit)
|
||||
}
|
||||
|
||||
@ -88,6 +88,7 @@ where
|
||||
timestamp: config.attributes.timestamp(),
|
||||
suggested_fee_recipient: config.attributes.suggested_fee_recipient(),
|
||||
prev_randao: config.attributes.prev_randao(),
|
||||
gas_limit: self.builder_config.gas_limit(parent.gas_limit),
|
||||
};
|
||||
self.evm_config.next_cfg_and_block_env(parent, next_attributes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user