From 6abd49ae9ee10dbe7db021ee66b36b7938e8304d Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 03:36:23 +0200 Subject: [PATCH 01/13] update benchmarks --- frame/identity/src/benchmarking.rs | 68 ++--- frame/identity/src/lib.rs | 458 +--------------------------- frame/identity/src/tests.rs | 471 +++++++++++++++++++++++++++++ 3 files changed, 505 insertions(+), 492 deletions(-) create mode 100644 frame/identity/src/tests.rs diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 8b0cb0c27cf0e..4be04dc1dbef9 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -22,29 +22,25 @@ use super::*; use frame_system::RawOrigin; -use sp_io::hashing::blake2_256; -use frame_benchmarking::benchmarks; +use frame_benchmarking::{benchmarks, account, whitelisted_caller}; use sp_runtime::traits::Bounded; use crate::Module as Identity; -// Support Functions -fn account(name: &'static str, index: u32) -> T::AccountId { - let entropy = (name, index).using_encoded(blake2_256); - T::AccountId::decode(&mut &entropy[..]).unwrap_or_default() -} +const SEED: u32 = 0; // Adds `r` registrars to the Identity Pallet. These registrars will have set fees and fields. fn add_registrars(r: u32) -> Result<(), &'static str> { for i in 0..r { - let _ = T::Currency::make_free_balance_be(&account::("registrar", i), BalanceOf::::max_value()); - Identity::::add_registrar(RawOrigin::Root.into(), account::("registrar", i))?; - Identity::::set_fee(RawOrigin::Signed(account::("registrar", i)).into(), i.into(), 10.into())?; + let registrar: T::AccountId = account("registrar", i, SEED); + let _ = T::Currency::make_free_balance_be(®istrar, BalanceOf::::max_value()); + Identity::::add_registrar(RawOrigin::Root.into(), registrar.clone())?; + Identity::::set_fee(RawOrigin::Signed(registrar.clone()).into(), i.into(), 10.into())?; let fields = IdentityFields( IdentityField::Display | IdentityField::Legal | IdentityField::Web | IdentityField::Riot | IdentityField::Email | IdentityField::PgpFingerprint | IdentityField::Image | IdentityField::Twitter ); - Identity::::set_fields(RawOrigin::Signed(account::("registrar", i)).into(), i.into(), fields)?; + Identity::::set_fields(RawOrigin::Signed(registrar.clone()).into(), i.into(), fields)?; } assert_eq!(Registrars::::get().len(), r as usize); @@ -59,7 +55,7 @@ fn create_sub_accounts(who: &T::AccountId, s: u32) -> Result("sub", i); + let sub_account = account("sub", i, SEED); subs.push((sub_account, data.clone())); } @@ -110,13 +106,13 @@ benchmarks! { let p in 1 .. T::MaxSubAccounts::get() => (); let s in 1 .. T::MaxSubAccounts::get() => { // Give them s many sub accounts - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let _ = add_sub_accounts::(&caller, s)?; }; let x in 1 .. T::MaxAdditionalFields::get() => { // Create their main identity with x additional fields let info = create_identity_info::(x); - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); Identity::::set_identity(caller_origin, info)?; }; @@ -124,7 +120,7 @@ benchmarks! { add_registrar { let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; - }: _(RawOrigin::Root, account::("registrar", r + 1)) + }: _(RawOrigin::Root, account("registrar", r + 1, SEED)) set_identity { let r in ...; @@ -133,7 +129,7 @@ benchmarks! { let x in _ .. _ => (); let caller = { // The target user - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let caller_lookup: ::Source = T::Lookup::unlookup(caller.clone()); let caller_origin: ::Origin = RawOrigin::Signed(caller.clone()).into(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -146,7 +142,7 @@ benchmarks! { for i in 0..r { Identity::::request_judgement(caller_origin.clone(), i, 10.into())?; Identity::::provide_judgement( - RawOrigin::Signed(account::("registrar", i)).into(), + RawOrigin::Signed(account("registrar", i, SEED)).into(), i, caller_lookup.clone(), Judgement::Reasonable @@ -160,7 +156,7 @@ benchmarks! { ) set_subs { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); // Give them p many previous sub accounts. let p in 1 .. T::MaxSubAccounts::get() => { @@ -173,18 +169,18 @@ benchmarks! { }: _(RawOrigin::Signed(caller), subs) add_sub { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); // Give them p many previous sub accounts. let p in 1 .. T::MaxSubAccounts::get() - 1 => { let _ = add_sub_accounts::(&caller, p)?; }; - let sub = account::("new_sub", 0); + let sub = account("new_sub", 0, SEED); let data = Data::Raw(vec![0; 32]); }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) rename_sub { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let p in 1 .. T::MaxSubAccounts::get(); @@ -195,7 +191,7 @@ benchmarks! { }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) remove_sub { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); // Give them p many previous sub accounts. let p in 1 .. T::MaxSubAccounts::get(); @@ -203,8 +199,8 @@ benchmarks! { }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub)) quit_sub { - let caller = account::("caller", 0); - let sup = account::("super", 0); + let caller: T::AccountId = whitelisted_caller(); + let sup = account("super", 0, SEED); // Give them p many previous sub accounts. let p in 1 .. T::MaxSubAccounts::get() - 1 => { @@ -215,7 +211,7 @@ benchmarks! { }: _(RawOrigin::Signed(caller)) clear_identity { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); let caller_lookup = ::unlookup(caller.clone()); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -228,7 +224,7 @@ benchmarks! { for i in 0..r { Identity::::request_judgement(caller_origin.clone(), i, 10.into())?; Identity::::provide_judgement( - RawOrigin::Signed(account::("registrar", i)).into(), + RawOrigin::Signed(account("registrar", i, SEED)).into(), i, caller_lookup.clone(), Judgement::Reasonable @@ -237,7 +233,7 @@ benchmarks! { }: _(RawOrigin::Signed(caller)) request_judgement { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); let r in ...; @@ -245,7 +241,7 @@ benchmarks! { }: _(RawOrigin::Signed(caller), r - 1, 10.into()) cancel_request { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -256,7 +252,7 @@ benchmarks! { }: _(RawOrigin::Signed(caller), r - 1) set_fee { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; @@ -264,16 +260,16 @@ benchmarks! { }: _(RawOrigin::Signed(caller), r, 10.into()) set_account_id { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; Identity::::add_registrar(RawOrigin::Root.into(), caller.clone())?; - }: _(RawOrigin::Signed(caller), r, account::("new", 0)) + }: _(RawOrigin::Signed(caller), r, account("new", 0, SEED)) set_fields { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; @@ -287,12 +283,12 @@ benchmarks! { provide_judgement { // The user - let user = account::("user", r); + let user: T::AccountId = account("user", r, SEED); let user_origin = ::Origin::from(RawOrigin::Signed(user.clone())); let user_lookup = ::unlookup(user.clone()); let _ = T::Currency::make_free_balance_be(&user, BalanceOf::::max_value()); - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; @@ -307,7 +303,7 @@ benchmarks! { }: _(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable) kill_identity { - let caller = account::("caller", 0); + let caller: T::AccountId = whitelisted_caller(); let caller_origin: ::Origin = RawOrigin::Signed(caller.clone()).into(); let caller_lookup: ::Source = T::Lookup::unlookup(caller.clone()); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -320,7 +316,7 @@ benchmarks! { for i in 0..r { Identity::::request_judgement(caller_origin.clone(), i, 10.into())?; Identity::::provide_judgement( - RawOrigin::Signed(account::("registrar", i)).into(), + RawOrigin::Signed(account("registrar", i, SEED)).into(), i, caller_lookup.clone(), Judgement::Reasonable diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 65f1597622c56..73a2fa4a6a35f 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -86,6 +86,8 @@ use frame_support::{ }; use frame_system::ensure_signed; +#[cfg(test)] +mod tests; mod benchmarking; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -1328,459 +1330,3 @@ impl Module { .collect() } } - -#[cfg(test)] -mod tests { - use super::*; - - use sp_runtime::traits::BadOrigin; - use frame_support::{ - assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight, - ord_parameter_types, - }; - use sp_core::H256; - use frame_system::{EnsureSignedBy, EnsureOneOf, EnsureRoot}; - use sp_runtime::{ - Perbill, testing::Header, traits::{BlakeTwo256, IdentityLookup}, - }; - - impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} - } - - #[derive(Clone, Eq, PartialEq)] - pub struct Test; - parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const MaximumBlockWeight: Weight = 1024; - pub const MaximumBlockLength: u32 = 2 * 1024; - pub const AvailableBlockRatio: Perbill = Perbill::one(); - } - impl frame_system::Trait for Test { - type BaseCallFilter = (); - type Origin = Origin; - type Index = u64; - type BlockNumber = u64; - type Hash = H256; - type Call = (); - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; - type Event = (); - type BlockHashCount = BlockHashCount; - type MaximumBlockWeight = MaximumBlockWeight; - type DbWeight = (); - type BlockExecutionWeight = (); - type ExtrinsicBaseWeight = (); - type MaximumExtrinsicWeight = MaximumBlockWeight; - type MaximumBlockLength = MaximumBlockLength; - type AvailableBlockRatio = AvailableBlockRatio; - type Version = (); - type ModuleToIndex = (); - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - } - parameter_types! { - pub const ExistentialDeposit: u64 = 1; - } - impl pallet_balances::Trait for Test { - type Balance = u64; - type Event = (); - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - } - parameter_types! { - pub const BasicDeposit: u64 = 10; - pub const FieldDeposit: u64 = 10; - pub const SubAccountDeposit: u64 = 10; - pub const MaxSubAccounts: u32 = 2; - pub const MaxAdditionalFields: u32 = 2; - pub const MaxRegistrars: u32 = 20; - } - ord_parameter_types! { - pub const One: u64 = 1; - pub const Two: u64 = 2; - } - type EnsureOneOrRoot = EnsureOneOf< - u64, - EnsureRoot, - EnsureSignedBy - >; - type EnsureTwoOrRoot = EnsureOneOf< - u64, - EnsureRoot, - EnsureSignedBy - >; - impl Trait for Test { - type Event = (); - type Currency = Balances; - type Slashed = (); - type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; - type SubAccountDeposit = SubAccountDeposit; - type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; - type MaxRegistrars = MaxRegistrars; - type RegistrarOrigin = EnsureOneOrRoot; - type ForceOrigin = EnsureTwoOrRoot; - type WeightInfo = (); - } - type System = frame_system::Module; - type Balances = pallet_balances::Module; - type Identity = Module; - - pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![ - (1, 10), - (2, 10), - (3, 10), - (10, 100), - (20, 100), - (30, 100), - ], - }.assimilate_storage(&mut t).unwrap(); - t.into() - } - - fn ten() -> IdentityInfo { - IdentityInfo { - display: Data::Raw(b"ten".to_vec()), - legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec()), - .. Default::default() - } - } - - fn twenty() -> IdentityInfo { - IdentityInfo { - display: Data::Raw(b"twenty".to_vec()), - legal: Data::Raw(b"The Right Ordinal Twenty, Esq.".to_vec()), - .. Default::default() - } - } - - #[test] - fn editing_subaccounts_should_work() { - new_test_ext().execute_with(|| { - let data = |x| Data::Raw(vec![x; 1]); - - assert_noop!(Identity::add_sub(Origin::signed(10), 20, data(1)), Error::::NoIdentity); - - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - - // first sub account - assert_ok!(Identity::add_sub(Origin::signed(10), 1, data(1))); - assert_eq!(SuperOf::::get(1), Some((10, data(1)))); - assert_eq!(Balances::free_balance(10), 80); - - // second sub account - assert_ok!(Identity::add_sub(Origin::signed(10), 2, data(2))); - assert_eq!(SuperOf::::get(1), Some((10, data(1)))); - assert_eq!(SuperOf::::get(2), Some((10, data(2)))); - assert_eq!(Balances::free_balance(10), 70); - - // third sub account is too many - assert_noop!(Identity::add_sub(Origin::signed(10), 3, data(3)), Error::::TooManySubAccounts); - - // rename first sub account - assert_ok!(Identity::rename_sub(Origin::signed(10), 1, data(11))); - assert_eq!(SuperOf::::get(1), Some((10, data(11)))); - assert_eq!(SuperOf::::get(2), Some((10, data(2)))); - assert_eq!(Balances::free_balance(10), 70); - - // remove first sub account - assert_ok!(Identity::remove_sub(Origin::signed(10), 1)); - assert_eq!(SuperOf::::get(1), None); - assert_eq!(SuperOf::::get(2), Some((10, data(2)))); - assert_eq!(Balances::free_balance(10), 80); - - // add third sub account - assert_ok!(Identity::add_sub(Origin::signed(10), 3, data(3))); - assert_eq!(SuperOf::::get(1), None); - assert_eq!(SuperOf::::get(2), Some((10, data(2)))); - assert_eq!(SuperOf::::get(3), Some((10, data(3)))); - assert_eq!(Balances::free_balance(10), 70); - }); - } - - #[test] - fn resolving_subaccount_ownership_works() { - new_test_ext().execute_with(|| { - let data = |x| Data::Raw(vec![x; 1]); - - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_ok!(Identity::set_identity(Origin::signed(20), twenty())); - - // 10 claims 1 as a subaccount - assert_ok!(Identity::add_sub(Origin::signed(10), 1, data(1))); - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(10), 80); - assert_eq!(Balances::reserved_balance(10), 20); - // 20 cannot claim 1 now - assert_noop!(Identity::add_sub(Origin::signed(20), 1, data(1)), Error::::AlreadyClaimed); - // 1 wants to be with 20 so it quits from 10 - assert_ok!(Identity::quit_sub(Origin::signed(1))); - // 1 gets the 10 that 10 paid. - assert_eq!(Balances::free_balance(1), 20); - assert_eq!(Balances::free_balance(10), 80); - assert_eq!(Balances::reserved_balance(10), 10); - // 20 can claim 1 now - assert_ok!(Identity::add_sub(Origin::signed(20), 1, data(1))); - }); - } - - #[test] - fn trailing_zeros_decodes_into_default_data() { - let encoded = Data::Raw(b"Hello".to_vec()).encode(); - assert!(<(Data, Data)>::decode(&mut &encoded[..]).is_err()); - let input = &mut &encoded[..]; - let (a, b) = <(Data, Data)>::decode(&mut AppendZerosInput::new(input)).unwrap(); - assert_eq!(a, Data::Raw(b"Hello".to_vec())); - assert_eq!(b, Data::None); - } - - #[test] - fn adding_registrar_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); - assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); - let fields = IdentityFields(IdentityField::Display | IdentityField::Legal); - assert_ok!(Identity::set_fields(Origin::signed(3), 0, fields)); - assert_eq!(Identity::registrars(), vec![ - Some(RegistrarInfo { account: 3, fee: 10, fields }) - ]); - }); - } - - #[test] - fn amount_of_registrars_is_limited() { - new_test_ext().execute_with(|| { - for i in 1..MaxRegistrars::get() + 1 { - assert_ok!(Identity::add_registrar(Origin::signed(1), i as u64)); - } - let last_registrar = MaxRegistrars::get() as u64 + 1; - assert_noop!( - Identity::add_registrar(Origin::signed(1), last_registrar), - Error::::TooManyRegistrars - ); - }); - } - - #[test] - fn registration_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); - assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); - let mut three_fields = ten(); - three_fields.additional.push(Default::default()); - three_fields.additional.push(Default::default()); - three_fields.additional.push(Default::default()); - assert_noop!( - Identity::set_identity(Origin::signed(10), three_fields), - Error::::TooManyFields - ); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_eq!(Identity::identity(10).unwrap().info, ten()); - assert_eq!(Balances::free_balance(10), 90); - assert_ok!(Identity::clear_identity(Origin::signed(10))); - assert_eq!(Balances::free_balance(10), 100); - assert_noop!(Identity::clear_identity(Origin::signed(10)), Error::::NotNamed); - }); - } - - #[test] - fn uninvited_judgement_should_work() { - new_test_ext().execute_with(|| { - assert_noop!( - Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable), - Error::::InvalidIndex - ); - - assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); - assert_noop!( - Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable), - Error::::InvalidTarget - ); - - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_noop!( - Identity::provide_judgement(Origin::signed(10), 0, 10, Judgement::Reasonable), - Error::::InvalidIndex - ); - assert_noop!( - Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::FeePaid(1)), - Error::::InvalidJudgement - ); - - assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable)); - assert_eq!(Identity::identity(10).unwrap().judgements, vec![(0, Judgement::Reasonable)]); - }); - } - - #[test] - fn clearing_judgement_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable)); - assert_ok!(Identity::clear_identity(Origin::signed(10))); - assert_eq!(Identity::identity(10), None); - }); - } - - #[test] - fn killing_slashing_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_noop!(Identity::kill_identity(Origin::signed(1), 10), BadOrigin); - assert_ok!(Identity::kill_identity(Origin::signed(2), 10)); - assert_eq!(Identity::identity(10), None); - assert_eq!(Balances::free_balance(10), 90); - assert_noop!(Identity::kill_identity(Origin::signed(2), 10), Error::::NotNamed); - }); - } - - #[test] - fn setting_subaccounts_should_work() { - new_test_ext().execute_with(|| { - let mut subs = vec![(20, Data::Raw(vec![40; 1]))]; - assert_noop!(Identity::set_subs(Origin::signed(10), subs.clone()), Error::::NotFound); - - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone())); - assert_eq!(Balances::free_balance(10), 80); - assert_eq!(Identity::subs_of(10), (10, vec![20])); - assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1])))); - - // push another item and re-set it. - subs.push((30, Data::Raw(vec![50; 1]))); - assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone())); - assert_eq!(Balances::free_balance(10), 70); - assert_eq!(Identity::subs_of(10), (20, vec![20, 30])); - assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1])))); - assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1])))); - - // switch out one of the items and re-set. - subs[0] = (40, Data::Raw(vec![60; 1])); - assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone())); - assert_eq!(Balances::free_balance(10), 70); // no change in the balance - assert_eq!(Identity::subs_of(10), (20, vec![40, 30])); - assert_eq!(Identity::super_of(20), None); - assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1])))); - assert_eq!(Identity::super_of(40), Some((10, Data::Raw(vec![60; 1])))); - - // clear - assert_ok!(Identity::set_subs(Origin::signed(10), vec![])); - assert_eq!(Balances::free_balance(10), 90); - assert_eq!(Identity::subs_of(10), (0, vec![])); - assert_eq!(Identity::super_of(30), None); - assert_eq!(Identity::super_of(40), None); - - subs.push((20, Data::Raw(vec![40; 1]))); - assert_noop!(Identity::set_subs(Origin::signed(10), subs.clone()), Error::::TooManySubAccounts); - }); - } - - #[test] - fn clearing_account_should_remove_subaccounts_and_refund() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_ok!(Identity::set_subs(Origin::signed(10), vec![(20, Data::Raw(vec![40; 1]))])); - assert_ok!(Identity::clear_identity(Origin::signed(10))); - assert_eq!(Balances::free_balance(10), 100); - assert!(Identity::super_of(20).is_none()); - }); - } - - #[test] - fn killing_account_should_remove_subaccounts_and_not_refund() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_ok!(Identity::set_subs(Origin::signed(10), vec![(20, Data::Raw(vec![40; 1]))])); - assert_ok!(Identity::kill_identity(Origin::signed(2), 10)); - assert_eq!(Balances::free_balance(10), 80); - assert!(Identity::super_of(20).is_none()); - }); - } - - #[test] - fn cancelling_requested_judgement_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); - assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); - assert_noop!(Identity::cancel_request(Origin::signed(10), 0), Error::::NoIdentity); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10)); - assert_ok!(Identity::cancel_request(Origin::signed(10), 0)); - assert_eq!(Balances::free_balance(10), 90); - assert_noop!(Identity::cancel_request(Origin::signed(10), 0), Error::::NotFound); - - assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable)); - assert_noop!(Identity::cancel_request(Origin::signed(10), 0), Error::::JudgementGiven); - }); - } - - #[test] - fn requesting_judgement_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); - assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); - assert_ok!(Identity::set_identity(Origin::signed(10), ten())); - assert_noop!(Identity::request_judgement(Origin::signed(10), 0, 9), Error::::FeeChanged); - assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10)); - // 10 for the judgement request, 10 for the identity. - assert_eq!(Balances::free_balance(10), 80); - - // Re-requesting won't work as we already paid. - assert_noop!(Identity::request_judgement(Origin::signed(10), 0, 10), Error::::StickyJudgement); - assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Erroneous)); - // Registrar got their payment now. - assert_eq!(Balances::free_balance(3), 20); - - // Re-requesting still won't work as it's erroneous. - assert_noop!(Identity::request_judgement(Origin::signed(10), 0, 10), Error::::StickyJudgement); - - // Requesting from a second registrar still works. - assert_ok!(Identity::add_registrar(Origin::signed(1), 4)); - assert_ok!(Identity::request_judgement(Origin::signed(10), 1, 10)); - - // Re-requesting after the judgement has been reduced works. - assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::OutOfDate)); - assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10)); - }); - } - - #[test] - fn field_deposit_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); - assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); - assert_ok!(Identity::set_identity(Origin::signed(10), IdentityInfo { - additional: vec![ - (Data::Raw(b"number".to_vec()), Data::Raw(10u32.encode())), - (Data::Raw(b"text".to_vec()), Data::Raw(b"10".to_vec())), - ], .. Default::default() - })); - assert_eq!(Balances::free_balance(10), 70); - }); - } - - #[test] - fn setting_account_id_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); - // account 4 cannot change the first registrar's identity since it's owned by 3. - assert_noop!(Identity::set_account_id(Origin::signed(4), 0, 3), Error::::InvalidIndex); - // account 3 can, because that's the registrar's current account. - assert_ok!(Identity::set_account_id(Origin::signed(3), 0, 4)); - // account 4 can now, because that's their new ID. - assert_ok!(Identity::set_account_id(Origin::signed(4), 0, 3)); - }); - } -} diff --git a/frame/identity/src/tests.rs b/frame/identity/src/tests.rs new file mode 100644 index 0000000000000..dd76b4d594984 --- /dev/null +++ b/frame/identity/src/tests.rs @@ -0,0 +1,471 @@ +// This file is part of Substrate. + +// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Tests for Identity Pallet + +use super::*; + +use sp_runtime::traits::BadOrigin; +use frame_support::{ + assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight, + ord_parameter_types, +}; +use sp_core::H256; +use frame_system::{EnsureSignedBy, EnsureOneOf, EnsureRoot}; +use sp_runtime::{ + Perbill, testing::Header, traits::{BlakeTwo256, IdentityLookup}, +}; + +impl_outer_origin! { + pub enum Origin for Test where system = frame_system {} +} + +#[derive(Clone, Eq, PartialEq)] +pub struct Test; +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub const MaximumBlockWeight: Weight = 1024; + pub const MaximumBlockLength: u32 = 2 * 1024; + pub const AvailableBlockRatio: Perbill = Perbill::one(); +} +impl frame_system::Trait for Test { + type BaseCallFilter = (); + type Origin = Origin; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Call = (); + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Header = Header; + type Event = (); + type BlockHashCount = BlockHashCount; + type MaximumBlockWeight = MaximumBlockWeight; + type DbWeight = (); + type BlockExecutionWeight = (); + type ExtrinsicBaseWeight = (); + type MaximumExtrinsicWeight = MaximumBlockWeight; + type MaximumBlockLength = MaximumBlockLength; + type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); + type ModuleToIndex = (); + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); +} +parameter_types! { + pub const ExistentialDeposit: u64 = 1; +} +impl pallet_balances::Trait for Test { + type Balance = u64; + type Event = (); + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} +parameter_types! { + pub const BasicDeposit: u64 = 10; + pub const FieldDeposit: u64 = 10; + pub const SubAccountDeposit: u64 = 10; + pub const MaxSubAccounts: u32 = 2; + pub const MaxAdditionalFields: u32 = 2; + pub const MaxRegistrars: u32 = 20; +} +ord_parameter_types! { + pub const One: u64 = 1; + pub const Two: u64 = 2; +} +type EnsureOneOrRoot = EnsureOneOf< + u64, + EnsureRoot, + EnsureSignedBy +>; +type EnsureTwoOrRoot = EnsureOneOf< + u64, + EnsureRoot, + EnsureSignedBy +>; +impl Trait for Test { + type Event = (); + type Currency = Balances; + type Slashed = (); + type BasicDeposit = BasicDeposit; + type FieldDeposit = FieldDeposit; + type SubAccountDeposit = SubAccountDeposit; + type MaxSubAccounts = MaxSubAccounts; + type MaxAdditionalFields = MaxAdditionalFields; + type MaxRegistrars = MaxRegistrars; + type RegistrarOrigin = EnsureOneOrRoot; + type ForceOrigin = EnsureTwoOrRoot; + type WeightInfo = (); +} +type System = frame_system::Module; +type Balances = pallet_balances::Module; +type Identity = Module; + +pub fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + pallet_balances::GenesisConfig:: { + balances: vec![ + (1, 10), + (2, 10), + (3, 10), + (10, 100), + (20, 100), + (30, 100), + ], + }.assimilate_storage(&mut t).unwrap(); + t.into() +} + +fn ten() -> IdentityInfo { + IdentityInfo { + display: Data::Raw(b"ten".to_vec()), + legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec()), + .. Default::default() + } +} + +fn twenty() -> IdentityInfo { + IdentityInfo { + display: Data::Raw(b"twenty".to_vec()), + legal: Data::Raw(b"The Right Ordinal Twenty, Esq.".to_vec()), + .. Default::default() + } +} + +#[test] +fn editing_subaccounts_should_work() { + new_test_ext().execute_with(|| { + let data = |x| Data::Raw(vec![x; 1]); + + assert_noop!(Identity::add_sub(Origin::signed(10), 20, data(1)), Error::::NoIdentity); + + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + + // first sub account + assert_ok!(Identity::add_sub(Origin::signed(10), 1, data(1))); + assert_eq!(SuperOf::::get(1), Some((10, data(1)))); + assert_eq!(Balances::free_balance(10), 80); + + // second sub account + assert_ok!(Identity::add_sub(Origin::signed(10), 2, data(2))); + assert_eq!(SuperOf::::get(1), Some((10, data(1)))); + assert_eq!(SuperOf::::get(2), Some((10, data(2)))); + assert_eq!(Balances::free_balance(10), 70); + + // third sub account is too many + assert_noop!(Identity::add_sub(Origin::signed(10), 3, data(3)), Error::::TooManySubAccounts); + + // rename first sub account + assert_ok!(Identity::rename_sub(Origin::signed(10), 1, data(11))); + assert_eq!(SuperOf::::get(1), Some((10, data(11)))); + assert_eq!(SuperOf::::get(2), Some((10, data(2)))); + assert_eq!(Balances::free_balance(10), 70); + + // remove first sub account + assert_ok!(Identity::remove_sub(Origin::signed(10), 1)); + assert_eq!(SuperOf::::get(1), None); + assert_eq!(SuperOf::::get(2), Some((10, data(2)))); + assert_eq!(Balances::free_balance(10), 80); + + // add third sub account + assert_ok!(Identity::add_sub(Origin::signed(10), 3, data(3))); + assert_eq!(SuperOf::::get(1), None); + assert_eq!(SuperOf::::get(2), Some((10, data(2)))); + assert_eq!(SuperOf::::get(3), Some((10, data(3)))); + assert_eq!(Balances::free_balance(10), 70); + }); +} + +#[test] +fn resolving_subaccount_ownership_works() { + new_test_ext().execute_with(|| { + let data = |x| Data::Raw(vec![x; 1]); + + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_identity(Origin::signed(20), twenty())); + + // 10 claims 1 as a subaccount + assert_ok!(Identity::add_sub(Origin::signed(10), 1, data(1))); + assert_eq!(Balances::free_balance(1), 10); + assert_eq!(Balances::free_balance(10), 80); + assert_eq!(Balances::reserved_balance(10), 20); + // 20 cannot claim 1 now + assert_noop!(Identity::add_sub(Origin::signed(20), 1, data(1)), Error::::AlreadyClaimed); + // 1 wants to be with 20 so it quits from 10 + assert_ok!(Identity::quit_sub(Origin::signed(1))); + // 1 gets the 10 that 10 paid. + assert_eq!(Balances::free_balance(1), 20); + assert_eq!(Balances::free_balance(10), 80); + assert_eq!(Balances::reserved_balance(10), 10); + // 20 can claim 1 now + assert_ok!(Identity::add_sub(Origin::signed(20), 1, data(1))); + }); +} + +#[test] +fn trailing_zeros_decodes_into_default_data() { + let encoded = Data::Raw(b"Hello".to_vec()).encode(); + assert!(<(Data, Data)>::decode(&mut &encoded[..]).is_err()); + let input = &mut &encoded[..]; + let (a, b) = <(Data, Data)>::decode(&mut AppendZerosInput::new(input)).unwrap(); + assert_eq!(a, Data::Raw(b"Hello".to_vec())); + assert_eq!(b, Data::None); +} + +#[test] +fn adding_registrar_should_work() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); + assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); + let fields = IdentityFields(IdentityField::Display | IdentityField::Legal); + assert_ok!(Identity::set_fields(Origin::signed(3), 0, fields)); + assert_eq!(Identity::registrars(), vec![ + Some(RegistrarInfo { account: 3, fee: 10, fields }) + ]); + }); +} + +#[test] +fn amount_of_registrars_is_limited() { + new_test_ext().execute_with(|| { + for i in 1..MaxRegistrars::get() + 1 { + assert_ok!(Identity::add_registrar(Origin::signed(1), i as u64)); + } + let last_registrar = MaxRegistrars::get() as u64 + 1; + assert_noop!( + Identity::add_registrar(Origin::signed(1), last_registrar), + Error::::TooManyRegistrars + ); + }); +} + +#[test] +fn registration_should_work() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); + assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); + let mut three_fields = ten(); + three_fields.additional.push(Default::default()); + three_fields.additional.push(Default::default()); + three_fields.additional.push(Default::default()); + assert_noop!( + Identity::set_identity(Origin::signed(10), three_fields), + Error::::TooManyFields + ); + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_eq!(Identity::identity(10).unwrap().info, ten()); + assert_eq!(Balances::free_balance(10), 90); + assert_ok!(Identity::clear_identity(Origin::signed(10))); + assert_eq!(Balances::free_balance(10), 100); + assert_noop!(Identity::clear_identity(Origin::signed(10)), Error::::NotNamed); + }); +} + +#[test] +fn uninvited_judgement_should_work() { + new_test_ext().execute_with(|| { + assert_noop!( + Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable), + Error::::InvalidIndex + ); + + assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); + assert_noop!( + Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable), + Error::::InvalidTarget + ); + + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_noop!( + Identity::provide_judgement(Origin::signed(10), 0, 10, Judgement::Reasonable), + Error::::InvalidIndex + ); + assert_noop!( + Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::FeePaid(1)), + Error::::InvalidJudgement + ); + + assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable)); + assert_eq!(Identity::identity(10).unwrap().judgements, vec![(0, Judgement::Reasonable)]); + }); +} + +#[test] +fn clearing_judgement_should_work() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable)); + assert_ok!(Identity::clear_identity(Origin::signed(10))); + assert_eq!(Identity::identity(10), None); + }); +} + +#[test] +fn killing_slashing_should_work() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_noop!(Identity::kill_identity(Origin::signed(1), 10), BadOrigin); + assert_ok!(Identity::kill_identity(Origin::signed(2), 10)); + assert_eq!(Identity::identity(10), None); + assert_eq!(Balances::free_balance(10), 90); + assert_noop!(Identity::kill_identity(Origin::signed(2), 10), Error::::NotNamed); + }); +} + +#[test] +fn setting_subaccounts_should_work() { + new_test_ext().execute_with(|| { + let mut subs = vec![(20, Data::Raw(vec![40; 1]))]; + assert_noop!(Identity::set_subs(Origin::signed(10), subs.clone()), Error::::NotFound); + + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone())); + assert_eq!(Balances::free_balance(10), 80); + assert_eq!(Identity::subs_of(10), (10, vec![20])); + assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1])))); + + // push another item and re-set it. + subs.push((30, Data::Raw(vec![50; 1]))); + assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone())); + assert_eq!(Balances::free_balance(10), 70); + assert_eq!(Identity::subs_of(10), (20, vec![20, 30])); + assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1])))); + assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1])))); + + // switch out one of the items and re-set. + subs[0] = (40, Data::Raw(vec![60; 1])); + assert_ok!(Identity::set_subs(Origin::signed(10), subs.clone())); + assert_eq!(Balances::free_balance(10), 70); // no change in the balance + assert_eq!(Identity::subs_of(10), (20, vec![40, 30])); + assert_eq!(Identity::super_of(20), None); + assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1])))); + assert_eq!(Identity::super_of(40), Some((10, Data::Raw(vec![60; 1])))); + + // clear + assert_ok!(Identity::set_subs(Origin::signed(10), vec![])); + assert_eq!(Balances::free_balance(10), 90); + assert_eq!(Identity::subs_of(10), (0, vec![])); + assert_eq!(Identity::super_of(30), None); + assert_eq!(Identity::super_of(40), None); + + subs.push((20, Data::Raw(vec![40; 1]))); + assert_noop!(Identity::set_subs(Origin::signed(10), subs.clone()), Error::::TooManySubAccounts); + }); +} + +#[test] +fn clearing_account_should_remove_subaccounts_and_refund() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_subs(Origin::signed(10), vec![(20, Data::Raw(vec![40; 1]))])); + assert_ok!(Identity::clear_identity(Origin::signed(10))); + assert_eq!(Balances::free_balance(10), 100); + assert!(Identity::super_of(20).is_none()); + }); +} + +#[test] +fn killing_account_should_remove_subaccounts_and_not_refund() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::set_subs(Origin::signed(10), vec![(20, Data::Raw(vec![40; 1]))])); + assert_ok!(Identity::kill_identity(Origin::signed(2), 10)); + assert_eq!(Balances::free_balance(10), 80); + assert!(Identity::super_of(20).is_none()); + }); +} + +#[test] +fn cancelling_requested_judgement_should_work() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); + assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); + assert_noop!(Identity::cancel_request(Origin::signed(10), 0), Error::::NoIdentity); + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10)); + assert_ok!(Identity::cancel_request(Origin::signed(10), 0)); + assert_eq!(Balances::free_balance(10), 90); + assert_noop!(Identity::cancel_request(Origin::signed(10), 0), Error::::NotFound); + + assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Reasonable)); + assert_noop!(Identity::cancel_request(Origin::signed(10), 0), Error::::JudgementGiven); + }); +} + +#[test] +fn requesting_judgement_should_work() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); + assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); + assert_ok!(Identity::set_identity(Origin::signed(10), ten())); + assert_noop!(Identity::request_judgement(Origin::signed(10), 0, 9), Error::::FeeChanged); + assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10)); + // 10 for the judgement request, 10 for the identity. + assert_eq!(Balances::free_balance(10), 80); + + // Re-requesting won't work as we already paid. + assert_noop!(Identity::request_judgement(Origin::signed(10), 0, 10), Error::::StickyJudgement); + assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::Erroneous)); + // Registrar got their payment now. + assert_eq!(Balances::free_balance(3), 20); + + // Re-requesting still won't work as it's erroneous. + assert_noop!(Identity::request_judgement(Origin::signed(10), 0, 10), Error::::StickyJudgement); + + // Requesting from a second registrar still works. + assert_ok!(Identity::add_registrar(Origin::signed(1), 4)); + assert_ok!(Identity::request_judgement(Origin::signed(10), 1, 10)); + + // Re-requesting after the judgement has been reduced works. + assert_ok!(Identity::provide_judgement(Origin::signed(3), 0, 10, Judgement::OutOfDate)); + assert_ok!(Identity::request_judgement(Origin::signed(10), 0, 10)); + }); +} + +#[test] +fn field_deposit_should_work() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); + assert_ok!(Identity::set_fee(Origin::signed(3), 0, 10)); + assert_ok!(Identity::set_identity(Origin::signed(10), IdentityInfo { + additional: vec![ + (Data::Raw(b"number".to_vec()), Data::Raw(10u32.encode())), + (Data::Raw(b"text".to_vec()), Data::Raw(b"10".to_vec())), + ], .. Default::default() + })); + assert_eq!(Balances::free_balance(10), 70); + }); +} + +#[test] +fn setting_account_id_should_work() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::add_registrar(Origin::signed(1), 3)); + // account 4 cannot change the first registrar's identity since it's owned by 3. + assert_noop!(Identity::set_account_id(Origin::signed(4), 0, 3), Error::::InvalidIndex); + // account 3 can, because that's the registrar's current account. + assert_ok!(Identity::set_account_id(Origin::signed(3), 0, 4)); + // account 4 can now, because that's their new ID. + assert_ok!(Identity::set_account_id(Origin::signed(4), 0, 3)); + }); +} From 47978cfc6a5a1faf9697fd0d997316a53b630c13 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 03:57:47 +0200 Subject: [PATCH 02/13] add automated weights --- frame/identity/src/default_weights.rs | 128 ++++++++++++++++++++++++++ frame/identity/src/lib.rs | 27 +----- 2 files changed, 133 insertions(+), 22 deletions(-) create mode 100644 frame/identity/src/default_weights.rs diff --git a/frame/identity/src/default_weights.rs b/frame/identity/src/default_weights.rs new file mode 100644 index 0000000000000..c6b63ae0918e6 --- /dev/null +++ b/frame/identity/src/default_weights.rs @@ -0,0 +1,128 @@ +// This file is part of Substrate. + +// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6 + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; + +impl crate::WeightInfo for () { + fn add_registrar(r: u32, ) -> Weight { + (39969000 as Weight) + .saturating_add((439000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn set_identity(r: u32, x: u32, ) -> Weight { + (111358000 as Weight) + .saturating_add((369000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3031000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn set_subs(p: u32, s: u32, ) -> Weight { + (0 as Weight) + .saturating_add((8242000 as Weight).saturating_mul(p as Weight)) + .saturating_add((18352000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) + .saturating_add(DbWeight::get().writes(102 as Weight)) + } + fn add_sub(p: u32, ) -> Weight { + (110769000 as Weight) + .saturating_add((259000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn rename_sub(p: u32, ) -> Weight { + (35953000 as Weight) + .saturating_add((88000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn remove_sub(p: u32, ) -> Weight { + (103039000 as Weight) + .saturating_add((243000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn quit_sub(p: u32, ) -> Weight { + (65845000 as Weight) + .saturating_add((227000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { + (92381000 as Weight) + .saturating_add((324000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5638000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1681000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn request_judgement(r: u32, x: u32, ) -> Weight { + (109858000 as Weight) + .saturating_add((600000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3301000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn cancel_request(r: u32, x: u32, ) -> Weight { + (95303000 as Weight) + .saturating_add((417000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3260000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn set_fee(r: u32, ) -> Weight { + (16385000 as Weight) + .saturating_add((406000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn set_account_id(r: u32, ) -> Weight { + (18470000 as Weight) + .saturating_add((420000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn set_fields(r: u32, ) -> Weight { + (16495000 as Weight) + .saturating_add((409000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn provide_judgement(r: u32, x: u32, ) -> Weight { + (71172000 as Weight) + .saturating_add((563000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3304000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { + (118471000 as Weight) + .saturating_add((241000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5647000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1684000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } +} diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 73a2fa4a6a35f..405a93fdeafa1 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -89,6 +89,7 @@ use frame_system::ensure_signed; #[cfg(test)] mod tests; mod benchmarking; +mod default_weights; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; type NegativeImbalanceOf = <::Currency as Currency<::AccountId>>::NegativeImbalance; @@ -97,6 +98,10 @@ pub trait WeightInfo { fn add_registrar(r: u32, ) -> Weight; fn set_identity(r: u32, x: u32, ) -> Weight; fn set_subs(p: u32, s: u32, ) -> Weight; + fn add_sub(p: u32, ) -> Weight; + fn rename_sub(p: u32, ) -> Weight; + fn remove_sub(p: u32, ) -> Weight; + fn quit_sub(p: u32, ) -> Weight; fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight; fn request_judgement(r: u32, x: u32, ) -> Weight; fn cancel_request(r: u32, x: u32, ) -> Weight; @@ -105,28 +110,6 @@ pub trait WeightInfo { fn set_fields(r: u32, ) -> Weight; fn provide_judgement(r: u32, x: u32, ) -> Weight; fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight; - fn add_sub(p: u32, ) -> Weight; - fn rename_sub() -> Weight; - fn remove_sub(p: u32, ) -> Weight; - fn quit_sub(p: u32, ) -> Weight; -} - -impl WeightInfo for () { - fn add_registrar(_r: u32, ) -> Weight { 1_000_000_000 } - fn set_identity(_r: u32, _x: u32, ) -> Weight { 1_000_000_000 } - fn set_subs(_p: u32, _s: u32, ) -> Weight { 1_000_000_000 } - fn clear_identity(_r: u32, _s: u32, _x: u32, ) -> Weight { 1_000_000_000 } - fn request_judgement(_r: u32, _x: u32, ) -> Weight { 1_000_000_000 } - fn cancel_request(_r: u32, _x: u32, ) -> Weight { 1_000_000_000 } - fn set_fee(_r: u32, ) -> Weight { 1_000_000_000 } - fn set_account_id(_r: u32, ) -> Weight { 1_000_000_000 } - fn set_fields(_r: u32, ) -> Weight { 1_000_000_000 } - fn provide_judgement(_r: u32, _x: u32, ) -> Weight { 1_000_000_000 } - fn kill_identity(_r: u32, _s: u32, _x: u32, ) -> Weight { 1_000_000_000 } - fn add_sub(_p: u32, ) -> Weight { 1_000_000_000 } - fn rename_sub() -> Weight { 1_000_000_000 } - fn remove_sub(_p: u32, ) -> Weight { 1_000_000_000 } - fn quit_sub(_p: u32, ) -> Weight { 1_000_000_000 } } pub trait Trait: frame_system::Trait { From a5e685728460cd241ced30523d1846066530800f Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 15:17:00 +0200 Subject: [PATCH 03/13] Update benchmarking.rs --- frame/identity/src/benchmarking.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 4be04dc1dbef9..01bf0eb94bde4 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -155,18 +155,26 @@ benchmarks! { create_identity_info::(x) ) - set_subs { + // We need to split `set_subs` into two benchmarks to accurately isolate the potential + // writes caused by new or old sub accounts. The actual weight should simply be + // the greater of these two weights. + set_subs_new_subs { let caller: T::AccountId = whitelisted_caller(); + // Create a new subs vec with s sub accounts + let s in 1 .. T::MaxSubAccounts::get() => (); + let subs = create_sub_accounts::(&caller, s)?; + }: set_subs(RawOrigin::Signed(caller), subs) + set_subs_old_subs { + let caller: T::AccountId = whitelisted_caller(); // Give them p many previous sub accounts. let p in 1 .. T::MaxSubAccounts::get() => { let _ = add_sub_accounts::(&caller, p)?; }; - // Create a new subs vec with s sub accounts - let s in 1 .. T::MaxSubAccounts::get() => (); - let subs = create_sub_accounts::(&caller, s)?; + // Remove all subs. + let subs = create_sub_accounts::(&caller, 0)?; - }: _(RawOrigin::Signed(caller), subs) + }: set_subs(RawOrigin::Signed(caller), subs) add_sub { let caller: T::AccountId = whitelisted_caller(); From 2ebb83fa4425920e499b63268995c69557187288 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 16:54:14 +0200 Subject: [PATCH 04/13] use underscores for file out --- frame/identity/src/benchmarking.rs | 4 +- frame/identity/src/default_weights.rs | 121 +++++++++++---------- frame/identity/src/lib.rs | 3 +- utils/frame/benchmarking-cli/src/writer.rs | 19 +++- 4 files changed, 85 insertions(+), 62 deletions(-) diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 01bf0eb94bde4..98f8281a2c83b 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -158,14 +158,14 @@ benchmarks! { // We need to split `set_subs` into two benchmarks to accurately isolate the potential // writes caused by new or old sub accounts. The actual weight should simply be // the greater of these two weights. - set_subs_new_subs { + set_subs_new { let caller: T::AccountId = whitelisted_caller(); // Create a new subs vec with s sub accounts let s in 1 .. T::MaxSubAccounts::get() => (); let subs = create_sub_accounts::(&caller, s)?; }: set_subs(RawOrigin::Signed(caller), subs) - set_subs_old_subs { + set_subs_old { let caller: T::AccountId = whitelisted_caller(); // Give them p many previous sub accounts. let p in 1 .. T::MaxSubAccounts::get() => { diff --git a/frame/identity/src/default_weights.rs b/frame/identity/src/default_weights.rs index c6b63ae0918e6..e1f9b9e1eb783 100644 --- a/frame/identity/src/default_weights.rs +++ b/frame/identity/src/default_weights.rs @@ -24,105 +24,112 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { fn add_registrar(r: u32, ) -> Weight { - (39969000 as Weight) - .saturating_add((439000 as Weight).saturating_mul(r as Weight)) + (38525000 as Weight) + .saturating_add((427000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_identity(r: u32, x: u32, ) -> Weight { - (111358000 as Weight) - .saturating_add((369000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3031000 as Weight).saturating_mul(x as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + (107872000 as Weight) + .saturating_add((419000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3013000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) } - fn set_subs(p: u32, s: u32, ) -> Weight { - (0 as Weight) - .saturating_add((8242000 as Weight).saturating_mul(p as Weight)) - .saturating_add((18352000 as Weight).saturating_mul(s as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) + fn set_subs_new(s: u32, ) -> Weight { + (76452000 as Weight) + .saturating_add((14836000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) - .saturating_add(DbWeight::get().writes(102 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn set_subs_old(p: u32, ) -> Weight { + (70274000 as Weight) + .saturating_add((5518000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) } fn add_sub(p: u32, ) -> Weight { - (110769000 as Weight) - .saturating_add((259000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + (108119000 as Weight) + .saturating_add((245000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn rename_sub(p: u32, ) -> Weight { - (35953000 as Weight) - .saturating_add((88000 as Weight).saturating_mul(p as Weight)) + (35829000 as Weight) + .saturating_add((67000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn remove_sub(p: u32, ) -> Weight { - (103039000 as Weight) - .saturating_add((243000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + (101562000 as Weight) + .saturating_add((216000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn quit_sub(p: u32, ) -> Weight { - (65845000 as Weight) - .saturating_add((227000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) + (64745000 as Weight) + .saturating_add((210000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { - (92381000 as Weight) - .saturating_add((324000 as Weight).saturating_mul(r as Weight)) - .saturating_add((5638000 as Weight).saturating_mul(s as Weight)) - .saturating_add((1681000 as Weight).saturating_mul(x as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + (89640000 as Weight) + .saturating_add((270000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5488000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1647000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn request_judgement(r: u32, x: u32, ) -> Weight { - (109858000 as Weight) - .saturating_add((600000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3301000 as Weight).saturating_mul(x as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + (108673000 as Weight) + .saturating_add((491000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3236000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) } fn cancel_request(r: u32, x: u32, ) -> Weight { - (95303000 as Weight) - .saturating_add((417000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3260000 as Weight).saturating_mul(x as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + (94605000 as Weight) + .saturating_add((341000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3205000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_fee(r: u32, ) -> Weight { - (16385000 as Weight) - .saturating_add((406000 as Weight).saturating_mul(r as Weight)) + (15928000 as Weight) + .saturating_add((377000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_account_id(r: u32, ) -> Weight { - (18470000 as Weight) - .saturating_add((420000 as Weight).saturating_mul(r as Weight)) + (17940000 as Weight) + .saturating_add((388000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_fields(r: u32, ) -> Weight { - (16495000 as Weight) - .saturating_add((409000 as Weight).saturating_mul(r as Weight)) + (15781000 as Weight) + .saturating_add((391000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn provide_judgement(r: u32, x: u32, ) -> Weight { - (71172000 as Weight) - .saturating_add((563000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3304000 as Weight).saturating_mul(x as Weight)) + (71415000 as Weight) + .saturating_add((445000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3212000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { - (118471000 as Weight) - .saturating_add((241000 as Weight).saturating_mul(r as Weight)) - .saturating_add((5647000 as Weight).saturating_mul(s as Weight)) - .saturating_add((1684000 as Weight).saturating_mul(x as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + (115969000 as Weight) + .saturating_add((161000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5509000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1635000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } } diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 405a93fdeafa1..b0626529357ee 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -97,7 +97,8 @@ type NegativeImbalanceOf = <::Currency as Currency< Weight; fn set_identity(r: u32, x: u32, ) -> Weight; - fn set_subs(p: u32, s: u32, ) -> Weight; + fn set_subs_new(s: u32, ) -> Weight; + fn set_subs_old(p: u32, ) -> Weight; fn add_sub(p: u32, ) -> Weight; fn rename_sub(p: u32, ) -> Weight; fn remove_sub(p: u32, ) -> Weight; diff --git a/utils/frame/benchmarking-cli/src/writer.rs b/utils/frame/benchmarking-cli/src/writer.rs index 964c1bf5fc112..2f5fd92ff01f0 100644 --- a/utils/frame/benchmarking-cli/src/writer.rs +++ b/utils/frame/benchmarking-cli/src/writer.rs @@ -32,6 +32,21 @@ pub fn open_file(path: &str) -> Result { .open(path) } +fn underscore(i: Number) -> String + where Number: std::string::ToString +{ + let mut s = String::new(); + let i_str = i.to_string(); + let a = i_str.chars().rev().enumerate(); + for (idx, val) in a { + if idx != 0 && idx % 3 == 0 { + s.insert(0, '_'); + } + s.insert(0, val); + } + s +} + pub fn write_trait(file: &mut File, batches: Vec) -> Result<(), std::io::Error> { let mut current_pallet = Vec::::new(); @@ -176,10 +191,10 @@ pub fn write_results(batches: &[BenchmarkBatch]) -> Result<(), std::io::Error> { // return value write!(file, ") -> Weight {{\n")?; - write!(file, "\t\t({} as Weight)\n", extrinsic_time.base.saturating_mul(1000))?; + write!(file, "\t\t({} as Weight)\n", underscore(extrinsic_time.base.saturating_mul(1000)))?; used_extrinsic_time.iter().try_for_each(|(slope, name)| -> Result<(), std::io::Error> { write!(file, "\t\t\t.saturating_add(({} as Weight).saturating_mul({} as Weight))\n", - slope.saturating_mul(1000), + underscore(slope.saturating_mul(1000)), name, ) })?; From f9e1007c146a0828b792499b2afc706877de2d9c Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 17:35:43 +0200 Subject: [PATCH 05/13] update some weights --- frame/identity/src/benchmarking.rs | 5 +- frame/identity/src/default_weights.rs | 80 ++++++++++++------------- frame/identity/src/lib.rs | 84 +++++++-------------------- 3 files changed, 65 insertions(+), 104 deletions(-) diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 98f8281a2c83b..2e7b3f952c0b7 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -157,7 +157,7 @@ benchmarks! { // We need to split `set_subs` into two benchmarks to accurately isolate the potential // writes caused by new or old sub accounts. The actual weight should simply be - // the greater of these two weights. + // the sum of these two weights. set_subs_new { let caller: T::AccountId = whitelisted_caller(); // Create a new subs vec with s sub accounts @@ -344,7 +344,8 @@ mod tests { new_test_ext().execute_with(|| { assert_ok!(test_benchmark_add_registrar::()); assert_ok!(test_benchmark_set_identity::()); - assert_ok!(test_benchmark_set_subs::()); + assert_ok!(test_benchmark_set_subs_new::()); + assert_ok!(test_benchmark_set_subs_old::()); assert_ok!(test_benchmark_clear_identity::()); assert_ok!(test_benchmark_request_judgement::()); assert_ok!(test_benchmark_cancel_request::()); diff --git a/frame/identity/src/default_weights.rs b/frame/identity/src/default_weights.rs index e1f9b9e1eb783..4075233194f1e 100644 --- a/frame/identity/src/default_weights.rs +++ b/frame/identity/src/default_weights.rs @@ -24,110 +24,110 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { fn add_registrar(r: u32, ) -> Weight { - (38525000 as Weight) - .saturating_add((427000 as Weight).saturating_mul(r as Weight)) + (38_700_000 as Weight) + .saturating_add((432_000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_identity(r: u32, x: u32, ) -> Weight { - (107872000 as Weight) - .saturating_add((419000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3013000 as Weight).saturating_mul(x as Weight)) + (108_344_000 as Weight) + .saturating_add((394_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((2_997_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_subs_new(s: u32, ) -> Weight { - (76452000 as Weight) - .saturating_add((14836000 as Weight).saturating_mul(s as Weight)) + (76_128_000 as Weight) + .saturating_add((14_854_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) .saturating_add(DbWeight::get().writes(1 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn set_subs_old(p: u32, ) -> Weight { - (70274000 as Weight) - .saturating_add((5518000 as Weight).saturating_mul(p as Weight)) + (69_632_000 as Weight) + .saturating_add((5_532_000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) } fn add_sub(p: u32, ) -> Weight { - (108119000 as Weight) - .saturating_add((245000 as Weight).saturating_mul(p as Weight)) + (107_628_000 as Weight) + .saturating_add((240_000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn rename_sub(p: u32, ) -> Weight { - (35829000 as Weight) - .saturating_add((67000 as Weight).saturating_mul(p as Weight)) + (35_566_000 as Weight) + .saturating_add((70_000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn remove_sub(p: u32, ) -> Weight { - (101562000 as Weight) - .saturating_add((216000 as Weight).saturating_mul(p as Weight)) + (100_689_000 as Weight) + .saturating_add((220_000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn quit_sub(p: u32, ) -> Weight { - (64745000 as Weight) - .saturating_add((210000 as Weight).saturating_mul(p as Weight)) + (64_411_000 as Weight) + .saturating_add((208_000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { - (89640000 as Weight) - .saturating_add((270000 as Weight).saturating_mul(r as Weight)) - .saturating_add((5488000 as Weight).saturating_mul(s as Weight)) - .saturating_add((1647000 as Weight).saturating_mul(x as Weight)) + (89_185_000 as Weight) + .saturating_add((250_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5_552_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_663_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn request_judgement(r: u32, x: u32, ) -> Weight { - (108673000 as Weight) - .saturating_add((491000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3236000 as Weight).saturating_mul(x as Weight)) + (107_531_000 as Weight) + .saturating_add((536_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3_237_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn cancel_request(r: u32, x: u32, ) -> Weight { - (94605000 as Weight) - .saturating_add((341000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3205000 as Weight).saturating_mul(x as Weight)) + (93_368_000 as Weight) + .saturating_add((371_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3_225_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_fee(r: u32, ) -> Weight { - (15928000 as Weight) - .saturating_add((377000 as Weight).saturating_mul(r as Weight)) + (15_942_000 as Weight) + .saturating_add((390_000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_account_id(r: u32, ) -> Weight { - (17940000 as Weight) - .saturating_add((388000 as Weight).saturating_mul(r as Weight)) + (18_135_000 as Weight) + .saturating_add((385_000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_fields(r: u32, ) -> Weight { - (15781000 as Weight) - .saturating_add((391000 as Weight).saturating_mul(r as Weight)) + (15_962_000 as Weight) + .saturating_add((398_000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn provide_judgement(r: u32, x: u32, ) -> Weight { - (71415000 as Weight) - .saturating_add((445000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3212000 as Weight).saturating_mul(x as Weight)) + (71_698_000 as Weight) + .saturating_add((423_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3_215_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { - (115969000 as Weight) - .saturating_add((161000 as Weight).saturating_mul(r as Weight)) - .saturating_add((5509000 as Weight).saturating_mul(s as Weight)) - .saturating_add((1635000 as Weight).saturating_mul(x as Weight)) + (111_774_000 as Weight) + .saturating_add((249_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5_571_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_662_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index b0626529357ee..198b5ab6256e7 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -516,49 +516,6 @@ mod weight_for { use frame_support::{traits::Get, weights::Weight}; use super::Trait; - /// Weight calculation for `add_registrar`. - /// - /// Based on benchmark: - /// 22.24 + R * 0.371 µs (min squares analysis) - pub(crate) fn add_registrar( - registrars: Weight - ) -> Weight { - T::DbWeight::get().reads_writes(1, 1) - + 23_000_000 // constant - + 380_000 * registrars // R - } - - /// Weight calculation for `set_identity`. - /// - /// Based on benchmark: - /// 50.64 + R * 0.215 + X * 1.424 µs (min squares analysis) - pub(crate) fn set_identity( - judgements: Weight, - extra_fields: Weight - ) -> Weight { - T::DbWeight::get().reads_writes(1, 1) - + 51_000_000 // constant - + 220_000 * judgements // R - + 1_500_000 * extra_fields // X - } - - /// Weight calculation for `set_subs`. - /// - /// Based on benchmark: - /// 36.21 + P * 2.481 + S * 3.633 µs (min squares analysis) - pub(crate) fn set_subs( - old_subs: Weight, - subs: Weight - ) -> Weight { - let db = T::DbWeight::get(); - db.reads(1) // storage-exists (`IdentityOf::contains_key`) - .saturating_add(db.reads_writes(1, old_subs)) // `SubsOf::get` read + P old DB deletions - .saturating_add(db.writes(subs + 1)) // S + 1 new DB writes - .saturating_add(37_000_000) // constant - .saturating_add(2_500_000 * old_subs) // P - .saturating_add(subs.saturating_mul(3_700_000)) // S - } - /// Weight calculation for `clear_identity`. /// /// Based on benchmark: @@ -708,7 +665,7 @@ decl_module! { /// - One storage mutation (codec `O(R)`). /// - One event. /// # - #[weight = weight_for::add_registrar::(T::MaxRegistrars::get().into()) ] + #[weight = T::WeightInfo::add_registrar(T::MaxRegistrars::get()) ] fn add_registrar(origin, account: T::AccountId) -> DispatchResultWithPostInfo { T::RegistrarOrigin::ensure_origin(origin)?; @@ -724,7 +681,7 @@ decl_module! { Self::deposit_event(RawEvent::RegistrarAdded(i)); - Ok(Some(weight_for::add_registrar::(registrar_count as Weight)).into()) + Ok(Some(T::WeightInfo::add_registrar(registrar_count as u32)).into()) } /// Set an account's identity information and reserve the appropriate deposit. @@ -746,7 +703,7 @@ decl_module! { /// - One storage mutation (codec-read `O(X' + R)`, codec-write `O(X + R)`). /// - One event. /// # - #[weight = weight_for::set_identity::( + #[weight = T::WeightInfo::set_identity( T::MaxRegistrars::get().into(), // R T::MaxAdditionalFields::get().into(), // X )] @@ -775,13 +732,13 @@ decl_module! { let _ = T::Currency::unreserve(&sender, old_deposit - id.deposit); } - let judgements = id.judgements.len() as Weight; + let judgements = id.judgements.len(); >::insert(&sender, id); Self::deposit_event(RawEvent::IdentitySet(sender)); - Ok(Some(weight_for::set_identity::( - judgements, // R - extra_fields as Weight // X + Ok(Some(T::WeightInfo::set_identity( + judgements as u32, // R + extra_fields // X )).into()) } @@ -806,10 +763,9 @@ decl_module! { /// - One storage write (codec complexity `O(S)`). /// - One storage-exists (`IdentityOf::contains_key`). /// # - #[weight = weight_for::set_subs::( - T::MaxSubAccounts::get().into(), // P - subs.len() as Weight // S - )] + #[weight = T::WeightInfo::set_subs_old(T::MaxSubAccounts::get()) // P: Assume max sub accounts removed. + .saturating_add(T::WeightInfo::set_subs_new(subs.len() as u32)) // S: Assume all subs are new. + ] fn set_subs(origin, subs: Vec<(T::AccountId, Data)>) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; ensure!(>::contains_key(&sender), Error::::NotFound); @@ -823,11 +779,15 @@ decl_module! { if old_deposit < new_deposit { T::Currency::reserve(&sender, new_deposit - old_deposit)?; - } - // do nothing if they're equal. - if old_deposit > new_deposit { + } else if old_deposit > new_deposit { let _ = T::Currency::unreserve(&sender, old_deposit - new_deposit); } + // do nothing if they're equal. + + // TODO: This whole extrinsic screams "not optimized". For example we could + // filter any overlap between new and old subs, and avoid reading/writing + // to those values... We could also ideally avoid needing to write to + // N storage items for N sub accounts. for s in old_ids.iter() { >::remove(s); @@ -836,7 +796,7 @@ decl_module! { >::insert(&id, (sender.clone(), name)); id }).collect::>(); - let new_subs = ids.len() as Weight; + let new_subs = ids.len(); if ids.is_empty() { >::remove(&sender); @@ -844,10 +804,10 @@ decl_module! { >::insert(&sender, (new_deposit, ids)); } - Ok(Some(weight_for::set_subs::( - old_ids.len() as Weight, // P - new_subs // S - )).into()) + Ok(Some( + T::WeightInfo::set_subs_old(old_ids.len() as u32) // P: Real number of old accounts removed. + .saturating_add(T::WeightInfo::set_subs_new(new_subs as u32)) // S: New subs added. + ).into()) } /// Clear an account's identity info and all sub-accounts and return all deposits. From 9ce60757f3a02b632278395f5131ac6466ac3d51 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 18:10:20 +0200 Subject: [PATCH 06/13] more weights --- frame/identity/src/benchmarking.rs | 89 +++++++++++----------- frame/identity/src/default_weights.rs | 48 ++++++------ frame/identity/src/lib.rs | 105 +++++++------------------- 3 files changed, 100 insertions(+), 142 deletions(-) diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 2e7b3f952c0b7..9a18fbf629272 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -176,48 +176,6 @@ benchmarks! { }: set_subs(RawOrigin::Signed(caller), subs) - add_sub { - let caller: T::AccountId = whitelisted_caller(); - - // Give them p many previous sub accounts. - let p in 1 .. T::MaxSubAccounts::get() - 1 => { - let _ = add_sub_accounts::(&caller, p)?; - }; - let sub = account("new_sub", 0, SEED); - let data = Data::Raw(vec![0; 32]); - }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) - - rename_sub { - let caller: T::AccountId = whitelisted_caller(); - - let p in 1 .. T::MaxSubAccounts::get(); - - // Give them p many previous sub accounts. - let (sub, _) = add_sub_accounts::(&caller, p)?.remove(0); - let data = Data::Raw(vec![1; 32]); - - }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) - - remove_sub { - let caller: T::AccountId = whitelisted_caller(); - - // Give them p many previous sub accounts. - let p in 1 .. T::MaxSubAccounts::get(); - let (sub, _) = add_sub_accounts::(&caller, p)?.remove(0); - }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub)) - - quit_sub { - let caller: T::AccountId = whitelisted_caller(); - let sup = account("super", 0, SEED); - - // Give them p many previous sub accounts. - let p in 1 .. T::MaxSubAccounts::get() - 1 => { - let _ = add_sub_accounts::(&sup, p)?; - }; - let sup_origin = RawOrigin::Signed(sup).into(); - Identity::::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32]))?; - }: _(RawOrigin::Signed(caller)) - clear_identity { let caller: T::AccountId = whitelisted_caller(); let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); @@ -331,6 +289,49 @@ benchmarks! { )?; } }: _(RawOrigin::Root, caller_lookup) + + add_sub { + let caller: T::AccountId = whitelisted_caller(); + + // Give them p many previous sub accounts. + let p in 1 .. T::MaxSubAccounts::get() - 1 => { + let _ = add_sub_accounts::(&caller, p)?; + }; + let sub = account("new_sub", 0, SEED); + let data = Data::Raw(vec![0; 32]); + }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) + + rename_sub { + let caller: T::AccountId = whitelisted_caller(); + + let p in 1 .. T::MaxSubAccounts::get(); + + // Give them p many previous sub accounts. + let (sub, _) = add_sub_accounts::(&caller, p)?.remove(0); + let data = Data::Raw(vec![1; 32]); + + }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) + + remove_sub { + let caller: T::AccountId = whitelisted_caller(); + + // Give them p many previous sub accounts. + let p in 1 .. T::MaxSubAccounts::get(); + let (sub, _) = add_sub_accounts::(&caller, p)?.remove(0); + }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub)) + + quit_sub { + let caller: T::AccountId = whitelisted_caller(); + let sup = account("super", 0, SEED); + + // Give them p many previous sub accounts. + let p in 1 .. T::MaxSubAccounts::get() - 1 => { + let _ = add_sub_accounts::(&sup, p)?; + }; + let sup_origin = RawOrigin::Signed(sup).into(); + Identity::::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32]))?; + }: _(RawOrigin::Signed(caller)) + } #[cfg(test)] @@ -354,6 +355,10 @@ mod tests { assert_ok!(test_benchmark_set_fields::()); assert_ok!(test_benchmark_provide_judgement::()); assert_ok!(test_benchmark_kill_identity::()); + assert_ok!(test_benchmark_add_sub::()); + assert_ok!(test_benchmark_rename_sub::()); + assert_ok!(test_benchmark_remove_sub::()); + assert_ok!(test_benchmark_quit_sub::()); }); } } diff --git a/frame/identity/src/default_weights.rs b/frame/identity/src/default_weights.rs index 4075233194f1e..3b00bc78105ea 100644 --- a/frame/identity/src/default_weights.rs +++ b/frame/identity/src/default_weights.rs @@ -51,30 +51,6 @@ impl crate::WeightInfo for () { .saturating_add(DbWeight::get().writes(1 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) } - fn add_sub(p: u32, ) -> Weight { - (107_628_000 as Weight) - .saturating_add((240_000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) - } - fn rename_sub(p: u32, ) -> Weight { - (35_566_000 as Weight) - .saturating_add((70_000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(1 as Weight)) - } - fn remove_sub(p: u32, ) -> Weight { - (100_689_000 as Weight) - .saturating_add((220_000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) - } - fn quit_sub(p: u32, ) -> Weight { - (64_411_000 as Weight) - .saturating_add((208_000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) - } fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { (89_185_000 as Weight) .saturating_add((250_000 as Weight).saturating_mul(r as Weight)) @@ -132,4 +108,28 @@ impl crate::WeightInfo for () { .saturating_add(DbWeight::get().writes(2 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } + fn add_sub(p: u32, ) -> Weight { + (107_628_000 as Weight) + .saturating_add((240_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn rename_sub(p: u32, ) -> Weight { + (35_566_000 as Weight) + .saturating_add((70_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn remove_sub(p: u32, ) -> Weight { + (100_689_000 as Weight) + .saturating_add((220_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn quit_sub(p: u32, ) -> Weight { + (64_411_000 as Weight) + .saturating_add((208_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } } diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 198b5ab6256e7..f010969855129 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -516,50 +516,6 @@ mod weight_for { use frame_support::{traits::Get, weights::Weight}; use super::Trait; - /// Weight calculation for `clear_identity`. - /// - /// Based on benchmark: - /// 43.19 + R * 0.099 + S * 2.547 + X * 0.875 µs (min squares analysis) - pub(crate) fn clear_identity( - judgements: Weight, - subs: Weight, - extra_fields: Weight - ) -> Weight { - T::DbWeight::get().reads_writes(2, subs + 2) // S + 2 deletions - + 44_000_000 // constant - + 100_000 * judgements // R - + 2_600_000 * subs // S - + 900_000 * extra_fields // X - } - - /// Weight calculation for `request_judgement`. - /// - /// Based on benchmark: - /// 51.51 + R * 0.32 + X * 1.85 µs (min squares analysis) - pub(crate) fn request_judgement( - judgements: Weight, - extra_fields: Weight - ) -> Weight { - T::DbWeight::get().reads_writes(2, 1) - + 52_000_000 // constant - + 400_000 * judgements // R - + 1_900_000 * extra_fields // X - } - - /// Weight calculation for `cancel_request`. - /// - /// Based on benchmark: - /// 40.95 + R * 0.219 + X * 1.655 µs (min squares analysis) - pub(crate) fn cancel_request( - judgements: Weight, - extra_fields: Weight - ) -> Weight { - T::DbWeight::get().reads_writes(1, 1) - + 41_000_000 // constant - + 300_000 * judgements // R - + 1_700_000 * extra_fields // X - } - /// Weight calculation for `provide_judgement`. /// /// Based on benchmark: @@ -763,6 +719,12 @@ decl_module! { /// - One storage write (codec complexity `O(S)`). /// - One storage-exists (`IdentityOf::contains_key`). /// # + // TODO: This whole extrinsic screams "not optimized". For example we could + // filter any overlap between new and old subs, and avoid reading/writing + // to those values... We could also ideally avoid needing to write to + // N storage items for N sub accounts. Right now the weight on this function + // is a large overestimate due to the fact that it could potentially write + // to 2 x T::MaxSubAccounts::get(). #[weight = T::WeightInfo::set_subs_old(T::MaxSubAccounts::get()) // P: Assume max sub accounts removed. .saturating_add(T::WeightInfo::set_subs_new(subs.len() as u32)) // S: Assume all subs are new. ] @@ -784,11 +746,6 @@ decl_module! { } // do nothing if they're equal. - // TODO: This whole extrinsic screams "not optimized". For example we could - // filter any overlap between new and old subs, and avoid reading/writing - // to those values... We could also ideally avoid needing to write to - // N storage items for N sub accounts. - for s in old_ids.iter() { >::remove(s); } @@ -828,7 +785,7 @@ decl_module! { /// - `2` storage reads and `S + 2` storage deletions. /// - One event. /// # - #[weight = weight_for::clear_identity::( + #[weight = T::WeightInfo::clear_identity( T::MaxRegistrars::get().into(), // R T::MaxSubAccounts::get().into(), // S T::MaxAdditionalFields::get().into(), // X @@ -847,10 +804,10 @@ decl_module! { Self::deposit_event(RawEvent::IdentityCleared(sender, deposit)); - Ok(Some(weight_for::clear_identity::( - id.judgements.len() as Weight, // R - sub_ids.len() as Weight, // S - id.info.additional.len() as Weight // X + Ok(Some(T::WeightInfo::clear_identity( + id.judgements.len() as u32, // R + sub_ids.len() as u32, // S + id.info.additional.len() as u32 // X )).into()) } @@ -877,7 +834,7 @@ decl_module! { /// - Storage: 1 read `O(R)`, 1 mutate `O(X + R)`. /// - One event. /// # - #[weight = weight_for::request_judgement::( + #[weight = T::WeightInfo::request_judgement( T::MaxRegistrars::get().into(), // R T::MaxAdditionalFields::get().into(), // X )] @@ -904,13 +861,16 @@ decl_module! { T::Currency::reserve(&sender, registrar.fee)?; - let judgements = id.judgements.len() as Weight; - let extra_fields = id.info.additional.len() as Weight; + let judgements = id.judgements.len(); + let extra_fields = id.info.additional.len(); >::insert(&sender, id); Self::deposit_event(RawEvent::JudgementRequested(sender, reg_index)); - Ok(Some(weight_for::request_judgement::(judgements, extra_fields)).into()) + Ok(Some(T::WeightInfo::request_judgement( + judgements as u32, + extra_fields as u32, + )).into()) } /// Cancel a previous request. @@ -930,7 +890,7 @@ decl_module! { /// - One storage mutation `O(R + X)`. /// - One event /// # - #[weight = weight_for::cancel_request::( + #[weight = T::WeightInfo::cancel_request( T::MaxRegistrars::get().into(), // R T::MaxAdditionalFields::get().into(), // X )] @@ -947,13 +907,16 @@ decl_module! { }; let _ = T::Currency::unreserve(&sender, fee); - let judgements = id.judgements.len() as Weight; - let extra_fields = id.info.additional.len() as Weight; + let judgements = id.judgements.len(); + let extra_fields = id.info.additional.len(); >::insert(&sender, id); Self::deposit_event(RawEvent::JudgementUnrequested(sender, reg_index)); - Ok(Some(weight_for::request_judgement::(judgements, extra_fields)).into()) + Ok(Some(T::WeightInfo::cancel_request( + judgements as u32, + extra_fields as u32 + )).into()) } /// Set the fee required for a judgement to be requested from a registrar. @@ -969,10 +932,7 @@ decl_module! { /// - One storage mutation `O(R)`. /// - Benchmark: 7.315 + R * 0.329 µs (min squares analysis) /// # - #[weight = T::DbWeight::get().reads_writes(1, 1) - + 7_400_000 // constant - + 330_000 * T::MaxRegistrars::get() as Weight // R - ] + #[weight = T::WeightInfo::set_fee(T::MaxRegistrars::get())] // R fn set_fee(origin, #[compact] index: RegistrarIndex, #[compact] fee: BalanceOf, @@ -986,9 +946,7 @@ decl_module! { .ok_or_else(|| DispatchError::from(Error::::InvalidIndex))?; Ok(rs.len()) })?; - Ok(Some(T::DbWeight::get().reads_writes(1, 1) - + 7_400_000 + 330_000 * registrars as Weight // R - ).into()) + Ok(Some(T::WeightInfo::set_fee(registrars as u32)).into()) // R } /// Change the account associated with a registrar. @@ -1004,10 +962,7 @@ decl_module! { /// - One storage mutation `O(R)`. /// - Benchmark: 8.823 + R * 0.32 µs (min squares analysis) /// # - #[weight = T::DbWeight::get().reads_writes(1, 1) - + 8_900_000 // constant - + 320_000 * T::MaxRegistrars::get() as Weight // R - ] + #[weight = T::WeightInfo::set_account_id(T::MaxRegistrars::get())] // R fn set_account_id(origin, #[compact] index: RegistrarIndex, new: T::AccountId, @@ -1021,9 +976,7 @@ decl_module! { .ok_or_else(|| DispatchError::from(Error::::InvalidIndex))?; Ok(rs.len()) })?; - Ok(Some(T::DbWeight::get().reads_writes(1, 1) - + 8_900_000 + 320_000 * registrars as Weight // R - ).into()) + Ok(Some(T::WeightInfo::set_account_id(registrars as u32)).into()) // R } /// Set the field information for a registrar. From 73e1f6cd3ca719730a41cdd5c6fe90282a08a8ee Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 18:45:31 +0200 Subject: [PATCH 07/13] finish weights --- frame/identity/src/benchmarking.rs | 29 +++---- frame/identity/src/default_weights.rs | 16 ++-- frame/identity/src/lib.rs | 114 +++++--------------------- 3 files changed, 39 insertions(+), 120 deletions(-) diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 9a18fbf629272..0696e2510f22e 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -291,43 +291,36 @@ benchmarks! { }: _(RawOrigin::Root, caller_lookup) add_sub { - let caller: T::AccountId = whitelisted_caller(); + let s in 1 .. T::MaxSubAccounts::get() - 1; - // Give them p many previous sub accounts. - let p in 1 .. T::MaxSubAccounts::get() - 1 => { - let _ = add_sub_accounts::(&caller, p)?; - }; + let caller: T::AccountId = whitelisted_caller(); + let _ = add_sub_accounts::(&caller, p)?; let sub = account("new_sub", 0, SEED); let data = Data::Raw(vec![0; 32]); }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) rename_sub { - let caller: T::AccountId = whitelisted_caller(); - - let p in 1 .. T::MaxSubAccounts::get(); + let s in 1 .. T::MaxSubAccounts::get(); - // Give them p many previous sub accounts. + let caller: T::AccountId = whitelisted_caller(); let (sub, _) = add_sub_accounts::(&caller, p)?.remove(0); let data = Data::Raw(vec![1; 32]); }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) remove_sub { - let caller: T::AccountId = whitelisted_caller(); + let s in 1 .. T::MaxSubAccounts::get(); - // Give them p many previous sub accounts. - let p in 1 .. T::MaxSubAccounts::get(); - let (sub, _) = add_sub_accounts::(&caller, p)?.remove(0); + let caller: T::AccountId = whitelisted_caller(); + let (sub, _) = add_sub_accounts::(&caller, s)?.remove(0); }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub)) quit_sub { + let s in 1 .. T::MaxSubAccounts::get() - 1; + let caller: T::AccountId = whitelisted_caller(); let sup = account("super", 0, SEED); - - // Give them p many previous sub accounts. - let p in 1 .. T::MaxSubAccounts::get() - 1 => { - let _ = add_sub_accounts::(&sup, p)?; - }; + let _ = add_sub_accounts::(&sup, p)?; let sup_origin = RawOrigin::Signed(sup).into(); Identity::::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32]))?; }: _(RawOrigin::Signed(caller)) diff --git a/frame/identity/src/default_weights.rs b/frame/identity/src/default_weights.rs index 3b00bc78105ea..624e35298f52d 100644 --- a/frame/identity/src/default_weights.rs +++ b/frame/identity/src/default_weights.rs @@ -108,27 +108,27 @@ impl crate::WeightInfo for () { .saturating_add(DbWeight::get().writes(2 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } - fn add_sub(p: u32, ) -> Weight { + fn add_sub(s: u32, ) -> Weight { (107_628_000 as Weight) - .saturating_add((240_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((240_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } - fn rename_sub(p: u32, ) -> Weight { + fn rename_sub(s: u32, ) -> Weight { (35_566_000 as Weight) - .saturating_add((70_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((70_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } - fn remove_sub(p: u32, ) -> Weight { + fn remove_sub(s: u32, ) -> Weight { (100_689_000 as Weight) - .saturating_add((220_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((220_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } - fn quit_sub(p: u32, ) -> Weight { + fn quit_sub(s: u32, ) -> Weight { (64_411_000 as Weight) - .saturating_add((208_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((208_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index f010969855129..1ff69af9a9036 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -511,74 +511,6 @@ decl_error! { } } -/// Functions for calcuating the weight of dispatchables. -mod weight_for { - use frame_support::{traits::Get, weights::Weight}; - use super::Trait; - - /// Weight calculation for `provide_judgement`. - /// - /// Based on benchmark: - /// 40.77 + R * 0.282 + X * 1.66 µs (min squares analysis) - pub(crate) fn provide_judgement( - judgements: Weight, - extra_fields: Weight - ) -> Weight { - T::DbWeight::get().reads_writes(2, 1) - + 41_000_000 // constant - + 300_000 * judgements // R - + 1_700_000 * extra_fields// X - } - - /// Weight calculation for `kill_identity`. - /// - /// Based on benchmark: - /// 83.96 + R * 0.122 + S * 2.533 + X * 0.867 µs (min squares analysis) - pub(crate) fn kill_identity( - judgements: Weight, - subs: Weight, - extra_fields: Weight - ) -> Weight { - let db = T::DbWeight::get(); - db.reads_writes(2, subs + 2) // 2 `take`s + S deletions - + db.reads_writes(1, 1) // balance ops - + 84_000_000 // constant - + 130_000 * judgements // R - + 2_600_000 * subs // S - + 900_000 * extra_fields // X - } - - /// Weight calculation for `add_sub`. - pub(crate) fn add_sub( - subs: Weight, - ) -> Weight { - let db = T::DbWeight::get(); - db.reads_writes(4, 3) + 124_000_000 + 156_000 * subs - } - - /// Weight calculation for `rename_sub`. - pub(crate) fn rename_sub() -> Weight { - let db = T::DbWeight::get(); - db.reads_writes(2, 1) + 30_000_000 - } - - /// Weight calculation for `remove_sub`. - pub(crate) fn remove_sub( - subs: Weight, - ) -> Weight { - let db = T::DbWeight::get(); - db.reads_writes(4, 3) + 86_000_000 + 50_000 * subs - } - - /// Weight calculation for `quit_sub`. - pub(crate) fn quit_sub( - subs: Weight, - ) -> Weight { - let db = T::DbWeight::get(); - db.reads_writes(3, 2) + 63_000_000 + 230_000 * subs - } -} - decl_module! { /// Identity module declaration. pub struct Module for enum Call where origin: T::Origin { @@ -992,10 +924,7 @@ decl_module! { /// - One storage mutation `O(R)`. /// - Benchmark: 7.464 + R * 0.325 µs (min squares analysis) /// # - #[weight = T::DbWeight::get().reads_writes(1, 1) - + 7_500_000 // constant - + 330_000 * T::MaxRegistrars::get() as Weight // R - ] + #[weight = T::WeightInfo::set_fields(T::MaxRegistrars::get())] // R fn set_fields(origin, #[compact] index: RegistrarIndex, fields: IdentityFields, @@ -1009,9 +938,9 @@ decl_module! { .ok_or_else(|| DispatchError::from(Error::::InvalidIndex))?; Ok(rs.len()) })?; - Ok(Some(T::DbWeight::get().reads_writes(1, 1) - + 7_500_000 + 330_000 * registrars as Weight // R - ).into()) + Ok(Some(T::WeightInfo::set_fields( + registrars as u32 // R + )).into()) } /// Provide a judgement for an account's identity. @@ -1033,7 +962,7 @@ decl_module! { /// - Storage: 1 read `O(R)`, 1 mutate `O(R + X)`. /// - One event. /// # - #[weight = weight_for::provide_judgement::( + #[weight = T::WeightInfo::provide_judgement( T::MaxRegistrars::get().into(), // R T::MaxAdditionalFields::get().into(), // X )] @@ -1063,12 +992,15 @@ decl_module! { Err(position) => id.judgements.insert(position, item), } - let judgements = id.judgements.len() as Weight; - let extra_fields = id.info.additional.len() as Weight; + let judgements = id.judgements.len(); + let extra_fields = id.info.additional.len(); >::insert(&target, id); Self::deposit_event(RawEvent::JudgementGiven(target, reg_index)); - Ok(Some(weight_for::provide_judgement::(judgements, extra_fields)).into()) + Ok(Some(T::WeightInfo::provide_judgement( + judgements as u32, + extra_fields as u32, + )).into()) } /// Remove an account's identity and sub-account information and slash the deposits. @@ -1090,7 +1022,7 @@ decl_module! { /// - `S + 2` storage mutations. /// - One event. /// # - #[weight = weight_for::kill_identity::( + #[weight = T::WeightInfo::kill_identity( T::MaxRegistrars::get().into(), // R T::MaxSubAccounts::get().into(), // S T::MaxAdditionalFields::get().into(), // X @@ -1112,10 +1044,10 @@ decl_module! { Self::deposit_event(RawEvent::IdentityKilled(target, deposit)); - Ok(Some(weight_for::kill_identity::( - id.judgements.len() as Weight, // R - sub_ids.len() as Weight, // S - id.info.additional.len() as Weight // X + Ok(Some(T::WeightInfo::kill_identity( + id.judgements.len() as u32, // R + sub_ids.len() as u32, // S + id.info.additional.len() as u32 // X )).into()) } @@ -1126,9 +1058,7 @@ decl_module! { /// /// The dispatch origin for this call must be _Signed_ and the sender must have a registered /// sub identity of `sub`. - #[weight = weight_for::add_sub::( - T::MaxSubAccounts::get().into(), // S - )] + #[weight = T::WeightInfo::add_sub(T::MaxSubAccounts::get())] fn add_sub(origin, sub: ::Source, data: Data) -> DispatchResult { let sender = ensure_signed(origin)?; let sub = T::Lookup::lookup(sub)?; @@ -1156,7 +1086,7 @@ decl_module! { /// /// The dispatch origin for this call must be _Signed_ and the sender must have a registered /// sub identity of `sub`. - #[weight = weight_for::rename_sub::()] + #[weight = T::WeightInfo::rename_sub(T::MaxSubAccounts::get())] fn rename_sub(origin, sub: ::Source, data: Data) { let sender = ensure_signed(origin)?; let sub = T::Lookup::lookup(sub)?; @@ -1172,9 +1102,7 @@ decl_module! { /// /// The dispatch origin for this call must be _Signed_ and the sender must have a registered /// sub identity of `sub`. - #[weight = weight_for::remove_sub::( - T::MaxSubAccounts::get().into(), // S - )] + #[weight = T::WeightInfo::remove_sub(T::MaxSubAccounts::get())] fn remove_sub(origin, sub: ::Source) { let sender = ensure_signed(origin)?; ensure!(IdentityOf::::contains_key(&sender), Error::::NoIdentity); @@ -1201,9 +1129,7 @@ decl_module! { /// /// NOTE: This should not normally be used, but is provided in the case that the non- /// controller of an account is maliciously registered as a sub-account. - #[weight = weight_for::quit_sub::( - T::MaxSubAccounts::get().into(), // S - )] + #[weight = T::WeightInfo::quit_sub(T::MaxSubAccounts::get())] fn quit_sub(origin) { let sender = ensure_signed(origin)?; let (sup, _) = SuperOf::::take(&sender).ok_or(Error::::NotSub)?; From 442ead29f0d5ffa843ecc30e56f33225e5c9c9fb Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 21:21:31 +0200 Subject: [PATCH 08/13] add basic verification to benchmarks --- frame/identity/src/benchmarking.rs | 125 +++++++++++++++++++++++------ 1 file changed, 100 insertions(+), 25 deletions(-) diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 0696e2510f22e..b47cf6ee1f4e2 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -21,7 +21,7 @@ use super::*; -use frame_system::RawOrigin; +use frame_system::{EventRecord, RawOrigin}; use frame_benchmarking::{benchmarks, account, whitelisted_caller}; use sp_runtime::traits::Bounded; @@ -29,6 +29,14 @@ use crate::Module as Identity; const SEED: u32 = 0; +fn assert_last_event(generic_event: ::Event) { + let events = frame_system::Module::::events(); + let system_event: ::Event = generic_event.into(); + // compare to the last event record + let EventRecord { event, .. } = &events[events.len() - 1]; + assert_eq!(event, &system_event); +} + // Adds `r` registrars to the Identity Pallet. These registrars will have set fees and fields. fn add_registrars(r: u32) -> Result<(), &'static str> { for i in 0..r { @@ -120,7 +128,11 @@ benchmarks! { add_registrar { let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; + ensure!(Registrars::::get().len() as u32 == r, "Registrars not set up correctly."); }: _(RawOrigin::Root, account("registrar", r + 1, SEED)) + verify { + ensure!(Registrars::::get().len() as u32 == r + 1, "Registrars not added."); + } set_identity { let r in ...; @@ -150,10 +162,10 @@ benchmarks! { } caller }; - }: _( - RawOrigin::Signed(caller), - create_identity_info::(x) - ) + }: _(RawOrigin::Signed(caller.clone()), create_identity_info::(x)) + verify { + assert_last_event::(Event::::IdentitySet(caller).into()); + } // We need to split `set_subs` into two benchmarks to accurately isolate the potential // writes caused by new or old sub accounts. The actual weight should simply be @@ -163,7 +175,11 @@ benchmarks! { // Create a new subs vec with s sub accounts let s in 1 .. T::MaxSubAccounts::get() => (); let subs = create_sub_accounts::(&caller, s)?; - }: set_subs(RawOrigin::Signed(caller), subs) + ensure!(SubsOf::::get(&caller).1.len() == 0, "Caller already has subs"); + }: set_subs(RawOrigin::Signed(caller.clone()), subs) + verify { + ensure!(SubsOf::::get(&caller).1.len() as u32 == s, "Subs not added"); + } set_subs_old { let caller: T::AccountId = whitelisted_caller(); @@ -173,8 +189,14 @@ benchmarks! { }; // Remove all subs. let subs = create_sub_accounts::(&caller, 0)?; - - }: set_subs(RawOrigin::Signed(caller), subs) + ensure!( + SubsOf::::get(&caller).1.len() as u32 == p, + "Caller does have subs", + ); + }: set_subs(RawOrigin::Signed(caller.clone()), subs) + verify { + ensure!(SubsOf::::get(&caller).1.len() == 0, "Subs not removed"); + } clear_identity { let caller: T::AccountId = whitelisted_caller(); @@ -196,7 +218,11 @@ benchmarks! { Judgement::Reasonable )?; } - }: _(RawOrigin::Signed(caller)) + ensure!(IdentityOf::::contains_key(&caller), "Identity does not exist."); + }: _(RawOrigin::Signed(caller.clone())) + verify { + ensure!(!IdentityOf::::contains_key(&caller), "Identity not cleared."); + } request_judgement { let caller: T::AccountId = whitelisted_caller(); @@ -204,7 +230,10 @@ benchmarks! { let r in ...; let x in ...; - }: _(RawOrigin::Signed(caller), r - 1, 10.into()) + }: _(RawOrigin::Signed(caller.clone()), r - 1, 10.into()) + verify { + assert_last_event::(Event::::JudgementRequested(caller, r-1).into()); + } cancel_request { let caller: T::AccountId = whitelisted_caller(); @@ -215,7 +244,10 @@ benchmarks! { let x in ...; Identity::::request_judgement(caller_origin, r - 1, 10.into())?; - }: _(RawOrigin::Signed(caller), r - 1) + }: _(RawOrigin::Signed(caller.clone()), r - 1) + verify { + assert_last_event::(Event::::JudgementUnrequested(caller, r-1).into()); + } set_fee { let caller: T::AccountId = whitelisted_caller(); @@ -223,7 +255,13 @@ benchmarks! { let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; Identity::::add_registrar(RawOrigin::Root.into(), caller.clone())?; - }: _(RawOrigin::Signed(caller), r, 10.into()) + let registrars = Registrars::::get(); + ensure!(registrars[r as usize].as_ref().unwrap().fee == 0.into(), "Fee already set."); + }: _(RawOrigin::Signed(caller), r, 100.into()) + verify { + let registrars = Registrars::::get(); + ensure!(registrars[r as usize].as_ref().unwrap().fee == 100.into(), "Fee not changed."); + } set_account_id { let caller: T::AccountId = whitelisted_caller(); @@ -232,7 +270,13 @@ benchmarks! { let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; Identity::::add_registrar(RawOrigin::Root.into(), caller.clone())?; + let registrars = Registrars::::get(); + ensure!(registrars[r as usize].as_ref().unwrap().account == caller.clone(), "id not set."); }: _(RawOrigin::Signed(caller), r, account("new", 0, SEED)) + verify { + let registrars = Registrars::::get(); + ensure!(registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED), "id not changed."); + } set_fields { let caller: T::AccountId = whitelisted_caller(); @@ -245,7 +289,13 @@ benchmarks! { IdentityField::Display | IdentityField::Legal | IdentityField::Web | IdentityField::Riot | IdentityField::Email | IdentityField::PgpFingerprint | IdentityField::Image | IdentityField::Twitter ); + let registrars = Registrars::::get(); + ensure!(registrars[r as usize].as_ref().unwrap().fields == Default::default(), "fields already set."); }: _(RawOrigin::Signed(caller), r, fields) + verify { + let registrars = Registrars::::get(); + ensure!(registrars[r as usize].as_ref().unwrap().fields != Default::default(), "fields not set."); + } provide_judgement { // The user @@ -267,28 +317,38 @@ benchmarks! { Identity::::add_registrar(RawOrigin::Root.into(), caller.clone())?; Identity::::request_judgement(user_origin.clone(), r, 10.into())?; }: _(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable) + verify { + assert_last_event::(Event::::JudgementGiven(user, r).into()) + } kill_identity { - let caller: T::AccountId = whitelisted_caller(); - let caller_origin: ::Origin = RawOrigin::Signed(caller.clone()).into(); - let caller_lookup: ::Source = T::Lookup::unlookup(caller.clone()); - let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in ...; let s in ...; let x in ...; + let target: T::AccountId = account("target", 0, SEED); + let target_origin: ::Origin = RawOrigin::Signed(target.clone()).into(); + let target_lookup: ::Source = T::Lookup::unlookup(target.clone()); + let _ = T::Currency::make_free_balance_be(&target, BalanceOf::::max_value()); + + let info = create_identity_info::(T::MaxAdditionalFields::get()); + Identity::::set_identity(target_origin.clone(), info)?; + // User requests judgement from all the registrars, and they approve for i in 0..r { - Identity::::request_judgement(caller_origin.clone(), i, 10.into())?; + Identity::::request_judgement(target_origin.clone(), i, 10.into())?; Identity::::provide_judgement( RawOrigin::Signed(account("registrar", i, SEED)).into(), i, - caller_lookup.clone(), + target_lookup.clone(), Judgement::Reasonable )?; } - }: _(RawOrigin::Root, caller_lookup) + ensure!(IdentityOf::::contains_key(&target), "Identity not set"); + }: _(RawOrigin::Root, target_lookup) + verify { + ensure!(!IdentityOf::::contains_key(&target), "Identity not removed"); + } add_sub { let s in 1 .. T::MaxSubAccounts::get() - 1; @@ -297,7 +357,11 @@ benchmarks! { let _ = add_sub_accounts::(&caller, p)?; let sub = account("new_sub", 0, SEED); let data = Data::Raw(vec![0; 32]); - }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) + ensure!(SubsOf::::get(&caller).1.len() as u32 == s, "Subs not set."); + }: _(RawOrigin::Signed(caller.clone()), T::Lookup::unlookup(sub), data) + verify { + ensure!(SubsOf::::get(&caller).1.len() as u32 == s + 1, "Subs not added."); + } rename_sub { let s in 1 .. T::MaxSubAccounts::get(); @@ -305,15 +369,22 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let (sub, _) = add_sub_accounts::(&caller, p)?.remove(0); let data = Data::Raw(vec![1; 32]); - - }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub), data) + ensure!(SuperOf::::get(&sub).unwrap().1 != data, "data already set"); + }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()), data.clone()) + verify { + ensure!(SuperOf::::get(&sub).unwrap().1 == data, "data not set"); + } remove_sub { let s in 1 .. T::MaxSubAccounts::get(); let caller: T::AccountId = whitelisted_caller(); let (sub, _) = add_sub_accounts::(&caller, s)?.remove(0); - }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub)) + ensure!(SuperOf::::contains_key(&sub), "Sub doesn't exists"); + }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone())) + verify { + ensure!(!SuperOf::::contains_key(&sub), "Sub not removed"); + } quit_sub { let s in 1 .. T::MaxSubAccounts::get() - 1; @@ -323,7 +394,11 @@ benchmarks! { let _ = add_sub_accounts::(&sup, p)?; let sup_origin = RawOrigin::Signed(sup).into(); Identity::::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32]))?; - }: _(RawOrigin::Signed(caller)) + ensure!(SuperOf::::contains_key(&caller), "Sub doesn't exists"); + }: _(RawOrigin::Signed(caller.clone())) + verify { + ensure!(!SuperOf::::contains_key(&caller), "Sub not removed"); + } } From d88f8cc8eda5f9e1c210c60798bc095c791a6028 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 21:40:21 +0200 Subject: [PATCH 09/13] patch benchmarks --- frame/identity/src/benchmarking.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index b47cf6ee1f4e2..43be851369aeb 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -354,7 +354,7 @@ benchmarks! { let s in 1 .. T::MaxSubAccounts::get() - 1; let caller: T::AccountId = whitelisted_caller(); - let _ = add_sub_accounts::(&caller, p)?; + let _ = add_sub_accounts::(&caller, s)?; let sub = account("new_sub", 0, SEED); let data = Data::Raw(vec![0; 32]); ensure!(SubsOf::::get(&caller).1.len() as u32 == s, "Subs not set."); @@ -367,7 +367,7 @@ benchmarks! { let s in 1 .. T::MaxSubAccounts::get(); let caller: T::AccountId = whitelisted_caller(); - let (sub, _) = add_sub_accounts::(&caller, p)?.remove(0); + let (sub, _) = add_sub_accounts::(&caller, s)?.remove(0); let data = Data::Raw(vec![1; 32]); ensure!(SuperOf::::get(&sub).unwrap().1 != data, "data already set"); }: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()), data.clone()) @@ -391,7 +391,7 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let sup = account("super", 0, SEED); - let _ = add_sub_accounts::(&sup, p)?; + let _ = add_sub_accounts::(&sup, s)?; let sup_origin = RawOrigin::Signed(sup).into(); Identity::::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32]))?; ensure!(SuperOf::::contains_key(&caller), "Sub doesn't exists"); From f7bfc7109e55ec8486f07440f18ea0097d092667 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 22:26:29 +0200 Subject: [PATCH 10/13] Update benchmarking.rs --- frame/identity/src/benchmarking.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 43be851369aeb..d39df27017b71 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -323,16 +323,18 @@ benchmarks! { kill_identity { let r in ...; - let s in ...; - let x in ...; + // Setting up our own account below. + let s in _ .. _ => {}; + let x in _ .. _ => {}; let target: T::AccountId = account("target", 0, SEED); let target_origin: ::Origin = RawOrigin::Signed(target.clone()).into(); let target_lookup: ::Source = T::Lookup::unlookup(target.clone()); let _ = T::Currency::make_free_balance_be(&target, BalanceOf::::max_value()); - let info = create_identity_info::(T::MaxAdditionalFields::get()); + let info = create_identity_info::(x); Identity::::set_identity(target_origin.clone(), info)?; + let _ = add_sub_accounts::(&target, s)?; // User requests judgement from all the registrars, and they approve for i in 0..r { From de8ba1659fae1542bafb91a43da6044d3f38c2a3 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 15 Sep 2020 23:04:24 +0200 Subject: [PATCH 11/13] final weights --- frame/identity/src/default_weights.rs | 82 +++++++++++++-------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/frame/identity/src/default_weights.rs b/frame/identity/src/default_weights.rs index 624e35298f52d..93b1c89ab93dd 100644 --- a/frame/identity/src/default_weights.rs +++ b/frame/identity/src/default_weights.rs @@ -24,111 +24,111 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { fn add_registrar(r: u32, ) -> Weight { - (38_700_000 as Weight) - .saturating_add((432_000 as Weight).saturating_mul(r as Weight)) + (39_603_000 as Weight) + .saturating_add((418_000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_identity(r: u32, x: u32, ) -> Weight { - (108_344_000 as Weight) - .saturating_add((394_000 as Weight).saturating_mul(r as Weight)) - .saturating_add((2_997_000 as Weight).saturating_mul(x as Weight)) + (110_679_000 as Weight) + .saturating_add((389_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((2_985_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_subs_new(s: u32, ) -> Weight { - (76_128_000 as Weight) - .saturating_add((14_854_000 as Weight).saturating_mul(s as Weight)) + (78_697_000 as Weight) + .saturating_add((15_225_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) .saturating_add(DbWeight::get().writes(1 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn set_subs_old(p: u32, ) -> Weight { - (69_632_000 as Weight) - .saturating_add((5_532_000 as Weight).saturating_mul(p as Weight)) + (71_308_000 as Weight) + .saturating_add((5_772_000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) } fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { - (89_185_000 as Weight) - .saturating_add((250_000 as Weight).saturating_mul(r as Weight)) - .saturating_add((5_552_000 as Weight).saturating_mul(s as Weight)) - .saturating_add((1_663_000 as Weight).saturating_mul(x as Weight)) + (91_553_000 as Weight) + .saturating_add((284_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5_749_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_621_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn request_judgement(r: u32, x: u32, ) -> Weight { - (107_531_000 as Weight) - .saturating_add((536_000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3_237_000 as Weight).saturating_mul(x as Weight)) + (110_856_000 as Weight) + .saturating_add((496_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3_221_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn cancel_request(r: u32, x: u32, ) -> Weight { - (93_368_000 as Weight) - .saturating_add((371_000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3_225_000 as Weight).saturating_mul(x as Weight)) + (96_857_000 as Weight) + .saturating_add((311_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3_204_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_fee(r: u32, ) -> Weight { - (15_942_000 as Weight) - .saturating_add((390_000 as Weight).saturating_mul(r as Weight)) + (16_276_000 as Weight) + .saturating_add((381_000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_account_id(r: u32, ) -> Weight { - (18_135_000 as Weight) - .saturating_add((385_000 as Weight).saturating_mul(r as Weight)) + (18_530_000 as Weight) + .saturating_add((391_000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn set_fields(r: u32, ) -> Weight { - (15_962_000 as Weight) - .saturating_add((398_000 as Weight).saturating_mul(r as Weight)) + (16_359_000 as Weight) + .saturating_add((379_000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn provide_judgement(r: u32, x: u32, ) -> Weight { - (71_698_000 as Weight) + (72_869_000 as Weight) .saturating_add((423_000 as Weight).saturating_mul(r as Weight)) - .saturating_add((3_215_000 as Weight).saturating_mul(x as Weight)) + .saturating_add((3_187_000 as Weight).saturating_mul(x as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { - (111_774_000 as Weight) - .saturating_add((249_000 as Weight).saturating_mul(r as Weight)) - .saturating_add((5_571_000 as Weight).saturating_mul(s as Weight)) - .saturating_add((1_662_000 as Weight).saturating_mul(x as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + (123_199_000 as Weight) + .saturating_add((71_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5_730_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((2_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) } fn add_sub(s: u32, ) -> Weight { - (107_628_000 as Weight) - .saturating_add((240_000 as Weight).saturating_mul(s as Weight)) + (110_070_000 as Weight) + .saturating_add((262_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn rename_sub(s: u32, ) -> Weight { - (35_566_000 as Weight) - .saturating_add((70_000 as Weight).saturating_mul(s as Weight)) + (37_130_000 as Weight) + .saturating_add((79_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn remove_sub(s: u32, ) -> Weight { - (100_689_000 as Weight) - .saturating_add((220_000 as Weight).saturating_mul(s as Weight)) + (103_295_000 as Weight) + .saturating_add((235_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn quit_sub(s: u32, ) -> Weight { - (64_411_000 as Weight) - .saturating_add((208_000 as Weight).saturating_mul(s as Weight)) + (65_716_000 as Weight) + .saturating_add((227_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } From 5b699edbcb84bdda7607c8b074616610815c4d77 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 17 Sep 2020 02:40:52 +0200 Subject: [PATCH 12/13] update for new type --- frame/identity/src/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frame/identity/src/tests.rs b/frame/identity/src/tests.rs index dd76b4d594984..109bab89cfc95 100644 --- a/frame/identity/src/tests.rs +++ b/frame/identity/src/tests.rs @@ -78,6 +78,7 @@ impl pallet_balances::Trait for Test { type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; + type MaxLocks = (); type WeightInfo = (); } parameter_types! { From a67c43f2e9af73b6b78e0d5383a4d97e34a8e52d Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 17 Sep 2020 23:21:40 +0200 Subject: [PATCH 13/13] add weightinfo to node --- bin/node/runtime/src/lib.rs | 2 +- bin/node/runtime/src/weights/mod.rs | 3 +- .../runtime/src/weights/pallet_identity.rs | 136 ++++++++++++++++++ 3 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 bin/node/runtime/src/weights/pallet_identity.rs diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 104cd2ba96cab..16fcc9f70bc16 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -803,7 +803,7 @@ impl pallet_identity::Trait for Runtime { type Slashed = Treasury; type ForceOrigin = EnsureRootOrHalfCouncil; type RegistrarOrigin = EnsureRootOrHalfCouncil; - type WeightInfo = (); + type WeightInfo = weights::pallet_identity::WeightInfo; } parameter_types! { diff --git a/bin/node/runtime/src/weights/mod.rs b/bin/node/runtime/src/weights/mod.rs index 81347ee7ce529..fd6d3cab49e28 100644 --- a/bin/node/runtime/src/weights/mod.rs +++ b/bin/node/runtime/src/weights/mod.rs @@ -19,9 +19,10 @@ pub mod frame_system; pub mod pallet_balances; pub mod pallet_collective; pub mod pallet_democracy; +pub mod pallet_identity; pub mod pallet_im_online; pub mod pallet_proxy; +pub mod pallet_staking; pub mod pallet_timestamp; pub mod pallet_utility; pub mod pallet_vesting; -pub mod pallet_staking; diff --git a/bin/node/runtime/src/weights/pallet_identity.rs b/bin/node/runtime/src/weights/pallet_identity.rs new file mode 100644 index 0000000000000..2995a7674f8ae --- /dev/null +++ b/bin/node/runtime/src/weights/pallet_identity.rs @@ -0,0 +1,136 @@ +// This file is part of Substrate. + +// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6 + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; + +pub struct WeightInfo; +impl pallet_identity::WeightInfo for WeightInfo { + fn add_registrar(r: u32, ) -> Weight { + (39_603_000 as Weight) + .saturating_add((418_000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn set_identity(r: u32, x: u32, ) -> Weight { + (110_679_000 as Weight) + .saturating_add((389_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((2_985_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn set_subs_new(s: u32, ) -> Weight { + (78_697_000 as Weight) + .saturating_add((15_225_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) + .saturating_add(DbWeight::get().writes(1 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn set_subs_old(p: u32, ) -> Weight { + (71_308_000 as Weight) + .saturating_add((5_772_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) + } + fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { + (91_553_000 as Weight) + .saturating_add((284_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5_749_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_621_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn request_judgement(r: u32, x: u32, ) -> Weight { + (110_856_000 as Weight) + .saturating_add((496_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3_221_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn cancel_request(r: u32, x: u32, ) -> Weight { + (96_857_000 as Weight) + .saturating_add((311_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3_204_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn set_fee(r: u32, ) -> Weight { + (16_276_000 as Weight) + .saturating_add((381_000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn set_account_id(r: u32, ) -> Weight { + (18_530_000 as Weight) + .saturating_add((391_000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn set_fields(r: u32, ) -> Weight { + (16_359_000 as Weight) + .saturating_add((379_000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn provide_judgement(r: u32, x: u32, ) -> Weight { + (72_869_000 as Weight) + .saturating_add((423_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((3_187_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { + (123_199_000 as Weight) + .saturating_add((71_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((5_730_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((2_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn add_sub(s: u32, ) -> Weight { + (110_070_000 as Weight) + .saturating_add((262_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn rename_sub(s: u32, ) -> Weight { + (37_130_000 as Weight) + .saturating_add((79_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn remove_sub(s: u32, ) -> Weight { + (103_295_000 as Weight) + .saturating_add((235_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn quit_sub(s: u32, ) -> Weight { + (65_716_000 as Weight) + .saturating_add((227_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } +}