feat: move core rpc server types to standalone crate (#8515)

This commit is contained in:
Aurélien
2024-06-04 14:06:47 +02:00
committed by GitHub
parent adb3605845
commit 60f6657988
15 changed files with 93 additions and 46 deletions

10
Cargo.lock generated
View File

@ -7210,6 +7210,7 @@ dependencies = [
"reth-rpc",
"reth-rpc-api",
"reth-rpc-builder",
"reth-rpc-server-types",
"reth-rpc-types",
"reth-rpc-types-compat",
"reth-storage-errors",
@ -7544,6 +7545,7 @@ dependencies = [
"reth-revm",
"reth-rpc-api",
"reth-rpc-engine-api",
"reth-rpc-server-types",
"reth-rpc-types",
"reth-rpc-types-compat",
"reth-tasks",
@ -7615,6 +7617,7 @@ dependencies = [
"reth-rpc-api",
"reth-rpc-engine-api",
"reth-rpc-layer",
"reth-rpc-server-types",
"reth-rpc-types",
"reth-rpc-types-compat",
"reth-tasks",
@ -7679,6 +7682,13 @@ dependencies = [
"tracing",
]
[[package]]
name = "reth-rpc-server-types"
version = "0.2.0-beta.8"
dependencies = [
"alloy-primitives",
]
[[package]]
name = "reth-rpc-types"
version = "0.2.0-beta.8"

View File

@ -296,6 +296,7 @@ reth-rpc-api-testing-util = { path = "crates/rpc/rpc-testing-util" }
reth-rpc-builder = { path = "crates/rpc/rpc-builder" }
reth-rpc-engine-api = { path = "crates/rpc/rpc-engine-api" }
reth-rpc-layer = { path = "crates/rpc/rpc-layer" }
reth-rpc-server-types = { path = "crates/rpc/rpc-server-types" }
reth-rpc-types = { path = "crates/rpc/rpc-types" }
reth-rpc-types-compat = { path = "crates/rpc/rpc-types-compat" }
reth-stages = { path = "crates/stages/stages" }

View File

@ -21,6 +21,7 @@ reth-network = { workspace = true, features = ["serde"] }
reth-network-p2p.workspace = true
reth-rpc-builder.workspace = true
reth-rpc.workspace = true
reth-rpc-server-types.workspace = true
reth-rpc-types.workspace = true
reth-rpc-types-compat.workspace = true
reth-rpc-api = { workspace = true, features = ["client"] }

View File

@ -1,7 +1,7 @@
use crate::primitives::U256;
use clap::Args;
use reth_rpc::eth::gas_oracle::GasPriceOracleConfig;
use reth_rpc_builder::constants::{
use reth_rpc_server_types::constants::gas_oracle::{
DEFAULT_GAS_PRICE_BLOCKS, DEFAULT_GAS_PRICE_PERCENTILE, DEFAULT_IGNORE_GAS_PRICE,
DEFAULT_MAX_GAS_PRICE,
};

View File

@ -18,10 +18,10 @@ use reth_rpc::eth::{
cache::EthStateCacheConfig, gas_oracle::GasPriceOracleConfig, RPC_DEFAULT_GAS_CAP,
};
use reth_rpc_builder::{
auth::AuthServerConfig, constants, error::RpcError, EthConfig, Identity, IpcServerBuilder,
RethRpcModule, RpcModuleConfig, RpcModuleSelection, RpcServerConfig, ServerBuilder,
TransportRpcModuleConfig,
auth::AuthServerConfig, error::RpcError, EthConfig, Identity, IpcServerBuilder, RethRpcModule,
RpcModuleConfig, RpcModuleSelection, RpcServerConfig, ServerBuilder, TransportRpcModuleConfig,
};
use reth_rpc_server_types::constants;
use std::{
ffi::OsStr,
net::{IpAddr, Ipv4Addr, SocketAddr},

View File

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

View File

@ -1,6 +1,4 @@
use crate::{
constants,
constants::{DEFAULT_MAX_BLOCKS_PER_FILTER, DEFAULT_MAX_LOGS_PER_RESPONSE},
error::{RpcError, ServerKind},
EthConfig,
};
@ -35,6 +33,10 @@ use reth_rpc_layer::{
secret_to_bearer_header, AuthClientLayer, AuthClientService, AuthLayer, JwtAuthValidator,
JwtSecret,
};
use reth_rpc_server_types::{
constants,
constants::{DEFAULT_MAX_BLOCKS_PER_FILTER, DEFAULT_MAX_LOGS_PER_RESPONSE},
};
use reth_tasks::{pool::BlockingTaskPool, TaskSpawner};
use reth_transaction_pool::TransactionPool;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

View File

@ -1,6 +1,3 @@
use crate::constants::{
default_max_tracing_requests, DEFAULT_MAX_BLOCKS_PER_FILTER, DEFAULT_MAX_LOGS_PER_RESPONSE,
};
use reth_rpc::{
eth::{
cache::{EthStateCache, EthStateCacheConfig},
@ -9,6 +6,9 @@ use reth_rpc::{
},
EthApi, EthFilter, EthPubSub,
};
use reth_rpc_server_types::constants::{
default_max_tracing_requests, DEFAULT_MAX_BLOCKS_PER_FILTER, DEFAULT_MAX_LOGS_PER_RESPONSE,
};
use reth_tasks::pool::BlockingTaskPool;
use serde::{Deserialize, Serialize};

View File

@ -159,7 +159,6 @@ use crate::{
auth::AuthRpcModule, cors::CorsDomainError, error::WsHttpSamePortError,
metrics::RpcRequestMetrics, RpcModuleSelection::Selection,
};
use constants::*;
use error::{ConflictingModules, RpcError, ServerKind};
use hyper::{header::AUTHORIZATION, HeaderMap};
pub use jsonrpsee::server::ServerBuilder;
@ -192,6 +191,7 @@ use reth_rpc::{
};
use reth_rpc_api::servers::*;
use reth_rpc_layer::{AuthLayer, Claims, JwtAuthValidator, JwtSecret};
pub use reth_rpc_server_types::constants;
use reth_tasks::{
pool::{BlockingTaskGuard, BlockingTaskPool},
TaskSpawner, TokioTaskExecutor,
@ -226,9 +226,6 @@ pub mod error;
/// Eth utils
mod eth;
/// Common RPC constants.
pub mod constants;
// Rpc server metrics
mod metrics;
@ -1576,7 +1573,8 @@ impl RpcServerConfig {
/// Configures the [`SocketAddr`] of the http server
///
/// Default is [`Ipv4Addr::LOCALHOST`] and [`DEFAULT_HTTP_RPC_PORT`]
/// Default is [`Ipv4Addr::LOCALHOST`] and
/// [`reth_rpc_server_types::constants::DEFAULT_HTTP_RPC_PORT`]
pub const fn with_http_address(mut self, addr: SocketAddr) -> Self {
self.http_addr = Some(addr);
self
@ -1584,7 +1582,8 @@ impl RpcServerConfig {
/// Configures the [`SocketAddr`] of the ws server
///
/// Default is [`Ipv4Addr::LOCALHOST`] and [`DEFAULT_WS_RPC_PORT`]
/// Default is [`Ipv4Addr::LOCALHOST`] and
/// [`reth_rpc_server_types::constants::DEFAULT_WS_RPC_PORT`]
pub const fn with_ws_address(mut self, addr: SocketAddr) -> Self {
self.ws_addr = Some(addr);
self
@ -1621,7 +1620,7 @@ impl RpcServerConfig {
/// Configures the endpoint of the ipc server
///
/// Default is [`DEFAULT_IPC_ENDPOINT`]
/// Default is [`reth_rpc_server_types::constants::DEFAULT_IPC_ENDPOINT`]
pub fn with_ipc_endpoint(mut self, path: impl Into<String>) -> Self {
self.ipc_endpoint = Some(path.into());
self
@ -1681,12 +1680,13 @@ impl RpcServerConfig {
) -> Result<WsHttpServer, RpcError> {
let http_socket_addr = self.http_addr.unwrap_or(SocketAddr::V4(SocketAddrV4::new(
Ipv4Addr::LOCALHOST,
DEFAULT_HTTP_RPC_PORT,
constants::DEFAULT_HTTP_RPC_PORT,
)));
let ws_socket_addr = self
.ws_addr
.unwrap_or(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, DEFAULT_WS_RPC_PORT)));
let ws_socket_addr = self.ws_addr.unwrap_or(SocketAddr::V4(SocketAddrV4::new(
Ipv4Addr::LOCALHOST,
constants::DEFAULT_WS_RPC_PORT,
)));
// If both are configured on the same port, we combine them into one server.
if self.http_addr == self.ws_addr &&
@ -1815,7 +1815,8 @@ impl RpcServerConfig {
if let Some(builder) = self.ipc_server_config {
let metrics = modules.ipc.as_ref().map(RpcRequestMetrics::ipc).unwrap_or_default();
let ipc_path = self.ipc_endpoint.unwrap_or_else(|| DEFAULT_IPC_ENDPOINT.into());
let ipc_path =
self.ipc_endpoint.unwrap_or_else(|| constants::DEFAULT_IPC_ENDPOINT.into());
let ipc = builder
.set_rpc_middleware(IpcRpcServiceBuilder::new().layer(metrics))
.build(ipc_path);

View File

@ -0,0 +1,16 @@
[package]
name = "reth-rpc-server-types"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
description = "RPC server types and constants"
[lints]
workspace = true
[dependencies]
# ethereum
alloy-primitives.workspace = true

View File

@ -1,8 +1,3 @@
/// GPO reexports
pub use reth_rpc::eth::gas_oracle::{
DEFAULT_GAS_PRICE_BLOCKS, DEFAULT_GAS_PRICE_PERCENTILE, DEFAULT_IGNORE_GAS_PRICE,
DEFAULT_MAX_GAS_PRICE,
};
use std::cmp::max;
/// The default port for the http server
@ -46,3 +41,27 @@ pub const DEFAULT_ENGINE_API_IPC_ENDPOINT: &str = r"\\.\pipe\reth_engine_api.ipc
/// The `engine_api` IPC endpoint
#[cfg(not(windows))]
pub const DEFAULT_ENGINE_API_IPC_ENDPOINT: &str = "/tmp/reth_engine_api.ipc";
/// GPO specific constants
pub mod gas_oracle {
use alloy_primitives::U256;
/// The number of transactions sampled in a block
pub const SAMPLE_NUMBER: usize = 3_usize;
/// The default maximum number of blocks to use for the gas price oracle.
pub const MAX_HEADER_HISTORY: u64 = 1024;
/// Number of recent blocks to check for gas price
pub const DEFAULT_GAS_PRICE_BLOCKS: u32 = 20;
/// The percentile of gas prices to use for the estimate
pub const DEFAULT_GAS_PRICE_PERCENTILE: u32 = 60;
/// Maximum transaction priority fee (or gas price before London Fork) to be recommended by the
/// gas price oracle
pub const DEFAULT_MAX_GAS_PRICE: U256 = U256::from_limbs([500_000_000_000u64, 0, 0, 0]);
/// The default minimum gas price, under which the sample will be ignored
pub const DEFAULT_IGNORE_GAS_PRICE: U256 = U256::from_limbs([2u64, 0, 0, 0]);
}

View File

@ -0,0 +1,12 @@
//! Reth RPC server types.
#![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(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
/// Common RPC constants.
pub mod constants;

View File

@ -15,6 +15,7 @@ workspace = true
# reth
reth-primitives.workspace = true
reth-rpc-api.workspace = true
reth-rpc-server-types.workspace = true
reth-rpc-types.workspace = true
reth-errors.workspace = true
reth-provider = { workspace = true, features = ["test-utils"] }

View File

@ -1,6 +1,6 @@
//! Consist of types adjacent to the fee history cache and its configs
use crate::eth::{cache::EthStateCache, error::EthApiError, gas_oracle::MAX_HEADER_HISTORY};
use crate::eth::{cache::EthStateCache, error::EthApiError};
use futures::{
future::{Fuse, FusedFuture},
FutureExt, Stream, StreamExt,
@ -12,6 +12,7 @@ use reth_primitives::{
ChainSpec, Receipt, SealedBlock, TransactionSigned, B256,
};
use reth_provider::{BlockReaderIdExt, CanonStateNotification, ChainSpecProvider};
use reth_rpc_server_types::constants::gas_oracle::MAX_HEADER_HISTORY;
use reth_rpc_types::TxGasAndReward;
use serde::{Deserialize, Serialize};
use std::{

View File

@ -8,31 +8,13 @@ use crate::eth::{
use derive_more::{Deref, DerefMut};
use reth_primitives::{constants::GWEI_TO_WEI, BlockNumberOrTag, B256, U256};
use reth_provider::BlockReaderIdExt;
use reth_rpc_server_types::constants::gas_oracle::*;
use schnellru::{ByLength, LruMap};
use serde::{Deserialize, Serialize};
use std::fmt::{self, Debug, Formatter};
use tokio::sync::Mutex;
use tracing::warn;
/// The number of transactions sampled in a block
pub const SAMPLE_NUMBER: usize = 3_usize;
/// The default maximum number of blocks to use for the gas price oracle.
pub const MAX_HEADER_HISTORY: u64 = 1024;
/// Number of recent blocks to check for gas price
pub const DEFAULT_GAS_PRICE_BLOCKS: u32 = 20;
/// The percentile of gas prices to use for the estimate
pub const DEFAULT_GAS_PRICE_PERCENTILE: u32 = 60;
/// Maximum transaction priority fee (or gas price before London Fork) to be recommended by the gas
/// price oracle
pub const DEFAULT_MAX_GAS_PRICE: U256 = U256::from_limbs([500_000_000_000u64, 0, 0, 0]);
/// The default minimum gas price, under which the sample will be ignored
pub const DEFAULT_IGNORE_GAS_PRICE: U256 = U256::from_limbs([2u64, 0, 0, 0]);
/// Settings for the [`GasPriceOracle`]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]