From 444dbe71730c3a90762ee88ca89a9db03edd8bec Mon Sep 17 00:00:00 2001
From: Serban Iorga <serban@parity.io>
Date: Tue, 10 Jan 2023 17:05:00 +0200
Subject: [PATCH] Use indirect runtime calls for RialtoParachain (#1753)

* Use indirect runtime calls for RialtoParachain

* Code review fixes
---
 bridges/primitives/runtime/src/lib.rs         |  1 -
 bridges/relays/bin-substrate/Cargo.toml       |  1 -
 ...ub_rococo_messages_to_bridge_hub_wococo.rs |  1 -
 ...ub_wococo_messages_to_bridge_hub_rococo.rs |  1 -
 .../millau_headers_to_rialto_parachain.rs     | 16 +++--
 .../millau_messages_to_rialto_parachain.rs    | 17 +++--
 .../src/chains/rialto_parachain.rs            | 16 ++---
 .../rialto_parachain_messages_to_millau.rs    | 19 +++---
 .../bin-substrate/src/cli/init_bridge.rs      | 16 ++---
 .../client-bridge-hub-rococo/Cargo.toml       |  1 +
 .../client-bridge-hub-rococo/src/lib.rs       |  2 +-
 .../src/runtime_wrapper.rs                    |  2 +-
 .../src/runtime_wrapper.rs                    |  2 +-
 .../relays/client-rialto-parachain/Cargo.toml | 12 +++-
 .../relays/client-rialto-parachain/src/lib.rs | 68 +++++++------------
 .../src/runtime_wrapper.rs                    | 57 ++++++++++++++++
 bridges/relays/client-substrate/Cargo.toml    |  6 ++
 .../client-substrate}/src/calls.rs            | 22 +++++-
 bridges/relays/client-substrate/src/lib.rs    |  1 +
 .../lib-substrate-relay/src/messages_lane.rs  |  2 +-
 20 files changed, 168 insertions(+), 95 deletions(-)
 create mode 100644 bridges/relays/client-rialto-parachain/src/runtime_wrapper.rs
 rename bridges/{primitives/runtime => relays/client-substrate}/src/calls.rs (62%)

diff --git a/bridges/primitives/runtime/src/lib.rs b/bridges/primitives/runtime/src/lib.rs
index 4c3fb152fa7..340088a85b1 100644
--- a/bridges/primitives/runtime/src/lib.rs
+++ b/bridges/primitives/runtime/src/lib.rs
@@ -47,7 +47,6 @@ pub use storage_types::BoundedStorageValue;
 #[cfg(feature = "std")]
 pub use storage_proof::craft_valid_storage_proof;
 
-pub mod calls;
 pub mod messages;
 
 mod chain;
diff --git a/bridges/relays/bin-substrate/Cargo.toml b/bridges/relays/bin-substrate/Cargo.toml
index c88b930cbb0..0ab3bd5634f 100644
--- a/bridges/relays/bin-substrate/Cargo.toml
+++ b/bridges/relays/bin-substrate/Cargo.toml
@@ -51,7 +51,6 @@ relay-substrate-client = { path = "../client-substrate" }
 relay-utils = { path = "../utils" }
 relay-westend-client = { path = "../client-westend" }
 relay-wococo-client = { path = "../client-wococo" }
-rialto-parachain-runtime = { path = "../../bin/rialto-parachain/runtime" }
 rialto-runtime = { path = "../../bin/rialto/runtime" }
 substrate-relay-helper = { path = "../lib-substrate-relay" }
 
diff --git a/bridges/relays/bin-substrate/src/chains/bridge_hub_rococo_messages_to_bridge_hub_wococo.rs b/bridges/relays/bin-substrate/src/chains/bridge_hub_rococo_messages_to_bridge_hub_wococo.rs
index 339be92063e..8422569d009 100644
--- a/bridges/relays/bin-substrate/src/chains/bridge_hub_rococo_messages_to_bridge_hub_wococo.rs
+++ b/bridges/relays/bin-substrate/src/chains/bridge_hub_rococo_messages_to_bridge_hub_wococo.rs
@@ -17,7 +17,6 @@
 //! BridgeHubRococo-to-BridgeHubWococo messages sync entrypoint.
 
 use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
