From 97133678203c1688d1aee6801de0c2788eecd691 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 30 Aug 2023 12:21:37 +0300 Subject: [PATCH] Add subcommand for starting the equivocation detection loop --- .../bridges/rialto-millau/docker-compose.yml | 20 ++++ ...llau-to-rialto-equivocations-entrypoint.sh | 10 ++ ...alto-to-millau-equivocations-entrypoint.sh | 10 ++ .../docker-compose.yml | 20 ++++ ...alto-parachain-equivocations-entrypoint.sh | 10 ++ ...alto-to-millau-equivocations-entrypoint.sh | 10 ++ .../kusama_headers_to_bridge_hub_polkadot.rs | 8 +- ...usama_parachains_to_bridge_hub_polkadot.rs | 12 +- .../polkadot_headers_to_bridge_hub_kusama.rs | 8 +- ...olkadot_parachains_to_bridge_hub_kusama.rs | 12 +- .../rialto_parachains_to_millau.rs | 11 +- .../rococo_headers_to_bridge_hub_wococo.rs | 8 +- .../rococo_parachains_to_bridge_hub_wococo.rs | 10 +- .../wococo_headers_to_bridge_hub_rococo.rs | 8 +- .../wococo_parachains_to_bridge_hub_rococo.rs | 10 +- relays/bin-substrate/src/cli/bridge.rs | 21 +--- .../src/cli/detect_equivocations.rs | 109 ++++++++++++++++++ relays/bin-substrate/src/cli/mod.rs | 5 +- relays/equivocation/src/equivocation_loop.rs | 2 - relays/equivocation/src/lib.rs | 2 + .../src/equivocation/mod.rs | 29 ++++- .../src/equivocation/source.rs | 7 ++ .../src/equivocation/target.rs | 4 + 23 files changed, 269 insertions(+), 77 deletions(-) create mode 100755 deployments/bridges/rialto-millau/entrypoints/detect-millau-to-rialto-equivocations-entrypoint.sh create mode 100755 deployments/bridges/rialto-millau/entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh create mode 100755 deployments/bridges/rialto-parachain-millau/entrypoints/detect-millau-to-rialto-parachain-equivocations-entrypoint.sh create mode 100755 deployments/bridges/rialto-parachain-millau/entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh create mode 100644 relays/bin-substrate/src/cli/detect_equivocations.rs diff --git a/deployments/bridges/rialto-millau/docker-compose.yml b/deployments/bridges/rialto-millau/docker-compose.yml index 7ce33da67c3..cd8431a46bc 100644 --- a/deployments/bridges/rialto-millau/docker-compose.yml +++ b/deployments/bridges/rialto-millau/docker-compose.yml @@ -72,6 +72,26 @@ services: depends_on: - relay-millau-rialto + detect-millau-to-rialto-equivocations: + <<: *sub-bridge-relay + environment: + RUST_LOG: bridge=trace + entrypoint: /entrypoints/detect-millau-to-rialto-equivocations-entrypoint.sh + ports: + - "10517:9616" + depends_on: + - relay-millau-rialto + + detect-rialto-to-millau-equivocations: + <<: *sub-bridge-relay + environment: + RUST_LOG: bridge=trace + entrypoint: /entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh + ports: + - "10518:9616" + depends_on: + - relay-millau-rialto + # Note: These are being overridden from the top level `monitoring` compose file. grafana-dashboard: environment: diff --git a/deployments/bridges/rialto-millau/entrypoints/detect-millau-to-rialto-equivocations-entrypoint.sh b/deployments/bridges/rialto-millau/entrypoints/detect-millau-to-rialto-equivocations-entrypoint.sh new file mode 100755 index 00000000000..7489d89bc3c --- /dev/null +++ b/deployments/bridges/rialto-millau/entrypoints/detect-millau-to-rialto-equivocations-entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -eu + +exec /home/user/substrate-relay detect-equivocations millau-to-rialto \ + --source-host millau-node-alice \ + --source-port 9944 \ + --source-signer //Rialto.HeadersAndMessagesRelay \ + --source-transactions-mortality=64 \ + --target-host rialto-node-alice \ + --target-port 9944 diff --git a/deployments/bridges/rialto-millau/entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh b/deployments/bridges/rialto-millau/entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh new file mode 100755 index 00000000000..b13977691ef --- /dev/null +++ b/deployments/bridges/rialto-millau/entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -eu + +exec /home/user/substrate-relay detect-equivocations rialto-to-millau \ + --source-host rialto-node-alice \ + --source-port 9944 \ + --source-signer //Millau.HeadersAndMessagesRelay \ + --source-transactions-mortality=64 \ + --target-host millau-node-alice \ + --target-port 9944 \ No newline at end of file diff --git a/deployments/bridges/rialto-parachain-millau/docker-compose.yml b/deployments/bridges/rialto-parachain-millau/docker-compose.yml index a62bda52eb3..9fc920bf5cc 100644 --- a/deployments/bridges/rialto-parachain-millau/docker-compose.yml +++ b/deployments/bridges/rialto-parachain-millau/docker-compose.yml @@ -73,6 +73,26 @@ services: depends_on: - relay-messages-millau-to-rialto-parachain-generator + detect-millau-to-rialto-parachain-equivocations: + <<: *sub-bridge-relay + environment: + RUST_LOG: bridge=trace + entrypoint: /entrypoints/detect-millau-to-rialto-parachain-equivocations-entrypoint.sh + ports: + - "11019:9616" + depends_on: + - relay-millau-rialto-parachain-1 + + detect-rialto-to-millau-equivocations: + <<: *sub-bridge-relay + environment: + RUST_LOG: bridge=trace + entrypoint: /entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh + ports: + - "11020:9616" + depends_on: + - relay-millau-rialto-parachain-1 + # Note: These are being overridden from the top level `monitoring` compose file. grafana-dashboard: environment: diff --git a/deployments/bridges/rialto-parachain-millau/entrypoints/detect-millau-to-rialto-parachain-equivocations-entrypoint.sh b/deployments/bridges/rialto-parachain-millau/entrypoints/detect-millau-to-rialto-parachain-equivocations-entrypoint.sh new file mode 100755 index 00000000000..21321c02eb2 --- /dev/null +++ b/deployments/bridges/rialto-parachain-millau/entrypoints/detect-millau-to-rialto-parachain-equivocations-entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -eu + +exec /home/user/substrate-relay detect-equivocations millau-to-rialto-parachain \ + --source-host millau-node-alice \ + --source-port 9944 \ + --source-signer //RialtoParachain.HeadersAndMessagesRelay1 \ + --source-transactions-mortality=64 \ + --target-host rialto-parachain-collator-charlie \ + --target-port 9944 diff --git a/deployments/bridges/rialto-parachain-millau/entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh b/deployments/bridges/rialto-parachain-millau/entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh new file mode 100755 index 00000000000..b13977691ef --- /dev/null +++ b/deployments/bridges/rialto-parachain-millau/entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -eu + +exec /home/user/substrate-relay detect-equivocations rialto-to-millau \ + --source-host rialto-node-alice \ + --source-port 9944 \ + --source-signer //Millau.HeadersAndMessagesRelay \ + --source-transactions-mortality=64 \ + --target-host millau-node-alice \ + --target-port 9944 \ No newline at end of file diff --git a/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs b/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs index c7c613ffd0c..9df949c3e59 100644 --- a/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs +++ b/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs @@ -16,7 +16,9 @@ //! Kusama-to-BridgeHubPolkadot headers sync entrypoint. -use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge}; +use crate::cli::bridge::{ + CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge, +}; use async_trait::async_trait; use relay_substrate_client::{AccountKeyPairOf, Client}; @@ -88,3 +90,7 @@ impl CliBridgeBase for KusamaToBridgeHubPolkadotCliBridge { impl RelayToRelayHeadersCliBridge for KusamaToBridgeHubPolkadotCliBridge { type Finality = KusamaFinalityToBridgeHubPolkadot; } + +impl RelayToRelayEquivocationDetectionCliBridge for KusamaToBridgeHubPolkadotCliBridge { + type Equivocation = KusamaFinalityToBridgeHubPolkadot; +} diff --git a/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_parachains_to_bridge_hub_polkadot.rs b/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_parachains_to_bridge_hub_polkadot.rs index dda19a94d2e..e5936640cb3 100644 --- a/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_parachains_to_bridge_hub_polkadot.rs +++ b/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_parachains_to_bridge_hub_polkadot.rs @@ -16,10 +16,7 @@ //! Kusama-to-BridgeHubPolkadot parachains sync entrypoint. -use crate::cli::bridge::{ - CliBridgeBase, MessagesCliBridge, ParachainToRelayEquivocationDetectionCliBridge, - ParachainToRelayHeadersCliBridge, -}; +use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge}; use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId}; use relay_substrate_client::{CallOf, HeaderIdOf}; use substrate_relay_helper::parachains::{ @@ -67,13 +64,6 @@ impl ParachainToRelayHeadersCliBridge for BridgeHubKusamaToBridgeHubPolkadotCliB crate::bridges::kusama_polkadot::kusama_headers_to_bridge_hub_polkadot::KusamaFinalityToBridgeHubPolkadot; } -impl ParachainToRelayEquivocationDetectionCliBridge - for BridgeHubKusamaToBridgeHubPolkadotCliBridge -{ - type SourceRelay = relay_kusama_client::Kusama; - type RelayEquivocation = crate::bridges::kusama_polkadot::kusama_headers_to_bridge_hub_polkadot::KusamaFinalityToBridgeHubPolkadot; -} - impl CliBridgeBase for BridgeHubKusamaToBridgeHubPolkadotCliBridge { type Source = relay_bridge_hub_kusama_client::BridgeHubKusama; type Target = relay_bridge_hub_polkadot_client::BridgeHubPolkadot; diff --git a/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs b/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs index dbd1f8e38cb..6a323d65a0d 100644 --- a/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs +++ b/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs @@ -16,7 +16,9 @@ //! Polkadot-to-KusamaBridgeHub headers sync entrypoint. -use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge}; +use crate::cli::bridge::{ + CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge, +}; use async_trait::async_trait; use relay_substrate_client::{AccountKeyPairOf, Client}; @@ -88,3 +90,7 @@ impl CliBridgeBase for PolkadotToBridgeHubKusamaCliBridge { impl RelayToRelayHeadersCliBridge for PolkadotToBridgeHubKusamaCliBridge { type Finality = PolkadotFinalityToBridgeHubKusama; } + +impl RelayToRelayEquivocationDetectionCliBridge for PolkadotToBridgeHubKusamaCliBridge { + type Equivocation = PolkadotFinalityToBridgeHubKusama; +} diff --git a/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_parachains_to_bridge_hub_kusama.rs b/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_parachains_to_bridge_hub_kusama.rs index b797cca1962..f2a7f7309cf 100644 --- a/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_parachains_to_bridge_hub_kusama.rs +++ b/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_parachains_to_bridge_hub_kusama.rs @@ -16,10 +16,7 @@ //! Polkadot-to-BridgeHubKusama parachains sync entrypoint. -use crate::cli::bridge::{ - CliBridgeBase, MessagesCliBridge, ParachainToRelayEquivocationDetectionCliBridge, - ParachainToRelayHeadersCliBridge, -}; +use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge}; use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId}; use relay_substrate_client::{CallOf, HeaderIdOf}; use substrate_relay_helper::parachains::{ @@ -67,13 +64,6 @@ impl ParachainToRelayHeadersCliBridge for BridgeHubPolkadotToBridgeHubKusamaCliB crate::bridges::kusama_polkadot::polkadot_headers_to_bridge_hub_kusama::PolkadotFinalityToBridgeHubKusama; } -impl ParachainToRelayEquivocationDetectionCliBridge - for BridgeHubPolkadotToBridgeHubKusamaCliBridge -{ - type SourceRelay = relay_polkadot_client::Polkadot; - type RelayEquivocation = crate::bridges::kusama_polkadot::polkadot_headers_to_bridge_hub_kusama::PolkadotFinalityToBridgeHubKusama; -} - impl CliBridgeBase for BridgeHubPolkadotToBridgeHubKusamaCliBridge { type Source = relay_bridge_hub_polkadot_client::BridgeHubPolkadot; type Target = relay_bridge_hub_kusama_client::BridgeHubKusama; diff --git a/relays/bin-substrate/src/bridges/rialto_parachain_millau/rialto_parachains_to_millau.rs b/relays/bin-substrate/src/bridges/rialto_parachain_millau/rialto_parachains_to_millau.rs index e50e161d866..6b2a1332144 100644 --- a/relays/bin-substrate/src/bridges/rialto_parachain_millau/rialto_parachains_to_millau.rs +++ b/relays/bin-substrate/src/bridges/rialto_parachain_millau/rialto_parachains_to_millau.rs @@ -16,10 +16,7 @@ //! Rialto-to-Millau parachains sync entrypoint. -use crate::cli::bridge::{ - CliBridgeBase, MessagesCliBridge, ParachainToRelayEquivocationDetectionCliBridge, - ParachainToRelayHeadersCliBridge, -}; +use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge}; use relay_millau_client::Millau; use relay_rialto_client::Rialto; use relay_rialto_parachain_client::RialtoParachain; @@ -62,12 +59,6 @@ impl ParachainToRelayHeadersCliBridge for RialtoParachainToMillauCliBridge { crate::bridges::rialto_millau::rialto_headers_to_millau::RialtoFinalityToMillau; } -impl ParachainToRelayEquivocationDetectionCliBridge for RialtoParachainToMillauCliBridge { - type SourceRelay = Rialto; - type RelayEquivocation = - crate::bridges::rialto_millau::rialto_headers_to_millau::RialtoFinalityToMillau; -} - impl MessagesCliBridge for RialtoParachainToMillauCliBridge { type MessagesLane = crate::bridges::rialto_parachain_millau::rialto_parachain_messages_to_millau::RialtoParachainMessagesToMillau; diff --git a/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs b/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs index 6fdca8b182e..6521958cc8a 100644 --- a/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs +++ b/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs @@ -16,7 +16,9 @@ //! Rococo-to-Wococo bridge hubs headers sync entrypoint. -use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge}; +use crate::cli::bridge::{ + CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge, +}; use async_trait::async_trait; use relay_substrate_client::{AccountKeyPairOf, Client}; @@ -88,3 +90,7 @@ impl CliBridgeBase for RococoToBridgeHubWococoCliBridge { impl RelayToRelayHeadersCliBridge for RococoToBridgeHubWococoCliBridge { type Finality = RococoFinalityToBridgeHubWococo; } + +impl RelayToRelayEquivocationDetectionCliBridge for RococoToBridgeHubWococoCliBridge { + type Equivocation = RococoFinalityToBridgeHubWococo; +} diff --git a/relays/bin-substrate/src/bridges/rococo_wococo/rococo_parachains_to_bridge_hub_wococo.rs b/relays/bin-substrate/src/bridges/rococo_wococo/rococo_parachains_to_bridge_hub_wococo.rs index 5f4dc20a78f..b2704c092b8 100644 --- a/relays/bin-substrate/src/bridges/rococo_wococo/rococo_parachains_to_bridge_hub_wococo.rs +++ b/relays/bin-substrate/src/bridges/rococo_wococo/rococo_parachains_to_bridge_hub_wococo.rs @@ -16,10 +16,7 @@ //! Wococo-to-Rococo parachains sync entrypoint. -use crate::cli::bridge::{ - CliBridgeBase, MessagesCliBridge, ParachainToRelayEquivocationDetectionCliBridge, - ParachainToRelayHeadersCliBridge, -}; +use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge}; use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId}; use relay_substrate_client::{CallOf, HeaderIdOf}; use substrate_relay_helper::parachains::{ @@ -67,11 +64,6 @@ impl ParachainToRelayHeadersCliBridge for BridgeHubRococoToBridgeHubWococoCliBri crate::bridges::rococo_wococo::rococo_headers_to_bridge_hub_wococo::RococoFinalityToBridgeHubWococo; } -impl ParachainToRelayEquivocationDetectionCliBridge for BridgeHubRococoToBridgeHubWococoCliBridge { - type SourceRelay = relay_rococo_client::Rococo; - type RelayEquivocation = crate::bridges::rococo_wococo::rococo_headers_to_bridge_hub_wococo::RococoFinalityToBridgeHubWococo; -} - impl CliBridgeBase for BridgeHubRococoToBridgeHubWococoCliBridge { type Source = relay_bridge_hub_rococo_client::BridgeHubRococo; type Target = relay_bridge_hub_wococo_client::BridgeHubWococo; diff --git a/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs b/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs index 22d1d1126bb..5801fda47f6 100644 --- a/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs +++ b/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs @@ -16,7 +16,9 @@ //! Wococo-to-Rococo bridge hubs headers sync entrypoint. -use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge}; +use crate::cli::bridge::{ + CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge, +}; use async_trait::async_trait; use relay_substrate_client::{AccountKeyPairOf, Client}; @@ -88,3 +90,7 @@ impl CliBridgeBase for WococoToBridgeHubRococoCliBridge { impl RelayToRelayHeadersCliBridge for WococoToBridgeHubRococoCliBridge { type Finality = WococoFinalityToBridgeHubRococo; } + +impl RelayToRelayEquivocationDetectionCliBridge for WococoToBridgeHubRococoCliBridge { + type Equivocation = WococoFinalityToBridgeHubRococo; +} diff --git a/relays/bin-substrate/src/bridges/rococo_wococo/wococo_parachains_to_bridge_hub_rococo.rs b/relays/bin-substrate/src/bridges/rococo_wococo/wococo_parachains_to_bridge_hub_rococo.rs index 49e7c19dd42..ca77857833d 100644 --- a/relays/bin-substrate/src/bridges/rococo_wococo/wococo_parachains_to_bridge_hub_rococo.rs +++ b/relays/bin-substrate/src/bridges/rococo_wococo/wococo_parachains_to_bridge_hub_rococo.rs @@ -16,10 +16,7 @@ //! Rococo-to-Wococo parachains sync entrypoint. -use crate::cli::bridge::{ - CliBridgeBase, MessagesCliBridge, ParachainToRelayEquivocationDetectionCliBridge, - ParachainToRelayHeadersCliBridge, -}; +use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge}; use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId}; use relay_substrate_client::{CallOf, HeaderIdOf}; use substrate_relay_helper::parachains::{ @@ -67,11 +64,6 @@ impl ParachainToRelayHeadersCliBridge for BridgeHubWococoToBridgeHubRococoCliBri crate::bridges::rococo_wococo::wococo_headers_to_bridge_hub_rococo::WococoFinalityToBridgeHubRococo; } -impl ParachainToRelayEquivocationDetectionCliBridge for BridgeHubWococoToBridgeHubRococoCliBridge { - type SourceRelay = relay_wococo_client::Wococo; - type RelayEquivocation = crate::bridges::rococo_wococo::wococo_headers_to_bridge_hub_rococo::WococoFinalityToBridgeHubRococo; -} - impl CliBridgeBase for BridgeHubWococoToBridgeHubRococoCliBridge { type Source = relay_bridge_hub_wococo_client::BridgeHubWococo; type Target = relay_bridge_hub_rococo_client::BridgeHubRococo; diff --git a/relays/bin-substrate/src/cli/bridge.rs b/relays/bin-substrate/src/cli/bridge.rs index 37a97b2a57e..88b6fbc5293 100644 --- a/relays/bin-substrate/src/cli/bridge.rs +++ b/relays/bin-substrate/src/cli/bridge.rs @@ -58,7 +58,7 @@ pub trait RelayToRelayHeadersCliBridge: CliBridgeBase { /// Convenience trait that adds bounds to `CliBridgeBase`. pub trait RelayToRelayEquivocationDetectionCliBridgeBase: CliBridgeBase { - type BoundedSourceChain: ChainWithTransactions; + type BoundedSource: ChainWithTransactions; } impl RelayToRelayEquivocationDetectionCliBridgeBase for T @@ -66,7 +66,7 @@ where T: CliBridgeBase, T::Source: ChainWithTransactions, { - type BoundedSourceChain = T::Source; + type BoundedSource = T::Source; } /// Bridge representation that can be used from the CLI for detecting equivocations @@ -105,23 +105,6 @@ where >; } -/// Bridge representation that can be used from the CLI for detecting equivocations -/// in the headers that are synchronized from a parachain to a relay chain. -pub trait ParachainToRelayEquivocationDetectionCliBridge: CliBridgeBase { - // The `CliBridgeBase` type represents the parachain in this situation. - // We need to add an extra type for the relay chain. - type SourceRelay: Chain - + ChainWithTransactions - + CliChain - + RelayChain; - - /// Equivocation detection pipeline (source relay chain -> target). - type RelayEquivocation: SubstrateEquivocationDetectionPipeline< - SourceChain = Self::SourceRelay, - TargetChain = Self::Target, - >; -} - /// Bridge representation that can be used from the CLI for relaying messages. pub trait MessagesCliBridge: CliBridgeBase { /// The Source -> Destination messages synchronization pipeline. diff --git a/relays/bin-substrate/src/cli/detect_equivocations.rs b/relays/bin-substrate/src/cli/detect_equivocations.rs new file mode 100644 index 00000000000..b9e001fd980 --- /dev/null +++ b/relays/bin-substrate/src/cli/detect_equivocations.rs @@ -0,0 +1,109 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Parity Bridges Common. + +// Parity Bridges Common is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity Bridges Common is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity Bridges Common. If not, see . + +use async_trait::async_trait; +use relay_substrate_client::ChainWithTransactions; +use structopt::StructOpt; +use strum::{EnumString, EnumVariantNames, VariantNames}; + +use crate::bridges::{ + kusama_polkadot::{ + kusama_headers_to_bridge_hub_polkadot::KusamaToBridgeHubPolkadotCliBridge, + polkadot_headers_to_bridge_hub_kusama::PolkadotToBridgeHubKusamaCliBridge, + }, + rialto_millau::{ + millau_headers_to_rialto::MillauToRialtoCliBridge, + rialto_headers_to_millau::RialtoToMillauCliBridge, + }, + rialto_parachain_millau::millau_headers_to_rialto_parachain::MillauToRialtoParachainCliBridge, + rococo_wococo::{ + rococo_headers_to_bridge_hub_wococo::RococoToBridgeHubWococoCliBridge, + wococo_headers_to_bridge_hub_rococo::WococoToBridgeHubRococoCliBridge, + }, +}; +use substrate_relay_helper::equivocation; + +use crate::cli::{bridge::*, chain_schema::*}; + +/// Start equivocation detection loop. +#[derive(StructOpt)] +pub struct DetectEquivocations { + #[structopt(possible_values = DetectEquivocationsBridge::VARIANTS, case_insensitive = true)] + bridge: DetectEquivocationsBridge, + #[structopt(flatten)] + source: SourceConnectionParams, + #[structopt(flatten)] + source_sign: SourceSigningParams, + #[structopt(flatten)] + target: TargetConnectionParams, +} + +#[derive(Debug, EnumString, EnumVariantNames)] +#[strum(serialize_all = "kebab_case")] +/// Equivocations detection bridge. +pub enum DetectEquivocationsBridge { + MillauToRialto, + RialtoToMillau, + MillauToRialtoParachain, + RococoToBridgeHubWococo, + WococoToBridgeHubRococo, + KusamaToBridgeHubPolkadot, + PolkadotToBridgeHubKusama, +} + +#[async_trait] +trait EquivocationsDetector: RelayToRelayEquivocationDetectionCliBridge +where + Self::Source: ChainWithTransactions, +{ + async fn start(data: DetectEquivocations) -> anyhow::Result<()> { + equivocation::run::( + data.source.into_client::().await?, + data.target.into_client::().await?, + data.source_sign.transaction_params::()?, + ) + .await + } +} + +impl EquivocationsDetector for MillauToRialtoCliBridge {} +impl EquivocationsDetector for RialtoToMillauCliBridge {} +impl EquivocationsDetector for MillauToRialtoParachainCliBridge {} +impl EquivocationsDetector for RococoToBridgeHubWococoCliBridge {} +impl EquivocationsDetector for WococoToBridgeHubRococoCliBridge {} +impl EquivocationsDetector for KusamaToBridgeHubPolkadotCliBridge {} +impl EquivocationsDetector for PolkadotToBridgeHubKusamaCliBridge {} + +impl DetectEquivocations { + /// Run the command. + pub async fn run(self) -> anyhow::Result<()> { + match self.bridge { + DetectEquivocationsBridge::MillauToRialto => MillauToRialtoCliBridge::start(self), + DetectEquivocationsBridge::RialtoToMillau => RialtoToMillauCliBridge::start(self), + DetectEquivocationsBridge::MillauToRialtoParachain => + MillauToRialtoParachainCliBridge::start(self), + DetectEquivocationsBridge::RococoToBridgeHubWococo => + RococoToBridgeHubWococoCliBridge::start(self), + DetectEquivocationsBridge::WococoToBridgeHubRococo => + WococoToBridgeHubRococoCliBridge::start(self), + DetectEquivocationsBridge::KusamaToBridgeHubPolkadot => + KusamaToBridgeHubPolkadotCliBridge::start(self), + DetectEquivocationsBridge::PolkadotToBridgeHubKusama => + PolkadotToBridgeHubKusamaCliBridge::start(self), + } + .await + } +} diff --git a/relays/bin-substrate/src/cli/mod.rs b/relays/bin-substrate/src/cli/mod.rs index 85251d6fdf3..18e37ea72c1 100644 --- a/relays/bin-substrate/src/cli/mod.rs +++ b/relays/bin-substrate/src/cli/mod.rs @@ -36,6 +36,7 @@ pub(crate) mod encode_message; pub(crate) mod send_message; mod chain_schema; +mod detect_equivocations; mod init_bridge; mod register_parachain; mod relay_headers; @@ -92,8 +93,9 @@ pub enum Command { ResubmitTransactions(resubmit_transactions::ResubmitTransactions), /// Register parachain. RegisterParachain(register_parachain::RegisterParachain), - /// + /// Relay parachain heads. RelayParachains(relay_parachains::RelayParachains), + DetectEquivocations(detect_equivocations::DetectEquivocations), } impl Command { @@ -125,6 +127,7 @@ impl Command { Self::ResubmitTransactions(arg) => arg.run().await?, Self::RegisterParachain(arg) => arg.run().await?, Self::RelayParachains(arg) => arg.run().await?, + Self::DetectEquivocations(arg) => arg.run().await?, } Ok(()) } diff --git a/relays/equivocation/src/equivocation_loop.rs b/relays/equivocation/src/equivocation_loop.rs index 0492df67224..aa1fc04b95c 100644 --- a/relays/equivocation/src/equivocation_loop.rs +++ b/relays/equivocation/src/equivocation_loop.rs @@ -314,8 +314,6 @@ impl, TC: TargetClient

