reth_engine_local/
payload.rs
1use 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#[derive(Debug)]
12#[non_exhaustive]
13pub struct LocalPayloadAttributesBuilder<ChainSpec> {
14 chain_spec: Arc<ChainSpec>,
15}
16
17impl<ChainSpec> LocalPayloadAttributesBuilder<ChainSpec> {
18 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 }
43 }
44}
45
46#[cfg(feature = "op")]
47impl<ChainSpec> PayloadAttributesBuilder<op_alloy_rpc_types_engine::OpPayloadAttributes>
48 for LocalPayloadAttributesBuilder<ChainSpec>
49where
50 ChainSpec: Send + Sync + EthereumHardforks + 'static,
51{
52 fn build(&self, timestamp: u64) -> op_alloy_rpc_types_engine::OpPayloadAttributes {
53 op_alloy_rpc_types_engine::OpPayloadAttributes {
54 payload_attributes: self.build(timestamp),
55 transactions: Some(vec![
57 reth_optimism_chainspec::constants::TX_SET_L1_BLOCK_OP_MAINNET_BLOCK_124665056
58 .into(),
59 ]),
60 no_tx_pool: None,
61 gas_limit: None,
62 eip_1559_params: None,
63 }
64 }
65}
66
67pub trait UnsupportedLocalAttributes: Send + Sync + 'static {}
72
73impl<T, ChainSpec> PayloadAttributesBuilder<T> for LocalPayloadAttributesBuilder<ChainSpec>
74where
75 ChainSpec: Send + Sync + 'static,
76 T: UnsupportedLocalAttributes,
77{
78 fn build(&self, _: u64) -> T {
79 panic!("Unsupported payload attributes")
80 }
81}