reth_engine_local/
payload.rs

1//! The implementation of the [`PayloadAttributesBuilder`] for the
2//! [`LocalMiner`](super::LocalMiner).
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    /// The chainspec
15    pub chain_spec: Arc<ChainSpec>,
16}
17
18impl<ChainSpec> LocalPayloadAttributesBuilder<ChainSpec> {
19    /// Creates a new instance of the builder.
20    pub const fn new(chain_spec: Arc<ChainSpec>) -> Self {
21        Self { chain_spec }
22    }
23}
24
25impl<ChainSpec> PayloadAttributesBuilder<EthPayloadAttributes>
26    for LocalPayloadAttributesBuilder<ChainSpec>
27where
28    ChainSpec: Send + Sync + EthereumHardforks + 'static,
29{
30    fn build(&self, timestamp: u64) -> EthPayloadAttributes {
31        EthPayloadAttributes {
32            timestamp,
33            prev_randao: B256::random(),
34            suggested_fee_recipient: Address::random(),
35            withdrawals: self
36                .chain_spec
37                .is_shanghai_active_at_timestamp(timestamp)
38                .then(Default::default),
39            parent_beacon_block_root: self
40                .chain_spec
41                .is_cancun_active_at_timestamp(timestamp)
42                .then(B256::random),
43        }
44    }
45}
46
47#[cfg(feature = "op")]
48impl<ChainSpec> PayloadAttributesBuilder<op_alloy_rpc_types_engine::OpPayloadAttributes>
49    for LocalPayloadAttributesBuilder<ChainSpec>
50where
51    ChainSpec: Send + Sync + EthereumHardforks + 'static,
52{
53    fn build(&self, timestamp: u64) -> op_alloy_rpc_types_engine::OpPayloadAttributes {
54        op_alloy_rpc_types_engine::OpPayloadAttributes {
55            payload_attributes: self.build(timestamp),
56            // Add dummy system transaction
57            transactions: Some(vec![
58                reth_optimism_chainspec::constants::TX_SET_L1_BLOCK_OP_MAINNET_BLOCK_124665056
59                    .into(),
60            ]),
61            no_tx_pool: None,
62            gas_limit: None,
63            eip_1559_params: None,
64        }
65    }
66}