From 2f9d8e33e0fde576892d2d5571a94d9fd68d2b31 Mon Sep 17 00:00:00 2001
From: Svyatoslav Nikolsky <svyatonik@gmail.com>
Date: Mon, 13 Jun 2022 15:43:58 +0300
Subject: [PATCH] Add missing parts to rialto parachain bridge (part 1) (#1454)

* add proper parameter names to bridge declaration

* associate RialtoParachain token with DOT

* RialtoParachain<>Millau message pallet owners

* fix compilation
---
 .../rialto-parachain/node/src/chain_spec.rs   |  9 ++++---
 .../bin/rialto-parachain/runtime/src/lib.rs   |  2 +-
 bridges/primitives/chain-millau/src/lib.rs    |  8 ++++++
 .../chain-rialto-parachain/src/lib.rs         | 13 ++++++---
 .../millau_messages_to_rialto_parachain.rs    | 27 ++++++++++++++-----
 .../rialto_parachain_messages_to_millau.rs    | 24 ++++++++++++-----
 .../relays/client-rialto-parachain/src/lib.rs |  5 ++--
 7 files changed, 64 insertions(+), 24 deletions(-)

diff --git a/bridges/bin/rialto-parachain/node/src/chain_spec.rs b/bridges/bin/rialto-parachain/node/src/chain_spec.rs
index f1d063c5a7b..e22035905c9 100644
--- a/bridges/bin/rialto-parachain/node/src/chain_spec.rs
+++ b/bridges/bin/rialto-parachain/node/src/chain_spec.rs
@@ -15,7 +15,7 @@
 // along with Parity Bridges Common.  If not, see <http://www.gnu.org/licenses/>.
 
 use cumulus_primitives_core::ParaId;
-use rialto_parachain_runtime::{AccountId, AuraId, Signature};
+use rialto_parachain_runtime::{AccountId, AuraId, BridgeMillauMessagesConfig, Signature};
 use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
 use sc_service::ChainType;
 use serde::{Deserialize, Serialize};
@@ -82,6 +82,7 @@ fn endowed_accounts() -> Vec<AccountId> {
 		get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
 		get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
 		get_account_id_from_seed::<sr25519::Public>("George//stash"),
+		get_account_id_from_seed::<sr25519::Public>("MillauMessagesOwner"),
 		pallet_bridge_messages::relayer_fund_account_id::<
 			bp_rialto_parachain::AccountId,
 			bp_rialto_parachain::AccountIdConverter,
@@ -172,7 +173,9 @@ fn testnet_genesis(
 		parachain_info: rialto_parachain_runtime::ParachainInfoConfig { parachain_id: id },
 		aura: rialto_parachain_runtime::AuraConfig { authorities: initial_authorities },
 		aura_ext: Default::default(),
-		bridge_millau_messages: Default::default(),
-		// parachain_system: Default::default(),
+		bridge_millau_messages: BridgeMillauMessagesConfig {
+			owner: Some(get_account_id_from_seed::<sr25519::Public>("MillauMessagesOwner")),
+			..Default::default()
+		},
 	}
 }
diff --git a/bridges/bin/rialto-parachain/runtime/src/lib.rs b/bridges/bin/rialto-parachain/runtime/src/lib.rs
index 1f8a0a2581e..ec1c754f7df 100644
--- a/bridges/bin/rialto-parachain/runtime/src/lib.rs
+++ b/bridges/bin/rialto-parachain/runtime/src/lib.rs
@@ -85,7 +85,7 @@ use xcm_builder::{
 };
 use xcm_executor::{Config, XcmExecutor};
 
-mod millau_messages;
+pub mod millau_messages;
 
 /// The address format for describing accounts.
 pub type Address = MultiAddress<AccountId, ()>;
diff --git a/bridges/primitives/chain-millau/src/lib.rs b/bridges/primitives/chain-millau/src/lib.rs
index b91ec86e3fe..c9b4153b2fc 100644
--- a/bridges/primitives/chain-millau/src/lib.rs
+++ b/bridges/primitives/chain-millau/src/lib.rs
@@ -282,9 +282,17 @@ frame_support::parameter_types! {
 pub const WITH_MILLAU_GRANDPA_PALLET_NAME: &str = "BridgeMillauGrandpa";
 /// Name of the With-Millau messages pallet instance that is deployed at bridged chains.
 pub const WITH_MILLAU_MESSAGES_PALLET_NAME: &str = "BridgeMillauMessages";
+/// Name of the transaction payment pallet at the Millau runtime.
+pub const TRANSACTION_PAYMENT_PALLET_NAME: &str = "TransactionPayment";
 
 /// Name of the Rialto->Millau (actually DOT->KSM) conversion rate stored in the Millau runtime.
 pub const RIALTO_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME: &str = "RialtoToMillauConversionRate";
+/// Name of the RialtoParachain->Millau (actually DOT->KSM) conversion rate stored in the Millau
+/// runtime.
+pub const RIALTO_PARACHAIN_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME: &str =
+	"RialtoParachainToMillauConversionRate";
+/// Name of the RialtoParachain fee multiplier parameter, stored in the Millau runtime.
+pub const RIALTO_PARACHAIN_FEE_MULTIPLIER_PARAMETER_NAME: &str = "RialtoParachainFeeMultiplier";
 
 /// Name of the `MillauFinalityApi::best_finalized` runtime method.
 pub const BEST_FINALIZED_MILLAU_HEADER_METHOD: &str = "MillauFinalityApi_best_finalized";
diff --git a/bridges/primitives/chain-rialto-parachain/src/lib.rs b/bridges/primitives/chain-rialto-parachain/src/lib.rs
index d42bfaf4110..df66996c4b1 100644
--- a/bridges/primitives/chain-rialto-parachain/src/lib.rs
+++ b/bridges/primitives/chain-rialto-parachain/src/lib.rs
@@ -195,10 +195,15 @@ frame_support::parameter_types! {
 
 /// Name of the With-Rialto-Parachain messages pallet instance that is deployed at bridged chains.
 pub const WITH_RIALTO_PARACHAIN_MESSAGES_PALLET_NAME: &str = "BridgeRialtoParachainMessages";
-
-/// Name of the Millau->Rialto (actually KSM->DOT) conversion rate stored in the Rialto parachain
-/// runtime.
-pub const MILLAU_TO_RIALTO_CONVERSION_RATE_PARAMETER_NAME: &str = "MillauToRialtoConversionRate";
+/// Name of the transaction payment pallet at the Rialto parachain runtime.
+pub const TRANSACTION_PAYMENT_PALLET_NAME: &str = "TransactionPayment";
+
+/// Name of the Millau->RialtoParachain (actually KSM->DOT) conversion rate stored in the Rialto
+/// parachain runtime.
+pub const MILLAU_TO_RIALTO_PARACHAIN_CONVERSION_RATE_PARAMETER_NAME: &str =
+	"MillauToRialtoParachainConversionRate";
+/// Name of the Millau fee multiplier parameter, stored in the Rialto parachain runtime.
+pub const MILLAU_FEE_MULTIPLIER_PARAMETER_NAME: &str = "MillauFeeMultiplier";
 
 /// Name of the `RialtoParachainFinalityApi::best_finalized` runtime method.
 pub const BEST_FINALIZED_RIALTO_PARACHAIN_HEADER_METHOD: &str =
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 f12fd1de89e..d5b42798dd4 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
@@ -27,17 +27,29 @@ use substrate_relay_helper::messages_lane::{
 /// Description of Millau -> RialtoParachain messages bridge.
 #[derive(Clone, Debug)]
 pub struct MillauMessagesToRialtoParachain;
+substrate_relay_helper::generate_direct_update_conversion_rate_call_builder!(
+	Millau,
+	MillauMessagesToRialtoParachainUpdateConversionRateCallBuilder,
+	millau_runtime::Runtime,
+	millau_runtime::WithRialtoParachainMessagesInstance,
+	millau_runtime::rialto_parachain_messages::MillauToRialtoParachainMessagesParameter::RialtoParachainToMillauConversionRate
+);
 
 impl SubstrateMessageLane for MillauMessagesToRialtoParachain {
 	const SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
-		Some(bp_rialto_parachain::MILLAU_TO_RIALTO_CONVERSION_RATE_PARAMETER_NAME);
+		Some(bp_rialto_parachain::MILLAU_TO_RIALTO_PARACHAIN_CONVERSION_RATE_PARAMETER_NAME);
 	const TARGET_TO_SOURCE_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
-		Some(bp_millau::RIALTO_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME);
+		Some(bp_millau::RIALTO_PARACHAIN_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME);
 
-	const SOURCE_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;
-	const TARGET_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;
-	const AT_SOURCE_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;
-	const AT_TARGET_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;
+	const SOURCE_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> =
+		Some(bp_rialto_parachain::MILLAU_FEE_MULTIPLIER_PARAMETER_NAME);
+	const TARGET_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> =
+		Some(bp_millau::RIALTO_PARACHAIN_FEE_MULTIPLIER_PARAMETER_NAME);
+
+	const AT_SOURCE_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> =
+		Some(bp_millau::TRANSACTION_PAYMENT_PALLET_NAME);
+	const AT_TARGET_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> =
+		Some(bp_rialto_parachain::TRANSACTION_PAYMENT_PALLET_NAME);
 
 	type SourceChain = Millau;
 	type TargetChain = RialtoParachain;
@@ -56,7 +68,8 @@ impl SubstrateMessageLane for MillauMessagesToRialtoParachain {
 		millau_runtime::WithRialtoParachainMessagesInstance,
 	>;
 
-	type TargetToSourceChainConversionRateUpdateBuilder = ();
+	type TargetToSourceChainConversionRateUpdateBuilder =
+		MillauMessagesToRialtoParachainUpdateConversionRateCallBuilder;
 
 	type RelayStrategy = MixStrategy;
 }
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 e1fef8caf0a..bc9b8a3170b 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
@@ -27,17 +27,29 @@ use substrate_relay_helper::messages_lane::{
 /// Description of RialtoParachain -> Millau messages bridge.
 #[derive(Clone, Debug)]
 pub struct RialtoParachainMessagesToMillau;
+substrate_relay_helper::generate_direct_update_conversion_rate_call_builder!(
+	RialtoParachain,
+	RialtoParachainMessagesToMillauUpdateConversionRateCallBuilder,
+	rialto_parachain_runtime::Runtime,
+	rialto_parachain_runtime::WithMillauMessagesInstance,
+	rialto_parachain_runtime::millau_messages::RialtoParachainToMillauMessagesParameter::MillauToRialtoParachainConversionRate
+);
 
 impl SubstrateMessageLane for RialtoParachainMessagesToMillau {
 	const SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
-		Some(bp_millau::RIALTO_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME);
+		Some(bp_millau::RIALTO_PARACHAIN_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME);
 	const TARGET_TO_SOURCE_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
-		Some(bp_rialto_parachain::MILLAU_TO_RIALTO_CONVERSION_RATE_PARAMETER_NAME);
+		Some(bp_rialto_parachain::MILLAU_TO_RIALTO_PARACHAIN_CONVERSION_RATE_PARAMETER_NAME);
 
-	const SOURCE_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;
-	const TARGET_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;
-	const AT_SOURCE_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;
-	const AT_TARGET_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;
+	const SOURCE_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> =
+		Some(bp_millau::RIALTO_PARACHAIN_FEE_MULTIPLIER_PARAMETER_NAME);
+	const TARGET_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> =
+		Some(bp_rialto_parachain::MILLAU_FEE_MULTIPLIER_PARAMETER_NAME);
+
+	const AT_SOURCE_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> =
+		Some(bp_rialto_parachain::TRANSACTION_PAYMENT_PALLET_NAME);
+	const AT_TARGET_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> =
+		Some(bp_millau::TRANSACTION_PAYMENT_PALLET_NAME);
 
 	type SourceChain = RialtoParachain;
 	type TargetChain = Millau;
diff --git a/bridges/relays/client-rialto-parachain/src/lib.rs b/bridges/relays/client-rialto-parachain/src/lib.rs
index 9f54363d9c4..74393211d93 100644
--- a/bridges/relays/client-rialto-parachain/src/lib.rs
+++ b/bridges/relays/client-rialto-parachain/src/lib.rs
@@ -57,9 +57,8 @@ impl ChainBase for RialtoParachain {
 
 impl Chain for RialtoParachain {
 	const NAME: &'static str = "RialtoParachain";
-	const TOKEN_ID: Option<&'static str> = None;
-	// should be fixed/changed in https://github.com/paritytech/parity-bridges-common/pull/1199
-	// should be removed in https://github.com/paritytech/parity-bridges-common/issues/1246
+	// RialtoParachain token has no value, but we associate it with DOT token
+	const TOKEN_ID: Option<&'static str> = Some("polkadot");
 	const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
 		bp_rialto_parachain::BEST_FINALIZED_RIALTO_PARACHAIN_HEADER_METHOD;
 	const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(5);
-- 
GitLab