From 60f82cf459470cd655bcd30a6cfedf12a1da4b63 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Fri, 25 Feb 2022 11:34:57 +0300 Subject: [PATCH] removed extra *_RUNTIME_VERSION consts from relay code (#1330) --- .../relays/bin-substrate/src/cli/bridge.rs | 30 ----------------- .../bin-substrate/src/cli/estimate_fee.rs | 2 +- .../bin-substrate/src/cli/init_bridge.rs | 32 ++----------------- bridges/relays/bin-substrate/src/cli/mod.rs | 8 ++--- .../src/cli/register_parachain.rs | 13 ++------ .../bin-substrate/src/cli/relay_headers.rs | 32 ++----------------- .../src/cli/relay_headers_and_messages.rs | 19 ++--------- .../bin-substrate/src/cli/relay_messages.rs | 4 +-- .../src/cli/resubmit_transactions.rs | 8 +---- .../bin-substrate/src/cli/send_message.rs | 7 ++-- .../bin-substrate/src/cli/swap_tokens.rs | 9 ++---- 11 files changed, 19 insertions(+), 145 deletions(-) diff --git a/bridges/relays/bin-substrate/src/cli/bridge.rs b/bridges/relays/bin-substrate/src/cli/bridge.rs index ea16c92c92..2eb836a84a 100644 --- a/bridges/relays/bin-substrate/src/cli/bridge.rs +++ b/bridges/relays/bin-substrate/src/cli/bridge.rs @@ -77,11 +77,6 @@ macro_rules! select_full_bridge { #[allow(unused_imports)] use millau_runtime::millau_to_rialto_account_ownership_digest as account_ownership_digest; - #[allow(dead_code)] - const SOURCE_RUNTIME_VERSION: Option = Some(millau_runtime::VERSION); - #[allow(dead_code)] - const TARGET_RUNTIME_VERSION: Option = Some(rialto_runtime::VERSION); - $generic } FullBridge::RialtoToMillau => { @@ -105,11 +100,6 @@ macro_rules! select_full_bridge { #[allow(unused_imports)] use rialto_runtime::rialto_to_millau_account_ownership_digest as account_ownership_digest; - #[allow(dead_code)] - const SOURCE_RUNTIME_VERSION: Option = Some(rialto_runtime::VERSION); - #[allow(dead_code)] - const TARGET_RUNTIME_VERSION: Option = Some(millau_runtime::VERSION); - $generic } FullBridge::RococoToWococo => { @@ -132,11 +122,6 @@ macro_rules! select_full_bridge { #[allow(unused_imports)] use relay_rococo_client::runtime::rococo_to_wococo_account_ownership_digest as account_ownership_digest; - #[allow(dead_code)] - const SOURCE_RUNTIME_VERSION: Option = Some(bp_rococo::VERSION); - #[allow(dead_code)] - const TARGET_RUNTIME_VERSION: Option = Some(bp_wococo::VERSION); - $generic } FullBridge::WococoToRococo => { @@ -159,11 +144,6 @@ macro_rules! select_full_bridge { #[allow(unused_imports)] use relay_wococo_client::runtime::wococo_to_rococo_account_ownership_digest as account_ownership_digest; - #[allow(dead_code)] - const SOURCE_RUNTIME_VERSION: Option = Some(bp_wococo::VERSION); - #[allow(dead_code)] - const TARGET_RUNTIME_VERSION: Option = Some(bp_rococo::VERSION); - $generic } FullBridge::KusamaToPolkadot => { @@ -186,11 +166,6 @@ macro_rules! select_full_bridge { #[allow(unused_imports)] use relay_kusama_client::runtime::kusama_to_polkadot_account_ownership_digest as account_ownership_digest; - #[allow(dead_code)] - const SOURCE_RUNTIME_VERSION: Option = Some(bp_kusama::VERSION); - #[allow(dead_code)] - const TARGET_RUNTIME_VERSION: Option = Some(bp_polkadot::VERSION); - $generic } FullBridge::PolkadotToKusama => { @@ -213,11 +188,6 @@ macro_rules! select_full_bridge { #[allow(unused_imports)] use relay_polkadot_client::runtime::polkadot_to_kusama_account_ownership_digest as account_ownership_digest; - #[allow(dead_code)] - const SOURCE_RUNTIME_VERSION: Option = Some(bp_polkadot::VERSION); - #[allow(dead_code)] - const TARGET_RUNTIME_VERSION: Option = Some(bp_kusama::VERSION); - $generic } } diff --git a/bridges/relays/bin-substrate/src/cli/estimate_fee.rs b/bridges/relays/bin-substrate/src/cli/estimate_fee.rs index 30bcae079b..ff5bffacdf 100644 --- a/bridges/relays/bin-substrate/src/cli/estimate_fee.rs +++ b/bridges/relays/bin-substrate/src/cli/estimate_fee.rs @@ -46,7 +46,7 @@ impl EstimateFee { let Self { source, bridge, lane, payload } = self; select_full_bridge!(bridge, { - let source_client = source.to_client::(SOURCE_RUNTIME_VERSION).await?; + let source_client = source.to_client::().await?; let lane = lane.into(); let payload = Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?; diff --git a/bridges/relays/bin-substrate/src/cli/init_bridge.rs b/bridges/relays/bin-substrate/src/cli/init_bridge.rs index ad133e369f..a0129ce9ba 100644 --- a/bridges/relays/bin-substrate/src/cli/init_bridge.rs +++ b/bridges/relays/bin-substrate/src/cli/init_bridge.rs @@ -56,10 +56,6 @@ macro_rules! select_bridge { InitBridgeName::MillauToRialto => { type Source = relay_millau_client::Millau; type Target = relay_rialto_client::Rialto; - const SOURCE_RUNTIME_VERSION: Option = - Some(millau_runtime::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(rialto_runtime::VERSION); fn encode_init_bridge( init_data: InitializationData<::Header>, @@ -78,10 +74,6 @@ macro_rules! select_bridge { InitBridgeName::RialtoToMillau => { type Source = relay_rialto_client::Rialto; type Target = relay_millau_client::Millau; - const SOURCE_RUNTIME_VERSION: Option = - Some(rialto_runtime::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(millau_runtime::VERSION); fn encode_init_bridge( init_data: InitializationData<::Header>, @@ -100,10 +92,6 @@ macro_rules! select_bridge { InitBridgeName::WestendToMillau => { type Source = relay_westend_client::Westend; type Target = relay_millau_client::Millau; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_westend::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(millau_runtime::VERSION); fn encode_init_bridge( init_data: InitializationData<::Header>, @@ -126,10 +114,6 @@ macro_rules! select_bridge { InitBridgeName::RococoToWococo => { type Source = relay_rococo_client::Rococo; type Target = relay_wococo_client::Wococo; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_rococo::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(bp_wococo::VERSION); fn encode_init_bridge( init_data: InitializationData<::Header>, @@ -146,10 +130,6 @@ macro_rules! select_bridge { InitBridgeName::WococoToRococo => { type Source = relay_wococo_client::Wococo; type Target = relay_rococo_client::Rococo; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_wococo::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(bp_rococo::VERSION); fn encode_init_bridge( init_data: InitializationData<::Header>, @@ -166,10 +146,6 @@ macro_rules! select_bridge { InitBridgeName::KusamaToPolkadot => { type Source = relay_kusama_client::Kusama; type Target = relay_polkadot_client::Polkadot; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_kusama::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(bp_polkadot::VERSION); fn encode_init_bridge( init_data: InitializationData<::Header>, @@ -186,10 +162,6 @@ macro_rules! select_bridge { InitBridgeName::PolkadotToKusama => { type Source = relay_polkadot_client::Polkadot; type Target = relay_kusama_client::Kusama; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_polkadot::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(bp_kusama::VERSION); fn encode_init_bridge( init_data: InitializationData<::Header>, @@ -211,8 +183,8 @@ impl InitBridge { /// Run the command. pub async fn run(self) -> anyhow::Result<()> { select_bridge!(self.bridge, { - let source_client = self.source.to_client::(SOURCE_RUNTIME_VERSION).await?; - let target_client = self.target.to_client::(TARGET_RUNTIME_VERSION).await?; + let source_client = self.source.to_client::().await?; + let target_client = self.target.to_client::().await?; let target_sign = self.target_sign.to_keypair::()?; let (spec_version, transaction_version) = diff --git a/bridges/relays/bin-substrate/src/cli/mod.rs b/bridges/relays/bin-substrate/src/cli/mod.rs index ae169f773e..a91dfc5d54 100644 --- a/bridges/relays/bin-substrate/src/cli/mod.rs +++ b/bridges/relays/bin-substrate/src/cli/mod.rs @@ -541,11 +541,10 @@ macro_rules! declare_chain_options { /// Convert connection params into Substrate client. pub async fn to_client( &self, - bundle_runtime_version: Option ) -> anyhow::Result> { let chain_runtime_version = self .[<$chain_prefix _runtime_version>] - .into_runtime_version(bundle_runtime_version)?; + .into_runtime_version(Some(Chain::RUNTIME_VERSION))?; Ok(relay_substrate_client::Client::new(relay_substrate_client::ConnectionParams { host: self.[<$chain_prefix _host>].clone(), port: self.[<$chain_prefix _port>], @@ -562,14 +561,13 @@ macro_rules! declare_chain_options { #[allow(dead_code)] pub async fn selected_chain_spec_version( &self, - bundle_runtime_version: Option, ) -> anyhow::Result { let chain_runtime_version = self .[<$chain_prefix _runtime_version>] - .into_runtime_version(bundle_runtime_version.clone())?; + .into_runtime_version(Some(Chain::RUNTIME_VERSION))?; Ok(match chain_runtime_version { ChainRuntimeVersion::Auto => self - .to_client::(bundle_runtime_version) + .to_client::() .await? .simple_runtime_version() .await? diff --git a/bridges/relays/bin-substrate/src/cli/register_parachain.rs b/bridges/relays/bin-substrate/src/cli/register_parachain.rs index 4ede369026..4d75143755 100644 --- a/bridges/relays/bin-substrate/src/cli/register_parachain.rs +++ b/bridges/relays/bin-substrate/src/cli/register_parachain.rs @@ -84,11 +84,6 @@ macro_rules! select_bridge { use bp_rialto::{PARAS_PALLET_NAME, PARAS_REGISTRAR_PALLET_NAME}; - const RELAY_CHAIN_RUNTIME_VERSION: Option = - Some(rialto_runtime::VERSION); - const PARA_CHAIN_RUNTIME_VERSION: Option = - Some(rialto_parachain_runtime::VERSION); - $generic }, } @@ -99,13 +94,9 @@ impl RegisterParachain { /// Run the command. pub async fn run(self) -> anyhow::Result<()> { select_bridge!(self.parachain, { - let relay_client = self - .relay_connection - .to_client::(RELAY_CHAIN_RUNTIME_VERSION) - .await?; + let relay_client = self.relay_connection.to_client::().await?; let relay_sign = self.relay_sign.to_keypair::()?; - let para_client = - self.para_connection.to_client::(PARA_CHAIN_RUNTIME_VERSION).await?; + let para_client = self.para_connection.to_client::().await?; // hopefully we're the only actor that is registering parachain right now // => read next parachain id diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers.rs b/bridges/relays/bin-substrate/src/cli/relay_headers.rs index e3c7fe76d3..45034aba4b 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers.rs @@ -64,10 +64,6 @@ macro_rules! select_bridge { type Source = relay_millau_client::Millau; type Target = relay_rialto_client::Rialto; type Finality = crate::chains::millau_headers_to_rialto::MillauFinalityToRialto; - const SOURCE_RUNTIME_VERSION: Option = - Some(millau_runtime::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(rialto_runtime::VERSION); $generic }, @@ -75,10 +71,6 @@ macro_rules! select_bridge { type Source = relay_rialto_client::Rialto; type Target = relay_millau_client::Millau; type Finality = crate::chains::rialto_headers_to_millau::RialtoFinalityToMillau; - const SOURCE_RUNTIME_VERSION: Option = - Some(rialto_runtime::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(millau_runtime::VERSION); $generic }, @@ -86,10 +78,6 @@ macro_rules! select_bridge { type Source = relay_westend_client::Westend; type Target = relay_millau_client::Millau; type Finality = crate::chains::westend_headers_to_millau::WestendFinalityToMillau; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_westend::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(millau_runtime::VERSION); $generic }, @@ -97,10 +85,6 @@ macro_rules! select_bridge { type Source = relay_rococo_client::Rococo; type Target = relay_wococo_client::Wococo; type Finality = crate::chains::rococo_headers_to_wococo::RococoFinalityToWococo; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_rococo::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(bp_wococo::VERSION); $generic }, @@ -108,10 +92,6 @@ macro_rules! select_bridge { type Source = relay_wococo_client::Wococo; type Target = relay_rococo_client::Rococo; type Finality = crate::chains::wococo_headers_to_rococo::WococoFinalityToRococo; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_wococo::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(bp_rococo::VERSION); $generic }, @@ -119,10 +99,6 @@ macro_rules! select_bridge { type Source = relay_kusama_client::Kusama; type Target = relay_polkadot_client::Polkadot; type Finality = crate::chains::kusama_headers_to_polkadot::KusamaFinalityToPolkadot; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_kusama::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(bp_polkadot::VERSION); $generic }, @@ -130,10 +106,6 @@ macro_rules! select_bridge { type Source = relay_polkadot_client::Polkadot; type Target = relay_kusama_client::Kusama; type Finality = crate::chains::polkadot_headers_to_kusama::PolkadotFinalityToKusama; - const SOURCE_RUNTIME_VERSION: Option = - Some(bp_polkadot::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(bp_kusama::VERSION); $generic }, @@ -145,8 +117,8 @@ impl RelayHeaders { /// Run the command. pub async fn run(self) -> anyhow::Result<()> { select_bridge!(self.bridge, { - let source_client = self.source.to_client::(SOURCE_RUNTIME_VERSION).await?; - let target_client = self.target.to_client::(TARGET_RUNTIME_VERSION).await?; + let source_client = self.source.to_client::().await?; + let target_client = self.target.to_client::().await?; let target_transactions_mortality = self.target_sign.target_transactions_mortality; let target_sign = self.target_sign.to_keypair::()?; diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages.rs index c8d74b8fae..4733600033 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages.rs @@ -133,11 +133,6 @@ macro_rules! select_bridge { type LeftAccountIdConverter = bp_millau::AccountIdConverter; type RightAccountIdConverter = bp_rialto::AccountIdConverter; - const LEFT_RUNTIME_VERSION: Option = - Some(millau_runtime::VERSION); - const RIGHT_RUNTIME_VERSION: Option = - Some(rialto_runtime::VERSION); - use crate::chains::{ millau_messages_to_rialto::{ update_rialto_to_millau_conversion_rate as update_right_to_left_conversion_rate, @@ -181,11 +176,6 @@ macro_rules! select_bridge { type LeftAccountIdConverter = bp_rococo::AccountIdConverter; type RightAccountIdConverter = bp_wococo::AccountIdConverter; - const LEFT_RUNTIME_VERSION: Option = - Some(bp_rococo::VERSION); - const RIGHT_RUNTIME_VERSION: Option = - Some(bp_wococo::VERSION); - use crate::chains::{ rococo_messages_to_wococo::RococoMessagesToWococo as LeftToRightMessageLane, wococo_messages_to_rococo::WococoMessagesToRococo as RightToLeftMessageLane, @@ -259,11 +249,6 @@ macro_rules! select_bridge { type LeftAccountIdConverter = bp_kusama::AccountIdConverter; type RightAccountIdConverter = bp_polkadot::AccountIdConverter; - const LEFT_RUNTIME_VERSION: Option = - Some(bp_kusama::VERSION); - const RIGHT_RUNTIME_VERSION: Option = - Some(bp_polkadot::VERSION); - use crate::chains::{ kusama_messages_to_polkadot::{ update_polkadot_to_kusama_conversion_rate as update_right_to_left_conversion_rate, @@ -335,12 +320,12 @@ impl RelayHeadersAndMessages { select_bridge!(self, { let params: Params = self.into(); - let left_client = params.left.to_client::(LEFT_RUNTIME_VERSION).await?; + let left_client = params.left.to_client::().await?; let left_transactions_mortality = params.left_sign.transactions_mortality()?; let left_sign = params.left_sign.to_keypair::()?; let left_messages_pallet_owner = params.left_messages_pallet_owner.to_keypair::()?; - let right_client = params.right.to_client::(RIGHT_RUNTIME_VERSION).await?; + let right_client = params.right.to_client::().await?; let right_transactions_mortality = params.right_sign.transactions_mortality()?; let right_sign = params.right_sign.to_keypair::()?; let right_messages_pallet_owner = diff --git a/bridges/relays/bin-substrate/src/cli/relay_messages.rs b/bridges/relays/bin-substrate/src/cli/relay_messages.rs index 521d00d50a..45087fad5e 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_messages.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_messages.rs @@ -75,10 +75,10 @@ impl RelayMessages { /// Run the command. pub async fn run(self) -> anyhow::Result<()> { select_full_bridge!(self.bridge, { - let source_client = self.source.to_client::(SOURCE_RUNTIME_VERSION).await?; + let source_client = self.source.to_client::().await?; let source_sign = self.source_sign.to_keypair::()?; let source_transactions_mortality = self.source_sign.transactions_mortality()?; - let target_client = self.target.to_client::(TARGET_RUNTIME_VERSION).await?; + let target_client = self.target.to_client::().await?; let target_sign = self.target_sign.to_keypair::()?; let target_transactions_mortality = self.target_sign.transactions_mortality()?; let relayer_mode = self.relayer_mode.into(); diff --git a/bridges/relays/bin-substrate/src/cli/resubmit_transactions.rs b/bridges/relays/bin-substrate/src/cli/resubmit_transactions.rs index d6edda3aaf..f92c035082 100644 --- a/bridges/relays/bin-substrate/src/cli/resubmit_transactions.rs +++ b/bridges/relays/bin-substrate/src/cli/resubmit_transactions.rs @@ -92,24 +92,18 @@ macro_rules! select_bridge { RelayChain::Millau => { type Target = relay_millau_client::Millau; type TargetSign = relay_millau_client::Millau; - const TARGET_RUNTIME_VERSION: Option = - Some(millau_runtime::VERSION); $generic }, RelayChain::Kusama => { type Target = relay_kusama_client::Kusama; type TargetSign = relay_kusama_client::Kusama; - const TARGET_RUNTIME_VERSION: Option = - Some(bp_kusama::VERSION); $generic }, RelayChain::Polkadot => { type Target = relay_polkadot_client::Polkadot; type TargetSign = relay_polkadot_client::Polkadot; - const TARGET_RUNTIME_VERSION: Option = - Some(bp_polkadot::VERSION); $generic }, @@ -122,7 +116,7 @@ impl ResubmitTransactions { pub async fn run(self) -> anyhow::Result<()> { select_bridge!(self.chain, { let relay_loop_name = format!("ResubmitTransactions{}", Target::NAME); - let client = self.target.to_client::(TARGET_RUNTIME_VERSION).await?; + let client = self.target.to_client::().await?; let transaction_params = TransactionParams { signer: self.target_sign.to_keypair::()?, mortality: self.target_sign.target_transactions_mortality, diff --git a/bridges/relays/bin-substrate/src/cli/send_message.rs b/bridges/relays/bin-substrate/src/cli/send_message.rs index 45f5fa89d0..372ce1fa2a 100644 --- a/bridges/relays/bin-substrate/src/cli/send_message.rs +++ b/bridges/relays/bin-substrate/src/cli/send_message.rs @@ -116,10 +116,7 @@ impl SendMessage { encode_call::preprocess_call::(message, bridge.bridge_instance_index()); let target_call = Target::encode_call(message)?; - let target_spec_version = self - .target - .selected_chain_spec_version::(Some(Target::RUNTIME_VERSION)) - .await?; + let target_spec_version = self.target.selected_chain_spec_version::().await?; let payload = { let target_call_weight = prepare_call_dispatch_weight( @@ -168,7 +165,7 @@ impl SendMessage { crate::select_full_bridge!(self.bridge, { let payload = self.encode_payload().await?; - let source_client = self.source.to_client::(SOURCE_RUNTIME_VERSION).await?; + let source_client = self.source.to_client::().await?; let source_sign = self.source_sign.to_keypair::()?; let lane = self.lane.clone().into(); diff --git a/bridges/relays/bin-substrate/src/cli/swap_tokens.rs b/bridges/relays/bin-substrate/src/cli/swap_tokens.rs index b9cdac7d34..c4b80ec66b 100644 --- a/bridges/relays/bin-substrate/src/cli/swap_tokens.rs +++ b/bridges/relays/bin-substrate/src/cli/swap_tokens.rs @@ -101,11 +101,6 @@ macro_rules! select_bridge { const SOURCE_SPEC_VERSION: u32 = millau_runtime::VERSION.spec_version; const TARGET_SPEC_VERSION: u32 = rialto_runtime::VERSION.spec_version; - const SOURCE_RUNTIME_VERSION: Option = - Some(millau_runtime::VERSION); - const TARGET_RUNTIME_VERSION: Option = - Some(rialto_runtime::VERSION); - type FromSwapToThisAccountIdConverter = bp_rialto::AccountIdConverter; use bp_millau::{ @@ -134,9 +129,9 @@ impl SwapTokens { /// Run the command. pub async fn run(self) -> anyhow::Result<()> { select_bridge!(self.bridge, { - let source_client = self.source.to_client::(SOURCE_RUNTIME_VERSION).await?; + let source_client = self.source.to_client::().await?; let source_sign = self.source_sign.to_keypair::()?; - let target_client = self.target.to_client::(TARGET_RUNTIME_VERSION).await?; + let target_client = self.target.to_client::().await?; let target_sign = self.target_sign.to_keypair::()?; // names of variables in this function are matching names used by the