tendermint_light_node/
config.rs

1//! LightNode Config
2//!
3//! See instructions in `commands.rs` to specify the path to your
4//! application's configuration file and/or command-line options
5//! for specifying it.
6
7use abscissa_core::path::PathBuf;
8use serde::{Deserialize, Serialize};
9use std::net::SocketAddr;
10use std::time::Duration;
11
12use tendermint_light_client::light_client;
13use tendermint_light_client::types::{PeerId, TrustThreshold};
14
15/// LightNode Configuration
16#[derive(Clone, Debug, Deserialize, Serialize)]
17#[serde(deny_unknown_fields)]
18pub struct LightNodeConfig {
19    /// The fraction of the total voting power of a known
20    /// and trusted validator set is sufficient for a commit to be
21    /// accepted going forward.
22    pub trust_threshold: TrustThreshold,
23    /// The duration until we consider a trusted state as expired.
24    pub trusting_period: Duration,
25    /// Correction parameter dealing with only approximately synchronized clocks.
26    pub clock_drift: Duration,
27
28    /// RPC related config parameters.
29    pub rpc_config: RpcConfig,
30
31    // TODO "now" should probably always be passed in as `Time::now()`
32    /// The actual light client instances' configuration.
33    /// Note: the first config will be used in the subjectively initialize
34    /// the light node in the `initialize` subcommand.
35    pub light_clients: Vec<LightClientConfig>,
36}
37
38/// LightClientConfig contains all options of a light client instance.
39#[derive(Clone, Debug, Deserialize, Serialize)]
40#[serde(deny_unknown_fields)]
41pub struct LightClientConfig {
42    /// Address of the Tendermint fullnode to connect to and
43    /// fetch LightBlock data from.
44    pub address: tendermint_rpc::Url,
45    /// PeerID of the same Tendermint fullnode.
46    pub peer_id: PeerId,
47    /// The data base folder for this instance's store.
48    pub db_path: PathBuf,
49}
50
51/// RpcConfig contains for the RPC server of the light node as
52/// well as RPC client related options.
53#[derive(Clone, Debug, Deserialize, Serialize)]
54#[serde(deny_unknown_fields)]
55pub struct RpcConfig {
56    /// The address the RPC server will serve.
57    pub listen_addr: SocketAddr,
58    /// The duration after which any RPC request to tendermint node will time out.
59    pub request_timeout: Duration,
60}
61
62/// Default light client config settings.
63impl Default for LightClientConfig {
64    fn default() -> Self {
65        Self {
66            address: "tcp://127.0.0.1:26657".parse().unwrap(),
67            peer_id: "BADFADAD0BEFEEDC0C0ADEADBEEFC0FFEEFACADE".parse().unwrap(),
68            db_path: "./lightstore/BADFADAD0BEFEEDC0C0ADEADBEEFC0FFEEFACADE"
69                .parse()
70                .unwrap(),
71        }
72    }
73}
74
75/// Default configuration settings.
76impl Default for LightNodeConfig {
77    fn default() -> Self {
78        Self {
79            trusting_period: Duration::from_secs(864_000), // 60*60*24*10
80            trust_threshold: TrustThreshold {
81                numerator: 1,
82                denominator: 3,
83            },
84            clock_drift: Duration::from_secs(1),
85            rpc_config: RpcConfig {
86                listen_addr: "127.0.0.1:8888".parse().unwrap(),
87                request_timeout: Duration::from_secs(60),
88            },
89            // TODO(ismail): need at least 2 peers for a proper init
90            // otherwise the light node will complain on `start` with `no witness left`
91            light_clients: vec![LightClientConfig::default()],
92        }
93    }
94}
95
96impl From<LightNodeConfig> for light_client::Options {
97    fn from(lnc: LightNodeConfig) -> Self {
98        Self {
99            trust_threshold: lnc.trust_threshold,
100            trusting_period: lnc.trusting_period,
101            clock_drift: lnc.clock_drift,
102        }
103    }
104}