Skip to content

Commit

Permalink
removed extra *_RUNTIME_VERSION consts from relay code (paritytech#1330)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and serban300 committed Apr 8, 2024
1 parent b54d267 commit 46c25d7
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 145 deletions.
30 changes: 0 additions & 30 deletions bridges/relays/bin-substrate/src/cli/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<sp_version::RuntimeVersion> = Some(millau_runtime::VERSION);
#[allow(dead_code)]
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(rialto_runtime::VERSION);

$generic
}
FullBridge::RialtoToMillau => {
Expand All @@ -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<sp_version::RuntimeVersion> = Some(rialto_runtime::VERSION);
#[allow(dead_code)]
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(millau_runtime::VERSION);

$generic
}
FullBridge::RococoToWococo => {
Expand All @@ -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<sp_version::RuntimeVersion> = Some(bp_rococo::VERSION);
#[allow(dead_code)]
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_wococo::VERSION);

$generic
}
FullBridge::WococoToRococo => {
Expand All @@ -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<sp_version::RuntimeVersion> = Some(bp_wococo::VERSION);
#[allow(dead_code)]
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_rococo::VERSION);

$generic
}
FullBridge::KusamaToPolkadot => {
Expand All @@ -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<sp_version::RuntimeVersion> = Some(bp_kusama::VERSION);
#[allow(dead_code)]
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_polkadot::VERSION);

