mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(builder): ethereum builder config (#13315)
This commit is contained in:
@ -27,6 +27,7 @@ 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 +44,6 @@ 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
|
||||
|
||||
@ -8,6 +8,7 @@ use reth_chainspec::ChainSpec;
|
||||
use reth_ethereum_engine_primitives::{
|
||||
EthBuiltPayload, EthPayloadAttributes, EthPayloadBuilderAttributes,
|
||||
};
|
||||
use reth_ethereum_payload_builder::EthereumBuilderConfig;
|
||||
use reth_evm::execute::BasicBlockExecutorProvider;
|
||||
use reth_evm_ethereum::execute::EthExecutionStrategyFactory;
|
||||
use reth_network::{EthNetworkPrimitives, NetworkHandle, PeersInfo};
|
||||
@ -23,6 +24,7 @@ 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};
|
||||
@ -228,9 +230,24 @@ where
|
||||
}
|
||||
|
||||
/// A basic ethereum payload service.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub struct EthereumPayloadBuilder;
|
||||
#[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 }
|
||||
}
|
||||
}
|
||||
|
||||
impl EthereumPayloadBuilder {
|
||||
/// A helper method initializing [`PayloadBuilderService`] with the given EVM config.
|
||||
@ -254,7 +271,7 @@ impl EthereumPayloadBuilder {
|
||||
>,
|
||||
{
|
||||
let payload_builder =
|
||||
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(evm_config);
|
||||
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(evm_config, self.config);
|
||||
let conf = ctx.payload_builder_config();
|
||||
|
||||
let payload_job_config = BasicPayloadJobGeneratorConfig::default()
|
||||
|
||||
22
crates/ethereum/payload/src/config.rs
Normal file
22
crates/ethereum/payload/src/config.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use alloy_primitives::Bytes;
|
||||
|
||||
/// Settings for the Ethereum builder.
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
pub struct EthereumBuilderConfig {
|
||||
/// Block extra data.
|
||||
pub extra_data: Bytes,
|
||||
}
|
||||
|
||||
impl EthereumBuilderConfig {
|
||||
/// Create new payload builder config.
|
||||
pub const fn new(extra_data: Bytes) -> Self {
|
||||
Self { extra_data }
|
||||
}
|
||||
}
|
||||
|
||||
impl EthereumBuilderConfig {
|
||||
/// Returns owned extra data bytes for the block.
|
||||
pub fn extra_data(&self) -> Bytes {
|
||||
self.extra_data.clone()
|
||||
}
|
||||
}
|
||||
@ -50,21 +50,26 @@ use revm::{
|
||||
use std::sync::Arc;
|
||||
use tracing::{debug, trace, warn};
|
||||
|
||||
mod config;
|
||||
pub use config::*;
|
||||
|
||||
type BestTransactionsIter<Pool> = Box<
|
||||
dyn BestTransactions<Item = Arc<ValidPoolTransaction<<Pool as TransactionPool>::Transaction>>>,
|
||||
>;
|
||||
|
||||
/// Ethereum payload builder
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EthereumPayloadBuilder<EvmConfig = EthEvmConfig> {
|
||||
/// The type responsible for creating the evm.
|
||||
evm_config: EvmConfig,
|
||||
/// Payload builder configuration.
|
||||
builder_config: EthereumBuilderConfig,
|
||||
}
|
||||
|
||||
impl<EvmConfig> EthereumPayloadBuilder<EvmConfig> {
|
||||
/// `EthereumPayloadBuilder` constructor.
|
||||
pub const fn new(evm_config: EvmConfig) -> Self {
|
||||
Self { evm_config }
|
||||
pub const fn new(evm_config: EvmConfig, builder_config: EthereumBuilderConfig) -> Self {
|
||||
Self { evm_config, builder_config }
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,9 +112,14 @@ where
|
||||
.map_err(PayloadBuilderError::other)?;
|
||||
|
||||
let pool = args.pool.clone();
|
||||
default_ethereum_payload(self.evm_config.clone(), args, cfg_env, block_env, |attributes| {
|
||||
pool.best_transactions_with_attributes(attributes)
|
||||
})
|
||||
default_ethereum_payload(
|
||||
self.evm_config.clone(),
|
||||
self.builder_config.clone(),
|
||||
args,
|
||||
cfg_env,
|
||||
block_env,
|
||||
|attributes| pool.best_transactions_with_attributes(attributes),
|
||||
)
|
||||
}
|
||||
|
||||
fn build_empty_payload(
|
||||
@ -133,9 +143,14 @@ where
|
||||
|
||||
let pool = args.pool.clone();
|
||||
|
||||
default_ethereum_payload(self.evm_config.clone(), args, cfg_env, block_env, |attributes| {
|
||||
pool.best_transactions_with_attributes(attributes)
|
||||
})?
|
||||
default_ethereum_payload(
|
||||
self.evm_config.clone(),
|
||||
self.builder_config.clone(),
|
||||
args,
|
||||
cfg_env,
|
||||
block_env,
|
||||
|attributes| pool.best_transactions_with_attributes(attributes),
|
||||
)?
|
||||
.into_payload()
|
||||
.ok_or_else(|| PayloadBuilderError::MissingPayload)
|
||||
}
|
||||
@ -149,6 +164,7 @@ where
|
||||
#[inline]
|
||||
pub fn default_ethereum_payload<EvmConfig, Pool, Client, F>(
|
||||
evm_config: EvmConfig,
|
||||
builder_config: EthereumBuilderConfig,
|
||||
args: BuildArguments<Pool, Client, EthPayloadBuilderAttributes, EthBuiltPayload>,
|
||||
initialized_cfg: CfgEnvWithHandlerCfg,
|
||||
initialized_block_env: BlockEnv,
|
||||
@ -167,7 +183,7 @@ where
|
||||
let state = StateProviderDatabase::new(state_provider);
|
||||
let mut db =
|
||||
State::builder().with_database(cached_reads.as_db_mut(state)).with_bundle_update().build();
|
||||
let PayloadConfig { parent_header, extra_data, attributes } = config;
|
||||
let PayloadConfig { parent_header, attributes } = config;
|
||||
|
||||
debug!(target: "payload_builder", id=%attributes.id, parent_header = ?parent_header.hash(), parent_number = parent_header.number, "building new payload");
|
||||
let mut cumulative_gas_used = 0;
|
||||
@ -470,7 +486,7 @@ where
|
||||
gas_limit: block_gas_limit,
|
||||
difficulty: U256::ZERO,
|
||||
gas_used: cumulative_gas_used,
|
||||
extra_data,
|
||||
extra_data: builder_config.extra_data,
|
||||
parent_beacon_block_root: attributes.parent_beacon_block_root,
|
||||
blob_gas_used: blob_gas_used.map(Into::into),
|
||||
excess_blob_gas: excess_blob_gas.map(Into::into),
|
||||
|
||||
Reference in New Issue
Block a user