mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(op): Clean up module reth_optimism_rpc::eth::sequencer (#10884)
This commit is contained in:
@ -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
|
||||
|
||||
@ -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>,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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(())
|
||||
}
|
||||
Reference in New Issue
Block a user