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
use std::fmt;
/// Errors that can occur while creating or applying a state delta.
///
/// Delta application can fail when the delta is incompatible with the target
/// state or when the delta payload cannot be interpreted or applied safely.
/// This error type distinguishes fork-specific incompatibilities from
/// malformed delta data.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
/// The delta was created for a different Ethereum consensus fork than
/// the state it is being applied to.
///
/// A delta must only be applied to a state from the same fork because
/// state fields and their SSZ layouts may differ between forks.
ForkMismatch {
/// Fork of the state receiving the delta.
state_fork: crate::ForkName,
/// Fork for which the delta was created.
delta_fork: crate::ForkName,
},
/// The delta contains a field that is not part of the target fork's
/// state representation.
///
/// This generally indicates an incorrectly constructed delta or an
/// attempt to apply a delta using the wrong fork-specific schema.
InvalidFieldForFork {
/// Name of the field included in the delta.
field: &'static str,
/// Fork against which the field was validated.
fork: crate::ForkName,
},
/// The delta is structurally valid enough to decode, but its contents
/// are inconsistent or incompatible with the state to which it is
/// being applied.
InvalidDelta(String),
/// The delta payload cannot be decoded or does not contain the data
/// required to apply it safely.
///
/// This includes malformed or corrupted serialized data, truncated or
/// otherwise invalid encoded payloads, and failures encountered while
/// decoding compressed delta data.
MalformedDelta(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ForkMismatch {
state_fork,
delta_fork,
} => {
write!(
f,
"Fork mismatch: cannot apply {delta_fork:?} delta to {state_fork:?} state",
)
}
Self::InvalidFieldForFork { field, fork } => {
write!(f, "Field '{field}' is invalid for fork {fork:?}")
}
Self::InvalidDelta(message) => {
write!(f, "Invalid delta: {message}")
}
Self::MalformedDelta(message) => {
write!(f, "Malformed delta payload: {message}")
}
}
}
}
impl std::error::Error for Error {}