Skip to content

Commit

Permalink
Set R/WococoBridgeHub bundle runtime version (paritytech#1756)
Browse files Browse the repository at this point in the history
* Define SimpleRuntimeVersion

* Set R/WococoBridgeHub bundle runtime version
  • Loading branch information
serban300 authored Jan 11, 2023
1 parent a3a2a06 commit 1327c9d
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 50 deletions.
5 changes: 3 additions & 2 deletions relays/bin-substrate/src/chains/millau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
use bp_rialto_parachain::RIALTO_PARACHAIN_ID;
use bp_runtime::EncodedOrDecodedCall;
use relay_millau_client::Millau;
use sp_version::RuntimeVersion;
use relay_substrate_client::SimpleRuntimeVersion;
use xcm::latest::prelude::*;

impl CliEncodeMessage for Millau {
Expand Down Expand Up @@ -53,5 +53,6 @@ impl CliEncodeMessage 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));
}
5 changes: 3 additions & 2 deletions relays/bin-substrate/src/chains/rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
use bp_runtime::EncodedOrDecodedCall;
use relay_rialto_client::Rialto;
use sp_version::RuntimeVersion;
use relay_substrate_client::SimpleRuntimeVersion;
use xcm::latest::prelude::*;

impl CliEncodeMessage for Rialto {
Expand All @@ -45,5 +45,6 @@ impl CliEncodeMessage 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));
}
5 changes: 2 additions & 3 deletions relays/bin-substrate/src/chains/rialto_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
use bp_runtime::EncodedOrDecodedCall;
use bridge_runtime_common::CustomNetworkId;
use relay_rialto_parachain_client::RialtoParachain;
use relay_substrate_client::calls::XcmCall;
use sp_version::RuntimeVersion;
use relay_substrate_client::{calls::XcmCall, SimpleRuntimeVersion};
use xcm::latest::prelude::*;

impl CliEncodeMessage for RialtoParachain {
Expand All @@ -45,5 +44,5 @@ impl CliEncodeMessage for RialtoParachain {
}

impl CliChain for RialtoParachain {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
}
7 changes: 4 additions & 3 deletions relays/bin-substrate/src/chains/rococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
use crate::cli::CliChain;
use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_rococo_client::Rococo;
use sp_version::RuntimeVersion;
use relay_substrate_client::SimpleRuntimeVersion;

impl CliChain for Rococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
}

impl CliChain for BridgeHubRococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion { spec_version: 9302, transaction_version: 1 });
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl SubstrateFinalitySyncPipeline for RococoFinalityToBridgeHubWococo {
if enable_version_guard {
relay_substrate_client::guard::abort_on_spec_version_change(
target_client.clone(),
target_client.simple_runtime_version().await?.0,
target_client.simple_runtime_version().await?.spec_version,
);
}
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions relays/bin-substrate/src/chains/westend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
//! Westend chain specification for CLI.

use crate::cli::CliChain;
use relay_substrate_client::SimpleRuntimeVersion;
use relay_westend_client::{Westend, Westmint};
use sp_version::RuntimeVersion;

impl CliChain for Westend {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
}

impl CliChain for Westmint {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
}
7 changes: 4 additions & 3 deletions relays/bin-substrate/src/chains/wococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

use crate::cli::CliChain;
use relay_bridge_hub_wococo_client::BridgeHubWococo;
use relay_substrate_client::SimpleRuntimeVersion;
use relay_wococo_client::Wococo;
use sp_version::RuntimeVersion;

impl CliChain for Wococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
}

impl CliChain for BridgeHubWococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion { spec_version: 9302, transaction_version: 1 });
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl SubstrateFinalitySyncPipeline for WococoFinalityToBridgeHubRococo {
if enable_version_guard {
relay_substrate_client::guard::abort_on_spec_version_change(
target_client.clone(),
target_client.simple_runtime_version().await?.0,
target_client.simple_runtime_version().await?.spec_version,
);
}
Ok(())
Expand Down
19 changes: 9 additions & 10 deletions relays/bin-substrate/src/cli/chain_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use structopt::StructOpt;
use strum::{EnumString, EnumVariantNames};

use crate::cli::CliChain;
pub use relay_substrate_client::ChainRuntimeVersion;
pub use relay_substrate_client::{ChainRuntimeVersion, SimpleRuntimeVersion};
use substrate_relay_helper::TransactionParams;

#[doc = "Runtime version params."]
Expand Down Expand Up @@ -57,25 +57,24 @@ macro_rules! declare_chain_runtime_version_params_cli_schema {
/// Converts self into `ChainRuntimeVersion`.
pub fn into_runtime_version(
self,
bundle_runtime_version: Option<sp_version::RuntimeVersion>,
bundle_runtime_version: Option<SimpleRuntimeVersion>,
) -> anyhow::Result<ChainRuntimeVersion> {
Ok(match self.[<$chain_prefix _version_mode>] {
RuntimeVersionType::Auto => ChainRuntimeVersion::Auto,
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))))?;
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))))?;
ChainRuntimeVersion::Custom(
except_spec_version,
except_transaction_version
SimpleRuntimeVersion {
spec_version: custom_spec_version,
transaction_version: custom_transaction_version
}
)
},
RuntimeVersionType::Bundle => match bundle_runtime_version {
Some(runtime_version) => ChainRuntimeVersion::Custom(
runtime_version.spec_version,
runtime_version.transaction_version
),
Some(runtime_version) => ChainRuntimeVersion::Custom(runtime_version),
None => ChainRuntimeVersion::Auto
},
})
Expand Down
3 changes: 2 additions & 1 deletion relays/bin-substrate/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use structopt::{clap::arg_enum, StructOpt};
use strum::{EnumString, EnumVariantNames};

