Extract layers module from rpc crate (#8163)

Co-authored-by: Emilia Hane <emiliaha95@gmail.com>
This commit is contained in:
Rupam Dey
2024-05-11 19:11:41 +05:30
committed by GitHub
parent bab96bedbc
commit e20cb91827
24 changed files with 352 additions and 289 deletions

529
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -46,6 +46,7 @@ members = [
"crates/rpc/rpc-testing-util/",
"crates/rpc/rpc-types/",
"crates/rpc/rpc-types-compat/",
"crates/rpc/rpc-layer",
"crates/engine-primitives/",
"crates/ethereum/engine-primitives/",
"crates/ethereum/node",
@ -264,6 +265,7 @@ reth-rpc-builder = { path = "crates/rpc/rpc-builder" }
reth-rpc-engine-api = { path = "crates/rpc/rpc-engine-api" }
reth-rpc-types = { path = "crates/rpc/rpc-types" }
reth-rpc-types-compat = { path = "crates/rpc/rpc-types-compat" }
reth-rpc-layer = { path = "crates/rpc/rpc-layer" }
reth-stages = { path = "crates/stages" }
reth-stages-api = { path = "crates/stages-api" }
reth-static-file = { path = "crates/static-file" }

View File

@ -16,6 +16,7 @@ reth-node-ethereum.workspace = true
reth-tracing.workspace = true
reth-db.workspace = true
reth-rpc.workspace = true
reth-rpc-layer.workspace = true
reth-payload-builder = { workspace = true, features = ["test-utils"] }
reth-provider.workspace = true
reth-node-builder.workspace = true

View File

@ -13,7 +13,7 @@ use reth::{
};
use reth_payload_builder::PayloadId;
use reth_primitives::B256;
use reth_rpc::AuthClientService;
use reth_rpc_layer::AuthClientService;
use std::marker::PhantomData;
/// Helper for engine api operations

View File

@ -23,6 +23,7 @@ reth-rpc.workspace = true
reth-rpc-types.workspace = true
reth-rpc-types-compat.workspace = true
reth-rpc-api = { workspace = true, features = ["client"] }
reth-rpc-layer.workspace = true
reth-transaction-pool.workspace = true
reth-tracing.workspace = true
reth-config.workspace = true

View File

@ -20,9 +20,8 @@ use reth_provider::{
AccountReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader,
EvmEnvProvider, HeaderProvider, StateProviderFactory,
};
use reth_rpc::{
eth::{cache::EthStateCacheConfig, gas_oracle::GasPriceOracleConfig, RPC_DEFAULT_GAS_CAP},
JwtError, JwtSecret,
use reth_rpc::eth::{
cache::EthStateCacheConfig, gas_oracle::GasPriceOracleConfig, RPC_DEFAULT_GAS_CAP,
};
use reth_rpc_builder::{
auth::{AuthServerConfig, AuthServerHandle},
@ -32,6 +31,7 @@ use reth_rpc_builder::{
RpcServerConfig, RpcServerHandle, ServerBuilder, TransportRpcModuleConfig,
};
use reth_rpc_engine_api::EngineApi;
use reth_rpc_layer::{JwtError, JwtSecret};
use reth_tasks::TaskSpawner;
use reth_transaction_pool::TransactionPool;
use std::{

View File

@ -2,14 +2,12 @@
use reth_network::protocol::IntoRlpxSubProtocol;
use reth_primitives::Bytes;
use reth_rpc::{
eth::{cache::EthStateCacheConfig, gas_oracle::GasPriceOracleConfig},
JwtError, JwtSecret,
};
use reth_rpc::eth::{cache::EthStateCacheConfig, gas_oracle::GasPriceOracleConfig};
use reth_rpc_builder::{
auth::AuthServerConfig, error::RpcError, EthConfig, Identity, IpcServerBuilder,
RpcServerConfig, ServerBuilder, TransportRpcModuleConfig,
};
use reth_rpc_layer::{JwtError, JwtSecret};
use reth_transaction_pool::PoolConfig;
use std::{borrow::Cow, path::PathBuf, time::Duration};

View File

@ -13,7 +13,7 @@ use reth_primitives::{
fs, BlockHashOrNumber, ChainSpec, HeadersDirection, SealedBlock, SealedHeader,
};
use reth_provider::BlockReader;
use reth_rpc::{JwtError, JwtSecret};
use reth_rpc_layer::{JwtError, JwtSecret};
use std::{
env::VarError,
path::{Path, PathBuf},

View File

@ -22,6 +22,7 @@ reth-provider.workspace = true
reth-db.workspace = true
reth-rpc-engine-api.workspace = true
reth-rpc.workspace = true
reth-rpc-layer.workspace = true
reth-node-api.workspace = true
reth-node-core.workspace = true
reth-network.workspace = true

View File

@ -19,7 +19,7 @@ use reth_node_core::{
use reth_primitives::{BlockNumber, Chain, ChainSpec, Head, PruneModes, B256};
use reth_provider::{providers::StaticFileProvider, ProviderFactory, StaticFileProviderFactory};
use reth_prune::PrunerBuilder;
use reth_rpc::JwtSecret;
use reth_rpc_layer::JwtSecret;
use reth_static_file::StaticFileProducer;
use reth_tasks::TaskExecutor;
use reth_tracing::tracing::{error, info, warn};

View File

@ -46,3 +46,5 @@ pub use reth_node_core::node_config::NodeConfig;
pub use reth_node_api::*;
use aquamarine as _;
use reth_rpc as _;

View File

@ -15,7 +15,7 @@ use reth_node_core::{
},
};
use reth_payload_builder::PayloadBuilderHandle;
use reth_rpc::JwtSecret;
use reth_rpc_layer::JwtSecret;
use reth_tasks::TaskExecutor;
use reth_tracing::tracing::{debug, info};
use std::{

View File

@ -18,6 +18,7 @@ reth-network-api.workspace = true
reth-provider.workspace = true
reth-rpc.workspace = true
reth-rpc-api.workspace = true
reth-rpc-layer.workspace = true
reth-tasks = { workspace = true, features = ["rayon"] }
reth-transaction-pool.workspace = true
reth-evm.workspace = true

View File

@ -28,10 +28,13 @@ use reth_rpc::{
cache::EthStateCache, gas_oracle::GasPriceOracle, EthFilterConfig, FeeHistoryCache,
FeeHistoryCacheConfig,
},
secret_to_bearer_header, AuthClientLayer, AuthClientService, AuthLayer, EngineEthApi, EthApi,
EthFilter, EthSubscriptionIdProvider, JwtAuthValidator, JwtSecret,
EngineEthApi, EthApi, EthFilter, EthSubscriptionIdProvider,
};
use reth_rpc_api::servers::*;
use reth_rpc_layer::{
secret_to_bearer_header, AuthClientLayer, AuthClientService, AuthLayer, JwtAuthValidator,
JwtSecret,
};
use reth_tasks::{pool::BlockingTaskPool, TaskSpawner};
use reth_transaction_pool::TransactionPool;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

View File

@ -84,12 +84,12 @@
//! AccountReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider,
//! ChangeSetReader, EvmEnvProvider, StateProviderFactory,
//! };
//! use reth_rpc::JwtSecret;
//! use reth_rpc_api::EngineApiServer;
//! use reth_rpc_builder::{
//! auth::AuthServerConfig, RethRpcModule, RpcModuleBuilder, RpcServerConfig,
//! TransportRpcModuleConfig,
//! };
//! use reth_rpc_layer::JwtSecret;
//! use reth_tasks::TokioTaskExecutor;
//! use reth_transaction_pool::TransactionPool;
//! use tokio::try_join;
@ -187,11 +187,11 @@ use reth_rpc::{
traits::RawTransactionForwarder,
EthBundle, FeeHistoryCache,
},
AdminApi, AuthLayer, Claims, DebugApi, EngineEthApi, EthApi, EthFilter, EthPubSub,
EthSubscriptionIdProvider, JwtAuthValidator, JwtSecret, NetApi, OtterscanApi, RPCApi, RethApi,
TraceApi, TxPoolApi, Web3Api,
AdminApi, DebugApi, EngineEthApi, EthApi, EthFilter, EthPubSub, EthSubscriptionIdProvider,
NetApi, OtterscanApi, RPCApi, RethApi, TraceApi, TxPoolApi, Web3Api,
};
use reth_rpc_api::servers::*;
use reth_rpc_layer::{AuthLayer, Claims, JwtAuthValidator, JwtSecret};
use reth_tasks::{
pool::{BlockingTaskGuard, BlockingTaskPool},
TaskSpawner, TokioTaskExecutor,

View File

@ -4,8 +4,8 @@ use crate::utils::launch_auth;
use jsonrpsee::core::client::{ClientT, SubscriptionClientT};
use reth_ethereum_engine_primitives::EthEngineTypes;
use reth_primitives::{Block, U64};
use reth_rpc::JwtSecret;
use reth_rpc_api::clients::EngineApiClient;
use reth_rpc_layer::JwtSecret;
use reth_rpc_types::engine::{ForkchoiceState, PayloadId, TransitionConfiguration};
use reth_rpc_types_compat::engine::payload::{
block_to_payload_v1, convert_block_to_payload_input_v2,

View File

@ -5,13 +5,13 @@ use reth_network_api::noop::NoopNetwork;
use reth_payload_builder::test_utils::spawn_test_payload_service;
use reth_primitives::MAINNET;
use reth_provider::test_utils::{NoopProvider, TestCanonStateSubscriptions};
use reth_rpc::JwtSecret;
use reth_rpc_builder::{
auth::{AuthRpcModule, AuthServerConfig, AuthServerHandle},
RpcModuleBuilder, RpcModuleSelection, RpcServerConfig, RpcServerHandle,
TransportRpcModuleConfig,
};
use reth_rpc_engine_api::EngineApi;
use reth_rpc_layer::JwtSecret;
use reth_tasks::TokioTaskExecutor;
use reth_transaction_pool::test_utils::{TestPool, TestPoolBuilder};
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};

View File

@ -0,0 +1,29 @@
[package]
name = "reth-rpc-layer"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
exclude.workspace = true
[dependencies]
http.workspace = true
hyper.workspace = true
tower.workspace = true
http-body.workspace = true
pin-project.workspace = true
tokio.workspace = true
jsonrpsee.workspace = true
jsonwebtoken = "8"
rand.workspace = true
reth-primitives.workspace = true
serde.workspace = true
thiserror.workspace = true
tempfile.workspace = true
assert_matches.workspace = true
tracing.workspace = true
[lints]
workspace = true

View File

@ -18,7 +18,7 @@ use tower::{Layer, Service};
/// ```rust
/// async fn build_layered_rpc_server() {
/// use jsonrpsee::server::ServerBuilder;
/// use reth_rpc::{AuthLayer, JwtAuthValidator, JwtSecret};
/// use reth_rpc_layer::{AuthLayer, JwtAuthValidator, JwtSecret};
/// use std::net::SocketAddr;
///
/// const AUTH_PORT: u32 = 8551;
@ -167,7 +167,7 @@ mod tests {
};
use super::AuthLayer;
use crate::{layers::jwt_secret::Claims, JwtAuthValidator, JwtError, JwtSecret};
use crate::{jwt_secret::Claims, JwtAuthValidator, JwtError, JwtSecret};
const AUTH_PORT: u32 = 8551;
const AUTH_ADDR: &str = "0.0.0.0";

View File

@ -162,7 +162,7 @@ impl JwtSecret {
/// and the key.
///
/// ```rust
/// use reth_rpc::{Claims, JwtSecret};
/// use reth_rpc_layer::{Claims, JwtSecret};
///
/// let my_claims = Claims { iat: 0, exp: None };
/// let secret = JwtSecret::random();

View File

@ -4,7 +4,7 @@ use tracing::error;
use crate::{AuthValidator, JwtError, JwtSecret};
/// Implements JWT validation logics and integrates
/// to an Http [`AuthLayer`][crate::layers::AuthLayer]
/// to an Http [`AuthLayer`][crate::AuthLayer]
/// by implementing the [`AuthValidator`] trait.
#[derive(Clone)]
#[allow(missing_debug_implementations)]
@ -68,7 +68,7 @@ fn err_response(err: JwtError) -> Response<hyper::Body> {
#[cfg(test)]
mod tests {
use crate::layers::jwt_validator::get_bearer;
use crate::jwt_validator::get_bearer;
use http::{header, HeaderMap};
#[test]

View File

@ -1,4 +1,18 @@
//! Reth RPC testing utilities.
#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
use assert_matches as _;
use http::{HeaderMap, Response};
use jsonrpsee as _;
use tempfile as _;
use tokio as _;
mod auth_client_layer;
mod auth_layer;

View File

@ -25,11 +25,17 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
use http as _;
use http_body as _;
use hyper as _;
use jsonwebtoken as _;
use pin_project as _;
use tower as _;
mod admin;
mod debug;
mod engine;
pub mod eth;
mod layers;
mod net;
mod otterscan;
mod reth;
@ -41,10 +47,6 @@ pub use admin::AdminApi;
pub use debug::DebugApi;
pub use engine::{EngineApi, EngineEthApi};
pub use eth::{EthApi, EthApiSpec, EthFilter, EthPubSub, EthSubscriptionIdProvider};
pub use layers::{
secret_to_bearer_header, AuthClientLayer, AuthClientService, AuthLayer, AuthValidator, Claims,
JwtAuthValidator, JwtError, JwtSecret,
};
pub use net::NetApi;
pub use otterscan::OtterscanApi;
pub use reth::RethApi;