polkadot_dispute_distribution/receiver/
error.rs1use 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 #[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
73pub 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}