embedded_td/config/
state_sync.rs

1use time::Duration;
2
3use super::define_build_mode_setter;
4
5#[derive(Debug, Clone)]
6pub struct StateSyncConfig {
7    /// RPC servers (comma-separated) for light client verification of the synced state machine and
8    /// retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding
9    /// header hash obtained from a trusted source, and a period during which validators can be trusted.
10    ///
11    /// For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2
12    /// weeks) during which they can be financially punished (slashed) for misbehavior.
13    pub rpc_servers: Vec<String>,
14    pub trust_height: u64,
15    pub trust_hash: String,
16    pub trust_period: Duration,
17
18    /// Time to spend discovering snapshots before initiating a restore.
19    pub discovery_time: Duration,
20
21    /// The timeout duration before re-requesting a chunk, possibly from a different
22    /// peer (default: 1 minute).
23    pub chunk_request_timeout: Duration,
24
25    /// The number of concurrent chunk fetchers to run (default: 1).
26    pub chunk_fetchers: u64,
27}
28
29impl Default for StateSyncConfig {
30    fn default() -> Self {
31        Self {
32            rpc_servers: Default::default(),
33            trust_height: 0,
34            trust_hash: Default::default(),
35            trust_period: Duration::hours(168),
36            discovery_time: Duration::new(15, 0),
37            chunk_request_timeout: Duration::new(10, 0),
38            chunk_fetchers: 4,
39        }
40    }
41}
42
43impl StateSyncConfig {
44    define_build_mode_setter!(rpc_servers, Vec<String>);
45
46    define_build_mode_setter!(trust_height, u64);
47
48    define_build_mode_setter!(trust_hash, str);
49
50    define_build_mode_setter!(trust_period, Duration);
51
52    define_build_mode_setter!(discovery_time, Duration);
53
54    define_build_mode_setter!(chunk_request_timeout, Duration);
55
56    define_build_mode_setter!(chunk_fetchers, u64);
57}