-use bp_messages::Weight;
 use relay_bridge_hub_rococo_client::BridgeHubRococo;
 use relay_bridge_hub_wococo_client::BridgeHubWococo;
 use substrate_relay_helper::messages_lane::SubstrateMessageLane;
diff --git a/bridges/relays/bin-substrate/src/chains/bridge_hub_wococo_messages_to_bridge_hub_rococo.rs b/bridges/relays/bin-substrate/src/chains/bridge_hub_wococo_messages_to_bridge_hub_rococo.rs
index 3bb2aabde06..96df83cd0b2 100644
--- a/bridges/relays/bin-substrate/src/chains/bridge_hub_wococo_messages_to_bridge_hub_rococo.rs
+++ b/bridges/relays/bin-substrate/src/chains/bridge_hub_wococo_messages_to_bridge_hub_rococo.rs
@@ -17,7 +17,6 @@
 //! BridgeHubWococo-to-BridgeHubRococo messages sync entrypoint.
 
 use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge};
-use bp_messages::Weight;
 use relay_bridge_hub_rococo_client::BridgeHubRococo;
 use relay_bridge_hub_wococo_client::BridgeHubWococo;
 use substrate_relay_helper::messages_lane::SubstrateMessageLane;
diff --git a/bridges/relays/bin-substrate/src/chains/millau_headers_to_rialto_parachain.rs b/bridges/relays/bin-substrate/src/chains/millau_headers_to_rialto_parachain.rs
index b830ce7fcc4..6496167cf7c 100644
--- a/bridges/relays/bin-substrate/src/chains/millau_headers_to_rialto_parachain.rs
+++ b/bridges/relays/bin-substrate/src/chains/millau_headers_to_rialto_parachain.rs
@@ -36,10 +36,16 @@
 
 use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, RelayToRelayHeadersCliBridge};
 use substrate_relay_helper::finality::{
-	engine::Grandpa as GrandpaFinalityEngine, DirectSubmitGrandpaFinalityProofCallBuilder,
-	SubstrateFinalitySyncPipeline,
+	engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalitySyncPipeline,
 };
 
+substrate_relay_helper::generate_mocked_submit_finality_proof_call_builder!(
+	MillauFinalityToRialtoParachain,
+	MillauFinalityToRialtoParachainCallBuilder,
+	relay_rialto_parachain_client::runtime::Call::BridgeMillauGrandpa,
+	relay_rialto_parachain_client::runtime::BridgeMillauGrandpaCall::submit_finality_proof
+);
+
 /// Description of Millau -> Rialto finalized headers bridge.
 #[derive(Clone, Debug)]
 pub struct MillauFinalityToRialtoParachain;
@@ -49,11 +55,7 @@ impl SubstrateFinalitySyncPipeline for MillauFinalityToRialtoParachain {
 	type TargetChain = relay_rialto_parachain_client::RialtoParachain;
 
 	type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
-	type SubmitFinalityProofCallBuilder = DirectSubmitGrandpaFinalityProofCallBuilder<
-		Self,
-		rialto_parachain_runtime::Runtime,
-		rialto_parachain_runtime::MillauGrandpaInstance,
-	>;
+	type SubmitFinalityProofCallBuilder = MillauFinalityToRialtoParachainCallBuilder;
 }
 
 //// `Millau` to `RialtoParachain`  bridge definition.
