cometbft_light_client_detector/
error.rs

1use cometbft::{block::Height, Hash, Time};
2use cometbft_light_client::components::io::IoError;
3use cometbft_light_client::errors::Error as LightClientError;
4use cometbft_light_client::verifier::types::LightBlock;
5
6use crate::conflict::GatheredEvidence;
7
8flex_error::define_error! {
9    /// Error type for the light client detector. See [`ErrorDetail`] for all the possible error variants.
10    ///
11    /// All the possible error variants.
12    #[derive(Debug)]
13    Error {
14        Io
15            [ IoError ]
16            |_| { "I/O error" },
17
18        LightClient
19            [ LightClientError ]
20            |_| { "light client error" },
21
22        NoDivergence
23            |_| { "expected divergence between conflicting headers but none found" },
24
25        Divergence
26            {
27                evidence: GatheredEvidence,
28                challenging_block: LightBlock,
29            }
30            |e| { format_args!("divergence detected, found evidence: {:#?}", e.evidence) },
31
32        NoWitnesses
33            |_| { "no witnesses provided" },
34
35        BadWitness
36            |_| { "bad witness" },
37
38        TargetBlockLowerThanTrusted
39            {
40                target_height: Height,
41                trusted_height: Height,
42            }
43            |e| {
44                format_args!(
45                    "target block height ({}) lower than trusted block height ({})",
46                    e.target_height, e.trusted_height
47                )
48            },
49
50        TrustedHashDifferentFromSourceFirstBlock
51            {
52                expected_hash: Hash,
53                got_hash: Hash,
54            }
55            |e| {
56                format_args!(
57                    "trusted block is different to the source's first block. Expected hash: {}, got: {}",
58                    e.expected_hash, e.got_hash
59                )
60            },
61
62        TraceTooShort
63            {
64                trace: Vec<LightBlock>,
65            }
66            |e| {
67                format_args!(
68                    "trace is too short. Expected at least 2 blocks, got {} block",
69                    e.trace.len()
70                )
71            },
72
73        TraceBlockAfterTargetBlock
74            {
75                trace_time: Time,
76                target_time: Time,
77            }
78            |e| {
79                format_args!(
80                    "trace block ({}) is after target block ({})",
81                    e.trace_time, e.target_time
82                )
83            },
84
85        FailedHeaderCrossReferencing
86            |_| { format_args!("failed to cross-reference header with witness") },
87    }
88}