Skip to main content

tempo_payload_types/
lib.rs

1//! Tempo payload types.
2
3#![cfg_attr(not(test), warn(unused_crate_dependencies))]
4#![cfg_attr(docsrs, feature(doc_cfg))]
5
6mod attrs;
7
8use alloy_primitives::B256;
9pub use attrs::{InterruptHandle, TempoPayloadAttributes, TempoPayloadBuilderAttributes};
10use std::sync::Arc;
11
12use alloy_eips::eip7685::Requests;
13use alloy_primitives::U256;
14use alloy_rpc_types_eth::Withdrawal;
15use reth_ethereum_engine_primitives::EthBuiltPayload;
16use reth_node_api::{BlockBody, ExecutionPayload, PayloadBuilderAttributes, PayloadTypes};
17use reth_payload_primitives::{BuiltPayload, BuiltPayloadExecutedBlock};
18use reth_primitives_traits::{AlloyBlockHeader as _, SealedBlock};
19use serde::{Deserialize, Serialize};
20use tempo_primitives::{Block, TempoPrimitives};
21
22/// Payload types for Tempo node.
23#[derive(Debug, Clone, Copy, Default)]
24#[non_exhaustive]
25pub struct TempoPayloadTypes;
26
27/// Built payload type for Tempo node.
28///
29/// Wraps [`EthBuiltPayload`] and optionally includes the executed block data
30/// to enable the engine tree fast path (skipping re-execution for self-built payloads).
31#[derive(Debug, Clone)]
32pub struct TempoBuiltPayload {
33    /// The inner built payload.
34    inner: EthBuiltPayload<TempoPrimitives>,
35    /// The executed block data, used to skip re-execution in the engine tree.
36    executed_block: Option<BuiltPayloadExecutedBlock<TempoPrimitives>>,
37}
38
39impl TempoBuiltPayload {
40    /// Creates a new [`TempoBuiltPayload`].
41    pub fn new(
42        inner: EthBuiltPayload<TempoPrimitives>,
43        executed_block: Option<BuiltPayloadExecutedBlock<TempoPrimitives>>,
44    ) -> Self {
45        Self {
46            inner,
47            executed_block,
48        }
49    }
50}
51
52impl BuiltPayload for TempoBuiltPayload {
53    type Primitives = TempoPrimitives;
54
55    fn block(&self) -> &SealedBlock<Block> {
56        self.inner.block()
57    }
58
59    fn fees(&self) -> U256 {
60        self.inner.fees()
61    }
62
63    fn executed_block(&self) -> Option<BuiltPayloadExecutedBlock<Self::Primitives>> {
64        self.executed_block.clone()
65    }
66
67    fn requests(&self) -> Option<Requests> {
68        self.inner.requests()
69    }
70}
71
72/// Execution data for Tempo node. Simply wraps a sealed block.
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct TempoExecutionData {
75    /// The built block.
76    pub block: Arc<SealedBlock<Block>>,
77    /// Validator set active at the time this block was built.
78    pub validator_set: Option<Vec<B256>>,
79}
80
81impl ExecutionPayload for TempoExecutionData {
82    fn parent_hash(&self) -> alloy_primitives::B256 {
83        self.block.parent_hash()
84    }
85
86    fn block_hash(&self) -> alloy_primitives::B256 {
87        self.block.hash()
88    }
89
90    fn block_number(&self) -> u64 {
91        self.block.number()
92    }
93
94    fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
95        self.block
96            .body()
97            .withdrawals
98            .as_ref()
99            .map(|withdrawals| &withdrawals.0)
100    }
101
102    fn parent_beacon_block_root(&self) -> Option<alloy_primitives::B256> {
103        self.block.parent_beacon_block_root()
104    }
105
106    fn timestamp(&self) -> u64 {
107        self.block.timestamp()
108    }
109
110    fn transaction_count(&self) -> usize {
111        self.block.body().transaction_count()
112    }
113
114    fn gas_used(&self) -> u64 {
115        self.block.gas_used()
116    }
117
118    fn block_access_list(&self) -> Option<&alloy_primitives::Bytes> {
119        None
120    }
121}
122
123impl PayloadTypes for TempoPayloadTypes {
124    type ExecutionData = TempoExecutionData;
125    type BuiltPayload = TempoBuiltPayload;
126    type PayloadAttributes =
127        <Self::PayloadBuilderAttributes as PayloadBuilderAttributes>::RpcPayloadAttributes;
128    type PayloadBuilderAttributes = TempoPayloadBuilderAttributes;
129
130    fn block_to_payload(block: SealedBlock<Block>) -> Self::ExecutionData {
131        TempoExecutionData {
132            block: Arc::new(block),
133            validator_set: None,
134        }
135    }
136}