Skip to content

Commit

Permalink
Small clean-up for EnsureForParachain stuff (#6714)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
bkontur and actions-user authored Nov 30, 2024
1 parent 080ff18 commit ef2a7c0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 0 additions & 4 deletions cumulus/pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ sp-version = { workspace = true }
# Polkadot
polkadot-parachain-primitives = { features = ["wasm-api"], workspace = true }
polkadot-runtime-parachains = { workspace = true }
polkadot-runtime-common = { optional = true, workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }

Expand Down Expand Up @@ -82,7 +81,6 @@ std = [
"log/std",
"pallet-message-queue/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"polkadot-runtime-parachains/std",
"scale-info/std",
"sp-core/std",
Expand All @@ -107,7 +105,6 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
"polkadot-runtime-parachains/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand All @@ -117,7 +114,6 @@ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-message-queue/try-runtime",
"polkadot-runtime-common?/try-runtime",
"polkadot-runtime-parachains/try-runtime",
"sp-runtime/try-runtime",
]
Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ impl<T: Config> InspectMessageQueues for Pallet<T> {
}

#[cfg(feature = "runtime-benchmarks")]
impl<T: Config> polkadot_runtime_common::xcm_sender::EnsureForParachain for Pallet<T> {
impl<T: Config> polkadot_runtime_parachains::EnsureForParachain for Pallet<T> {
fn ensure(para_id: ParaId) {
if let ChannelStatus::Closed = Self::get_channel_status(para_id) {
Self::open_outbound_hrmp_channel_for_benchmarks_or_tests(para_id)
Expand Down
23 changes: 1 addition & 22 deletions polkadot/runtime/common/src/xcm_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl<
ExistentialDeposit: Get<Option<Asset>>,
PriceForDelivery: PriceForMessageDelivery<Id = ParaId>,
Parachain: Get<ParaId>,
ToParachainHelper: EnsureForParachain,
ToParachainHelper: polkadot_runtime_parachains::EnsureForParachain,
> xcm_builder::EnsureDelivery
for ToParachainDeliveryHelper<
XcmConfig,
Expand Down Expand Up @@ -248,27 +248,6 @@ impl<
}
}

/// Ensure more initialization for `ParaId`. (e.g. open HRMP channels, ...)
#[cfg(feature = "runtime-benchmarks")]
pub trait EnsureForParachain {
fn ensure(para_id: ParaId);
}
#[cfg(feature = "runtime-benchmarks")]
impl EnsureForParachain for () {
fn ensure(_: ParaId) {
// doing nothing
}
}

#[cfg(feature = "runtime-benchmarks")]
impl<T: polkadot_runtime_parachains::dmp::Config> EnsureForParachain
for polkadot_runtime_parachains::dmp::Pallet<T>
{
fn ensure(para: ParaId) {
polkadot_runtime_parachains::paras::Heads::<T>::insert(para, alloc::vec![]);
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 7 additions & 0 deletions polkadot/runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,10 @@ impl<T: Config> FeeTracker for Pallet<T> {
})
}
}

#[cfg(feature = "runtime-benchmarks")]
impl<T: Config> crate::EnsureForParachain for Pallet<T> {
fn ensure(para: ParaId) {
paras::Heads::<T>::insert(para, alloc::vec![]);
}
}
16 changes: 16 additions & 0 deletions polkadot/runtime/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,19 @@ pub fn schedule_code_upgrade<T: paras::Config>(
pub fn set_current_head<T: paras::Config>(id: ParaId, new_head: HeadData) {
paras::Pallet::<T>::set_current_head(id, new_head)
}

/// Ensure more initialization for `ParaId` when benchmarking. (e.g. open HRMP channels, ...)
#[cfg(feature = "runtime-benchmarks")]
pub trait EnsureForParachain {
fn ensure(para_id: ParaId);
}

#[cfg(feature = "runtime-benchmarks")]
#[impl_trait_for_tuples::impl_for_tuples(30)]
impl EnsureForParachain for Tuple {
fn ensure(para: ParaId) {
for_tuples!( #(
Tuple::ensure(para);
)* );
}
}
2 changes: 1 addition & 1 deletion polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,7 @@ sp_api::impl_runtime_apis! {
ExistentialDepositAsset,
xcm_config::PriceForChildParachainDelivery,
AssetHubParaId,
(),
Dmp,
>;
fn valid_destination() -> Result<Location, BenchmarkError> {
Ok(AssetHub::get())
Expand Down

0 comments on commit ef2a7c0

Please sign in to comment.