Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions bin/millau/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use super::{
use bp_messages::LaneId;
use bp_millau::WeightToFee;
use bp_rialto_parachain::RIALTO_PARACHAIN_ID;
use bridge_runtime_common::messages::source::{XcmBridge, XcmBridgeAdapter};
use bridge_runtime_common::{
messages::source::{XcmBridge, XcmBridgeAdapter},
CustomNetworkId,
};
use frame_support::{
parameter_types,
traits::{Everything, Nothing},
Expand All @@ -45,12 +48,12 @@ parameter_types! {
/// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to
/// the context".
pub const TokenLocation: MultiLocation = Here.into_location();
/// The Millau network ID, associated with Kusama.
pub const ThisNetwork: NetworkId = Kusama;
/// The Rialto network ID, associated with Polkadot.
pub const RialtoNetwork: NetworkId = Polkadot;
/// The RialtoParachain network ID, associated with Westend.
pub const RialtoParachainNetwork: NetworkId = Westend;
/// The Millau network ID.
pub const ThisNetwork: NetworkId = CustomNetworkId::Millau.as_network_id();
/// The Rialto network ID.
pub const RialtoNetwork: NetworkId = CustomNetworkId::Rialto.as_network_id();
/// The RialtoParachain network ID.
pub const RialtoParachainNetwork: NetworkId = CustomNetworkId::RialtoParachain.as_network_id();

/// Our XCM location ancestry - i.e. our location within the Consensus Universe.
///
Expand Down
11 changes: 6 additions & 5 deletions bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub use pallet_bridge_messages::Call as MessagesCall;
pub use pallet_xcm::Call as XcmCall;

// Polkadot & XCM imports
use bridge_runtime_common::CustomNetworkId;
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use xcm::latest::prelude::*;
Expand Down Expand Up @@ -304,13 +305,13 @@ impl pallet_randomness_collective_flip::Config for Runtime {}

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
pub const RelayNetwork: NetworkId = CustomNetworkId::Rialto.as_network_id();
pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorMultiLocation = X1(Parachain(ParachainInfo::parachain_id().into()));
/// The Millau network ID, associated with Kusama.
pub const MillauNetwork: NetworkId = Kusama;
/// The RialtoParachain network ID, associated with Westend.
pub const ThisNetwork: NetworkId = Westend;
/// The Millau network ID.
pub const MillauNetwork: NetworkId = CustomNetworkId::Millau.as_network_id();
/// The RialtoParachain network ID.
pub const ThisNetwork: NetworkId = CustomNetworkId::RialtoParachain.as_network_id();
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down
13 changes: 8 additions & 5 deletions bin/rialto/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use super::{
Event, Origin, Runtime, WithMillauMessagesInstance, XcmPallet,
};
use bp_rialto::WeightToFee;
use bridge_runtime_common::messages::source::{XcmBridge, XcmBridgeAdapter};
use bridge_runtime_common::{
messages::source::{XcmBridge, XcmBridgeAdapter},
CustomNetworkId,
};
use frame_support::{
parameter_types,
traits::{Everything, Nothing},
Expand All @@ -39,10 +42,10 @@ parameter_types! {
/// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to
/// the context".
pub const TokenLocation: MultiLocation = Here.into_location();
/// The Rialto network ID, associated with Polkadot.
pub const ThisNetwork: NetworkId = Polkadot;
/// The Millau network ID, associated with Kusama.
pub const MillauNetwork: NetworkId = Kusama;
/// The Rialto network ID.
pub const ThisNetwork: NetworkId = CustomNetworkId::Rialto.as_network_id();
/// The Millau network ID.
pub const MillauNetwork: NetworkId = CustomNetworkId::Millau.as_network_id();

/// Our XCM location ancestry - i.e. our location within the Consensus Universe.
///
Expand Down
23 changes: 23 additions & 0 deletions bin/runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use bp_runtime::FilterCall;
use sp_runtime::transaction_validity::TransactionValidity;
use xcm::v3::NetworkId;

pub mod messages;
pub mod messages_api;
Expand Down Expand Up @@ -119,6 +120,28 @@ macro_rules! generate_bridge_reject_obsolete_headers_and_messages {
};
}

/// A mapping over `NetworkId`.
/// Since `NetworkId` doesn't include `Millau`, `Rialto` and `RialtoParachain`, we create some
/// synthetic associations between these chains and `NetworkId` chains.
pub enum CustomNetworkId {
/// The Millau network ID, associated with Kusama.
Millau,
/// The Rialto network ID, associated with Polkadot.
Rialto,
/// The RialtoParachain network ID, associated with Westend.
RialtoParachain,
}

impl CustomNetworkId {
pub const fn as_network_id(&self) -> NetworkId {
match *self {
CustomNetworkId::Millau => NetworkId::Kusama,
CustomNetworkId::Rialto => NetworkId::Polkadot,
CustomNetworkId::RialtoParachain => NetworkId::Westend,
}
}
}

#[cfg(test)]
mod tests {
use crate::BridgeRuntimeFilterCall;
Expand Down
2 changes: 1 addition & 1 deletion bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ pub mod source {
}

let route = T::build_destination();
let msg = (route, msg.take().unwrap()).encode();
let msg = (route, msg.take().ok_or(SendError::MissingArgument)?).encode();

let fee = estimate_message_dispatch_and_delivery_fee::<T::MessageBridge>(
&msg,
Expand Down
1 change: 0 additions & 1 deletion relays/bin-substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ sp-version = { git = "https://github.com/paritytech/substrate", branch = "master

# Polkadot Dependencies

#pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3", default-features = false }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3" }
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3" }
Expand Down
40 changes: 16 additions & 24 deletions relays/bin-substrate/src/chains/millau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,27 @@ impl CliEncodeMessage for Millau {
message: xcm::VersionedXcm<()>,
bridge_instance_index: u8,
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
Ok(match bridge_instance_index {
bridge::MILLAU_TO_RIALTO_INDEX => {
let dest =
(Parent, X1(GlobalConsensus(millau_runtime::xcm_config::RialtoNetwork::get())));
millau_runtime::Call::XcmPallet(millau_runtime::XcmCall::send {
dest: Box::new(dest.into()),
message: Box::new(message),
})
.into()
},
bridge::MILLAU_TO_RIALTO_PARACHAIN_INDEX => {
let dest = (
Parent,
X2(
GlobalConsensus(millau_runtime::xcm_config::RialtoNetwork::get()),
Parachain(RIALTO_PARACHAIN_ID),
),
);
millau_runtime::Call::XcmPallet(millau_runtime::XcmCall::send {
dest: Box::new(dest.into()),
message: Box::new(message),
})
.into()
},
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::Call::XcmPallet(millau_runtime::XcmCall::send {
dest: Box::new(dest.into()),
message: Box::new(message),
})
.into())
}

fn encode_send_message_call(
Expand Down
19 changes: 9 additions & 10 deletions relays/bin-substrate/src/chains/rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@ impl CliEncodeMessage for Rialto {
message: xcm::VersionedXcm<()>,
bridge_instance_index: u8,
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
Ok(match bridge_instance_index {
bridge::RIALTO_TO_MILLAU_INDEX => {
let dest =
(Parent, X1(GlobalConsensus(rialto_runtime::xcm_config::MillauNetwork::get())));
rialto_runtime::Call::XcmPallet(rialto_runtime::XcmCall::send {
dest: Box::new(dest.into()),
message: Box::new(message),
})
.into()
},
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::Call::XcmPallet(rialto_runtime::XcmCall::send {
dest: Box::new(dest.into()),
message: Box::new(message),
})
.into())
}

fn encode_send_message_call(
Expand Down
21 changes: 9 additions & 12 deletions relays/bin-substrate/src/chains/rialto_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,20 @@ impl CliEncodeMessage for RialtoParachain {
message: xcm::VersionedXcm<()>,
bridge_instance_index: u8,
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
Ok(match bridge_instance_index {
bridge::RIALTO_PARACHAIN_TO_MILLAU_INDEX => {
let dest =
(Parent, X1(GlobalConsensus(rialto_parachain_runtime::MillauNetwork::get())));
rialto_parachain_runtime::Call::PolkadotXcm(
rialto_parachain_runtime::XcmCall::send {
dest: Box::new(dest.into()),
message: Box::new(message),
},
)
.into()
},
let dest = match bridge_instance_index {
bridge::RIALTO_PARACHAIN_TO_MILLAU_INDEX =>
(Parent, X1(GlobalConsensus(rialto_parachain_runtime::MillauNetwork::get()))),
_ => anyhow::bail!(
"Unsupported target bridge pallet with instance index: {}",
bridge_instance_index
),
};

Ok(rialto_parachain_runtime::Call::PolkadotXcm(rialto_parachain_runtime::XcmCall::send {
dest: Box::new(dest.into()),
message: Box::new(message),
})
.into())
}

fn encode_send_message_call(
Expand Down
10 changes: 5 additions & 5 deletions relays/bin-substrate/src/cli/estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
data.conversion_rate_override,
Self::ESTIMATE_MESSAGE_FEE_METHOD,
lane,
payload,
&payload,
)
.await?;

Expand Down Expand Up @@ -141,7 +141,7 @@ pub(crate) async fn estimate_message_delivery_and_dispatch_fee<
conversion_rate_override: Option<ConversionRateOverride>,
estimate_fee_method: &str,
lane: bp_messages::LaneId,
payload: P,
payload: &P,
) -> anyhow::Result<BalanceOf<Source>> {
// actual conversion rate CAN be lesser than the rate stored in the runtime. So we may try to
// pay lesser fee for the message delivery. But in this case, message may be rejected by the
Expand Down Expand Up @@ -196,15 +196,15 @@ pub(crate) async fn estimate_message_delivery_and_dispatch_fee<
client,
estimate_fee_method,
lane,
payload.clone(),
payload,
None,
)
.await?;
let with_override = do_estimate_message_delivery_and_dispatch_fee(
client,
estimate_fee_method,
lane,
payload.clone(),
payload,
conversion_rate_override,
)
.await?;
Expand All @@ -227,7 +227,7 @@ async fn do_estimate_message_delivery_and_dispatch_fee<Source: Chain, P: Encode>
client: &relay_substrate_client::Client<Source>,
estimate_fee_method: &str,
lane: bp_messages::LaneId,
payload: P,
payload: &P,
conversion_rate_override: Option<FixedU128>,
) -> anyhow::Result<BalanceOf<Source>> {
let encoded_response = client
Expand Down
4 changes: 2 additions & 2 deletions relays/bin-substrate/src/cli/send_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ where
conversion_rate_override,
Self::ESTIMATE_MESSAGE_FEE_METHOD,
lane,
payload.clone(),
&payload,
)
.await?
.into(),
),
};
let payload_len = payload.encode().len();
let payload_len = payload.encoded_size();
let send_message_call = if data.use_xcm_pallet {
Self::Source::encode_send_xcm(
decode_xcm(payload)?,
Expand Down