referrerpolicy=no-referrer-when-downgrade

polkadot_node_core_backing/
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 std::collections::HashMap;
18
19use fatality::Nested;
20use futures::channel::{mpsc, oneshot};
21
22use polkadot_node_subsystem::{
23	messages::{StoreAvailableDataError, ValidationFailed},
24	RuntimeApiError, SubsystemError,
25};
26use polkadot_node_subsystem_util::{runtime, Error as UtilError};
27use polkadot_primitives::{BackedCandidate, ValidationCodeHash};
28
29use crate::{ParaId, LOG_TARGET};
30
31pub type Result<T> = std::result::Result<T, Error>;
32pub type FatalResult<T> = std::result::Result<T, FatalError>;
33
34/// Errors that can occur in candidate backing.
35#[allow(missing_docs)]
36#[fatality::fatality(splitable)]
37pub enum Error {
38	#[fatal]
39	#[error("Failed to spawn background task")]
40	FailedToSpawnBackgroundTask,
41
42	#[fatal(forward)]
43	#[error("Error while accessing runtime information")]
44	Runtime(#[from] runtime::Error),
45
46	#[fatal]
47	#[error(transparent)]
48	BackgroundValidationMpsc(#[from] mpsc::SendError),
49
50	#[error("Candidate is not found")]
51	CandidateNotFound,
52
53	#[error("CoreIndex cannot be determined for a candidate")]
54	CoreIndexUnavailable,
55
56	#[error("Signature is invalid")]
57	InvalidSignature,
58
59	#[error("Failed to send candidates {0:?}")]
60	Send(HashMap<ParaId, Vec<BackedCandidate>>),
61
62	#[error("FetchPoV failed")]
63	FetchPoV,
64
65	#[error("Fetching validation code by hash failed {0:?}, {1:?}")]
66	FetchValidationCode(ValidationCodeHash, RuntimeApiError),
67
68	#[error("Fetching Runtime API version failed {0:?}")]
69	FetchRuntimeApiVersion(RuntimeApiError),
70
71	#[error("No validation code {0:?}")]
72	NoValidationCode(ValidationCodeHash),
73
74	#[error("Candidate rejected by prospective parachains subsystem")]
75	RejectedByProspectiveParachains,
76
77	#[error("ValidateFromExhaustive channel closed before receipt")]
78	ValidateFromExhaustive(#[source] oneshot::Canceled),
79
80	#[error("StoreAvailableData channel closed before receipt")]
81	StoreAvailableDataChannel(#[source] oneshot::Canceled),
82
83	#[error("RuntimeAPISubsystem channel closed before receipt")]
84	RuntimeApiUnavailable(#[source] oneshot::Canceled),
85
86	#[error("a channel was closed before receipt in try_join!")]
87	#[fatal]
88	JoinMultiple(#[source] oneshot::Canceled),
89
90	#[error("Obtaining erasure chunks failed")]
91	ObtainErasureChunks(#[from] polkadot_erasure_coding::Error),
92
93	#[error(transparent)]
94	ValidationFailed(#[from] ValidationFailed),
95
96	#[error(transparent)]
97	UtilError(#[from] UtilError),
98
99	#[error(transparent)]
100	SubsystemError(#[from] SubsystemError),
101
102	#[fatal]
103	#[error(transparent)]
104	OverseerExited(SubsystemError),
105
106	#[error("Availability store error")]
107	StoreAvailableData(#[source] StoreAvailableDataError),
108
109	#[error("Runtime API returned None for executor params")]
110	MissingExecutorParams,
111}
112
113/// Utility for eating top level errors and log them.
114///
115/// We basically always want to try and continue on error. This utility function is meant to
116/// consume top-level errors by simply logging them
117pub fn log_error(result: Result<()>) -> std::result::Result<(), FatalError> {
118	match result.into_nested()? {
119		Ok(()) => Ok(()),
120		Err(jfyi) => {
121			jfyi.log();
122			Ok(())
123		},
124	}
125}
126
127impl JfyiError {
128	/// Log a `JfyiError`.
129	pub fn log(self) {
130		gum::debug!(target: LOG_TARGET, error = ?self);
131	}
132}