2019-08-29 14:46:54 -07:00
|
|
|
//! Zebrad Config
|
|
|
|
//!
|
|
|
|
//! See instructions in `commands.rs` to specify the path to your
|
|
|
|
//! application's configuration file and/or command-line options
|
|
|
|
//! for specifying it.
|
|
|
|
|
2020-08-05 16:35:56 -07:00
|
|
|
use std::{net::SocketAddr, path::PathBuf};
|
2020-02-14 13:38:33 -08:00
|
|
|
|
2019-08-29 14:46:54 -07:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2020-08-19 19:25:46 -07:00
|
|
|
use zebra_consensus::Config as ConsensusSection;
|
2019-10-08 13:57:24 -07:00
|
|
|
use zebra_network::Config as NetworkSection;
|
2022-02-22 03:26:29 -08:00
|
|
|
use zebra_rpc::config::Config as RpcSection;
|
2020-07-20 22:31:11 -07:00
|
|
|
use zebra_state::Config as StateSection;
|
2019-10-08 13:57:24 -07:00
|
|
|
|
2021-11-18 17:55:38 -08:00
|
|
|
use crate::components::{mempool::Config as MempoolSection, sync};
|
|
|
|
|
2020-06-17 14:44:24 -07:00
|
|
|
/// Configuration for `zebrad`.
|
|
|
|
///
|
|
|
|
/// The `zebrad` config is a TOML-encoded version of this structure. The meaning
|
|
|
|
/// of each field is described in the documentation, although it may be necessary
|
|
|
|
/// to click through to the sub-structures for each section.
|
2019-12-20 11:20:04 -08:00
|
|
|
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
|
2020-06-18 13:34:05 -07:00
|
|
|
#[serde(deny_unknown_fields, default)]
|
2019-08-29 14:46:54 -07:00
|
|
|
pub struct ZebradConfig {
|
2020-08-19 19:25:46 -07:00
|
|
|
/// Consensus configuration
|
|
|
|
pub consensus: ConsensusSection,
|
|
|
|
|
2020-02-14 13:38:33 -08:00
|
|
|
/// Metrics configuration
|
|
|
|
pub metrics: MetricsSection,
|
2020-07-20 22:31:11 -07:00
|
|
|
|
|
|
|
/// Networking configuration
|
|
|
|
pub network: NetworkSection,
|
|
|
|
|
|
|
|
/// State configuration
|
|
|
|
pub state: StateSection,
|
|
|
|
|
|
|
|
/// Tracing configuration
|
|
|
|
pub tracing: TracingSection,
|
2020-10-23 18:56:54 -07:00
|
|
|
|
|
|
|
/// Sync configuration
|
|
|
|
pub sync: SyncSection,
|
2021-10-07 15:47:37 -07:00
|
|
|
|
|
|
|
/// Mempool configuration
|
|
|
|
pub mempool: MempoolSection,
|
2022-02-22 03:26:29 -08:00
|
|
|
|
|
|
|
/// RPC configuration
|
|
|
|
pub rpc: RpcSection,
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
|
2019-09-09 13:05:42 -07:00
|
|
|
/// Tracing configuration section.
|
2020-07-27 21:35:07 -07:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2020-06-18 13:34:05 -07:00
|
|
|
#[serde(deny_unknown_fields, default)]
|
2019-09-09 13:05:42 -07:00
|
|
|
pub struct TracingSection {
|
2020-11-30 12:11:55 -08:00
|
|
|
/// Whether to use colored terminal output, if available.
|
|
|
|
///
|
2020-11-30 17:08:55 -08:00
|
|
|
/// Colored terminal output is automatically disabled if an output stream
|
|
|
|
/// is connected to a file. (Or another non-terminal device.)
|
|
|
|
///
|
|
|
|
/// Defaults to `true`, which automatically enables colored output to
|
|
|
|
/// terminals.
|
2020-11-30 12:11:55 -08:00
|
|
|
pub use_color: bool,
|
|
|
|
|
2022-02-16 16:09:04 -08:00
|
|
|
/// Whether to force the use of colored terminal output, even if it's not available.
|
|
|
|
///
|
|
|
|
/// Will force Zebra to use colored terminal output even if it does not detect that the output
|
|
|
|
/// is a terminal that supports colors.
|
|
|
|
///
|
|
|
|
/// Defaults to `false`, which keeps the behavior of `use_color`.
|
|
|
|
pub force_use_color: bool,
|
|
|
|
|
2019-09-09 13:05:42 -07:00
|
|
|
/// The filter used for tracing events.
|
2020-08-05 11:48:08 -07:00
|
|
|
///
|
|
|
|
/// The filter is used to create a `tracing-subscriber`
|
|
|
|
/// [`EnvFilter`](https://docs.rs/tracing-subscriber/0.2.10/tracing_subscriber/filter/struct.EnvFilter.html#directives),
|
|
|
|
/// and more details on the syntax can be found there or in the examples
|
|
|
|
/// below.
|
|
|
|
///
|
2020-08-06 10:29:31 -07:00
|
|
|
/// If no filter is specified (`None`), the filter is set to `info` if the
|
|
|
|
/// `-v` flag is given and `warn` if it is not given.
|
|
|
|
///
|
2020-08-05 11:48:08 -07:00
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// `warn,zebrad=info,zebra_network=debug` sets a global `warn` level, an
|
|
|
|
/// `info` level for the `zebrad` crate, and a `debug` level for the
|
|
|
|
/// `zebra_network` crate.
|
|
|
|
///
|
|
|
|
/// ```ascii,no_run
|
2020-09-04 15:40:48 -07:00
|
|
|
/// [block_verify{height=Some\(block::Height\(.*000\)\)}]=trace
|
2020-08-05 11:48:08 -07:00
|
|
|
/// ```
|
|
|
|
/// sets `trace` level for all events occurring in the context of a
|
|
|
|
/// `block_verify` span whose `height` field ends in `000`, i.e., traces the
|
|
|
|
/// verification of every 1000th block.
|
2020-06-04 19:34:06 -07:00
|
|
|
pub filter: Option<String>,
|
2020-07-27 21:35:07 -07:00
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
/// The address used for an ad-hoc RPC endpoint allowing dynamic control of the tracing filter.
|
|
|
|
///
|
|
|
|
/// If this is set to None, the endpoint is disabled.
|
|
|
|
pub endpoint_addr: Option<SocketAddr>,
|
2020-07-27 21:35:07 -07:00
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
/// Controls whether to write a flamegraph of tracing spans.
|
|
|
|
///
|
|
|
|
/// If this is set to None, flamegraphs are disabled. Otherwise, it specifies
|
|
|
|
/// an output file path, as described below.
|
2020-08-05 16:35:56 -07:00
|
|
|
///
|
|
|
|
/// This path is not used verbatim when writing out the flamegraph. This is
|
|
|
|
/// because the flamegraph is written out as two parts. First the flamegraph
|
|
|
|
/// is constantly persisted to the disk in a "folded" representation that
|
|
|
|
/// records collapsed stack traces of the tracing spans that are active.
|
|
|
|
/// Then, when the application is finished running the destructor will flush
|
|
|
|
/// the flamegraph output to the folded file and then read that file and
|
|
|
|
/// generate the final flamegraph from it as an SVG.
|
|
|
|
///
|
|
|
|
/// The need to create two files means that we will slightly manipulate the
|
|
|
|
/// path given to us to create the two representations.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
2020-08-06 10:29:31 -07:00
|
|
|
/// Given `flamegraph = "flamegraph"` we will generate a `flamegraph.svg` and
|
|
|
|
/// a `flamegraph.folded` file in the current directory.
|
2020-08-05 16:35:56 -07:00
|
|
|
///
|
|
|
|
/// If you provide a path with an extension the extension will be ignored and
|
|
|
|
/// replaced with `.folded` and `.svg` for the respective files.
|
|
|
|
pub flamegraph: Option<PathBuf>,
|
2021-04-21 16:31:06 -07:00
|
|
|
|
|
|
|
/// The use_journald flag sends tracing events to systemd-journald, on Linux
|
|
|
|
/// distributions that use systemd.
|
|
|
|
pub use_journald: bool,
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
impl Default for TracingSection {
|
|
|
|
fn default() -> Self {
|
2019-08-29 14:46:54 -07:00
|
|
|
Self {
|
2020-11-30 12:11:55 -08:00
|
|
|
use_color: true,
|
2022-02-16 16:09:04 -08:00
|
|
|
force_use_color: false,
|
2020-08-06 10:29:31 -07:00
|
|
|
filter: None,
|
|
|
|
endpoint_addr: None,
|
2020-08-05 16:35:56 -07:00
|
|
|
flamegraph: None,
|
2021-04-21 16:31:06 -07:00
|
|
|
use_journald: false,
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 13:38:33 -08:00
|
|
|
|
|
|
|
/// Metrics configuration section.
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2020-06-18 13:34:05 -07:00
|
|
|
#[serde(deny_unknown_fields, default)]
|
2020-02-14 13:38:33 -08:00
|
|
|
pub struct MetricsSection {
|
2020-08-06 10:29:31 -07:00
|
|
|
/// The address used for the Prometheus metrics endpoint.
|
|
|
|
///
|
|
|
|
/// The endpoint is disabled if this is set to `None`.
|
|
|
|
pub endpoint_addr: Option<SocketAddr>,
|
2020-02-14 13:38:33 -08:00
|
|
|
}
|
|
|
|
|
2021-09-22 06:43:27 -07:00
|
|
|
// we like our default configs to be explicit
|
|
|
|
#[allow(unknown_lints)]
|
|
|
|
#[allow(clippy::derivable_impls)]
|
2020-02-14 13:38:33 -08:00
|
|
|
impl Default for MetricsSection {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2020-08-06 10:29:31 -07:00
|
|
|
endpoint_addr: None,
|
2020-02-14 13:38:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-23 18:56:54 -07:00
|
|
|
|
|
|
|
/// Sync configuration section.
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
|
|
#[serde(deny_unknown_fields, default)]
|
|
|
|
pub struct SyncSection {
|
|
|
|
/// The maximum number of concurrent block requests during sync.
|
|
|
|
///
|
2020-11-19 16:49:14 -08:00
|
|
|
/// This is set to a low value by default, to avoid task and
|
|
|
|
/// network contention. Increasing this value may improve
|
|
|
|
/// performance on machines with many cores and a fast network
|
|
|
|
/// connection.
|
2020-10-23 18:56:54 -07:00
|
|
|
pub max_concurrent_block_requests: usize,
|
2020-10-30 15:50:15 -07:00
|
|
|
|
|
|
|
/// Controls how far ahead of the chain tip the syncer tries to
|
|
|
|
/// download before waiting for queued verifications to complete.
|
|
|
|
///
|
|
|
|
/// Increasing this limit increases the buffer size, so it reduces
|
|
|
|
/// the impact of an individual block request failing. The block
|
|
|
|
/// size limit is 2MB, so in theory, this could represent multiple
|
|
|
|
/// gigabytes of data, if we downloaded arbitrary blocks. However,
|
|
|
|
/// because we randomly load balance outbound requests, and separate
|
|
|
|
/// block download from obtaining block hashes, an adversary would
|
|
|
|
/// have to control a significant fraction of our peers to lead us
|
|
|
|
/// astray.
|
|
|
|
///
|
|
|
|
/// This value is clamped to an implementation-defined lower bound.
|
|
|
|
pub lookahead_limit: usize,
|
2020-10-23 18:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SyncSection {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2020-11-13 10:52:39 -08:00
|
|
|
max_concurrent_block_requests: 50,
|
2021-11-18 17:55:38 -08:00
|
|
|
lookahead_limit: sync::DEFAULT_LOOKAHEAD_LIMIT,
|
2020-10-23 18:56:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|