reth_engine_local/
payload.rs

1//! The implementation of the [`PayloadAttributesBuilder`] for the
2//! [`LocalEngineService`](super::service::LocalEngineService).
3
4use alloy_primitives::{Address, B256};
5use reth_chainspec::EthereumHardforks;
6use reth_ethereum_engine_primitives::EthPayloadAttributes;
7use reth_payload_primitives::PayloadAttributesBuilder;
8use std::sync::Arc;
9
10/// The attributes builder for local Ethereum payload.
11#[derive(Debug)]
12#[non_exhaustive]
13pub struct LocalPayloadAttributesBuilder<ChainSpec> {
14    chain_spec: Arc<ChainSpec>,
15}
16
17impl<ChainSpec> LocalPayloadAttributesBuilder<ChainSpec> {
18    /// Creates a new instance of the builder.
19    pub const fn new(chain_spec: Arc<ChainSpec>) -> Self {
20        Self { chain_spec }
21    }
22}
23
24impl<ChainSpec> PayloadAttributesBuilder<EthPayloadAttributes>
25    for LocalPayloadAttributesBuilder<ChainSpec>
26where
27    ChainSpec: Send + Sync + EthereumHardforks + 'static,
28{
29    fn build(&self, timestamp: u64) -> EthPayloadAttributes {
30        EthPayloadAttributes {
31            timestamp,
32            prev_randao: B256::random(),
33            suggested_fee_recipient: Address::random(),
34            withdrawals: self
35                .chain_spec
36                .is_shanghai_active_at_timestamp(timestamp)
37                .then(Default::default),
38            parent_beacon_block_root: self
39                .chain_spec
40                .is_cancun_active_at_timestamp(timestamp)
41                .then(B256::random),
42            target_blobs_per_block: None,
43            max_blobs_per_block: None,
44        }
45    }
46}
47
48#[cfg(feature = "optimism")]
49impl<ChainSpec> PayloadAttributesBuilder<op_alloy_rpc_types_engine::OpPayloadAttributes>
50    for LocalPayloadAttributesBuilder<ChainSpec>
51where
52    ChainSpec: Send + Sync + EthereumHardforks + 'static,
53{
54    fn build(&self, timestamp: u64) -> op_alloy_rpc_types_engine::OpPayloadAttributes {
55        op_alloy_rpc_types_engine::OpPayloadAttributes {
56            payload_attributes: self.build(timestamp),
57            transactions: None,
58            no_tx_pool: None,
59            gas_limit: None,
60            eip_1559_params: None,
61        }
62    }
63}