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 estimated blocks behind the network tip when the node started waiting for its
18 /// latest block, at most `ready_max_tip_age` before that block arrived.
19 ///
20 /// Used by `/ready`. Negative estimates are treated as 0.
21 pub ready_max_blocks_behind: i64,
22 /// Enforce readiness checks on test networks.
23 ///
24 /// If `false`, `/ready` always returns 200 on regtest and testnets.
25 pub enforce_on_test_networks: bool,
26 /// Maximum time since the node last added a block before readiness fails.
27 ///
28 /// Used by `/ready`. Lower it to detect a stalled node sooner.
29 #[serde(with = "humantime_serde")]
30 pub ready_max_tip_age: Duration,
31}
32
33impl Default for Config {
34 fn default() -> Self {
35 Self {
36 listen_addr: None,
37 min_connected_peers: 1,
38 ready_max_blocks_behind: 2,
39 enforce_on_test_networks: false,
40 ready_max_tip_age: DEFAULT_READY_MAX_TIP_AGE,
41 }
42 }
43}
44
45const DEFAULT_READY_MAX_TIP_AGE: Duration = Duration::from_secs(5 * 60);