mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: extends engine validator (#12900)
This commit is contained in:
@ -17,11 +17,6 @@
|
||||
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
|
||||
use std::{convert::Infallible, sync::Arc};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
use alloy_eips::eip4895::Withdrawals;
|
||||
use alloy_genesis::Genesis;
|
||||
use alloy_primitives::{Address, B256};
|
||||
@ -33,7 +28,7 @@ use alloy_rpc_types::{
|
||||
Withdrawal,
|
||||
};
|
||||
use reth::{
|
||||
api::PayloadTypes,
|
||||
api::{InvalidPayloadAttributesError, PayloadTypes},
|
||||
builder::{
|
||||
components::{ComponentsBuilder, PayloadServiceBuilder},
|
||||
node::{NodeTypes, NodeTypesWithEngine},
|
||||
@ -42,9 +37,13 @@ use reth::{
|
||||
PayloadBuilderConfig,
|
||||
},
|
||||
network::NetworkHandle,
|
||||
primitives::EthPrimitives,
|
||||
payload::ExecutionPayloadValidator,
|
||||
primitives::{Block, EthPrimitives, SealedBlockFor},
|
||||
providers::{CanonStateSubscriptions, EthStorage, StateProviderFactory},
|
||||
rpc::eth::EthApi,
|
||||
rpc::{
|
||||
eth::EthApi,
|
||||
types::engine::{ExecutionPayload, ExecutionPayloadSidecar, PayloadError},
|
||||
},
|
||||
tasks::TaskManager,
|
||||
transaction_pool::TransactionPool,
|
||||
};
|
||||
@ -72,6 +71,9 @@ use reth_payload_builder::{
|
||||
};
|
||||
use reth_tracing::{RethTracer, Tracer};
|
||||
use reth_trie_db::MerklePatriciaTrie;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{convert::Infallible, sync::Arc};
|
||||
use thiserror::Error;
|
||||
|
||||
/// A custom payload attributes type.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@ -171,19 +173,34 @@ impl EngineTypes for CustomEngineTypes {
|
||||
/// Custom engine validator
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CustomEngineValidator {
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
inner: ExecutionPayloadValidator<ChainSpec>,
|
||||
}
|
||||
|
||||
impl CustomEngineValidator {
|
||||
/// Instantiates a new validator.
|
||||
pub const fn new(chain_spec: Arc<ChainSpec>) -> Self {
|
||||
Self { inner: ExecutionPayloadValidator::new(chain_spec) }
|
||||
}
|
||||
|
||||
/// Returns the chain spec used by the validator.
|
||||
#[inline]
|
||||
fn chain_spec(&self) -> &ChainSpec {
|
||||
self.inner.chain_spec()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> EngineValidator<T> for CustomEngineValidator
|
||||
where
|
||||
T: EngineTypes<PayloadAttributes = CustomPayloadAttributes>,
|
||||
{
|
||||
type Block = Block;
|
||||
|
||||
fn validate_version_specific_fields(
|
||||
&self,
|
||||
version: EngineApiMessageVersion,
|
||||
payload_or_attrs: PayloadOrAttributes<'_, T::PayloadAttributes>,
|
||||
) -> Result<(), EngineObjectValidationError> {
|
||||
validate_version_specific_fields(&self.chain_spec, version, payload_or_attrs)
|
||||
validate_version_specific_fields(self.chain_spec(), version, payload_or_attrs)
|
||||
}
|
||||
|
||||
fn ensure_well_formed_attributes(
|
||||
@ -191,7 +208,7 @@ where
|
||||
version: EngineApiMessageVersion,
|
||||
attributes: &T::PayloadAttributes,
|
||||
) -> Result<(), EngineObjectValidationError> {
|
||||
validate_version_specific_fields(&self.chain_spec, version, attributes.into())?;
|
||||
validate_version_specific_fields(self.chain_spec(), version, attributes.into())?;
|
||||
|
||||
// custom validation logic - ensure that the custom field is not zero
|
||||
if attributes.custom == 0 {
|
||||
@ -202,6 +219,23 @@ where
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ensure_well_formed_payload(
|
||||
&self,
|
||||
payload: ExecutionPayload,
|
||||
sidecar: ExecutionPayloadSidecar,
|
||||
) -> Result<SealedBlockFor<Self::Block>, PayloadError> {
|
||||
self.inner.ensure_well_formed_payload(payload, sidecar)
|
||||
}
|
||||
|
||||
fn validate_payload_attributes_against_header(
|
||||
&self,
|
||||
_attr: &<T as PayloadTypes>::PayloadAttributes,
|
||||
_header: &<Self::Block as reth::api::Block>::Header,
|
||||
) -> Result<(), InvalidPayloadAttributesError> {
|
||||
// skip default timestamp validation
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Custom engine validator builder
|
||||
@ -218,7 +252,7 @@ where
|
||||
type Validator = CustomEngineValidator;
|
||||
|
||||
async fn build(self, ctx: &AddOnsContext<'_, N>) -> eyre::Result<Self::Validator> {
|
||||
Ok(CustomEngineValidator { chain_spec: ctx.config.chain.clone() })
|
||||
Ok(CustomEngineValidator::new(ctx.config.chain.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user