> } /// Spawn the equivocations detection loop. -/// TODO: remove `#[allow(dead_code)]` -#[allow(dead_code)] pub async fn run( source_client: impl SourceClient

, target_client: impl TargetClient

, diff --git a/relays/equivocation/src/lib.rs b/relays/equivocation/src/lib.rs index bbae97502f5..6f9337483fd 100644 --- a/relays/equivocation/src/lib.rs +++ b/relays/equivocation/src/lib.rs @@ -23,6 +23,8 @@ use finality_relay::{FinalityPipeline, SourceClientBase}; use relay_utils::{relay_loop::Client as RelayClient, TransactionTracker}; use std::fmt::Debug; +pub use equivocation_loop::run; + pub trait EquivocationDetectionPipeline: FinalityPipeline { /// Block number of the target chain. type TargetNumber: relay_utils::BlockNumberBase; diff --git a/relays/lib-substrate-relay/src/equivocation/mod.rs b/relays/lib-substrate-relay/src/equivocation/mod.rs index 104f2072301..7e050c275e2 100644 --- a/relays/lib-substrate-relay/src/equivocation/mod.rs +++ b/relays/lib-substrate-relay/src/equivocation/mod.rs @@ -22,12 +22,16 @@ mod target; use crate::finality_base::{engine::Engine, SubstrateFinalityPipeline, SubstrateFinalityProof}; +use crate::{ + equivocation::{source::SubstrateEquivocationSource, target::SubstrateEquivocationTarget}, + TransactionParams, +}; use async_trait::async_trait; use bp_runtime::{AccountIdOf, BlockNumberOf, HashOf}; use equivocation_detector::EquivocationDetectionPipeline; use finality_relay::FinalityPipeline; use pallet_grandpa::{Call as GrandpaCall, Config as GrandpaConfig}; -use relay_substrate_client::{AccountKeyPairOf, CallOf, Chain, ChainWithTransactions}; +use relay_substrate_client::{AccountKeyPairOf, CallOf, Chain, ChainWithTransactions, Client}; use sp_core::Pair; use sp_runtime::traits::{Block, Header}; use std::marker::PhantomData; @@ -178,3 +182,26 @@ macro_rules! generate_report_equivocation_call_builder { } }; } + +/// Run Substrate-to-Substrate equivocations detection loop. +pub async fn run( + source_client: impl Client, + target_client: impl Client, + source_transaction_params: TransactionParams>, +) -> anyhow::Result<()> { + log::info!( + target: "bridge", + "Starting {} -> {} equivocations detection loop", + P::SourceChain::NAME, + P::TargetChain::NAME, + ); + + equivocation_detector::run( + SubstrateEquivocationSource::::new(source_client, source_transaction_params), + SubstrateEquivocationTarget::::new(target_client), + P::TargetChain::AVERAGE_BLOCK_INTERVAL, + futures::future::pending(), + ) + .await + .map_err(|e| anyhow::format_err!("{}", e)) +} diff --git a/relays/lib-substrate-relay/src/equivocation/source.rs b/relays/lib-substrate-relay/src/equivocation/source.rs index 22688a56a48..de2a1276b67 100644 --- a/relays/lib-substrate-relay/src/equivocation/source.rs +++ b/relays/lib-substrate-relay/src/equivocation/source.rs @@ -43,6 +43,13 @@ pub struct SubstrateEquivocationSource> SubstrateEquivocationSource { + /// Create new instance of `SubstrateEquivocationSource`. + pub fn new( + client: SourceClnt, + transaction_params: TransactionParams>, + ) -> Self { + Self { client, transaction_params } + } } impl Clone diff --git a/relays/lib-substrate-relay/src/equivocation/target.rs b/relays/lib-substrate-relay/src/equivocation/target.rs index 05295e5b93e..48600f16d73 100644 --- a/relays/lib-substrate-relay/src/equivocation/target.rs +++ b/relays/lib-substrate-relay/src/equivocation/target.rs @@ -42,6 +42,10 @@ pub struct SubstrateEquivocationTarget> SubstrateEquivocationTarget { + /// Create new instance of `SubstrateEquivocationTarget`. + pub fn new(client: TargetClnt) -> Self { + Self { client, _phantom: Default::default() } + } } impl Clone