Skip to content

Commit

Permalink
chore: Remove ChainSpec from PayloadConfig (#11103)
Browse files Browse the repository at this point in the history
Co-authored-by: garwah <garwah@garwah>
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent 53f23bf commit ab66f58
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 52 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
best_block.hash(),
payload_attrs,
)?,
provider_factory.chain_spec(),
);

let args = BuildArguments::new(
Expand Down
1 change: 0 additions & 1 deletion bin/reth/src/commands/debug_cmd/replay_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
NoopTransactionPool::default(),
ctx.task_executor.clone(),
BasicPayloadJobGeneratorConfig::default(),
provider_factory.chain_spec(),
payload_builder,
);

Expand Down
1 change: 0 additions & 1 deletion crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ impl EthereumPayloadBuilder {
pool,
ctx.task_executor().clone(),
payload_job_config,
ctx.chain_spec(),
payload_builder,
);
let (payload_service, payload_builder) =
Expand Down
1 change: 1 addition & 0 deletions crates/ethereum/payload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ reth-evm-ethereum.workspace = true
reth-errors.workspace = true
reth-trie.workspace = true
reth-chain-state.workspace = true
reth-chainspec.workspace = true

# ethereum
revm.workspace = true
Expand Down
13 changes: 7 additions & 6 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use reth_basic_payload_builder::{
PayloadConfig, WithdrawalsOutcome,
};
use reth_chain_state::ExecutedBlock;
use reth_chainspec::ChainSpec;
use reth_errors::RethError;
use reth_evm::{
system_calls::{
Expand All @@ -36,7 +37,7 @@ use reth_primitives::{
Block, BlockBody, EthereumHardforks, Header, IntoRecoveredTransaction, Receipt,
EMPTY_OMMER_ROOT_HASH,
};
use reth_provider::StateProviderFactory;
use reth_provider::{ChainSpecProvider, StateProviderFactory};
use reth_revm::database::StateProviderDatabase;
use reth_transaction_pool::{
noop::NoopTransactionPool, BestTransactionsAttributes, TransactionPool,
Expand Down Expand Up @@ -88,7 +89,7 @@ where
impl<EvmConfig, Pool, Client> PayloadBuilder<Pool, Client> for EthereumPayloadBuilder<EvmConfig>
where
EvmConfig: ConfigureEvm<Header = Header>,
Client: StateProviderFactory,
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
Pool: TransactionPool,
{
type Attributes = EthPayloadBuilderAttributes;
Expand Down Expand Up @@ -137,22 +138,22 @@ pub fn default_ethereum_payload<EvmConfig, Pool, Client>(
) -> Result<BuildOutcome<EthBuiltPayload>, PayloadBuilderError>
where
EvmConfig: ConfigureEvm<Header = Header>,
Client: StateProviderFactory,
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
Pool: TransactionPool,
{
let BuildArguments { client, pool, mut cached_reads, config, cancel, best_payload } = args;

let chain_spec = client.chain_spec();
let state_provider = client.state_by_block_hash(config.parent_block.hash())?;
let state = StateProviderDatabase::new(state_provider);
let mut db =
State::builder().with_database_ref(cached_reads.as_db(state)).with_bundle_update().build();
let PayloadConfig { parent_block, extra_data, attributes, chain_spec } = config;
let PayloadConfig { parent_block, extra_data, attributes } = config;

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(chain_spec.max_gas_limit);
let block_gas_limit: u64 = initialized_block_env.gas_limit.to::<u64>();
let base_fee = initialized_block_env.basefee.to::<u64>();

let mut executed_txs = Vec::new();
Expand Down
1 change: 0 additions & 1 deletion crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ impl OptimismPayloadBuilder {
pool,
ctx.task_executor().clone(),
payload_job_config,
ctx.chain_spec(),
payload_builder,
);
let (payload_service, payload_builder) =
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 @@ -5,7 +5,7 @@ use std::sync::Arc;
use alloy_primitives::U256;
use reth_basic_payload_builder::*;
use reth_chain_state::ExecutedBlock;
use reth_chainspec::EthereumHardforks;
use reth_chainspec::{ChainSpec, ChainSpecProvider, EthereumHardforks};
use reth_evm::{
system_calls::pre_block_beacon_root_contract_call, ConfigureEvm, ConfigureEvmEnv,
NextBlockEnvAttributes,
Expand Down Expand Up @@ -93,7 +93,7 @@ where
/// Implementation of the [`PayloadBuilder`] trait for [`OptimismPayloadBuilder`].
impl<Pool, Client, EvmConfig> PayloadBuilder<Pool, Client> for OptimismPayloadBuilder<EvmConfig>
where
Client: StateProviderFactory,
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
Pool: TransactionPool,
EvmConfig: ConfigureEvm<Header = Header>,
{
Expand Down Expand Up @@ -164,16 +164,17 @@ pub(crate) fn optimism_payload<EvmConfig, Pool, Client>(
) -> Result<BuildOutcome<OptimismBuiltPayload>, PayloadBuilderError>
where
EvmConfig: ConfigureEvm<Header = Header>,
Client: StateProviderFactory,
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
Pool: TransactionPool,
{
let BuildArguments { client, pool, mut cached_reads, config, cancel, best_payload } = args;

let chain_spec = client.chain_spec();
let state_provider = client.state_by_block_hash(config.parent_block.hash())?;
let state = StateProviderDatabase::new(state_provider);
let mut db =
State::builder().with_database_ref(cached_reads.as_db(state)).with_bundle_update().build();
let PayloadConfig { parent_block, attributes, chain_spec, extra_data } = config;
let PayloadConfig { parent_block, attributes, extra_data } = config;

debug!(target: "payload_builder", id=%attributes.payload_attributes.payload_id(), parent_hash = ?parent_block.hash(), parent_number = parent_block.number, "building new payload");

Expand Down
17 changes: 3 additions & 14 deletions crates/payload/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ pub struct BasicPayloadJobGenerator<Client, Pool, Tasks, Builder> {
config: BasicPayloadJobGeneratorConfig,
/// Restricts how many generator tasks can be executed at once.
payload_task_guard: PayloadTaskGuard,
/// The chain spec.
chain_spec: Arc<ChainSpec>,
/// The type responsible for building payloads.
///
/// See [`PayloadBuilder`]
Expand All @@ -78,7 +76,6 @@ impl<Client, Pool, Tasks, Builder> BasicPayloadJobGenerator<Client, Pool, Tasks,
pool: Pool,
executor: Tasks,
config: BasicPayloadJobGeneratorConfig,
chain_spec: Arc<ChainSpec>,
builder: Builder,
) -> Self {
Self {
Expand All @@ -87,7 +84,6 @@ impl<Client, Pool, Tasks, Builder> BasicPayloadJobGenerator<Client, Pool, Tasks,
executor,
payload_task_guard: PayloadTaskGuard::new(config.max_payload_tasks),
config,
chain_spec,
builder,
pre_cached: None,
}
Expand Down Expand Up @@ -163,12 +159,8 @@ where
block.seal(attributes.parent())
};

let config = PayloadConfig::new(
Arc::new(parent_block),
self.config.extradata.clone(),
attributes,
Arc::clone(&self.chain_spec),
);
let config =
PayloadConfig::new(Arc::new(parent_block), self.config.extradata.clone(), attributes);

let until = self.job_deadline(config.attributes.timestamp());
let deadline = Box::pin(tokio::time::sleep_until(until));
Expand Down Expand Up @@ -676,8 +668,6 @@ pub struct PayloadConfig<Attributes> {
pub extra_data: Bytes,
/// Requested attributes for the payload.
pub attributes: Attributes,
/// The chain spec.
pub chain_spec: Arc<ChainSpec>,
}

impl<Attributes> PayloadConfig<Attributes> {
Expand All @@ -696,9 +686,8 @@ where
parent_block: Arc<SealedBlock>,
extra_data: Bytes,
attributes: Attributes,
chain_spec: Arc<ChainSpec>,
) -> Self {
Self { parent_block, extra_data, attributes, chain_spec }
Self { parent_block, extra_data, attributes }
}

/// Returns the payload id.
Expand Down
21 changes: 9 additions & 12 deletions examples/custom-engine-types/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use reth_basic_payload_builder::{
BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig, BuildArguments, BuildOutcome,
PayloadBuilder, PayloadConfig,
};
use reth_chainspec::{Chain, ChainSpec};
use reth_chainspec::{Chain, ChainSpec, ChainSpecProvider};
use reth_node_api::{
payload::{EngineApiMessageVersion, EngineObjectValidationError, PayloadOrAttributes},
validate_version_specific_fields, EngineTypes, EngineValidator, PayloadAttributes,
Expand Down Expand Up @@ -285,7 +285,6 @@ where
pool,
ctx.task_executor().clone(),
payload_job_config,
ctx.chain_spec(),
payload_builder,
);
let (payload_service, payload_builder) =
Expand All @@ -304,7 +303,7 @@ pub struct CustomPayloadBuilder;

impl<Pool, Client> PayloadBuilder<Pool, Client> for CustomPayloadBuilder
where
Client: StateProviderFactory,
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
Pool: TransactionPool,
{
type Attributes = CustomPayloadBuilderAttributes;
Expand All @@ -315,7 +314,9 @@ where
args: BuildArguments<Pool, Client, Self::Attributes, Self::BuiltPayload>,
) -> Result<BuildOutcome<Self::BuiltPayload>, PayloadBuilderError> {
let BuildArguments { client, pool, cached_reads, config, cancel, best_payload } = args;
let PayloadConfig { parent_block, extra_data, attributes, chain_spec } = config;
let PayloadConfig { parent_block, extra_data, attributes } = config;

let chain_spec = client.chain_spec();

// This reuses the default EthereumPayloadBuilder to build the payload
// but any custom logic can be implemented here
Expand All @@ -326,12 +327,7 @@ where
client,
pool,
cached_reads,
config: PayloadConfig {
parent_block,
extra_data,
attributes: attributes.0,
chain_spec,
},
config: PayloadConfig { parent_block, extra_data, attributes: attributes.0 },
cancel,
best_payload,
})
Expand All @@ -342,9 +338,10 @@ where
client: &Client,
config: PayloadConfig<Self::Attributes>,
) -> Result<Self::BuiltPayload, PayloadBuilderError> {
let PayloadConfig { parent_block, extra_data, attributes, chain_spec } = config;
let PayloadConfig { parent_block, extra_data, attributes } = config;
let chain_spec = client.chain_spec();
<reth_ethereum_payload_builder::EthereumPayloadBuilder as PayloadBuilder<Pool, Client>>::build_empty_payload(&reth_ethereum_payload_builder::EthereumPayloadBuilder::new(EthEvmConfig::new(chain_spec.clone())),client,
PayloadConfig { parent_block, extra_data, attributes: attributes.0, chain_spec })
PayloadConfig { parent_block, extra_data, attributes: attributes.0})
}
}

Expand Down
13 changes: 2 additions & 11 deletions examples/custom-payload-builder/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use reth::{
transaction_pool::TransactionPool,
};
use reth_basic_payload_builder::{BasicPayloadJobGeneratorConfig, PayloadBuilder, PayloadConfig};
use reth_chainspec::ChainSpec;
use reth_node_api::PayloadBuilderAttributes;
use reth_payload_builder::{PayloadBuilderError, PayloadJobGenerator};
use reth_primitives::{BlockNumberOrTag, Bytes};
Expand All @@ -22,8 +21,6 @@ pub struct EmptyBlockPayloadJobGenerator<Client, Pool, Tasks, Builder> {
executor: Tasks,
/// The configuration for the job generator.
_config: BasicPayloadJobGeneratorConfig,
/// The chain spec.
chain_spec: Arc<ChainSpec>,
/// The type responsible for building payloads.
///
/// See [PayloadBuilder]
Expand All @@ -40,10 +37,9 @@ impl<Client, Pool, Tasks, Builder> EmptyBlockPayloadJobGenerator<Client, Pool, T
pool: Pool,
executor: Tasks,
config: BasicPayloadJobGeneratorConfig,
chain_spec: Arc<ChainSpec>,
builder: Builder,
) -> Self {
Self { client, pool, executor, _config: config, builder, chain_spec }
Self { client, pool, executor, _config: config, builder }
}
}

Expand Down Expand Up @@ -80,12 +76,7 @@ where
// we already know the hash, so we can seal it
block.seal(attributes.parent())
};
let config = PayloadConfig::new(
Arc::new(parent_block),
Bytes::default(),
attributes,
Arc::clone(&self.chain_spec),
);
let config = PayloadConfig::new(Arc::new(parent_block), Bytes::default(), attributes);
Ok(EmptyBlockPayloadJob {
client: self.client.clone(),
_pool: self.pool.clone(),
Expand Down
1 change: 0 additions & 1 deletion examples/custom-payload-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ where
pool,
ctx.task_executor().clone(),
payload_job_config,
ctx.chain_spec().clone(),
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(EthEvmConfig::new(
ctx.chain_spec(),
)),
Expand Down

0 comments on commit ab66f58

Please sign in to comment.