Repository navigation
Expand file tree
/
Copy patherror.rs
More file actions
207 lines (195 loc) · 6.15 KB
/
Copy patherror.rs
File metadata and controls
207 lines (195 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//! Errors of block connection, disconnection and sync.
use bitcoin_jsonrpsee::jsonrpsee;
use error_fatality::{Fatality, Split};
use sneed::{db, env, rwtxn};
use thiserror::Error;
use transitive::Transitive;
use crate::{
errors::Splittable,
validator::{dbs, main_rest_client::MainRestClientError, parse_block_files},
};
#[derive(Debug, Error, Transitive)]
#[expect(clippy::duplicated_attributes)]
#[transitive(from(db::error::Get, db::Error), from(db::error::TryGet, db::Error))]
pub(in crate::validator::task) enum ValidateTransactionInner {
#[error(transparent)]
Db(Box<db::Error>),
#[error(transparent)]
NestedWriteTxn(#[from] env::error::NestedWriteTxn),
#[error("No chain tip")]
NoChainTip,
}
impl From<db::Error> for ValidateTransactionInner {
fn from(err: db::Error) -> Self {
Self::Db(Box::new(err))
}
}
#[derive(Debug, Error)]
#[error(transparent)]
#[repr(transparent)]
pub struct ValidateTransaction(ValidateTransactionInner);
impl<Err> From<Err> for ValidateTransaction
where
ValidateTransactionInner: From<Err>,
{
fn from(err: Err) -> Self {
Self(err.into())
}
}
#[derive(Debug, Error, Fatality, Split, Transitive)]
#[expect(clippy::duplicated_attributes)]
#[split(attrs(derive(Debug, Error)))]
#[transitive(
from(db::error::Delete, db::Error),
from(db::error::First, db::Error),
from(db::error::Get, db::Error),
from(db::error::Len, db::Error),
from(db::error::Put, db::Error),
from(db::error::TryGet, db::Error)
)]
pub(in crate::validator) enum ConnectBlock {
#[error("Block parent `{parent}` does not match tip `{tip}` at height {tip_height}")]
#[fatal(false)]
BlockParent {
parent: bitcoin::BlockHash,
tip: bitcoin::BlockHash,
tip_height: u32,
},
#[error(transparent)]
#[fatal(true)]
Db(Box<db::Error>),
#[error("Block has no transactions (missing coinbase)")]
#[fatal(false)]
NoCoinbase,
#[error(transparent)]
#[fatal(true)]
PutBlockInfo(#[from] dbs::block_hash_dbs_error::PutBlockInfo),
}
impl From<db::Error> for ConnectBlock {
fn from(err: db::Error) -> Self {
Self::Db(Box::new(err))
}
}
#[derive(Debug, Error, Transitive)]
#[expect(clippy::duplicated_attributes)]
#[transitive(
from(db::error::Delete, db::Error),
from(db::error::Get, db::Error),
from(db::error::Put, db::Error),
from(db::error::TryGet, db::Error)
)]
pub(in crate::validator) enum DisconnectBlock {
#[error(transparent)]
Db(Box<db::Error>),
#[error(transparent)]
GetHeaderInfo(#[from] dbs::block_hash_dbs_error::GetHeaderInfo),
#[error("Block hash `{block_hash}` does not match tip `{tip_hash}`")]
TipHash {
block_hash: bitcoin::BlockHash,
tip_hash: bitcoin::BlockHash,
},
#[error(transparent)]
Undo(#[from] dbs::diff::UndoError),
}
impl From<db::Error> for DisconnectBlock {
fn from(err: db::Error) -> Self {
Self::Db(Box::new(err))
}
}
#[derive(Debug, Error, Fatality, Split, Transitive)]
#[expect(clippy::duplicated_attributes)]
#[split(attrs(derive(Debug, Error)))]
#[transitive(
from(db::error::Get, db::Error),
from(db::error::Put, db::Error),
from(db::error::TryGet, db::Error),
from(env::error::ReadTxn, env::Error),
from(env::error::WriteTxn, env::Error)
)]
pub(in crate::validator) enum Sync {
#[error("Batch JSON RPC error: {}", .errors.join(", "))]
#[fatal(true)]
BatchJsonRpc { errors: Vec<String> },
#[error(transparent)]
#[fatal(true)]
BlockDirectoryParser(#[from] parse_block_files::BlockDirectoryParserError),
#[error("failed to set byte offset in block file parser")]
#[fatal(true)]
BlockFileParserSetOffset(#[source] std::io::Error),
#[error("Block not in active chain: `{block_hash}`")]
#[fatal(true)]
BlockNotInActiveChain { block_hash: bitcoin::BlockHash },
#[error(transparent)]
#[fatal(true)]
CommitWriteTxn(#[from] rwtxn::error::Commit),
#[error(transparent)]
#[fatal(forward)]
ConnectBlock(Box<Splittable<ConnectBlock>>),
#[error(transparent)]
#[fatal(true)]
Db(#[from] db::Error),
#[error(transparent)]
#[fatal(false)]
Decode(#[from] bitcoin::consensus::encode::Error),
#[error(transparent)]
#[fatal(false)]
DeserializeHex(#[from] bitcoin::consensus::encode::FromHexError),
#[error(transparent)]
#[fatal(true)]
DisconnectBlock(#[from] DisconnectBlock),
#[error(transparent)]
#[fatal(true)]
Env(#[from] env::Error),
#[error(transparent)]
#[fatal(true)]
FetchBlockIndex(#[from] parse_block_files::FetchBlockIndexError),
#[error(transparent)]
#[fatal(true)]
GetHeaderInfo(#[from] dbs::block_hash_dbs_error::GetHeaderInfo),
#[error("Header sync already in progress")]
#[fatal(false)]
HeaderSyncInProgress,
#[error(transparent)]
#[fatal(false)]
Hex(#[from] hex::FromHexError),
#[error("JSON RPC error (`{method}`)")]
#[fatal(true)]
JsonRpc {
method: String,
source: jsonrpsee::core::ClientError,
},
#[error("JSON serialization error")]
#[fatal(true)]
JsonSerialize(#[source] serde_json::Error),
#[error(transparent)]
#[fatal(true)]
LastCommonAncestor(#[from] dbs::block_hash_dbs_error::LastCommonAncestor),
#[error(transparent)]
#[fatal(true)]
MissingBackgroundChainstate(#[from] super::chainstates::MissingBackgroundChainstate),
#[error(transparent)]
#[fatal(true)]
NestedWriteTxn(#[from] env::error::NestedWriteTxn),
#[error(transparent)]
#[fatal(true)]
ParseBlockFiles(#[from] parse_block_files::ParseBlockFileError),
#[error(transparent)]
#[fatal(true)]
Rest(#[from] MainRestClientError),
#[error("Shutdown signal received")]
#[fatal(true)]
Shutdown,
#[error(
"the node is background-validating an assumeutxo snapshot with base block \
`{snapshot_blockhash}`, but that header is not in the enforcer's database"
)]
#[fatal(true)]
SnapshotBaseHeaderUnknown {
snapshot_blockhash: bitcoin::BlockHash,
},
}
impl From<ConnectBlock> for Sync {
fn from(err: ConnectBlock) -> Self {
Self::ConnectBlock(Box::new(Splittable(err)))
}
}