diff --git a/bridges/relays/bin-substrate/src/chains/millau_messages_to_rialto_parachain.rs b/bridges/relays/bin-substrate/src/chains/millau_messages_to_rialto_parachain.rs
index 0b1d3afb797..817d0098d9b 100644
--- a/bridges/relays/bin-substrate/src/chains/millau_messages_to_rialto_parachain.rs
+++ b/bridges/relays/bin-substrate/src/chains/millau_messages_to_rialto_parachain.rs
@@ -19,10 +19,16 @@
 use relay_millau_client::Millau;
 use relay_rialto_parachain_client::RialtoParachain;
 use substrate_relay_helper::messages_lane::{
-	DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
-	SubstrateMessageLane,
+	DirectReceiveMessagesDeliveryProofCallBuilder, SubstrateMessageLane,
 };
 
+substrate_relay_helper::generate_mocked_receive_message_proof_call_builder!(
+	MillauMessagesToRialtoParachain,
+	MillauMessagesToRialtoParachainReceiveMessagesProofCallBuilder,
+	relay_rialto_parachain_client::runtime::Call::BridgeMillauMessages,
+	relay_rialto_parachain_client::runtime::BridgeMillauMessagesCall::receive_messages_proof
+);
+
 /// Description of Millau -> RialtoParachain messages bridge.
 #[derive(Clone, Debug)]
 pub struct MillauMessagesToRialtoParachain;
@@ -31,11 +37,8 @@ impl SubstrateMessageLane for MillauMessagesToRialtoParachain {
 	type SourceChain = Millau;
 	type TargetChain = RialtoParachain;
 
-	type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
-		Self,
-		rialto_parachain_runtime::Runtime,
-		rialto_parachain_runtime::WithMillauMessagesInstance,
-	>;
+	type ReceiveMessagesProofCallBuilder =
+		MillauMessagesToRialtoParachainReceiveMessagesProofCallBuilder;
 	type ReceiveMessagesDeliveryProofCallBuilder = DirectReceiveMessagesDeliveryProofCallBuilder<
 		Self,
 		millau_runtime::Runtime,
diff --git a/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs b/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs
index 7105dc2b7d7..4d1e1b02e37 100644
--- a/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs
+++ b/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs
@@ -18,7 +18,9 @@
 
 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 xcm::latest::prelude::*;
 
@@ -29,23 +31,19 @@ impl CliEncodeMessage for RialtoParachain {
 	) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
 		let dest = match bridge_instance_index {
 			bridge::RIALTO_PARACHAIN_TO_MILLAU_INDEX =>
-				(Parent, X1(GlobalConsensus(rialto_parachain_runtime::MillauNetwork::get()))),
+				(Parent, X1(GlobalConsensus(CustomNetworkId::Millau.as_network_id()))),
 			_ => anyhow::bail!(
 				"Unsupported target bridge pallet with instance index: {}",
 				bridge_instance_index
 			),
 		};
 
-		Ok(rialto_parachain_runtime::RuntimeCall::PolkadotXcm(
-			rialto_parachain_runtime::XcmCall::send {
-				dest: Box::new(dest.into()),
-				message: Box::new(message),
-			},
-		)
-		.into())
+		let xcm_call = XcmCall::send(Box::new(dest.into()), Box::new(message));
+
+		Ok(relay_rialto_parachain_client::runtime::Call::PolkadotXcm(xcm_call).into())
 	}
 }
 
 impl CliChain for RialtoParachain {
-	const RUNTIME_VERSION: Option<RuntimeVersion> = Some(rialto_parachain_runtime::VERSION);
+	const RUNTIME_VERSION: Option<RuntimeVersion> = None;
 }
diff --git a/bridges/relays/bin-substrate/src/chains/rialto_parachain_messages_to_millau.rs b/bridges/relays/bin-substrate/src/chains/rialto_parachain_messages_to_millau.rs
index 74db3738e6b..0000a0a754a 100644
--- a/bridges/relays/bin-substrate/src/chains/rialto_parachain_messages_to_millau.rs
+++ b/bridges/relays/bin-substrate/src/chains/rialto_parachain_messages_to_millau.rs
@@ -19,13 +19,17 @@
 use relay_millau_client::Millau;
 use relay_rialto_parachain_client::RialtoParachain;
 use substrate_relay_helper::{
-	messages_lane::{
-		DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
-		SubstrateMessageLane,
-	},
+	messages_lane::{DirectReceiveMessagesProofCallBuilder, SubstrateMessageLane},
 	UtilityPalletBatchCallBuilder,
 };
 
