Skip to main content

lexe_api_core/cli/
node.rs

1#[cfg(test)]
2use lexe_common::test_utils::arbitrary;
3use lexe_common::{api::MegaId, env::DeployEnv, ln::network::Network};
4#[cfg(test)]
5use proptest_derive::Arbitrary;
6use serde::{Deserialize, Serialize};
7
8use crate::cli::{EnclaveArgs, LspInfo, OAuthConfig};
9
10#[cfg_attr(test, derive(Arbitrary))]
11#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
12pub struct MegaArgs {
13    /// A randomly generated id for this mega node.
14    pub mega_id: MegaId,
15
16    /// protocol://host:port of the backend.
17    #[cfg_attr(test, proptest(strategy = "arbitrary::any_simple_string()"))]
18    pub backend_url: String,
19
20    /// Maximum duration for user node leases (in seconds).
21    pub lease_lifetime_secs: u64,
22
23    /// Interval at which user nodes should renew their leases (in seconds).
24    pub lease_renewal_interval_secs: u64,
25
26    /// info relating to Lexe's LSP.
27    pub lsp: LspInfo,
28
29    /// protocol://host:port of the LSP's HTTP server.
30    #[cfg_attr(test, proptest(strategy = "arbitrary::any_simple_string()"))]
31    pub lsp_url: String,
32
33    /// How long the meganode can remain inactive before it shuts itself down.
34    pub mega_inactivity_secs: u64,
35
36    /// An estimate of the amount of enclave heap consumed by shared meganode
37    /// components such as the network graph, Tokio, connection pools, etc.
38    pub memory_overhead: u64,
39
40    /// configuration info for Google OAuth2.
41    /// Required only if running in staging / prod.
42    pub oauth: Option<OAuthConfig>,
43
44    /// protocol://host:port of the runner.
45    #[cfg_attr(test, proptest(strategy = "arbitrary::any_simple_string()"))]
46    pub runner_url: String,
47
48    /// The value to set for `RUST_BACKTRACE`. Does nothing if set to [`None`].
49    /// Passed as an arg since envs aren't available in SGX.
50    #[cfg_attr(
51        test,
52        proptest(strategy = "arbitrary::any_option_simple_string()")
53    )]
54    pub rust_backtrace: Option<String>,
55
56    /// The value to set for `RUST_LOG`. Does nothing if set to [`None`].
57    /// Passed as an arg since envs aren't available in SGX.
58    #[cfg_attr(
59        test,
60        proptest(strategy = "arbitrary::any_option_simple_string()")
61    )]
62    pub rust_log: Option<String>,
63
64    /// the allocatable memory available to this enclave in SGX.
65    pub sgx_heap_size: u64,
66
67    /// BDK/LDK sync timeout for user nodes (in seconds).
68    ///
69    /// Defaults to [`lexe_common::constants::DEFAULT_USERNODE_SYNC_TIMEOUT`].
70    // Added in node-v0.9.4
71    #[serde(default)]
72    pub usernode_sync_timeout_secs: Option<u64>,
73
74    /// The current deploy environment passed to us by Lexe (or someone in
75    /// Lexe's cloud). This input should be treated as untrusted.
76    pub untrusted_deploy_env: DeployEnv,
77
78    /// Esplora urls which someone in Lexe's infra says we should use.
79    /// We'll only use urls contained in our whitelist.
80    #[cfg_attr(
81        test,
82        proptest(strategy = "arbitrary::any_vec_simple_string()")
83    )]
84    pub untrusted_esplora_urls: Vec<String>,
85
86    /// The current deploy network passed to us by Lexe (or someone in
87    /// Lexe's cloud). This input should be treated as untrusted.
88    pub untrusted_network: Network,
89
90    /// How long the usernode can remain inactive (in seconds) before it gets
91    /// evicted by the UserRunner.
92    pub user_inactivity_secs: u64,
93
94    /// The # of usernodes that the meganode tries to maintain capacity for.
95    /// Users are evicted when remaining memory fits fewer than this amount.
96    pub usernode_buffer_slots: usize,
97
98    /// An estimate of the amount of enclave heap consumed by each usernode.
99    pub usernode_memory: u64,
100}
101
102impl EnclaveArgs for MegaArgs {
103    const NAME: &str = "mega";
104}
105
106#[cfg(test)]
107mod test {
108    use lexe_common::test_utils::roundtrip;
109
110    use super::*;
111
112    #[test]
113    fn node_args_json_string_roundtrip() {
114        roundtrip::json_string_roundtrip_proptest::<MegaArgs>();
115    }
116}