Set R/WococoBridgeHub bundle runtime version (#1756)

* Define SimpleRuntimeVersion

* Set R/WococoBridgeHub bundle runtime version
This commit is contained in:
Serban Iorga
2023-01-11 09:45:22 +02:00
committed by Bastian Köcher
parent 70eb076ab2
commit b4c338f77d
14 changed files with 68 additions and 50 deletions
@@ -20,7 +20,7 @@ use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
use bp_rialto_parachain::RIALTO_PARACHAIN_ID; use bp_rialto_parachain::RIALTO_PARACHAIN_ID;
use bp_runtime::EncodedOrDecodedCall; use bp_runtime::EncodedOrDecodedCall;
use relay_millau_client::Millau; use relay_millau_client::Millau;
use sp_version::RuntimeVersion; use relay_substrate_client::SimpleRuntimeVersion;
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
impl CliEncodeMessage for Millau { impl CliEncodeMessage for Millau {
@@ -53,5 +53,6 @@ impl CliEncodeMessage for Millau {
} }
impl CliChain for Millau { impl CliChain for Millau {
const RUNTIME_VERSION: Option<RuntimeVersion> = Some(millau_runtime::VERSION); const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion::from_runtime_version(&millau_runtime::VERSION));
} }
@@ -19,7 +19,7 @@
use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain}; use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
use bp_runtime::EncodedOrDecodedCall; use bp_runtime::EncodedOrDecodedCall;
use relay_rialto_client::Rialto; use relay_rialto_client::Rialto;
use sp_version::RuntimeVersion; use relay_substrate_client::SimpleRuntimeVersion;
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
impl CliEncodeMessage for Rialto { impl CliEncodeMessage for Rialto {
@@ -45,5 +45,6 @@ impl CliEncodeMessage for Rialto {
} }
impl CliChain for Rialto { impl CliChain for Rialto {
const RUNTIME_VERSION: Option<RuntimeVersion> = Some(rialto_runtime::VERSION); const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion::from_runtime_version(&rialto_runtime::VERSION));
} }
@@ -20,8 +20,7 @@ use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
use bp_runtime::EncodedOrDecodedCall; use bp_runtime::EncodedOrDecodedCall;
use bridge_runtime_common::CustomNetworkId; use bridge_runtime_common::CustomNetworkId;
use relay_rialto_parachain_client::RialtoParachain; use relay_rialto_parachain_client::RialtoParachain;
use relay_substrate_client::calls::XcmCall; use relay_substrate_client::{calls::XcmCall, SimpleRuntimeVersion};
use sp_version::RuntimeVersion;
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
impl CliEncodeMessage for RialtoParachain { impl CliEncodeMessage for RialtoParachain {
@@ -45,5 +44,5 @@ impl CliEncodeMessage for RialtoParachain {
} }
impl CliChain for RialtoParachain { impl CliChain for RialtoParachain {
const RUNTIME_VERSION: Option<RuntimeVersion> = None; const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
} }
@@ -19,12 +19,13 @@
use crate::cli::CliChain; use crate::cli::CliChain;
use relay_bridge_hub_rococo_client::BridgeHubRococo; use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_rococo_client::Rococo; use relay_rococo_client::Rococo;
use sp_version::RuntimeVersion; use relay_substrate_client::SimpleRuntimeVersion;
impl CliChain for Rococo { impl CliChain for Rococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None; const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
} }
impl CliChain for BridgeHubRococo { impl CliChain for BridgeHubRococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None; const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion { spec_version: 9302, transaction_version: 1 });
} }
@@ -52,7 +52,7 @@ impl SubstrateFinalitySyncPipeline for RococoFinalityToBridgeHubWococo {
if enable_version_guard { if enable_version_guard {
relay_substrate_client::guard::abort_on_spec_version_change( relay_substrate_client::guard::abort_on_spec_version_change(
target_client.clone(), target_client.clone(),
target_client.simple_runtime_version().await?.0, target_client.simple_runtime_version().await?.spec_version,
); );
} }
Ok(()) Ok(())
@@ -17,13 +17,13 @@
//! Westend chain specification for CLI. //! Westend chain specification for CLI.
use crate::cli::CliChain; use crate::cli::CliChain;
use relay_substrate_client::SimpleRuntimeVersion;
use relay_westend_client::{Westend, Westmint}; use relay_westend_client::{Westend, Westmint};
use sp_version::RuntimeVersion;
impl CliChain for Westend { impl CliChain for Westend {
const RUNTIME_VERSION: Option<RuntimeVersion> = None; const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
} }
impl CliChain for Westmint { impl CliChain for Westmint {
const RUNTIME_VERSION: Option<RuntimeVersion> = None; const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
} }
@@ -18,13 +18,14 @@
use crate::cli::CliChain; use crate::cli::CliChain;
use relay_bridge_hub_wococo_client::BridgeHubWococo; use relay_bridge_hub_wococo_client::BridgeHubWococo;
use relay_substrate_client::SimpleRuntimeVersion;
use relay_wococo_client::Wococo; use relay_wococo_client::Wococo;
use sp_version::RuntimeVersion;
impl CliChain for Wococo { impl CliChain for Wococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None; const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
} }
impl CliChain for BridgeHubWococo { impl CliChain for BridgeHubWococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None; const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion { spec_version: 9302, transaction_version: 1 });
} }
@@ -52,7 +52,7 @@ impl SubstrateFinalitySyncPipeline for WococoFinalityToBridgeHubRococo {
if enable_version_guard { if enable_version_guard {
relay_substrate_client::guard::abort_on_spec_version_change( relay_substrate_client::guard::abort_on_spec_version_change(
target_client.clone(), target_client.clone(),
target_client.simple_runtime_version().await?.0, target_client.simple_runtime_version().await?.spec_version,
); );
} }
Ok(()) Ok(())
@@ -20,7 +20,7 @@ use structopt::StructOpt;
use strum::{EnumString, EnumVariantNames}; use strum::{EnumString, EnumVariantNames};
use crate::cli::CliChain; use crate::cli::CliChain;
pub use relay_substrate_client::ChainRuntimeVersion; pub use relay_substrate_client::{ChainRuntimeVersion, SimpleRuntimeVersion};
use substrate_relay_helper::TransactionParams; use substrate_relay_helper::TransactionParams;
#[doc = "Runtime version params."] #[doc = "Runtime version params."]
@@ -57,25 +57,24 @@ macro_rules! declare_chain_runtime_version_params_cli_schema {
/// Converts self into `ChainRuntimeVersion`. /// Converts self into `ChainRuntimeVersion`.
pub fn into_runtime_version( pub fn into_runtime_version(
self, self,
bundle_runtime_version: Option<sp_version::RuntimeVersion>, bundle_runtime_version: Option<SimpleRuntimeVersion>,
) -> anyhow::Result<ChainRuntimeVersion> { ) -> anyhow::Result<ChainRuntimeVersion> {
Ok(match self.[<$chain_prefix _version_mode>] { Ok(match self.[<$chain_prefix _version_mode>] {
RuntimeVersionType::Auto => ChainRuntimeVersion::Auto, RuntimeVersionType::Auto => ChainRuntimeVersion::Auto,
RuntimeVersionType::Custom => { RuntimeVersionType::Custom => {
let except_spec_version = self.[<$chain_prefix _spec_version>] let custom_spec_version = self.[<$chain_prefix _spec_version>]
.ok_or_else(|| anyhow::Error::msg(format!("The {}-spec-version is required when choose custom mode", stringify!($chain_prefix))))?; .ok_or_else(|| anyhow::Error::msg(format!("The {}-spec-version is required when choose custom mode", stringify!($chain_prefix))))?;
let except_transaction_version = self.[<$chain_prefix _transaction_version>] let custom_transaction_version = self.[<$chain_prefix _transaction_version>]
.ok_or_else(|| anyhow::Error::msg(format!("The {}-transaction-version is required when choose custom mode", stringify!($chain_prefix))))?; .ok_or_else(|| anyhow::Error::msg(format!("The {}-transaction-version is required when choose custom mode", stringify!($chain_prefix))))?;
ChainRuntimeVersion::Custom( ChainRuntimeVersion::Custom(
except_spec_version, SimpleRuntimeVersion {
except_transaction_version spec_version: custom_spec_version,
transaction_version: custom_transaction_version
}
) )
}, },
RuntimeVersionType::Bundle => match bundle_runtime_version { RuntimeVersionType::Bundle => match bundle_runtime_version {
Some(runtime_version) => ChainRuntimeVersion::Custom( Some(runtime_version) => ChainRuntimeVersion::Custom(runtime_version),
runtime_version.spec_version,
runtime_version.transaction_version
),
None => ChainRuntimeVersion::Auto None => ChainRuntimeVersion::Auto
}, },
}) })
+2 -1
View File
@@ -28,6 +28,7 @@ use structopt::{clap::arg_enum, StructOpt};
use strum::{EnumString, EnumVariantNames}; use strum::{EnumString, EnumVariantNames};
use bp_messages::LaneId; use bp_messages::LaneId;
use relay_substrate_client::SimpleRuntimeVersion;
pub(crate) mod bridge; pub(crate) mod bridge;
pub(crate) mod encode_message; pub(crate) mod encode_message;
@@ -194,7 +195,7 @@ pub trait CliChain: relay_substrate_client::Chain {
/// Current version of the chain runtime, known to relay. /// Current version of the chain runtime, known to relay.
/// ///
/// can be `None` if relay is not going to submit transactions to that chain. /// can be `None` if relay is not going to submit transactions to that chain.
const RUNTIME_VERSION: Option<sp_version::RuntimeVersion>; const RUNTIME_VERSION: Option<SimpleRuntimeVersion>;
} }
/// Lane id. /// Lane id.
@@ -403,7 +403,7 @@ async fn update_transaction_tip<C: ChainWithTransactions>(
})?; })?;
let old_tip = unsigned_tx.tip; let old_tip = unsigned_tx.tip;
let (spec_version, transaction_version) = client.simple_runtime_version().await?; let runtime_version = client.simple_runtime_version().await?;
while current_priority < target_priority { while current_priority < target_priority {
let next_tip = unsigned_tx.tip + tip_step; let next_tip = unsigned_tx.tip + tip_step;
if next_tip > tip_limit { if next_tip > tip_limit {
@@ -425,8 +425,8 @@ async fn update_transaction_tip<C: ChainWithTransactions>(
at_block.1, at_block.1,
C::sign_transaction( C::sign_transaction(
SignParam { SignParam {
spec_version, spec_version: runtime_version.spec_version,
transaction_version, transaction_version: runtime_version.transaction_version,
genesis_hash: *client.genesis_hash(), genesis_hash: *client.genesis_hash(),
signer: transaction_params.signer.clone(), signer: transaction_params.signer.clone(),
}, },
@@ -449,8 +449,8 @@ async fn update_transaction_tip<C: ChainWithTransactions>(
old_tip != unsigned_tx.tip, old_tip != unsigned_tx.tip,
C::sign_transaction( C::sign_transaction(
SignParam { SignParam {
spec_version, spec_version: runtime_version.spec_version,
transaction_version, transaction_version: runtime_version.transaction_version,
genesis_hash: *client.genesis_hash(), genesis_hash: *client.genesis_hash(),
signer: transaction_params.signer.clone(), signer: transaction_params.signer.clone(),
}, },
+28 -13
View File
@@ -75,15 +75,32 @@ pub struct Subscription<T>(pub(crate) Mutex<futures::channel::mpsc::Receiver<Opt
/// Opaque GRANDPA authorities set. /// Opaque GRANDPA authorities set.
pub type OpaqueGrandpaAuthoritiesSet = Vec<u8>; pub type OpaqueGrandpaAuthoritiesSet = Vec<u8>;
/// A simple runtime version. It only includes the `spec_version` and `transaction_version`.
#[derive(Copy, Clone, Debug)]
pub struct SimpleRuntimeVersion {
/// Version of the runtime specification.
pub spec_version: u32,
/// All existing dispatches are fully compatible when this number doesn't change.
pub transaction_version: u32,
}
impl SimpleRuntimeVersion {
/// Create a new instance of `SimpleRuntimeVersion` from a `RuntimeVersion`.
pub const fn from_runtime_version(runtime_version: &RuntimeVersion) -> Self {
Self {
spec_version: runtime_version.spec_version,
transaction_version: runtime_version.transaction_version,
}
}
}
/// Chain runtime version in client /// Chain runtime version in client
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum ChainRuntimeVersion { pub enum ChainRuntimeVersion {
/// Auto query from chain. /// Auto query from chain.
Auto, Auto,
/// Custom runtime version, defined by user. /// Custom runtime version, defined by user.
/// the first is `spec_version` Custom(SimpleRuntimeVersion),
/// the second is `transaction_version`
Custom(u32, u32),
} }
/// Substrate client type. /// Substrate client type.
@@ -213,16 +230,14 @@ impl<C: Chain> Client<C> {
impl<C: Chain> Client<C> { impl<C: Chain> Client<C> {
/// Return simple runtime version, only include `spec_version` and `transaction_version`. /// Return simple runtime version, only include `spec_version` and `transaction_version`.
pub async fn simple_runtime_version(&self) -> Result<(u32, u32)> { pub async fn simple_runtime_version(&self) -> Result<SimpleRuntimeVersion> {
let (spec_version, transaction_version) = match self.chain_runtime_version { Ok(match &self.chain_runtime_version {
ChainRuntimeVersion::Auto => { ChainRuntimeVersion::Auto => {
let runtime_version = self.runtime_version().await?; let runtime_version = self.runtime_version().await?;
(runtime_version.spec_version, runtime_version.transaction_version) SimpleRuntimeVersion::from_runtime_version(&runtime_version)
}, },
ChainRuntimeVersion::Custom(spec_version, transaction_version) => ChainRuntimeVersion::Custom(version) => *version,
(spec_version, transaction_version), })
};
Ok((spec_version, transaction_version))
} }
/// Returns true if client is connected to at least one peer and is in synced state. /// Returns true if client is connected to at least one peer and is in synced state.
@@ -430,10 +445,10 @@ impl<C: Chain> Client<C> {
where where
C: ChainWithTransactions, C: ChainWithTransactions,
{ {
let (spec_version, transaction_version) = self.simple_runtime_version().await?; let runtime_version = self.simple_runtime_version().await?;
Ok(SignParam::<C> { Ok(SignParam::<C> {
spec_version, spec_version: runtime_version.spec_version,
transaction_version, transaction_version: runtime_version.transaction_version,
genesis_hash: self.genesis_hash, genesis_hash: self.genesis_hash,
signer, signer,
}) })
+2 -2
View File
@@ -40,8 +40,8 @@ pub use crate::{
UnsignedTransaction, UtilityPallet, UnsignedTransaction, UtilityPallet,
}, },
client::{ client::{
ChainRuntimeVersion, Client, OpaqueGrandpaAuthoritiesSet, Subscription, ChainRuntimeVersion, Client, OpaqueGrandpaAuthoritiesSet, SimpleRuntimeVersion,
ANCIENT_BLOCK_THRESHOLD, Subscription, ANCIENT_BLOCK_THRESHOLD,
}, },
error::{Error, Result}, error::{Error, Result},
rpc::{SubstrateBeefyFinalityClient, SubstrateFinalityClient, SubstrateGrandpaFinalityClient}, rpc::{SubstrateBeefyFinalityClient, SubstrateFinalityClient, SubstrateGrandpaFinalityClient},
@@ -36,7 +36,7 @@ where
if enable_version_guard { if enable_version_guard {
relay_substrate_client::guard::abort_on_spec_version_change( relay_substrate_client::guard::abort_on_spec_version_change(
target_client.clone(), target_client.clone(),
target_client.simple_runtime_version().await?.0, target_client.simple_runtime_version().await?.spec_version,
); );
} }
relay_substrate_client::guard::abort_when_account_balance_decreased( relay_substrate_client::guard::abort_when_account_balance_decreased(