chore(payload): Custom PayloadError variant (#14607)

This commit is contained in:
Emilia Hane
2025-02-20 12:45:34 +01:00
committed by GitHub
parent 246a9ffb20
commit f03e7e02f7
7 changed files with 64 additions and 25 deletions

View File

@ -1,8 +1,9 @@
//! Error types emitted by types or implementations of this crate.
use alloc::boxed::Box;
use alloc::{boxed::Box, string::ToString};
use alloy_primitives::B256;
use alloy_rpc_types_engine::ForkchoiceUpdateError;
use alloy_rpc_types_engine::{ForkchoiceUpdateError, PayloadError, PayloadStatusEnum};
use core::error;
use reth_errors::{ProviderError, RethError};
use tokio::sync::oneshot;
@ -115,6 +116,45 @@ pub enum VersionSpecificValidationError {
NoParentBeaconBlockRootPostCancun,
}
/// Error validating payload received over `newPayload` API.
#[derive(thiserror::Error, Debug)]
pub enum NewPayloadError {
/// Payload validation error.
#[error(transparent)]
Eth(#[from] PayloadError),
/// Custom payload validation error.
#[error(transparent)]
Other(Box<dyn error::Error + Send + Sync>),
}
impl NewPayloadError {
/// Creates instance of variant [`NewPayloadError::Other`].
#[inline]
pub const fn other(err: Box<dyn error::Error + Send + Sync>) -> Self {
Self::Other(err)
}
}
impl NewPayloadError {
/// Returns `true` if the error is caused by a block hash mismatch.
#[inline]
pub const fn is_block_hash_mismatch(&self) -> bool {
matches!(self, Self::Eth(PayloadError::BlockHash { .. }))
}
/// Returns `true` if the error is caused by invalid block hashes (Cancun).
#[inline]
pub const fn is_invalid_versioned_hashes(&self) -> bool {
matches!(self, Self::Eth(PayloadError::InvalidVersionedHashes))
}
}
impl From<NewPayloadError> for PayloadStatusEnum {
fn from(error: NewPayloadError) -> Self {
Self::Invalid { validation_error: error.to_string() }
}
}
impl EngineObjectValidationError {
/// Creates an instance of the `InvalidParams` variant with the given error.
pub fn invalid_params<E>(error: E) -> Self

View File

@ -17,8 +17,8 @@ use reth_chainspec::EthereumHardforks;
mod error;
pub use error::{
EngineObjectValidationError, InvalidPayloadAttributesError, PayloadBuilderError,
VersionSpecificValidationError,
EngineObjectValidationError, InvalidPayloadAttributesError, NewPayloadError,
PayloadBuilderError, VersionSpecificValidationError,
};
/// Contains traits to abstract over payload attributes types and default implementations of the