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, Default)]
20pub enum ProofKind {
21    #[default]
22    Dummy,
23    ConstraintsChecked,
24    Full,
25}
26
27impl ClusterConfig {
28    pub fn new(ocaml_node_executable: Option<OcamlNodeExecutable>) -> anyhow::Result<Self> {
29        Ok(Self {
30            port_range: None,
31            all_rust_to_rust_use_webrtc: false,
32            proof_kind: ProofKind::default(),
33            is_replay: false,
34            use_debugger: false,
35            ocaml_node_executable,
36        })
37    }
38
39    pub fn use_debugger(&mut self) -> &mut Self {
40        self.use_debugger = true;
41        self
42    }
43
44    pub fn is_use_debugger(&self) -> bool {
45        self.use_debugger
46    }
47
48    pub fn set_replay(&mut self) -> &mut Self {
49        self.is_replay = true;
50        self
51    }
52
53    pub fn is_replay(&self) -> bool {
54        self.is_replay
55    }
56
57    pub fn port_range(&self) -> std::ops::RangeInclusive<u16> {
58        let range = self.port_range.unwrap_or((11_000, 49_151));
59        (range.0)..=(range.1)
60    }
61
62    pub fn set_all_rust_to_rust_use_webrtc(&mut self) -> &mut Self {
63        if !cfg!(feature = "p2p-webrtc") {
64            unreachable!();
65        }
66        self.all_rust_to_rust_use_webrtc = true;
67        self
68    }
69
70    pub fn all_rust_to_rust_use_webrtc(&self) -> bool {
71        self.all_rust_to_rust_use_webrtc
72    }
73
74    pub fn set_proof_kind(&mut self, kind: ProofKind) -> &mut Self {
75        self.proof_kind = kind;
76        self
77    }
78
79    pub fn proof_kind(&self) -> ProofKind {
80        self.proof_kind
81    }
82
83    pub fn set_ocaml_node_executable(&mut self, executable: OcamlNodeExecutable) -> &mut Self {
84        self.ocaml_node_executable = Some(executable);
85        self
86    }
87
88    pub fn ocaml_node_executable(&mut self) -> OcamlNodeExecutable {
89        self.ocaml_node_executable
90            .get_or_insert_with(|| {
91                OcamlNodeExecutable::find_working().expect("cannot run OCaml node")
92            })
93            .clone()
94    }
95}