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

parachains_coretime: Expose MaxXCMTransactWeight #4189

Merged
merged 6 commits into from
Apr 23, 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
8 changes: 4 additions & 4 deletions polkadot/runtime/parachains/src/coretime/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ mod v_coretime {
mask: CoreMask::complete(),
assignment: CoreAssignment::Task(p.into()),
}]);
mk_coretime_call(crate::coretime::CoretimeCalls::Reserve(schedule))
mk_coretime_call::<T>(crate::coretime::CoretimeCalls::Reserve(schedule))
});

let leases = lease_holding.into_iter().filter_map(|p| {
Expand All @@ -243,14 +243,14 @@ mod v_coretime {
let round_up = if valid_until % TIME_SLICE_PERIOD > 0 { 1 } else { 0 };
let time_slice = valid_until / TIME_SLICE_PERIOD + TIME_SLICE_PERIOD * round_up;
log::trace!(target: "coretime-migration", "Sending of lease holding para {:?}, valid_until: {:?}, time_slice: {:?}", p, valid_until, time_slice);
Some(mk_coretime_call(crate::coretime::CoretimeCalls::SetLease(p.into(), time_slice)))
Some(mk_coretime_call::<T>(crate::coretime::CoretimeCalls::SetLease(p.into(), time_slice)))
});

let core_count: u16 = configuration::ActiveConfig::<T>::get()
.scheduler_params
.num_cores
.saturated_into();
let set_core_count = iter::once(mk_coretime_call(
let set_core_count = iter::once(mk_coretime_call::<T>(
crate::coretime::CoretimeCalls::NotifyCoreCount(core_count),
));

Expand All @@ -261,7 +261,7 @@ mod v_coretime {
}]);
// Reserved cores will come before lease cores, so cores will change their assignments
// when coretime chain sends us their assign_core calls -> Good test.
mk_coretime_call(crate::coretime::CoretimeCalls::Reserve(schedule))
mk_coretime_call::<T>(crate::coretime::CoretimeCalls::Reserve(schedule))
});

let message_content = iter::once(Instruction::UnpaidExecution {
Expand Down
15 changes: 9 additions & 6 deletions polkadot/runtime/parachains/src/coretime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ pub mod pallet {
/// Something that provides the weight of this pallet.
type WeightInfo: WeightInfo;
type SendXcm: SendXcm;

/// Maximum weight for any XCM transact call that should be executed on the coretime chain.
///
/// Basically should be `max_weight(set_leases, reserve, notify_core_count)`.
type MaxXcmTransactWeight: Get<Weight>;
}

#[pallet::event]
Expand Down Expand Up @@ -225,7 +230,7 @@ impl<T: Config> Pallet<T> {
weight_limit: WeightLimit::Unlimited,
check_origin: None,
},
mk_coretime_call(crate::coretime::CoretimeCalls::NotifyCoreCount(core_count)),
mk_coretime_call::<T>(crate::coretime::CoretimeCalls::NotifyCoreCount(core_count)),
]);
if let Err(err) = send_xcm::<T::SendXcm>(
Location::new(0, [Junction::Parachain(T::BrokerId::get())]),
Expand All @@ -244,7 +249,7 @@ impl<T: Config> Pallet<T> {
weight_limit: WeightLimit::Unlimited,
check_origin: None,
},
mk_coretime_call(crate::coretime::CoretimeCalls::SwapLeases(one, other)),
mk_coretime_call::<T>(crate::coretime::CoretimeCalls::SwapLeases(one, other)),
]);
if let Err(err) = send_xcm::<T::SendXcm>(
Location::new(0, [Junction::Parachain(T::BrokerId::get())]),
Expand All @@ -261,12 +266,10 @@ impl<T: Config> OnNewSession<BlockNumberFor<T>> for Pallet<T> {
}
}

fn mk_coretime_call(call: crate::coretime::CoretimeCalls) -> Instruction<()> {
fn mk_coretime_call<T: Config>(call: crate::coretime::CoretimeCalls) -> Instruction<()> {
Instruction::Transact {
origin_kind: OriginKind::Superuser,
// Largest call is set_lease with 1526 byte:
// Longest call is reserve() with 31_000_000
require_weight_at_most: Weight::from_parts(170_000_000, 20_000),
require_weight_at_most: T::MaxXcmTransactWeight::get(),
call: BrokerRuntimePallets::Broker(call).encode().into(),
}
}
2 changes: 2 additions & 0 deletions polkadot/runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ impl assigner_coretime::Config for Test {}

parameter_types! {
pub const BrokerId: u32 = 10u32;
pub MaxXcmTransactWeight: Weight = Weight::from_parts(10_000_000, 10_000);
}

impl coretime::Config for Test {
Expand All @@ -396,6 +397,7 @@ impl coretime::Config for Test {
type BrokerId = BrokerId;
type WeightInfo = crate::coretime::TestWeightInfo;
type SendXcm = DummyXcmSender;
type MaxXcmTransactWeight = MaxXcmTransactWeight;
}

pub struct DummyXcmSender;
Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ impl parachains_scheduler::Config for Runtime {

parameter_types! {
pub const BrokerId: u32 = BROKER_ID;
pub MaxXcmTransactWeight: Weight = Weight::from_parts(200_000_000, 20_000);
}

impl coretime::Config for Runtime {
Expand All @@ -1066,6 +1067,7 @@ impl coretime::Config for Runtime {
type BrokerId = BrokerId;
type WeightInfo = weights::runtime_parachains_coretime::WeightInfo<Runtime>;
type SendXcm = crate::xcm_config::XcmRouter;
type MaxXcmTransactWeight = MaxXcmTransactWeight;
}

parameter_types! {
Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@ impl parachains_scheduler::Config for Runtime {

parameter_types! {
pub const BrokerId: u32 = BROKER_ID;
pub MaxXcmTransactWeight: Weight = Weight::from_parts(200_000_000, 20_000);
}

impl coretime::Config for Runtime {
Expand All @@ -1197,6 +1198,7 @@ impl coretime::Config for Runtime {
type BrokerId = BrokerId;
type WeightInfo = weights::runtime_parachains_coretime::WeightInfo<Runtime>;
type SendXcm = crate::xcm_config::XcmRouter;
type MaxXcmTransactWeight = MaxXcmTransactWeight;
}

parameter_types! {
Expand Down
16 changes: 16 additions & 0 deletions prdoc/pr_4189.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
title: "polkadot_runtime_parachains::coretime: Expose `MaxXcmTransactWeight`"

doc:
- audience: Runtime Dev
description: |
Expose `MaxXcmTransactWeight` via the `Config` trait. This exposes the
possibility for runtime implementors to set the maximum weight required
for the calls on the coretime chain. Basically it needs to be set to
`max_weight(set_leases, reserve, notify_core_count)` where `set_leases`
etc are the calls on the coretime chain. This ensures that these XCM
transact calls send by the relay chain coretime pallet to the coretime
chain can be dispatched.

crates:
- name: polkadot-runtime-parachains
bump: major
Loading