mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(sdk): add helper trait to node API to simplify type definition (#10616)
This commit is contained in:
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -7866,7 +7866,6 @@ dependencies = [
|
||||
"reth-payload-primitives",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
"reth-rpc-eth-api",
|
||||
"reth-tasks",
|
||||
"reth-transaction-pool",
|
||||
]
|
||||
@ -7966,8 +7965,6 @@ dependencies = [
|
||||
"reth-network-peers",
|
||||
"reth-primitives",
|
||||
"reth-prune-types",
|
||||
"reth-rpc-api",
|
||||
"reth-rpc-eth-api",
|
||||
"reth-rpc-eth-types",
|
||||
"reth-rpc-server-types",
|
||||
"reth-rpc-types-compat",
|
||||
@ -8629,7 +8626,6 @@ dependencies = [
|
||||
"reth-network-api",
|
||||
"reth-network-peers",
|
||||
"reth-network-types",
|
||||
"reth-node-api",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
"reth-revm",
|
||||
@ -8812,6 +8808,7 @@ dependencies = [
|
||||
"reth-evm",
|
||||
"reth-execution-types",
|
||||
"reth-network-api",
|
||||
"reth-node-api",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
"reth-revm",
|
||||
|
||||
@ -13,7 +13,7 @@ workspace = true
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-node-api.workspace = true
|
||||
reth-rpc-api.workspace = true
|
||||
reth-rpc-api = { workspace = true, features = ["client"] }
|
||||
reth-rpc-builder.workspace = true
|
||||
reth-tracing.workspace = true
|
||||
|
||||
|
||||
@ -4,12 +4,15 @@ use alloy_primitives::{Bytes, B256};
|
||||
use reth::{
|
||||
builder::{rpc::RpcRegistry, FullNodeComponents},
|
||||
rpc::api::{
|
||||
eth::helpers::{EthApiSpec, EthTransactions, TraceExt},
|
||||
eth::{
|
||||
helpers::{EthApiSpec, EthTransactions, TraceExt},
|
||||
EthApiTypes,
|
||||
},
|
||||
DebugApiServer,
|
||||
},
|
||||
};
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_node_builder::{EthApiTypes, NodeTypes};
|
||||
use reth_node_builder::NodeTypes;
|
||||
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct RpcTestContext<Node: FullNodeComponents, EthApi: EthApiTypes> {
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::utils::eth_payload_attributes;
|
||||
use alloy_genesis::Genesis;
|
||||
use alloy_primitives::{b256, hex};
|
||||
use futures::StreamExt;
|
||||
use reth::{args::DevArgs, core::rpc::eth::helpers::EthTransactions};
|
||||
use reth::{args::DevArgs, rpc::api::eth::helpers::EthTransactions};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_e2e_test_utils::setup;
|
||||
use reth_node_api::FullNodeComponents;
|
||||
|
||||
@ -21,7 +21,6 @@ reth-transaction-pool.workspace = true
|
||||
reth-payload-builder.workspace = true
|
||||
reth-payload-primitives.workspace = true
|
||||
reth-tasks.workspace = true
|
||||
reth-rpc-eth-api.workspace = true
|
||||
reth-network-api.workspace = true
|
||||
reth-node-types.workspace = true
|
||||
reth-primitives.workspace = true
|
||||
|
||||
@ -25,5 +25,3 @@ pub use node::*;
|
||||
// re-export for convenience
|
||||
pub use reth_node_types::*;
|
||||
pub use reth_provider::FullProvider;
|
||||
|
||||
pub use reth_rpc_eth_api::EthApiTypes;
|
||||
|
||||
@ -23,15 +23,14 @@ use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider,
|
||||
use reth_engine_util::EngineMessageStreamExt;
|
||||
use reth_exex::ExExManagerHandle;
|
||||
use reth_network::{BlockDownloaderProvider, NetworkEventListenerProvider};
|
||||
use reth_node_api::{
|
||||
AddOnsContext, FullNodeComponents, FullNodeTypes, NodeTypesWithDB, NodeTypesWithEngine,
|
||||
};
|
||||
use reth_node_api::{AddOnsContext, FullNodeTypes, NodeTypesWithDB, NodeTypesWithEngine};
|
||||
use reth_node_core::{
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
exit::NodeExitFuture,
|
||||
};
|
||||
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
|
||||
use reth_provider::providers::BlockchainProvider;
|
||||
use reth_rpc::eth::RpcNodeCore;
|
||||
use reth_tasks::TaskExecutor;
|
||||
use reth_tracing::tracing::{debug, info};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
@ -47,14 +46,14 @@ use crate::{
|
||||
AddOns, NodeBuilderWithComponents, NodeHandle,
|
||||
};
|
||||
|
||||
/// Alias for [`reth_rpc_eth_types::EthApiBuilderCtx`], adapter for [`FullNodeComponents`].
|
||||
/// Alias for [`reth_rpc_eth_types::EthApiBuilderCtx`], adapter for [`RpcNodeCore`].
|
||||
pub type EthApiBuilderCtx<N> = reth_rpc_eth_types::EthApiBuilderCtx<
|
||||
<N as FullNodeTypes>::Provider,
|
||||
<N as FullNodeComponents>::Pool,
|
||||
<N as FullNodeComponents>::Evm,
|
||||
<N as FullNodeComponents>::Network,
|
||||
<N as RpcNodeCore>::Provider,
|
||||
<N as RpcNodeCore>::Pool,
|
||||
<N as RpcNodeCore>::Evm,
|
||||
<N as RpcNodeCore>::Network,
|
||||
TaskExecutor,
|
||||
<N as FullNodeTypes>::Provider,
|
||||
<N as RpcNodeCore>::Provider,
|
||||
>;
|
||||
|
||||
/// A general purpose trait that launches a new node of any kind.
|
||||
|
||||
@ -11,10 +11,10 @@ use reth_node_api::{EngineTypes, FullNodeComponents};
|
||||
use reth_node_core::{
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
node_config::NodeConfig,
|
||||
rpc::api::EngineApiClient,
|
||||
};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_provider::ChainSpecProvider;
|
||||
use reth_rpc_api::EngineApiClient;
|
||||
use reth_rpc_builder::{auth::AuthServerHandle, RpcServerHandle};
|
||||
use reth_tasks::TaskExecutor;
|
||||
|
||||
|
||||
@ -14,12 +14,14 @@ use reth_node_api::{
|
||||
};
|
||||
use reth_node_core::{
|
||||
node_config::NodeConfig,
|
||||
rpc::eth::{EthApiTypes, FullEthApiServer},
|
||||
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
|
||||
};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_provider::providers::ProviderNodeTypes;
|
||||
use reth_rpc::EthApi;
|
||||
use reth_rpc::{
|
||||
eth::{EthApiTypes, FullEthApiServer},
|
||||
EthApi,
|
||||
};
|
||||
use reth_rpc_api::eth::helpers::AddDevSigners;
|
||||
use reth_rpc_builder::{
|
||||
auth::{AuthRpcModule, AuthServerHandle},
|
||||
|
||||
@ -23,8 +23,6 @@ reth-network-p2p.workspace = true
|
||||
reth-rpc-eth-types.workspace = true
|
||||
reth-rpc-server-types.workspace = true
|
||||
reth-rpc-types-compat.workspace = true
|
||||
reth-rpc-api = { workspace = true, features = ["client"] }
|
||||
reth-rpc-eth-api = { workspace = true, features = ["client"] }
|
||||
reth-transaction-pool.workspace = true
|
||||
reth-tracing.workspace = true
|
||||
reth-config.workspace = true
|
||||
@ -38,7 +36,7 @@ reth-stages-types.workspace = true
|
||||
|
||||
# ethereum
|
||||
alloy-primitives.workspace = true
|
||||
alloy-rpc-types-engine = { workspace = true, features = ["jwt"] }
|
||||
alloy-rpc-types-engine = { workspace = true, features = ["std", "jwt"] }
|
||||
alloy-consensus.workspace = true
|
||||
alloy-eips.workspace = true
|
||||
|
||||
|
||||
@ -22,15 +22,6 @@ pub mod primitives {
|
||||
|
||||
/// Re-export of `reth_rpc_*` crates.
|
||||
pub mod rpc {
|
||||
/// Re-exported from `reth_rpc_api`.
|
||||
pub mod api {
|
||||
pub use reth_rpc_api::*;
|
||||
}
|
||||
/// Re-exported from `reth_rpc::eth`.
|
||||
pub mod eth {
|
||||
pub use reth_rpc_eth_api::*;
|
||||
}
|
||||
|
||||
/// Re-exported from `reth_rpc::rpc`.
|
||||
pub mod result {
|
||||
pub use reth_rpc_server_types::result::*;
|
||||
|
||||
@ -17,12 +17,12 @@ use op_alloy_network::Optimism;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeTypes};
|
||||
use reth_node_api::{FullNodeComponents, NodeTypes};
|
||||
use reth_node_builder::EthApiBuilderCtx;
|
||||
use reth_primitives::Header;
|
||||
use reth_provider::{
|
||||
BlockIdReader, BlockNumReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider,
|
||||
StageCheckpointReader, StateProviderFactory,
|
||||
BlockIdReader, BlockNumReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider,
|
||||
HeaderProvider, StageCheckpointReader, StateProviderFactory,
|
||||
};
|
||||
use reth_rpc::eth::{core::EthApiInner, DevSigner};
|
||||
use reth_rpc_eth_api::{
|
||||
@ -30,7 +30,7 @@ use reth_rpc_eth_api::{
|
||||
AddDevSigners, EthApiSpec, EthFees, EthSigner, EthState, LoadBlock, LoadFee, LoadState,
|
||||
SpawnBlocking, Trace,
|
||||
},
|
||||
EthApiTypes,
|
||||
EthApiTypes, RpcNodeCore,
|
||||
};
|
||||
use reth_rpc_eth_types::{EthStateCache, FeeHistoryCache, GasPriceOracle};
|
||||
use reth_tasks::{
|
||||
@ -43,10 +43,10 @@ use crate::{OpEthApiError, SequencerClient};
|
||||
|
||||
/// Adapter for [`EthApiInner`], which holds all the data required to serve core `eth_` API.
|
||||
pub type EthApiNodeBackend<N> = EthApiInner<
|
||||
<N as FullNodeTypes>::Provider,
|
||||
<N as FullNodeComponents>::Pool,
|
||||
<N as FullNodeComponents>::Network,
|
||||
<N as FullNodeComponents>::Evm,
|
||||
<N as RpcNodeCore>::Provider,
|
||||
<N as RpcNodeCore>::Pool,
|
||||
<N as RpcNodeCore>::Network,
|
||||
<N as RpcNodeCore>::Evm,
|
||||
>;
|
||||
|
||||
/// OP-Reth `Eth` API implementation.
|
||||
@ -59,8 +59,8 @@ pub type EthApiNodeBackend<N> = EthApiInner<
|
||||
///
|
||||
/// This type implements the [`FullEthApi`](reth_rpc_eth_api::helpers::FullEthApi) by implemented
|
||||
/// all the `Eth` helper traits and prerequisite traits.
|
||||
#[derive(Deref)]
|
||||
pub struct OpEthApi<N: FullNodeComponents> {
|
||||
#[derive(Deref, Clone)]
|
||||
pub struct OpEthApi<N: RpcNodeCore> {
|
||||
/// Gateway to node's core components.
|
||||
#[deref]
|
||||
inner: Arc<EthApiNodeBackend<N>>,
|
||||
@ -69,7 +69,12 @@ pub struct OpEthApi<N: FullNodeComponents> {
|
||||
sequencer_client: Option<SequencerClient>,
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents> OpEthApi<N> {
|
||||
impl<N> OpEthApi<N>
|
||||
where
|
||||
N: RpcNodeCore<
|
||||
Provider: BlockReaderIdExt + ChainSpecProvider + CanonStateSubscriptions + Clone + 'static,
|
||||
>,
|
||||
{
|
||||
/// Creates a new instance for given context.
|
||||
pub fn new(ctx: &EthApiBuilderCtx<N>, sequencer_http: Option<String>) -> Self {
|
||||
let blocking_task_pool =
|
||||
@ -98,7 +103,7 @@ impl<N: FullNodeComponents> OpEthApi<N> {
|
||||
impl<N> EthApiTypes for OpEthApi<N>
|
||||
where
|
||||
Self: Send + Sync,
|
||||
N: FullNodeComponents,
|
||||
N: RpcNodeCore,
|
||||
{
|
||||
type Error = OpEthApiError;
|
||||
type NetworkTypes = Optimism;
|
||||
@ -248,17 +253,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents> fmt::Debug for OpEthApi<N> {
|
||||
impl<N: RpcNodeCore> fmt::Debug for OpEthApi<N> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("OpEthApi").finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> Clone for OpEthApi<N>
|
||||
where
|
||||
N: FullNodeComponents,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self { inner: self.inner.clone(), sequencer_client: self.sequencer_client.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@ reth-rpc-eth-types.workspace = true
|
||||
reth-rpc-server-types.workspace = true
|
||||
reth-network-api.workspace = true
|
||||
reth-trie.workspace = true
|
||||
reth-node-api.workspace = true
|
||||
|
||||
# ethereum
|
||||
alloy-eips.workspace = true
|
||||
|
||||
@ -16,6 +16,7 @@ pub mod bundle;
|
||||
pub mod core;
|
||||
pub mod filter;
|
||||
pub mod helpers;
|
||||
pub mod node;
|
||||
pub mod pubsub;
|
||||
pub mod types;
|
||||
|
||||
@ -25,6 +26,7 @@ pub use bundle::{EthBundleApiServer, EthCallBundleApiServer};
|
||||
pub use core::{EthApiServer, FullEthApiServer};
|
||||
pub use filter::EthFilterApiServer;
|
||||
pub use helpers::error::{AsEthApiError, FromEthApiError, FromEvmError, IntoEthApiError};
|
||||
pub use node::RpcNodeCore;
|
||||
pub use pubsub::EthPubSubApiServer;
|
||||
pub use types::{EthApiTypes, FullEthApiTypes, RpcBlock, RpcReceipt, RpcTransaction};
|
||||
|
||||
|
||||
58
crates/rpc/rpc-eth-api/src/node.rs
Normal file
58
crates/rpc/rpc-eth-api/src/node.rs
Normal file
@ -0,0 +1,58 @@
|
||||
//! Helper trait for interfacing with [`FullNodeComponents`].
|
||||
|
||||
use reth_node_api::FullNodeComponents;
|
||||
|
||||
/// Helper trait to relax trait bounds on [`FullNodeComponents`].
|
||||
///
|
||||
/// Helpful when defining types that would otherwise have a generic `N: FullNodeComponents`. Using
|
||||
/// `N: RpcNodeCore` instead, allows access to all the associated types on [`FullNodeComponents`]
|
||||
/// that are used in RPC, but with more flexibility since they have no trait bounds (asides auto
|
||||
/// traits).
|
||||
pub trait RpcNodeCore: Clone {
|
||||
/// The provider type used to interact with the node.
|
||||
type Provider: Send + Sync + Clone + Unpin;
|
||||
/// The transaction pool of the node.
|
||||
type Pool: Send + Sync + Clone + Unpin;
|
||||
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
|
||||
type Evm: Send + Sync + Clone + Unpin;
|
||||
/// Network API.
|
||||
type Network: Send + Sync + Clone;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
|
||||
/// Returns the node's evm config.
|
||||
fn evm_config(&self) -> &Self::Evm;
|
||||
|
||||
/// Returns the handle to the network
|
||||
fn network(&self) -> &Self::Network;
|
||||
|
||||
/// Returns the provider of the node.
|
||||
fn provider(&self) -> &Self::Provider;
|
||||
}
|
||||
|
||||
impl<T> RpcNodeCore for T
|
||||
where
|
||||
T: FullNodeComponents,
|
||||
{
|
||||
type Provider = T::Provider;
|
||||
type Pool = T::Pool;
|
||||
type Network = <T as FullNodeComponents>::Network;
|
||||
type Evm = <T as FullNodeComponents>::Evm;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
FullNodeComponents::pool(self)
|
||||
}
|
||||
|
||||
fn evm_config(&self) -> &Self::Evm {
|
||||
FullNodeComponents::evm_config(self)
|
||||
}
|
||||
|
||||
fn network(&self) -> &Self::Network {
|
||||
FullNodeComponents::network(self)
|
||||
}
|
||||
|
||||
fn provider(&self) -> &Self::Provider {
|
||||
FullNodeComponents::provider(self)
|
||||
}
|
||||
}
|
||||
@ -31,7 +31,6 @@ reth-network-peers = { workspace = true, features = ["secp256k1"] }
|
||||
reth-evm.workspace = true
|
||||
reth-rpc-eth-types.workspace = true
|
||||
reth-rpc-server-types.workspace = true
|
||||
reth-node-api.workspace = true
|
||||
reth-network-types.workspace = true
|
||||
reth-trie.workspace = true
|
||||
|
||||
|
||||
@ -17,10 +17,11 @@ use alloy_rpc_types::{
|
||||
use async_trait::async_trait;
|
||||
use jsonrpsee::{core::RpcResult, server::IdProvider};
|
||||
use reth_chainspec::ChainInfo;
|
||||
use reth_node_api::EthApiTypes;
|
||||
use reth_primitives::{Receipt, SealedBlockWithSenders, TransactionSignedEcRecovered};
|
||||
use reth_provider::{BlockIdReader, BlockReader, EvmEnvProvider, ProviderError};
|
||||
use reth_rpc_eth_api::{EthFilterApiServer, FullEthApiTypes, RpcTransaction, TransactionCompat};
|
||||
use reth_rpc_eth_api::{
|
||||
EthApiTypes, EthFilterApiServer, FullEthApiTypes, RpcTransaction, TransactionCompat,
|
||||
};
|
||||
use reth_rpc_eth_types::{
|
||||
logs_utils::{self, append_matching_block_logs, ProviderOrBlock},
|
||||
EthApiError, EthFilterConfig, EthStateCache, EthSubscriptionIdProvider,
|
||||
|
||||
@ -15,4 +15,4 @@ pub use pubsub::EthPubSub;
|
||||
|
||||
pub use helpers::{signer::DevSigner, types::EthTxBuilder};
|
||||
|
||||
pub use reth_rpc_eth_api::EthApiServer;
|
||||
pub use reth_rpc_eth_api::{EthApiServer, EthApiTypes, FullEthApiServer, RpcNodeCore};
|
||||
|
||||
Reference in New Issue
Block a user