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            validator_set: _,
30        } = payload;
31        Ok(Arc::unwrap_or_clone(block))
32    }
33
34    fn validate_payload_attributes_against_header(
35        &self,
36        attr: &TempoPayloadAttributes,
37        header: &TempoHeader,
38    ) -> Result<(), InvalidPayloadAttributesError> {
39        // Ensure that payload attributes timestamp is not in the past
40        if attr.inner.timestamp < header.timestamp() {
41            return Err(InvalidPayloadAttributesError::InvalidTimestamp);
42        }
43        Ok(())
44    }
45}