Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Benchmark pallet sudo #13880

Merged
merged 24 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
086d363
set_key
Doordashcon Apr 11, 2023
0319a2f
v2
Doordashcon Apr 18, 2023
6e16a8c
Merge branch 'master' into ddc-OG
Doordashcon Apr 18, 2023
6cccbfe
update runtime
Doordashcon Apr 18, 2023
7b5817b
Merge branch 'ddc-OG' of https://github.com/Doordashcon/substrate int…
Doordashcon Apr 18, 2023
fd71be3
cargo fmt
Doordashcon Apr 18, 2023
823d98b
remove commenting
Doordashcon Apr 18, 2023
e082fec
Merge branch 'master' of https://github.com/paritytech/substrate into…
Apr 19, 2023
5078939
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_sudo
Apr 19, 2023
01a597a
impl weights
Doordashcon Apr 20, 2023
811d52d
Merge branch 'paritytech:master' into ddc-OG
Doordashcon Apr 23, 2023
fe6e0a4
Merge branch 'paritytech:master' into ddc-OG
Doordashcon Apr 24, 2023
1890456
sudo & sudo_as
Doordashcon May 1, 2023
885b7b0
Merge branch 'paritytech:master' into ddc-OG
Doordashcon May 3, 2023
28878cf
where
Doordashcon May 6, 2023
6d9d079
Merge branch 'paritytech:master' into ddc-OG
Doordashcon May 6, 2023
f931e7b
Merge branch 'paritytech:master' into ddc-OG
Doordashcon May 8, 2023
e38b8a9
Merge branch 'master' of https://github.com/paritytech/substrate into…
May 9, 2023
891a949
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_sudo
May 9, 2023
8ffafdf
update weights
Doordashcon May 9, 2023
ff180b3
cargo fmt
Doordashcon May 9, 2023
ff4405c
Merge branch 'paritytech:master' into ddc-OG
Doordashcon May 10, 2023
fc1d8af
Merge branch 'paritytech:master' into ddc-OG
Doordashcon May 10, 2023
6c3acef
Update Cargo.lock
ggwpez May 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions frame/sudo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" }
Expand All @@ -28,11 +29,17 @@ sp-core = { version = "7.0.0", path = "../../primitives/core" }
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
46 changes: 46 additions & 0 deletions frame/sudo/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This file is part of Substrate.

// Copyright (C) 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.

// Benchmarks for Sudo Pallet
Doordashcon marked this conversation as resolved.
Show resolved Hide resolved

use super::*;
use crate::Pallet;
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_system::RawOrigin;

const SEED: u32 = 0;

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}

benchmarks! {
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
set_key {

let caller: T::AccountId = whitelisted_caller();
Key::<T>::put(caller.clone());

let new_sudoer: T::AccountId = account("sudoer", 0, SEED);
let new_sudoer_lookup = T::Lookup::unlookup(new_sudoer.clone());

}: _(RawOrigin::Signed(caller.clone()), new_sudoer_lookup)
verify {
assert_last_event::<T>(Event::KeyChanged { old_sudoer: Some(caller)}.into());
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_bench_ext(), crate::mock::Test);
}
3 changes: 3 additions & 0 deletions frame/sudo/src/lib.rs
Doordashcon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ mod mock;
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

pub use extension::CheckOnlySudoAccount;
pub use pallet::*;

Expand Down
5 changes: 5 additions & 0 deletions frame/sudo/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,8 @@ pub fn new_test_ext(root_key: u64) -> sp_io::TestExternalities {
.unwrap();
t.into()
}

#[cfg(feature = "runtime-benchmarks")]
pub fn new_bench_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
}