kaspa_consensus/processes/reachability/
mod.rs1mod extensions;
2pub mod inquirer;
3pub mod interval;
4mod reindex;
5pub mod tests;
6mod tree;
7
8use kaspa_database::prelude::StoreError;
9use thiserror::Error;
10
11#[derive(Error, Debug)]
12pub enum ReachabilityError {
13 #[error("data store error")]
14 StoreError(#[from] StoreError),
15
16 #[error("data overflow error")]
17 DataOverflow(String),
18
19 #[error("data inconsistency error")]
20 DataInconsistency,
21
22 #[error("query is inconsistent")]
23 BadQuery,
24}
25
26impl ReachabilityError {
27 pub fn is_key_not_found(&self) -> bool {
28 matches!(self, ReachabilityError::StoreError(e) if matches!(e, StoreError::KeyNotFound(_)))
29 }
30}
31
32pub type Result<T> = std::result::Result<T, ReachabilityError>;
33
34pub trait ReachabilityResultExtensions<T> {
35 fn unwrap_option(self) -> Option<T>;
37}
38
39impl<T> ReachabilityResultExtensions<T> for Result<T> {
40 fn unwrap_option(self) -> Option<T> {
41 match self {
42 Ok(value) => Some(value),
43 Err(err) if err.is_key_not_found() => None,
44 Err(err) => panic!("Unexpected reachability error: {err:?}"),
45 }
46 }
47}