difftreelog
fix(pallet-collator-selection) benchmarking
in: master
2 files changed
Makefilediffbeforeafterboth146 make _bench PALLET=xcm OUTPUT=./runtime/common/weights/xcm.rs TEMPLATE="--template=.maintain/external-weight-template.hbs"146 make _bench PALLET=xcm OUTPUT=./runtime/common/weights/xcm.rs TEMPLATE="--template=.maintain/external-weight-template.hbs"147147148.PHONY: bench148.PHONY: bench149# Disabled: bench-scheduler, bench-collator-selection, bench-identity149# Disabled: bench-scheduler, bench-identity150bench: bench-app-promotion bench-common bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-maintenance bench-xcm150bench: bench-app-promotion bench-common bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-maintenance bench-xcm bench-collator-selection151151152.PHONY: check152.PHONY: check153check:153check:pallets/collator-selection/src/benchmarking.rsdiffbeforeafterboth77 balance_factor: u32,77 balance_factor: u32,78) -> T::AccountId {78) -> T::AccountId {79 let user = account(string, n, SEED);79 let user = account(string, n, SEED);80 let balance = T::Currency::minimum_balance() * balance_factor.into();80 let balance = balance_unit::<T>() * balance_factor.into();81 let _ = T::Currency::make_free_balance_be(&user, balance);81 let _ = T::Currency::make_free_balance_be(&user, balance);82 user82 user83}83}158 }158 }159}159}160161/// `Currency::minimum_balance` was used originally, but in unique-chain, we have162/// zero existential deposit, thus triggering zero bond assertion.163fn balance_unit<T: Config>() -> <T::Currency as Currency<T::AccountId>>::Balance {164 200u32.into()165}166167/// Our benchmarking environment already has invulnerables registered.168const INITIAL_INVULNERABLES: u32 = 2;160169161benchmarks! {170benchmarks! {162 where_clause { where T: pallet_authorship::Config + session::Config + configuration::Config }171 where_clause { where T: pallet_authorship::Config + session::Config + configuration::Config }165 // Both invulnerables and candidates count together against MaxCollators.174 // Both invulnerables and candidates count together against MaxCollators.166 // Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2)175 // Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2)167 add_invulnerable {176 add_invulnerable {168 let b in 1 .. T::MaxCollators::get() - 3;177 let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;169 register_validators::<T>(b);178 register_validators::<T>(b);170 register_invulnerables::<T>(b);179 register_invulnerables::<T>(b);171180172 // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);181 // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);173182174 let new_invulnerable: T::AccountId = whitelisted_caller();183 let new_invulnerable: T::AccountId = whitelisted_caller();175 let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();184 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();176 T::Currency::make_free_balance_be(&new_invulnerable, bond.clone());185 T::Currency::make_free_balance_be(&new_invulnerable, bond.clone());177186178 <session::Pallet<T>>::set_keys(187 <session::Pallet<T>>::set_keys(192 }201 }193202194 remove_invulnerable {203 remove_invulnerable {195 let b in 1 .. T::MaxCollators::get();204 let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;196 register_validators::<T>(b);205 register_validators::<T>(b);197 register_invulnerables::<T>(b);206 register_invulnerables::<T>(b);198207209 }218 }210219211 get_license {220 get_license {212 let c in 1 .. T::MaxCollators::get();221 let c in 1 .. T::MaxCollators::get() - 1;213222214 <LicenseBond<T>>::put(T::Currency::minimum_balance());223 <LicenseBond<T>>::put(balance_unit::<T>());215224216 register_validators::<T>(c);225 register_validators::<T>(c);217 get_licenses::<T>(c);226 get_licenses::<T>(c);218227219 let caller: T::AccountId = whitelisted_caller();228 let caller: T::AccountId = whitelisted_caller();220 let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();229 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();221 T::Currency::make_free_balance_be(&caller, bond.clone());230 T::Currency::make_free_balance_be(&caller, bond.clone());222231223 <session::Pallet<T>>::set_keys(232 <session::Pallet<T>>::set_keys(234 // worst case is when we have all the max-candidate slots filled except one, and we fill that243 // worst case is when we have all the max-candidate slots filled except one, and we fill that235 // one.244 // one.236 onboard {245 onboard {237 let c in 1 .. 5;246 let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;238247239 <LicenseBond<T>>::put(T::Currency::minimum_balance());248 <LicenseBond<T>>::put(balance_unit::<T>());240 <DesiredCollators<T>>::put(c + 2);249 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES + 1);241250242 register_validators::<T>(c);251 register_validators::<T>(c);243 register_candidates::<T>(c);252 register_candidates::<T>(c);244253245 let caller: T::AccountId = whitelisted_caller();254 let caller: T::AccountId = whitelisted_caller();246 let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();255 let bond: BalanceOf<T> = balance_unit::<T>() * 2u32.into();247 T::Currency::make_free_balance_be(&caller, bond.clone());256 T::Currency::make_free_balance_be(&caller, bond.clone());248257249 let origin = RawOrigin::Signed(caller.clone());258 let origin = RawOrigin::Signed(caller.clone());265 // worst case is the last candidate leaving.274 // worst case is the last candidate leaving.266 offboard {275 offboard {267 let c in 1 .. T::MaxCollators::get();276 let c in 1 .. T::MaxCollators::get();268 <LicenseBond<T>>::put(T::Currency::minimum_balance());277 <LicenseBond<T>>::put(balance_unit::<T>());269 <DesiredCollators<T>>::put(c + 2);278 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES);270279271 register_validators::<T>(c);280 register_validators::<T>(c);272 register_candidates::<T>(c);281 register_candidates::<T>(c);281 // worst case is the last candidate leaving.290 // worst case is the last candidate leaving.282 release_license {291 release_license {283 let c in 1 .. T::MaxCollators::get();292 let c in 1 .. T::MaxCollators::get();284 let bond = T::Currency::minimum_balance();293 let bond = balance_unit::<T>();285 <LicenseBond<T>>::put(bond);294 <LicenseBond<T>>::put(bond);286 <DesiredCollators<T>>::put(c);295 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES);287296288 register_validators::<T>(c);297 register_validators::<T>(c);289 register_candidates::<T>(c);298 register_candidates::<T>(c);298 // worst case is the last candidate leaving.307 // worst case is the last candidate leaving.299 force_release_license {308 force_release_license {300 let c in 1 .. T::MaxCollators::get();309 let c in 1 .. T::MaxCollators::get();301 let bond = T::Currency::minimum_balance();310 let bond = balance_unit::<T>();302 <LicenseBond<T>>::put(bond);311 <LicenseBond<T>>::put(bond);303 <DesiredCollators<T>>::put(c);312 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES);304313305 register_validators::<T>(c);314 register_validators::<T>(c);306 register_candidates::<T>(c);315 register_candidates::<T>(c);319328320 // worst case is paying a non-existing candidate account.329 // worst case is paying a non-existing candidate account.321 note_author {330 note_author {322 <LicenseBond<T>>::put(T::Currency::minimum_balance());331 <LicenseBond<T>>::put(balance_unit::<T>());323 T::Currency::make_free_balance_be(332 T::Currency::make_free_balance_be(324 &<CollatorSelection<T>>::account_id(),333 &<CollatorSelection<T>>::account_id(),325 T::Currency::minimum_balance() * 4u32.into(),334 balance_unit::<T>() * 4u32.into(),326 );335 );327 let author = account("author", 0, SEED);336 let author = account("author", 0, SEED);328 let new_block: T::BlockNumber = 10u32.into();337 let new_block: T::BlockNumber = 10u32.into();341 let r in 1 .. T::MaxCollators::get();350 let r in 1 .. T::MaxCollators::get();342 let c in 1 .. T::MaxCollators::get();351 let c in 1 .. T::MaxCollators::get();343352344 <LicenseBond<T>>::put(T::Currency::minimum_balance());353 <LicenseBond<T>>::put(balance_unit::<T>());345 <DesiredCollators<T>>::put(c);354 <DesiredCollators<T>>::put(c + INITIAL_INVULNERABLES);346 frame_system::Pallet::<T>::set_block_number(0u32.into());355 frame_system::Pallet::<T>::set_block_number(0u32.into());347356348 register_validators::<T>(c);357 register_validators::<T>(c);