Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reorder validation items #12503

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 55 additions & 54 deletions crates/rpc/rpc/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,60 +30,6 @@ use serde::{Deserialize, Serialize};
use std::{collections::HashSet, sync::Arc};
use tokio::sync::RwLock;

/// Configuration for validation API.
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct ValidationApiConfig {
/// Disallowed addresses.
pub disallow: HashSet<Address>,
}

#[derive(Debug, thiserror::Error)]
pub enum ValidationApiError {
#[error("block gas limit mismatch: {_0}")]
GasLimitMismatch(GotExpected<u64>),
#[error("block gas used mismatch: {_0}")]
GasUsedMismatch(GotExpected<u64>),
#[error("block parent hash mismatch: {_0}")]
ParentHashMismatch(GotExpected<B256>),
#[error("block hash mismatch: {_0}")]
BlockHashMismatch(GotExpected<B256>),
#[error("missing latest block in database")]
MissingLatestBlock,
#[error("could not verify proposer payment")]
ProposerPayment,
#[error("invalid blobs bundle")]
InvalidBlobsBundle,
#[error("block accesses blacklisted address: {_0}")]
Blacklist(Address),
#[error(transparent)]
Blob(#[from] BlobTransactionValidationError),
#[error(transparent)]
Consensus(#[from] ConsensusError),
#[error(transparent)]
Provider(#[from] ProviderError),
#[error(transparent)]
Execution(#[from] BlockExecutionError),
}

#[derive(Debug)]
pub struct ValidationApiInner<Provider: ChainSpecProvider, E> {
/// The provider that can interact with the chain.
provider: Provider,
/// Consensus implementation.
consensus: Arc<dyn Consensus>,
/// Execution payload validator.
payload_validator: ExecutionPayloadValidator<Provider::ChainSpec>,
/// Block executor factory.
executor_provider: E,
/// Set of disallowed addresses
disallow: HashSet<Address>,
/// Cached state reads to avoid redundant disk I/O across multiple validation attempts
/// targeting the same state. Stores a tuple of (`block_hash`, `cached_reads`) for the
/// latest head block state. Uses async `RwLock` to safely handle concurrent validation
/// requests.
cached_state: RwLock<(B256, CachedReads)>,
}

/// The type that implements the `validation` rpc namespace trait
#[derive(Debug, derive_more::Deref)]
pub struct ValidationApi<Provider: ChainSpecProvider, E> {
Expand Down Expand Up @@ -486,3 +432,58 @@ where
.to_rpc_result()
}
}

#[derive(Debug)]
pub struct ValidationApiInner<Provider: ChainSpecProvider, E> {
/// The provider that can interact with the chain.
provider: Provider,
/// Consensus implementation.
consensus: Arc<dyn Consensus>,
/// Execution payload validator.
payload_validator: ExecutionPayloadValidator<Provider::ChainSpec>,
/// Block executor factory.
executor_provider: E,
/// Set of disallowed addresses
disallow: HashSet<Address>,
/// Cached state reads to avoid redundant disk I/O across multiple validation attempts
/// targeting the same state. Stores a tuple of (`block_hash`, `cached_reads`) for the
/// latest head block state. Uses async `RwLock` to safely handle concurrent validation
/// requests.
cached_state: RwLock<(B256, CachedReads)>,
}

/// Configuration for validation API.
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct ValidationApiConfig {
/// Disallowed addresses.
pub disallow: HashSet<Address>,
}

/// Errors thrown by the validation API.
#[derive(Debug, thiserror::Error)]
pub enum ValidationApiError {
#[error("block gas limit mismatch: {_0}")]
GasLimitMismatch(GotExpected<u64>),
#[error("block gas used mismatch: {_0}")]
GasUsedMismatch(GotExpected<u64>),
#[error("block parent hash mismatch: {_0}")]
ParentHashMismatch(GotExpected<B256>),
#[error("block hash mismatch: {_0}")]
BlockHashMismatch(GotExpected<B256>),
#[error("missing latest block in database")]
MissingLatestBlock,
#[error("could not verify proposer payment")]
ProposerPayment,
#[error("invalid blobs bundle")]
InvalidBlobsBundle,
#[error("block accesses blacklisted address: {_0}")]
Blacklist(Address),
#[error(transparent)]
Blob(#[from] BlobTransactionValidationError),
#[error(transparent)]
Consensus(#[from] ConsensusError),
#[error(transparent)]
Provider(#[from] ProviderError),
#[error(transparent)]
Execution(#[from] BlockExecutionError),
}
Loading