fix config output

This commit is contained in:
Boog900 2024-12-02 21:26:37 +00:00
parent bd00c92425
commit 1dd1ed1d67
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
4 changed files with 29 additions and 17 deletions

View file

@ -41,11 +41,11 @@ peer_save_period = { secs = 90, nanos = 0 }
## The block downloader config.
[p2p.block_downloader]
## The size of the buffer of sequential blocks waiting to be verified and added to the chain (bytes).
buffer_size = 50_000_000
buffer_bytes = 50_000_000
## The size of the queue of blocks which are waiting for a parent block to be downloaded (bytes).
in_progress_queue_size = 50_000_000
in_progress_queue_bytes = 50_000_000
## The target size of a batch of blocks (bytes), must not exceed 100MB.
target_batch_size = 5_000_000
target_batch_bytes= 5_000_000
## 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 }

View file

@ -31,13 +31,14 @@ use tracing_config::TracingConfig;
/// Reads the args & config file, returning a [`Config`].
pub fn read_config_and_args() -> Config {
let args = args::Args::parse();
args.do_quick_requests();
let config: Config = if let Some(config_file) = &args.config_file {
// If a config file was set in the args try to read it and exit if we can't.
match Config::read_from_path(config_file) {
Ok(config) => config,
Err(e) => {
tracing::error!("Failed to read config from file: {e}");
eprintln!("Failed to read config from file: {e}");
std::process::exit(1);
}
}
@ -55,7 +56,7 @@ pub fn read_config_and_args() -> Config {
})
.inspect_err(|e| {
tracing::debug!("Failed to read config from config dir: {e}");
println!("Failed to find/read config file, using default config.");
eprintln!("Failed to find/read config file, using default config.");
})
.unwrap_or_default()
};
@ -92,10 +93,10 @@ impl Config {
let file_text = read_to_string(file.as_ref())?;
Ok(toml::from_str(&file_text)
.inspect(|_| println!("Using config at: {}", file.as_ref().to_string_lossy()))
.inspect(|_| eprintln!("Using config at: {}", file.as_ref().to_string_lossy()))
.inspect_err(|e| {
println!("{e}");
println!(
eprintln!("{e}");
eprintln!(
"Failed to parse config file at: {}",
file.as_ref().to_string_lossy()
);

View file

@ -24,21 +24,26 @@ pub struct Args {
/// The PATH of the `cuprated` config file.
#[arg(long)]
pub config_file: Option<PathBuf>,
/// Generate a config file and place it in the given PATH.
/// Generate a config file and print it to stdout.
#[arg(long)]
pub generate_config: Option<PathBuf>,
pub generate_config: bool,
}
impl Args {
/// Complete any quick requests asked for in [`Args`].
///
/// May cause the process to [`exit`].
pub fn do_quick_requests(&self) {
if self.generate_config {
println!("{EXAMPLE_CONFIG}");
exit(0);
};
}
/// Apply the [`Args`] to the given [`Config`].
///
/// This may exit the program if a config value was set that requires an early exit.
pub fn apply_args(&self, mut config: Config) -> Config {
if let Some(config_folder) = self.generate_config.as_ref() {
println!("{EXAMPLE_CONFIG}");
exit(0);
};
config.network = self.network;
if let Some(outbound_connections) = self.outbound_connections {

View file

@ -34,8 +34,14 @@ impl<T> redb::Value for StorableRedb<T>
where
T: Storable + 'static,
{
type SelfType<'a> = T where Self: 'a;
type AsBytes<'a> = &'a [u8] where Self: 'a;
type SelfType<'a>
= T
where
Self: 'a;
type AsBytes<'a>
= &'a [u8]
where
Self: 'a;
#[inline]
fn fixed_width() -> Option<usize> {