referrerpolicy=no-referrer-when-downgrade

polkadot_collator_protocol/validator_side/
error.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17use 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
24/// General result.
25pub type Result<T> = std::result::Result<T, Error>;
26
27/// General subsystem error.
28#[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/// An error occurred when attempting to start seconding a candidate.
56#[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	/// Returns true if an error indicates that a peer is malicious.
97	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/// Failed to request a collation due to an error.
113#[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}