diff --git a/binaries/cuprated/src/config.rs b/binaries/cuprated/src/config.rs index b553c078..08d38e4c 100644 --- a/binaries/cuprated/src/config.rs +++ b/binaries/cuprated/src/config.rs @@ -10,7 +10,10 @@ use clap::Parser; use serde::{Deserialize, Serialize}; use cuprate_consensus::ContextConfig; -use cuprate_helper::{fs::CUPRATE_CONFIG_DIR, network::Network}; +use cuprate_helper::{ + fs::{CUPRATE_CONFIG_DIR, DEFAULT_CONFIG_FILE_NAME}, + network::Network, +}; use cuprate_p2p::block_downloader::BlockDownloaderConfig; use cuprate_p2p_core::ClearNet; @@ -24,19 +27,16 @@ use p2p::P2PConfig; use storage::StorageConfig; use tracing_config::TracingConfig; -/// The default name of Cuprate's config file. -const DEFAULT_CONFIG_FILE_NAME: &str = "Cuprate.toml"; - /// Reads the args & config file, returning a [`Config`]. pub fn read_config_and_args() -> Config { let args = args::Args::parse(); let config: Config = if let Some(config_file) = &args.config_file { - // If a config file was set in the args try read it and exit if we can't. + // If a config file was set in the args try to read it and exit if we can't. match Config::read_from_file(config_file) { Ok(config) => config, Err(e) => { - tracing::error!("Failed to read config from file: {}", e); + tracing::error!("Failed to read config from file: {e}"); std::process::exit(1); } } @@ -74,20 +74,22 @@ pub struct Config { /// The P2P network config. p2p: P2PConfig, - /// The Storage config + /// The storage config. storage: StorageConfig, } impl Config { - /// Attempts to read a config file in [`toml`] format from the given [`Path`. + /// Attempts to read a config file in [`toml`] format from the given [`Path`]. /// /// # Errors /// /// Will return an [`Err`] if the file cannot be read or if the file is not a valid [`toml`] config. - fn read_from_file(file: impl AsRef) -> Result { + fn read_from_path(file: impl AsRef) -> Result { let file_text = read_to_string(file.as_ref())?; - Ok(toml::from_str(&file_text).inspect_err(|_| { + Ok(toml::from_str(&file_text).inspect_err(|e| { + tracing::warn!("Error: {e}"); + tracing::warn!( "Failed to parse config file at: {}", file.as_ref().to_string_lossy() diff --git a/binaries/cuprated/src/config/Cuprate.toml b/binaries/cuprated/src/config/Cuprate.toml index 0a92a178..ecc53790 100644 --- a/binaries/cuprated/src/config/Cuprate.toml +++ b/binaries/cuprated/src/config/Cuprate.toml @@ -48,7 +48,7 @@ buffer_size = 50_000_000 in_progress_queue_size = 50_000_000 ## The target size of a batch of blocks (bytes), must not exceed 100MB. target_batch_size = 5_000_000 -## The number of blocks in the first bacth (you probably shouldn't change this). +## The number of blocks in the first batch (you probably shouldn't change this). initial_batch_len = 1 ## The amount of time between checking the pool of connected peers for free peers to download blocks. check_client_pool_interval = {{ secs = 30, nanos = 0 }} diff --git a/binaries/cuprated/src/config/args.rs b/binaries/cuprated/src/config/args.rs index 0e397417..9abb3f13 100644 --- a/binaries/cuprated/src/config/args.rs +++ b/binaries/cuprated/src/config/args.rs @@ -10,7 +10,7 @@ use crate::config::{default::create_default_config_file, Config, DEFAULT_CONFIG_ #[derive(clap::Parser, Debug)] #[command(version, about)] pub struct Args { - /// The network we should run on. + /// The network to run on. #[arg( long, default_value_t = Network::Mainnet, @@ -21,10 +21,10 @@ pub struct Args { /// The amount of outbound clear-net connections to maintain. #[arg(long)] pub outbound_connections: Option, - /// The location of the Cuprate config file. + /// The PATH of the `cuprated` config file. #[arg(long)] pub config_file: Option, - /// Generate a config file and place it in the given folder. + /// Generate a config file and place it in the given PATH. #[arg(long)] pub generate_config: Option, } diff --git a/binaries/cuprated/src/config/p2p.rs b/binaries/cuprated/src/config/p2p.rs index 81e5b5fa..abd667d3 100644 --- a/binaries/cuprated/src/config/p2p.rs +++ b/binaries/cuprated/src/config/p2p.rs @@ -51,7 +51,7 @@ impl SharedNetConfig { // HACK: we add the network here so we don't need to define another address book config. let mut address_book_config = self.address_book_config.clone(); address_book_config - .peer_store_folder + .peer_store_directory .push(network.to_string()); address_book_config @@ -104,7 +104,7 @@ pub fn clear_net_seed_nodes(network: Network) -> Vec { seeds .iter() - .map(|&s| str::parse(s)) + .map(|s| s.parse()) .collect::>() .unwrap() } diff --git a/binaries/cuprated/src/config/storage.rs b/binaries/cuprated/src/config/storage.rs index ba86c48e..80de2656 100644 --- a/binaries/cuprated/src/config/storage.rs +++ b/binaries/cuprated/src/config/storage.rs @@ -42,8 +42,8 @@ pub struct TxpoolConfig { #[serde(flatten)] pub shared: SharedStorageConfig, - /// The maximum size of the tx-pool (bytes). - pub max_txpool_size: usize, + /// The maximum size of the tx-pool. + pub max_txpool_byte_size: usize, } impl Default for TxpoolConfig { diff --git a/helper/src/fs.rs b/helper/src/fs.rs index 7abde893..cebd0cc4 100644 --- a/helper/src/fs.rs +++ b/helper/src/fs.rs @@ -63,6 +63,9 @@ pub const CUPRATE_DIR: &str = { } }; +/// The default name of Cuprate's config file. +pub const DEFAULT_CONFIG_FILE_NAME: &str = "Cuprated.toml"; + //---------------------------------------------------------------------------------------------------- Directories /// Create a `LazyLock` for common PATHs used by Cuprate. /// diff --git a/p2p/address-book/src/book/tests.rs b/p2p/address-book/src/book/tests.rs index 33f881ee..b2c4c493 100644 --- a/p2p/address-book/src/book/tests.rs +++ b/p2p/address-book/src/book/tests.rs @@ -15,7 +15,7 @@ fn test_cfg() -> AddressBookConfig { AddressBookConfig { max_white_list_length: 100, max_gray_list_length: 500, - peer_store_folder: PathBuf::new(), + peer_store_directory: PathBuf::new(), peer_save_period: Duration::from_secs(60), } } diff --git a/p2p/address-book/src/lib.rs b/p2p/address-book/src/lib.rs index 2d7b3d63..04229677 100644 --- a/p2p/address-book/src/lib.rs +++ b/p2p/address-book/src/lib.rs @@ -31,8 +31,8 @@ pub struct AddressBookConfig { /// /// Gray peers are peers we are yet to make a connection to. pub max_gray_list_length: usize, - /// The location to store the peer store file. - pub peer_store_folder: PathBuf, + /// The location to store the peer store files. + pub peer_store_directory: PathBuf, /// The amount of time between saving the address book to disk. pub peer_save_period: Duration, } @@ -43,7 +43,7 @@ impl Default for AddressBookConfig { Self { max_white_list_length: 1000, max_gray_list_length: 5000, - peer_store_folder: cuprate_helper::fs::CUPRATE_CACHE_DIR.clone(), + peer_store_directory: cuprate_helper::fs::CUPRATE_CACHE_DIR.clone(), peer_save_period: Duration::from_secs(90), } } diff --git a/p2p/address-book/src/store.rs b/p2p/address-book/src/store.rs index 31277f9e..47994ae5 100644 --- a/p2p/address-book/src/store.rs +++ b/p2p/address-book/src/store.rs @@ -39,7 +39,9 @@ pub(crate) fn save_peers_to_disk( }) .unwrap(); - let file = cfg.peer_store_folder.join(format!("{}_p2p_state", Z::NAME)); + let file = cfg + .peer_store_directory + .join(format!("{}_p2p_state", Z::NAME)); spawn_blocking(move || fs::write(&file, &data)) } @@ -52,7 +54,9 @@ pub(crate) async fn read_peers_from_disk( ), std::io::Error, > { - let file = cfg.peer_store_folder.join(format!("{}_p2p_state", Z::NAME)); + let file = cfg + .peer_store_directory + .join(format!("{}_p2p_state", Z::NAME)); tracing::info!("Loading peers from file: {} ", file.display()); diff --git a/storage/txpool/src/config.rs b/storage/txpool/src/config.rs index 6e838df6..69b73aab 100644 --- a/storage/txpool/src/config.rs +++ b/storage/txpool/src/config.rs @@ -90,7 +90,7 @@ impl ConfigBuilder { } } - /// Change the network this blockchain database is for. + /// Change the network this database is for. #[must_use] pub const fn network(mut self, network: Network) -> Self { self.network = network;