mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 07:31:02 +00:00
Remove deprecated code from bridge-runtime-common (#1983)
* removed FromBridgedChainMessageDispatch in favor of XcmBlobMessageDispatch * use HaulBlobExporter/HaulBlobExporterAdapter instead of XcmBridge/XcmBridgeAdapter * tests for sending/dispatching messages * use new schema in testnet bridges + some cleanup * clippy * spelling + added TODO * cleanup some checks * benchmarks compilation * all is XCM * updated README.md * ref issue from TODO
This commit is contained in:
committed by
Bastian Köcher
parent
2407228972
commit
a75c28d5b2
@@ -16,37 +16,18 @@
|
||||
|
||||
//! Millau chain specification for CLI.
|
||||
|
||||
use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
|
||||
use bp_rialto_parachain::RIALTO_PARACHAIN_ID;
|
||||
use crate::cli::{encode_message::CliEncodeMessage, CliChain};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use relay_millau_client::Millau;
|
||||
use relay_substrate_client::SimpleRuntimeVersion;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
impl CliEncodeMessage for Millau {
|
||||
fn encode_send_xcm(
|
||||
message: xcm::VersionedXcm<()>,
|
||||
bridge_instance_index: u8,
|
||||
fn encode_execute_xcm(
|
||||
message: xcm::VersionedXcm<Self::Call>,
|
||||
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
|
||||
let dest = match bridge_instance_index {
|
||||
bridge::MILLAU_TO_RIALTO_INDEX =>
|
||||
(Parent, X1(GlobalConsensus(millau_runtime::xcm_config::RialtoNetwork::get()))),
|
||||
bridge::MILLAU_TO_RIALTO_PARACHAIN_INDEX => (
|
||||
Parent,
|
||||
X2(
|
||||
GlobalConsensus(millau_runtime::xcm_config::RialtoNetwork::get()),
|
||||
Parachain(RIALTO_PARACHAIN_ID),
|
||||
),
|
||||
),
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
};
|
||||
|
||||
Ok(millau_runtime::RuntimeCall::XcmPallet(millau_runtime::XcmCall::send {
|
||||
dest: Box::new(dest.into()),
|
||||
Ok(millau_runtime::RuntimeCall::XcmPallet(millau_runtime::XcmCall::execute {
|
||||
message: Box::new(message),
|
||||
max_weight: Self::estimate_execute_xcm_weight(),
|
||||
})
|
||||
.into())
|
||||
}
|
||||
|
||||
@@ -16,29 +16,18 @@
|
||||
|
||||
//! Rialto chain specification for CLI.
|
||||
|
||||
use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
|
||||
use crate::cli::{encode_message::CliEncodeMessage, CliChain};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use relay_rialto_client::Rialto;
|
||||
use relay_substrate_client::SimpleRuntimeVersion;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
impl CliEncodeMessage for Rialto {
|
||||
fn encode_send_xcm(
|
||||
message: xcm::VersionedXcm<()>,
|
||||
bridge_instance_index: u8,
|
||||
fn encode_execute_xcm(
|
||||
message: xcm::VersionedXcm<Self::Call>,
|
||||
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
|
||||
let dest = match bridge_instance_index {
|
||||
bridge::RIALTO_TO_MILLAU_INDEX =>
|
||||
(Parent, X1(GlobalConsensus(rialto_runtime::xcm_config::MillauNetwork::get()))),
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
};
|
||||
|
||||
Ok(rialto_runtime::RuntimeCall::XcmPallet(rialto_runtime::XcmCall::send {
|
||||
dest: Box::new(dest.into()),
|
||||
Ok(rialto_runtime::RuntimeCall::XcmPallet(rialto_runtime::XcmCall::execute {
|
||||
message: Box::new(message),
|
||||
max_weight: Self::estimate_execute_xcm_weight(),
|
||||
})
|
||||
.into())
|
||||
}
|
||||
|
||||
@@ -16,33 +16,21 @@
|
||||
|
||||
//! Rialto parachain specification for CLI.
|
||||
|
||||
use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
|
||||
use crate::cli::{encode_message::CliEncodeMessage, CliChain};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use bridge_runtime_common::CustomNetworkId;
|
||||
use relay_rialto_parachain_client::RialtoParachain;
|
||||
use relay_substrate_client::SimpleRuntimeVersion;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
impl CliEncodeMessage for RialtoParachain {
|
||||
fn encode_send_xcm(
|
||||
message: xcm::VersionedXcm<()>,
|
||||
bridge_instance_index: u8,
|
||||
fn encode_execute_xcm(
|
||||
message: xcm::VersionedXcm<Self::Call>,
|
||||
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
|
||||
type RuntimeCall = relay_rialto_parachain_client::RuntimeCall;
|
||||
type XcmCall = relay_rialto_parachain_client::runtime_types::pallet_xcm::pallet::Call;
|
||||
|
||||
let dest = match bridge_instance_index {
|
||||
bridge::RIALTO_PARACHAIN_TO_MILLAU_INDEX =>
|
||||
(Parent, X1(GlobalConsensus(CustomNetworkId::Millau.as_network_id()))),
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
};
|
||||
|
||||
let xcm_call = XcmCall::send {
|
||||
dest: Box::new(unsafe { std::mem::transmute(xcm::VersionedMultiLocation::from(dest)) }),
|
||||
let xcm_call = XcmCall::execute {
|
||||
message: Box::new(unsafe { std::mem::transmute(message) }),
|
||||
max_weight: Self::estimate_execute_xcm_weight(),
|
||||
};
|
||||
|
||||
Ok(RuntimeCall::PolkadotXcm(xcm_call).into())
|
||||
|
||||
@@ -37,28 +37,6 @@ pub enum FullBridge {
|
||||
BridgeHubPolkadotToBridgeHubKusama,
|
||||
}
|
||||
|
||||
impl FullBridge {
|
||||
/// Return instance index of the bridge pallet in source runtime.
|
||||
pub fn bridge_instance_index(&self) -> u8 {
|
||||
match self {
|
||||
Self::MillauToRialto => MILLAU_TO_RIALTO_INDEX,
|
||||
Self::RialtoToMillau => RIALTO_TO_MILLAU_INDEX,
|
||||
Self::MillauToRialtoParachain => MILLAU_TO_RIALTO_PARACHAIN_INDEX,
|
||||
Self::RialtoParachainToMillau => RIALTO_PARACHAIN_TO_MILLAU_INDEX,
|
||||
Self::BridgeHubRococoToBridgeHubWococo |
|
||||
Self::BridgeHubWococoToBridgeHubRococo |
|
||||
Self::BridgeHubKusamaToBridgeHubPolkadot |
|
||||
Self::BridgeHubPolkadotToBridgeHubKusama =>
|
||||
unimplemented!("Relay doesn't support send-message subcommand on bridge hubs"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const RIALTO_TO_MILLAU_INDEX: u8 = 0;
|
||||
pub const MILLAU_TO_RIALTO_INDEX: u8 = 0;
|
||||
pub const MILLAU_TO_RIALTO_PARACHAIN_INDEX: u8 = 1;
|
||||
pub const RIALTO_PARACHAIN_TO_MILLAU_INDEX: u8 = 0;
|
||||
|
||||
/// Minimal bridge representation that can be used from the CLI.
|
||||
/// It connects a source chain to a target chain.
|
||||
pub trait CliBridgeBase: Sized {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
use crate::cli::{ExplicitOrMaximal, HexBytes};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use codec::Encode;
|
||||
use frame_support::weights::Weight;
|
||||
use relay_substrate_client::Chain;
|
||||
use structopt::StructOpt;
|
||||
|
||||
@@ -42,11 +43,16 @@ pub enum Message {
|
||||
pub type RawMessage = Vec<u8>;
|
||||
|
||||
pub trait CliEncodeMessage: Chain {
|
||||
/// Encode a send XCM call of the XCM pallet.
|
||||
fn encode_send_xcm(
|
||||
message: xcm::VersionedXcm<()>,
|
||||
bridge_instance_index: u8,
|
||||
/// Encode an `execute` XCM call of the XCM pallet.
|
||||
fn encode_execute_xcm(
|
||||
message: xcm::VersionedXcm<Self::Call>,
|
||||
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>>;
|
||||
|
||||
/// Estimate value of `max_weight` argument for the `execute` XCM call of the XCM pallet.
|
||||
fn estimate_execute_xcm_weight() -> Weight {
|
||||
// we are only executing XCM on our testnets and 1/100 of max extrinsic weight is ok
|
||||
Self::max_extrinsic_weight() / 100
|
||||
}
|
||||
}
|
||||
|
||||
/// Encode message payload passed through CLI flags.
|
||||
@@ -125,7 +131,7 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(msg.len(), 100);
|
||||
// check that it decodes to valid xcm
|
||||
let _ = decode_xcm(msg).unwrap();
|
||||
let _ = decode_xcm::<()>(msg).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -140,6 +146,6 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(msg.len(), maximal_size as usize);
|
||||
// check that it decodes to valid xcm
|
||||
let _ = decode_xcm(msg).unwrap();
|
||||
let _ = decode_xcm::<()>(msg).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,10 +75,7 @@ where
|
||||
let source_sign = data.source_sign.to_keypair::<Self::Source>()?;
|
||||
|
||||
let payload_len = payload.encoded_size();
|
||||
let send_message_call = Self::Source::encode_send_xcm(
|
||||
decode_xcm(payload)?,
|
||||
data.bridge.bridge_instance_index(),
|
||||
)?;
|
||||
let send_message_call = Self::Source::encode_execute_xcm(decode_xcm(payload)?)?;
|
||||
|
||||
source_client
|
||||
.submit_signed_extrinsic(&source_sign, move |_, transaction_nonce| {
|
||||
@@ -130,7 +127,7 @@ impl SendMessage {
|
||||
}
|
||||
|
||||
/// Decode SCALE encoded raw XCM message.
|
||||
pub(crate) fn decode_xcm(message: RawMessage) -> anyhow::Result<xcm::VersionedXcm<()>> {
|
||||
pub(crate) fn decode_xcm<Call>(message: RawMessage) -> anyhow::Result<xcm::VersionedXcm<Call>> {
|
||||
Decode::decode(&mut &message[..])
|
||||
.map_err(|e| anyhow::format_err!("Failed to decode XCM program: {:?}", e))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user