referrerpolicy=no-referrer-when-downgrade

cumulus_pallet_session_benchmarking/
inner.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Benchmarking setup for pallet-session.
17#![cfg(feature = "runtime-benchmarks")]
18
19use alloc::vec::Vec;
20
21use frame_benchmarking::v2::*;
22use frame_system::RawOrigin;
23use pallet_session::*;
24pub struct Pallet<T: Config>(pallet_session::Pallet<T>);
25pub trait Config: pallet_session::Config {
26	/// Generate a session key and a proof of ownership.
27	///
28	/// The given `owner` is the account that will call `set_keys` using the returned session keys
29	/// and proof. This means that the proof should prove the ownership of `owner` over the private
30	/// keys associated to the session keys.
31	fn generate_session_keys_and_proof(owner: Self::AccountId) -> (Self::Keys, Vec<u8>);
32}
33
34#[benchmarks]
35mod benchmarks {
36	use super::*;
37
38	#[benchmark]
39	fn set_keys() -> Result<(), BenchmarkError> {
40		let caller: T::AccountId = whitelisted_caller();
41		frame_system::Pallet::<T>::inc_providers(&caller);
42		let (keys, proof) = T::generate_session_keys_and_proof(caller.clone());
43
44		<pallet_session::Pallet<T>>::ensure_can_pay_key_deposit(&caller).unwrap();
45
46		#[extrinsic_call]
47		_(RawOrigin::Signed(caller), keys, proof);
48
49		Ok(())
50	}
51
52	#[benchmark]
53	fn purge_keys() -> Result<(), BenchmarkError> {
54		let caller: T::AccountId = whitelisted_caller();
55		frame_system::Pallet::<T>::inc_providers(&caller);
56		let (keys, proof) = T::generate_session_keys_and_proof(caller.clone());
57		<pallet_session::Pallet<T>>::ensure_can_pay_key_deposit(&caller).unwrap();
58
59		let _t = pallet_session::Pallet::<T>::set_keys(
60			RawOrigin::Signed(caller.clone()).into(),
61			keys,
62			proof,
63		);
64
65		#[extrinsic_call]
66		_(RawOrigin::Signed(caller));
67
68		Ok(())
69	}
70}