Skip to content
Snippets Groups Projects
Commit 8b1e1465 authored by Branislav Kontur's avatar Branislav Kontur Committed by Bastian Köcher
Browse files

Pokladot sdk backport to staging (#2746)

* Bump to `polkadot-sdk` master `ebe2aad6`

* align with others

* Backport xcm version stuff from `polkadot-sdk`

* Backport Slava's commit from `polkadot-sdk`

* Workspace clippy as `polkadot-sdk` does

* Make submodules use workspace lints

* Add Bridges clippy addons to workspace lints

* Looks like we dont need extra clippy addons anymore?
parent 23440cea
Branches
No related merge requests found
Showing
with 179 additions and 51 deletions
...@@ -7,6 +7,9 @@ edition.workspace = true ...@@ -7,6 +7,9 @@ edition.workspace = true
repository.workspace = true repository.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
hash-db = { version = "0.16.0", default-features = false } hash-db = { version = "0.16.0", default-features = false }
...@@ -59,8 +62,8 @@ std = [ ...@@ -59,8 +62,8 @@ std = [
"bp-polkadot-core/std", "bp-polkadot-core/std",
"bp-relayers/std", "bp-relayers/std",
"bp-runtime/std", "bp-runtime/std",
"bp-xcm-bridge-hub/std",
"bp-xcm-bridge-hub-router/std", "bp-xcm-bridge-hub-router/std",
"bp-xcm-bridge-hub/std",
"codec/std", "codec/std",
"frame-support/std", "frame-support/std",
"frame-system/std", "frame-system/std",
......
...@@ -309,6 +309,28 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> { ...@@ -309,6 +309,28 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
} }
} }
/// Adapter for the implementation of `GetVersion`, which attempts to find the minimal
/// configured XCM version between the destination `dest` and the bridge hub location provided as
/// `Get<Location>`.
pub struct XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>(
sp_std::marker::PhantomData<(Version, RemoteBridge)>,
);
impl<Version: GetVersion, RemoteBridge: Get<MultiLocation>> GetVersion
for XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>
{
fn get_version_for(dest: &MultiLocation) -> Option<XcmVersion> {
let dest_version = Version::get_version_for(dest);
let bridge_hub_version = Version::get_version_for(&RemoteBridge::get());
match (dest_version, bridge_hub_version) {
(Some(dv), Some(bhv)) => Some(sp_std::cmp::min(dv, bhv)),
(Some(dv), None) => Some(dv),
(None, Some(bhv)) => Some(bhv),
(None, None) => None,
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
......
...@@ -6,6 +6,9 @@ authors = ["Parity Technologies <admin@parity.io>"] ...@@ -6,6 +6,9 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021" edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false } log = { version = "0.4.20", default-features = false }
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false } log = { version = "0.4.20", default-features = false }
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false } log = { version = "0.4.20", default-features = false }
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false } log = { version = "0.4.20", default-features = false }
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false } log = { version = "0.4.20", default-features = false }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
use crate::{Bridge, Call}; use crate::{Bridge, Call};
use bp_xcm_bridge_hub_router::{BridgeState, MINIMAL_DELIVERY_FEE_FACTOR}; use bp_xcm_bridge_hub_router::{BridgeState, MINIMAL_DELIVERY_FEE_FACTOR};
use frame_benchmarking::benchmarks_instance_pallet; use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError};
use frame_support::traits::{EnsureOrigin, Get, Hooks, UnfilteredDispatchable}; use frame_support::traits::{EnsureOrigin, Get, Hooks, UnfilteredDispatchable};
use sp_runtime::traits::Zero; use sp_runtime::traits::Zero;
use xcm::prelude::*; use xcm::prelude::*;
...@@ -37,11 +37,11 @@ pub trait Config<I: 'static>: crate::Config<I> { ...@@ -37,11 +37,11 @@ pub trait Config<I: 'static>: crate::Config<I> {
/// Returns destination which is valid for this router instance. /// Returns destination which is valid for this router instance.
/// (Needs to pass `T::Bridges`) /// (Needs to pass `T::Bridges`)
/// Make sure that `SendXcm` will pass. /// Make sure that `SendXcm` will pass.
fn ensure_bridged_target_destination() -> MultiLocation { fn ensure_bridged_target_destination() -> Result<MultiLocation, BenchmarkError> {
MultiLocation::new( Ok(MultiLocation::new(
Self::UniversalLocation::get().len() as u8, Self::UniversalLocation::get().len() as u8,
X1(GlobalConsensus(Self::BridgedNetworkId::get().unwrap())), X1(GlobalConsensus(Self::BridgedNetworkId::get().unwrap())),
) ))
} }
} }
...@@ -61,7 +61,7 @@ benchmarks_instance_pallet! { ...@@ -61,7 +61,7 @@ benchmarks_instance_pallet! {
delivery_fee_factor: MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR, delivery_fee_factor: MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR,
}); });
let _ = T::ensure_bridged_target_destination(); let _ = T::ensure_bridged_target_destination()?;
T::make_congested(); T::make_congested();
}: { }: {
crate::Pallet::<T, I>::on_initialize(Zero::zero()) crate::Pallet::<T, I>::on_initialize(Zero::zero())
...@@ -81,7 +81,7 @@ benchmarks_instance_pallet! { ...@@ -81,7 +81,7 @@ benchmarks_instance_pallet! {
} }
send_message { send_message {
let dest = T::ensure_bridged_target_destination(); let dest = T::ensure_bridged_target_destination()?;
let xcm = sp_std::vec![].into(); let xcm = sp_std::vec![].into();
// make local queue congested, because it means additional db write // make local queue congested, because it means additional db write
......
...@@ -89,6 +89,8 @@ pub mod pallet { ...@@ -89,6 +89,8 @@ pub mod pallet {
/// **possible fee**. Allows to externalize better control over allowed **bridged /// **possible fee**. Allows to externalize better control over allowed **bridged
/// networks/locations**. /// networks/locations**.
type Bridges: ExporterFor; type Bridges: ExporterFor;
/// Checks the XCM version for the destination.
type DestinationVersion: GetVersion;
/// Origin of the sibling bridge hub that is allowed to report bridge status. /// Origin of the sibling bridge hub that is allowed to report bridge status.
type BridgeHubOrigin: EnsureOrigin<Self::RuntimeOrigin>; type BridgeHubOrigin: EnsureOrigin<Self::RuntimeOrigin>;
...@@ -319,12 +321,13 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> { ...@@ -319,12 +321,13 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
dest: &mut Option<MultiLocation>, dest: &mut Option<MultiLocation>,
xcm: &mut Option<Xcm<()>>, xcm: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> { ) -> SendResult<Self::Ticket> {
// we won't have an access to `dest` and `xcm` in the `delvier` method, so precompute // `dest` and `xcm` are required here
let dest_ref = dest.as_ref().ok_or(SendError::MissingArgument)?;
let xcm_ref = xcm.as_ref().ok_or(SendError::MissingArgument)?;
// we won't have an access to `dest` and `xcm` in the `deliver` method, so precompute
// everything required here // everything required here
let message_size = xcm let message_size = xcm_ref.encoded_size() as _;
.as_ref()
.map(|xcm| xcm.encoded_size() as _)
.ok_or(SendError::MissingArgument)?;
// bridge doesn't support oversized/overweight messages now. So it is better to drop such // bridge doesn't support oversized/overweight messages now. So it is better to drop such
// messages here than at the bridge hub. Let's check the message size. // messages here than at the bridge hub. Let's check the message size.
...@@ -332,6 +335,18 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> { ...@@ -332,6 +335,18 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
return Err(SendError::ExceedsMaxMessageSize) return Err(SendError::ExceedsMaxMessageSize)
} }
// We need to ensure that the known `dest`'s XCM version can comprehend the current `xcm`
// program. This may seem like an additional, unnecessary check, but it is not. A similar
// check is probably performed by the `ViaBridgeHubExporter`, which attempts to send a
// versioned message to the sibling bridge hub. However, the local bridge hub may have a
// higher XCM version than the remote `dest`. Once again, it is better to discard such
// messages here than at the bridge hub (e.g., to avoid losing funds).
let destination_version = T::DestinationVersion::get_version_for(dest_ref)
.ok_or(SendError::DestinationUnsupported)?;
let _ = VersionedXcm::from(xcm_ref.clone())
.into_version(destination_version)
.map_err(|()| SendError::DestinationUnsupported)?;
// just use exporter to validate destination and insert instructions to pay message fee // just use exporter to validate destination and insert instructions to pay message fee
// at the sibling/child bridge hub // at the sibling/child bridge hub
// //
...@@ -358,6 +373,7 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> { ...@@ -358,6 +373,7 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use frame_support::assert_ok;
use mock::*; use mock::*;
use frame_support::traits::Hooks; use frame_support::traits::Hooks;
...@@ -451,6 +467,19 @@ mod tests { ...@@ -451,6 +467,19 @@ mod tests {
}); });
} }
#[test]
fn destination_unsupported_if_wrap_version_fails() {
run_test(|| {
assert_eq!(
send_xcm::<XcmBridgeHubRouter>(
UnknownXcmVersionLocation::get(),
vec![ClearOrigin].into(),
),
Err(SendError::DestinationUnsupported),
);
});
}
#[test] #[test]
fn returns_proper_delivery_price() { fn returns_proper_delivery_price() {
run_test(|| { run_test(|| {
...@@ -488,17 +517,14 @@ mod tests { ...@@ -488,17 +517,14 @@ mod tests {
fn sent_message_doesnt_increase_factor_if_xcm_channel_is_uncongested() { fn sent_message_doesnt_increase_factor_if_xcm_channel_is_uncongested() {
run_test(|| { run_test(|| {
let old_bridge = XcmBridgeHubRouter::bridge(); let old_bridge = XcmBridgeHubRouter::bridge();
assert_eq!( assert_ok!(send_xcm::<XcmBridgeHubRouter>(
send_xcm::<XcmBridgeHubRouter>( MultiLocation::new(
MultiLocation::new( 2,
2, X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)) ),
), vec![ClearOrigin].into(),
vec![ClearOrigin].into(), )
) .map(drop));
.map(drop),
Ok(()),
);
assert!(TestToBridgeHubSender::is_message_sent()); assert!(TestToBridgeHubSender::is_message_sent());
assert_eq!(old_bridge, XcmBridgeHubRouter::bridge()); assert_eq!(old_bridge, XcmBridgeHubRouter::bridge());
...@@ -511,17 +537,14 @@ mod tests { ...@@ -511,17 +537,14 @@ mod tests {
TestWithBridgeHubChannel::make_congested(); TestWithBridgeHubChannel::make_congested();
let old_bridge = XcmBridgeHubRouter::bridge(); let old_bridge = XcmBridgeHubRouter::bridge();
assert_eq!( assert_ok!(send_xcm::<XcmBridgeHubRouter>(
send_xcm::<XcmBridgeHubRouter>( MultiLocation::new(
MultiLocation::new( 2,
2, X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)) ),
), vec![ClearOrigin].into(),
vec![ClearOrigin].into(), )
) .map(drop));
.map(drop),
Ok(()),
);
assert!(TestToBridgeHubSender::is_message_sent()); assert!(TestToBridgeHubSender::is_message_sent());
assert!( assert!(
...@@ -536,17 +559,14 @@ mod tests { ...@@ -536,17 +559,14 @@ mod tests {
Bridge::<TestRuntime, ()>::put(congested_bridge(MINIMAL_DELIVERY_FEE_FACTOR)); Bridge::<TestRuntime, ()>::put(congested_bridge(MINIMAL_DELIVERY_FEE_FACTOR));
let old_bridge = XcmBridgeHubRouter::bridge(); let old_bridge = XcmBridgeHubRouter::bridge();
assert_eq!( assert_ok!(send_xcm::<XcmBridgeHubRouter>(
send_xcm::<XcmBridgeHubRouter>( MultiLocation::new(
MultiLocation::new( 2,
2, X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)) ),
), vec![ClearOrigin].into(),
vec![ClearOrigin].into(), )
) .map(drop));
.map(drop),
Ok(()),
);
assert!(TestToBridgeHubSender::is_message_sent()); assert!(TestToBridgeHubSender::is_message_sent());
assert!( assert!(
......
...@@ -19,7 +19,10 @@ ...@@ -19,7 +19,10 @@
use crate as pallet_xcm_bridge_hub_router; use crate as pallet_xcm_bridge_hub_router;
use bp_xcm_bridge_hub_router::XcmChannelStatusProvider; use bp_xcm_bridge_hub_router::XcmChannelStatusProvider;
use frame_support::{construct_runtime, derive_impl, parameter_types}; use frame_support::{
construct_runtime, derive_impl, parameter_types,
traits::{Contains, Equals},
};
use frame_system::EnsureRoot; use frame_system::EnsureRoot;
use sp_runtime::{traits::ConstU128, BuildStorage}; use sp_runtime::{traits::ConstU128, BuildStorage};
use xcm::prelude::*; use xcm::prelude::*;
...@@ -58,6 +61,7 @@ parameter_types! { ...@@ -58,6 +61,7 @@ parameter_types! {
Some((BridgeFeeAsset::get(), BASE_FEE).into()) Some((BridgeFeeAsset::get(), BASE_FEE).into())
) )
]; ];
pub UnknownXcmVersionLocation: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(9999)));
} }
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
...@@ -71,6 +75,8 @@ impl pallet_xcm_bridge_hub_router::Config<()> for TestRuntime { ...@@ -71,6 +75,8 @@ impl pallet_xcm_bridge_hub_router::Config<()> for TestRuntime {
type UniversalLocation = UniversalLocation; type UniversalLocation = UniversalLocation;
type BridgedNetworkId = BridgedNetworkId; type BridgedNetworkId = BridgedNetworkId;
type Bridges = NetworkExportTable<BridgeTable>; type Bridges = NetworkExportTable<BridgeTable>;
type DestinationVersion =
LatestOrNoneForLocationVersionChecker<Equals<UnknownXcmVersionLocation>>;
type BridgeHubOrigin = EnsureRoot<AccountId>; type BridgeHubOrigin = EnsureRoot<AccountId>;
type ToBridgeHubSender = TestToBridgeHubSender; type ToBridgeHubSender = TestToBridgeHubSender;
...@@ -80,6 +86,18 @@ impl pallet_xcm_bridge_hub_router::Config<()> for TestRuntime { ...@@ -80,6 +86,18 @@ impl pallet_xcm_bridge_hub_router::Config<()> for TestRuntime {
type FeeAsset = BridgeFeeAsset; type FeeAsset = BridgeFeeAsset;
} }
pub struct LatestOrNoneForLocationVersionChecker<Location>(sp_std::marker::PhantomData<Location>);
impl<Location: Contains<MultiLocation>> GetVersion
for LatestOrNoneForLocationVersionChecker<Location>
{
fn get_version_for(dest: &MultiLocation) -> Option<XcmVersion> {
if Location::contains(dest) {
return None
}
Some(XCM_VERSION)
}
}
pub struct TestToBridgeHubSender; pub struct TestToBridgeHubSender;
impl TestToBridgeHubSender { impl TestToBridgeHubSender {
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false } log = { version = "0.4.20", default-features = false }
......
...@@ -33,7 +33,8 @@ use xcm_executor::traits::ExportXcm; ...@@ -33,7 +33,8 @@ use xcm_executor::traits::ExportXcm;
/// An easy way to access `HaulBlobExporter`. /// An easy way to access `HaulBlobExporter`.
pub type PalletAsHaulBlobExporter<T, I> = HaulBlobExporter< pub type PalletAsHaulBlobExporter<T, I> = HaulBlobExporter<
DummyHaulBlob, DummyHaulBlob,
<T as Config<I>>::BridgedNetworkId, <T as Config<I>>::BridgedNetwork,
<T as Config<I>>::DestinationVersion,
<T as Config<I>>::MessageExportPrice, <T as Config<I>>::MessageExportPrice,
>; >;
/// An easy way to access associated messages pallet. /// An easy way to access associated messages pallet.
......
...@@ -37,6 +37,7 @@ pub mod pallet { ...@@ -37,6 +37,7 @@ pub mod pallet {
use super::*; use super::*;
use bridge_runtime_common::messages_xcm_extension::SenderAndLane; use bridge_runtime_common::messages_xcm_extension::SenderAndLane;
use frame_support::pallet_prelude::*; use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config] #[pallet::config]
#[pallet::disable_frame_system_supertrait_check] #[pallet::disable_frame_system_supertrait_check]
...@@ -48,15 +49,17 @@ pub mod pallet { ...@@ -48,15 +49,17 @@ pub mod pallet {
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1666 remove `ChainId` and // TODO: https://github.com/paritytech/parity-bridges-common/issues/1666 remove `ChainId` and
// replace it with the `NetworkId` - then we'll be able to use // replace it with the `NetworkId` - then we'll be able to use
// `T as pallet_bridge_messages::Config<T::BridgeMessagesPalletInstance>::BridgedChain::NetworkId` // `T as pallet_bridge_messages::Config<T::BridgeMessagesPalletInstance>::BridgedChain::NetworkId`
/// Bridged network id. /// Bridged network as relative location of bridged `GlobalConsensus`.
#[pallet::constant] #[pallet::constant]
type BridgedNetworkId: Get<NetworkId>; type BridgedNetwork: Get<MultiLocation>;
/// Associated messages pallet instance that bridges us with the /// Associated messages pallet instance that bridges us with the
/// `BridgedNetworkId` consensus. /// `BridgedNetworkId` consensus.
type BridgeMessagesPalletInstance: 'static; type BridgeMessagesPalletInstance: 'static;
/// Price of single message export to the bridged consensus (`Self::BridgedNetworkId`). /// Price of single message export to the bridged consensus (`Self::BridgedNetworkId`).
type MessageExportPrice: Get<MultiAssets>; type MessageExportPrice: Get<MultiAssets>;
/// Checks the XCM version for the destination.
type DestinationVersion: GetVersion;
/// Get point-to-point links with bridged consensus (`Self::BridgedNetworkId`). /// Get point-to-point links with bridged consensus (`Self::BridgedNetworkId`).
/// (this will be replaced with dynamic on-chain bridges - `Bridges V2`) /// (this will be replaced with dynamic on-chain bridges - `Bridges V2`)
...@@ -69,6 +72,17 @@ pub mod pallet { ...@@ -69,6 +72,17 @@ pub mod pallet {
#[pallet::pallet] #[pallet::pallet]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>); pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
fn integrity_test() {
assert!(
Self::bridged_network_id().is_some(),
"Configured `T::BridgedNetwork`: {:?} does not contain `GlobalConsensus` junction with `NetworkId`",
T::BridgedNetwork::get()
)
}
}
impl<T: Config<I>, I: 'static> Pallet<T, I> { impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Returns dedicated/configured lane identifier. /// Returns dedicated/configured lane identifier.
pub(crate) fn lane_for( pub(crate) fn lane_for(
...@@ -83,7 +97,7 @@ pub mod pallet { ...@@ -83,7 +97,7 @@ pub mod pallet {
.find_map(|(lane_source, (lane_dest_network, lane_dest))| { .find_map(|(lane_source, (lane_dest_network, lane_dest))| {
if lane_source.location == source && if lane_source.location == source &&
&lane_dest_network == dest.0 && &lane_dest_network == dest.0 &&
&T::BridgedNetworkId::get() == dest.0 && Self::bridged_network_id().as_ref() == Some(dest.0) &&
&lane_dest == dest.1 &lane_dest == dest.1
{ {
Some(lane_source) Some(lane_source)
...@@ -92,5 +106,13 @@ pub mod pallet { ...@@ -92,5 +106,13 @@ pub mod pallet {
} }
}) })
} }
/// Returns some `NetworkId` if contains `GlobalConsensus` junction.
fn bridged_network_id() -> Option<NetworkId> {
match T::BridgedNetwork::get().take_first_interior() {
Some(GlobalConsensus(network)) => Some(network),
_ => None,
}
}
} }
} }
...@@ -170,6 +170,10 @@ impl pallet_bridge_messages::WeightInfoExt for TestMessagesWeights { ...@@ -170,6 +170,10 @@ impl pallet_bridge_messages::WeightInfoExt for TestMessagesWeights {
parameter_types! { parameter_types! {
pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub const BridgedRelayNetwork: NetworkId = NetworkId::Polkadot; pub const BridgedRelayNetwork: NetworkId = NetworkId::Polkadot;
pub const BridgedRelayNetworkLocation: MultiLocation = MultiLocation {
parents: 1,
interior: X1(GlobalConsensus(BridgedRelayNetwork::get()))
};
pub const NonBridgedRelayNetwork: NetworkId = NetworkId::Rococo; pub const NonBridgedRelayNetwork: NetworkId = NetworkId::Rococo;
pub const BridgeReserve: Balance = 100_000; pub const BridgeReserve: Balance = 100_000;
pub UniversalLocation: InteriorMultiLocation = X2( pub UniversalLocation: InteriorMultiLocation = X2(
...@@ -181,10 +185,12 @@ parameter_types! { ...@@ -181,10 +185,12 @@ parameter_types! {
impl pallet_xcm_bridge_hub::Config for TestRuntime { impl pallet_xcm_bridge_hub::Config for TestRuntime {
type UniversalLocation = UniversalLocation; type UniversalLocation = UniversalLocation;
type BridgedNetworkId = BridgedRelayNetwork; type BridgedNetwork = BridgedRelayNetworkLocation;
type BridgeMessagesPalletInstance = (); type BridgeMessagesPalletInstance = ();
type MessageExportPrice = (); type MessageExportPrice = ();
type DestinationVersion = AlwaysLatest;
type Lanes = TestLanes; type Lanes = TestLanes;
type LanesSupport = TestXcmBlobHauler; type LanesSupport = TestXcmBlobHauler;
} }
......
...@@ -6,6 +6,9 @@ authors = ["Parity Technologies <admin@parity.io>"] ...@@ -6,6 +6,9 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021" edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "bit-vec"] } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "bit-vec"] }
scale-info = { version = "2.10.0", default-features = false, features = ["bit-vec", "derive"] } scale-info = { version = "2.10.0", default-features = false, features = ["bit-vec", "derive"] }
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
# Bridge Dependencies # Bridge Dependencies
......
...@@ -6,6 +6,9 @@ authors.workspace = true ...@@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true
[dependencies] [dependencies]
# Bridge Dependencies # Bridge Dependencies
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment