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