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

Pre-support logical HRMP channels in pallet-xcm-bridge-hub-router #2501

Open
wants to merge 16 commits into
base: bridges-v2
Choose a base branch
from
Open
15 changes: 14 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ members = [
"primitives/runtime",
"primitives/test-utils",
"primitives/xcm-bridge-hub",
"primitives/xcm-bridge-hub-router",
"relays/bin-substrate",
"relays/client-bridge-hub-kusama",
"relays/client-bridge-hub-polkadot",
Expand Down
19 changes: 7 additions & 12 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm_builder::NetworkExportTable;

// to be able to use Millau runtime in `bridge-runtime-common` tests
pub use bridge_runtime_common;
Expand Down Expand Up @@ -530,27 +529,19 @@ impl pallet_utility::Config for Runtime {

// this config is totally incorrect - the pallet is not actually used at this runtime. We need
// it only to be able to run benchmarks and make required traits (and default weights for tests).

parameter_types! {
pub BridgeTable: Vec<(xcm::prelude::NetworkId, xcm::prelude::MultiLocation, Option<xcm::prelude::MultiAsset>)>
= vec![(
xcm_config::RialtoNetwork::get(),
xcm_config::TokenLocation::get(),
Some((xcm_config::TokenAssetId::get(), 1_000_000_000_u128).into()),
)];
}

impl pallet_xcm_bridge_hub_router::Config for Runtime {
type WeightInfo = ();

type MaxBridges = ConstU32<2>;

type UniversalLocation = xcm_config::UniversalLocation;
type SiblingBridgeHubLocation = xcm_config::TokenLocation;
type BridgedNetworkId = xcm_config::RialtoNetwork;
type Bridges = NetworkExportTable<BridgeTable>;

type ToBridgeHubSender = xcm_config::XcmRouter;
type LocalXcmChannelManager = xcm_config::EmulatedSiblingXcmpChannel;

type BaseFee = ConstU128<1_000_000>;
type ByteFee = ConstU128<1_000>;
type FeeAsset = xcm_config::TokenAssetId;
}
Expand Down Expand Up @@ -1220,6 +1211,10 @@ impl_runtime_apis! {
fn make_congested() {
xcm_config::EmulatedSiblingXcmpChannel::make_congested()
}

fn to_bridge_hub_ticket() -> () {
()
}
}

let mut batches = Vec::<BenchmarkBatch>::new();
Expand Down
17 changes: 16 additions & 1 deletion bin/millau/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,22 @@ parameter_types! {
}

/// The XCM router. We are not sending messages to sibling/parent/child chains here.
pub type XcmRouter = ();
pub struct XcmRouter;

impl SendXcm for XcmRouter {
type Ticket = ();

fn validate(
_dest: &mut Option<MultiLocation>,
_xcm: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> {
Ok(((), Default::default()))
}

fn deliver(_ticket: Self::Ticket) -> Result<XcmHash, SendError> {
Ok(Default::default())
}
}

/// The barriers one of which must be passed for an XCM message to be executed.
pub type Barrier = (
Expand Down
9 changes: 6 additions & 3 deletions modules/xcm-bridge-hub-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ scale-info = { version = "2.8.0", default-features = false, features = ["bit-vec

# Bridge dependencies

bp-xcm-bridge-hub = { path = "../../primitives/xcm-bridge-hub", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false }
bp-xcm-bridge-hub-router = { path = "../../primitives/xcm-bridge-hub-router", default-features = false }

# Substrate Dependencies

frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

Expand All @@ -29,20 +31,21 @@ xcm = { git = "https://github.com/paritytech/polkadot", branch = "master", defau
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" }

[features]
default = ["std"]
std = [
"bp-xcm-bridge-hub/std",
"bp-runtime/std",
"bp-xcm-bridge-hub-router/std",
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"xcm/std",
Expand Down
43 changes: 40 additions & 3 deletions modules/xcm-bridge-hub-router/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@

#![cfg(feature = "runtime-benchmarks")]

use crate::{DeliveryFeeFactor, MINIMAL_DELIVERY_FEE_FACTOR};
use crate::{
Bridges, CongestionFeeFactor, RelievingBridges, SuspendedMessages, ToBridgeHubTicket,
MINIMAL_DELIVERY_FEE_FACTOR,
};

use bp_xcm_bridge_hub_router::BridgeId;
use codec::Decode;
use frame_benchmarking::benchmarks_instance_pallet;
use frame_support::traits::Hooks;
use sp_runtime::traits::Zero;
use xcm::latest::prelude::*;

/// Pallet we're benchmarking here.
pub struct Pallet<T: Config<I>, I: 'static = ()>(crate::Pallet<T, I>);
Expand All @@ -31,19 +37,50 @@ pub struct Pallet<T: Config<I>, I: 'static = ()>(crate::Pallet<T, I>);
pub trait Config<I: 'static>: crate::Config<I> {
/// Fill up queue so it becomes congested.
fn make_congested();
/// Prepare a valid ticket for `Self::ToBridgeHubSender`.
fn to_bridge_hub_ticket() -> ToBridgeHubTicket<Self, I>;
}

benchmarks_instance_pallet! {
where_clause {
where
ToBridgeHubTicket<T, I>: Decode,
}

on_initialize_when_non_congested {
DeliveryFeeFactor::<T, I>::put(MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR);
CongestionFeeFactor::<T, I>::put(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);
CongestionFeeFactor::<T, I>::put(MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR);
T::make_congested();
}: {
crate::Pallet::<T, I>::on_initialize(Zero::zero())
}

to_bridge_hub_deliver_weight {
let ticket = T::to_bridge_hub_ticket();
}: {
T::ToBridgeHubSender::deliver(ticket).expect("Invalid ticket")
}

bridge_read_weight {
// since we are using `MaxEncodedLen` approach, we don't care about actual value of `Bridge`
}: {
Bridges::<T, I>::get(BridgeId::new(&Here.into(), &Here.into()))
}

relieving_bridges_read_weight {
// since we are using `MaxEncodedLen` approach, we don't care about actual value of `RelievingBridges`
}: {
RelievingBridges::<T, I>::get()
}

suspended_message_read_weight {
// since we are using `MaxEncodedLen` approach, we don't care about actual value of `SuspendedMessage`
}: {
SuspendedMessages::<T, I>::get(BridgeId::new(&Here.into(), &Here.into()), 1)
}
}
Loading