referrerpolicy=no-referrer-when-downgrade

sc_consensus_beefy/
error.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! BEEFY gadget specific errors
20//!
21//! Used for BEEFY gadget internal error handling only
22
23use sp_blockchain::Error as ClientError;
24use std::fmt::Debug;
25
26#[derive(Debug, thiserror::Error)]
27pub enum Error {
28	#[error("Backend: {0}")]
29	Backend(String),
30	#[error("Keystore error: {0}")]
31	Keystore(String),
32	#[error("Runtime api error: {0}")]
33	RuntimeApi(sp_api::ApiError),
34	#[error("Signature error: {0}")]
35	Signature(String),
36	#[error("Session uninitialized")]
37	UninitSession,
38	#[error("pallet-beefy was reset")]
39	ConsensusReset,
40	#[error("Block import stream terminated")]
41	BlockImportStreamTerminated,
42	#[error("Gossip Engine terminated")]
43	GossipEngineTerminated,
44	#[error("Finality proofs gossiping stream terminated")]
45	FinalityProofGossipStreamTerminated,
46	#[error("Finality stream terminated")]
47	FinalityStreamTerminated,
48	#[error("Votes gossiping stream terminated")]
49	VotesGossipStreamTerminated,
50}
51
52impl From<ClientError> for Error {
53	fn from(e: ClientError) -> Self {
54		Self::Backend(e.to_string())
55	}
56}
57
58#[cfg(test)]
59impl PartialEq for Error {
60	fn eq(&self, other: &Self) -> bool {
61		match (self, other) {
62			(Error::Backend(s1), Error::Backend(s2)) => s1 == s2,
63			(Error::Keystore(s1), Error::Keystore(s2)) => s1 == s2,
64			(Error::RuntimeApi(_), Error::RuntimeApi(_)) => true,
65			(Error::Signature(s1), Error::Signature(s2)) => s1 == s2,
66			(Error::UninitSession, Error::UninitSession) => true,
67			(Error::ConsensusReset, Error::ConsensusReset) => true,
68			_ => false,
69		}
70	}
71}