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
use anomaly::{BoxError, Context};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::errors::ErrorExt;
use crate::operations::voting_power::VotingPowerTally;
use crate::types::{Hash, Height, Time, Validator, ValidatorAddress};
#[derive(Debug, Clone, Error, PartialEq, Serialize, Deserialize)]
pub enum VerificationError {
#[error("header from the future: header_time={header_time} now={now}")]
HeaderFromTheFuture {
header_time: Time,
now: Time,
},
#[error("implementation specific: {0}")]
ImplementationSpecific(String),
#[error("not enough trust because insufficient validators overlap: {0}")]
NotEnoughTrust(VotingPowerTally),
#[error("insufficient signers overlap: {0}")]
InsufficientSignersOverlap(VotingPowerTally),
#[error("duplicate validator with address {0}")]
DuplicateValidator(ValidatorAddress),
#[error("Couldn't verify signature `{signature:?}` with validator `{validator:?}` on sign_bytes `{sign_bytes:?}`")]
InvalidSignature {
signature: Vec<u8>,
validator: Box<Validator>,
sign_bytes: Vec<u8>,
},
#[error("invalid commit value: header_hash={header_hash} commit_hash={commit_hash}")]
InvalidCommitValue {
#[serde(with = "tendermint::serializers::hash")]
header_hash: Hash,
#[serde(with = "tendermint::serializers::hash")]
commit_hash: Hash,
},
#[error("invalid next validator set: header_next_validators_hash={header_next_validators_hash} next_validators_hash={next_validators_hash}")]
InvalidNextValidatorSet {
#[serde(with = "tendermint::serializers::hash")]
header_next_validators_hash: Hash,
#[serde(with = "tendermint::serializers::hash")]
next_validators_hash: Hash,
},
#[error("invalid validator set: header_validators_hash={header_validators_hash} validators_hash={validators_hash}")]
InvalidValidatorSet {
#[serde(with = "tendermint::serializers::hash")]
header_validators_hash: Hash,
#[serde(with = "tendermint::serializers::hash")]
validators_hash: Hash,
},
#[error("non increasing height: got={got} expected={expected}")]
NonIncreasingHeight {
got: Height,
expected: Height,
},
#[error("non monotonic BFT time: header_bft_time={header_bft_time} trusted_header_bft_time={trusted_header_bft_time}")]
NonMonotonicBftTime {
header_bft_time: Time,
trusted_header_bft_time: Time,
},
#[error("not withing trusting period: expires_at={expires_at} now={now}")]
NotWithinTrustPeriod {
expires_at: Time,
now: Time,
},
}
impl VerificationError {
pub fn context(self, source: impl Into<BoxError>) -> Context<Self> {
Context::new(self, Some(source.into()))
}
}
impl ErrorExt for VerificationError {
fn not_enough_trust(&self) -> bool {
matches!(self, Self::NotEnoughTrust { .. })
}
fn has_expired(&self) -> bool {
matches!(self, Self::NotWithinTrustPeriod { .. })
}
fn is_timeout(&self) -> bool {
false
}
}