From 6d9bb2226a0bdc0a6b75002f29a599c3837de862 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 14 Jun 2022 03:21:24 -0300 Subject: [PATCH] fix(config): Duration fields (#4587) * use `humantime_serde` for config durations * move debug config option to the bottom * fix deserialization Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- Cargo.lock | 6 ++++-- zebra-network/Cargo.toml | 1 + zebra-network/src/config.rs | 6 ++---- zebrad/Cargo.toml | 1 + zebrad/src/components/mempool/config.rs | 25 +++++++++++-------------- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2811dd74..8a016d7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2033,9 +2033,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "humantime-serde" -version = "1.0.1" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac34a56cfd4acddb469cc7fff187ed5ac36f498ba085caf8bbc725e3ff474058" +checksum = "57a3db5ea5923d99402c94e9feb261dc5ee9b4efa158b0315f788cf549cc200c" dependencies = [ "humantime", "serde", @@ -6245,6 +6245,7 @@ dependencies = [ "chrono", "futures", "hex", + "humantime-serde", "lazy_static", "metrics", "ordered-map", @@ -6405,6 +6406,7 @@ dependencies = [ "futures", "gumdrop", "hex", + "humantime-serde", "hyper", "indexmap", "inferno", diff --git a/zebra-network/Cargo.toml b/zebra-network/Cargo.toml index ed85d41c..c98d9dc7 100644 --- a/zebra-network/Cargo.toml +++ b/zebra-network/Cargo.toml @@ -18,6 +18,7 @@ byteorder = "1.4.3" bytes = "1.1.0" chrono = "0.4.19" hex = "0.4.3" +humantime-serde = "1.1.1" lazy_static = "1.4.0" ordered-map = "0.4.2" pin-project = "1.0.10" diff --git a/zebra-network/src/config.rs b/zebra-network/src/config.rs index ec1a4562..cb993059 100644 --- a/zebra-network/src/config.rs +++ b/zebra-network/src/config.rs @@ -77,9 +77,7 @@ pub struct Config { /// - regularly, every time `crawl_new_peer_interval` elapses, and /// - if the peer set is busy, and there aren't any peer addresses for the /// next connection attempt. - // - // Note: Durations become a TOML table, so they must be the final item in the config - // We'll replace them with a more user-friendly format in #2847 + #[serde(with = "humantime_serde")] pub crawl_new_peer_interval: Duration, } @@ -301,7 +299,7 @@ impl<'de> Deserialize<'de> for Config { initial_mainnet_peers: HashSet, initial_testnet_peers: HashSet, peerset_initial_target_size: usize, - #[serde(alias = "new_peer_interval")] + #[serde(alias = "new_peer_interval", with = "humantime_serde")] crawl_new_peer_interval: Duration, } diff --git a/zebrad/Cargo.toml b/zebrad/Cargo.toml index 7e5b1e81..cb243707 100644 --- a/zebrad/Cargo.toml +++ b/zebrad/Cargo.toml @@ -59,6 +59,7 @@ zebra-state = { path = "../zebra-state" } abscissa_core = "0.5" gumdrop = "0.7" chrono = "0.4.19" +humantime-serde = "1.1.1" indexmap = "1.8.2" lazy_static = "1.4.0" serde = { version = "1.0.137", features = ["serde_derive"] } diff --git a/zebrad/src/components/mempool/config.rs b/zebrad/src/components/mempool/config.rs index c1afa280..01708680 100644 --- a/zebrad/src/components/mempool/config.rs +++ b/zebrad/src/components/mempool/config.rs @@ -8,17 +8,6 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(deny_unknown_fields, default)] pub struct Config { - /// If the state's best chain tip has reached this height, always enable the mempool, - /// regardless of Zebra's sync status. - /// - /// Set to `None` by default: Zebra always checks the sync status before enabling the mempool. - // - // TODO: - // - allow the mempool to be enabled before the genesis block is committed? - // we could replace `Option` with an enum that has an `AlwaysEnable` variant - // - move debug configs last (needs #2847) - pub debug_enable_at_height: Option, - /// The mempool transaction cost limit. /// /// This limits the total serialized byte size of all transactions in the mempool. @@ -39,10 +28,18 @@ pub struct Config { /// /// This corresponds to `mempoolevictionmemoryminutes` from /// [ZIP-401](https://zips.z.cash/zip-0401#specification). - /// - // Note: Durations become a TOML table, so they must be the final item in the config - // We'll replace them with a more user-friendly format in #2847 + #[serde(with = "humantime_serde")] pub eviction_memory_time: Duration, + + /// If the state's best chain tip has reached this height, always enable the mempool, + /// regardless of Zebra's sync status. + /// + /// Set to `None` by default: Zebra always checks the sync status before enabling the mempool. + // + // TODO: + // - allow the mempool to be enabled before the genesis block is committed? + // we could replace `Option` with an enum that has an `AlwaysEnable` variant + pub debug_enable_at_height: Option, } impl Default for Config {