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 /// When set, how long the meganode can live before it shuts itself down.
40 //
41 // TODO(phlip9): This is a temporary operational workaround to keep the
42 // meganode network graph and scorer from growing too stale until we have
43 // proper LSP->meganode sync. Remove once that's implemented.
44 pub mega_max_lifetime_secs: Option<u64>,
45
46 /// An estimate of the amount of enclave heap consumed by shared meganode
47 /// components such as the network graph, Tokio, connection pools, etc.
48 pub memory_overhead: u64,
49
50 /// configuration info for Google OAuth2.
51 /// Required only if running in staging / prod.
52 pub oauth: Option<OAuthConfig>,
53
54 /// Policy information for Lexe partners that user nodes need to know.
55 /// Includes data like the revshare schedules.
56 pub partners: PartnersInfo,
57
58 /// protocol://host:port of the runner.
59 #[cfg_attr(test, proptest(strategy = "arbitrary::any_simple_string()"))]
60 pub runner_url: String,
61
62 /// The value to set for `RUST_BACKTRACE`. Does nothing if set to [`None`].
63 /// Passed as an arg since envs aren't available in SGX.
64 #[cfg_attr(
65 test,
66 proptest(strategy = "arbitrary::any_option_simple_string()")
67 )]
68 pub rust_backtrace: Option<String>,
69
70 /// The value to set for `RUST_LOG`. Does nothing if set to [`None`].
71 /// Passed as an arg since envs aren't available in SGX.
72 #[cfg_attr(
73 test,
74 proptest(strategy = "arbitrary::any_option_simple_string()")
75 )]
76 pub rust_log: Option<String>,
77
78 /// the allocatable memory available to this enclave in SGX.
79 pub sgx_heap_size: u64,
80
81 /// BDK/LDK sync timeout for user nodes (in seconds).
82 ///
83 /// Defaults to [`lexe_common::constants::DEFAULT_USERNODE_SYNC_TIMEOUT`].
84 // Added in node-v0.9.4
85 #[serde(default)]
86 pub usernode_sync_timeout_secs: Option<u64>,
87
88 /// The current deploy environment passed to us by Lexe (or someone in
89 /// Lexe's cloud). This input should be treated as untrusted.
90 pub untrusted_deploy_env: DeployEnv,
91
92 /// Esplora urls which someone in Lexe's infra says we should use.
93 /// We'll only use urls contained in our whitelist.
94 #[cfg_attr(
95 test,
96 proptest(strategy = "arbitrary::any_vec_simple_string()")
97 )]
98 pub untrusted_esplora_urls: Vec<String>,
99
100 /// The current deploy network passed to us by Lexe (or someone in
101 /// Lexe's cloud). This input should be treated as untrusted.
102 pub untrusted_network: Network,
103
104 /// How long the usernode can remain inactive (in seconds) before it gets
105 /// evicted by the UserRunner.
106 pub user_inactivity_secs: u64,
107
108 /// The # of usernodes that the meganode tries to maintain capacity for.
109 /// Users are evicted when remaining memory fits fewer than this amount.
110 pub usernode_buffer_slots: usize,
111
112 /// An estimate of the amount of enclave heap consumed by each usernode.
113 pub usernode_memory: u64,
114}
115
116impl EnclaveArgs for MegaArgs {
117 const NAME: &str = "mega";
118}
119
120#[cfg(test)]
121mod test {
122 use lexe_common::test_utils::roundtrip;
123 use proptest::{arbitrary::any, test_runner::Config};
124
125 use super::*;
126
127 #[test]
128 fn node_args_json_string_roundtrip() {
129 roundtrip::json_string_custom(
130 any::<MegaArgs>(),
131 Config::with_cases(10),
132 );
133 }
134}