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-02-14 13:38:33 -08:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
2019-08-29 14:46:54 -07:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2019-10-08 13:57:24 -07:00
|
|
|
use zebra_network::Config as NetworkSection;
|
2020-07-20 22:31:11 -07:00
|
|
|
use zebra_state::Config as StateSection;
|
2019-10-08 13:57:24 -07:00
|
|
|
|
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-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,
|
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 {
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
/// # 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
|
|
|
|
/// [block_verify{height=Some\(BlockHeight\(.*000\)\)}]=trace
|
|
|
|
/// ```
|
|
|
|
/// 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
|
|
|
|
|
|
|
/// The endpoint address used for tracing.
|
|
|
|
pub endpoint_addr: SocketAddr,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TracingSection {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::populated()
|
|
|
|
}
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
|
2020-06-04 19:34:06 -07:00
|
|
|
impl TracingSection {
|
|
|
|
pub fn populated() -> Self {
|
2019-08-29 14:46:54 -07:00
|
|
|
Self {
|
2020-06-04 19:34:06 -07:00
|
|
|
filter: Some("info".to_owned()),
|
2020-07-27 21:35:07 -07:00
|
|
|
endpoint_addr: "0.0.0.0:3000".parse().unwrap(),
|
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-07-27 21:35:07 -07:00
|
|
|
/// The endpoint address used for metrics.
|
2020-02-14 13:38:33 -08:00
|
|
|
pub endpoint_addr: SocketAddr,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for MetricsSection {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2020-06-18 22:44:59 -07:00
|
|
|
endpoint_addr: "0.0.0.0:9999".parse().unwrap(),
|
2020-02-14 13:38:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 12:24:28 -07:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2020-06-22 15:36:23 -07:00
|
|
|
use color_eyre::eyre::Result;
|
|
|
|
|
2020-06-09 12:24:28 -07:00
|
|
|
#[test]
|
2020-06-22 15:36:23 -07:00
|
|
|
fn test_toml_ser() -> Result<()> {
|
2020-06-09 12:24:28 -07:00
|
|
|
let default_config = super::ZebradConfig::default();
|
|
|
|
println!("Default config: {:?}", default_config);
|
|
|
|
|
|
|
|
println!("Toml:\n{}", toml::Value::try_from(&default_config)?);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|