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:
Svyatoslav Nikolsky
2023-03-23 10:44:53 +03:00
committed by Bastian Köcher
parent 2407228972
commit a75c28d5b2
21 changed files with 604 additions and 889 deletions
@@ -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))
}