diff --git a/binaries/cuprated/src/config.rs b/binaries/cuprated/src/config.rs index 898db41..2a55beb 100644 --- a/binaries/cuprated/src/config.rs +++ b/binaries/cuprated/src/config.rs @@ -1,12 +1,70 @@ //! 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 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)] #[serde(deny_unknown_fields, default)] pub struct Config { + network: Network, + p2p: P2PConfig, + + storage: StorageConfig, +} + +impl Config { + pub fn network(&self) -> Network { + self.network + } + + pub fn clearnet_p2p_config(&self) -> cuprate_p2p::P2PConfig { + 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, + } + } } diff --git a/binaries/cuprated/src/config/sections.rs b/binaries/cuprated/src/config/p2p.rs similarity index 85% rename from binaries/cuprated/src/config/sections.rs rename to binaries/cuprated/src/config/p2p.rs index c345d22..f89b246 100644 --- a/binaries/cuprated/src/config/sections.rs +++ b/binaries/cuprated/src/config/p2p.rs @@ -5,15 +5,15 @@ use serde::{Deserialize, Serialize}; #[derive(Default, Deserialize, Serialize)] #[serde(deny_unknown_fields, default)] pub struct P2PConfig { - clear_net: ClearNetConfig, + pub clear_net: ClearNetConfig, } #[derive(Default, Deserialize, Serialize)] #[serde(deny_unknown_fields, default)] pub struct ClearNetConfig { - server: ClearNetServerCfg, + pub server: ClearNetServerCfg, #[serde(flatten)] - flattened: SharedNetConfig, + pub general: SharedNetConfig, } #[derive(Deserialize, Serialize)] @@ -25,6 +25,7 @@ pub struct SharedNetConfig { pub extra_outbound_connections: usize, /// The maximum amount of inbound connections pub max_inbound_connections: usize, + pub gray_peers_percent: f64, /// port to use to accept p2p connections. pub p2p_port: u16, /// The address book config. @@ -34,9 +35,10 @@ pub struct SharedNetConfig { impl Default for SharedNetConfig { fn default() -> Self { Self { - outbound_connections: 32, + outbound_connections: 64, extra_outbound_connections: 8, max_inbound_connections: 128, + gray_peers_percent: 0.7, p2p_port: 18080, address_book_config: AddressBookConfig::default(), } diff --git a/binaries/cuprated/src/config/storage.rs b/binaries/cuprated/src/config/storage.rs new file mode 100644 index 0000000..de91394 --- /dev/null +++ b/binaries/cuprated/src/config/storage.rs @@ -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, +} diff --git a/p2p/p2p/src/lib.rs b/p2p/p2p/src/lib.rs index 2431158..5d78e85 100644 --- a/p2p/p2p/src/lib.rs +++ b/p2p/p2p/src/lib.rs @@ -17,7 +17,7 @@ use cuprate_p2p_core::{ CoreSyncSvc, NetworkZone, ProtocolRequestHandlerMaker, }; -mod block_downloader; +pub mod block_downloader; mod broadcast; mod client_pool; pub mod config;