diff --git a/Cargo.lock b/Cargo.lock index 9799a0f044b1726e5d1a8221f639c080ed613958..1c0cd9e7469a48fbca897569237ef26268cc42b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -891,6 +891,7 @@ dependencies = [ "pallet-proxy", "pallet-scheduler", "pallet-session", + "pallet-session-benchmarking", "pallet-timestamp", "pallet-treasury", "pallet-universal-dividend", @@ -2582,6 +2583,7 @@ dependencies = [ "pallet-proxy", "pallet-scheduler", "pallet-session", + "pallet-session-benchmarking", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", @@ -5417,6 +5419,26 @@ dependencies = [ "sp-trie", ] +[[package]] +name = "pallet-session-benchmarking" +version = "4.0.0-dev" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-authority-members", + "pallet-balances", + "pallet-session", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-session", + "sp-std", +] + [[package]] name = "pallet-sudo" version = "4.0.0-dev" diff --git a/pallets/README.md b/pallets/README.md index 1f0305b5d6fc4a8d3066dc0643a3288433b74bd9..718e3cdf4db96ff02f00fe12eedde0ccdc0fa619 100644 --- a/pallets/README.md +++ b/pallets/README.md @@ -20,4 +20,5 @@ These pallets are at the core of Duniter/Ğ1 currency - **`duniter-test-parameters`** Test parameters only used in ĞDev to allow tweaking parameters more easily. - **`oneshot-account`** Oneshot accounts are light accounts only used once for anonimity or convenience use case. - **`provide-randomness`** Lets blockchain users ask for a verifiable random number. +- **`session-benchmarking`** Benchmarks the session pallet. - **`upgrade-origin`** Allows some origins to dispatch a call as root. \ No newline at end of file diff --git a/pallets/session-benchmarking/Cargo.toml b/pallets/session-benchmarking/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..e561e345ba11bea12b52394d255cf96a28d2ee9f --- /dev/null +++ b/pallets/session-benchmarking/Cargo.toml @@ -0,0 +1,100 @@ +[package] +name = "pallet-session-benchmarking" +version = "4.0.0-dev" +authors = ["Parity Technologies <admin@parity.io>"] +edition = "2021" +license = "Apache-2.0" +homepage = "https://substrate.io" +repository = "https://github.com/paritytech/substrate/" +description = "FRAME sessions pallet benchmarking" +readme = "README.md" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } + +pallet-authority-members = { path = "../authority-members", default-features = false } + +[dependencies.frame-benchmarking] +default-features = false +git = 'https://github.com/duniter/substrate' +optional = true +branch = 'duniter-substrate-v0.9.32' + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.frame-system] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.pallet-session] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-session] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-std] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.parity-scale-codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = "3.1.5" + +[dev-dependencies.pallet-balances] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dev-dependencies.pallet-timestamp] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dev-dependencies.sp-core] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dev-dependencies.sp-io] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[features] +default = ["std"] +std = [ + "parity-scale-codec/std", + "frame-benchmarking/std", + "frame-support/std", + "frame-system/std", + "pallet-session/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", +] + +runtime-benchmarks = [ + 'frame-benchmarking/runtime-benchmarks', + 'frame-support/runtime-benchmarks', + 'frame-system/runtime-benchmarks', +] + diff --git a/pallets/session-benchmarking/README.md b/pallets/session-benchmarking/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8d0946772e12c530b15d43fe41738bffe1301c06 --- /dev/null +++ b/pallets/session-benchmarking/README.md @@ -0,0 +1,4 @@ +# Duniter session-benchmarking pallet + +Benchmark crate for the `pallet-session` that is decoupled from the `staking-pallet` not used in Duniter. +In Duniter, the `SessionManager `and `SessionHandler` hooks are implemented in the `authority-members` pallet. \ No newline at end of file diff --git a/pallets/session-benchmarking/src/lib.rs b/pallets/session-benchmarking/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..057de1931ec2e87434e2f3c83e9f0576d924402e --- /dev/null +++ b/pallets/session-benchmarking/src/lib.rs @@ -0,0 +1,47 @@ +// 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/>. + +//! Benchmarks for the Session Pallet. +// This is separated into its own crate due to cyclic dependency issues. + +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg(feature = "runtime-benchmarks")] +use parity_scale_codec::Decode; +use sp_std::{prelude::*, vec}; + +use frame_benchmarking::{benchmarks, whitelisted_caller}; +use frame_system::RawOrigin; +use pallet_session::*; + +pub struct Pallet<T: Config>(pallet_session::Pallet<T>); +pub trait Config: pallet_session::Config {} + +benchmarks! { + set_keys { + let caller: T::AccountId = whitelisted_caller(); + frame_system::Pallet::<T>::inc_providers(&caller); + let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap(); + let proof: Vec<u8> = vec![0,1,2,3]; + }: _(RawOrigin::Signed(caller), keys, proof) + + purge_keys { + let caller: T::AccountId = whitelisted_caller(); + frame_system::Pallet::<T>::inc_providers(&caller); + let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap(); + let proof: Vec<u8> = vec![0,1,2,3]; + let _t = pallet_session::Pallet::<T>::set_keys(RawOrigin::Signed(caller.clone()).into(), keys, proof); + }: _(RawOrigin::Signed(caller)) +} diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 951feb975ee9402a365a57d74be3594bf7720317..203a9fd6c5eb514d3ec9c45f5f4d0d59d8d817f8 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -23,6 +23,7 @@ runtime-benchmarks = [ 'pallet-multisig/runtime-benchmarks', 'pallet-proxy/runtime-benchmarks', 'pallet-preimage/runtime-benchmarks', + 'pallet-session-benchmarking/runtime-benchmarks', 'pallet-treasury/runtime-benchmarks', 'pallet-upgrade-origin/runtime-benchmarks', 'sp-runtime/runtime-benchmarks', @@ -77,6 +78,7 @@ pallet-oneshot-account = { path = '../../pallets/oneshot-account', default-featu pallet-provide-randomness = { path = '../../pallets/provide-randomness', default-features = false } pallet-upgrade-origin = { path = '../../pallets/upgrade-origin', default-features = false } pallet-universal-dividend = { path = '../../pallets/universal-dividend', default-features = false } +pallet-session-benchmarking = { path = '../../pallets/session-benchmarking', default-features = false } sp-membership = { path = '../../primitives/membership', default-features = false } # Crates.io diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index e3936762bfcfe9a84b11567f98881c1c1de81041..e31d84d6aaa773ab9792425c06d2f5f8707516b6 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -239,6 +239,7 @@ macro_rules! runtime_apis { use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; + use pallet_session_benchmarking::Pallet as SessionBench; use frame_system_benchmarking::Pallet as SystemBench; use frame_benchmarking::baseline::Pallet as Baseline; @@ -258,9 +259,11 @@ macro_rules! runtime_apis { use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; // Trying to add benchmarks directly to some pallets caused cyclic dependency issues. // To get around that, we separated the benchmarks into its own crate. + use pallet_session_benchmarking::Pallet as SessionBench; use frame_system_benchmarking::Pallet as SystemBench; use frame_benchmarking::baseline::Pallet as Baseline; + impl pallet_session_benchmarking::Config for Runtime {} impl frame_system_benchmarking::Config for Runtime {} impl frame_benchmarking::baseline::Config for Runtime {} diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index b802f3070c11319141eefa4caee397cc311c252b..d89fdcb779f922a95a726f44b0c074015dca761e 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -243,7 +243,7 @@ macro_rules! pallets_config { type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, AuthorityMembers>; type SessionHandler = <opaque::SessionKeys as OpaqueKeys>::KeyTypeIdProviders; type Keys = opaque::SessionKeys; - type WeightInfo = pallet_session::weights::SubstrateWeight<Runtime>; + type WeightInfo = common_runtime::weights::pallet_session::WeightInfo<Runtime>; } impl pallet_session::historical::Config for Runtime { type FullIdentification = ValidatorFullIdentification; diff --git a/runtime/common/src/weights.rs b/runtime/common/src/weights.rs index efdf94c4292664c8ae4856861e57ed12eb7da728..4ba7c758564d5a17cd3c2a1a9cd81176196e8262 100644 --- a/runtime/common/src/weights.rs +++ b/runtime/common/src/weights.rs @@ -28,6 +28,7 @@ pub mod pallet_grandpa; pub mod pallet_im_online; pub mod pallet_multisig; pub mod pallet_proxy; +pub mod pallet_session; pub mod pallet_scheduler; pub mod pallet_timestamp; pub mod pallet_treasury; diff --git a/runtime/common/src/weights/pallet_session.rs b/runtime/common/src/weights/pallet_session.rs new file mode 100644 index 0000000000000000000000000000000000000000..db853538a58776193dc568a7f78925dcf5eb6e03 --- /dev/null +++ b/runtime/common/src/weights/pallet_session.rs @@ -0,0 +1,65 @@ +// Copyright 2021-2022 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/>. + +//! Autogenerated weights for `pallet_session` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-05-04, STEPS: `5`, REPEAT: 2, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `benjamin-xps139380`, CPU: `Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// target/release/duniter +// benchmark +// pallet +// --chain=dev +// --steps=5 +// --repeat=2 +// --pallet=pallet_session +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./file_header.txt +// --output=./runtime/common/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_session`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_session::WeightInfo for WeightInfo<T> { + // Storage: Session NextKeys (r:1 w:1) + // Storage: Session KeyOwner (r:4 w:4) + fn set_keys() -> Weight { + // Minimum execution time: 127_407 nanoseconds. + Weight::from_ref_time(136_848_000 as u64) + .saturating_add(T::DbWeight::get().reads(5 as u64)) + .saturating_add(T::DbWeight::get().writes(5 as u64)) + } + // Storage: Session NextKeys (r:1 w:1) + // Storage: Session KeyOwner (r:0 w:4) + fn purge_keys() -> Weight { + // Minimum execution time: 161_605 nanoseconds. + Weight::from_ref_time(166_513_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(5 as u64)) + } +} diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml index 643fc4b03a121197620de2bd4082f32898ece4b4..a30d763c4ea2adff82e8407c5332bed8159b8f1e 100644 --- a/runtime/gdev/Cargo.toml +++ b/runtime/gdev/Cargo.toml @@ -38,6 +38,7 @@ runtime-benchmarks = [ 'pallet-multisig/runtime-benchmarks', 'pallet-oneshot-account/runtime-benchmarks', 'pallet-preimage/runtime-benchmarks', + 'pallet-session-benchmarking/runtime-benchmarks', 'pallet-proxy/runtime-benchmarks', 'pallet-scheduler/runtime-benchmarks', 'pallet-timestamp/runtime-benchmarks', @@ -145,6 +146,7 @@ pallet-membership = { path = '../../pallets/membership', default-features = fals pallet-oneshot-account = { path = '../../pallets/oneshot-account', default-features = false } pallet-provide-randomness = { path = '../../pallets/provide-randomness', default-features = false } pallet-universal-dividend = { path = '../../pallets/universal-dividend', default-features = false } +pallet-session-benchmarking = { path = '../../pallets/session-benchmarking', default-features = false } pallet-upgrade-origin = { path = '../../pallets/upgrade-origin', default-features = false } sp-membership = { path = '../../primitives/membership', default-features = false } diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index a96c9b659c635e346f8aa5241f4b98f4ed7d6241..f7cf7b58c7208de5221946b71ea1c1d6937a9e66 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -154,7 +154,7 @@ mod benches { [pallet_balances, Balances] [frame_benchmarking::baseline, Baseline::<Runtime>] [pallet_collective, TechnicalCommittee] - //[pallet_session, TransactionPayment] FIXME + [pallet_session, SessionBench::<Runtime>] [pallet_im_online, ImOnline] [pallet_multisig, Multisig] [pallet_preimage, Preimage]