git.delta.rocks / unique-network / refs/commits / 30011e53c39d

difftreelog

fix(pallet-collator-selection) benchmarking

Yaroslav Bolyukin2023-04-20parent: #8613e5e.patch.diff
in: master

2 files changed

modifiedMakefilediffbeforeafterboth
--- a/Makefile
+++ b/Makefile
@@ -146,8 +146,8 @@
 	make _bench PALLET=xcm OUTPUT=./runtime/common/weights/xcm.rs TEMPLATE="--template=.maintain/external-weight-template.hbs"
 
 .PHONY: bench
-# Disabled: bench-scheduler, bench-collator-selection, bench-identity
-bench: 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
+# Disabled: bench-scheduler, bench-identity
+bench: 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-selection
 
 .PHONY: check
 check:
modifiedpallets/collator-selection/src/benchmarking.rsdiffbeforeafterboth
77 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 user
83}83}
158 }158 }
159}159}
160
161/// `Currency::minimum_balance` was used originally, but in unique-chain, we have
162/// zero existential deposit, thus triggering zero bond assertion.
163fn balance_unit<T: Config>() -> <T::Currency as Currency<T::AccountId>>::Balance {
164 200u32.into()
165}
166
167/// Our benchmarking environment already has invulnerables registered.
168const INITIAL_INVULNERABLES: u32 = 2;
160169
161benchmarks! {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);
171180
172 // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);181 // log::info!("{} {}", <Invulnerables<T>>::get().len(), b);
173182
174 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());
177186
178 <session::Pallet<T>>::set_keys(187 <session::Pallet<T>>::set_keys(
192 }201 }
193202
194 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);
198207
209 }218 }
210219
211 get_license {220 get_license {
212 let c in 1 .. T::MaxCollators::get();221 let c in 1 .. T::MaxCollators::get() - 1;
213222
214 <LicenseBond<T>>::put(T::Currency::minimum_balance());223 <LicenseBond<T>>::put(balance_unit::<T>());
215224
216 register_validators::<T>(c);225 register_validators::<T>(c);
217 get_licenses::<T>(c);226 get_licenses::<T>(c);
218227
219 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());
222231
223 <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 that
235 // one.244 // one.
236 onboard {245 onboard {
237 let c in 1 .. 5;246 let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1;
238247
239 <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);
241250
242 register_validators::<T>(c);251 register_validators::<T>(c);
243 register_candidates::<T>(c);252 register_candidates::<T>(c);
244253
245 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());
248257
249 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);
270279
271 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);
287296
288 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);
304313
305 register_validators::<T>(c);314 register_validators::<T>(c);
306 register_candidates::<T>(c);315 register_candidates::<T>(c);
319328
320 // 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();
343352
344 <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());
347356
348 register_validators::<T>(c);357 register_validators::<T>(c);