$generic
}
FullBridge::PolkadotToKusama => {
Expand All @@ -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<sp_version::RuntimeVersion> = Some(bp_polkadot::VERSION);
#[allow(dead_code)]
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> = Some(bp_kusama::VERSION);

$generic
}
}
Expand Down
2 changes: 1 addition & 1 deletion bridges/relays/bin-substrate/src/cli/estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl EstimateFee {
let Self { source, bridge, lane, payload } = self;

select_full_bridge!(bridge, {
let source_client = source.to_client::<Source>(SOURCE_RUNTIME_VERSION).await?;
let source_client = source.to_client::<Source>().await?;
let lane = lane.into();
let payload =
Source::encode_message(payload).map_err(|e| anyhow::format_err!("{:?}", e))?;
Expand Down
32 changes: 2 additions & 30 deletions bridges/relays/bin-substrate/src/cli/init_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<sp_version::RuntimeVersion> =
Some(millau_runtime::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(rialto_runtime::VERSION);

fn encode_init_bridge(
init_data: InitializationData<<Source as ChainBase>::Header>,
Expand All @@ -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<sp_version::RuntimeVersion> =
Some(rialto_runtime::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(millau_runtime::VERSION);

fn encode_init_bridge(
init_data: InitializationData<<Source as ChainBase>::Header>,
Expand All @@ -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<sp_version::RuntimeVersion> =
Some(bp_westend::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(millau_runtime::VERSION);

fn encode_init_bridge(
init_data: InitializationData<<Source as ChainBase>::Header>,
Expand All @@ -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<sp_version::RuntimeVersion> =
Some(bp_rococo::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_wococo::VERSION);

fn encode_init_bridge(
init_data: InitializationData<<Source as ChainBase>::Header>,
Expand All @@ -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<sp_version::RuntimeVersion> =
Some(bp_wococo::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_rococo::VERSION);

fn encode_init_bridge(
init_data: InitializationData<<Source as ChainBase>::Header>,
Expand All @@ -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<sp_version::RuntimeVersion> =
Some(bp_kusama::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_polkadot::VERSION);

fn encode_init_bridge(
init_data: InitializationData<<Source as ChainBase>::Header>,
Expand All @@ -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<sp_version::RuntimeVersion> =
Some(bp_polkadot::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_kusama::VERSION);

fn encode_init_bridge(
init_data: InitializationData<<Source as ChainBase>::Header>,
Expand All @@ -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>(SOURCE_RUNTIME_VERSION).await?;
let target_client = self.target.to_client::<Target>(TARGET_RUNTIME_VERSION).await?;
let source_client = self.source.to_client::<Source>().await?;
let target_client = self.target.to_client::<Target>().await?;
let target_sign = self.target_sign.to_keypair::<Target>()?;

let (spec_version, transaction_version) =
Expand Down
8 changes: 3 additions & 5 deletions bridges/relays/bin-substrate/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,10 @@ macro_rules! declare_chain_options {
/// Convert connection params into Substrate client.
pub async fn to_client<Chain: CliChain>(
&self,
bundle_runtime_version: Option<sp_version::RuntimeVersion>
) -> anyhow::Result<relay_substrate_client::Client<Chain>> {
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>],
Expand All @@ -562,14 +561,13 @@ macro_rules! declare_chain_options {
#[allow(dead_code)]
pub async fn selected_chain_spec_version<Chain: CliChain>(
&self,
bundle_runtime_version: Option<sp_version::RuntimeVersion>,
) -> anyhow::Result<u32> {
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::<Chain>(bundle_runtime_version)
.to_client::<Chain>()
.await?
.simple_runtime_version()
.await?
Expand Down
13 changes: 2 additions & 11 deletions bridges/relays/bin-substrate/src/cli/register_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ macro_rules! select_bridge {

use bp_rialto::{PARAS_PALLET_NAME, PARAS_REGISTRAR_PALLET_NAME};

const RELAY_CHAIN_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(rialto_runtime::VERSION);
const PARA_CHAIN_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(rialto_parachain_runtime::VERSION);

$generic
},
}
Expand All @@ -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::<Relaychain>(RELAY_CHAIN_RUNTIME_VERSION)
.await?;
let relay_client = self.relay_connection.to_client::<Relaychain>().await?;
let relay_sign = self.relay_sign.to_keypair::<Relaychain>()?;
let para_client =
self.para_connection.to_client::<Parachain>(PARA_CHAIN_RUNTIME_VERSION).await?;
let para_client = self.para_connection.to_client::<Parachain>().await?;

// hopefully we're the only actor that is registering parachain right now
// => read next parachain id
Expand Down
32 changes: 2 additions & 30 deletions bridges/relays/bin-substrate/src/cli/relay_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,76 +64,48 @@ 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<sp_version::RuntimeVersion> =
Some(millau_runtime::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(rialto_runtime::VERSION);

$generic
},
RelayHeadersBridge::RialtoToMillau => {
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<sp_version::RuntimeVersion> =
Some(rialto_runtime::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(millau_runtime::VERSION);

$generic
},
RelayHeadersBridge::WestendToMillau => {
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<sp_version::RuntimeVersion> =
Some(bp_westend::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(millau_runtime::VERSION);

$generic
},
RelayHeadersBridge::RococoToWococo => {
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<sp_version::RuntimeVersion> =
Some(bp_rococo::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_wococo::VERSION);

$generic
},
RelayHeadersBridge::WococoToRococo => {
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<sp_version::RuntimeVersion> =
Some(bp_wococo::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_rococo::VERSION);

$generic
},
RelayHeadersBridge::KusamaToPolkadot => {
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<sp_version::RuntimeVersion> =
Some(bp_kusama::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_polkadot::VERSION);

$generic
},
RelayHeadersBridge::PolkadotToKusama => {
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<sp_version::RuntimeVersion> =
Some(bp_polkadot::VERSION);
const TARGET_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_kusama::VERSION);

$generic
},
Expand All @@ -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>(SOURCE_RUNTIME_VERSION).await?;
let target_client = self.target.to_client::<Target>(TARGET_RUNTIME_VERSION).await?;
let source_client = self.source.to_client::<Source>().await?;
let target_client = self.target.to_client::<Target>().await?;
let target_transactions_mortality = self.target_sign.target_transactions_mortality;
let target_sign = self.target_sign.to_keypair::<Target>()?;

Expand Down
19 changes: 2 additions & 17 deletions bridges/relays/bin-substrate/src/cli/relay_headers_and_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ macro_rules! select_bridge {
type LeftAccountIdConverter = bp_millau::AccountIdConverter;
type RightAccountIdConverter = bp_rialto::AccountIdConverter;

const LEFT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(millau_runtime::VERSION);
const RIGHT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(rialto_runtime::VERSION);

use crate::chains::{
millau_messages_to_rialto::{
update_rialto_to_millau_conversion_rate as update_right_to_left_conversion_rate,
Expand Down Expand Up @@ -181,11 +176,6 @@ macro_rules! select_bridge {
type LeftAccountIdConverter = bp_rococo::AccountIdConverter;
type RightAccountIdConverter = bp_wococo::AccountIdConverter;

const LEFT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_rococo::VERSION);
const RIGHT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_wococo::VERSION);

use crate::chains::{
rococo_messages_to_wococo::RococoMessagesToWococo as LeftToRightMessageLane,
wococo_messages_to_rococo::WococoMessagesToRococo as RightToLeftMessageLane,
Expand Down Expand Up @@ -259,11 +249,6 @@ macro_rules! select_bridge {
type LeftAccountIdConverter = bp_kusama::AccountIdConverter;
type RightAccountIdConverter = bp_polkadot::AccountIdConverter;

const LEFT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_kusama::VERSION);
const RIGHT_RUNTIME_VERSION: Option<sp_version::RuntimeVersion> =
Some(bp_polkadot::VERSION);

use crate::chains::{
kusama_messages_to_polkadot::{
update_polkadot_to_kusama_conversion_rate as update_right_to_left_conversion_rate,
Expand Down Expand Up @@ -335,12 +320,12 @@ impl RelayHeadersAndMessages {
select_bridge!(self, {
let params: Params = self.into();

let left_client = params.left.to_client::<Left>(LEFT_RUNTIME_VERSION).await?;
let left_client = params.left.to_client::<Left>().await?;
let left_transactions_mortality = params.left_sign.transactions_mortality()?;
let left_sign = params.left_sign.to_keypair::<Left>()?;
let left_messages_pallet_owner =
params.left_messages_pallet_owner.to_keypair::<Left>()?;
let right_client = params.right.to_client::<Right>(RIGHT_RUNTIME_VERSION).await?;
let right_client = params.right.to_client::<Right>().await?;
let right_transactions_mortality = params.right_sign.transactions_mortality()?;
let right_sign = params.right_sign.to_keypair::<Right>()?;
let right_messages_pallet_owner =
Expand Down
4 changes: 2 additions & 2 deletions bridges/relays/bin-substrate/src/cli/relay_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(SOURCE_RUNTIME_VERSION).await?;
let source_client = self.source.to_client::<Source>().await?;
let source_sign = self.source_sign.to_keypair::<Source>()?;
let source_transactions_mortality = self.source_sign.transactions_mortality()?;
let target_client = self.target.to_client::<Target>(TARGET_RUNTIME_VERSION).await?;
let target_client = self.target.to_client::<Target>().await?;
let target_sign = self.target_sign.to_keypair::<Target>()?;
let target_transactions_mortality = self.target_sign.transactions_mortality()?;
let relayer_mode = self.relayer_mode.into();
Expand Down
Loading

0 comments on commit 46c25d7

Please sign in to comment.