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};
10
11use alloy_rpc_types_eth::Withdrawal;
12use reth_ethereum_engine_primitives::EthBuiltPayload;
13use reth_node_api::{ExecutionPayload, PayloadBuilderAttributes, PayloadTypes};
14use reth_primitives_traits::{AlloyBlockHeader as _, SealedBlock};
15use serde::{Deserialize, Serialize};
16use tempo_primitives::{Block, TempoPrimitives};
17
18/// Payload types for Tempo node.
19#[derive(Debug, Clone, Copy, Default)]
20#[non_exhaustive]
21pub struct TempoPayloadTypes;
22
23/// Execution data for Tempo node. Simply wraps a sealed block.
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct TempoExecutionData {
26    /// The built block.
27    pub block: SealedBlock<Block>,
28    /// Validator set active at the time this block was built.
29    pub validator_set: Option<Vec<B256>>,
30}
31
32impl ExecutionPayload for TempoExecutionData {
33    fn parent_hash(&self) -> alloy_primitives::B256 {
34        self.block.parent_hash()
35    }
36
37    fn block_hash(&self) -> alloy_primitives::B256 {
38        self.block.hash()
39    }
40
41    fn block_number(&self) -> u64 {
42        self.block.number()
43    }
44
45    fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
46        self.block
47            .body()
48            .withdrawals
49            .as_ref()
50            .map(|withdrawals| &withdrawals.0)
51    }
52
53    fn parent_beacon_block_root(&self) -> Option<alloy_primitives::B256> {
54        self.block.parent_beacon_block_root()
55    }
56
57    fn timestamp(&self) -> u64 {
58        self.block.timestamp()
59    }
60
61    fn gas_used(&self) -> u64 {
62        self.block.gas_used()
63    }
64}
65
66impl PayloadTypes for TempoPayloadTypes {
67    type ExecutionData = TempoExecutionData;
68    type BuiltPayload = EthBuiltPayload<TempoPrimitives>;
69    type PayloadAttributes =
70        <Self::PayloadBuilderAttributes as PayloadBuilderAttributes>::RpcPayloadAttributes;
71    type PayloadBuilderAttributes = TempoPayloadBuilderAttributes;
72
73    fn block_to_payload(block: SealedBlock<Block>) -> Self::ExecutionData {
74        TempoExecutionData {
75            block,
76            validator_set: None,
77        }
78    }
79}