use bp_messages::LaneId;
use relay_substrate_client::SimpleRuntimeVersion;

pub(crate) mod bridge;
pub(crate) mod encode_message;
Expand Down Expand Up @@ -194,7 +195,7 @@ pub trait CliChain: relay_substrate_client::Chain {
/// Current version of the chain runtime, known to relay.
///
/// 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.
Expand Down
10 changes: 5 additions & 5 deletions relays/bin-substrate/src/cli/resubmit_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ async fn update_transaction_tip<C: ChainWithTransactions>(
})?;
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 {
let next_tip = unsigned_tx.tip + tip_step;
if next_tip > tip_limit {
Expand All @@ -425,8 +425,8 @@ async fn update_transaction_tip<C: ChainWithTransactions>(
at_block.1,
C::sign_transaction(
SignParam {
spec_version,
transaction_version,
spec_version: runtime_version.spec_version,
transaction_version: runtime_version.transaction_version,
genesis_hash: *client.genesis_hash(),
signer: transaction_params.signer.clone(),
},
Expand All @@ -449,8 +449,8 @@ async fn update_transaction_tip<C: ChainWithTransactions>(
old_tip != unsigned_tx.tip,
C::sign_transaction(
SignParam {
spec_version,
transaction_version,
spec_version: runtime_version.spec_version,
transaction_version: runtime_version.transaction_version,
genesis_hash: *client.genesis_hash(),
signer: transaction_params.signer.clone(),
},
Expand Down
41 changes: 28 additions & 13 deletions relays/client-substrate/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,32 @@ pub struct Subscription<T>(pub(crate) Mutex<futures::channel::mpsc::Receiver<Opt
/// Opaque GRANDPA authorities set.
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
#[derive(Clone, Debug)]
pub enum ChainRuntimeVersion {
/// Auto query from chain.
Auto,
/// Custom runtime version, defined by user.
/// the first is `spec_version`
/// the second is `transaction_version`
Custom(u32, u32),
Custom(SimpleRuntimeVersion),
}

/// Substrate client type.
Expand Down Expand Up @@ -213,16 +230,14 @@ impl<C: Chain> Client<C> {

impl<C: Chain> Client<C> {
/// Return simple runtime version, only include `spec_version` and `transaction_version`.
pub async fn simple_runtime_version(&self) -> Result<(u32, u32)> {
let (spec_version, transaction_version) = match self.chain_runtime_version {
pub async fn simple_runtime_version(&self) -> Result<SimpleRuntimeVersion> {
Ok(match &self.chain_runtime_version {
ChainRuntimeVersion::Auto => {
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) =>
(spec_version, transaction_version),
};
Ok((spec_version, transaction_version))
ChainRuntimeVersion::Custom(version) => *version,
})
}

/// Returns true if client is connected to at least one peer and is in synced state.
Expand Down Expand Up @@ -430,10 +445,10 @@ impl<C: Chain> Client<C> {
where
C: ChainWithTransactions,
{
let (spec_version, transaction_version) = self.simple_runtime_version().await?;
let runtime_version = self.simple_runtime_version().await?;
Ok(SignParam::<C> {
spec_version,
transaction_version,
spec_version: runtime_version.spec_version,
transaction_version: runtime_version.transaction_version,
genesis_hash: self.genesis_hash,
signer,
})
Expand Down
4 changes: 2 additions & 2 deletions relays/client-substrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub use crate::{
UnsignedTransaction, UtilityPallet,
},
client::{
ChainRuntimeVersion, Client, OpaqueGrandpaAuthoritiesSet, Subscription,
ANCIENT_BLOCK_THRESHOLD,
ChainRuntimeVersion, Client, OpaqueGrandpaAuthoritiesSet, SimpleRuntimeVersion,
Subscription, ANCIENT_BLOCK_THRESHOLD,
},
error::{Error, Result},
rpc::{SubstrateBeefyFinalityClient, SubstrateFinalityClient, SubstrateGrandpaFinalityClient},
Expand Down
2 changes: 1 addition & 1 deletion relays/lib-substrate-relay/src/finality/guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
if enable_version_guard {
relay_substrate_client::guard::abort_on_spec_version_change(
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(
Expand Down

0 comments on commit 1327c9d

Please sign in to comment.