Skip to content

Commit

Permalink
chore(op): Clean up module reth_optimism_rpc::eth::sequencer (#10884)
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Sep 13, 2024
1 parent d3acd09 commit dd95508
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion crates/optimism/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use clap::Parser;
use reth_node_builder::EngineNodeLauncher;
use reth_node_optimism::{args::RollupArgs, node::OptimismAddOns, OptimismNode};
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
use reth_optimism_rpc::eth::rpc::SequencerClient;
use reth_optimism_rpc::SequencerClient;
use reth_provider::providers::BlockchainProvider2;

// We use jemalloc for performance reasons
Expand Down
28 changes: 27 additions & 1 deletion crates/optimism/rpc/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! RPC errors specific to OP.
use jsonrpsee_types::error::INTERNAL_ERROR_CODE;
use reth_evm_optimism::OptimismBlockExecutionError;
use reth_primitives::revm_primitives::{InvalidTransaction, OptimismInvalidTransaction};
use reth_rpc_eth_api::AsEthApiError;
Expand All @@ -24,7 +25,10 @@ pub enum OpEthApiError {
L1BlockGasError,
/// Wrapper for [`revm_primitives::InvalidTransaction`](InvalidTransaction).
#[error(transparent)]
InvalidTransaction(OptimismInvalidTransactionError),
InvalidTransaction(#[from] OptimismInvalidTransactionError),
/// Sequencer client error.
#[error(transparent)]
Sequencer(#[from] SequencerClientError),
}

impl AsEthApiError for OpEthApiError {
Expand All @@ -44,6 +48,7 @@ impl From<OpEthApiError> for jsonrpsee_types::error::ErrorObject<'static> {
OpEthApiError::Evm(_) |
OpEthApiError::L1BlockFeeError |
OpEthApiError::L1BlockGasError => internal_rpc_err(err.to_string()),
OpEthApiError::Sequencer(err) => err.into(),
}
}
}
Expand Down Expand Up @@ -87,3 +92,24 @@ impl TryFrom<InvalidTransaction> for OptimismInvalidTransactionError {
}
}
}

/// Error type when interacting with the Sequencer
#[derive(Debug, thiserror::Error)]
pub enum SequencerClientError {
/// Wrapper around an [`reqwest::Error`].
#[error(transparent)]
HttpError(#[from] reqwest::Error),
/// Thrown when serializing transaction to forward to sequencer
#[error("invalid sequencer transaction")]
InvalidSequencerTransaction,
}

impl From<SequencerClientError> for jsonrpsee_types::error::ErrorObject<'static> {
fn from(err: SequencerClientError) -> Self {
jsonrpsee_types::error::ErrorObject::owned(
INTERNAL_ERROR_CODE,
err.to_string(),
None::<String>,
)
}
}
3 changes: 1 addition & 2 deletions crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! OP-Reth `eth_` endpoint implementation.
pub mod receipt;
pub mod rpc;
pub mod transaction;

mod block;
Expand Down Expand Up @@ -38,7 +37,7 @@ use reth_tasks::{
};
use reth_transaction_pool::TransactionPool;

use crate::{eth::rpc::SequencerClient, OpEthApiError};
use crate::{OpEthApiError, SequencerClient};

/// Adapter for [`EthApiInner`], which holds all the data required to serve core `eth_` API.
pub type EthApiNodeBackend<N> = EthApiInner<
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_rpc_eth_api::{
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthStateCache};
use reth_transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool};

use crate::{eth::rpc::SequencerClient, OpEthApi};
use crate::{OpEthApi, SequencerClient};

impl<N> EthTransactions for OpEthApi<N>
where
Expand Down
4 changes: 3 additions & 1 deletion crates/optimism/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

pub mod error;
pub mod eth;
pub mod sequencer;

pub use error::OpEthApiError;
pub use error::{OpEthApiError, OptimismInvalidTransactionError, SequencerClientError};
pub use eth::OpEthApi;
pub use sequencer::SequencerClient;
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,9 @@
use std::sync::{atomic::AtomicUsize, Arc};

use jsonrpsee_types::error::{ErrorObject, INTERNAL_ERROR_CODE};
use reqwest::Client;
use reth_rpc_eth_types::error::EthApiError;
use reth_rpc_types::ToRpcError;

/// Error type when interacting with the Sequencer
#[derive(Debug, thiserror::Error)]
pub enum SequencerRpcError {
/// Wrapper around an [`reqwest::Error`].
#[error(transparent)]
HttpError(#[from] reqwest::Error),
/// Thrown when serializing transaction to forward to sequencer
#[error("invalid sequencer transaction")]
InvalidSequencerTransaction,
}

impl ToRpcError for SequencerRpcError {
fn to_rpc_error(&self) -> ErrorObject<'static> {
ErrorObject::owned(INTERNAL_ERROR_CODE, self.to_string(), None::<String>)
}
}

impl From<SequencerRpcError> for EthApiError {
fn from(err: SequencerRpcError) -> Self {
Self::other(err)
}
}
use crate::SequencerClientError;

/// A client to interact with a Sequencer
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -69,7 +45,7 @@ impl SequencerClient {
}

/// Forwards a transaction to the sequencer endpoint.
pub async fn forward_raw_transaction(&self, tx: &[u8]) -> Result<(), SequencerRpcError> {
pub async fn forward_raw_transaction(&self, tx: &[u8]) -> Result<(), SequencerClientError> {
let body = serde_json::to_string(&serde_json::json!({
"jsonrpc": "2.0",
"method": "eth_sendRawTransaction",
Expand All @@ -81,7 +57,7 @@ impl SequencerClient {
target = "rpc::eth",
"Failed to serialize transaction for forwarding to sequencer"
);
SequencerRpcError::InvalidSequencerTransaction
SequencerClientError::InvalidSequencerTransaction
})?;

self.http_client()
Expand All @@ -96,8 +72,7 @@ impl SequencerClient {
%err,
"Failed to forward transaction to sequencer",
);
})
.map_err(SequencerRpcError::HttpError)?;
})?;

Ok(())
}
Expand Down

0 comments on commit dd95508

Please sign in to comment.