Skip to main content

zebrad/components/health/
config.rs

1use std::{net::SocketAddr, time::Duration};
2
3use serde::{Deserialize, Serialize};
4
5/// Health server configuration.
6#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
7#[serde(deny_unknown_fields, default)]
8pub struct Config {
9    /// Address to bind the health server to.
10    ///
11    /// The server is disabled when this is `None`.
12    pub listen_addr: Option<SocketAddr>,
13    /// Minimum number of recently live peers to consider the node healthy.
14    ///
15    /// Used by `/healthy`.
16    pub min_connected_peers: usize,
17    /// Maximum allowed estimated blocks behind the network tip for readiness.
18    ///
19    /// Used by `/ready`. Negative estimates are treated as 0.
20    pub ready_max_blocks_behind: i64,
21    /// Enforce readiness checks on test networks.
22    ///
23    /// If `false`, `/ready` always returns 200 on regtest and testnets.
24    pub enforce_on_test_networks: bool,
25    /// Maximum age of the last committed block before readiness fails.
26    #[serde(with = "humantime_serde")]
27    pub ready_max_tip_age: Duration,
28}
29
30impl Default for Config {
31    fn default() -> Self {
32        Self {
33            listen_addr: None,
34            min_connected_peers: 1,
35            ready_max_blocks_behind: 2,
36            enforce_on_test_networks: false,
37            ready_max_tip_age: DEFAULT_READY_MAX_TIP_AGE,
38        }
39    }
40}
41
42const DEFAULT_READY_MAX_TIP_AGE: Duration = Duration::from_secs(5 * 60);