1use std::io;
2
3use chia_consensus::validation_error::ErrorCode;
4#[cfg(feature = "serde")]
5use chia_protocol::Bytes32;
6use chia_sdk_signer::SignerError;
7use thiserror::Error;
8
9#[derive(Debug, Error)]
10pub enum SimulatorError {
11 #[error("IO error: {0}")]
12 Io(#[from] io::Error),
13
14 #[error("Validation error: {0:?}")]
15 Validation(ErrorCode),
16
17 #[error("Signer error: {0}")]
18 Signer(#[from] SignerError),
19
20 #[error("Missing key")]
21 MissingKey,
22
23 #[error(transparent)]
24 ChainState(#[from] ChainStateError),
25
26 #[cfg(feature = "serde")]
27 #[error(transparent)]
28 StateDump(#[from] StateDumpError),
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
32pub enum ChainStateError {
33 #[error("canonical height has no tip header")]
34 MissingTipHeader,
35
36 #[error("canonical tip block is missing")]
37 MissingTipBlock,
38
39 #[error("block height does not extend the canonical chain")]
40 InvalidBlockHeight,
41
42 #[error("block previous hash does not match the canonical tip")]
43 InvalidPreviousHash,
44
45 #[error("block timestamp does not match the next timestamp")]
46 InvalidBlockTimestamp,
47
48 #[error("block header is already canonical")]
49 DuplicateBlockHeader,
50
51 #[error("block is not the canonical tip")]
52 BlockIsNotTip,
53
54 #[error("block delta changes a coin more than once")]
55 DuplicateCoinChange,
56
57 #[error("block delta changes a coin spend more than once")]
58 DuplicateSpendChange,
59
60 #[error("block delta changes a coin hint more than once")]
61 DuplicateHintChange,
62
63 #[error("coin state does not match block delta")]
64 CoinStateMismatch,
65
66 #[error("coin spend state does not match block delta")]
67 CoinSpendStateMismatch,
68
69 #[error("coin hint state does not match block delta")]
70 CoinHintStateMismatch,
71}
72
73#[cfg(feature = "serde")]
74#[derive(Debug, Error)]
75pub enum StateDumpError {
76 #[error("failed to serialize simulator state: {0}")]
77 Serialize(String),
78
79 #[error("failed to deserialize simulator state: {0}")]
80 Deserialize(String),
81
82 #[error("missing canonical block {0}")]
83 MissingCanonicalBlock(Bytes32),
84
85 #[error("cannot dump state with canonical spend of unsupported manual coin {0}")]
86 UnsupportedManualCoinSpend(Bytes32),
87
88 #[error("block key {block_key} does not match record header hash {record_header_hash}")]
89 BlockHeaderMismatch {
90 block_key: Bytes32,
91 record_header_hash: Bytes32,
92 },
93
94 #[error("canonical block is missing a timestamp")]
95 MissingBlockTimestamp,
96
97 #[error("{0} contain a duplicate key")]
98 DuplicateKey(&'static str),
99
100 #[error("previous coin record does not match replayed state for {0}")]
101 PreviousCoinRecordMismatch(Bytes32),
102
103 #[error("previous coin records contain an unchanged coin")]
104 PreviousCoinRecordForUnchangedCoin,
105
106 #[error("missing final coin record for addition {0}")]
107 MissingFinalCoinRecord(Bytes32),
108
109 #[error("added coin record is inconsistent with block {0}")]
110 InconsistentAddedCoinRecord(u32),
111
112 #[error("block removes unknown coin {0}")]
113 UnknownRemovedCoin(Bytes32),
114
115 #[error("block spends contain a duplicate coin")]
116 DuplicateBlockSpend,
117
118 #[error("block spend is not listed as a removal")]
119 SpendNotRemoval,
120
121 #[error("coin spend does not match final index for {0}")]
122 CoinSpendIndexMismatch(Bytes32),
123
124 #[error("block hint is not for an added coin")]
125 HintNotAddition,
126
127 #[error("missing final hint for coin {0}")]
128 MissingFinalHint(Bytes32),
129
130 #[error("coin hint does not match canonical transaction for {0}")]
131 CoinHintMismatch(Bytes32),
132
133 #[error("block additions do not match canonical transactions")]
134 BlockAdditionsMismatch,
135
136 #[error("block removals do not match canonical transactions")]
137 BlockRemovalsMismatch,
138
139 #[error("block spends do not match canonical transactions")]
140 BlockSpendsMismatch,
141
142 #[error("block hints do not match canonical transactions")]
143 BlockHintsMismatch,
144
145 #[error("serialized {0} do not match canonical blocks")]
146 SerializedIndexMismatch(&'static str),
147
148 #[error("unsupported full node simulator state format {0}")]
149 UnsupportedFormat(String),
150
151 #[error("unsupported full node simulator state version {0}")]
152 UnsupportedVersion(u32),
153
154 #[error("height {height} does not match {header_count} header hashes")]
155 HeightHeaderCountMismatch { height: u32, header_count: usize },
156
157 #[error("{header_count} canonical headers do not match {block_count} blocks")]
158 HeaderBlockCountMismatch {
159 header_count: usize,
160 block_count: usize,
161 },
162
163 #[error("coin record key does not match coin id {0}")]
164 CoinRecordKeyMismatch(Bytes32),
165
166 #[error("coin spend key does not match coin id {0}")]
167 CoinSpendKeyMismatch(Bytes32),
168
169 #[error("invalid master secret key: {0}")]
170 InvalidMasterSecretKey(String),
171
172 #[error("canonical genesis block is missing a timestamp")]
173 MissingGenesisTimestamp,
174
175 #[error("canonical block ordering does not match header hashes")]
176 CanonicalBlockOrderMismatch,
177
178 #[error("replayed height does not match serialized height")]
179 ReplayedHeightMismatch,
180
181 #[error("next timestamp does not follow the canonical blocks")]
182 NextTimestampMismatch,
183}