diff --git a/Cargo.lock b/Cargo.lock index 16591d4c5ae5a6e6866a3798cd1345982b6130fd..39852d445546e2dfffa15407a385572afd96a84d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5770,18 +5770,24 @@ dependencies = [ name = "pallet-distance" version = "1.0.0" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", + "getrandom 0.2.8", "pallet-authority-members", "pallet-authorship", + "pallet-balances", "pallet-identity", "pallet-membership", "pallet-session", "parity-scale-codec", "scale-info", + "sp-consensus-babe", "sp-core", "sp-distance", "sp-inherents", + "sp-io", + "sp-keystore", "sp-runtime", "sp-std 5.0.0", ] diff --git a/pallets/distance/Cargo.toml b/pallets/distance/Cargo.toml index 1a08c2f2fd428782d39aee506f315629a47494d2..2387c3ce188dbe2b14c58f6edf81bfe90f1a8005 100644 --- a/pallets/distance/Cargo.toml +++ b/pallets/distance/Cargo.toml @@ -11,15 +11,23 @@ version = '1.0.0' [features] default = ['std'] +runtime-benchmarks = [ + 'frame-benchmarking/runtime-benchmarks', + 'pallet-balances', + 'pallet-identity/runtime-benchmarks', + 'sp-consensus-babe', +] std = [ 'codec/std', 'frame-support/std', + 'frame-benchmarking/std', 'pallet-authority-members/std', 'pallet-authorship/std', 'pallet-identity/std', 'pallet-membership/std', 'pallet-session/std', 'sp-core/std', + 'sp-consensus-babe/std', 'sp-distance/std', 'sp-runtime/std', 'sp-std/std', @@ -31,18 +39,28 @@ pallet-authority-members = { path = "../authority-members", default-features = f pallet-identity = { path = "../identity", default-features = false } pallet-membership = { path = "../membership", default-features = false } sp-distance = { path = "../../primitives/distance", default-features = false } +sp-consensus-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false, optional = true } +getrandom = { version = "0.2", features = ["js"] } # substrate scale-info = { version = "2.1.1", default-features = false, features = [ "derive", ] } +pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', optional = true, default-features = false } + [dependencies.codec] default-features = false features = ['derive'] package = 'parity-scale-codec' version = '3.1.5' +[dependencies.frame-benchmarking] +default-features = false +git = 'https://github.com/duniter/substrate' +optional = true +branch = 'duniter-substrate-v0.9.42' + [dependencies.frame-support] default-features = false git = 'https://github.com/duniter/substrate' @@ -87,3 +105,8 @@ branch = 'duniter-substrate-v0.9.42' [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] + +[dev-dependencies] +pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false } +sp-io = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false } +sp-keystore = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false } diff --git a/pallets/distance/src/benchmarking.rs b/pallets/distance/src/benchmarking.rs new file mode 100644 index 0000000000000000000000000000000000000000..eb181d4c06f894efc6fb9ef6245ea38621c5cc4c --- /dev/null +++ b/pallets/distance/src/benchmarking.rs @@ -0,0 +1,91 @@ +// Copyright 2021-2023 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +#![cfg(feature = "runtime-benchmarks")] + +use super::*; + +use codec::Encode; +use frame_benchmarking::{benchmarks, vec}; +use frame_support::traits::{Currency, OnFinalize}; +use frame_system::RawOrigin; +use pallet_balances::Pallet as Balances; +use sp_runtime::traits::{Bounded, One}; +use sp_runtime::Perbill; + +use crate::Pallet; + +fn populate_pool<T: Config>(i: u32) -> Result<(), &'static str> { + EvaluationPool0::<T>::mutate(|current_pool| -> Result<(), &'static str> { + for j in 0..i { + current_pool + .evaluations + .try_push((j.into(), median::MedianAcc::new())) + .map_err(|_| Error::<T>::QueueFull)?; + } + Ok(()) + }) +} + +benchmarks! { + where_clause { + where + T: pallet_balances::Config, T::Balance: From<u64>, + T::BlockNumber: From<u32>, + } + request_distance_evaluation { + let idty = T::IdtyIndex::one(); + let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key; + let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); + let _ = <Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value()); + }: _<T::RuntimeOrigin>(caller_origin.clone()) + verify { + assert!(IdentityDistanceStatus::<T>::get(&idty) == Some((caller, DistanceStatus::Pending)), "Request not added"); + } + update_evaluation { + let digest_data = sp_consensus_babe::digests::PreDigest::SecondaryPlain( + sp_consensus_babe::digests::SecondaryPlainPreDigest { authority_index: 0u32, slot: Default::default() }); + // A BABE digest item is needed to check authorship + let digest = sp_runtime::DigestItem::PreRuntime(*b"BABE", digest_data.encode()); + let _ = <frame_system::Pallet<T>>::deposit_log(digest); + let idty = T::IdtyIndex::one(); + let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key; + let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); + let i in 1 .. MAX_EVALUATIONS_PER_SESSION => populate_pool::<T>(i)?; + }: _<T::RuntimeOrigin>(RawOrigin::None.into(), ComputationResult{distances: vec![Perbill::one(); i as usize]}) + force_update_evaluation { + let idty = T::IdtyIndex::one(); + let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key; + let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); + let i in 1 .. MAX_EVALUATIONS_PER_SESSION => populate_pool::<T>(i)?; + }: _<T::RuntimeOrigin>(RawOrigin::Root.into(), caller, ComputationResult{distances: vec![Perbill::one(); i as usize]}) + force_set_distance_status { + let idty = T::IdtyIndex::one(); + let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key; + let status = Some((caller.clone(), DistanceStatus::Valid)); + }: _<T::RuntimeOrigin>(RawOrigin::Root.into(), idty, status) + verify { + assert!(IdentityDistanceStatus::<T>::get(&idty) == Some((caller, DistanceStatus::Valid)), "Status not set"); + } + on_finalize { + DidUpdate::<T>::set(true); + }: { Pallet::<T>::on_finalize(Default::default()); } + verify { + assert!(!DidUpdate::<T>::get()); + } + + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); +} diff --git a/pallets/distance/src/lib.rs b/pallets/distance/src/lib.rs index ab01a85b84deaf737b6e167ff24cb1476c2bf54c..d467368e64279f860adddb0563c16f092a143854 100644 --- a/pallets/distance/src/lib.rs +++ b/pallets/distance/src/lib.rs @@ -21,10 +21,16 @@ mod traits; mod types; mod weights; +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; + +#[cfg(test)] +mod mock; + pub use pallet::*; pub use traits::*; pub use types::*; -// pub use weights::WeightInfo; +pub use weights::WeightInfo; use frame_support::traits::StorageVersion; use pallet_authority_members::SessionIndex; @@ -39,7 +45,7 @@ pub const MAX_EVALUATIONS_PER_SESSION: u32 = 600; /// Maximum number of evaluators in a session pub const MAX_EVALUATORS_PER_SESSION: u32 = 100; -#[frame_support::pallet(dev_mode)] // dev mode while waiting for benchmarks +#[frame_support::pallet()] pub mod pallet { use super::*; use frame_support::{pallet_prelude::*, traits::ReservableCurrency}; @@ -50,7 +56,6 @@ pub mod pallet { const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); #[pallet::pallet] - // #[pallet::generate_store(pub(super) trait Store)] // deprecated #[pallet::storage_version(STORAGE_VERSION)] #[pallet::without_storage_info] pub struct Pallet<T>(PhantomData<T>); @@ -73,7 +78,7 @@ pub mod pallet { /// Number of session to keep a positive evaluation result type ResultExpiration: Get<u32>; // /// Type representing the weight of this pallet - // type WeightInfo: WeightInfo; + type WeightInfo: WeightInfo; } // STORAGE // @@ -177,8 +182,7 @@ pub mod pallet { /// dummy `on_initialize` to return the weight used in `on_finalize`. fn on_initialize(_n: BlockNumberFor<T>) -> Weight { // weight of `on_finalize` - //T::WeightInfo::on_finalize()// TODO uncomment when benchmarking - Weight::zero() + <T as pallet::Config>::WeightInfo::on_finalize() } /// # <weight> @@ -196,8 +200,7 @@ pub mod pallet { impl<T: Config> Pallet<T> { /// Request an identity to be evaluated #[pallet::call_index(0)] - #[pallet::weight(0)] - // #[pallet::weight(T::WeightInfo::request_distance_evaluation())] + #[pallet::weight(<T as pallet::Config>::WeightInfo::request_distance_evaluation())] pub fn request_distance_evaluation(origin: OriginFor<T>) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; @@ -215,8 +218,7 @@ pub mod pallet { /// (Inherent) Push an evaluation result to the pool #[pallet::call_index(1)] - #[pallet::weight(0)] - // #[pallet::weight(T::WeightInfo::update_evaluation())] + #[pallet::weight(<T as pallet::Config>::WeightInfo::update_evaluation(MAX_EVALUATIONS_PER_SESSION))] pub fn update_evaluation( origin: OriginFor<T>, computation_result: ComputationResult, @@ -236,8 +238,7 @@ pub mod pallet { /// Push an evaluation result to the pool #[pallet::call_index(2)] - #[pallet::weight(0)] - // #[pallet::weight(T::WeightInfo::force_update_evaluation())] + #[pallet::weight(<T as pallet::Config>::WeightInfo::force_update_evaluation(MAX_EVALUATIONS_PER_SESSION))] pub fn force_update_evaluation( origin: OriginFor<T>, evaluator: <T as frame_system::Config>::AccountId, @@ -256,8 +257,7 @@ pub mod pallet { /// when the evaluation completes. /// * `status.1` is the status of the evaluation. #[pallet::call_index(3)] - #[pallet::weight(0)] - // #[pallet::weight(T::WeightInfo::force_set_distance_status())] + #[pallet::weight(<T as pallet::Config>::WeightInfo::force_set_distance_status())] pub fn force_set_distance_status( origin: OriginFor<T>, identity: <T as pallet_identity::Config>::IdtyIndex, diff --git a/pallets/distance/src/mock.rs b/pallets/distance/src/mock.rs new file mode 100644 index 0000000000000000000000000000000000000000..977c4228c063e0a65c460dd95c404eaa04b2edc7 --- /dev/null +++ b/pallets/distance/src/mock.rs @@ -0,0 +1,290 @@ +// Copyright 2023 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +use super::*; +use crate::{self as pallet_distance}; +use core::marker::PhantomData; +use frame_support::{ + parameter_types, + traits::{Everything, GenesisBuild}, +}; +use frame_system as system; +use pallet_balances::AccountData; +use pallet_session::ShouldEndSession; +use sp_core::{ConstU32, H256}; +use sp_runtime::{ + impl_opaque_keys, + key_types::DUMMY, + testing::{Header, TestSignature, UintAuthorityId}, + traits::{BlakeTwo256, ConvertInto, IdentityLookup, IsMember, OpaqueKeys}, + KeyTypeId, Perbill, +}; + +type Balance = u64; +type Block = frame_system::mocking::MockBlock<Test>; +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>; +pub type AccountId = u64; + +impl_opaque_keys! { + pub struct MockSessionKeys { + pub dummy: UintAuthorityId, + } +} + +impl From<UintAuthorityId> for MockSessionKeys { + fn from(dummy: UintAuthorityId) -> Self { + Self { dummy } + } +} + +// Configure a mock runtime to test the pallet. +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event<T>}, + Session: pallet_session::{Pallet, Call, Storage, Config<T>, Event}, + Authorship: pallet_authorship::{Pallet, Storage}, + AuthorityMembers: pallet_authority_members::{Pallet, Call, Storage, Config<T>, Event<T>}, + Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>}, + Identity: pallet_identity::{Pallet, Call, Storage, Config<T>, Event<T>}, + Distance: pallet_distance::{Pallet, Call, Storage}, + } +); + +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub const SS58Prefix: u8 = 42; +} + +impl system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup<Self::AccountId>; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = AccountData<u64>; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = SS58Prefix; + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +pub struct TestSessionHandler; +impl pallet_session::SessionHandler<AccountId> for TestSessionHandler { + const KEY_TYPE_IDS: &'static [KeyTypeId] = &[DUMMY]; + + fn on_new_session<Ks: OpaqueKeys>( + _changed: bool, + _validators: &[(AccountId, Ks)], + _queued_validators: &[(AccountId, Ks)], + ) { + } + + fn on_disabled(_validator_index: u32) {} + + fn on_genesis_session<Ks: OpaqueKeys>(_validators: &[(AccountId, Ks)]) {} +} + +const SESSION_LENGTH: u64 = 5; +pub struct TestShouldEndSession; +impl ShouldEndSession<u64> for TestShouldEndSession { + fn should_end_session(now: u64) -> bool { + now % SESSION_LENGTH == 0 + } +} + +impl pallet_session::Config for Test { + type RuntimeEvent = RuntimeEvent; + type ValidatorId = AccountId; + type ValidatorIdOf = ConvertInto; + type ShouldEndSession = TestShouldEndSession; + type NextSessionRotation = (); + type SessionManager = AuthorityMembers; + type SessionHandler = TestSessionHandler; + type Keys = MockSessionKeys; + type WeightInfo = (); +} + +pub struct FullIdentificationOfImpl; +impl sp_runtime::traits::Convert<AccountId, Option<()>> for FullIdentificationOfImpl { + fn convert(_: AccountId) -> Option<()> { + Some(()) + } +} +impl pallet_session::historical::Config for Test { + type FullIdentification = (); + type FullIdentificationOf = FullIdentificationOfImpl; +} + +pub struct ConstantAuthor<T>(PhantomData<T>); + +impl<T: From<u64>> frame_support::traits::FindAuthor<T> for ConstantAuthor<T> { + fn find_author<'a, I>(_: I) -> Option<T> + where + I: 'a + IntoIterator<Item = (sp_runtime::ConsensusEngineId, &'a [u8])>, + { + Some(1u64.into()) + } +} + +impl pallet_authorship::Config for Test { + type FindAuthor = ConstantAuthor<Self::AccountId>; + type EventHandler = (); +} + +pub struct TestIsSmithMember; +impl IsMember<u32> for TestIsSmithMember { + fn is_member(member_id: &u32) -> bool { + member_id % 3 == 0 + } +} + +pub struct IdentityIndexOf<T: pallet_identity::Config>(PhantomData<T>); + +impl<T: pallet_identity::Config> sp_runtime::traits::Convert<T::AccountId, Option<T::IdtyIndex>> + for IdentityIndexOf<T> +{ + fn convert(account_id: T::AccountId) -> Option<T::IdtyIndex> { + pallet_identity::Pallet::<T>::identity_index_of(account_id) + } +} + +impl pallet_authority_members::Config for Test { + type KeysWrapper = MockSessionKeys; + type IsMember = TestIsSmithMember; + type MaxAuthorities = ConstU32<4>; + type MemberId = u32; + type MemberIdOf = IdentityIndexOf<Self>; + type OnNewSession = (); + type OnRemovedMember = (); + type RemoveMemberOrigin = system::EnsureRoot<AccountId>; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); +} + +parameter_types! { + pub const ExistentialDeposit: Balance = 10; + pub const MaxLocks: u32 = 50; +} + +impl pallet_balances::Config for Test { + type Balance = Balance; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = pallet_balances::weights::SubstrateWeight<Test>; + type MaxLocks = MaxLocks; + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type RuntimeEvent = RuntimeEvent; + type HoldIdentifier = (); + type FreezeIdentifier = (); + type MaxHolds = ConstU32<0>; + type MaxFreezes = ConstU32<0>; +} + +parameter_types! { + pub const ChangeOwnerKeyPeriod: u64 = 10; + pub const ConfirmPeriod: u64 = 2; + pub const IdtyCreationPeriod: u64 = 3; + pub const MaxInactivityPeriod: u64 = 5; + pub const ValidationPeriod: u64 = 2; +} + +pub struct IdtyNameValidatorTestImpl; +impl pallet_identity::traits::IdtyNameValidator for IdtyNameValidatorTestImpl { + fn validate(idty_name: &pallet_identity::IdtyName) -> bool { + idty_name.0.len() < 16 + } +} + +impl pallet_identity::Config for Test { + type ChangeOwnerKeyPeriod = ChangeOwnerKeyPeriod; + type ConfirmPeriod = ConfirmPeriod; + type CheckIdtyCallAllowed = (); + type IdtyCreationPeriod = IdtyCreationPeriod; + type IdtyData = (); + type IdtyNameValidator = IdtyNameValidatorTestImpl; + type IdtyIndex = u32; + type AccountLinker = (); + type IdtyRemovalOtherReason = (); + type Signer = UintAuthorityId; + type Signature = TestSignature; + type OnIdtyChange = (); + type RemoveIdentityConsumers = (); + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkSetupHandler = (); +} + +parameter_types! { + pub const MinAccessibleReferees: Perbill = Perbill::from_percent(80); +} +impl pallet_distance::Config for Test { + type Currency = Balances; + type EvaluationPrice = frame_support::traits::ConstU64<1000>; + type MinAccessibleReferees = MinAccessibleReferees; + type ResultExpiration = frame_support::traits::ConstU32<720>; + type WeightInfo = (); +} + +// Build genesis storage according to the mock runtime. +#[allow(dead_code)] // ??? Clippy triggers dead code for new_test_ext while it is used during test benchmark +pub fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default() + .build_storage::<Test>() + .unwrap(); + + pub const NAMES: [&str; 6] = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Ferdie"]; + pallet_identity::GenesisConfig::<Test> { + identities: (1..=4) + .map(|i| pallet_identity::GenesisIdty { + index: i as u32, + name: pallet_identity::IdtyName::from(NAMES[i - 1]), + value: pallet_identity::IdtyValue { + data: (), + next_creatable_identity_on: 0, + owner_key: i as u64, + old_owner_key: None, + removable_on: 0, + status: pallet_identity::IdtyStatus::Validated, + }, + }) + .collect(), + } + .assimilate_storage(&mut t) + .unwrap(); + + sp_io::TestExternalities::new(t) +} diff --git a/pallets/distance/src/weights.rs b/pallets/distance/src/weights.rs index 8b137891791fe96927ad78e64b0aad7bded08bdc..b0808361a6b8d1810b51c159390fe3d8d640c268 100644 --- a/pallets/distance/src/weights.rs +++ b/pallets/distance/src/weights.rs @@ -1 +1,123 @@ +// Copyright 2021-2023 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. +#![allow(clippy::unnecessary_cast)] + +use frame_support::weights::{constants::RocksDbWeight, Weight}; + +pub trait WeightInfo { + fn request_distance_evaluation() -> Weight; + fn update_evaluation(i: u32) -> Weight; + fn force_update_evaluation(i: u32) -> Weight; + fn force_set_distance_status() -> Weight; + fn on_finalize() -> Weight; +} + +// Insecure weights implementation, use it for tests only! +impl WeightInfo for () { + /// Storage: Identity IdentityIndexOf (r:1 w:0) + /// Proof Skipped: Identity IdentityIndexOf (max_values: None, max_size: None, mode: Measured) + /// Storage: Distance IdentityDistanceStatus (r:1 w:1) + /// Proof Skipped: Distance IdentityDistanceStatus (max_values: None, max_size: None, mode: Measured) + /// Storage: Session CurrentIndex (r:1 w:0) + /// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Distance EvaluationPool2 (r:1 w:1) + /// Proof Skipped: Distance EvaluationPool2 (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(121), added: 2596, mode: MaxEncodedLen) + /// Storage: Distance DistanceStatusExpireOn (r:1 w:1) + /// Proof Skipped: Distance DistanceStatusExpireOn (max_values: None, max_size: None, mode: Measured) + fn request_distance_evaluation() -> Weight { + // Proof Size summary in bytes: + // Measured: `935` + // Estimated: `4400` + // Minimum execution time: 28_469_000 picoseconds. + Weight::from_parts(30_905_000, 0) + .saturating_add(Weight::from_parts(0, 4400)) + .saturating_add(RocksDbWeight::get().reads(6)) + .saturating_add(RocksDbWeight::get().writes(4)) + } + /// Storage: Distance DidUpdate (r:1 w:1) + /// Proof Skipped: Distance DidUpdate (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Authorship Author (r:1 w:1) + /// Proof: Authorship Author (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) + /// Storage: System Digest (r:1 w:0) + /// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Session CurrentIndex (r:1 w:0) + /// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Distance EvaluationPool0 (r:1 w:1) + /// Proof Skipped: Distance EvaluationPool0 (max_values: Some(1), max_size: None, mode: Measured) + /// The range of component `i` is `[1, 600]`. + fn update_evaluation(i: u32) -> Weight { + // Proof Size summary in bytes: + // Measured: `744 + i * (10 ±0)` + // Estimated: `2228 + i * (10 ±0)` + // Minimum execution time: 13_870_000 picoseconds. + Weight::from_parts(17_116_748, 0) + .saturating_add(Weight::from_parts(0, 2228)) + // Standard Error: 684 + .saturating_add(Weight::from_parts(128_989, 0).saturating_mul(i.into())) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 10).saturating_mul(i.into())) + } + /// Storage: Session CurrentIndex (r:1 w:0) + /// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Distance EvaluationPool0 (r:1 w:1) + /// Proof Skipped: Distance EvaluationPool0 (max_values: Some(1), max_size: None, mode: Measured) + /// The range of component `i` is `[1, 600]`. + fn force_update_evaluation(i: u32) -> Weight { + // Proof Size summary in bytes: + // Measured: `612 + i * (10 ±0)` + // Estimated: `2096 + i * (10 ±0)` + // Minimum execution time: 8_392_000 picoseconds. + Weight::from_parts(10_825_908, 0) + .saturating_add(Weight::from_parts(0, 2096)) + // Standard Error: 326 + .saturating_add(Weight::from_parts(123_200, 0).saturating_mul(i.into())) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(1)) + .saturating_add(Weight::from_parts(0, 10).saturating_mul(i.into())) + } + /// Storage: Session CurrentIndex (r:1 w:0) + /// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Distance DistanceStatusExpireOn (r:1 w:1) + /// Proof Skipped: Distance DistanceStatusExpireOn (max_values: None, max_size: None, mode: Measured) + /// Storage: Distance IdentityDistanceStatus (r:0 w:1) + /// Proof Skipped: Distance IdentityDistanceStatus (max_values: None, max_size: None, mode: Measured) + fn force_set_distance_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `586` + // Estimated: `4051` + // Minimum execution time: 8_099_000 picoseconds. + Weight::from_parts(8_786_000, 0) + .saturating_add(Weight::from_parts(0, 4051)) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(2)) + } + /// Storage: Distance DidUpdate (r:1 w:1) + /// Proof Skipped: Distance DidUpdate (max_values: Some(1), max_size: None, mode: Measured) + fn on_finalize() -> Weight { + // Proof Size summary in bytes: + // Measured: `170` + // Estimated: `1655` + // Minimum execution time: 3_904_000 picoseconds. + Weight::from_parts(4_132_000, 0) + .saturating_add(Weight::from_parts(0, 1655)) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) + } +} diff --git a/pallets/duniter-wot/Cargo.toml b/pallets/duniter-wot/Cargo.toml index e86400ac175260a38fc6aaba1908d7b1376cd3b6..403af9bcec971c9a886eb62f7cfff9d1f6f258ef 100644 --- a/pallets/duniter-wot/Cargo.toml +++ b/pallets/duniter-wot/Cargo.toml @@ -11,7 +11,7 @@ version = '3.0.0' [features] default = ['std'] -runtime-benchmarks = ['frame-benchmarking'] +runtime-benchmarks = ['frame-benchmarking', 'pallet-membership/runtime-benchmarks', 'pallet-identity/runtime-benchmarks'] std = [ 'codec/std', 'frame-support/std', diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index dc585e3f1e677c46fb8864e8423d66c96bb9b250..6b49541287f0f7464331fe1ce327ab6138cde430 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -247,8 +247,8 @@ macro_rules! pallets_config { type WeightInfo = common_runtime::weights::pallet_authority_members::WeightInfo<Runtime>; } impl pallet_authorship::Config for Runtime { - type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>; type EventHandler = ImOnline; + type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>; } impl pallet_im_online::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -518,6 +518,7 @@ macro_rules! pallets_config { type EvaluationPrice = frame_support::traits::ConstU64<1000>; type MinAccessibleReferees = MinAccessibleReferees; type ResultExpiration = frame_support::traits::ConstU32<720>; + type WeightInfo = common_runtime::weights::pallet_distance::WeightInfo<Runtime>; } // SMITHS SUB-WOT // diff --git a/runtime/common/src/weights.rs b/runtime/common/src/weights.rs index f8ab1253ae5c7bf8f9d06f4860b40cccb1c863ae..60201d11e1e880b00a73b7a0042abd3315d76cf4 100644 --- a/runtime/common/src/weights.rs +++ b/runtime/common/src/weights.rs @@ -25,6 +25,7 @@ pub mod frame_system; pub mod pallet_babe; pub mod pallet_balances; pub mod pallet_collective; +pub mod pallet_distance; pub mod pallet_grandpa; pub mod pallet_im_online; pub mod pallet_multisig; diff --git a/runtime/common/src/weights/pallet_distance.rs b/runtime/common/src/weights/pallet_distance.rs new file mode 100644 index 0000000000000000000000000000000000000000..0dbf1514f6e2c733887264a4312fb2bf70447b81 --- /dev/null +++ b/runtime/common/src/weights/pallet_distance.rs @@ -0,0 +1,132 @@ + +//! Autogenerated weights for `pallet_distance` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-11-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `bgallois-ms7d43`, CPU: `12th Gen Intel(R) Core(TM) i3-12100F` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("gdev-benchmark"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/duniter +// benchmark +// pallet +// --chain +// gdev-benchmark +// --execution=wasm +// --wasm-execution=compiled +// --pallet +// pallet-distance +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --output +// runtime/common/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_distance`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_distance::WeightInfo for WeightInfo<T> { + /// Storage: Identity IdentityIndexOf (r:1 w:0) + /// Proof Skipped: Identity IdentityIndexOf (max_values: None, max_size: None, mode: Measured) + /// Storage: Distance IdentityDistanceStatus (r:1 w:1) + /// Proof Skipped: Distance IdentityDistanceStatus (max_values: None, max_size: None, mode: Measured) + /// Storage: Session CurrentIndex (r:1 w:0) + /// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Distance EvaluationPool2 (r:1 w:1) + /// Proof Skipped: Distance EvaluationPool2 (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(121), added: 2596, mode: MaxEncodedLen) + /// Storage: Distance DistanceStatusExpireOn (r:1 w:1) + /// Proof Skipped: Distance DistanceStatusExpireOn (max_values: None, max_size: None, mode: Measured) + fn request_distance_evaluation() -> Weight { + // Proof Size summary in bytes: + // Measured: `935` + // Estimated: `4400` + // Minimum execution time: 28_469_000 picoseconds. + Weight::from_parts(30_905_000, 0) + .saturating_add(Weight::from_parts(0, 4400)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: Distance DidUpdate (r:1 w:1) + /// Proof Skipped: Distance DidUpdate (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Authorship Author (r:1 w:1) + /// Proof: Authorship Author (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) + /// Storage: System Digest (r:1 w:0) + /// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Session CurrentIndex (r:1 w:0) + /// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Distance EvaluationPool0 (r:1 w:1) + /// Proof Skipped: Distance EvaluationPool0 (max_values: Some(1), max_size: None, mode: Measured) + /// The range of component `i` is `[1, 600]`. + fn update_evaluation(i: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `744 + i * (10 ±0)` + // Estimated: `2228 + i * (10 ±0)` + // Minimum execution time: 13_870_000 picoseconds. + Weight::from_parts(17_116_748, 0) + .saturating_add(Weight::from_parts(0, 2228)) + // Standard Error: 684 + .saturating_add(Weight::from_parts(128_989, 0).saturating_mul(i.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 10).saturating_mul(i.into())) + } + /// Storage: Session CurrentIndex (r:1 w:0) + /// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Distance EvaluationPool0 (r:1 w:1) + /// Proof Skipped: Distance EvaluationPool0 (max_values: Some(1), max_size: None, mode: Measured) + /// The range of component `i` is `[1, 600]`. + fn force_update_evaluation(i: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `612 + i * (10 ±0)` + // Estimated: `2096 + i * (10 ±0)` + // Minimum execution time: 8_392_000 picoseconds. + Weight::from_parts(10_825_908, 0) + .saturating_add(Weight::from_parts(0, 2096)) + // Standard Error: 326 + .saturating_add(Weight::from_parts(123_200, 0).saturating_mul(i.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(Weight::from_parts(0, 10).saturating_mul(i.into())) + } + /// Storage: Session CurrentIndex (r:1 w:0) + /// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Distance DistanceStatusExpireOn (r:1 w:1) + /// Proof Skipped: Distance DistanceStatusExpireOn (max_values: None, max_size: None, mode: Measured) + /// Storage: Distance IdentityDistanceStatus (r:0 w:1) + /// Proof Skipped: Distance IdentityDistanceStatus (max_values: None, max_size: None, mode: Measured) + fn force_set_distance_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `586` + // Estimated: `4051` + // Minimum execution time: 8_099_000 picoseconds. + Weight::from_parts(8_786_000, 0) + .saturating_add(Weight::from_parts(0, 4051)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: Distance DidUpdate (r:1 w:1) + /// Proof Skipped: Distance DidUpdate (max_values: Some(1), max_size: None, mode: Measured) + fn on_finalize() -> Weight { + // Proof Size summary in bytes: + // Measured: `170` + // Estimated: `1655` + // Minimum execution time: 3_904_000 picoseconds. + Weight::from_parts(4_132_000, 0) + .saturating_add(Weight::from_parts(0, 1655)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs index 920d06390f3a711b52ab65f1cc967d56b92406c4..321e5cd0f7199c7a4a26f3fc189ef7252273db78 100644 --- a/runtime/g1/src/lib.rs +++ b/runtime/g1/src/lib.rs @@ -136,6 +136,7 @@ mod benches { define_benchmarks!( [pallet_certification, Cert] [pallet_certification, SmithCert] + [pallet_distance, Distance] [pallet_oneshot_account, OneshotAccount] [pallet_universal_dividend, UniversalDividend] [pallet_provide_randomness, ProvideRandomness] diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml index 93f07bc788f15f6c8e8eb6d6e8aaa54ab473e104..680b3da3491563def2a8dae615a094ff52fc3c3a 100644 --- a/runtime/gdev/Cargo.toml +++ b/runtime/gdev/Cargo.toml @@ -27,6 +27,7 @@ runtime-benchmarks = [ 'pallet-balances/runtime-benchmarks', 'pallet-certification/runtime-benchmarks', 'pallet-collective/runtime-benchmarks', + 'pallet-distance/runtime-benchmarks', 'pallet-duniter-test-parameters/runtime-benchmarks', 'pallet-duniter-account/runtime-benchmarks', 'pallet-quota/runtime-benchmarks', diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 15abf4260691588a8eef9c0d9725869dadfda0a3..d7ccbcb21ed54d1698e0e1bc715842dbcb821209 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -145,6 +145,7 @@ mod benches { define_benchmarks!( [pallet_certification, Cert] [pallet_certification, SmithCert] + [pallet_distance, Distance] [pallet_oneshot_account, OneshotAccount] [pallet_universal_dividend, UniversalDividend] [pallet_provide_randomness, ProvideRandomness] diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs index 185c6abb1cf467467ba5f8459ca884044c3a4fc2..7759470e039cb1bafe850e2f93cfc52d10f6fffe 100644 --- a/runtime/gtest/src/lib.rs +++ b/runtime/gtest/src/lib.rs @@ -141,6 +141,7 @@ mod benches { define_benchmarks!( [pallet_certification, Cert] [pallet_certification, SmithCert] + [pallet_distance, Distance] [pallet_oneshot_account, OneshotAccount] [pallet_universal_dividend, UniversalDividend] [pallet_provide_randomness, ProvideRandomness]