zebra_consensus/config.rs
1//! Configuration for semantic verification which is run in parallel.
2
3use serde::{Deserialize, Serialize};
4
5/// Configuration for parallel semantic verification:
6/// <https://zebra.zfnd.org/dev/rfcs/0002-parallel-verification.html#definitions>
7#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
8#[serde(
9 deny_unknown_fields,
10 default,
11 from = "InnerConfig",
12 into = "InnerConfig"
13)]
14pub struct Config {
15 /// Should Zebra make sure that it follows the consensus chain while syncing?
16 /// This is a developer-only option.
17 ///
18 /// # Security
19 ///
20 /// Disabling this option leaves your node vulnerable to some kinds of chain-based attacks.
21 /// Zebra regularly updates its checkpoints to ensure nodes are following the best chain.
22 ///
23 /// # Details
24 ///
25 /// This option is `true` by default, because it prevents some kinds of chain attacks.
26 ///
27 /// Disabling this option makes Zebra start full validation earlier.
28 /// It is slower and less secure.
29 ///
30 /// Zebra requires some checkpoints to simplify validation of legacy network upgrades.
31 /// Required checkpoints are always active, even when this option is `false`.
32 ///
33 /// # Deprecation
34 ///
35 /// For security reasons, this option might be deprecated or ignored in a future Zebra
36 /// release.
37 pub checkpoint_sync: bool,
38}
39
40impl From<InnerConfig> for Config {
41 fn from(
42 InnerConfig {
43 checkpoint_sync, ..
44 }: InnerConfig,
45 ) -> Self {
46 Self { checkpoint_sync }
47 }
48}
49
50impl From<Config> for InnerConfig {
51 fn from(Config { checkpoint_sync }: Config) -> Self {
52 Self {
53 checkpoint_sync,
54 _debug_skip_parameter_preload: false,
55 }
56 }
57}
58
59/// Inner consensus configuration for backwards compatibility with older `zebrad.toml` files,
60/// which contain fields that have been removed.
61///
62/// Rust API callers should use [`Config`].
63#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
64#[serde(deny_unknown_fields, default)]
65pub struct InnerConfig {
66 /// See [`Config`] for more details.
67 pub checkpoint_sync: bool,
68
69 #[serde(skip_serializing, rename = "debug_skip_parameter_preload")]
70 /// Unused config field for backwards compatibility.
71 pub _debug_skip_parameter_preload: bool,
72}
73
74// we like our default configs to be explicit
75#[allow(unknown_lints)]
76#[allow(clippy::derivable_impls)]
77impl Default for Config {
78 fn default() -> Self {
79 Self {
80 checkpoint_sync: true,
81 }
82 }
83}
84
85impl Default for InnerConfig {
86 fn default() -> Self {
87 Self {
88 checkpoint_sync: Config::default().checkpoint_sync,
89 _debug_skip_parameter_preload: false,
90 }
91 }
92}