difftreelog
fix(collator-selection) configuration weights + disable benchmarking for now
in: master
3 files changed
Makefilediffbeforeafterboth--- a/Makefile
+++ b/Makefile
@@ -146,5 +146,5 @@
make _bench PALLET=app-promotion PALLET_DIR=app-promotion
.PHONY: bench
-# Disabled: bench-scheduler, bench-rmrk-core, bench-rmrk-equip
-bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-collator-selection bench-identity
+# Disabled: bench-scheduler, bench-collator-selection, bench-rmrk-core, bench-rmrk-equip
+bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-identity
pallets/collator-selection/src/benchmarking.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.3233//! Benchmarking setup for pallet-collator-selection3435use super::*;3637#[allow(unused)]38use crate::Pallet as CollatorSelection;39use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};40use frame_support::{41 assert_ok,42 codec::Decode,43 traits::{Currency, EnsureOrigin, Get},44};45use frame_system::{EventRecord, RawOrigin};46use pallet_authorship::EventHandler;47use pallet_session::{self as session, SessionManager};48use pallet_configuration::{49 self as configuration, BalanceOf,50 CollatorSelectionDesiredCollatorsOverride as DesiredCollators,51 CollatorSelectionLicenseBondOverride as LicenseBond,52};53use sp_std::prelude::*;5455const SEED: u32 = 0;5657// TODO: remove if this is given in substrate commit.58macro_rules! whitelist {59 ($acc:ident) => {60 frame_benchmarking::benchmarking::add_to_whitelist(61 frame_system::Account::<T>::hashed_key_for(&$acc).into(),62 );63 };64}6566fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {67 let events = frame_system::Pallet::<T>::events();68 let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();69 // compare to the last event record70 let EventRecord { event, .. } = &events[events.len() - 1];71 assert_eq!(event, &system_event);72}7374fn create_funded_user<T: Config>(75 string: &'static str,76 n: u32,77 balance_factor: u32,78) -> T::AccountId {79 let user = account(string, n, SEED);80 let balance = T::Currency::minimum_balance() * balance_factor.into();81 let _ = T::Currency::make_free_balance_be(&user, balance);82 user83}8485fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {86 use rand::{RngCore, SeedableRng};8788 let keys = {89 let mut keys = [0u8; 128];9091 if c > 0 {92 let mut rng = rand::rngs::StdRng::seed_from_u64(c as u64);93 rng.fill_bytes(&mut keys);94 }9596 keys97 };9899 Decode::decode(&mut &keys[..]).unwrap()100}101102fn validator<T: Config + session::Config>(c: u32) -> (T::AccountId, <T as session::Config>::Keys) {103 (create_funded_user::<T>("candidate", c, 1000), keys::<T>(c))104}105106fn register_validators<T: Config + session::Config>(count: u32) -> Vec<T::AccountId> {107 let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();108109 for (who, keys) in validators.clone() {110 <session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap();111 }112113 validators.into_iter().map(|(who, _)| who).collect()114}115116fn register_invulnerables<T: Config + configuration::Config>(count: u32) {117 let candidates = (0..count)118 .map(|c| account("candidate", c, SEED))119 .collect::<Vec<_>>();120121 for who in candidates {122 <CollatorSelection<T>>::add_invulnerable(T::UpdateOrigin::successful_origin(), who)123 .unwrap();124 }125}126127fn register_candidates<T: Config + configuration::Config>(count: u32) {128 let candidates = (0..count)129 .map(|c| account("candidate", c, SEED))130 .collect::<Vec<_>>();131 /*assert!(132 <LicenseBond<T>>::get() > 0u32.into(),133 "Bond cannot be zero!"134 );*/135136 for who in candidates {137 T::Currency::make_free_balance_be(&who, <LicenseBond<T>>::get() * 2u32.into());138 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();139 <CollatorSelection<T>>::onboard(RawOrigin::Signed(who).into()).unwrap();140 }141}142143fn get_licenses<T: Config + configuration::Config>(count: u32) {144 let candidates = (0..count)145 .map(|c| account("candidate", c, SEED))146 .collect::<Vec<_>>();147 /*assert!(148 <LicenseBond<T>>::get() > 0u32.into(),149 "Bond cannot be zero!"150 );*/151152 for who in candidates {153 T::Currency::make_free_balance_be(&who, <LicenseBond<T>>::get() * 2u32.into());154 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();155 }156}157158benchmarks! {159 where_clause { where T: pallet_authorship::Config + session::Config + configuration::Config }160161 add_invulnerable {162 let b in 1 .. T::MaxCollators::get() - 3;163 register_validators::<T>(b);164 register_invulnerables::<T>(b);165166 // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);167168 let new_invulnerable: T::AccountId = whitelisted_caller();169 let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();170 T::Currency::make_free_balance_be(&new_invulnerable, bond.clone());171172 <session::Pallet<T>>::set_keys(173 RawOrigin::Signed(new_invulnerable.clone()).into(),174 keys::<T>(b + 1),175 Vec::new()176 ).unwrap();177178 let root_origin = T::UpdateOrigin::successful_origin();179 }: {180 assert_ok!(181 <CollatorSelection<T>>::add_invulnerable(root_origin, new_invulnerable.clone())182 );183 }184 verify {185 assert_last_event::<T>(Event::InvulnerableAdded{invulnerable: new_invulnerable}.into());186 }187188 remove_invulnerable {189 let b in 1 .. T::MaxCollators::get();190 register_validators::<T>(b);191 register_invulnerables::<T>(b);192193 let root_origin = T::UpdateOrigin::successful_origin();194 let leaving = <Invulnerables<T>>::get().last().unwrap().clone();195 whitelist!(leaving);196 }: {197 assert_ok!(198 <CollatorSelection<T>>::remove_invulnerable(root_origin, leaving.clone())199 );200 }201 verify {202 assert_last_event::<T>(Event::InvulnerableRemoved{invulnerable: leaving}.into());203 }204205 get_license {206 let c in 1 .. T::MaxCollators::get();207208 <LicenseBond<T>>::put(T::Currency::minimum_balance());209210 register_validators::<T>(c);211 get_licenses::<T>(c);212213 let caller: T::AccountId = whitelisted_caller();214 let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();215 T::Currency::make_free_balance_be(&caller, bond.clone());216217 <session::Pallet<T>>::set_keys(218 RawOrigin::Signed(caller.clone()).into(),219 keys::<T>(c + 1),220 Vec::new()221 ).unwrap();222223 }: _(RawOrigin::Signed(caller.clone()))224 verify {225 assert_last_event::<T>(Event::LicenseObtained{account_id: caller, deposit: bond / 2u32.into()}.into());226 }227228 // worst case is when we have all the max-candidate slots filled except one, and we fill that229 // one.230 onboard {231 let c in 1 .. 5;232233 <LicenseBond<T>>::put(T::Currency::minimum_balance());234 <DesiredCollators<T>>::put(c + 2);235236 register_validators::<T>(c);237 register_candidates::<T>(c);238239 let caller: T::AccountId = whitelisted_caller();240 let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();241 T::Currency::make_free_balance_be(&caller, bond.clone());242243 let origin = RawOrigin::Signed(caller.clone());244245 <session::Pallet<T>>::set_keys(246 origin.clone().into(),247 keys::<T>(c + 1),248 Vec::new()249 ).unwrap();250251 assert_ok!(252 <CollatorSelection<T>>::get_license(origin.clone().into())253 );254 }: _(origin)255 verify {256 assert_last_event::<T>(Event::CandidateAdded{account_id: caller}.into());257 }258259 // worst case is the last candidate leaving.260 offboard {261 let c in 1 .. T::MaxCollators::get();262 <LicenseBond<T>>::put(T::Currency::minimum_balance());263 <DesiredCollators<T>>::put(c + 2);264265 register_validators::<T>(c);266 register_candidates::<T>(c);267268 let leaving = <Candidates<T>>::get().last().unwrap().clone();269 whitelist!(leaving);270 }: _(RawOrigin::Signed(leaving.clone()))271 verify {272 assert_last_event::<T>(Event::CandidateRemoved{account_id: leaving}.into());273 }274275 // worst case is the last candidate leaving.276 release_license {277 let c in 1 .. T::MaxCollators::get();278 let bond = T::Currency::minimum_balance();279 <LicenseBond<T>>::put(bond);280 <DesiredCollators<T>>::put(c);281282 register_validators::<T>(c);283 register_candidates::<T>(c);284285 let leaving = <Candidates<T>>::get().last().unwrap().clone();286 whitelist!(leaving);287 }: _(RawOrigin::Signed(leaving.clone()))288 verify {289 assert_last_event::<T>(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into());290 }291292 // worst case is the last candidate leaving.293 force_release_license {294 let c in 1 .. T::MaxCollators::get();295 let bond = T::Currency::minimum_balance();296 <LicenseBond<T>>::put(bond);297 <DesiredCollators<T>>::put(c);298299 register_validators::<T>(c);300 register_candidates::<T>(c);301302 let leaving = <Candidates<T>>::get().last().unwrap().clone();303 whitelist!(leaving);304 let origin = T::UpdateOrigin::successful_origin();305 }: {306 assert_ok!(307 <CollatorSelection<T>>::force_release_license(origin, leaving.clone())308 );309 }310 verify {311 assert_last_event::<T>(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into());312 }313314 // worst case is paying a non-existing candidate account.315 note_author {316 <LicenseBond<T>>::put(T::Currency::minimum_balance());317 T::Currency::make_free_balance_be(318 &<CollatorSelection<T>>::account_id(),319 T::Currency::minimum_balance() * 4u32.into(),320 );321 let author = account("author", 0, SEED);322 let new_block: T::BlockNumber = 10u32.into();323324 frame_system::Pallet::<T>::set_block_number(new_block);325 assert!(T::Currency::free_balance(&author) == 0u32.into());326 }: {327 <CollatorSelection<T> as EventHandler<_, _>>::note_author(author.clone())328 } verify {329 assert!(T::Currency::free_balance(&author) > 0u32.into());330 assert_eq!(frame_system::Pallet::<T>::block_number(), new_block);331 }332333 // worst case for new session.334 new_session {335 let r in 1 .. T::MaxCollators::get();336 let c in 1 .. T::MaxCollators::get();337338 <LicenseBond<T>>::put(T::Currency::minimum_balance());339 <DesiredCollators<T>>::put(c);340 frame_system::Pallet::<T>::set_block_number(0u32.into());341342 register_validators::<T>(c);343 register_candidates::<T>(c);344345 let new_block: T::BlockNumber = 1800u32.into();346 let zero_block: T::BlockNumber = 0u32.into();347 let candidates = <Candidates<T>>::get();348349 let non_removals = c.saturating_sub(r);350351 for i in 0..c {352 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), zero_block);353 }354355 if non_removals > 0 {356 for i in 0..non_removals {357 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);358 }359 } else {360 for i in 0..c {361 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);362 }363 }364365 let pre_length = <Candidates<T>>::get().len();366367 frame_system::Pallet::<T>::set_block_number(new_block);368369 assert!(<Candidates<T>>::get().len() == c as usize);370 }: {371 <CollatorSelection<T> as SessionManager<_>>::new_session(0)372 } verify {373 if c > r {374 assert!(<Candidates<T>>::get().len() < pre_length);375 } else {376 assert!(<Candidates<T>>::get().len() == pre_length);377 }378 }379}380381impl_benchmark_test_suite!(382 CollatorSelection,383 crate::mock::new_test_ext(),384 crate::mock::Test,385);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.3233//! Benchmarking setup for pallet-collator-selection3435use super::*;3637#[allow(unused)]38use crate::Pallet as CollatorSelection;39use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};40use frame_support::{41 assert_ok,42 codec::Decode,43 traits::{Currency, EnsureOrigin, Get},44};45use frame_system::{EventRecord, RawOrigin};46use pallet_authorship::EventHandler;47use pallet_session::{self as session, SessionManager};48use pallet_configuration::{49 self as configuration, BalanceOf,50 CollatorSelectionDesiredCollatorsOverride as DesiredCollators,51 CollatorSelectionLicenseBondOverride as LicenseBond,52};53use sp_std::prelude::*;5455const SEED: u32 = 0;5657// TODO: remove if this is given in substrate commit.58macro_rules! whitelist {59 ($acc:ident) => {60 frame_benchmarking::benchmarking::add_to_whitelist(61 frame_system::Account::<T>::hashed_key_for(&$acc).into(),62 );63 };64}6566fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {67 let events = frame_system::Pallet::<T>::events();68 let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();69 // compare to the last event record70 let EventRecord { event, .. } = &events[events.len() - 1];71 assert_eq!(event, &system_event);72}7374fn create_funded_user<T: Config>(75 string: &'static str,76 n: u32,77 balance_factor: u32,78) -> T::AccountId {79 let user = account(string, n, SEED);80 let balance = T::Currency::minimum_balance() * balance_factor.into();81 let _ = T::Currency::make_free_balance_be(&user, balance);82 user83}8485fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {86 use rand::{RngCore, SeedableRng};8788 let keys = {89 let mut keys = [0u8; 128];9091 if c > 0 {92 let mut rng = rand::rngs::StdRng::seed_from_u64(c as u64);93 rng.fill_bytes(&mut keys);94 }9596 keys97 };9899 Decode::decode(&mut &keys[..]).unwrap()100}101102fn validator<T: Config + session::Config>(c: u32) -> (T::AccountId, <T as session::Config>::Keys) {103 (create_funded_user::<T>("candidate", c, 1000), keys::<T>(c))104}105106fn register_validators<T: Config + session::Config>(count: u32) -> Vec<T::AccountId> {107 let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();108109 for (who, keys) in validators.clone() {110 <session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap();111 }112113 validators.into_iter().map(|(who, _)| who).collect()114}115116fn register_invulnerables<T: Config + configuration::Config>(count: u32) {117 let candidates = (0..count)118 .map(|c| account("candidate", c, SEED))119 .collect::<Vec<_>>();120121 for who in candidates {122 <CollatorSelection<T>>::add_invulnerable(T::UpdateOrigin::successful_origin(), who)123 .unwrap();124 }125}126127fn register_candidates<T: Config + configuration::Config>(count: u32) {128 let candidates = (0..count)129 .map(|c| account("candidate", c, SEED))130 .collect::<Vec<_>>();131 assert!(132 <LicenseBond<T>>::get() > 0u32.into(),133 "Bond cannot be zero!"134 );135136 for who in candidates {137 T::Currency::make_free_balance_be(&who, <LicenseBond<T>>::get() * 2u32.into());138 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();139 <CollatorSelection<T>>::onboard(RawOrigin::Signed(who).into()).unwrap();140 }141}142143fn get_licenses<T: Config + configuration::Config>(count: u32) {144 let candidates = (0..count)145 .map(|c| account("candidate", c, SEED))146 .collect::<Vec<_>>();147 assert!(148 <LicenseBond<T>>::get() > 0u32.into(),149 "Bond cannot be zero!"150 );151152 for who in candidates {153 T::Currency::make_free_balance_be(&who, <LicenseBond<T>>::get() * 2u32.into());154 <CollatorSelection<T>>::get_license(RawOrigin::Signed(who.clone()).into()).unwrap();155 }156}157158benchmarks! {159 where_clause { where T: pallet_authorship::Config + session::Config + configuration::Config }160161 // todo:collator this and all the following do not work for some reason, going all the way up to 10 in length162 // Both invulnerables and candidates count together against MaxCollators.163 // Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2)164 add_invulnerable {165 let b in 1 .. T::MaxCollators::get() - 3;166 register_validators::<T>(b);167 register_invulnerables::<T>(b);168169 // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);170171 let new_invulnerable: T::AccountId = whitelisted_caller();172 let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();173 T::Currency::make_free_balance_be(&new_invulnerable, bond.clone());174175 <session::Pallet<T>>::set_keys(176 RawOrigin::Signed(new_invulnerable.clone()).into(),177 keys::<T>(b + 1),178 Vec::new()179 ).unwrap();180181 let root_origin = T::UpdateOrigin::successful_origin();182 }: {183 assert_ok!(184 <CollatorSelection<T>>::add_invulnerable(root_origin, new_invulnerable.clone())185 );186 }187 verify {188 assert_last_event::<T>(Event::InvulnerableAdded{invulnerable: new_invulnerable}.into());189 }190191 remove_invulnerable {192 let b in 1 .. T::MaxCollators::get();193 register_validators::<T>(b);194 register_invulnerables::<T>(b);195196 let root_origin = T::UpdateOrigin::successful_origin();197 let leaving = <Invulnerables<T>>::get().last().unwrap().clone();198 whitelist!(leaving);199 }: {200 assert_ok!(201 <CollatorSelection<T>>::remove_invulnerable(root_origin, leaving.clone())202 );203 }204 verify {205 assert_last_event::<T>(Event::InvulnerableRemoved{invulnerable: leaving}.into());206 }207208 get_license {209 let c in 1 .. T::MaxCollators::get();210211 <LicenseBond<T>>::put(T::Currency::minimum_balance());212213 register_validators::<T>(c);214 get_licenses::<T>(c);215216 let caller: T::AccountId = whitelisted_caller();217 let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();218 T::Currency::make_free_balance_be(&caller, bond.clone());219220 <session::Pallet<T>>::set_keys(221 RawOrigin::Signed(caller.clone()).into(),222 keys::<T>(c + 1),223 Vec::new()224 ).unwrap();225226 }: _(RawOrigin::Signed(caller.clone()))227 verify {228 assert_last_event::<T>(Event::LicenseObtained{account_id: caller, deposit: bond / 2u32.into()}.into());229 }230231 // worst case is when we have all the max-candidate slots filled except one, and we fill that232 // one.233 onboard {234 let c in 1 .. 5;235236 <LicenseBond<T>>::put(T::Currency::minimum_balance());237 <DesiredCollators<T>>::put(c + 2);238239 register_validators::<T>(c);240 register_candidates::<T>(c);241242 let caller: T::AccountId = whitelisted_caller();243 let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();244 T::Currency::make_free_balance_be(&caller, bond.clone());245246 let origin = RawOrigin::Signed(caller.clone());247248 <session::Pallet<T>>::set_keys(249 origin.clone().into(),250 keys::<T>(c + 1),251 Vec::new()252 ).unwrap();253254 assert_ok!(255 <CollatorSelection<T>>::get_license(origin.clone().into())256 );257 }: _(origin)258 verify {259 assert_last_event::<T>(Event::CandidateAdded{account_id: caller}.into());260 }261262 // worst case is the last candidate leaving.263 offboard {264 let c in 1 .. T::MaxCollators::get();265 <LicenseBond<T>>::put(T::Currency::minimum_balance());266 <DesiredCollators<T>>::put(c + 2);267268 register_validators::<T>(c);269 register_candidates::<T>(c);270271 let leaving = <Candidates<T>>::get().last().unwrap().clone();272 whitelist!(leaving);273 }: _(RawOrigin::Signed(leaving.clone()))274 verify {275 assert_last_event::<T>(Event::CandidateRemoved{account_id: leaving}.into());276 }277278 // worst case is the last candidate leaving.279 release_license {280 let c in 1 .. T::MaxCollators::get();281 let bond = T::Currency::minimum_balance();282 <LicenseBond<T>>::put(bond);283 <DesiredCollators<T>>::put(c);284285 register_validators::<T>(c);286 register_candidates::<T>(c);287288 let leaving = <Candidates<T>>::get().last().unwrap().clone();289 whitelist!(leaving);290 }: _(RawOrigin::Signed(leaving.clone()))291 verify {292 assert_last_event::<T>(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into());293 }294295 // worst case is the last candidate leaving.296 force_release_license {297 let c in 1 .. T::MaxCollators::get();298 let bond = T::Currency::minimum_balance();299 <LicenseBond<T>>::put(bond);300 <DesiredCollators<T>>::put(c);301302 register_validators::<T>(c);303 register_candidates::<T>(c);304305 let leaving = <Candidates<T>>::get().last().unwrap().clone();306 whitelist!(leaving);307 let origin = T::UpdateOrigin::successful_origin();308 }: {309 assert_ok!(310 <CollatorSelection<T>>::force_release_license(origin, leaving.clone())311 );312 }313 verify {314 assert_last_event::<T>(Event::LicenseReleased{account_id: leaving, deposit_returned: bond}.into());315 }316317 // worst case is paying a non-existing candidate account.318 note_author {319 <LicenseBond<T>>::put(T::Currency::minimum_balance());320 T::Currency::make_free_balance_be(321 &<CollatorSelection<T>>::account_id(),322 T::Currency::minimum_balance() * 4u32.into(),323 );324 let author = account("author", 0, SEED);325 let new_block: T::BlockNumber = 10u32.into();326327 frame_system::Pallet::<T>::set_block_number(new_block);328 assert!(T::Currency::free_balance(&author) == 0u32.into());329 }: {330 <CollatorSelection<T> as EventHandler<_, _>>::note_author(author.clone())331 } verify {332 assert!(T::Currency::free_balance(&author) > 0u32.into());333 assert_eq!(frame_system::Pallet::<T>::block_number(), new_block);334 }335336 // worst case for new session.337 new_session {338 let r in 1 .. T::MaxCollators::get();339 let c in 1 .. T::MaxCollators::get();340341 <LicenseBond<T>>::put(T::Currency::minimum_balance());342 <DesiredCollators<T>>::put(c);343 frame_system::Pallet::<T>::set_block_number(0u32.into());344345 register_validators::<T>(c);346 register_candidates::<T>(c);347348 let new_block: T::BlockNumber = 1800u32.into();349 let zero_block: T::BlockNumber = 0u32.into();350 let candidates = <Candidates<T>>::get();351352 let non_removals = c.saturating_sub(r);353354 for i in 0..c {355 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), zero_block);356 }357358 if non_removals > 0 {359 for i in 0..non_removals {360 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);361 }362 } else {363 for i in 0..c {364 <LastAuthoredBlock<T>>::insert(candidates[i as usize].clone(), new_block);365 }366 }367368 let pre_length = <Candidates<T>>::get().len();369370 frame_system::Pallet::<T>::set_block_number(new_block);371372 assert!(<Candidates<T>>::get().len() == c as usize);373 }: {374 <CollatorSelection<T> as SessionManager<_>>::new_session(0)375 } verify {376 if c > r {377 assert!(<Candidates<T>>::get().len() < pre_length);378 } else {379 assert!(<Candidates<T>>::get().len() == pre_length);380 }381 }382}383384impl_benchmark_test_suite!(385 CollatorSelection,386 crate::mock::new_test_ext(),387 crate::mock::Test,388);pallets/collator-selection/src/mock.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/mock.rs
+++ b/pallets/collator-selection/src/mock.rs
@@ -219,13 +219,13 @@
type DefaultCollatorSelectionMaxCollators = MaxCollators;
type DefaultCollatorSelectionKickThreshold = KickThreshold;
type DefaultCollatorSelectionLicenseBond = LicenseBond;
- // the following we don't care about
+ // the following constants we don't care about
type DefaultWeightToFeeCoefficient = DefaultWeightToFeeCoefficient;
type DefaultMinGasPrice = DefaultMinGasPrice;
type MaxXcmAllowedLocations = MaxXcmAllowedLocations;
type AppPromotionDailyRate = AppPromotionDailyRate;
type DayRelayBlocks = DayRelayBlocks;
- type WeightInfo = ();
+ type WeightInfo = pallet_configuration::weights::SubstrateWeight<Self>;
}
ord_parameter_types! {