+substrate_relay_helper::generate_mocked_receive_message_delivery_proof_call_builder!(
+	RialtoParachainMessagesToMillau,
+	RialtoParachainMessagesToMillauReceiveMessagesDeliveryProofCallBuilder,
+	relay_rialto_parachain_client::runtime::Call::BridgeMillauMessages,
+	relay_rialto_parachain_client::runtime::BridgeMillauMessagesCall::receive_messages_delivery_proof
+);
+
 /// Description of RialtoParachain -> Millau messages bridge.
 #[derive(Clone, Debug)]
 pub struct RialtoParachainMessagesToMillau;
@@ -39,11 +43,8 @@ impl SubstrateMessageLane for RialtoParachainMessagesToMillau {
 		millau_runtime::Runtime,
 		millau_runtime::WithRialtoParachainMessagesInstance,
 	>;
-	type ReceiveMessagesDeliveryProofCallBuilder = DirectReceiveMessagesDeliveryProofCallBuilder<
-		Self,
-		rialto_parachain_runtime::Runtime,
-		rialto_parachain_runtime::WithMillauMessagesInstance,
-	>;
+	type ReceiveMessagesDeliveryProofCallBuilder =
+		RialtoParachainMessagesToMillauReceiveMessagesDeliveryProofCallBuilder;
 
 	type SourceBatchCallBuilder = ();
 	type TargetBatchCallBuilder = UtilityPalletBatchCallBuilder<Millau>;
diff --git a/bridges/relays/bin-substrate/src/cli/init_bridge.rs b/bridges/relays/bin-substrate/src/cli/init_bridge.rs
index 322cca1bef5..8f4080b338c 100644
--- a/bridges/relays/bin-substrate/src/cli/init_bridge.rs
+++ b/bridges/relays/bin-substrate/src/cli/init_bridge.rs
@@ -29,7 +29,7 @@ use crate::{
 	cli::{bridge::CliBridgeBase, chain_schema::*},
 };
 use bp_runtime::Chain as ChainBase;
-use relay_substrate_client::{AccountKeyPairOf, Chain, UnsignedTransaction};
+use relay_substrate_client::{calls::SudoCall, AccountKeyPairOf, Chain, UnsignedTransaction};
 use sp_core::Pair;
 use structopt::StructOpt;
 use strum::{EnumString, EnumVariantNames, VariantNames};
@@ -123,13 +123,13 @@ impl BridgeInitializer for MillauToRialtoParachainCliBridge {
 	fn encode_init_bridge(
 		init_data: <Self::Engine as Engine<Self::Source>>::InitializationData,
 	) -> <Self::Target as Chain>::Call {
-		let initialize_call = rialto_parachain_runtime::BridgeGrandpaCall::<
-			rialto_parachain_runtime::Runtime,
-			rialto_parachain_runtime::MillauGrandpaInstance,
-		>::initialize {
-			init_data,
-		};
-		rialto_parachain_runtime::SudoCall::sudo { call: Box::new(initialize_call.into()) }.into()
+		use relay_rialto_parachain_client::runtime;
+
+		let initialize_call = runtime::Call::BridgeMillauGrandpa(
+			runtime::BridgeMillauGrandpaCall::initialize(init_data),
+		);
+		let sudo_call = SudoCall::sudo(Box::new(initialize_call));
+		runtime::Call::Sudo(sudo_call)
 	}
 }
 
diff --git a/bridges/relays/client-bridge-hub-rococo/Cargo.toml b/bridges/relays/client-bridge-hub-rococo/Cargo.toml
index 6872c59f760..e650ba9da76 100644
--- a/bridges/relays/client-bridge-hub-rococo/Cargo.toml
+++ b/bridges/relays/client-bridge-hub-rococo/Cargo.toml
@@ -22,6 +22,7 @@ bp-runtime = { path = "../../primitives/runtime" }
 bp-wococo = { path = "../../primitives/chain-wococo" }
 
 bridge-runtime-common = { path = "../../bin/runtime-common" }
+
 # Substrate Dependencies
 
 sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
diff --git a/bridges/relays/client-bridge-hub-rococo/src/lib.rs b/bridges/relays/client-bridge-hub-rococo/src/lib.rs
index 08a9e688487..653c5af2c5e 100644
--- a/bridges/relays/client-bridge-hub-rococo/src/lib.rs
+++ b/bridges/relays/client-bridge-hub-rococo/src/lib.rs
@@ -132,7 +132,7 @@ mod tests {
 	#[test]
 	fn parse_transaction_works() {
 		let unsigned = UnsignedTransaction {
-			call: runtime::Call::System(bp_runtime::calls::SystemCall::remark(
+			call: runtime::Call::System(relay_substrate_client::calls::SystemCall::remark(
 				b"Hello world!".to_vec(),
 			))
 			.into(),
diff --git a/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs b/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs
index e7136117360..2c50128201b 100644
--- a/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs
+++ b/bridges/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs
@@ -23,8 +23,8 @@ use scale_info::TypeInfo;
 
 pub use bp_header_chain::BridgeGrandpaCallOf;
 pub use bp_parachains::BridgeParachainCall;
-pub use bp_runtime::calls::SystemCall;
 pub use bridge_runtime_common::messages::BridgeMessagesCallOf;
+pub use relay_substrate_client::calls::SystemCall;
 
 // TODO:check-parameter - check SignedExtension
 /// Unchecked BridgeHubRococo extrinsic.
diff --git a/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs b/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs
index 5c11d8c7ebf..0d73a91029d 100644
--- a/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs
+++ b/bridges/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs
@@ -21,8 +21,8 @@ use scale_info::TypeInfo;
 
 pub use bp_header_chain::BridgeGrandpaCallOf;
 pub use bp_parachains::BridgeParachainCall;
-pub use bp_runtime::calls::SystemCall;
 pub use bridge_runtime_common::messages::BridgeMessagesCallOf;
+pub use relay_substrate_client::calls::SystemCall;
 
 // TODO:check-parameter - check SignedExtension
 /// Unchecked BridgeHubWococo extrinsic.
diff --git a/bridges/relays/client-rialto-parachain/Cargo.toml b/bridges/relays/client-rialto-parachain/Cargo.toml
index 915d0e786cc..8ecc915f953 100644
--- a/bridges/relays/client-rialto-parachain/Cargo.toml
+++ b/bridges/relays/client-rialto-parachain/Cargo.toml
@@ -7,14 +7,20 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
 
 [dependencies]
 codec = { package = "parity-scale-codec", version = "3.1.5" }
-relay-substrate-client = { path = "../client-substrate" }
-relay-utils = { path = "../utils" }
+scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
 
 # Bridge dependencies
 
+bp-header-chain = { path = "../../primitives/header-chain" }
 bp-messages = { path = "../../primitives/messages" }
+bp-millau = { path = "../../primitives/chain-millau" }
+bp-polkadot-core = { path = "../../primitives/polkadot-core" }
 bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" }
-rialto-parachain-runtime = { path = "../../bin/rialto-parachain/runtime" }
+bp-runtime = { path = "../../primitives/runtime" }
+
+bridge-runtime-common = { path = "../../bin/runtime-common" }
+relay-substrate-client = { path = "../client-substrate" }
+relay-utils = { path = "../utils" }
 
 # Substrate Dependencies
 
diff --git a/bridges/relays/client-rialto-parachain/src/lib.rs b/bridges/relays/client-rialto-parachain/src/lib.rs
index 16abd6e8808..c3fb0da7418 100644
--- a/bridges/relays/client-rialto-parachain/src/lib.rs
+++ b/bridges/relays/client-rialto-parachain/src/lib.rs
@@ -16,6 +16,8 @@
 
 //! Types used to connect to the Rialto-Substrate chain.
 
+pub mod runtime_wrapper;
+
 use bp_messages::MessageNonce;
 use codec::Encode;
 use relay_substrate_client::{
@@ -23,12 +25,13 @@ use relay_substrate_client::{
 	SignParam, UnderlyingChainProvider, UnsignedTransaction,
 };
 use sp_core::{storage::StorageKey, Pair};
-use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
+use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount, MultiAddress};
 use std::time::Duration;
 
-/// Rialto header id.
-pub type HeaderId =
-	relay_utils::HeaderId<rialto_parachain_runtime::Hash, rialto_parachain_runtime::BlockNumber>;
+pub use runtime_wrapper as runtime;
+
+/// The address format for describing accounts.
+pub type Address = MultiAddress<bp_rialto_parachain::AccountId, ()>;
 
 /// Rialto parachain definition
 #[derive(Debug, Clone, Copy)]
@@ -46,18 +49,13 @@ impl Chain for RialtoParachain {
 		bp_rialto_parachain::BEST_FINALIZED_RIALTO_PARACHAIN_HEADER_METHOD;
 	const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(5);
 
-	type SignedBlock = rialto_parachain_runtime::SignedBlock;
-	type Call = rialto_parachain_runtime::RuntimeCall;
+	type SignedBlock = bp_polkadot_core::SignedBlock;
+	type Call = runtime::Call;
 }
 
 impl ChainWithBalances for RialtoParachain {
 	fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey {
-		use frame_support::storage::generator::StorageMap;
-		StorageKey(
-			frame_system::Account::<rialto_parachain_runtime::Runtime>::storage_map_final_key(
-				account_id,
-			),
-		)
+		bp_polkadot_core::AccountInfoStorageMapKeyProvider::final_key(account_id)
 	}
 }
 
@@ -77,45 +75,30 @@ impl ChainWithMessages for RialtoParachain {
 
 impl ChainWithTransactions for RialtoParachain {
 	type AccountKeyPair = sp_core::sr25519::Pair;
-	type SignedTransaction = rialto_parachain_runtime::UncheckedExtrinsic;
+	type SignedTransaction = bp_polkadot_core::UncheckedExtrinsic<Self::Call>;
 
 	fn sign_transaction(
 		param: SignParam<Self>,
 		unsigned: UnsignedTransaction<Self>,
 	) -> Result<Self::SignedTransaction, SubstrateError> {
-		let raw_payload = SignedPayload::from_raw(
+		let raw_payload = SignedPayload::new(
 			unsigned.call,
-			(
-				frame_system::CheckNonZeroSender::<rialto_parachain_runtime::Runtime>::new(),
-				frame_system::CheckSpecVersion::<rialto_parachain_runtime::Runtime>::new(),
-				frame_system::CheckTxVersion::<rialto_parachain_runtime::Runtime>::new(),
-				frame_system::CheckGenesis::<rialto_parachain_runtime::Runtime>::new(),
-				frame_system::CheckEra::<rialto_parachain_runtime::Runtime>::from(
-					unsigned.era.frame_era(),
-				),
-				frame_system::CheckNonce::<rialto_parachain_runtime::Runtime>::from(unsigned.nonce),
-				frame_system::CheckWeight::<rialto_parachain_runtime::Runtime>::new(),
-				pallet_transaction_payment::ChargeTransactionPayment::<
-					rialto_parachain_runtime::Runtime,
-				>::from(unsigned.tip),
-			),
-			(
-				(),
+			bp_polkadot_core::SignedExtensions::new(
 				param.spec_version,
 				param.transaction_version,
+				unsigned.era,
 				param.genesis_hash,
-				unsigned.era.signed_payload(param.genesis_hash),
-				(),
-				(),
-				(),
+				unsigned.nonce,
+				unsigned.tip,
 			),
-		);
+		)?;
+
 		let signature = raw_payload.using_encoded(|payload| param.signer.sign(payload));
 		let signer: sp_runtime::MultiSigner = param.signer.public().into();
 		let (call, extra, _) = raw_payload.deconstruct();
 
-		Ok(rialto_parachain_runtime::UncheckedExtrinsic::new_signed(
-			call.into_decoded()?,
+		Ok(Self::SignedTransaction::new_signed(
+			call,
 			signer.into_account().into(),
 			signature.into(),
 			extra,
@@ -129,14 +112,13 @@ impl ChainWithTransactions for RialtoParachain {
 	fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
 		tx.signature
 			.as_ref()
-			.map(|(address, _, _)| {
-				*address == rialto_parachain_runtime::Address::Id(signer.public().into())
-			})
+			.map(|(address, _, _)| *address == Address::Id(signer.public().into()))
 			.unwrap_or(false)
 	}
 
-	fn parse_transaction(_tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
-		None
+	fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
+		let extra = &tx.signature.as_ref()?.2;
+		Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
 	}
 }
 
@@ -144,4 +126,4 @@ impl ChainWithTransactions for RialtoParachain {
 pub type SigningParams = sp_core::sr25519::Pair;
 
 /// RialtoParachain header type used in headers sync.
-pub type SyncHeader = relay_substrate_client::SyncHeader<rialto_parachain_runtime::Header>;
+pub type SyncHeader = relay_substrate_client::SyncHeader<bp_rialto_parachain::Header>;
diff --git a/bridges/relays/client-rialto-parachain/src/runtime_wrapper.rs b/bridges/relays/client-rialto-parachain/src/runtime_wrapper.rs
new file mode 100644
index 00000000000..b595d145d01
--- /dev/null
+++ b/bridges/relays/client-rialto-parachain/src/runtime_wrapper.rs
@@ -0,0 +1,57 @@
+// Copyright 2019-2021 Parity Technologies (UK) Ltd.
+// This file is part of Parity Bridges Common.
+
+// Parity Bridges Common is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Parity Bridges Common is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Parity Bridges Common.  If not, see <http://www.gnu.org/licenses/>.
+
+//! Types that are specific to the `RialtoParachain` runtime. Normally we could use the full
+//! `RialtoParachain` runtime here, since it is constructed in this repo and we have access to it.
+//! However we use a wrapped runtime instead in order to test the indirect runtime calls
+//! functionality.
+
+use codec::{Decode, Encode};
+use scale_info::TypeInfo;
+
+use bp_header_chain::BridgeGrandpaCallOf;
+use bridge_runtime_common::messages::BridgeMessagesCallOf;
+use relay_substrate_client::calls::{SudoCall, XcmCall};
+
+// The indirect pallet call used to sync `Millau` GRANDPA finality to `RialtoParachain`.
+pub type BridgeMillauGrandpaCall = BridgeGrandpaCallOf<bp_millau::Millau>;
+// The indirect pallet call used to sync `Millau` messages to `RialtoParachain`.
+pub type BridgeMillauMessagesCall = BridgeMessagesCallOf<bp_millau::Millau>;
+
+/// `RialtoParachain` Runtime `Call` enum.
+///
+/// The enum represents a subset of possible `Call`s we can send to `RialtoParachain` chain.
+///
+/// All entries here (like pretty much in the entire file) must be kept in sync with
+/// `RialtoParachain` `construct_runtime`, so that we maintain SCALE-compatibility.
+#[allow(clippy::large_enum_variant)]
+#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
+pub enum Call {
+	/// `Sudo` pallet.
+	#[codec(index = 2)]
+	Sudo(SudoCall<Call>),
+
+	/// `Xcm` pallet.
+	#[codec(index = 51)]
+	PolkadotXcm(XcmCall),
+
+	/// Millau GRANDPA bridge pallet.
+	#[codec(index = 55)]
+	BridgeMillauGrandpa(BridgeMillauGrandpaCall),
+	/// Millau messages bridge pallet.
+	#[codec(index = 56)]
+	BridgeMillauMessages(BridgeMillauMessagesCall),
+}
diff --git a/bridges/relays/client-substrate/Cargo.toml b/bridges/relays/client-substrate/Cargo.toml
index 29b910c11bd..f9760a32603 100644
--- a/bridges/relays/client-substrate/Cargo.toml
+++ b/bridges/relays/client-substrate/Cargo.toml
@@ -14,6 +14,7 @@ jsonrpsee = { version = "0.15", features = ["macros", "ws-client"] }
 log = "0.4.17"
 num-traits = "0.2"
 rand = "0.7"
+scale-info = { version = "2.1.1", features = ["derive"] }
 tokio = { version = "1.8", features = ["rt-multi-thread"] }
 thiserror = "1.0.26"
 
@@ -42,10 +43,15 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
 sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
 sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
 sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
+sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" }
 sp-storage = { git = "https://github.com/paritytech/substrate", branch = "master" }
 sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
 sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" }
 
+# Polkadot Dependencies
+
+xcm = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
+
 [features]
 default = []
 test-helpers = []
diff --git a/bridges/primitives/runtime/src/calls.rs b/bridges/relays/client-substrate/src/calls.rs
similarity index 62%
rename from bridges/primitives/runtime/src/calls.rs
rename to bridges/relays/client-substrate/src/calls.rs
index 194c2126ba3..89fc49a209a 100644
--- a/bridges/primitives/runtime/src/calls.rs
+++ b/bridges/relays/client-substrate/src/calls.rs
@@ -18,7 +18,9 @@
 
 use codec::{Decode, Encode};
 use scale_info::TypeInfo;
-use sp_std::vec::Vec;
+use sp_std::{boxed::Box, vec::Vec};
+
+use xcm::{VersionedMultiLocation, VersionedXcm};
 
 /// A minimized version of `frame-system::Call` that can be used without a runtime.
 #[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
@@ -28,3 +30,21 @@ pub enum SystemCall {
 	#[codec(index = 1)]
 	remark(Vec<u8>),
 }
+
+/// A minimized version of `pallet-sudo::Call` that can be used without a runtime.
+#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
+#[allow(non_camel_case_types)]
+pub enum SudoCall<Call> {
+	/// `pallet-sudo::Call::sudo`
+	#[codec(index = 0)]
+	sudo(Box<Call>),
+}
+
+/// A minimized version of `pallet-xcm::Call`, that can be used without a runtime.
+#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
+#[allow(non_camel_case_types)]
+pub enum XcmCall {
+	/// `pallet-xcm::Call::send`
+	#[codec(index = 0)]
+	send(Box<VersionedMultiLocation>, Box<VersionedXcm<()>>),
+}
diff --git a/bridges/relays/client-substrate/src/lib.rs b/bridges/relays/client-substrate/src/lib.rs
index e576aca1119..599d9c658b5 100644
--- a/bridges/relays/client-substrate/src/lib.rs
+++ b/bridges/relays/client-substrate/src/lib.rs
@@ -25,6 +25,7 @@ mod rpc;
 mod sync_header;
 mod transaction_tracker;
 
+pub mod calls;
 pub mod guard;
 pub mod metrics;
 pub mod test_chain;
diff --git a/bridges/relays/lib-substrate-relay/src/messages_lane.rs b/bridges/relays/lib-substrate-relay/src/messages_lane.rs
index 22ff3e7215b..61ea72853f4 100644
--- a/bridges/relays/lib-substrate-relay/src/messages_lane.rs
+++ b/bridges/relays/lib-substrate-relay/src/messages_lane.rs
@@ -330,7 +330,7 @@ macro_rules! generate_mocked_receive_message_proof_call_builder {
 					<$pipeline as $crate::messages_lane::SubstrateMessageLane>::SourceChain
 				>,
 				messages_count: u32,
-				dispatch_weight: Weight,
+				dispatch_weight: bp_messages::Weight,
 				_trace_call: bool,
 			) -> relay_substrate_client::CallOf<
 				<$pipeline as $crate::messages_lane::SubstrateMessageLane>::TargetChain
-- 
GitLab