Skip to content

Commit

Permalink
fix(config): Duration fields (#4587)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and upbqdn committed Jun 14, 2022
1 parent 6d5defc commit 25e494a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zebra-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions zebra-network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -301,7 +299,7 @@ impl<'de> Deserialize<'de> for Config {
initial_mainnet_peers: HashSet<String>,
initial_testnet_peers: HashSet<String>,
peerset_initial_target_size: usize,
#[serde(alias = "new_peer_interval")]
#[serde(alias = "new_peer_interval", with = "humantime_serde")]
crawl_new_peer_interval: Duration,
}

Expand Down
1 change: 1 addition & 0 deletions zebrad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
25 changes: 11 additions & 14 deletions zebrad/src/components/mempool/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,

/// The mempool transaction cost limit.
///
/// This limits the total serialized byte size of all transactions in the mempool.
Expand All @@ -40,10 +29,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<u32>,
}

impl Default for Config {
Expand Down

0 comments on commit 25e494a

Please sign in to comment.