referrerpolicy=no-referrer-when-downgrade

polkadot_dispute_distribution/receiver/
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//
17
18//! Error handling related code and Error/Result definitions.
19
20use fatality::Nested;
21
22use gum::CandidateHash;
23use polkadot_node_network_protocol::{request_response::incoming, PeerId};
24use polkadot_node_subsystem_util::runtime;
25use polkadot_primitives::AuthorityDiscoveryId;
26
27use crate::LOG_TARGET;
28
29#[allow(missing_docs)]
30#[fatality::fatality(splitable)]
31pub enum Error {
32	#[fatal(forward)]
33	#[error("Error while accessing runtime information")]
34	Runtime(#[from] runtime::Error),
35
36	#[fatal(forward)]
37	#[error("Retrieving next incoming request failed.")]
38	IncomingRequest(#[from] incoming::Error),
39
40	#[error("Sending back response to peers {0:#?} failed.")]
41	SendResponses(Vec<PeerId>),
42
43	#[error("Changing peer's ({0}) reputation failed.")]
44	SetPeerReputation(PeerId),
45
46	#[error("Dispute request with invalid signatures, from peer {0}.")]
47	InvalidSignature(PeerId),
48
49	#[error("Received votes from peer {0} have been completely redundant.")]
50	RedundantMessage(PeerId),
51
52	#[error("Import of dispute got canceled for candidate {0} - import failed for some reason.")]
53	ImportCanceled(CandidateHash),
54
55	#[error("Peer {0} attempted to participate in dispute and is not a validator.")]
56	NotAValidator(PeerId),
57
58	#[error("Force flush for batch that could not be found attempted, candidate hash: {0}")]
59	ForceFlushBatchDoesNotExist(CandidateHash),
60
61	// Should never happen in practice:
62	#[error("We needed to drop messages, because we reached limit on concurrent batches.")]
63	MaxBatchLimitReached,
64
65	#[error("Authority {0} sent messages at a too high rate.")]
66	AuthorityFlooding(AuthorityDiscoveryId),
67}
68
69pub type Result<T> = std::result::Result<T, Error>;
70
71pub type JfyiResult<T> = std::result::Result<T, JfyiError>;
72
73/// Utility for eating top level errors and log them.
74///
75/// We basically always want to try and continue on error. This utility function is meant to
76/// consume top-level errors by simply logging them.
77pub fn log_error(result: Result<()>) -> std::result::Result<(), FatalError> {
78	match result.into_nested()? {
79		Err(error @ JfyiError::ImportCanceled(_)) => {
80			gum::debug!(target: LOG_TARGET, error = ?error);
81			Ok(())
82		},
83		Err(JfyiError::NotAValidator(peer)) => {
84			gum::debug!(
85				target: LOG_TARGET,
86				?peer,
87				"Dropping message from peer (unknown authority id)"
88			);
89			Ok(())
90		},
91		Err(error) => {
92			gum::warn!(target: LOG_TARGET, error = ?error);
93			Ok(())
94		},
95		Ok(()) => Ok(()),
96	}
97}