Skip to content

Commit

Permalink
Move generic CLI logic to different crate (paritytech#2885)
Browse files Browse the repository at this point in the history
* Move generic CLI logic to separate crate

* Move and rename `CliChain` trait definition

Move it to `relay-substrate-client`

* Move generic cli logic to substrate-relay-helper

* Fix docs warnings
  • Loading branch information
serban300 committed Apr 9, 2024
1 parent 1d46022 commit 87a94e2
Show file tree
Hide file tree
Showing 63 changed files with 1,744 additions and 1,436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

//! BridgeHubKusama-to-BridgeHubPolkadot messages sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use relay_bridge_hub_kusama_client::BridgeHubKusama;
use relay_bridge_hub_polkadot_client::BridgeHubPolkadot;
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
messages_lane::SubstrateMessageLane,
UtilityPalletBatchCallBuilder,
};

/// BridgeHubKusama-to-BridgeHubPolkadot messages bridge.
pub struct BridgeHubKusamaToBridgeHubPolkadotMessagesCliBridge {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

//! BridgeHubPolkadot-to-BridgeHubKusama messages sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use relay_bridge_hub_kusama_client::BridgeHubKusama;
use relay_bridge_hub_polkadot_client::BridgeHubPolkadot;
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
messages_lane::SubstrateMessageLane,
UtilityPalletBatchCallBuilder,
};

/// BridgeHubPolkadot-to-BridgeHubKusama messages bridge.
pub struct BridgeHubPolkadotToBridgeHubKusamaMessagesCliBridge {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Kusama-to-BridgeHubPolkadot headers sync entrypoint.

use crate::cli::bridge::{
use substrate_relay_helper::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

//! Kusama-to-BridgeHubPolkadot parachains sync entrypoint.

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::{
SubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline,
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge},
parachains::{SubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline},
};

/// Kusama-to-BridgeHubPolkadot parachain sync description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Polkadot-to-KusamaBridgeHub headers sync entrypoint.

use crate::cli::bridge::{
use substrate_relay_helper::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

//! Polkadot-to-BridgeHubKusama parachains sync entrypoint.

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::{
SubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline,
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge},
parachains::{SubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline},
};

/// Polkadot-to-BridgeHubKusama parachain sync description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

//! BridgeHubPolkadot-to-PolkadotBulletin messages sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use relay_bridge_hub_polkadot_client::BridgeHubPolkadot;
use relay_polkadot_bulletin_client::PolkadotBulletin;
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
messages_lane::SubstrateMessageLane,
UtilityPalletBatchCallBuilder,
};

