mina_node_testing/cluster/
config.rs

1use serde::{Deserialize, Serialize};
2
3use crate::node::OcamlNodeExecutable;
4
5#[derive(Serialize, Deserialize, Debug, Clone)]
6pub struct ClusterConfig {
7    #[serde(default)]
8    port_range: Option<(u16, u16)>,
9    all_rust_to_rust_use_webrtc: bool,
10    proof_kind: ProofKind,
11    #[serde(default)]
12    is_replay: bool,
13    #[serde(default)]
14    use_debugger: bool,
15    #[serde(default)]
16    ocaml_node_executable: Option<OcamlNodeExecutable>,
17}
18
19#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
20pub enum ProofKind {
21    Dummy,
22    ConstraintsChecked,
23    Full,
24}
25
26impl Default for ProofKind {
27    fn default() -> Self {
28        // once it's working, change to Self::ConstraintsChecked
29        Self::Dummy
30    }
31}
32
33impl ClusterConfig {
34    pub fn new(ocaml_node_executable: Option<OcamlNodeExecutable>) -> anyhow::Result<Self> {
35        Ok(Self {
36            port_range: None,
37            all_rust_to_rust_use_webrtc: false,
38            proof_kind: ProofKind::default(),
39            is_replay: false,
40            use_debugger: false,
41            ocaml_node_executable,
42        })
43    }
44
45    pub fn use_debugger(&mut self) -> &mut Self {
46        self.use_debugger = true;
47        self
48    }
49
50    pub fn is_use_debugger(&self) -> bool {
51        self.use_debugger
52    }
53
54    pub fn set_replay(&mut self) -> &mut Self {
55        self.is_replay = true;
56        self
57    }
58
59    pub fn is_replay(&self) -> bool {
60        self.is_replay
61    }
62
63    pub fn port_range(&self) -> std::ops::RangeInclusive<u16> {
64        let range = self.port_range.unwrap_or((11_000, 49_151));
65        (range.0)..=(range.1)
66    }
67
68    pub fn set_all_rust_to_rust_use_webrtc(&mut self) -> &mut Self {
69        assert!(cfg!(feature = "p2p-webrtc"));
70        self.all_rust_to_rust_use_webrtc = true;
71        self
72    }
73
74    pub fn all_rust_to_rust_use_webrtc(&self) -> bool {
75        self.all_rust_to_rust_use_webrtc
76    }
77
78    pub fn set_proof_kind(&mut self, kind: ProofKind) -> &mut Self {
79        self.proof_kind = kind;
80        self
81    }
82
83    pub fn proof_kind(&self) -> ProofKind {
84        self.proof_kind
85    }
86
87    pub fn set_ocaml_node_executable(&mut self, executable: OcamlNodeExecutable) -> &mut Self {
88        self.ocaml_node_executable = Some(executable);
89        self
90    }
91
92    pub fn ocaml_node_executable(&mut self) -> OcamlNodeExecutable {
93        self.ocaml_node_executable
94            .get_or_insert_with(|| {
95                OcamlNodeExecutable::find_working().expect("cannot run OCaml node")
96            })
97            .clone()
98    }
99}