Skip to content

Commit

Permalink
Merge branch 'stable2409' of https://github.com/paritytech/polkadot-sdk
Browse files Browse the repository at this point in the history
… into backport-6459-to-stable2409
  • Loading branch information
EgorPopelyaev committed Dec 11, 2024
2 parents 95cacdb + 940966e commit 7d3b9ea
Show file tree
Hide file tree
Showing 36 changed files with 1,443 additions and 213 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions bridges/chains/chain-asset-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ workspace = true
codec = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-support.workspace = true
sp-core.workspace = true
bp-xcm-bridge-hub-router.workspace = true
xcm.workspace = true

[features]
default = ["std"]
Expand All @@ -26,4 +28,6 @@ std = [
"codec/std",
"frame-support/std",
"scale-info/std",
"sp-core/std",
"xcm/std",
]
25 changes: 25 additions & 0 deletions bridges/chains/chain-asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use codec::{Decode, Encode};
use scale_info::TypeInfo;

pub use bp_xcm_bridge_hub_router::XcmBridgeHubRouterCall;
use xcm::latest::prelude::*;

/// `AssetHubRococo` Runtime `Call` enum.
///
Expand All @@ -44,5 +47,27 @@ frame_support::parameter_types! {
pub const XcmBridgeHubRouterTransactCallMaxWeight: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(200_000_000, 6144);
}

/// Builds an (un)congestion XCM program with the `report_bridge_status` call for
/// `ToWestendXcmRouter`.
pub fn build_congestion_message<RuntimeCall>(
bridge_id: sp_core::H256,
is_congested: bool,
) -> alloc::vec::Vec<Instruction<RuntimeCall>> {
alloc::vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind: OriginKind::Xcm,
require_weight_at_most: XcmBridgeHubRouterTransactCallMaxWeight::get(),
call: Call::ToWestendXcmRouter(XcmBridgeHubRouterCall::report_bridge_status {
bridge_id,
is_congested,
})
.encode()
.into(),
},
ExpectTransactStatus(MaybeErrorCode::Success),
]
}

/// Identifier of AssetHubRococo in the Rococo relay chain.
pub const ASSET_HUB_ROCOCO_PARACHAIN_ID: u32 = 1000;
4 changes: 4 additions & 0 deletions bridges/chains/chain-asset-hub-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ workspace = true
codec = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-support.workspace = true
sp-core.workspace = true
bp-xcm-bridge-hub-router.workspace = true
xcm.workspace = true

[features]
default = ["std"]
Expand All @@ -26,4 +28,6 @@ std = [
"codec/std",
"frame-support/std",
"scale-info/std",
"sp-core/std",
"xcm/std",
]
25 changes: 25 additions & 0 deletions bridges/chains/chain-asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use codec::{Decode, Encode};
use scale_info::TypeInfo;

pub use bp_xcm_bridge_hub_router::XcmBridgeHubRouterCall;
use xcm::latest::prelude::*;

/// `AssetHubWestend` Runtime `Call` enum.
///
Expand All @@ -44,5 +47,27 @@ frame_support::parameter_types! {
pub const XcmBridgeHubRouterTransactCallMaxWeight: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(200_000_000, 6144);
}

/// Builds an (un)congestion XCM program with the `report_bridge_status` call for
/// `ToRococoXcmRouter`.
pub fn build_congestion_message<RuntimeCall>(
bridge_id: sp_core::H256,
is_congested: bool,
) -> alloc::vec::Vec<Instruction<RuntimeCall>> {
alloc::vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind: OriginKind::Xcm,
require_weight_at_most: XcmBridgeHubRouterTransactCallMaxWeight::get(),
call: Call::ToRococoXcmRouter(XcmBridgeHubRouterCall::report_bridge_status {
bridge_id,
is_congested,
})
.encode()
.into(),
},
ExpectTransactStatus(MaybeErrorCode::Success),
]
}

/// Identifier of AssetHubWestend in the Westend relay chain.
pub const ASSET_HUB_WESTEND_PARACHAIN_ID: u32 = 1000;
27 changes: 23 additions & 4 deletions bridges/modules/xcm-bridge-hub-router/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#![cfg(feature = "runtime-benchmarks")]

use crate::{DeliveryFeeFactor, MINIMAL_DELIVERY_FEE_FACTOR};
use crate::{Bridge, BridgeState, Call, MINIMAL_DELIVERY_FEE_FACTOR};
use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError};
use frame_support::traits::{Get, Hooks};
use frame_support::traits::{EnsureOrigin, Get, Hooks, UnfilteredDispatchable};
use sp_runtime::traits::Zero;
use xcm::prelude::*;

Expand All @@ -45,16 +45,35 @@ pub trait Config<I: 'static>: crate::Config<I> {

benchmarks_instance_pallet! {
on_initialize_when_non_congested {
DeliveryFeeFactor::<T, I>::put(MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR);
Bridge::<T, I>::put(BridgeState {
is_congested: false,
delivery_fee_factor: MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR,
});
}: {
crate::Pallet::<T, I>::on_initialize(Zero::zero())
}

on_initialize_when_congested {
DeliveryFeeFactor::<T, I>::put(MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR);
Bridge::<T, I>::put(BridgeState {
is_congested: false,
delivery_fee_factor: MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR,
});
let _ = T::ensure_bridged_target_destination()?;
T::make_congested();
}: {
crate::Pallet::<T, I>::on_initialize(Zero::zero())
}

report_bridge_status {
Bridge::<T, I>::put(BridgeState::default());

let origin: T::RuntimeOrigin = T::BridgeHubOrigin::try_successful_origin().expect("expected valid BridgeHubOrigin");
let bridge_id = Default::default();
let is_congested = true;

let call = Call::<T, I>::report_bridge_status { bridge_id, is_congested };
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert!(Bridge::<T, I>::get().is_congested);
}
}
Loading

0 comments on commit 7d3b9ea

Please sign in to comment.