feat: fix WASM build for crates dependent on reth-payload-primitives (#12610)

This commit is contained in:
Federico Gimenez
2024-11-17 11:26:15 +01:00
committed by GitHub
parent bf92a5fb59
commit 2f3fde8fb5
10 changed files with 69 additions and 83 deletions

View File

@ -13,13 +13,9 @@ workspace = true
[dependencies]
# reth
reth-errors.workspace = true
reth-payload-primitives.workspace = true
reth-transaction-pool.workspace = true
revm-primitives.workspace = true
# alloy
alloy-primitives.workspace = true
alloy-rpc-types-engine = { workspace = true, features = ["serde"] }
# async
@ -29,5 +25,4 @@ tokio = { workspace = true, features = ["sync"] }
tokio-stream.workspace = true
# misc
thiserror.workspace = true
tracing.workspace = true

View File

@ -1,58 +0,0 @@
//! Error types emitted by types or implementations of this crate.
use alloy_primitives::B256;
use reth_errors::{ProviderError, RethError};
use reth_transaction_pool::BlobStoreError;
use revm_primitives::EVMError;
use tokio::sync::oneshot;
/// Possible error variants during payload building.
#[derive(Debug, thiserror::Error)]
pub enum PayloadBuilderError {
/// Thrown when the parent header cannot be found
#[error("missing parent header: {0}")]
MissingParentHeader(B256),
/// Thrown when the parent block is missing.
#[error("missing parent block {0}")]
MissingParentBlock(B256),
/// An oneshot channels has been closed.
#[error("sender has been dropped")]
ChannelClosed,
/// If there's no payload to resolve.
#[error("missing payload")]
MissingPayload,
/// Error occurring in the blob store.
#[error(transparent)]
BlobStore(#[from] BlobStoreError),
/// Other internal error
#[error(transparent)]
Internal(#[from] RethError),
/// Unrecoverable error during evm execution.
#[error("evm execution error: {0}")]
EvmExecutionError(EVMError<ProviderError>),
/// Any other payload building errors.
#[error(transparent)]
Other(Box<dyn core::error::Error + Send + Sync>),
}
impl PayloadBuilderError {
/// Create a new error from a boxed error.
pub fn other<E>(error: E) -> Self
where
E: core::error::Error + Send + Sync + 'static,
{
Self::Other(Box::new(error))
}
}
impl From<ProviderError> for PayloadBuilderError {
fn from(error: ProviderError) -> Self {
Self::Internal(RethError::Provider(error))
}
}
impl From<oneshot::error::RecvError> for PayloadBuilderError {
fn from(_: oneshot::error::RecvError) -> Self {
Self::ChannelClosed
}
}

View File

@ -8,12 +8,11 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
mod error;
pub use error::PayloadBuilderError;
mod events;
pub use crate::events::{Events, PayloadEvents};
/// Contains the payload builder trait to abstract over payload attributes.
mod traits;
pub use traits::{PayloadBuilder, PayloadStoreExt};
pub use reth_payload_primitives::PayloadBuilderError;

View File

@ -14,9 +14,12 @@ workspace = true
[dependencies]
# reth
reth-chainspec.workspace = true
reth-errors.workspace = true
reth-primitives.workspace = true
reth-chain-state.workspace = true
revm-primitives.workspace = true
# alloy
alloy-eips.workspace = true
alloy-primitives.workspace = true
@ -26,6 +29,7 @@ op-alloy-rpc-types-engine = { workspace = true, optional = true }
# misc
serde.workspace = true
thiserror.workspace = true
tokio = { workspace = true, default-features = false, features = ["sync"] }
[features]
op = ["dep:op-alloy-rpc-types-engine"]

View File

@ -1,5 +1,58 @@
//! Error types emitted by types or implementations of this crate.
use alloy_primitives::B256;
use reth_errors::{ProviderError, RethError};
use revm_primitives::EVMError;
use tokio::sync::oneshot;
/// Possible error variants during payload building.
#[derive(Debug, thiserror::Error)]
pub enum PayloadBuilderError {
/// Thrown when the parent header cannot be found
#[error("missing parent header: {0}")]
MissingParentHeader(B256),
/// Thrown when the parent block is missing.
#[error("missing parent block {0}")]
MissingParentBlock(B256),
/// An oneshot channels has been closed.
#[error("sender has been dropped")]
ChannelClosed,
/// If there's no payload to resolve.
#[error("missing payload")]
MissingPayload,
/// Other internal error
#[error(transparent)]
Internal(#[from] RethError),
/// Unrecoverable error during evm execution.
#[error("evm execution error: {0}")]
EvmExecutionError(EVMError<ProviderError>),
/// Any other payload building errors.
#[error(transparent)]
Other(Box<dyn core::error::Error + Send + Sync>),
}
impl PayloadBuilderError {
/// Create a new error from a boxed error.
pub fn other<E>(error: E) -> Self
where
E: core::error::Error + Send + Sync + 'static,
{
Self::Other(Box::new(error))
}
}
impl From<ProviderError> for PayloadBuilderError {
fn from(error: ProviderError) -> Self {
Self::Internal(RethError::Provider(error))
}
}
impl From<oneshot::error::RecvError> for PayloadBuilderError {
fn from(_: oneshot::error::RecvError) -> Self {
Self::ChannelClosed
}
}
/// Thrown when the payload or attributes are known to be invalid before processing.
///
/// This is used mainly for

View File

@ -9,7 +9,7 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
mod error;
pub use error::{EngineObjectValidationError, VersionSpecificValidationError};
pub use error::{EngineObjectValidationError, PayloadBuilderError, VersionSpecificValidationError};
/// Contains traits to abstract over payload attributes types and default implementations of the
/// [`PayloadAttributes`] trait for ethereum mainnet and optimism types.