/// BridgeHubPolkadot-to-PolkadotBulletin messages bridge.
pub struct BridgeHubPolkadotToPolkadotBulletinMessagesCliBridge {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

//! PolkadotBulletin-to-BridgeHubPolkadot headers sync entrypoint.

use crate::cli::bridge::{
CliBridgeBase, MessagesCliBridge, RelayToRelayEquivocationDetectionCliBridge,
RelayToRelayHeadersCliBridge,
};

use async_trait::async_trait;
use substrate_relay_helper::{
equivocation::SubstrateEquivocationDetectionPipeline,
finality::SubstrateFinalitySyncPipeline,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

use substrate_relay_helper::cli::bridge::{
CliBridgeBase, MessagesCliBridge, RelayToRelayEquivocationDetectionCliBridge,
RelayToRelayHeadersCliBridge,
};

/// Description of `PolkadotBulletin` -> `PolkadotBridgeHub` finalized headers bridge.
#[derive(Clone, Debug)]
pub struct PolkadotBulletinFinalityToBridgeHubPolkadot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

//! PolkadotBulletin-to-BridgeHubPolkadot messages sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use relay_bridge_hub_polkadot_client::BridgeHubPolkadot;
use relay_polkadot_bulletin_client::PolkadotBulletin;
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
messages_lane::SubstrateMessageLane,
UtilityPalletBatchCallBuilder,
};

/// PolkadotBulletin-to-BridgeHubPolkadot messages bridge.
pub struct PolkadotBulletinToBridgeHubPolkadotMessagesCliBridge {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

//! Polkadot-to-PolkadotBulletin headers sync entrypoint.

use crate::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

use async_trait::async_trait;
use substrate_relay_helper::{
equivocation::SubstrateEquivocationDetectionPipeline,
finality::SubstrateFinalitySyncPipeline,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

use substrate_relay_helper::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

/// Description of Polkadot -> `PolkadotBulletin` finalized headers bridge.
#[derive(Clone, Debug)]
pub struct PolkadotFinalityToPolkadotBulletin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

//! Polkadot-to-PolkadotBulletin parachains sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge};
use substrate_relay_helper::cli::bridge::{
CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge,
};

use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId};
use bp_runtime::Chain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
//! BridgeHubRococo-to-RococoBulletin messages sync entrypoint.

use super::BridgeHubRococoAsBridgeHubPolkadot;
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use relay_polkadot_bulletin_client::PolkadotBulletin as RococoBulletin;
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
messages_lane::SubstrateMessageLane,
UtilityPalletBatchCallBuilder,
};

/// BridgeHubRococo-to-RococoBulletin messages bridge.
pub struct BridgeHubRococoToRococoBulletinMessagesCliBridge {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

//! Declaration of all bridges between Rococo Bulletin Chain and Rococo Bridge Hub.

use crate::cli::CliChain;

use bp_messages::MessageNonce;
use bp_runtime::{
AccountIdOf, BalanceOf, BlockNumberOf, ChainId, HashOf, HasherOf, HeaderOf, NonceOf,
SignatureOf,
};
use frame_support::pallet_prelude::Weight;
use relay_substrate_client::{
Error as SubstrateError, SignParam, SimpleRuntimeVersion, UnsignedTransaction,
ChainWithRuntimeVersion, Error as SubstrateError, SignParam, SimpleRuntimeVersion,
UnsignedTransaction,
};
use sp_core::storage::StorageKey;
use std::time::Duration;
Expand Down Expand Up @@ -127,7 +126,7 @@ impl relay_substrate_client::ChainWithTransactions for RococoAsPolkadot {
}
}

impl CliChain for RococoAsPolkadot {
impl ChainWithRuntimeVersion for RococoAsPolkadot {
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
}

Expand Down Expand Up @@ -232,7 +231,7 @@ impl relay_substrate_client::ChainWithMessages for BridgeHubRococoAsBridgeHubPol
relay_bridge_hub_polkadot_client::BridgeHubPolkadot::FROM_CHAIN_MESSAGE_DETAILS_METHOD;
}

impl CliChain for BridgeHubRococoAsBridgeHubPolkadot {
impl ChainWithRuntimeVersion for BridgeHubRococoAsBridgeHubPolkadot {
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion { spec_version: 1_003_000, transaction_version: 3 });
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
//! RococoBulletin-to-BridgeHubRococo headers sync entrypoint.

use super::BridgeHubRococoAsBridgeHubPolkadot;
use crate::cli::bridge::{
CliBridgeBase, MessagesCliBridge, RelayToRelayEquivocationDetectionCliBridge,
RelayToRelayHeadersCliBridge,
};

use async_trait::async_trait;
use substrate_relay_helper::{
Expand All @@ -29,6 +25,11 @@ use substrate_relay_helper::{
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

use substrate_relay_helper::cli::bridge::{
CliBridgeBase, MessagesCliBridge, RelayToRelayEquivocationDetectionCliBridge,
RelayToRelayHeadersCliBridge,
};

/// Description of `RococoBulletin` -> `RococoBridgeHub` finalized headers bridge.
#[derive(Clone, Debug)]
pub struct RococoBulletinFinalityToBridgeHubRococo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
//! RococoBulletin-to-BridgeHubRococo messages sync entrypoint.

use super::BridgeHubRococoAsBridgeHubPolkadot;
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use relay_polkadot_bulletin_client::PolkadotBulletin as RococoBulletin;
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
messages_lane::SubstrateMessageLane,
UtilityPalletBatchCallBuilder,
};

/// RococoBulletin-to-BridgeHubRococo messages bridge.
pub struct RococoBulletinToBridgeHubRococoMessagesCliBridge {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
//! Rococo-to-RococoBulletin headers sync entrypoint.

use super::RococoAsPolkadot;
use crate::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

use async_trait::async_trait;
use substrate_relay_helper::{
Expand All @@ -28,6 +25,10 @@ use substrate_relay_helper::{
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

use substrate_relay_helper::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

/// Description of Rococo -> `RococoBulletin` finalized headers bridge.
#[derive(Clone, Debug)]
pub struct RococoFinalityToRococoBulletin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
//! Rococo-to-RococoBulletin parachains sync entrypoint.

use super::{BridgeHubRococoAsBridgeHubPolkadot, RococoAsPolkadot};
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge};

use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId};
use bp_runtime::Chain;
use relay_substrate_client::{CallOf, HeaderIdOf};
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge},
messages_lane::MessagesRelayLimits,
parachains::{SubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

//! BridgeHubRococo-to-BridgeHubWestend messages sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_bridge_hub_westend_client::BridgeHubWestend;
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
messages_lane::SubstrateMessageLane,
UtilityPalletBatchCallBuilder,
};

pub struct BridgeHubRococoToBridgeHubWestendMessagesCliBridge {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

//! BridgeHubWestend-to-BridgeHubRococo messages sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_bridge_hub_westend_client::BridgeHubWestend;
use substrate_relay_helper::{messages_lane::SubstrateMessageLane, UtilityPalletBatchCallBuilder};
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
messages_lane::SubstrateMessageLane,
UtilityPalletBatchCallBuilder,
};

pub struct BridgeHubWestendToBridgeHubRococoMessagesCliBridge {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

//! Rococo-to-Westend bridge hubs headers sync entrypoint.

use crate::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

use async_trait::async_trait;
use substrate_relay_helper::{
equivocation::SubstrateEquivocationDetectionPipeline,
finality::SubstrateFinalitySyncPipeline,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

use substrate_relay_helper::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

/// Description of Rococo -> Westend finalized headers bridge.
#[derive(Clone, Debug)]
pub struct RococoFinalityToBridgeHubWestend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

//! Westend-to-Rococo parachains sync entrypoint.

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::{
SubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline,
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge},
parachains::{SubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline},
};

/// BridgeHub-to-BridgeHub parachain sync description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

//! Westend-to-Rococo bridge hubs headers sync entrypoint.

use crate::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

use async_trait::async_trait;
use substrate_relay_helper::{
equivocation::SubstrateEquivocationDetectionPipeline,
finality::SubstrateFinalitySyncPipeline,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

use substrate_relay_helper::cli::bridge::{
CliBridgeBase, RelayToRelayEquivocationDetectionCliBridge, RelayToRelayHeadersCliBridge,
};

/// Description of Westend -> Rococo finalized headers bridge.
#[derive(Clone, Debug)]
pub struct WestendFinalityToBridgeHubRococo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

//! Rococo-to-Westend parachains sync entrypoint.

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::{
SubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline,
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge},
parachains::{SubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline},
};

/// BridgeHub-to-BridgeHub parachain sync description.
Expand Down
Loading

0 comments on commit 87a94e2

Please sign in to comment.