|
1 |
| -use crate::{ |
2 |
| - error::{RpcError, ServerKind}, |
3 |
| - EthConfig, |
4 |
| -}; |
5 |
| - |
| 1 | +use crate::error::{RpcError, ServerKind}; |
6 | 2 | use hyper::header::AUTHORIZATION;
|
7 | 3 | pub use jsonrpsee::server::ServerBuilder;
|
8 | 4 | use jsonrpsee::{
|
9 | 5 | core::RegisterMethodError,
|
10 |
| - http_client::HeaderMap, |
| 6 | + http_client::{transport::HttpBackend, HeaderMap}, |
11 | 7 | server::{AlreadyStoppedError, RpcModule},
|
12 | 8 | Methods,
|
13 | 9 | };
|
14 |
| -pub use reth_ipc::server::Builder as IpcServerBuilder; |
15 |
| - |
16 |
| -use jsonrpsee::http_client::transport::HttpBackend; |
17 | 10 | use reth_engine_primitives::EngineTypes;
|
18 |
| -use reth_evm::ConfigureEvm; |
19 |
| -use reth_network_api::{NetworkInfo, Peers}; |
20 |
| -use reth_provider::{ |
21 |
| - BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, HeaderProvider, ReceiptProviderIdExt, |
22 |
| - StateProviderFactory, |
23 |
| -}; |
24 |
| -use reth_rpc::{ |
25 |
| - eth::{ |
26 |
| - cache::EthStateCache, gas_oracle::GasPriceOracle, EthFilterConfig, FeeHistoryCache, |
27 |
| - FeeHistoryCacheConfig, |
28 |
| - }, |
29 |
| - EngineEthApi, EthApi, EthFilter, EthSubscriptionIdProvider, |
30 |
| -}; |
| 11 | +pub use reth_ipc::server::Builder as IpcServerBuilder; |
| 12 | +use reth_rpc::EthSubscriptionIdProvider; |
31 | 13 | use reth_rpc_api::servers::*;
|
32 | 14 | use reth_rpc_layer::{
|
33 | 15 | secret_to_bearer_header, AuthClientLayer, AuthClientService, AuthLayer, JwtAuthValidator,
|
34 | 16 | JwtSecret,
|
35 | 17 | };
|
36 |
| -use reth_rpc_server_types::{ |
37 |
| - constants, |
38 |
| - constants::{DEFAULT_MAX_BLOCKS_PER_FILTER, DEFAULT_MAX_LOGS_PER_RESPONSE}, |
39 |
| -}; |
40 |
| -use reth_tasks::{pool::BlockingTaskPool, TaskSpawner}; |
41 |
| -use reth_transaction_pool::TransactionPool; |
| 18 | +use reth_rpc_server_types::constants; |
42 | 19 | use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
43 | 20 | use tower::layer::util::Identity;
|
44 | 21 |
|
45 |
| -/// Configure and launch a _standalone_ auth server with `engine` and a _new_ `eth` namespace. |
46 |
| -#[allow(clippy::too_many_arguments)] |
47 |
| -pub async fn launch<Provider, Pool, Network, Tasks, EngineApi, EngineT, EvmConfig>( |
48 |
| - provider: Provider, |
49 |
| - pool: Pool, |
50 |
| - network: Network, |
51 |
| - executor: Tasks, |
52 |
| - engine_api: EngineApi, |
53 |
| - socket_addr: SocketAddr, |
54 |
| - secret: JwtSecret, |
55 |
| - evm_config: EvmConfig, |
56 |
| -) -> Result<AuthServerHandle, RpcError> |
57 |
| -where |
58 |
| - Provider: BlockReaderIdExt |
59 |
| - + ChainSpecProvider |
60 |
| - + EvmEnvProvider |
61 |
| - + HeaderProvider |
62 |
| - + ReceiptProviderIdExt |
63 |
| - + StateProviderFactory |
64 |
| - + Clone |
65 |
| - + Unpin |
66 |
| - + 'static, |
67 |
| - Pool: TransactionPool + Clone + 'static, |
68 |
| - Network: NetworkInfo + Peers + Clone + 'static, |
69 |
| - Tasks: TaskSpawner + Clone + 'static, |
70 |
| - EngineT: EngineTypes + 'static, |
71 |
| - EngineApi: EngineApiServer<EngineT>, |
72 |
| - EvmConfig: ConfigureEvm + 'static, |
73 |
| -{ |
74 |
| - // spawn a new cache task |
75 |
| - let eth_cache = EthStateCache::spawn_with( |
76 |
| - provider.clone(), |
77 |
| - Default::default(), |
78 |
| - executor.clone(), |
79 |
| - evm_config.clone(), |
80 |
| - ); |
81 |
| - |
82 |
| - let gas_oracle = GasPriceOracle::new(provider.clone(), Default::default(), eth_cache.clone()); |
83 |
| - |
84 |
| - let fee_history_cache = |
85 |
| - FeeHistoryCache::new(eth_cache.clone(), FeeHistoryCacheConfig::default()); |
86 |
| - let eth_api = EthApi::with_spawner( |
87 |
| - provider.clone(), |
88 |
| - pool.clone(), |
89 |
| - network, |
90 |
| - eth_cache.clone(), |
91 |
| - gas_oracle, |
92 |
| - EthConfig::default().rpc_gas_cap, |
93 |
| - Box::new(executor.clone()), |
94 |
| - BlockingTaskPool::build().expect("failed to build tracing pool"), |
95 |
| - fee_history_cache, |
96 |
| - evm_config, |
97 |
| - None, |
98 |
| - ); |
99 |
| - let config = EthFilterConfig::default() |
100 |
| - .max_logs_per_response(DEFAULT_MAX_LOGS_PER_RESPONSE) |
101 |
| - .max_blocks_per_filter(DEFAULT_MAX_BLOCKS_PER_FILTER); |
102 |
| - let eth_filter = |
103 |
| - EthFilter::new(provider, pool, eth_cache.clone(), config, Box::new(executor.clone())); |
104 |
| - launch_with_eth_api(eth_api, eth_filter, engine_api, socket_addr, secret).await |
105 |
| -} |
106 |
| - |
107 |
| -/// Configure and launch a _standalone_ auth server with existing `EthApi` implementation. |
108 |
| -pub async fn launch_with_eth_api<Provider, Pool, Network, EngineApi, EngineT, EvmConfig>( |
109 |
| - eth_api: EthApi<Provider, Pool, Network, EvmConfig>, |
110 |
| - eth_filter: EthFilter<Provider, Pool>, |
111 |
| - engine_api: EngineApi, |
112 |
| - socket_addr: SocketAddr, |
113 |
| - secret: JwtSecret, |
114 |
| -) -> Result<AuthServerHandle, RpcError> |
115 |
| -where |
116 |
| - Provider: BlockReaderIdExt |
117 |
| - + ChainSpecProvider |
118 |
| - + EvmEnvProvider |
119 |
| - + HeaderProvider |
120 |
| - + StateProviderFactory |
121 |
| - + Clone |
122 |
| - + Unpin |
123 |
| - + 'static, |
124 |
| - Pool: TransactionPool + Clone + 'static, |
125 |
| - Network: NetworkInfo + Peers + Clone + 'static, |
126 |
| - EngineT: EngineTypes + 'static, |
127 |
| - EngineApi: EngineApiServer<EngineT>, |
128 |
| - EvmConfig: ConfigureEvm + 'static, |
129 |
| -{ |
130 |
| - // Configure the module and start the server. |
131 |
| - let mut module = RpcModule::new(()); |
132 |
| - module.merge(engine_api.into_rpc()).expect("No conflicting methods"); |
133 |
| - let engine_eth = EngineEthApi::new(eth_api, eth_filter); |
134 |
| - module.merge(engine_eth.into_rpc()).expect("No conflicting methods"); |
135 |
| - |
136 |
| - // Create auth middleware. |
137 |
| - let middleware = |
138 |
| - tower::ServiceBuilder::new().layer(AuthLayer::new(JwtAuthValidator::new(secret))); |
139 |
| - |
140 |
| - // By default, both http and ws are enabled. |
141 |
| - let server = ServerBuilder::new() |
142 |
| - .set_http_middleware(middleware) |
143 |
| - .build(socket_addr) |
144 |
| - .await |
145 |
| - .map_err(|err| RpcError::server_error(err, ServerKind::Auth(socket_addr)))?; |
146 |
| - |
147 |
| - let local_addr = server |
148 |
| - .local_addr() |
149 |
| - .map_err(|err| RpcError::server_error(err, ServerKind::Auth(socket_addr)))?; |
150 |
| - |
151 |
| - let handle = server.start(module); |
152 |
| - |
153 |
| - Ok(AuthServerHandle { handle, local_addr, secret, ipc_endpoint: None, ipc_handle: None }) |
154 |
| -} |
155 |
| - |
156 | 22 | /// Server configuration for the auth server.
|
157 | 23 | #[derive(Debug)]
|
158 | 24 | pub struct AuthServerConfig {
|
|
0 commit comments