polkadot_collator_protocol/validator_side/
error.rs1use fatality::thiserror::Error;
18use futures::channel::oneshot;
19
20use polkadot_node_subsystem::RuntimeApiError;
21use polkadot_node_subsystem_util::backing_implicit_view;
22use polkadot_primitives::CandidateDescriptorVersion;
23
24pub type Result<T> = std::result::Result<T, Error>;
26
27#[derive(Error, Debug)]
29pub enum Error {
30 #[error(transparent)]
31 ImplicitViewFetchError(backing_implicit_view::FetchError),
32
33 #[error("Response receiver for active validators request cancelled")]
34 CancelledActiveValidators(oneshot::Canceled),
35
36 #[error("Response receiver for validator groups request cancelled")]
37 CancelledValidatorGroups(oneshot::Canceled),
38
39 #[error("Response receiver for session index request cancelled")]
40 CancelledSessionIndex(oneshot::Canceled),
41
42 #[error("Response receiver for claim queue request cancelled")]
43 CancelledClaimQueue(oneshot::Canceled),
44
45 #[error("Response receiver for node features request cancelled")]
46 CancelledNodeFeatures(oneshot::Canceled),
47
48 #[error("No state for the relay parent")]
49 RelayParentStateNotFound,
50
51 #[error("Error while accessing Runtime API")]
52 RuntimeApi(#[from] RuntimeApiError),
53}
54
55#[derive(Debug, Error)]
57pub enum SecondingError {
58 #[error("Error while accessing Runtime API")]
59 RuntimeApi(#[from] RuntimeApiError),
60
61 #[error("Response receiver for persisted validation data request cancelled")]
62 CancelledRuntimePersistedValidationData(oneshot::Canceled),
63
64 #[error("Response receiver for prospective validation data request cancelled")]
65 CancelledProspectiveValidationData(oneshot::Canceled),
66
67 #[error("Persisted validation data is not available")]
68 PersistedValidationDataNotFound,
69
70 #[error("Persisted validation data hash doesn't match one in the candidate receipt.")]
71 PersistedValidationDataMismatch,
72
73 #[error("Candidate hash doesn't match the advertisement")]
74 CandidateHashMismatch,
75
76 #[error("Relay parent hash doesn't match the advertisement")]
77 RelayParentMismatch,
78
79 #[error("Received duplicate collation from the peer")]
80 Duplicate,
81
82 #[error("The provided parent head data does not match the hash")]
83 ParentHeadDataMismatch,
84
85 #[error("Core index {0} present in descriptor is different than the assigned core {1}")]
86 InvalidCoreIndex(u32, u32),
87
88 #[error("Session index {0} present in descriptor is different than the expected one {1}")]
89 InvalidSessionIndex(u32, u32),
90
91 #[error("Invalid candidate receipt version {0:?}")]
92 InvalidReceiptVersion(CandidateDescriptorVersion),
93}
94
95impl SecondingError {
96 pub fn is_malicious(&self) -> bool {
98 use SecondingError::*;
99 matches!(
100 self,
101 PersistedValidationDataMismatch |
102 CandidateHashMismatch |
103 RelayParentMismatch |
104 ParentHeadDataMismatch |
105 InvalidCoreIndex(_, _) |
106 InvalidSessionIndex(_, _) |
107 InvalidReceiptVersion(_)
108 )
109 }
110}
111
112#[derive(Debug, Error)]
114pub enum FetchError {
115 #[error("Collation was not previously advertised")]
116 NotAdvertised,
117
118 #[error("Peer is unknown")]
119 UnknownPeer,
120
121 #[error("Collation was already requested")]
122 AlreadyRequested,
123
124 #[error("Relay parent went out of view")]
125 RelayParentOutOfView,
126
127 #[error("Peer's protocol doesn't match the advertisement")]
128 ProtocolMismatch,
129}