Skip to main content

zebra_chain/parameters/network/
error.rs

1//! Error types for `ParametersBuilder`.
2
3use std::path::PathBuf;
4
5use thiserror::Error;
6
7/// An error that can occur when building `Parameters` using `ParametersBuilder`.
8#[derive(Debug, Error, Clone, PartialEq, Eq)]
9pub enum ParametersBuilderError {
10    #[error("cannot use reserved network name '{network_name}' as configured Testnet name, reserved names: {reserved_names:?}")]
11    #[non_exhaustive]
12    ReservedNetworkName {
13        network_name: String,
14        reserved_names: Vec<&'static str>,
15    },
16
17    #[error("network name {network_name} is too long, must be {max_length} characters or less")]
18    #[non_exhaustive]
19    NetworkNameTooLong {
20        network_name: String,
21        max_length: usize,
22    },
23
24    #[error("network name must include only alphanumeric characters or '_'")]
25    #[non_exhaustive]
26    InvalidCharacter,
27
28    #[error("network magic should be distinct from reserved network magics")]
29    #[non_exhaustive]
30    ReservedNetworkMagic,
31
32    #[error("configured genesis hash must parse")]
33    #[non_exhaustive]
34    InvalidGenesisHash,
35
36    #[error(
37        "activation heights on ParametersBuilder must not be set after setting funding streams"
38    )]
39    #[non_exhaustive]
40    LockFundingStreams,
41
42    #[error("activation height must be valid")]
43    #[non_exhaustive]
44    InvalidActivationHeight,
45
46    #[error("Height(0) is reserved for the `Genesis` upgrade")]
47    #[non_exhaustive]
48    InvalidHeightZero,
49
50    #[error("halving interval must be in 1..=Height::MAX and produce supported halving indices and heights; configured funding streams require a nonzero address period, and reissuance requires a positive NSM coefficient")]
51    #[non_exhaustive]
52    InvalidHalvingInterval,
53
54    #[error("scheduled issuance through the maximum supported height, excluding unspendable genesis issuance, must not exceed MAX_MONEY; early spacing upgrades may require slow_start_interval = 0")]
55    #[non_exhaustive]
56    InvalidSubsidySchedule,
57
58    #[error("network upgrades must be activated in order specified by the protocol")]
59    #[non_exhaustive]
60    OutOfOrderUpgrades,
61
62    /// A configured network upgrade has no consensus branch ID in this build.
63    #[error("network upgrade {upgrade} has no consensus branch ID in this build, so it can't be given an activation height")]
64    #[non_exhaustive]
65    MissingBranchId {
66        /// The configured upgrade with no consensus branch ID.
67        upgrade: crate::parameters::NetworkUpgrade,
68    },
69
70    #[error("difficulty limits are valid expanded values")]
71    #[non_exhaustive]
72    InvaildDifficultyLimits,
73
74    #[error("halving interval on ParametersBuilder must not be set after setting funding streams")]
75    #[non_exhaustive]
76    HalvingIntervalAfterFundingStreams,
77
78    /// A funding stream recipient does not cover the configured address periods.
79    #[error("funding stream recipient {receiver:?} requires {required} addresses, but only {provided} were provided")]
80    #[non_exhaustive]
81    InsufficientFundingStreamAddresses {
82        /// The recipient whose address list is too short.
83        receiver: super::subsidy::FundingStreamReceiver,
84        /// The minimum number of addresses needed for the configured height range.
85        required: usize,
86        /// The number of configured addresses.
87        provided: usize,
88    },
89
90    /// Two nonempty funding stream height ranges overlap after applying inherited defaults.
91    #[error("funding stream height ranges {first:?} and {second:?} overlap")]
92    #[non_exhaustive]
93    OverlappingFundingStreamRanges {
94        /// The earlier configured range in the overlapping pair.
95        first: std::ops::Range<crate::block::Height>,
96        /// The later configured range in the overlapping pair.
97        second: std::ops::Range<crate::block::Height>,
98    },
99
100    /// A non-deferred funding stream recipient uses an address without a supported payment script.
101    #[error("funding stream recipient {receiver:?} uses unsupported address {address}; only P2SH and P2PKH addresses are supported")]
102    #[non_exhaustive]
103    UnsupportedFundingStreamAddress {
104        /// The receiver whose payment cannot be represented by a supported funding stream script.
105        receiver: super::subsidy::FundingStreamReceiver,
106        /// The unsupported address.
107        address: crate::transparent::Address,
108    },
109
110    #[error("checkpoints file format must be valid")]
111    #[non_exhaustive]
112    InvalidCheckpointsFormat,
113
114    #[error("must parse checkpoints")]
115    #[non_exhaustive]
116    FailedToParseDefaultCheckpoint,
117
118    #[error("could not read file at configured checkpoints file path: {path_buf:?}")]
119    #[non_exhaustive]
120    FailedToReadCheckpointFile { path_buf: PathBuf },
121
122    #[error("could not parse checkpoints at the provided path: {path_buf:?}, err: {err}")]
123    #[non_exhaustive]
124    FailedToParseCheckpointFile { path_buf: PathBuf, err: String },
125
126    #[error("configured checkpoints must be valid")]
127    #[non_exhaustive]
128    InvalidCustomCheckpoints,
129
130    #[error("first checkpoint hash must match genesis hash")]
131    #[non_exhaustive]
132    CheckpointGenesisMismatch,
133
134    #[error(
135        "checkpoints must be provided for block heights below the mandatory checkpoint height"
136    )]
137    #[non_exhaustive]
138    InsufficientCheckpointCoverage,
139
140    #[error("the NSM reissuance height must be at or after the NU7 activation height")]
141    #[non_exhaustive]
142    NsmReissuanceHeightBeforeNu7,
143}