chore(op): Clean up module reth_optimism_rpc::eth::sequencer (#10884)

This commit is contained in:
Emilia Hane
2024-09-13 15:22:37 +02:00
committed by GitHub
parent d3acd09be2
commit dd95508d34
6 changed files with 37 additions and 35 deletions

View File

@ -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

View File

@ -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;
@ -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 {
@ -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(),
}
}
}
@ -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>,
)
}
}

View File

@ -1,7 +1,6 @@
//! OP-Reth `eth_` endpoint implementation.
pub mod receipt;
pub mod rpc;
pub mod transaction;
mod block;
@ -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<

View File

@ -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

View File

@ -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;

View File

@ -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)]
@ -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",
@ -81,7 +57,7 @@ impl SequencerClient {
target = "rpc::eth",
"Failed to serialize transaction for forwarding to sequencer"
);
SequencerRpcError::InvalidSequencerTransaction
SequencerClientError::InvalidSequencerTransaction
})?;
self.http_client()
@ -96,8 +72,7 @@ impl SequencerClient {
%err,
"Failed to forward transaction to sequencer",
);
})
.map_err(SequencerRpcError::HttpError)?;
})?;
Ok(())
}