mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-23 03:59:31 +00:00
fix config output
This commit is contained in:
parent
bd00c92425
commit
1dd1ed1d67
4 changed files with 29 additions and 17 deletions
|
@ -41,11 +41,11 @@ peer_save_period = { secs = 90, nanos = 0 }
|
||||||
## The block downloader config.
|
## The block downloader config.
|
||||||
[p2p.block_downloader]
|
[p2p.block_downloader]
|
||||||
## The size of the buffer of sequential blocks waiting to be verified and added to the chain (bytes).
|
## 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).
|
## 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.
|
## 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.
|
## 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 }
|
check_client_pool_interval = { secs = 30, nanos = 0 }
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,14 @@ use tracing_config::TracingConfig;
|
||||||
/// Reads the args & config file, returning a [`Config`].
|
/// Reads the args & config file, returning a [`Config`].
|
||||||
pub fn read_config_and_args() -> Config {
|
pub fn read_config_and_args() -> Config {
|
||||||
let args = args::Args::parse();
|
let args = args::Args::parse();
|
||||||
|
args.do_quick_requests();
|
||||||
|
|
||||||
let config: Config = if let Some(config_file) = &args.config_file {
|
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.
|
// 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) {
|
match Config::read_from_path(config_file) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Failed to read config from file: {e}");
|
eprintln!("Failed to read config from file: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ pub fn read_config_and_args() -> Config {
|
||||||
})
|
})
|
||||||
.inspect_err(|e| {
|
.inspect_err(|e| {
|
||||||
tracing::debug!("Failed to read config from config dir: {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()
|
.unwrap_or_default()
|
||||||
};
|
};
|
||||||
|
@ -92,10 +93,10 @@ impl Config {
|
||||||
let file_text = read_to_string(file.as_ref())?;
|
let file_text = read_to_string(file.as_ref())?;
|
||||||
|
|
||||||
Ok(toml::from_str(&file_text)
|
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| {
|
.inspect_err(|e| {
|
||||||
println!("{e}");
|
eprintln!("{e}");
|
||||||
println!(
|
eprintln!(
|
||||||
"Failed to parse config file at: {}",
|
"Failed to parse config file at: {}",
|
||||||
file.as_ref().to_string_lossy()
|
file.as_ref().to_string_lossy()
|
||||||
);
|
);
|
||||||
|
|
|
@ -24,21 +24,26 @@ pub struct Args {
|
||||||
/// The PATH of the `cuprated` config file.
|
/// The PATH of the `cuprated` config file.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub config_file: Option<PathBuf>,
|
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)]
|
#[arg(long)]
|
||||||
pub generate_config: Option<PathBuf>,
|
pub generate_config: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
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`].
|
/// Apply the [`Args`] to the given [`Config`].
|
||||||
///
|
///
|
||||||
/// This may exit the program if a config value was set that requires an early exit.
|
/// 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 {
|
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;
|
config.network = self.network;
|
||||||
|
|
||||||
if let Some(outbound_connections) = self.outbound_connections {
|
if let Some(outbound_connections) = self.outbound_connections {
|
||||||
|
|
|
@ -34,8 +34,14 @@ impl<T> redb::Value for StorableRedb<T>
|
||||||
where
|
where
|
||||||
T: Storable + 'static,
|
T: Storable + 'static,
|
||||||
{
|
{
|
||||||
type SelfType<'a> = T where Self: 'a;
|
type SelfType<'a>
|
||||||
type AsBytes<'a> = &'a [u8] where Self: 'a;
|
= T
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
|
type AsBytes<'a>
|
||||||
|
= &'a [u8]
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fixed_width() -> Option<usize> {
|
fn fixed_width() -> Option<usize> {
|
||||||
|
|
Loading…
Reference in a new issue