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: move OP payload builder error to OP crate #5940

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 12 additions & 23 deletions crates/payload/builder/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@ pub enum PayloadBuilderError {
/// Thrown if the payload requests withdrawals before Shanghai activation.
#[error("withdrawals set before Shanghai activation")]
WithdrawalsBeforeShanghai,
/// Optimism specific payload building errors.
#[cfg(feature = "optimism")]
/// Any other payload building errors.
#[error(transparent)]
Optimism(#[from] OptimismPayloadBuilderError),
Other(Box<dyn std::error::Error + Send + Sync>),
}

impl PayloadBuilderError {
/// Create a new error from a boxed error.
pub fn other<E>(error: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
PayloadBuilderError::Other(Box::new(error))
}
}

impl From<ProviderError> for PayloadBuilderError {
Expand All @@ -38,26 +47,6 @@ impl From<ProviderError> for PayloadBuilderError {
}
}

/// Optimism specific payload building errors.
#[cfg(feature = "optimism")]
#[derive(Debug, thiserror::Error)]
pub enum OptimismPayloadBuilderError {
/// Thrown when a transaction fails to convert to a
/// [reth_primitives::TransactionSignedEcRecovered].
#[error("failed to convert deposit transaction to TransactionSignedEcRecovered")]
TransactionEcRecoverFailed,
/// Thrown when the L1 block info could not be parsed from the calldata of the
/// first transaction supplied in the payload attributes.
#[error("failed to parse L1 block info from L1 info tx calldata")]
L1BlockInfoParseFailed,
/// Thrown when a database account could not be loaded.
#[error("failed to load account {0:?}")]
AccountLoadFailed(revm_primitives::Address),
/// Thrown when force deploy of create2deployer code fails.
#[error("failed to force create2deployer account code")]
ForceCreate2DeployerFail,
}

impl From<oneshot::error::RecvError> for PayloadBuilderError {
fn from(_: oneshot::error::RecvError) -> Self {
PayloadBuilderError::ChannelClosed
Expand Down
2 changes: 2 additions & 0 deletions crates/payload/optimism/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ revm.workspace = true

# misc
tracing.workspace = true
thiserror.workspace = true


[features]
# This is a workaround for reth-cli crate to allow this as mandatory dependency without breaking the build even if unused.
Expand Down
20 changes: 20 additions & 0 deletions crates/payload/optimism/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Error type

/// Optimism specific payload building errors.
#[derive(Debug, thiserror::Error)]
pub enum OptimismPayloadBuilderError {
/// Thrown when a transaction fails to convert to a
/// [reth_primitives::TransactionSignedEcRecovered].
#[error("failed to convert deposit transaction to TransactionSignedEcRecovered")]
TransactionEcRecoverFailed,
/// Thrown when the L1 block info could not be parsed from the calldata of the
/// first transaction supplied in the payload attributes.
#[error("failed to parse L1 block info from L1 info tx calldata")]
L1BlockInfoParseFailed,
/// Thrown when a database account could not be loaded.
#[error("failed to load account {0:?}")]
AccountLoadFailed(reth_primitives::Address),
/// Thrown when force deploy of create2deployer code fails.
#[error("failed to force create2deployer account code")]
ForceCreate2DeployerFail,
}
16 changes: 7 additions & 9 deletions crates/payload/optimism/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#[cfg(feature = "optimism")]
pub use builder::*;

pub mod error;

#[cfg(feature = "optimism")]
mod builder {
use crate::error::OptimismPayloadBuilderError;
use reth_basic_payload_builder::*;
use reth_payload_builder::{
error::{OptimismPayloadBuilderError, PayloadBuilderError},
BuiltPayload,
};
use reth_payload_builder::{error::PayloadBuilderError, BuiltPayload};
use reth_primitives::{
constants::BEACON_NONCE,
proofs,
Expand Down Expand Up @@ -158,7 +158,7 @@ mod builder {
&mut db,
)
.map_err(|_| {
PayloadBuilderError::Optimism(OptimismPayloadBuilderError::ForceCreate2DeployerFail)
PayloadBuilderError::other(OptimismPayloadBuilderError::ForceCreate2DeployerFail)
})?;

let mut receipts = Vec::new();
Expand All @@ -173,9 +173,7 @@ mod builder {
// Deposit transactions do not have signatures, so if the tx is a deposit, this
// will just pull in its `from` address.
let sequencer_tx = sequencer_tx.clone().try_into_ecrecovered().map_err(|_| {
PayloadBuilderError::Optimism(
OptimismPayloadBuilderError::TransactionEcRecoverFailed,
)
PayloadBuilderError::other(OptimismPayloadBuilderError::TransactionEcRecoverFailed)
})?;

// Cache the depositor account prior to the state transition for the deposit nonce.
Expand All @@ -190,7 +188,7 @@ mod builder {
})
.transpose()
.map_err(|_| {
PayloadBuilderError::Optimism(OptimismPayloadBuilderError::AccountLoadFailed(
PayloadBuilderError::other(OptimismPayloadBuilderError::AccountLoadFailed(
sequencer_tx.signer(),
))
})?;
Expand Down
Loading