feat: integrate request validation in EnginveValidator (#13858)

Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com>
This commit is contained in:
DevOrbitlabs
2025-01-23 23:11:30 +07:00
committed by GitHub
parent 187634fd2f
commit 9039909a78
11 changed files with 47 additions and 29 deletions

3
Cargo.lock generated
View File

@ -7109,6 +7109,7 @@ name = "reth-engine-primitives"
version = "1.1.5" version = "1.1.5"
dependencies = [ dependencies = [
"alloy-consensus", "alloy-consensus",
"alloy-eips",
"alloy-primitives", "alloy-primitives",
"alloy-rpc-types-engine", "alloy-rpc-types-engine",
"futures", "futures",
@ -7228,6 +7229,7 @@ dependencies = [
"reth-ethereum-forks", "reth-ethereum-forks",
"reth-evm", "reth-evm",
"reth-fs-util", "reth-fs-util",
"reth-payload-primitives",
"reth-payload-validator", "reth-payload-validator",
"reth-primitives", "reth-primitives",
"reth-primitives-traits", "reth-primitives-traits",
@ -8129,6 +8131,7 @@ dependencies = [
"reth-chainspec", "reth-chainspec",
"reth-db-api", "reth-db-api",
"reth-engine-primitives", "reth-engine-primitives",
"reth-payload-primitives",
"reth-primitives-traits", "reth-primitives-traits",
"reth-trie-db", "reth-trie-db",
] ]

View File

@ -5,10 +5,12 @@ use alloy_primitives::{TxHash, B256};
use alloy_rpc_types_engine::ForkchoiceState; use alloy_rpc_types_engine::ForkchoiceState;
use eyre::OptionExt; use eyre::OptionExt;
use futures_util::{stream::Fuse, StreamExt}; use futures_util::{stream::Fuse, StreamExt};
use reth_engine_primitives::{BeaconEngineMessage, EngineApiMessageVersion, EngineTypes}; use reth_engine_primitives::{BeaconEngineMessage, EngineTypes};
use reth_payload_builder::PayloadBuilderHandle; use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_builder_primitives::PayloadBuilder; use reth_payload_builder_primitives::PayloadBuilder;
use reth_payload_primitives::{BuiltPayload, PayloadAttributesBuilder, PayloadKind, PayloadTypes}; use reth_payload_primitives::{
BuiltPayload, EngineApiMessageVersion, PayloadAttributesBuilder, PayloadKind, PayloadTypes,
};
use reth_provider::BlockReader; use reth_provider::BlockReader;
use reth_transaction_pool::TransactionPool; use reth_transaction_pool::TransactionPool;
use std::{ use std::{

View File

@ -24,6 +24,7 @@ reth-errors.workspace = true
alloy-primitives.workspace = true alloy-primitives.workspace = true
alloy-consensus.workspace = true alloy-consensus.workspace = true
alloy-rpc-types-engine.workspace = true alloy-rpc-types-engine.workspace = true
alloy-eips.workspace = true
# async # async
tokio = { workspace = true, features = ["sync"] } tokio = { workspace = true, features = ["sync"] }
@ -36,13 +37,14 @@ thiserror.workspace = true
[features] [features]
default = ["std"] default = ["std"]
std = [ std = [
"reth-execution-types/std", "reth-execution-types/std",
"reth-primitives/std", "reth-primitives/std",
"reth-primitives-traits/std", "reth-primitives-traits/std",
"alloy-primitives/std", "alloy-primitives/std",
"alloy-consensus/std", "alloy-consensus/std",
"alloy-rpc-types-engine/std", "alloy-rpc-types-engine/std",
"futures/std", "futures/std",
"serde/std", "serde/std",
"thiserror/std", "thiserror/std",
"alloy-eips/std"
] ]

View File

@ -11,6 +11,7 @@
extern crate alloc; extern crate alloc;
use reth_payload_primitives::{BuiltPayload, PayloadAttributes};
mod error; mod error;
use core::fmt; use core::fmt;
@ -31,15 +32,16 @@ pub use event::*;
mod invalid_block_hook; mod invalid_block_hook;
pub use invalid_block_hook::InvalidBlockHook; pub use invalid_block_hook::InvalidBlockHook;
pub use reth_payload_primitives::{ use reth_payload_primitives::{
BuiltPayload, EngineApiMessageVersion, EngineObjectValidationError, PayloadOrAttributes, validate_execution_requests, EngineApiMessageVersion, EngineObjectValidationError,
PayloadTypes, InvalidPayloadAttributesError, PayloadOrAttributes, PayloadTypes,
}; };
use reth_payload_primitives::{InvalidPayloadAttributesError, PayloadAttributes};
use reth_primitives::{NodePrimitives, SealedBlock}; use reth_primitives::{NodePrimitives, SealedBlock};
use reth_primitives_traits::Block; use reth_primitives_traits::Block;
use serde::{de::DeserializeOwned, ser::Serialize}; use serde::{de::DeserializeOwned, ser::Serialize};
use alloy_eips::eip7685::Requests;
/// This type defines the versioned types of the engine API. /// This type defines the versioned types of the engine API.
/// ///
/// This includes the execution payload types and payload attributes that are used to trigger a /// This includes the execution payload types and payload attributes that are used to trigger a
@ -117,6 +119,14 @@ pub trait PayloadValidator: fmt::Debug + Send + Sync + Unpin + 'static {
/// Type that validates the payloads processed by the engine. /// Type that validates the payloads processed by the engine.
pub trait EngineValidator<Types: EngineTypes>: PayloadValidator { pub trait EngineValidator<Types: EngineTypes>: PayloadValidator {
/// Validates the execution requests according to [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685).
fn validate_execution_requests(
&self,
requests: &Requests,
) -> Result<(), EngineObjectValidationError> {
validate_execution_requests(requests)
}
/// Validates the presence or exclusion of fork-specific fields based on the payload attributes /// Validates the presence or exclusion of fork-specific fields based on the payload attributes
/// and the message version. /// and the message version.
fn validate_version_specific_fields( fn validate_version_specific_fields(

View File

@ -26,9 +26,8 @@ use reth_chain_state::{
use reth_consensus::{Consensus, FullConsensus, PostExecutionInput}; use reth_consensus::{Consensus, FullConsensus, PostExecutionInput};
pub use reth_engine_primitives::InvalidBlockHook; pub use reth_engine_primitives::InvalidBlockHook;
use reth_engine_primitives::{ use reth_engine_primitives::{
BeaconConsensusEngineEvent, BeaconEngineMessage, BeaconOnNewPayloadError, BeaconConsensusEngineEvent, BeaconEngineMessage, BeaconOnNewPayloadError, EngineTypes,
EngineApiMessageVersion, EngineTypes, EngineValidator, ForkchoiceStateTracker, EngineValidator, ForkchoiceStateTracker, OnForkChoiceUpdated,
OnForkChoiceUpdated,
}; };
use reth_errors::{ConsensusError, ProviderResult}; use reth_errors::{ConsensusError, ProviderResult};
use reth_evm::{ use reth_evm::{
@ -37,7 +36,7 @@ use reth_evm::{
}; };
use reth_payload_builder::PayloadBuilderHandle; use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_builder_primitives::PayloadBuilder; use reth_payload_builder_primitives::PayloadBuilder;
use reth_payload_primitives::PayloadBuilderAttributes; use reth_payload_primitives::{EngineApiMessageVersion, PayloadBuilderAttributes};
use reth_primitives::{ use reth_primitives::{
EthPrimitives, GotExpected, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader, EthPrimitives, GotExpected, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader,
}; };

View File

@ -26,6 +26,7 @@ reth-provider.workspace = true
reth-ethereum-forks.workspace = true reth-ethereum-forks.workspace = true
revm-primitives.workspace = true revm-primitives.workspace = true
reth-trie.workspace = true reth-trie.workspace = true
reth-payload-primitives.workspace = true
# alloy # alloy
alloy-eips.workspace = true alloy-eips.workspace = true

View File

@ -8,8 +8,7 @@ use alloy_rpc_types_engine::{
use futures::{stream::FuturesUnordered, Stream, StreamExt, TryFutureExt}; use futures::{stream::FuturesUnordered, Stream, StreamExt, TryFutureExt};
use itertools::Either; use itertools::Either;
use reth_engine_primitives::{ use reth_engine_primitives::{
BeaconEngineMessage, BeaconOnNewPayloadError, EngineApiMessageVersion, EngineTypes, BeaconEngineMessage, BeaconOnNewPayloadError, EngineTypes, OnForkChoiceUpdated,
OnForkChoiceUpdated,
}; };
use reth_errors::{BlockExecutionError, BlockValidationError, RethError, RethResult}; use reth_errors::{BlockExecutionError, BlockValidationError, RethError, RethResult};
use reth_ethereum_forks::EthereumHardforks; use reth_ethereum_forks::EthereumHardforks;
@ -17,6 +16,7 @@ use reth_evm::{
state_change::post_block_withdrawals_balance_increments, system_calls::SystemCaller, state_change::post_block_withdrawals_balance_increments, system_calls::SystemCaller,
ConfigureEvm, Evm, ConfigureEvm, Evm,
}; };
use reth_payload_primitives::EngineApiMessageVersion;
use reth_payload_validator::ExecutionPayloadValidator; use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{ use reth_primitives::{
transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt, Receipts, transaction::SignedTransactionIntoRecoveredExt, Block, BlockBody, Receipt, Receipts,

View File

@ -20,10 +20,10 @@ pub use alloy_rpc_types_engine::{
}; };
pub use payload::{EthBuiltPayload, EthPayloadBuilderAttributes}; pub use payload::{EthBuiltPayload, EthPayloadBuilderAttributes};
use reth_chainspec::ChainSpec; use reth_chainspec::ChainSpec;
use reth_engine_primitives::{BuiltPayload, EngineTypes, EngineValidator, PayloadValidator}; use reth_engine_primitives::{EngineTypes, EngineValidator, PayloadValidator};
use reth_payload_primitives::{ use reth_payload_primitives::{
validate_version_specific_fields, EngineApiMessageVersion, EngineObjectValidationError, validate_version_specific_fields, BuiltPayload, EngineApiMessageVersion,
PayloadOrAttributes, PayloadTypes, EngineObjectValidationError, PayloadOrAttributes, PayloadTypes,
}; };
use reth_payload_validator::ExecutionPayloadValidator; use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{Block, NodePrimitives, SealedBlock}; use reth_primitives::{Block, NodePrimitives, SealedBlock};

View File

@ -17,6 +17,7 @@ reth-db-api.workspace = true
reth-engine-primitives.workspace = true reth-engine-primitives.workspace = true
reth-primitives-traits.workspace = true reth-primitives-traits.workspace = true
reth-trie-db.workspace = true reth-trie-db.workspace = true
reth-payload-primitives.workspace = true
[features] [features]
default = ["std"] default = ["std"]

View File

@ -19,7 +19,8 @@ use reth_db_api::{
database_metrics::{DatabaseMetadata, DatabaseMetrics}, database_metrics::{DatabaseMetadata, DatabaseMetrics},
Database, Database,
}; };
use reth_engine_primitives::{BuiltPayload, EngineTypes}; use reth_engine_primitives::EngineTypes;
use reth_payload_primitives::BuiltPayload;
use reth_trie_db::StateCommitment; use reth_trie_db::StateCommitment;
/// The type that configures the essential types of an Ethereum-like node. /// The type that configures the essential types of an Ethereum-like node.

View File

@ -20,8 +20,8 @@ use reth_chainspec::{EthereumHardfork, EthereumHardforks};
use reth_engine_primitives::{BeaconConsensusEngineHandle, EngineTypes, EngineValidator}; use reth_engine_primitives::{BeaconConsensusEngineHandle, EngineTypes, EngineValidator};
use reth_payload_builder::PayloadStore; use reth_payload_builder::PayloadStore;
use reth_payload_primitives::{ use reth_payload_primitives::{
validate_execution_requests, validate_payload_timestamp, EngineApiMessageVersion, validate_payload_timestamp, EngineApiMessageVersion, PayloadBuilderAttributes,
PayloadBuilderAttributes, PayloadOrAttributes, PayloadOrAttributes,
}; };
use reth_rpc_api::EngineApiServer; use reth_rpc_api::EngineApiServer;
use reth_rpc_types_compat::engine::payload::convert_to_payload_body_v1; use reth_rpc_types_compat::engine::payload::convert_to_payload_body_v1;
@ -268,8 +268,7 @@ where
.validator .validator
.validate_version_specific_fields(EngineApiMessageVersion::V4, payload_or_attrs)?; .validate_version_specific_fields(EngineApiMessageVersion::V4, payload_or_attrs)?;
validate_execution_requests(&execution_requests)?; self.inner.validator.validate_execution_requests(&execution_requests)?;
Ok(self Ok(self
.inner .inner
.beacon_consensus .beacon_consensus