Skip to content

Commit 9e1039e

Browse files
ggwpezbkchr
authored andcommitted
Add sudo::remove_key (#2165)
Changes: - Adds a new call `remove_key` to the sudo pallet to permanently remove the sudo key. - Remove some clones and general maintenance --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: command-bot <>
1 parent 8af08e7 commit 9e1039e

File tree

8 files changed

+240
-160
lines changed

8 files changed

+240
-160
lines changed

polkadot/runtime/rococo/src/weights/pallet_sudo.rs

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,25 @@
1717
//! Autogenerated weights for `pallet_sudo`
1818
//!
1919
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
20-
//! DATE: 2023-05-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
20+
//! DATE: 2023-11-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
2121
//! WORST CASE MAP SIZE: `1000000`
22-
//! HOSTNAME: `bm5`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
23-
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("rococo-dev"), DB CACHE: 1024
22+
//! HOSTNAME: `runner-yprdrvc7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
23+
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024
2424
2525
// Executed Command:
26-
// ./target/production/polkadot
26+
// target/production/polkadot
2727
// benchmark
2828
// pallet
29-
// --chain=rococo-dev
3029
// --steps=50
3130
// --repeat=20
32-
// --pallet=pallet_sudo
3331
// --extrinsic=*
34-
// --execution=wasm
3532
// --wasm-execution=compiled
36-
// --header=./file_header.txt
37-
// --output=./runtime/rococo/src/weights/
33+
// --heap-pages=4096
34+
// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json
35+
// --pallet=pallet_sudo
36+
// --chain=rococo-dev
37+
// --header=./polkadot/file_header.txt
38+
// --output=./polkadot/runtime/rococo/src/weights/
3839

3940
#![cfg_attr(rustfmt, rustfmt_skip)]
4041
#![allow(unused_parens)]
@@ -47,38 +48,50 @@ use core::marker::PhantomData;
4748
/// Weight functions for `pallet_sudo`.
4849
pub struct WeightInfo<T>(PhantomData<T>);
4950
impl<T: frame_system::Config> pallet_sudo::WeightInfo for WeightInfo<T> {
50-
/// Storage: Sudo Key (r:1 w:1)
51-
/// Proof: Sudo Key (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
51+
/// Storage: `Sudo::Key` (r:1 w:1)
52+
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
5253
fn set_key() -> Weight {
5354
// Proof Size summary in bytes:
5455
// Measured: `132`
5556
// Estimated: `1517`
56-
// Minimum execution time: 13_047_000 picoseconds.
57-
Weight::from_parts(13_325_000, 0)
57+
// Minimum execution time: 8_432_000 picoseconds.
58+
Weight::from_parts(8_757_000, 0)
5859
.saturating_add(Weight::from_parts(0, 1517))
5960
.saturating_add(T::DbWeight::get().reads(1))
6061
.saturating_add(T::DbWeight::get().writes(1))
6162
}
62-
/// Storage: Sudo Key (r:1 w:0)
63-
/// Proof: Sudo Key (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
63+
/// Storage: `Sudo::Key` (r:1 w:0)
64+
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
6465
fn sudo() -> Weight {
6566
// Proof Size summary in bytes:
6667
// Measured: `132`
6768
// Estimated: `1517`
68-
// Minimum execution time: 13_250_000 picoseconds.
69-
Weight::from_parts(13_544_000, 0)
69+
// Minimum execution time: 9_167_000 picoseconds.
70+
Weight::from_parts(9_397_000, 0)
7071
.saturating_add(Weight::from_parts(0, 1517))
7172
.saturating_add(T::DbWeight::get().reads(1))
7273
}
73-
/// Storage: Sudo Key (r:1 w:0)
74-
/// Proof: Sudo Key (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
74+
/// Storage: `Sudo::Key` (r:1 w:0)
75+
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
7576
fn sudo_as() -> Weight {
7677
// Proof Size summary in bytes:
7778
// Measured: `132`
7879
// Estimated: `1517`
79-
// Minimum execution time: 13_424_000 picoseconds.
80-
Weight::from_parts(13_801_000, 0)
80+
// Minimum execution time: 9_133_000 picoseconds.
81+
Weight::from_parts(9_573_000, 0)
8182
.saturating_add(Weight::from_parts(0, 1517))
8283
.saturating_add(T::DbWeight::get().reads(1))
8384
}
85+
/// Storage: `Sudo::Key` (r:1 w:1)
86+
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
87+
fn remove_key() -> Weight {
88+
// Proof Size summary in bytes:
89+
// Measured: `132`
90+
// Estimated: `1517`
91+
// Minimum execution time: 7_374_000 picoseconds.
92+
Weight::from_parts(7_702_000, 0)
93+
.saturating_add(Weight::from_parts(0, 1517))
94+
.saturating_add(T::DbWeight::get().reads(1))
95+
.saturating_add(T::DbWeight::get().writes(1))
96+
}
8497
}

polkadot/runtime/westend/src/weights/pallet_sudo.rs

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,25 @@
1717
//! Autogenerated weights for `pallet_sudo`
1818
//!
1919
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
20-
//! DATE: 2023-06-14, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
20+
//! DATE: 2023-11-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
2121
//! WORST CASE MAP SIZE: `1000000`
22-
//! HOSTNAME: `runner--ss9ysm1-project-163-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
23-
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 1024
22+
//! HOSTNAME: `runner-yprdrvc7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
23+
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("westend-dev")`, DB CACHE: 1024
2424
2525
// Executed Command:
26-
// ./target/production/polkadot
26+
// target/production/polkadot
2727
// benchmark
2828
// pallet
29-
// --chain=westend-dev
3029
// --steps=50
3130
// --repeat=20
32-
// --no-storage-info
33-
// --no-median-slopes
34-
// --no-min-squares
35-
// --pallet=pallet_sudo
3631
// --extrinsic=*
37-
// --execution=wasm
3832
// --wasm-execution=compiled
39-
// --header=./file_header.txt
40-
// --output=./runtime/westend/src/weights/
33+
// --heap-pages=4096
34+
// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json
35+
// --pallet=pallet_sudo
36+
// --chain=westend-dev
37+
// --header=./polkadot/file_header.txt
38+
// --output=./polkadot/runtime/westend/src/weights/
4139

4240
#![cfg_attr(rustfmt, rustfmt_skip)]
4341
#![allow(unused_parens)]
@@ -50,38 +48,50 @@ use core::marker::PhantomData;
5048
/// Weight functions for `pallet_sudo`.
5149
pub struct WeightInfo<T>(PhantomData<T>);
5250
impl<T: frame_system::Config> pallet_sudo::WeightInfo for WeightInfo<T> {
53-
/// Storage: Sudo Key (r:1 w:1)
54-
/// Proof: Sudo Key (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
51+
/// Storage: `Sudo::Key` (r:1 w:1)
52+
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
5553
fn set_key() -> Weight {
5654
// Proof Size summary in bytes:
5755
// Measured: `132`
5856
// Estimated: `1517`
59-
// Minimum execution time: 12_360_000 picoseconds.
60-
Weight::from_parts(12_803_000, 0)
57+
// Minimum execution time: 8_750_000 picoseconds.
58+
Weight::from_parts(9_102_000, 0)
6159
.saturating_add(Weight::from_parts(0, 1517))
6260
.saturating_add(T::DbWeight::get().reads(1))
6361
.saturating_add(T::DbWeight::get().writes(1))
6462
}
65-
/// Storage: Sudo Key (r:1 w:0)
66-
/// Proof: Sudo Key (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
63+
/// Storage: `Sudo::Key` (r:1 w:0)
64+
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
6765
fn sudo() -> Weight {
6866
// Proof Size summary in bytes:
6967
// Measured: `132`
7068
// Estimated: `1517`
71-
// Minimum execution time: 12_158_000 picoseconds.
72-
Weight::from_parts(12_506_000, 0)
69+
// Minimum execution time: 9_607_000 picoseconds.
70+
Weight::from_parts(10_139_000, 0)
7371
.saturating_add(Weight::from_parts(0, 1517))
7472
.saturating_add(T::DbWeight::get().reads(1))
7573
}
76-
/// Storage: Sudo Key (r:1 w:0)
77-
/// Proof: Sudo Key (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
74+
/// Storage: `Sudo::Key` (r:1 w:0)
75+
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
7876
fn sudo_as() -> Weight {
7977
// Proof Size summary in bytes:
8078
// Measured: `132`
8179
// Estimated: `1517`
82-
// Minimum execution time: 12_286_000 picoseconds.
83-
Weight::from_parts(12_664_000, 0)
80+
// Minimum execution time: 9_886_000 picoseconds.
81+
Weight::from_parts(10_175_000, 0)
8482
.saturating_add(Weight::from_parts(0, 1517))
8583
.saturating_add(T::DbWeight::get().reads(1))
8684
}
85+
/// Storage: `Sudo::Key` (r:1 w:1)
86+
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
87+
fn remove_key() -> Weight {
88+
// Proof Size summary in bytes:
89+
// Measured: `132`
90+
// Estimated: `1517`
91+
// Minimum execution time: 7_843_000 picoseconds.
92+
Weight::from_parts(8_152_000, 0)
93+
.saturating_add(Weight::from_parts(0, 1517))
94+
.saturating_add(T::DbWeight::get().reads(1))
95+
.saturating_add(T::DbWeight::get().writes(1))
96+
}
8797
}

prdoc/pr_2165.prdoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
title: Add sudo::remove_key
2+
3+
doc:
4+
- audience: Core Dev
5+
description: |
6+
Pallet `Sudo` now has the ability to remove the sudo key via `remove_key`. This is a less-invasive way of rendering the sudo pallet useless without needing a code upgrade.
7+
8+
migrations:
9+
db: []
10+
11+
runtime: []
12+
13+
crates:
14+
- name: pallet-sudo
15+
semver: minor
16+
17+
host_functions: []

substrate/frame/sudo/src/benchmarking.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,57 +22,67 @@ use crate::Pallet;
2222
use frame_benchmarking::v2::*;
2323
use frame_system::RawOrigin;
2424

25-
const SEED: u32 = 0;
26-
27-
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
28-
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
25+
fn assert_last_event<T: Config>(generic_event: crate::Event<T>) {
26+
let re: <T as Config>::RuntimeEvent = generic_event.into();
27+
frame_system::Pallet::<T>::assert_last_event(re.into());
2928
}
3029

31-
#[benchmarks( where <T as Config>::RuntimeCall: From<frame_system::Call<T>>)]
30+
#[benchmarks(where <T as Config>::RuntimeCall: From<frame_system::Call<T>>)]
3231
mod benchmarks {
3332
use super::*;
3433

3534
#[benchmark]
3635
fn set_key() {
3736
let caller: T::AccountId = whitelisted_caller();
38-
Key::<T>::put(caller.clone());
37+
Key::<T>::put(&caller);
3938

40-
let new_sudoer: T::AccountId = account("sudoer", 0, SEED);
39+
let new_sudoer: T::AccountId = account("sudoer", 0, 0);
4140
let new_sudoer_lookup = T::Lookup::unlookup(new_sudoer.clone());
4241

4342
#[extrinsic_call]
4443
_(RawOrigin::Signed(caller.clone()), new_sudoer_lookup);
4544

46-
assert_last_event::<T>(Event::KeyChanged { old_sudoer: Some(caller) }.into());
45+
assert_last_event::<T>(Event::KeyChanged { old: Some(caller), new: new_sudoer });
4746
}
4847

4948
#[benchmark]
5049
fn sudo() {
5150
let caller: T::AccountId = whitelisted_caller();
52-
Key::<T>::put(caller.clone());
51+
Key::<T>::put(&caller);
5352

54-
let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
53+
let call = frame_system::Call::remark { remark: vec![] }.into();
5554

5655
#[extrinsic_call]
57-
_(RawOrigin::Signed(caller.clone()), Box::new(call.clone()));
56+
_(RawOrigin::Signed(caller), Box::new(call));
5857

59-
assert_last_event::<T>(Event::Sudid { sudo_result: Ok(()) }.into())
58+
assert_last_event::<T>(Event::Sudid { sudo_result: Ok(()) })
6059
}
6160

6261
#[benchmark]
6362
fn sudo_as() {
6463
let caller: T::AccountId = whitelisted_caller();
6564
Key::<T>::put(caller.clone());
6665

67-
let call: <T as Config>::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
66+
let call = frame_system::Call::remark { remark: vec![] }.into();
67+
68+
let who: T::AccountId = account("as", 0, 0);
69+
let who_lookup = T::Lookup::unlookup(who);
70+
71+
#[extrinsic_call]
72+
_(RawOrigin::Signed(caller), who_lookup, Box::new(call));
73+
74+
assert_last_event::<T>(Event::SudoAsDone { sudo_result: Ok(()) })
75+
}
6876

69-
let who: T::AccountId = account("as", 0, SEED);
70-
let who_lookup = T::Lookup::unlookup(who.clone());
77+
#[benchmark]
78+
fn remove_key() {
79+
let caller: T::AccountId = whitelisted_caller();
80+
Key::<T>::put(&caller);
7181

7282
#[extrinsic_call]
73-
_(RawOrigin::Signed(caller), who_lookup, Box::new(call.clone()));
83+
_(RawOrigin::Signed(caller.clone()));
7484

75-
assert_last_event::<T>(Event::SudoAsDone { sudo_result: Ok(()) }.into())
85+
assert_last_event::<T>(Event::KeyRemoved {});
7686
}
7787

7888
impl_benchmark_test_suite!(Pallet, crate::mock::new_bench_ext(), crate::mock::Test);

0 commit comments

Comments
 (0)