split sections

This commit is contained in:
Boog900 2024-10-17 16:50:14 +01:00
parent a280221cd9
commit 5236ede85b
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
4 changed files with 75 additions and 7 deletions

View file

@ -1,12 +1,70 @@
//! cuprated config //! cuprated config
use cuprate_consensus::ContextConfig;
use cuprate_helper::network::Network;
use cuprate_p2p::block_downloader::BlockDownloaderConfig;
use cuprate_p2p_core::ClearNet;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::time::Duration;
mod sections; mod p2p;
mod storage;
use sections::P2PConfig; use p2p::P2PConfig;
use storage::StorageConfig;
pub fn config() -> Config {
Config::default()
}
#[derive(Default, Deserialize, Serialize)] #[derive(Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)] #[serde(deny_unknown_fields, default)]
pub struct Config { pub struct Config {
network: Network,
p2p: P2PConfig, p2p: P2PConfig,
storage: StorageConfig,
}
impl Config {
pub fn network(&self) -> Network {
self.network
}
pub fn clearnet_p2p_config(&self) -> cuprate_p2p::P2PConfig<ClearNet> {
cuprate_p2p::P2PConfig {
network: self.network,
outbound_connections: self.p2p.clear_net.general.outbound_connections,
extra_outbound_connections: self.p2p.clear_net.general.extra_outbound_connections,
max_inbound_connections: self.p2p.clear_net.general.max_inbound_connections,
gray_peers_percent: self.p2p.clear_net.general.gray_peers_percent,
server_config: Some(self.p2p.clear_net.server.clone()),
p2p_port: self.p2p.clear_net.general.p2p_port,
rpc_port: 0,
address_book_config: self.p2p.clear_net.general.address_book_config.clone(),
}
}
pub fn context_config(&self) -> ContextConfig {
match self.network {
Network::Mainnet => ContextConfig::main_net(),
Network::Stagenet => ContextConfig::stage_net(),
Network::Testnet => ContextConfig::test_net(),
}
}
pub fn blockchain_config(&self) -> cuprate_blockchain::config::Config {
self.storage.blockchain.clone()
}
pub fn block_downloader_config(&self) -> BlockDownloaderConfig {
BlockDownloaderConfig {
buffer_size: 50_000_000,
in_progress_queue_size: 50_000_000,
check_client_pool_interval: Duration::from_secs(30),
target_batch_size: 5_000_000,
initial_batch_size: 1,
}
}
} }

View file

@ -5,15 +5,15 @@ use serde::{Deserialize, Serialize};
#[derive(Default, Deserialize, Serialize)] #[derive(Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)] #[serde(deny_unknown_fields, default)]
pub struct P2PConfig { pub struct P2PConfig {
clear_net: ClearNetConfig, pub clear_net: ClearNetConfig,
} }
#[derive(Default, Deserialize, Serialize)] #[derive(Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)] #[serde(deny_unknown_fields, default)]
pub struct ClearNetConfig { pub struct ClearNetConfig {
server: ClearNetServerCfg, pub server: ClearNetServerCfg,
#[serde(flatten)] #[serde(flatten)]
flattened: SharedNetConfig, pub general: SharedNetConfig,
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
@ -25,6 +25,7 @@ pub struct SharedNetConfig {
pub extra_outbound_connections: usize, pub extra_outbound_connections: usize,
/// The maximum amount of inbound connections /// The maximum amount of inbound connections
pub max_inbound_connections: usize, pub max_inbound_connections: usize,
pub gray_peers_percent: f64,
/// port to use to accept p2p connections. /// port to use to accept p2p connections.
pub p2p_port: u16, pub p2p_port: u16,
/// The address book config. /// The address book config.
@ -34,9 +35,10 @@ pub struct SharedNetConfig {
impl Default for SharedNetConfig { impl Default for SharedNetConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
outbound_connections: 32, outbound_connections: 64,
extra_outbound_connections: 8, extra_outbound_connections: 8,
max_inbound_connections: 128, max_inbound_connections: 128,
gray_peers_percent: 0.7,
p2p_port: 18080, p2p_port: 18080,
address_book_config: AddressBookConfig::default(), address_book_config: AddressBookConfig::default(),
} }

View file

@ -0,0 +1,8 @@
use serde::{Deserialize, Serialize};
#[derive(Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)]
pub struct StorageConfig {
pub blockchain: cuprate_blockchain::config::Config,
pub txpool: cuprate_txpool::Config,
}

View file

@ -17,7 +17,7 @@ use cuprate_p2p_core::{
CoreSyncSvc, NetworkZone, ProtocolRequestHandlerMaker, CoreSyncSvc, NetworkZone, ProtocolRequestHandlerMaker,
}; };
mod block_downloader; pub mod block_downloader;
mod broadcast; mod broadcast;
mod client_pool; mod client_pool;
pub mod config; pub mod config;