Skip to main content

tempo_node/
engine.rs

1use crate::{TempoExecutionData, TempoPayloadTypes};
2use reth_node_api::{InvalidPayloadAttributesError, NewPayloadError, PayloadValidator};
3use reth_primitives_traits::{AlloyBlockHeader as _, SealedBlock};
4use std::sync::Arc;
5use tempo_payload_types::TempoPayloadAttributes;
6use tempo_primitives::{Block, TempoHeader};
7
8/// Type encapsulating Tempo engine validation logic.
9#[derive(Debug, Default, Clone, Copy)]
10#[non_exhaustive]
11pub struct TempoEngineValidator;
12
13impl TempoEngineValidator {
14    /// Creates a new [`TempoEngineValidator`] with the given chain spec.
15    pub fn new() -> Self {
16        Self {}
17    }
18}
19
20impl PayloadValidator<TempoPayloadTypes> for TempoEngineValidator {
21    type Block = Block;
22
23    fn convert_payload_to_block(
24        &self,
25        payload: TempoExecutionData,
26    ) -> Result<SealedBlock<Self::Block>, NewPayloadError> {
27        let TempoExecutionData {
28            block,
29            block_access_list: _,
30            validator_set: _,
31        } = payload;
32        Ok(Arc::unwrap_or_clone(block))
33    }
34
35    fn validate_payload_attributes_against_header(
36        &self,
37        attr: &TempoPayloadAttributes,
38        header: &TempoHeader,
39    ) -> Result<(), InvalidPayloadAttributesError> {
40        // Ensure that payload attributes timestamp is not in the past
41        if attr.timestamp < header.timestamp() {
42            return Err(InvalidPayloadAttributesError::InvalidTimestamp);
43        }
44        Ok(())
45    }
46}