From 30011e53c39d4414362070db668ea9fae50701a3 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 20 Apr 2023 16:18:26 +0000 Subject: [PATCH] fix(pallet-collator-selection): benchmarking --- --- 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: --- a/pallets/collator-selection/src/benchmarking.rs +++ b/pallets/collator-selection/src/benchmarking.rs @@ -77,7 +77,7 @@ balance_factor: u32, ) -> T::AccountId { let user = account(string, n, SEED); - let balance = T::Currency::minimum_balance() * balance_factor.into(); + let balance = balance_unit::() * balance_factor.into(); let _ = T::Currency::make_free_balance_be(&user, balance); user } @@ -158,6 +158,15 @@ } } +/// `Currency::minimum_balance` was used originally, but in unique-chain, we have +/// zero existential deposit, thus triggering zero bond assertion. +fn balance_unit() -> >::Balance { + 200u32.into() +} + +/// Our benchmarking environment already has invulnerables registered. +const INITIAL_INVULNERABLES: u32 = 2; + benchmarks! { where_clause { where T: pallet_authorship::Config + session::Config + configuration::Config } @@ -165,14 +174,14 @@ // Both invulnerables and candidates count together against MaxCollators. // Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2) add_invulnerable { - let b in 1 .. T::MaxCollators::get() - 3; + let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1; register_validators::(b); register_invulnerables::(b); // log::info!("{} {}", >::get().len(), b); let new_invulnerable: T::AccountId = whitelisted_caller(); - let bond: BalanceOf = T::Currency::minimum_balance() * 2u32.into(); + let bond: BalanceOf = balance_unit::() * 2u32.into(); T::Currency::make_free_balance_be(&new_invulnerable, bond.clone()); >::set_keys( @@ -192,7 +201,7 @@ } remove_invulnerable { - let b in 1 .. T::MaxCollators::get(); + let b in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1; register_validators::(b); register_invulnerables::(b); @@ -209,15 +218,15 @@ } get_license { - let c in 1 .. T::MaxCollators::get(); + let c in 1 .. T::MaxCollators::get() - 1; - >::put(T::Currency::minimum_balance()); + >::put(balance_unit::()); register_validators::(c); get_licenses::(c); let caller: T::AccountId = whitelisted_caller(); - let bond: BalanceOf = T::Currency::minimum_balance() * 2u32.into(); + let bond: BalanceOf = balance_unit::() * 2u32.into(); T::Currency::make_free_balance_be(&caller, bond.clone()); >::set_keys( @@ -234,16 +243,16 @@ // worst case is when we have all the max-candidate slots filled except one, and we fill that // one. onboard { - let c in 1 .. 5; + let c in 1 .. T::MaxCollators::get() - INITIAL_INVULNERABLES - 1; - >::put(T::Currency::minimum_balance()); - >::put(c + 2); + >::put(balance_unit::()); + >::put(c + INITIAL_INVULNERABLES + 1); register_validators::(c); register_candidates::(c); let caller: T::AccountId = whitelisted_caller(); - let bond: BalanceOf = T::Currency::minimum_balance() * 2u32.into(); + let bond: BalanceOf = balance_unit::() * 2u32.into(); T::Currency::make_free_balance_be(&caller, bond.clone()); let origin = RawOrigin::Signed(caller.clone()); @@ -265,8 +274,8 @@ // worst case is the last candidate leaving. offboard { let c in 1 .. T::MaxCollators::get(); - >::put(T::Currency::minimum_balance()); - >::put(c + 2); + >::put(balance_unit::()); + >::put(c + INITIAL_INVULNERABLES); register_validators::(c); register_candidates::(c); @@ -281,9 +290,9 @@ // worst case is the last candidate leaving. release_license { let c in 1 .. T::MaxCollators::get(); - let bond = T::Currency::minimum_balance(); + let bond = balance_unit::(); >::put(bond); - >::put(c); + >::put(c + INITIAL_INVULNERABLES); register_validators::(c); register_candidates::(c); @@ -298,9 +307,9 @@ // worst case is the last candidate leaving. force_release_license { let c in 1 .. T::MaxCollators::get(); - let bond = T::Currency::minimum_balance(); + let bond = balance_unit::(); >::put(bond); - >::put(c); + >::put(c + INITIAL_INVULNERABLES); register_validators::(c); register_candidates::(c); @@ -319,10 +328,10 @@ // worst case is paying a non-existing candidate account. note_author { - >::put(T::Currency::minimum_balance()); + >::put(balance_unit::()); T::Currency::make_free_balance_be( &>::account_id(), - T::Currency::minimum_balance() * 4u32.into(), + balance_unit::() * 4u32.into(), ); let author = account("author", 0, SEED); let new_block: T::BlockNumber = 10u32.into(); @@ -341,8 +350,8 @@ let r in 1 .. T::MaxCollators::get(); let c in 1 .. T::MaxCollators::get(); - >::put(T::Currency::minimum_balance()); - >::put(c); + >::put(balance_unit::()); + >::put(c + INITIAL_INVULNERABLES); frame_system::Pallet::::set_block_number(0u32.into()); register_validators::(c); -- gitstuff