referrerpolicy=no-referrer-when-downgrade

substrate_relay_helper/cli/
detect_equivocations.rs

1// Copyright 2019-2023 Parity Technologies (UK) Ltd.
2// This file is part of Parity Bridges Common.
3
4// Parity Bridges Common 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// Parity Bridges Common 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 Parity Bridges Common.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Primitives for exposing the equivocation detection functionality in the CLI.
18
19use crate::{
20	cli::{bridge::*, chain_schema::*, PrometheusParams},
21	equivocation,
22	equivocation::SubstrateEquivocationDetectionPipeline,
23};
24
25use async_trait::async_trait;
26use clap::Parser;
27use relay_substrate_client::{ChainWithTransactions, Client};
28
29/// Start equivocation detection loop.
30#[derive(Parser)]
31pub struct DetectEquivocationsParams {
32	#[command(flatten)]
33	source: SourceConnectionParams,
34	#[command(flatten)]
35	source_sign: SourceSigningParams,
36	#[command(flatten)]
37	target: TargetConnectionParams,
38	#[command(flatten)]
39	prometheus_params: PrometheusParams,
40}
41
42/// Trait used for starting the equivocation detection loop between 2 chains.
43#[async_trait]
44pub trait EquivocationsDetector: RelayToRelayEquivocationDetectionCliBridge
45where
46	Self::Source: ChainWithTransactions,
47{
48	/// Start the equivocation detection loop.
49	async fn start(data: DetectEquivocationsParams) -> anyhow::Result<()> {
50		let source_client = data.source.into_client::<Self::Source>().await?;
51		Self::Equivocation::start_relay_guards(
52			&source_client,
53			source_client.can_start_version_guard(),
54		)
55		.await?;
56
57		equivocation::run::<Self::Equivocation>(
58			source_client,
59			data.target.into_client::<Self::Target>().await?,
60			data.source_sign.transaction_params::<Self::Source>()?,
61			data.prometheus_params.into_metrics_params()?,
62		)
63		.await
64	}
65}