Skip to content

Commit

Permalink
Bridges - revert-back congestion mechanism (#6781)
Browse files Browse the repository at this point in the history
Closes: #5551

## Description

With [permissionless lanes
PR#4949](#4949), the
congestion mechanism based on sending
`Transact(report_bridge_status(is_congested))` from
`pallet-xcm-bridge-hub` to `pallet-xcm-bridge-hub-router` was replaced
with a congestion mechanism that relied on monitoring XCMP queues.
However, this approach could cause issues, such as suspending the entire
XCMP queue instead of isolating the affected bridge. This PR reverts
back to using `report_bridge_status` as before.

## TODO
- [x] benchmarks
- [x] prdoc

## Follow-up

#6231

---------

Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: command-bot <>
Co-authored-by: Adrian Catangiu <[email protected]>
(cherry picked from commit 8f4b99c)

# Conflicts:
#	Cargo.lock
#	cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs
#	cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
  • Loading branch information
bkontur committed Dec 10, 2024
1 parent 5e47c23 commit a22cb55
Show file tree
Hide file tree
Showing 26 changed files with 780 additions and 157 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.

6 changes: 6 additions & 0 deletions bridges/chains/chain-asset-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ scale-info = { features = ["derive"], workspace = true }

# Substrate Dependencies
frame-support = { workspace = true }
sp-core = { workspace = true }

# Bridge Dependencies
bp-xcm-bridge-hub-router = { workspace = true }

# Polkadot dependencies
xcm = { workspace = true }

[features]
default = ["std"]
std = [
"bp-xcm-bridge-hub-router/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,
fallback_max_weight: Some(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;
6 changes: 6 additions & 0 deletions bridges/chains/chain-asset-hub-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ scale-info = { features = ["derive"], workspace = true }

# Substrate Dependencies
frame-support = { workspace = true }
sp-core = { workspace = true }

# Bridge Dependencies
bp-xcm-bridge-hub-router = { workspace = true }

# Polkadot dependencies
xcm = { workspace = true }

[features]
default = ["std"]
std = [
"bp-xcm-bridge-hub-router/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,
fallback_max_weight: Some(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 a22cb55

Please sign in to comment.