mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-12-24 23:35:18 +00:00
Optimize rpc config (#213)
This commit is contained in:
parent
84c415e959
commit
ad80b22a1b
@ -1,11 +1,27 @@
|
||||
use std::net::SocketAddr;
|
||||
use std::{net::SocketAddr, str::FromStr};
|
||||
|
||||
#[derive(Clone)]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
pub enabled: bool,
|
||||
pub listen_address: SocketAddr,
|
||||
pub listen_address_admin: Option<SocketAddr>,
|
||||
pub listen_address_admin: SocketAddr,
|
||||
pub chunks_per_segment: usize,
|
||||
pub max_request_body_size: u32,
|
||||
pub max_cache_file_size: usize,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
listen_address: SocketAddr::from_str("0.0.0.0:5678").unwrap(),
|
||||
listen_address_admin: SocketAddr::from_str("127.0.0.1:5679").unwrap(),
|
||||
chunks_per_segment: 1024,
|
||||
max_request_body_size: 100 * 1024 * 1024, // 100MB
|
||||
max_cache_file_size: 10 * 1024 * 1024, // 10MB
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ use jsonrpsee::http_server::{HttpServerBuilder, HttpServerHandle};
|
||||
use network::NetworkGlobals;
|
||||
use network::NetworkMessage;
|
||||
use std::error::Error;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use storage_async::Store;
|
||||
use sync::{SyncRequest, SyncResponse, SyncSender};
|
||||
@ -69,9 +68,10 @@ impl Context {
|
||||
pub async fn run_server(
|
||||
ctx: Context,
|
||||
) -> Result<(HttpServerHandle, Option<HttpServerHandle>), Box<dyn Error>> {
|
||||
let handles = match ctx.config.listen_address_admin {
|
||||
Some(listen_addr_private) => run_server_public_private(ctx, listen_addr_private).await?,
|
||||
None => (run_server_all(ctx).await?, None),
|
||||
let handles = if ctx.config.listen_address.port() != ctx.config.listen_address_admin.port() {
|
||||
run_server_public_private(ctx).await?
|
||||
} else {
|
||||
(run_server_all(ctx).await?, None)
|
||||
};
|
||||
|
||||
info!("Server started");
|
||||
@ -107,7 +107,6 @@ async fn run_server_all(ctx: Context) -> Result<HttpServerHandle, Box<dyn Error>
|
||||
/// Run 2 RPC servers (public & private) for different namespace RPCs.
|
||||
async fn run_server_public_private(
|
||||
ctx: Context,
|
||||
listen_addr_private: SocketAddr,
|
||||
) -> Result<(HttpServerHandle, Option<HttpServerHandle>), Box<dyn Error>> {
|
||||
// public rpc
|
||||
let zgs = (zgs::RpcServerImpl { ctx: ctx.clone() }).into_rpc();
|
||||
@ -127,7 +126,7 @@ async fn run_server_public_private(
|
||||
.start(zgs)?;
|
||||
|
||||
let handle_private = server_builder(ctx.clone())
|
||||
.build(listen_addr_private)
|
||||
.build(ctx.config.listen_address_admin)
|
||||
.await?
|
||||
.start(admin)?;
|
||||
|
||||
|
@ -7,7 +7,6 @@ use log_entry_sync::{CacheConfig, ContractAddress, LogSyncConfig};
|
||||
use miner::MinerConfig;
|
||||
use network::NetworkConfig;
|
||||
use pruner::PrunerConfig;
|
||||
use rpc::RPCConfig;
|
||||
use shared_types::{NetworkIdentity, ProtocolVersion};
|
||||
use std::net::IpAddr;
|
||||
use std::time::Duration;
|
||||
@ -107,32 +106,6 @@ impl ZgsConfig {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn rpc_config(&self) -> Result<RPCConfig, String> {
|
||||
let listen_address = self
|
||||
.rpc_listen_address
|
||||
.parse::<std::net::SocketAddr>()
|
||||
.map_err(|e| format!("Unable to parse rpc_listen_address: {:?}", e))?;
|
||||
|
||||
let listen_address_admin = if self.rpc_listen_address_admin.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(
|
||||
self.rpc_listen_address_admin
|
||||
.parse::<std::net::SocketAddr>()
|
||||
.map_err(|e| format!("Unable to parse rpc_listen_address_admin: {:?}", e))?,
|
||||
)
|
||||
};
|
||||
|
||||
Ok(RPCConfig {
|
||||
enabled: self.rpc_enabled,
|
||||
listen_address,
|
||||
listen_address_admin,
|
||||
max_request_body_size: self.max_request_body_size,
|
||||
chunks_per_segment: self.rpc_chunks_per_segment,
|
||||
max_cache_file_size: self.rpc_max_cache_file_size,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn log_sync_config(&self) -> Result<LogSyncConfig, String> {
|
||||
let contract_address = self
|
||||
.log_contract_address
|
||||
|
@ -48,14 +48,6 @@ build_config! {
|
||||
(remove_finalized_block_interval_minutes, (u64), 30)
|
||||
(watch_loop_wait_time_ms, (u64), 500)
|
||||
|
||||
// rpc
|
||||
(rpc_enabled, (bool), true)
|
||||
(rpc_listen_address, (String), "0.0.0.0:5678".to_string())
|
||||
(rpc_listen_address_admin, (String), "127.0.0.1:5679".to_string())
|
||||
(max_request_body_size, (u32), 100*1024*1024) // 100MB
|
||||
(rpc_chunks_per_segment, (usize), 1024)
|
||||
(rpc_max_cache_file_size, (usize), 10*1024*1024) //10MB
|
||||
|
||||
// chunk pool
|
||||
(chunk_pool_write_window_size, (usize), 4)
|
||||
(chunk_pool_max_cached_chunks_all, (usize), 4*1024*1024) // 1G
|
||||
@ -103,6 +95,9 @@ pub struct ZgsConfig {
|
||||
// file location cache config, configured by [file_location_cache] section by `config` crate.
|
||||
pub file_location_cache: file_location_cache::Config,
|
||||
|
||||
// rpc config, configured by [rpc] section by `config` crate.
|
||||
pub rpc: rpc::RPCConfig,
|
||||
|
||||
// metrics config, configured by [metrics] section by `config` crate.
|
||||
pub metrics: metrics::MetricsConfiguration,
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ use std::error::Error;
|
||||
async fn start_node(context: RuntimeContext, config: ZgsConfig) -> Result<Client, String> {
|
||||
let network_config = config.network_config().await?;
|
||||
let storage_config = config.storage_config()?;
|
||||
let rpc_config = config.rpc_config()?;
|
||||
let log_sync_config = config.log_sync_config()?;
|
||||
let miner_config = config.mine_config()?;
|
||||
let router_config = config.router_config(&network_config)?;
|
||||
@ -33,7 +32,7 @@ async fn start_node(context: RuntimeContext, config: ZgsConfig) -> Result<Client
|
||||
.await?
|
||||
.with_pruner(pruner_config)
|
||||
.await?
|
||||
.with_rpc(rpc_config, config.chunk_pool_config()?)
|
||||
.with_rpc(config.rpc, config.chunk_pool_config()?)
|
||||
.await?
|
||||
.with_router(router_config)?
|
||||
.build()
|
||||
|
@ -120,28 +120,6 @@ log_sync_start_block_number = 595059
|
||||
# Watch_loop (eth_getLogs) trigger interval.
|
||||
# watch_loop_wait_time_ms = 500
|
||||
|
||||
#######################################################################
|
||||
### RPC Config Options ###
|
||||
#######################################################################
|
||||
|
||||
# Whether to provide RPC service.
|
||||
# rpc_enabled = true
|
||||
|
||||
# HTTP server address to bind for public RPC.
|
||||
# rpc_listen_address = "0.0.0.0:5678"
|
||||
|
||||
# HTTP server address to bind for admin and debug RPC.
|
||||
# rpc_listen_address_admin = "127.0.0.1:5679"
|
||||
|
||||
# Maximum data size of RPC request body (by default, 100MB).
|
||||
# max_request_body_size = 104857600
|
||||
|
||||
# Number of chunks for a single segment.
|
||||
# rpc_chunks_per_segment = 1024
|
||||
|
||||
# Maximum file size that allowed to cache in memory (by default, 10MB).
|
||||
# rpc_max_cache_file_size = 10485760
|
||||
|
||||
#######################################################################
|
||||
### Chunk Pool Config Options ###
|
||||
#######################################################################
|
||||
@ -312,6 +290,30 @@ auto_sync_enabled = true
|
||||
# If the timestamp in the storage location information exceeds this duration from the current time, it will be removed from the cache.
|
||||
# entry_expiration_time_secs = 86400
|
||||
|
||||
#######################################################################
|
||||
### RPC Config Options ###
|
||||
#######################################################################
|
||||
|
||||
# [rpc]
|
||||
|
||||
# Whether to provide RPC service.
|
||||
# enabled = true
|
||||
|
||||
# HTTP server address to bind for public RPC.
|
||||
# listen_address = "0.0.0.0:5678"
|
||||
|
||||
# HTTP server address to bind for admin and debug RPC.
|
||||
# listen_address_admin = "127.0.0.1:5679"
|
||||
|
||||
# Number of chunks for a single segment.
|
||||
# chunks_per_segment = 1024
|
||||
|
||||
# Maximum data size of RPC request body (by default, 100MB).
|
||||
# max_request_body_size = 104857600
|
||||
|
||||
# Maximum file size that allowed to cache in memory (by default, 10MB).
|
||||
# max_cache_file_size = 10485760
|
||||
|
||||
#######################################################################
|
||||
### Metrics Options ###
|
||||
#######################################################################
|
||||
|
@ -120,28 +120,6 @@ log_sync_start_block_number = 595059
|
||||
# Watch_loop (eth_getLogs) trigger interval.
|
||||
# watch_loop_wait_time_ms = 500
|
||||
|
||||
#######################################################################
|
||||
### RPC Config Options ###
|
||||
#######################################################################
|
||||
|
||||
# Whether to provide RPC service.
|
||||
# rpc_enabled = true
|
||||
|
||||
# HTTP server address to bind for public RPC.
|
||||
# rpc_listen_address = "0.0.0.0:5678"
|
||||
|
||||
# HTTP server address to bind for admin and debug RPC.
|
||||
# rpc_listen_address_admin = "127.0.0.1:5679"
|
||||
|
||||
# Maximum data size of RPC request body (by default, 100MB).
|
||||
# max_request_body_size = 104857600
|
||||
|
||||
# Number of chunks for a single segment.
|
||||
# rpc_chunks_per_segment = 1024
|
||||
|
||||
# Maximum file size that allowed to cache in memory (by default, 10MB).
|
||||
# rpc_max_cache_file_size = 10485760
|
||||
|
||||
#######################################################################
|
||||
### Chunk Pool Config Options ###
|
||||
#######################################################################
|
||||
@ -324,6 +302,30 @@ auto_sync_enabled = true
|
||||
# If the timestamp in the storage location information exceeds this duration from the current time, it will be removed from the cache.
|
||||
# entry_expiration_time_secs = 86400
|
||||
|
||||
#######################################################################
|
||||
### RPC Config Options ###
|
||||
#######################################################################
|
||||
|
||||
# [rpc]
|
||||
|
||||
# Whether to provide RPC service.
|
||||
# enabled = true
|
||||
|
||||
# HTTP server address to bind for public RPC.
|
||||
# listen_address = "0.0.0.0:5678"
|
||||
|
||||
# HTTP server address to bind for admin and debug RPC.
|
||||
# listen_address_admin = "127.0.0.1:5679"
|
||||
|
||||
# Number of chunks for a single segment.
|
||||
# chunks_per_segment = 1024
|
||||
|
||||
# Maximum data size of RPC request body (by default, 100MB).
|
||||
# max_request_body_size = 104857600
|
||||
|
||||
# Maximum file size that allowed to cache in memory (by default, 10MB).
|
||||
# max_cache_file_size = 10485760
|
||||
|
||||
#######################################################################
|
||||
### Metrics Options ###
|
||||
#######################################################################
|
||||
|
@ -120,28 +120,6 @@
|
||||
# Watch_loop (eth_getLogs) trigger interval.
|
||||
# watch_loop_wait_time_ms = 500
|
||||
|
||||
#######################################################################
|
||||
### RPC Config Options ###
|
||||
#######################################################################
|
||||
|
||||
# Whether to provide RPC service.
|
||||
# rpc_enabled = true
|
||||
|
||||
# HTTP server address to bind for public RPC.
|
||||
# rpc_listen_address = "0.0.0.0:5678"
|
||||
|
||||
# HTTP server address to bind for admin and debug RPC.
|
||||
# rpc_listen_address_admin = "127.0.0.1:5679"
|
||||
|
||||
# Maximum data size of RPC request body (by default, 100MB).
|
||||
# max_request_body_size = 104857600
|
||||
|
||||
# Number of chunks for a single segment.
|
||||
# rpc_chunks_per_segment = 1024
|
||||
|
||||
# Maximum file size that allowed to cache in memory (by default, 10MB).
|
||||
# rpc_max_cache_file_size = 10485760
|
||||
|
||||
#######################################################################
|
||||
### Chunk Pool Config Options ###
|
||||
#######################################################################
|
||||
@ -326,6 +304,30 @@
|
||||
# If the timestamp in the storage location information exceeds this duration from the current time, it will be removed from the cache.
|
||||
# entry_expiration_time_secs = 86400
|
||||
|
||||
#######################################################################
|
||||
### RPC Config Options ###
|
||||
#######################################################################
|
||||
|
||||
# [rpc]
|
||||
|
||||
# Whether to provide RPC service.
|
||||
# enabled = true
|
||||
|
||||
# HTTP server address to bind for public RPC.
|
||||
# listen_address = "0.0.0.0:5678"
|
||||
|
||||
# HTTP server address to bind for admin and debug RPC.
|
||||
# listen_address_admin = "127.0.0.1:5679"
|
||||
|
||||
# Number of chunks for a single segment.
|
||||
# chunks_per_segment = 1024
|
||||
|
||||
# Maximum data size of RPC request body (by default, 100MB).
|
||||
# max_request_body_size = 104857600
|
||||
|
||||
# Maximum file size that allowed to cache in memory (by default, 10MB).
|
||||
# max_cache_file_size = 10485760
|
||||
|
||||
#######################################################################
|
||||
### Metrics Options ###
|
||||
#######################################################################
|
||||
|
@ -34,11 +34,15 @@ class ZgsNode(TestNode):
|
||||
for i in range(index):
|
||||
libp2p_nodes.append(f"/ip4/127.0.0.1/tcp/{p2p_port(i)}")
|
||||
|
||||
rpc_listen_address = f"127.0.0.1:{rpc_port(index)}"
|
||||
|
||||
indexed_config = {
|
||||
"network_libp2p_port": p2p_port(index),
|
||||
"network_discovery_port": p2p_port(index),
|
||||
"rpc_listen_address": f"127.0.0.1:{rpc_port(index)}",
|
||||
"rpc_listen_address_admin": "",
|
||||
"rpc": {
|
||||
"listen_address": rpc_listen_address,
|
||||
"listen_address_admin": rpc_listen_address,
|
||||
},
|
||||
"network_libp2p_nodes": libp2p_nodes,
|
||||
"log_contract_address": log_contract_address,
|
||||
"mine_contract_address": mine_contract_address,
|
||||
@ -50,7 +54,7 @@ class ZgsNode(TestNode):
|
||||
# Overwrite with personalized configs.
|
||||
update_config(local_conf, updated_config)
|
||||
data_dir = os.path.join(root_dir, "zgs_node" + str(index))
|
||||
rpc_url = "http://" + local_conf["rpc_listen_address"]
|
||||
rpc_url = "http://" + rpc_listen_address
|
||||
super().__init__(
|
||||
NodeType.Zgs,
|
||||
index,
|
||||
|
Loading…
Reference in New Issue
Block a user