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

Add Coretime to Westend #3319

Merged
merged 10 commits into from
Feb 19, 2024
66 changes: 60 additions & 6 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ use runtime_common::{
impls::{
LocatableAssetConverter, ToAuthor, VersionedLocatableAsset, VersionedLocationConverter,
},
paras_registrar, paras_sudo_wrapper, prod_or_fast, slots, BalanceToU256, BlockHashCount,
BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate, U256ToBalance,
paras_registrar, paras_sudo_wrapper, prod_or_fast, slots,
traits::Leaser,
BalanceToU256, BlockHashCount, BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate,
U256ToBalance,
};
use runtime_parachains::{
assigner_coretime as parachains_assigner_coretime,
assigner_on_demand as parachains_assigner_on_demand,
assigner_parachains as parachains_assigner_parachains,
configuration as parachains_configuration, disputes as parachains_disputes,
configuration as parachains_configuration, coretime, disputes as parachains_disputes,
disputes::slashing as parachains_slashing,
dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion,
inclusion::{AggregateMessageOrigin, UmpQueueId},
Expand Down Expand Up @@ -1143,7 +1147,7 @@ impl parachains_paras::Config for Runtime {
type QueueFootprinter = ParaInclusion;
type NextSessionRotation = Babe;
type OnNewHead = ();
type AssignCoretime = ();
type AssignCoretime = CoretimeAssignmentProvider;
}

parameter_types! {
Expand Down Expand Up @@ -1212,20 +1216,42 @@ impl parachains_paras_inherent::Config for Runtime {
impl parachains_scheduler::Config for Runtime {
// If you change this, make sure the `Assignment` type of the new provider is binary compatible,
// otherwise provide a migration.
type AssignmentProvider = ParachainsAssignmentProvider;
type AssignmentProvider = CoretimeAssignmentProvider;
}

parameter_types! {
pub const BrokerId: u32 = BROKER_ID;
}

impl coretime::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type BrokerId = BrokerId;
type WeightInfo = weights::runtime_parachains_coretime::WeightInfo<Runtime>;
type SendXcm = crate::xcm_config::XcmRouter;
}

parameter_types! {
pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1);
}

impl parachains_assigner_on_demand::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type TrafficDefaultValue = OnDemandTrafficDefaultValue;
type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo<Runtime>;
}

impl parachains_assigner_parachains::Config for Runtime {}

impl parachains_assigner_coretime::Config for Runtime {}

impl parachains_initializer::Config for Runtime {
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
type ForceOrigin = EnsureRoot<AccountId>;
type WeightInfo = weights::runtime_parachains_initializer::WeightInfo<Runtime>;
type CoretimeOnNewSession = ();
type CoretimeOnNewSession = Coretime;
}

impl paras_sudo_wrapper::Config for Runtime {}
Expand Down Expand Up @@ -1480,6 +1506,8 @@ construct_runtime! {
ParasDisputes: parachains_disputes = 53,
ParasSlashing: parachains_slashing = 54,
ParachainsAssignmentProvider: parachains_assigner_parachains = 55,
OnDemandAssignmentProvider: parachains_assigner_on_demand = 56,
CoretimeAssignmentProvider: parachains_assigner_coretime = 57,

// Parachain Onboarding Pallets. Start indices at 60 to leave room.
Registrar: paras_registrar = 60,
Expand All @@ -1488,6 +1516,7 @@ construct_runtime! {
Auctions: auctions = 63,
Crowdloan: crowdloan = 64,
AssignedSlots: assigned_slots = 65,
Coretime: coretime = 66,

// Pallet for sending XCM.
XcmPallet: pallet_xcm = 99,
Expand Down Expand Up @@ -1555,6 +1584,24 @@ pub mod migrations {
#[cfg(feature = "try-runtime")]
use sp_core::crypto::ByteArray;

pub struct GetLegacyLeaseImpl;
impl coretime::migration::GetLegacyLease<BlockNumber> for GetLegacyLeaseImpl {
fn get_parachain_lease_in_blocks(para: ParaId) -> Option<BlockNumber> {
let now = frame_system::Pallet::<Runtime>::block_number();
let lease = slots::Pallet::<Runtime>::lease(para);
if lease.is_empty() {
return None
}
// Lease not yet started, ignore:
if lease.iter().any(Option::is_none) {
return None
}
let (index, _) =
<slots::Pallet<Runtime> as Leaser<BlockNumber>>::lease_period_index(now)?;
Some(index.saturating_add(lease.len() as u32).saturating_mul(LeasePeriod::get()))
}
}

parameter_types! {
pub const ImOnlinePalletName: &'static str = "ImOnline";
}
Expand Down Expand Up @@ -1658,6 +1705,12 @@ pub mod migrations {
parachains_configuration::migration::v11::MigrateToV11<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
// Migrate from legacy lease to coretime. Needs to run after configuration v11
coretime::migration::MigrateToCoretime<
Runtime,
crate::xcm_config::XcmRouter,
GetLegacyLeaseImpl,
>,
);
}

Expand Down Expand Up @@ -1696,6 +1749,7 @@ mod benches {
[runtime_parachains::initializer, Initializer]
antonva marked this conversation as resolved.
Show resolved Hide resolved
[runtime_parachains::paras, Paras]
[runtime_parachains::paras_inherent, ParaInherent]
[runtime_parachains::assigner_on_demand, OnDemandAssignmentProvider]
// Substrate
[pallet_bags_list, VoterList]
[pallet_balances, Balances]
Expand Down
3 changes: 3 additions & 0 deletions polkadot/runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ parameter_types! {
pub Collectives: Location = Parachain(COLLECTIVES_ID).into_location();
pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
pub People: Location = Parachain(PEOPLE_ID).into_location();
pub Broker: Location = Parachain(BROKER_ID).into_location();
pub Wnd: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
pub WndForAssetHub: (AssetFilter, Location) = (Wnd::get(), AssetHub::get());
pub WndForCollectives: (AssetFilter, Location) = (Wnd::get(), Collectives::get());
pub WndForBridgeHub: (AssetFilter, Location) = (Wnd::get(), BridgeHub::get());
pub WndForPeople: (AssetFilter, Location) = (Wnd::get(), People::get());
pub WndForBroker: (AssetFilter, Location) = (Wnd::get(), Broker::get());
pub MaxInstructions: u32 = 100;
pub MaxAssetsIntoHolding: u32 = 64;
}
Expand All @@ -132,6 +134,7 @@ pub type TrustedTeleporters = (
xcm_builder::Case<WndForCollectives>,
xcm_builder::Case<WndForBridgeHub>,
xcm_builder::Case<WndForPeople>,
xcm_builder::Case<WndForBroker>,
);

pub struct OnlyParachains;
Expand Down
Loading