Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Backport polkadot-sdk updates + bump polkadot-sdk refs #2801

Merged
merged 2 commits into from
Jan 22, 2024
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
1,193 changes: 196 additions & 997 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions bin/runtime-common/src/messages_benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use pallet_bridge_messages::{
};
use sp_runtime::traits::{Header, Zero};
use sp_std::prelude::*;
use xcm::v3::prelude::*;
use xcm::latest::prelude::*;

/// Prepare inbound bridge message according to given message proof parameters.
fn prepare_inbound_message(
Expand Down Expand Up @@ -273,19 +273,19 @@ where
/// Returns callback which generates `BridgeMessage` from Polkadot XCM builder based on
/// `expected_message_size` for benchmark.
pub fn generate_xcm_builder_bridge_message_sample(
destination: InteriorMultiLocation,
destination: InteriorLocation,
) -> impl Fn(usize) -> MessagePayload {
move |expected_message_size| -> MessagePayload {
// For XCM bridge hubs, it is the message that
// will be pushed further to some XCM queue (XCMP/UMP)
let location = xcm::VersionedInteriorMultiLocation::V3(destination);
let location = xcm::VersionedInteriorLocation::V4(destination.clone());
let location_encoded_size = location.encoded_size();

// we don't need to be super-precise with `expected_size` here
let xcm_size = expected_message_size.saturating_sub(location_encoded_size);
let xcm_data_size = xcm_size.saturating_sub(
// minus empty instruction size
xcm::v3::Instruction::<()>::ExpectPallet {
Instruction::<()>::ExpectPallet {
index: 0,
name: vec![],
module_name: vec![],
Expand All @@ -301,8 +301,8 @@ pub fn generate_xcm_builder_bridge_message_sample(
expected_message_size, location_encoded_size, xcm_size, xcm_data_size,
);

let xcm = xcm::VersionedXcm::<()>::V3(
vec![xcm::v3::Instruction::<()>::ExpectPallet {
let xcm = xcm::VersionedXcm::<()>::V4(
vec![Instruction::<()>::ExpectPallet {
index: 0,
name: vec![42; xcm_data_size],
module_name: vec![],
Expand Down
2 changes: 1 addition & 1 deletion modules/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ pub(crate) mod tests {
);

// then if someone is pretending to provide updated head#10 of parachain#1 at relay
// block#30, and actualy provides it
// block#30, and actually provides it
//
// => we'll update value
proceed(30, state_root_10_at_30);
Expand Down
30 changes: 12 additions & 18 deletions modules/xcm-bridge-hub-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ pub mod pallet {
type WeightInfo: WeightInfo;

/// Universal location of this runtime.
type UniversalLocation: Get<InteriorMultiLocation>;
type UniversalLocation: Get<InteriorLocation>;
/// Relative location of the sibling bridge hub.
type SiblingBridgeHubLocation: Get<MultiLocation>;
type SiblingBridgeHubLocation: Get<Location>;
/// The bridged network that this config is for if specified.
/// Also used for filtering `Bridges` by `BridgedNetworkId`.
/// If not specified, allows all networks pass through.
Expand Down Expand Up @@ -240,9 +240,9 @@ type ViaBridgeHubExporter<T, I> = SovereignPaidRemoteExporter<
impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
fn exporter_for(
network: &NetworkId,
remote_location: &InteriorMultiLocation,
remote_location: &InteriorLocation,
message: &Xcm<()>,
) -> Option<(MultiLocation, Option<MultiAsset>)> {
) -> Option<(Location, Option<Asset>)> {
// ensure that the message is sent to the expected bridged network (if specified).
if *network != T::BridgedNetworkId::get() {
log::trace!(
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
// take `base_fee` from `T::Brides`, but it has to be the same `T::FeeAsset`
let base_fee = match maybe_payment {
Some(payment) => match payment {
MultiAsset { fun: Fungible(amount), id } if id.eq(&T::FeeAsset::get()) => amount,
Asset { fun: Fungible(amount), id } if id.eq(&T::FeeAsset::get()) => amount,
invalid_asset => {
log::error!(
target: LOG_TARGET,
Expand Down Expand Up @@ -333,7 +333,7 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
type Ticket = (u32, <T::ToBridgeHubSender as SendXcm>::Ticket);

fn validate(
dest: &mut Option<MultiLocation>,
dest: &mut Option<Location>,
xcm: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> {
// `dest` and `xcm` are required here
Expand Down Expand Up @@ -451,7 +451,7 @@ mod tests {
run_test(|| {
assert_eq!(
send_xcm::<XcmBridgeHubRouter>(
MultiLocation::new(2, X2(GlobalConsensus(Rococo), Parachain(1000))),
Location::new(2, [GlobalConsensus(Rococo), Parachain(1000)]),
vec![].into(),
),
Err(SendError::NotApplicable),
Expand All @@ -464,7 +464,7 @@ mod tests {
run_test(|| {
assert_eq!(
send_xcm::<XcmBridgeHubRouter>(
MultiLocation::new(2, X2(GlobalConsensus(Rococo), Parachain(1000))),
Location::new(2, [GlobalConsensus(Rococo), Parachain(1000)]),
vec![ClearOrigin; HARD_MESSAGE_SIZE_LIMIT as usize].into(),
),
Err(SendError::ExceedsMaxMessageSize),
Expand All @@ -488,14 +488,14 @@ mod tests {
#[test]
fn returns_proper_delivery_price() {
run_test(|| {
let dest = MultiLocation::new(2, X1(GlobalConsensus(BridgedNetworkId::get())));
let dest = Location::new(2, [GlobalConsensus(BridgedNetworkId::get())]);
let xcm: Xcm<()> = vec![ClearOrigin].into();
let msg_size = xcm.encoded_size();

// initially the base fee is used: `BASE_FEE + BYTE_FEE * msg_size + HRMP_FEE`
let expected_fee = BASE_FEE + BYTE_FEE * (msg_size as u128) + HRMP_FEE;
assert_eq!(
XcmBridgeHubRouter::validate(&mut Some(dest), &mut Some(xcm.clone()))
XcmBridgeHubRouter::validate(&mut Some(dest.clone()), &mut Some(xcm.clone()))
.unwrap()
.1
.get(0),
Expand Down Expand Up @@ -524,10 +524,7 @@ mod tests {
let old_delivery_fee_factor = XcmBridgeHubRouter::delivery_fee_factor();
assert_eq!(
send_xcm::<XcmBridgeHubRouter>(
MultiLocation::new(
2,
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
),
Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)]),
vec![ClearOrigin].into(),
)
.map(drop),
Expand All @@ -549,10 +546,7 @@ mod tests {
let old_delivery_fee_factor = XcmBridgeHubRouter::delivery_fee_factor();
assert_eq!(
send_xcm::<XcmBridgeHubRouter>(
MultiLocation::new(
2,
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
),
Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)]),
vec![ClearOrigin].into(),
)
.map(drop),
Expand Down
24 changes: 12 additions & 12 deletions modules/xcm-bridge-hub-router/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ construct_runtime! {
parameter_types! {
pub ThisNetworkId: NetworkId = Polkadot;
pub BridgedNetworkId: NetworkId = Kusama;
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(ThisNetworkId::get()), Parachain(1000));
pub SiblingBridgeHubLocation: MultiLocation = ParentThen(X1(Parachain(1002))).into();
pub BridgeFeeAsset: AssetId = MultiLocation::parent().into();
pub UniversalLocation: InteriorLocation = [GlobalConsensus(ThisNetworkId::get()), Parachain(1000)].into();
pub SiblingBridgeHubLocation: Location = ParentThen([Parachain(1002)].into()).into();
pub BridgeFeeAsset: AssetId = Location::parent().into();
pub BridgeTable: Vec<NetworkExportTableItem>
= vec![
NetworkExportTableItem::new(
Expand All @@ -59,7 +59,7 @@ parameter_types! {
Some((BridgeFeeAsset::get(), BASE_FEE).into())
)
];
pub UnknownXcmVersionLocation: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(9999)));
pub UnknownXcmVersionLocation: Location = Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(9999)]);
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
Expand Down Expand Up @@ -93,11 +93,11 @@ impl pallet_xcm_bridge_hub_router::benchmarking::Config<()> for TestRuntime {
}

pub struct LatestOrNoneForLocationVersionChecker<Location>(sp_std::marker::PhantomData<Location>);
impl<Location: Contains<MultiLocation>> GetVersion
for LatestOrNoneForLocationVersionChecker<Location>
impl<LocationValue: Contains<Location>> GetVersion
for LatestOrNoneForLocationVersionChecker<LocationValue>
{
fn get_version_for(dest: &MultiLocation) -> Option<XcmVersion> {
if Location::contains(dest) {
fn get_version_for(dest: &Location) -> Option<XcmVersion> {
if LocationValue::contains(dest) {
return None
}
Some(XCM_VERSION)
Expand All @@ -116,7 +116,7 @@ impl SendXcm for TestToBridgeHubSender {
type Ticket = ();

fn validate(
_destination: &mut Option<MultiLocation>,
_destination: &mut Option<Location>,
_message: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> {
Ok(((), (BridgeFeeAsset::get(), HRMP_FEE).into()))
Expand All @@ -139,15 +139,15 @@ impl TestLocalXcmChannelManager {
impl LocalXcmChannelManager for TestLocalXcmChannelManager {
type Error = ();

fn is_congested(_with: &MultiLocation) -> bool {
fn is_congested(_with: &Location) -> bool {
frame_support::storage::unhashed::get_or_default(b"TestLocalXcmChannelManager.Congested")
}

fn suspend_bridge(_with: &MultiLocation, _bridge: BridgeId) -> Result<(), Self::Error> {
fn suspend_bridge(_with: &Location, _bridge: BridgeId) -> Result<(), Self::Error> {
Ok(())
}

fn resume_bridge(_with: &MultiLocation, _bridge: BridgeId) -> Result<(), Self::Error> {
fn resume_bridge(_with: &Location, _bridge: BridgeId) -> Result<(), Self::Error> {
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/xcm-bridge-hub/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
let bridge_id = BridgeId::from_lane_id(lane);
Pallet::<T, I>::bridge(bridge_id)
.and_then(|bridge| bridge.bridge_origin_relative_location.try_as().cloned().ok())
.map(|recipient: MultiLocation| !T::LocalXcmChannelManager::is_congested(&recipient))
.map(|recipient: Location| !T::LocalXcmChannelManager::is_congested(&recipient))
.unwrap_or(false)
}

Expand Down Expand Up @@ -134,7 +134,7 @@ mod tests {
Bridges::<TestRuntime, ()>::insert(
bridge_id(),
Bridge {
bridge_origin_relative_location: Box::new(MultiLocation::new(0, Here).into()),
bridge_origin_relative_location: Box::new(Location::new(0, Here).into()),
state: BridgeState::Opened,
bridge_owner_account: [0u8; 32].into(),
reserve: 0,
Expand Down
16 changes: 8 additions & 8 deletions modules/xcm-bridge-hub/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ where
fn validate(
network: NetworkId,
channel: u32,
universal_source: &mut Option<InteriorMultiLocation>,
destination: &mut Option<InteriorMultiLocation>,
universal_source: &mut Option<InteriorLocation>,
destination: &mut Option<InteriorLocation>,
message: &mut Option<Xcm<()>>,
) -> Result<(Self::Ticket, MultiAssets), SendError> {
) -> Result<(Self::Ticket, Assets), SendError> {
// `HaulBlobExporter` may consume the `universal_source` and `destination` arguments, so
// let's save them before
let bridge_origin_universal_location =
Expand Down Expand Up @@ -301,12 +301,12 @@ mod tests {
use bp_xcm_bridge_hub::{Bridge, BridgeState};
use xcm_executor::traits::export_xcm;

fn universal_source() -> InteriorMultiLocation {
X2(GlobalConsensus(RelayNetwork::get()), Parachain(SIBLING_ASSET_HUB_ID))
fn universal_source() -> InteriorLocation {
[GlobalConsensus(RelayNetwork::get()), Parachain(SIBLING_ASSET_HUB_ID)].into()
}

fn universal_destination() -> InteriorMultiLocation {
X2(GlobalConsensus(BridgedRelayNetwork::get()), Parachain(BRIDGED_ASSET_HUB_ID))
fn universal_destination() -> InteriorLocation {
[GlobalConsensus(BridgedRelayNetwork::get()), Parachain(BRIDGED_ASSET_HUB_ID)].into()
}

fn open_lane_and_send_regular_message() -> BridgeId {
Expand All @@ -329,7 +329,7 @@ mod tests {
locations.bridge_id,
Bridge {
bridge_origin_relative_location: Box::new(
MultiLocation::new(1, Parachain(SIBLING_ASSET_HUB_ID)).into(),
Location::new(1, Parachain(SIBLING_ASSET_HUB_ID)).into(),
),
state: BridgeState::Opened,
bridge_owner_account: [0u8; 32].into(),
Expand Down
Loading