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    /// The current deploy environment passed to us by Lexe (or someone in
68    /// Lexe's cloud). This input should be treated as untrusted.
69    pub untrusted_deploy_env: DeployEnv,
70
71    /// Esplora urls which someone in Lexe's infra says we should use.
72    /// We'll only use urls contained in our whitelist.
73    #[cfg_attr(
74        test,
75        proptest(strategy = "arbitrary::any_vec_simple_string()")
76    )]
77    pub untrusted_esplora_urls: Vec<String>,
78
79    /// The current deploy network passed to us by Lexe (or someone in
80    /// Lexe's cloud). This input should be treated as untrusted.
81    pub untrusted_network: Network,
82
83    /// How long the usernode can remain inactive (in seconds) before it gets
84    /// evicted by the UserRunner.
85    pub user_inactivity_secs: u64,
86
87    /// The # of usernodes that the meganode tries to maintain capacity for.
88    /// Users are evicted when remaining memory fits fewer than this amount.
89    pub usernode_buffer_slots: usize,
90
91    /// An estimate of the amount of enclave heap consumed by each usernode.
92    pub usernode_memory: u64,
93}
94
95impl EnclaveArgs for MegaArgs {
96    const NAME: &str = "mega";
97}
98
99#[cfg(test)]
100mod test {
101    use lexe_common::test_utils::roundtrip;
102
103    use super::*;
104
105    #[test]
106    fn node_args_json_string_roundtrip() {
107        roundtrip::json_string_roundtrip_proptest::<MegaArgs>();
108    }
109}