difftreelog
refactor(collator-selection) rename revoke to release + update tx + cargo fmt
in: master
13 files changed
pallets/collator-selection/src/lib.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/lib.rs
+++ b/pallets/collator-selection/src/lib.rs
@@ -217,7 +217,7 @@
let bounded_invulnerables =
BoundedVec::<_, T::MaxCollators>::try_from(self.invulnerables.clone())
.expect("genesis invulnerables are more than T::MaxCollators");
-
+
<Invulnerables<T>>::put(bounded_invulnerables);
}
}
@@ -284,6 +284,7 @@
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Add a collator to the list of invulnerable (fixed) collators.
+ #[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::set_invulnerables(1u32))] // todo:collator weight
pub fn add_invulnerable(
origin: OriginFor<T>,
@@ -313,6 +314,7 @@
}
/// Remove a collator from the list of invulnerable (fixed) collators.
+ #[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::set_invulnerables(1))] // todo:collator weight
pub fn remove_invulnerable(
origin: OriginFor<T>,
@@ -341,6 +343,7 @@
/// (a) already have registered session keys and (b) be able to reserve the `LicenseBond`.
///
/// This call is not available to `Invulnerable` collators.
+ #[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCollators::get()))] // todo:collator weight
pub fn get_license(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
// register_as_candidate
@@ -373,6 +376,7 @@
/// The account must already hold a license, and cannot offboard immediately during a session.
///
/// This call is not available to `Invulnerable` collators.
+ #[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCollators::get()))] // todo:collator weight
pub fn onboard(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
// register_as_candidate
@@ -418,6 +422,7 @@
/// Deregister `origin` as a collator candidate. Note that the collator can only leave on
/// session change. The license to `onboard` later at any other time will remain.
+ #[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight
pub fn offboard(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
// leave_intent
@@ -430,6 +435,7 @@
/// Forfeit `origin`'s own license. The `LicenseBond` will be unreserved immediately.
///
/// This call is not available to `Invulnerable` collators.
+ #[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight
pub fn release_license(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
// leave_intent
@@ -445,8 +451,9 @@
/// The `LicenseBond` will be unreserved and returned immediately.
///
/// This call is, of course, not applicable to `Invulnerable` collators.
+ #[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight
- pub fn force_revoke_license(
+ pub fn force_release_license(
origin: OriginFor<T>,
who: T::AccountId,
) -> DispatchResultWithPostInfo {
pallets/collator-selection/src/mock.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// Copyright (C) 2021 Parity Technologies (UK) Ltd.19// SPDX-License-Identifier: Apache-2.02021// Licensed under the Apache License, Version 2.0 (the "License");22// you may not use this file except in compliance with the License.23// You may obtain a copy of the License at24//25// http://www.apache.org/licenses/LICENSE-2.026//27// Unless required by applicable law or agreed to in writing, software28// distributed under the License is distributed on an "AS IS" BASIS,29// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.30// See the License for the specific language governing permissions and31// limitations under the License.3233use super::*;34use crate as collator_selection;35use frame_support::{36 ord_parameter_types, parameter_types,37 traits::{FindAuthor, GenesisBuild, ValidatorRegistration},38 PalletId,39};40use frame_system as system;41use frame_system::EnsureSignedBy;42use sp_core::H256;43use sp_runtime::{44 testing::{Header, UintAuthorityId},45 traits::{BlakeTwo256, IdentityLookup, OpaqueKeys},46 Perbill, RuntimeAppPublic,47};4849type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;50type Block = frame_system::mocking::MockBlock<Test>;5152// Configure a mock runtime to test the pallet.53frame_support::construct_runtime!(54 pub enum Test where55 Block = Block,56 NodeBlock = Block,57 UncheckedExtrinsic = UncheckedExtrinsic,58 {59 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},60 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},61 Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},62 Aura: pallet_aura::{Pallet, Storage, Config<T>},63 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},64 CollatorSelection: collator_selection::{Pallet, Call, Storage, Event<T>},65 Authorship: pallet_authorship::{Pallet, Call, Storage, Inherent},66 Configuration: pallet_configuration::{Pallet, Call, Storage, Event<T>},67 }68);6970parameter_types! {71 pub const BlockHashCount: u64 = 250;72 pub const SS58Prefix: u8 = 42;73}7475impl system::Config for Test {76 type BaseCallFilter = frame_support::traits::Everything;77 type BlockWeights = ();78 type BlockLength = ();79 type DbWeight = ();80 type RuntimeOrigin = RuntimeOrigin;81 type RuntimeCall = RuntimeCall;82 type Index = u64;83 type BlockNumber = u64;84 type Hash = H256;85 type Hashing = BlakeTwo256;86 type AccountId = u64;87 type Lookup = IdentityLookup<Self::AccountId>;88 type Header = Header;89 type RuntimeEvent = RuntimeEvent;90 type BlockHashCount = BlockHashCount;91 type Version = ();92 type PalletInfo = PalletInfo;93 type AccountData = pallet_balances::AccountData<u64>;94 type OnNewAccount = ();95 type OnKilledAccount = ();96 type SystemWeightInfo = ();97 type SS58Prefix = SS58Prefix;98 type OnSetCode = ();99 type MaxConsumers = frame_support::traits::ConstU32<16>;100}101102parameter_types! {103 pub const ExistentialDeposit: u64 = 5;104 pub const MaxReserves: u32 = 50;105}106107impl pallet_balances::Config for Test {108 type Balance = u64;109 type RuntimeEvent = RuntimeEvent;110 type DustRemoval = ();111 type ExistentialDeposit = ExistentialDeposit;112 type AccountStore = System;113 type WeightInfo = ();114 type MaxLocks = ();115 type MaxReserves = MaxReserves;116 type ReserveIdentifier = [u8; 8];117}118119pub struct Author4;120impl FindAuthor<u64> for Author4 {121 fn find_author<'a, I>(_digests: I) -> Option<u64>122 where123 I: 'a + IntoIterator<Item = (frame_support::ConsensusEngineId, &'a [u8])>,124 {125 Some(4)126 }127}128129impl pallet_authorship::Config for Test {130 type FindAuthor = Author4;131 type UncleGenerations = ();132 type FilterUncle = ();133 type EventHandler = CollatorSelection;134}135136parameter_types! {137 pub const MinimumPeriod: u64 = 1;138}139140impl pallet_timestamp::Config for Test {141 type Moment = u64;142 type OnTimestampSet = Aura;143 type MinimumPeriod = MinimumPeriod;144 type WeightInfo = ();145}146147impl pallet_aura::Config for Test {148 type AuthorityId = sp_consensus_aura::sr25519::AuthorityId;149 type MaxAuthorities = MaxAuthorities;150 type DisabledValidators = ();151}152153sp_runtime::impl_opaque_keys! {154 pub struct MockSessionKeys {155 // a key for aura authoring156 pub aura: UintAuthorityId,157 }158}159160impl From<UintAuthorityId> for MockSessionKeys {161 fn from(aura: sp_runtime::testing::UintAuthorityId) -> Self {162 Self { aura }163 }164}165166parameter_types! {167 pub static SessionHandlerCollators: Vec<u64> = Vec::new();168 pub static SessionChangeBlock: u64 = 0;169}170171pub struct TestSessionHandler;172impl pallet_session::SessionHandler<u64> for TestSessionHandler {173 const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[UintAuthorityId::ID];174 fn on_genesis_session<Ks: OpaqueKeys>(keys: &[(u64, Ks)]) {175 SessionHandlerCollators::set(keys.into_iter().map(|(a, _)| *a).collect::<Vec<_>>())176 }177 fn on_new_session<Ks: OpaqueKeys>(_: bool, keys: &[(u64, Ks)], _: &[(u64, Ks)]) {178 SessionChangeBlock::set(System::block_number());179 dbg!(keys.len());180 SessionHandlerCollators::set(keys.into_iter().map(|(a, _)| *a).collect::<Vec<_>>())181 }182 fn on_before_session_ending() {}183 fn on_disabled(_: u32) {}184}185186parameter_types! {187 pub const Offset: u64 = 0;188 pub const Period: u64 = 10;189}190191impl pallet_session::Config for Test {192 type RuntimeEvent = RuntimeEvent;193 type ValidatorId = <Self as frame_system::Config>::AccountId;194 // we don't have stash and controller, thus we don't need the convert as well.195 type ValidatorIdOf = IdentityCollator;196 type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;197 type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;198 type SessionManager = CollatorSelection;199 type SessionHandler = TestSessionHandler;200 type Keys = MockSessionKeys;201 type WeightInfo = ();202}203204parameter_types! {205 pub const MaxCollators: u32 = 5;206 pub const LicenseBond: u64 = 10;207 pub const KickThreshold: u64 = 10;208 // the following values do not matter and are meaningless, etc.209 pub const DefaultWeightToFeeCoefficient: u64 = 100_000;210 pub const DefaultMinGasPrice: u64 = 100_000;211 pub const MaxXcmAllowedLocations: u32 = 16;212 pub AppPromotionDailyRate: Perbill = Perbill::from_rational(5u32, 10_000);213 pub const DayRelayBlocks: u32 = 1;214}215216impl pallet_configuration::Config for Test {217 type RuntimeEvent = RuntimeEvent;218 type Currency = Balances;219 type DefaultCollatorSelectionMaxCollators = MaxCollators;220 type DefaultCollatorSelectionKickThreshold = KickThreshold;221 type DefaultCollatorSelectionLicenseBond = LicenseBond;222 // the following we don't care about223 type DefaultWeightToFeeCoefficient = DefaultWeightToFeeCoefficient;224 type DefaultMinGasPrice = DefaultMinGasPrice;225 type MaxXcmAllowedLocations = MaxXcmAllowedLocations;226 type AppPromotionDailyRate = AppPromotionDailyRate;227 type DayRelayBlocks = DayRelayBlocks;228}229230ord_parameter_types! {231 pub const RootAccount: u64 = 777;232}233234parameter_types! {235 pub const PotId: PalletId = PalletId(*b"PotStake");236 pub const MaxAuthorities: u32 = 100_000;237 pub const SlashRatio: Perbill = Perbill::one();238}239240pub struct IsRegistered;241impl ValidatorRegistration<u64> for IsRegistered {242 fn is_registered(id: &u64) -> bool {243 if *id == 7u64 {244 false245 } else {246 true247 }248 }249}250251impl Config for Test {252 type RuntimeEvent = RuntimeEvent;253 type UpdateOrigin = EnsureSignedBy<RootAccount, u64>;254 type PotId = PotId;255 type MaxCollators = MaxCollators;256 type SlashRatio = SlashRatio;257 type TreasuryAccountId = ();258 type ValidatorId = <Self as frame_system::Config>::AccountId;259 type ValidatorIdOf = IdentityCollator;260 type ValidatorRegistration = IsRegistered;261 type WeightInfo = ();262}263264pub fn new_test_ext() -> sp_io::TestExternalities {265 sp_tracing::try_init_simple();266 let mut t = frame_system::GenesisConfig::default()267 .build_storage::<Test>()268 .unwrap();269 let invulnerables = vec![1, 2];270271 let balances = vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100)];272 let keys = balances273 .iter()274 .map(|&(i, _)| {275 (276 i,277 i,278 MockSessionKeys {279 aura: UintAuthorityId(i),280 },281 )282 })283 .collect::<Vec<_>>();284 let collator_selection = collator_selection::GenesisConfig::<Test> {285 invulnerables,286 };287 let session = pallet_session::GenesisConfig::<Test> { keys };288 pallet_balances::GenesisConfig::<Test> { balances }289 .assimilate_storage(&mut t)290 .unwrap();291 // collator selection must be initialized before session.292 collator_selection.assimilate_storage(&mut t).unwrap();293 session.assimilate_storage(&mut t).unwrap();294295 t.into()296}297298pub fn initialize_to_block(n: u64) {299 for i in System::block_number() + 1..=n {300 System::set_block_number(i);301 <AllPalletsWithSystem as frame_support::traits::OnInitialize<u64>>::on_initialize(i);302 }303}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// Copyright (C) 2021 Parity Technologies (UK) Ltd.19// SPDX-License-Identifier: Apache-2.02021// Licensed under the Apache License, Version 2.0 (the "License");22// you may not use this file except in compliance with the License.23// You may obtain a copy of the License at24//25// http://www.apache.org/licenses/LICENSE-2.026//27// Unless required by applicable law or agreed to in writing, software28// distributed under the License is distributed on an "AS IS" BASIS,29// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.30// See the License for the specific language governing permissions and31// limitations under the License.3233use super::*;34use crate as collator_selection;35use frame_support::{36 ord_parameter_types, parameter_types,37 traits::{FindAuthor, GenesisBuild, ValidatorRegistration},38 PalletId,39};40use frame_system as system;41use frame_system::EnsureSignedBy;42use sp_core::H256;43use sp_runtime::{44 testing::{Header, UintAuthorityId},45 traits::{BlakeTwo256, IdentityLookup, OpaqueKeys},46 Perbill, RuntimeAppPublic,47};4849type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;50type Block = frame_system::mocking::MockBlock<Test>;5152// Configure a mock runtime to test the pallet.53frame_support::construct_runtime!(54 pub enum Test where55 Block = Block,56 NodeBlock = Block,57 UncheckedExtrinsic = UncheckedExtrinsic,58 {59 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},60 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},61 Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},62 Aura: pallet_aura::{Pallet, Storage, Config<T>},63 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},64 CollatorSelection: collator_selection::{Pallet, Call, Storage, Event<T>},65 Authorship: pallet_authorship::{Pallet, Call, Storage, Inherent},66 Configuration: pallet_configuration::{Pallet, Call, Storage, Event<T>},67 }68);6970parameter_types! {71 pub const BlockHashCount: u64 = 250;72 pub const SS58Prefix: u8 = 42;73}7475impl system::Config for Test {76 type BaseCallFilter = frame_support::traits::Everything;77 type BlockWeights = ();78 type BlockLength = ();79 type DbWeight = ();80 type RuntimeOrigin = RuntimeOrigin;81 type RuntimeCall = RuntimeCall;82 type Index = u64;83 type BlockNumber = u64;84 type Hash = H256;85 type Hashing = BlakeTwo256;86 type AccountId = u64;87 type Lookup = IdentityLookup<Self::AccountId>;88 type Header = Header;89 type RuntimeEvent = RuntimeEvent;90 type BlockHashCount = BlockHashCount;91 type Version = ();92 type PalletInfo = PalletInfo;93 type AccountData = pallet_balances::AccountData<u64>;94 type OnNewAccount = ();95 type OnKilledAccount = ();96 type SystemWeightInfo = ();97 type SS58Prefix = SS58Prefix;98 type OnSetCode = ();99 type MaxConsumers = frame_support::traits::ConstU32<16>;100}101102parameter_types! {103 pub const ExistentialDeposit: u64 = 5;104 pub const MaxReserves: u32 = 50;105}106107impl pallet_balances::Config for Test {108 type Balance = u64;109 type RuntimeEvent = RuntimeEvent;110 type DustRemoval = ();111 type ExistentialDeposit = ExistentialDeposit;112 type AccountStore = System;113 type WeightInfo = ();114 type MaxLocks = ();115 type MaxReserves = MaxReserves;116 type ReserveIdentifier = [u8; 8];117}118119pub struct Author4;120impl FindAuthor<u64> for Author4 {121 fn find_author<'a, I>(_digests: I) -> Option<u64>122 where123 I: 'a + IntoIterator<Item = (frame_support::ConsensusEngineId, &'a [u8])>,124 {125 Some(4)126 }127}128129impl pallet_authorship::Config for Test {130 type FindAuthor = Author4;131 type UncleGenerations = ();132 type FilterUncle = ();133 type EventHandler = CollatorSelection;134}135136parameter_types! {137 pub const MinimumPeriod: u64 = 1;138}139140impl pallet_timestamp::Config for Test {141 type Moment = u64;142 type OnTimestampSet = Aura;143 type MinimumPeriod = MinimumPeriod;144 type WeightInfo = ();145}146147impl pallet_aura::Config for Test {148 type AuthorityId = sp_consensus_aura::sr25519::AuthorityId;149 type MaxAuthorities = MaxAuthorities;150 type DisabledValidators = ();151}152153sp_runtime::impl_opaque_keys! {154 pub struct MockSessionKeys {155 // a key for aura authoring156 pub aura: UintAuthorityId,157 }158}159160impl From<UintAuthorityId> for MockSessionKeys {161 fn from(aura: sp_runtime::testing::UintAuthorityId) -> Self {162 Self { aura }163 }164}165166parameter_types! {167 pub static SessionHandlerCollators: Vec<u64> = Vec::new();168 pub static SessionChangeBlock: u64 = 0;169}170171pub struct TestSessionHandler;172impl pallet_session::SessionHandler<u64> for TestSessionHandler {173 const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[UintAuthorityId::ID];174 fn on_genesis_session<Ks: OpaqueKeys>(keys: &[(u64, Ks)]) {175 SessionHandlerCollators::set(keys.into_iter().map(|(a, _)| *a).collect::<Vec<_>>())176 }177 fn on_new_session<Ks: OpaqueKeys>(_: bool, keys: &[(u64, Ks)], _: &[(u64, Ks)]) {178 SessionChangeBlock::set(System::block_number());179 dbg!(keys.len());180 SessionHandlerCollators::set(keys.into_iter().map(|(a, _)| *a).collect::<Vec<_>>())181 }182 fn on_before_session_ending() {}183 fn on_disabled(_: u32) {}184}185186parameter_types! {187 pub const Offset: u64 = 0;188 pub const Period: u64 = 10;189}190191impl pallet_session::Config for Test {192 type RuntimeEvent = RuntimeEvent;193 type ValidatorId = <Self as frame_system::Config>::AccountId;194 // we don't have stash and controller, thus we don't need the convert as well.195 type ValidatorIdOf = IdentityCollator;196 type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;197 type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;198 type SessionManager = CollatorSelection;199 type SessionHandler = TestSessionHandler;200 type Keys = MockSessionKeys;201 type WeightInfo = ();202}203204parameter_types! {205 pub const MaxCollators: u32 = 5;206 pub const LicenseBond: u64 = 10;207 pub const KickThreshold: u64 = 10;208 // the following values do not matter and are meaningless, etc.209 pub const DefaultWeightToFeeCoefficient: u64 = 100_000;210 pub const DefaultMinGasPrice: u64 = 100_000;211 pub const MaxXcmAllowedLocations: u32 = 16;212 pub AppPromotionDailyRate: Perbill = Perbill::from_rational(5u32, 10_000);213 pub const DayRelayBlocks: u32 = 1;214}215216impl pallet_configuration::Config for Test {217 type RuntimeEvent = RuntimeEvent;218 type Currency = Balances;219 type DefaultCollatorSelectionMaxCollators = MaxCollators;220 type DefaultCollatorSelectionKickThreshold = KickThreshold;221 type DefaultCollatorSelectionLicenseBond = LicenseBond;222 // the following we don't care about223 type DefaultWeightToFeeCoefficient = DefaultWeightToFeeCoefficient;224 type DefaultMinGasPrice = DefaultMinGasPrice;225 type MaxXcmAllowedLocations = MaxXcmAllowedLocations;226 type AppPromotionDailyRate = AppPromotionDailyRate;227 type DayRelayBlocks = DayRelayBlocks;228}229230ord_parameter_types! {231 pub const RootAccount: u64 = 777;232}233234parameter_types! {235 pub const PotId: PalletId = PalletId(*b"PotStake");236 pub const MaxAuthorities: u32 = 100_000;237 pub const SlashRatio: Perbill = Perbill::one();238}239240pub struct IsRegistered;241impl ValidatorRegistration<u64> for IsRegistered {242 fn is_registered(id: &u64) -> bool {243 if *id == 7u64 {244 false245 } else {246 true247 }248 }249}250251impl Config for Test {252 type RuntimeEvent = RuntimeEvent;253 type UpdateOrigin = EnsureSignedBy<RootAccount, u64>;254 type PotId = PotId;255 type MaxCollators = MaxCollators;256 type SlashRatio = SlashRatio;257 type TreasuryAccountId = ();258 type ValidatorId = <Self as frame_system::Config>::AccountId;259 type ValidatorIdOf = IdentityCollator;260 type ValidatorRegistration = IsRegistered;261 type WeightInfo = ();262}263264pub fn new_test_ext() -> sp_io::TestExternalities {265 sp_tracing::try_init_simple();266 let mut t = frame_system::GenesisConfig::default()267 .build_storage::<Test>()268 .unwrap();269 let invulnerables = vec![1, 2];270271 let balances = vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100)];272 let keys = balances273 .iter()274 .map(|&(i, _)| {275 (276 i,277 i,278 MockSessionKeys {279 aura: UintAuthorityId(i),280 },281 )282 })283 .collect::<Vec<_>>();284 let collator_selection = collator_selection::GenesisConfig::<Test> { invulnerables };285 let session = pallet_session::GenesisConfig::<Test> { keys };286 pallet_balances::GenesisConfig::<Test> { balances }287 .assimilate_storage(&mut t)288 .unwrap();289 // collator selection must be initialized before session.290 collator_selection.assimilate_storage(&mut t).unwrap();291 session.assimilate_storage(&mut t).unwrap();292293 t.into()294}295296pub fn initialize_to_block(n: u64) {297 for i in System::block_number() + 1..=n {298 System::set_block_number(i);299 <AllPalletsWithSystem as frame_support::traits::OnInitialize<u64>>::on_initialize(i);300 }301}pallets/collator-selection/src/tests.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/tests.rs
+++ b/pallets/collator-selection/src/tests.rs
@@ -380,7 +380,7 @@
}
#[test]
-fn force_revoke_license() {
+fn force_release_license() {
new_test_ext().execute_with(|| {
// obtain a license to collate and reserve the bond.
assert_ok!(CollatorSelection::get_license(RuntimeOrigin::signed(3)));
@@ -388,12 +388,12 @@
// cannot execute the operation as non-root
assert_noop!(
- CollatorSelection::force_revoke_license(RuntimeOrigin::signed(3), 3),
+ CollatorSelection::force_release_license(RuntimeOrigin::signed(3), 3),
BadOrigin
);
// release the license and get the bond back.
- assert_ok!(CollatorSelection::force_revoke_license(
+ assert_ok!(CollatorSelection::force_release_license(
RuntimeOrigin::signed(RootAccount::get()),
3
));
@@ -404,7 +404,7 @@
assert_eq!(Balances::free_balance(3), 90);
// can release license even if onboarded.
- assert_ok!(CollatorSelection::force_revoke_license(
+ assert_ok!(CollatorSelection::force_release_license(
RuntimeOrigin::signed(RootAccount::get()),
3
));
@@ -532,9 +532,7 @@
.unwrap();
let invulnerables = vec![1, 1];
- let collator_selection = collator_selection::GenesisConfig::<Test> {
- invulnerables,
- };
+ let collator_selection = collator_selection::GenesisConfig::<Test> { invulnerables };
// collator selection must be initialized before session.
collator_selection.assimilate_storage(&mut t).unwrap();
}
pallets/configuration/src/lib.rsdiffbeforeafterboth--- a/pallets/configuration/src/lib.rs
+++ b/pallets/configuration/src/lib.rs
@@ -201,6 +201,7 @@
Ok(())
}
+ #[pallet::call_index(4)]
#[pallet::weight(T::DbWeight::get().writes(1))]
pub fn set_collator_selection_desired_collators(
origin: OriginFor<T>,
@@ -216,10 +217,13 @@
} else {
<CollatorSelectionDesiredCollatorsOverride<T>>::kill();
}
- Self::deposit_event(Event::NewDesiredCollators { desired_collators: max });
+ Self::deposit_event(Event::NewDesiredCollators {
+ desired_collators: max,
+ });
Ok(())
}
+ #[pallet::call_index(5)]
#[pallet::weight(T::DbWeight::get().writes(1))]
pub fn set_collator_selection_license_bond(
origin: OriginFor<T>,
@@ -235,6 +239,7 @@
Ok(())
}
+ #[pallet::call_index(6)]
#[pallet::weight(T::DbWeight::get().writes(1))]
pub fn set_collator_selection_kick_threshold(
origin: OriginFor<T>,
@@ -246,7 +251,9 @@
} else {
<CollatorSelectionKickThresholdOverride<T>>::kill();
}
- Self::deposit_event(Event::NewCollatorKickThreshold { length_in_blocks: threshold });
+ Self::deposit_event(Event::NewCollatorKickThreshold {
+ length_in_blocks: threshold,
+ });
Ok(())
}
}
runtime/common/data_management.rsdiffbeforeafterboth--- a/runtime/common/data_management.rs
+++ b/runtime/common/data_management.rs
@@ -58,10 +58,10 @@
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
- match call {
- #[cfg(feature = "collator-selection")]
- RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),
- _ => Ok(ValidTransaction::default()),
- }
+ match call {
+ #[cfg(feature = "collator-selection")]
+ RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),
+ _ => Ok(ValidTransaction::default()),
+ }
}
}
runtime/common/mod.rsdiffbeforeafterboth--- a/runtime/common/mod.rs
+++ b/runtime/common/mod.rs
@@ -16,11 +16,11 @@
pub mod config;
pub mod construct_runtime;
+pub mod data_management;
pub mod dispatch;
pub mod ethereum;
pub mod instance;
pub mod maintenance;
-pub mod data_management;
pub mod runtime_apis;
pub mod xcm;
runtime/common/tests/mod.rsdiffbeforeafterboth--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -63,9 +63,7 @@
.collect::<Vec<_>>();
let cfg = GenesisConfig {
- collator_selection: CollatorSelectionConfig {
- invulnerables,
- },
+ collator_selection: CollatorSelectionConfig { invulnerables },
session: SessionConfig { keys },
parachain_info: ParachainInfoConfig {
parachain_id: para_id.into(),
tests/src/collatorSelection.seqtest.tsdiffbeforeafterboth--- a/tests/src/collatorSelection.seqtest.ts
+++ b/tests/src/collatorSelection.seqtest.ts
@@ -209,7 +209,7 @@
expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(licenseBond);
// force-releasing a license un-reserves the license bond cost as well
- await helper.getSudo().collatorSelection.forceRevokeLicense(superuser, account.address);
+ await helper.getSudo().collatorSelection.forceReleaseLicense(superuser, account.address);
expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(previousBalance.reserved);
const balance = await helper.balance.getSubstrateFull(account.address);
@@ -243,7 +243,7 @@
itSub('Cannot force revoke a license as non-sudo', async ({helper}) => {
const account = crowd.pop()!;
await helper.collatorSelection.obtainLicense(account);
- await expect(helper.collatorSelection.forceRevokeLicense(superuser, account.address))
+ await expect(helper.collatorSelection.forceReleaseLicense(superuser, account.address))
.to.be.rejectedWith(/BadOrigin/);
});
});
@@ -459,7 +459,7 @@
const candidates = await helper.collatorSelection.getCandidates();
let nonce = await helper.chain.getNonce(superuser.address);
await Promise.all(candidates.map(candidate =>
- helper.getSudo().executeExtrinsic(superuser, 'api.tx.collatorSelection.forceRevokeLicense', [candidate], true, {nonce: nonce++})));
+ helper.getSudo().executeExtrinsic(superuser, 'api.tx.collatorSelection.forceReleaseLicense', [candidate], true, {nonce: nonce++})));
});
});
});
\ No newline at end of file
tests/src/interfaces/augment-api-tx.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-tx.ts
+++ b/tests/src/interfaces/augment-api-tx.ts
@@ -237,7 +237,7 @@
*
* This call is, of course, not applicable to `Invulnerable` collators.
**/
- forceRevokeLicense: AugmentedSubmittable<(who: AccountId32 | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [AccountId32]>;
+ forceReleaseLicense: AugmentedSubmittable<(who: AccountId32 | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [AccountId32]>;
/**
* Purchase a license on block collation for this account.
* It does not make it a collator candidate, use `onboard` afterward. The account must
tests/src/interfaces/default/types.tsdiffbeforeafterboth--- a/tests/src/interfaces/default/types.ts
+++ b/tests/src/interfaces/default/types.ts
@@ -1243,11 +1243,11 @@
readonly isOnboard: boolean;
readonly isOffboard: boolean;
readonly isReleaseLicense: boolean;
- readonly isForceRevokeLicense: boolean;
- readonly asForceRevokeLicense: {
+ readonly isForceReleaseLicense: boolean;
+ readonly asForceReleaseLicense: {
readonly who: AccountId32;
} & Struct;
- readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceRevokeLicense';
+ readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceReleaseLicense';
}
/** @name PalletCollatorSelectionError */
tests/src/interfaces/lookup.tsdiffbeforeafterboth--- a/tests/src/interfaces/lookup.ts
+++ b/tests/src/interfaces/lookup.ts
@@ -1692,7 +1692,7 @@
onboard: 'Null',
offboard: 'Null',
release_license: 'Null',
- force_revoke_license: {
+ force_release_license: {
who: 'AccountId32'
}
}
tests/src/interfaces/types-lookup.tsdiffbeforeafterboth--- a/tests/src/interfaces/types-lookup.ts
+++ b/tests/src/interfaces/types-lookup.ts
@@ -1867,11 +1867,11 @@
readonly isOnboard: boolean;
readonly isOffboard: boolean;
readonly isReleaseLicense: boolean;
- readonly isForceRevokeLicense: boolean;
- readonly asForceRevokeLicense: {
+ readonly isForceReleaseLicense: boolean;
+ readonly asForceReleaseLicense: {
readonly who: AccountId32;
} & Struct;
- readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceRevokeLicense';
+ readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceReleaseLicense';
}
/** @name PalletCollatorSelectionError (185) */
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2772,8 +2772,8 @@
return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.releaseLicense', []);
}
- forceRevokeLicense(signer: TSigner, released: string) {
- return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.forceRevokeLicense', [released]);
+ forceReleaseLicense(signer: TSigner, released: string) {
+ return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.forceReleaseLicense', [released]);
}
async hasLicense(address: string): Promise<bigint> {