Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk committed Dec 12, 2024
1 parent db12c6e commit a3a03b1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
3 changes: 1 addition & 2 deletions bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Command for debugging block building.
use alloy_consensus::TxEip4844;
use alloy_eips::{
eip1559::ETHEREUM_BLOCK_GAS_LIMIT,
eip2718::Encodable2718,
eip4844::{env_settings::EnvKzgSettings, BlobTransactionSidecar},
};
Expand Down Expand Up @@ -248,7 +247,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {

let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
EthEvmConfig::new(provider_factory.chain_spec()),
EthereumBuilderConfig::new(Default::default(), ETHEREUM_BLOCK_GAS_LIMIT),
EthereumBuilderConfig::new(Default::default()),
);

match payload_builder.try_build(args)? {
Expand Down
3 changes: 1 addition & 2 deletions bin/reth/src/commands/debug_cmd/replay_engine.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::args::NetworkArgs;
use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT;
use clap::Parser;
use eyre::Context;
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
Expand Down Expand Up @@ -125,7 +124,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
// Set up payload builder
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
EthEvmConfig::new(provider_factory.chain_spec()),
EthereumBuilderConfig::new(Default::default(), ETHEREUM_BLOCK_GAS_LIMIT),
EthereumBuilderConfig::new(Default::default()),
);

let payload_generator = BasicPayloadJobGenerator::with_builder(
Expand Down
2 changes: 1 addition & 1 deletion crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl EthereumPayloadBuilder {
let conf = ctx.payload_builder_config();
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
evm_config,
EthereumBuilderConfig::new(conf.extradata_bytes(), conf.gas_limit()),
EthereumBuilderConfig::new(conf.extradata_bytes()).with_gas_limit(conf.gas_limit()),
);

let payload_job_config = BasicPayloadJobGeneratorConfig::default()
Expand Down
24 changes: 18 additions & 6 deletions crates/ethereum/payload/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT;
use alloy_primitives::Bytes;
use reth_primitives_traits::constants::GAS_LIMIT_BOUND_DIVISOR;

Expand All @@ -12,8 +13,14 @@ pub struct EthereumBuilderConfig {

impl EthereumBuilderConfig {
/// Create new payload builder config.
pub const fn new(extra_data: Bytes, desired_gas_limit: u64) -> Self {
Self { extra_data, desired_gas_limit }
pub const fn new(extra_data: Bytes) -> Self {
Self { extra_data, desired_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT }
}

/// Set desired gas limit.
pub fn with_gas_limit(desired_gas_limit: u64) -> Self {
self.desired_gas_limit = desired_gas_limit;
self
}
}

Expand All @@ -26,9 +33,14 @@ impl EthereumBuilderConfig {
/// 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 {
let delta = parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR;
let min_gas_limit = parent_gas_limit + delta - 1;
let max_gas_limit = parent_gas_limit - delta + 1;
parent_gas_limit.clamp(min_gas_limit, max_gas_limit)
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.
pub fn calculate_block_gas_limit(parent_gas_limit: u64, desired_gas_limit: u64) -> u64 {
let delta = parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR;
let min_gas_limit = parent_gas_limit + delta - 1;
let max_gas_limit = parent_gas_limit - delta + 1;
desired_gas_limit.clamp(min_gas_limit, max_gas_limit)
}
2 changes: 1 addition & 1 deletion crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ where
timestamp: attributes.timestamp(),
suggested_fee_recipient: attributes.suggested_fee_recipient(),
prev_randao: attributes.prev_randao(),
gas_limit: parent.gas_limit,
gas_limit: attributes.gas_limit.unwrap_or(parent.gas_limit),
};
self.evm_config.next_cfg_and_block_env(parent, next_attributes)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/custom-engine-types/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use alloy_eips::{eip1559::ETHEREUM_BLOCK_GAS_LIMIT, eip4895::Withdrawals};
use alloy_eips::eip4895::Withdrawals;
use alloy_genesis::Genesis;
use alloy_primitives::{Address, B256};
use alloy_rpc_types::{
Expand Down Expand Up @@ -408,7 +408,7 @@ where
// but any custom logic can be implemented here
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
EthEvmConfig::new(chain_spec.clone()),
EthereumBuilderConfig::new(default_extra_data_bytes(), ETHEREUM_BLOCK_GAS_LIMIT),
EthereumBuilderConfig::new(default_extra_data_bytes()),
)
.try_build(BuildArguments {
client,
Expand All @@ -430,7 +430,7 @@ where
<reth_ethereum_payload_builder::EthereumPayloadBuilder as PayloadBuilder<Pool, Client>>::build_empty_payload(
&reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
EthEvmConfig::new(chain_spec.clone()),
EthereumBuilderConfig::new(default_extra_data_bytes(), ETHEREUM_BLOCK_GAS_LIMIT)
EthereumBuilderConfig::new(default_extra_data_bytes())
),
client,
PayloadConfig { parent_header, attributes: attributes.0}
Expand Down
3 changes: 1 addition & 2 deletions examples/custom-payload-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT;
use generator::EmptyBlockPayloadJobGenerator;
use reth::{
builder::{components::PayloadServiceBuilder, node::FullNodeTypes, BuilderContext},
Expand Down Expand Up @@ -70,7 +69,7 @@ where
payload_job_config,
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
EthEvmConfig::new(ctx.chain_spec()),
EthereumBuilderConfig::new(default_extra_data_bytes(), ETHEREUM_BLOCK_GAS_LIMIT),
EthereumBuilderConfig::new(default_extra_data_bytes()),
),
);

Expand Down

0 comments on commit a3a03b1

Please sign in to comment.