pathfinder_consensus/
config.rs1use std::path::PathBuf;
2use std::time::Duration;
3
4use malachite_types::{ThresholdParams, TimeoutKind};
5
6#[derive(Clone, Debug, Default)]
8pub struct Config<A> {
9 pub address: A,
11 pub initial_height: u64,
13 pub timeout_values: TimeoutValues,
15 pub history_depth: u64,
17 pub wal_dir: PathBuf,
19 pub(crate) threshold_params: ThresholdParams,
21}
22
23impl<A: Default> Config<A> {
24 pub fn new(address: A) -> Self {
27 Self {
28 address,
29 history_depth: 10,
30 wal_dir: PathBuf::from("wal"),
31 ..Default::default()
32 }
33 }
34
35 pub fn with_initial_height(mut self, height: u64) -> Self {
37 self.initial_height = height;
38 self
39 }
40
41 pub fn with_timeout_values(mut self, timeout_values: TimeoutValues) -> Self {
43 self.timeout_values = timeout_values;
44 self
45 }
46
47 pub fn with_history_depth(mut self, history_depth: u64) -> Self {
49 self.history_depth = history_depth;
50 self
51 }
52
53 pub fn with_wal_dir(mut self, wal_dir: PathBuf) -> Self {
55 self.wal_dir = wal_dir;
56 self
57 }
58}
59
60#[derive(Debug, Clone)]
62pub struct TimeoutValues {
63 pub propose: Duration,
65 pub prevote: Duration,
67 pub precommit: Duration,
69 pub rebroadcast: Duration,
71}
72
73impl Default for TimeoutValues {
74 fn default() -> Self {
75 Self {
76 propose: Duration::from_secs(10),
77 prevote: Duration::from_secs(10),
78 precommit: Duration::from_secs(10),
79 rebroadcast: Duration::from_secs(10),
80 }
81 }
82}
83
84impl TimeoutValues {
85 pub fn get(&self, kind: TimeoutKind) -> Duration {
87 match kind {
88 TimeoutKind::Propose => self.propose,
89 TimeoutKind::Prevote => self.prevote,
90 TimeoutKind::Precommit => self.precommit,
91 TimeoutKind::Rebroadcast => self.rebroadcast,
92 }
93 }
94}