mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-23 21:21:06 +00:00
Rococo: ability to programatically assign slots to teams (#3943)
* Permanent & Temp parachain slots on Rococo - WIP * Revert test change * Revert test change * Fix formatting * Extract logic to separate assigned_slots pallet * Formatting * Parachain downgrade logic * Pallet doc comment * Revert unnecessary changes * Fix few issues, tweak temp slots allocation logic; add a bunch of tests * Address review comments; track active temp slots * Update runtime/common/src/assigned_slots.rs * Update runtime/common/src/assigned_slots.rs * Remove assigned_slots calls from paras_sudo_wrapper * Unassign is a perfectly valid verb * Remove unneeded collect * Update code following #3980 * Cleanup * Generate storage info for pallet * Address review comments * Add ForceOrigin to slots pallet * Track permanent slot duration in storage * Fix tests build Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
use sp_std::vec::Vec;
|
use sp_std::vec::Vec;
|
||||||
|
|
||||||
use frame_support::weights::Weight;
|
use frame_support::weights::Weight;
|
||||||
use parity_scale_codec::{CompactAs, Decode, Encode};
|
use parity_scale_codec::{CompactAs, Decode, Encode, MaxEncodedLen};
|
||||||
use scale_info::TypeInfo;
|
use scale_info::TypeInfo;
|
||||||
use sp_core::{RuntimeDebug, TypeId};
|
use sp_core::{RuntimeDebug, TypeId};
|
||||||
use sp_runtime::traits::Hash as _;
|
use sp_runtime::traits::Hash as _;
|
||||||
@@ -139,6 +139,7 @@ pub struct BlockData(#[cfg_attr(feature = "std", serde(with = "bytes"))] pub Vec
|
|||||||
Encode,
|
Encode,
|
||||||
Eq,
|
Eq,
|
||||||
Hash,
|
Hash,
|
||||||
|
MaxEncodedLen,
|
||||||
Ord,
|
Ord,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
PartialOrd,
|
PartialOrd,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -216,6 +216,7 @@ impl slots::Config for Test {
|
|||||||
type Registrar = Registrar;
|
type Registrar = Registrar;
|
||||||
type LeasePeriod = LeasePeriod;
|
type LeasePeriod = LeasePeriod;
|
||||||
type LeaseOffset = LeaseOffset;
|
type LeaseOffset = LeaseOffset;
|
||||||
|
type ForceOrigin = EnsureRoot<AccountId>;
|
||||||
type WeightInfo = crate::slots::TestWeightInfo;
|
type WeightInfo = crate::slots::TestWeightInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
pub mod assigned_slots;
|
||||||
pub mod auctions;
|
pub mod auctions;
|
||||||
pub mod claims;
|
pub mod claims;
|
||||||
pub mod crowdloan;
|
pub mod crowdloan;
|
||||||
|
|||||||
@@ -87,6 +87,9 @@ pub mod pallet {
|
|||||||
#[pallet::constant]
|
#[pallet::constant]
|
||||||
type LeaseOffset: Get<Self::BlockNumber>;
|
type LeaseOffset: Get<Self::BlockNumber>;
|
||||||
|
|
||||||
|
/// The origin which may forcibly create or clear leases. Root can always do this.
|
||||||
|
type ForceOrigin: EnsureOrigin<<Self as frame_system::Config>::Origin>;
|
||||||
|
|
||||||
/// Weight Information for the Extrinsics in the Pallet
|
/// Weight Information for the Extrinsics in the Pallet
|
||||||
type WeightInfo: WeightInfo;
|
type WeightInfo: WeightInfo;
|
||||||
}
|
}
|
||||||
@@ -159,7 +162,7 @@ pub mod pallet {
|
|||||||
/// Just a connect into the `lease_out` call, in case Root wants to force some lease to happen
|
/// Just a connect into the `lease_out` call, in case Root wants to force some lease to happen
|
||||||
/// independently of any other on-chain mechanism to use it.
|
/// independently of any other on-chain mechanism to use it.
|
||||||
///
|
///
|
||||||
/// Can only be called by the Root origin.
|
/// The dispatch origin for this call must match `T::ForceOrigin`.
|
||||||
#[pallet::weight(T::WeightInfo::force_lease())]
|
#[pallet::weight(T::WeightInfo::force_lease())]
|
||||||
pub fn force_lease(
|
pub fn force_lease(
|
||||||
origin: OriginFor<T>,
|
origin: OriginFor<T>,
|
||||||
@@ -169,7 +172,7 @@ pub mod pallet {
|
|||||||
period_begin: LeasePeriodOf<T>,
|
period_begin: LeasePeriodOf<T>,
|
||||||
period_count: LeasePeriodOf<T>,
|
period_count: LeasePeriodOf<T>,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
T::ForceOrigin::ensure_origin(origin)?;
|
||||||
Self::lease_out(para, &leaser, amount, period_begin, period_count)
|
Self::lease_out(para, &leaser, amount, period_begin, period_count)
|
||||||
.map_err(|_| Error::<T>::LeaseError)?;
|
.map_err(|_| Error::<T>::LeaseError)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -177,10 +180,10 @@ pub mod pallet {
|
|||||||
|
|
||||||
/// Clear all leases for a Para Id, refunding any deposits back to the original owners.
|
/// Clear all leases for a Para Id, refunding any deposits back to the original owners.
|
||||||
///
|
///
|
||||||
/// Can only be called by the Root origin.
|
/// The dispatch origin for this call must match `T::ForceOrigin`.
|
||||||
#[pallet::weight(T::WeightInfo::clear_all_leases())]
|
#[pallet::weight(T::WeightInfo::clear_all_leases())]
|
||||||
pub fn clear_all_leases(origin: OriginFor<T>, para: ParaId) -> DispatchResult {
|
pub fn clear_all_leases(origin: OriginFor<T>, para: ParaId) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
T::ForceOrigin::ensure_origin(origin)?;
|
||||||
let deposits = Self::all_deposits_held(para);
|
let deposits = Self::all_deposits_held(para);
|
||||||
|
|
||||||
// Refund any deposits for these leases
|
// Refund any deposits for these leases
|
||||||
@@ -495,6 +498,7 @@ mod tests {
|
|||||||
|
|
||||||
use crate::{mock::TestRegistrar, slots};
|
use crate::{mock::TestRegistrar, slots};
|
||||||
use frame_support::{assert_noop, assert_ok, parameter_types};
|
use frame_support::{assert_noop, assert_ok, parameter_types};
|
||||||
|
use frame_system::EnsureRoot;
|
||||||
use pallet_balances;
|
use pallet_balances;
|
||||||
use primitives::v1::{BlockNumber, Header};
|
use primitives::v1::{BlockNumber, Header};
|
||||||
use sp_core::H256;
|
use sp_core::H256;
|
||||||
@@ -572,6 +576,7 @@ mod tests {
|
|||||||
type Registrar = TestRegistrar<Test>;
|
type Registrar = TestRegistrar<Test>;
|
||||||
type LeasePeriod = LeasePeriod;
|
type LeasePeriod = LeasePeriod;
|
||||||
type LeaseOffset = LeaseOffset;
|
type LeaseOffset = LeaseOffset;
|
||||||
|
type ForceOrigin = EnsureRoot<Self::AccountId>;
|
||||||
type WeightInfo = crate::slots::TestWeightInfo;
|
type WeightInfo = crate::slots::TestWeightInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1238,6 +1238,7 @@ impl slots::Config for Runtime {
|
|||||||
type Registrar = Registrar;
|
type Registrar = Registrar;
|
||||||
type LeasePeriod = LeasePeriod;
|
type LeasePeriod = LeasePeriod;
|
||||||
type LeaseOffset = ();
|
type LeaseOffset = ();
|
||||||
|
type ForceOrigin = MoreThanHalfCouncil;
|
||||||
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
|
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1228,6 +1228,7 @@ impl slots::Config for Runtime {
|
|||||||
type Registrar = Registrar;
|
type Registrar = Registrar;
|
||||||
type LeasePeriod = LeasePeriod;
|
type LeasePeriod = LeasePeriod;
|
||||||
type LeaseOffset = LeaseOffset;
|
type LeaseOffset = LeaseOffset;
|
||||||
|
type ForceOrigin = MoreThanHalfCouncil;
|
||||||
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
|
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,9 @@ use primitives::v1::{
|
|||||||
ValidatorIndex,
|
ValidatorIndex,
|
||||||
};
|
};
|
||||||
use runtime_common::{
|
use runtime_common::{
|
||||||
auctions, crowdloan, impls::ToAuthor, paras_registrar, paras_sudo_wrapper, slots, xcm_sender,
|
assigned_slots, auctions, crowdloan, impls::ToAuthor, paras_registrar, paras_sudo_wrapper,
|
||||||
BlockHashCount, BlockLength, BlockWeights, RocksDbWeight, SlowAdjustingFeeUpdate,
|
slots, xcm_sender, BlockHashCount, BlockLength, BlockWeights, RocksDbWeight,
|
||||||
|
SlowAdjustingFeeUpdate,
|
||||||
};
|
};
|
||||||
use runtime_parachains::{self, runtime_api_impl::v1 as runtime_api_impl};
|
use runtime_parachains::{self, runtime_api_impl::v1 as runtime_api_impl};
|
||||||
use scale_info::TypeInfo;
|
use scale_info::TypeInfo;
|
||||||
@@ -239,11 +240,12 @@ construct_runtime! {
|
|||||||
ParasDisputes: parachains_disputes,
|
ParasDisputes: parachains_disputes,
|
||||||
|
|
||||||
// Parachain Onboarding Pallets
|
// Parachain Onboarding Pallets
|
||||||
Registrar: paras_registrar,
|
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>, Config},
|
||||||
Auctions: auctions,
|
Auctions: auctions::{Pallet, Call, Storage, Event<T>},
|
||||||
Crowdloan: crowdloan,
|
Crowdloan: crowdloan::{Pallet, Call, Storage, Event<T>},
|
||||||
Slots: slots,
|
Slots: slots::{Pallet, Call, Storage, Event<T>},
|
||||||
ParasSudoWrapper: paras_sudo_wrapper,
|
ParasSudoWrapper: paras_sudo_wrapper::{Pallet, Call},
|
||||||
|
AssignedSlots: assigned_slots::{Pallet, Call, Storage, Event<T>},
|
||||||
|
|
||||||
// Sudo
|
// Sudo
|
||||||
Sudo: pallet_sudo,
|
Sudo: pallet_sudo,
|
||||||
@@ -786,6 +788,25 @@ impl parachains_initializer::Config for Runtime {
|
|||||||
|
|
||||||
impl paras_sudo_wrapper::Config for Runtime {}
|
impl paras_sudo_wrapper::Config for Runtime {}
|
||||||
|
|
||||||
|
parameter_types! {
|
||||||
|
pub const PermanentSlotLeasePeriodLength: u32 = 26;
|
||||||
|
pub const TemporarySlotLeasePeriodLength: u32 = 1;
|
||||||
|
pub const MaxPermanentSlots: u32 = 5;
|
||||||
|
pub const MaxTemporarySlots: u32 = 20;
|
||||||
|
pub const MaxTemporarySlotPerLeasePeriod: u32 = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl assigned_slots::Config for Runtime {
|
||||||
|
type Event = Event;
|
||||||
|
type AssignSlotOrigin = EnsureRoot<AccountId>;
|
||||||
|
type Leaser = Slots;
|
||||||
|
type PermanentSlotLeasePeriodLength = PermanentSlotLeasePeriodLength;
|
||||||
|
type TemporarySlotLeasePeriodLength = TemporarySlotLeasePeriodLength;
|
||||||
|
type MaxPermanentSlots = MaxPermanentSlots;
|
||||||
|
type MaxTemporarySlots = MaxTemporarySlots;
|
||||||
|
type MaxTemporarySlotPerLeasePeriod = MaxTemporarySlotPerLeasePeriod;
|
||||||
|
}
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const ParaDeposit: Balance = 5 * DOLLARS;
|
pub const ParaDeposit: Balance = 5 * DOLLARS;
|
||||||
pub const DataDepositPerByte: Balance = deposit(0, 1);
|
pub const DataDepositPerByte: Balance = deposit(0, 1);
|
||||||
@@ -1019,7 +1040,7 @@ impl auctions::Config for Runtime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const LeasePeriod: BlockNumber = 1 * DAYS;
|
pub const LeasePeriod: BlockNumber = 7 * DAYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl slots::Config for Runtime {
|
impl slots::Config for Runtime {
|
||||||
@@ -1028,6 +1049,7 @@ impl slots::Config for Runtime {
|
|||||||
type Registrar = Registrar;
|
type Registrar = Registrar;
|
||||||
type LeasePeriod = LeasePeriod;
|
type LeasePeriod = LeasePeriod;
|
||||||
type LeaseOffset = ();
|
type LeaseOffset = ();
|
||||||
|
type ForceOrigin = EnsureRoot<AccountId>;
|
||||||
type WeightInfo = slots::TestWeightInfo;
|
type WeightInfo = slots::TestWeightInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1108,8 +1130,9 @@ impl InstanceFilter<Call> for ProxyType {
|
|||||||
fn filter(&self, c: &Call) -> bool {
|
fn filter(&self, c: &Call) -> bool {
|
||||||
match self {
|
match self {
|
||||||
ProxyType::Any => true,
|
ProxyType::Any => true,
|
||||||
ProxyType::CancelProxy =>
|
ProxyType::CancelProxy => {
|
||||||
matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement { .. })),
|
matches!(c, Call::Proxy(pallet_proxy::Call::reject_announcement { .. }))
|
||||||
|
},
|
||||||
ProxyType::Auction => matches!(
|
ProxyType::Auction => matches!(
|
||||||
c,
|
c,
|
||||||
Call::Auctions { .. } |
|
Call::Auctions { .. } |
|
||||||
|
|||||||
@@ -29,9 +29,10 @@ use primitives::v1::{
|
|||||||
SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
|
SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
|
||||||
};
|
};
|
||||||
use runtime_common::{
|
use runtime_common::{
|
||||||
auctions, crowdloan, impls::ToAuthor, paras_registrar, paras_sudo_wrapper, slots, xcm_sender,
|
assigned_slots, auctions, crowdloan, impls::ToAuthor, paras_registrar, paras_sudo_wrapper,
|
||||||
BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit,
|
slots, xcm_sender, BlockHashCount, BlockLength, BlockWeights, CurrencyToVote,
|
||||||
OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate,
|
OffchainSolutionLengthLimit, OffchainSolutionWeightLimit, RocksDbWeight,
|
||||||
|
SlowAdjustingFeeUpdate,
|
||||||
};
|
};
|
||||||
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
||||||
|
|
||||||
@@ -862,6 +863,25 @@ impl parachains_initializer::Config for Runtime {
|
|||||||
|
|
||||||
impl paras_sudo_wrapper::Config for Runtime {}
|
impl paras_sudo_wrapper::Config for Runtime {}
|
||||||
|
|
||||||
|
parameter_types! {
|
||||||
|
pub const PermanentSlotLeasePeriodLength: u32 = 26;
|
||||||
|
pub const TemporarySlotLeasePeriodLength: u32 = 1;
|
||||||
|
pub const MaxPermanentSlots: u32 = 5;
|
||||||
|
pub const MaxTemporarySlots: u32 = 20;
|
||||||
|
pub const MaxTemporarySlotPerLeasePeriod: u32 = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl assigned_slots::Config for Runtime {
|
||||||
|
type Event = Event;
|
||||||
|
type AssignSlotOrigin = EnsureRoot<AccountId>;
|
||||||
|
type Leaser = Slots;
|
||||||
|
type PermanentSlotLeasePeriodLength = PermanentSlotLeasePeriodLength;
|
||||||
|
type TemporarySlotLeasePeriodLength = TemporarySlotLeasePeriodLength;
|
||||||
|
type MaxPermanentSlots = MaxPermanentSlots;
|
||||||
|
type MaxTemporarySlots = MaxTemporarySlots;
|
||||||
|
type MaxTemporarySlotPerLeasePeriod = MaxTemporarySlotPerLeasePeriod;
|
||||||
|
}
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const ParaDeposit: Balance = 2000 * CENTS;
|
pub const ParaDeposit: Balance = 2000 * CENTS;
|
||||||
pub const DataDepositPerByte: Balance = deposit(0, 1);
|
pub const DataDepositPerByte: Balance = deposit(0, 1);
|
||||||
@@ -887,6 +907,7 @@ impl slots::Config for Runtime {
|
|||||||
type Registrar = Registrar;
|
type Registrar = Registrar;
|
||||||
type LeasePeriod = LeasePeriod;
|
type LeasePeriod = LeasePeriod;
|
||||||
type LeaseOffset = ();
|
type LeaseOffset = ();
|
||||||
|
type ForceOrigin = EnsureRoot<AccountId>;
|
||||||
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
|
type WeightInfo = weights::runtime_common_slots::WeightInfo<Runtime>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1112,6 +1133,7 @@ construct_runtime! {
|
|||||||
ParasSudoWrapper: paras_sudo_wrapper::{Pallet, Call} = 62,
|
ParasSudoWrapper: paras_sudo_wrapper::{Pallet, Call} = 62,
|
||||||
Auctions: auctions::{Pallet, Call, Storage, Event<T>} = 63,
|
Auctions: auctions::{Pallet, Call, Storage, Event<T>} = 63,
|
||||||
Crowdloan: crowdloan::{Pallet, Call, Storage, Event<T>} = 64,
|
Crowdloan: crowdloan::{Pallet, Call, Storage, Event<T>} = 64,
|
||||||
|
AssignedSlots: assigned_slots::{Pallet, Call, Storage, Event<T>} = 65,
|
||||||
|
|
||||||
// Pallet for sending XCM.
|
// Pallet for sending XCM.
|
||||||
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config} = 99,
|
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config} = 99,
|
||||||
|
|||||||
@@ -280,6 +280,7 @@ typesystem
|
|||||||
ubuntu/M
|
ubuntu/M
|
||||||
UDP
|
UDP
|
||||||
UI
|
UI
|
||||||
|
unassign
|
||||||
unconcluded
|
unconcluded
|
||||||
unfinalize/B
|
unfinalize/B
|
||||||
unfinalized
|
unfinalized
|
||||||
|
|||||||
Reference in New Issue
Block a user