Skip to content

Commit a0ffb6a

Browse files
committed
bring in utility pallet code
1 parent fb8ce6a commit a0ffb6a

File tree

8 files changed

+1831
-5
lines changed

8 files changed

+1831
-5
lines changed

Cargo.lock

Lines changed: 36 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk.git", tag
112112
pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
113113
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409" }
114114
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
115-
pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
115+
#pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
116+
pallet-utility = { path = "pallets/utility", default-features = false }
117+
pallet-root-testing = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
116118

117119
sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409" }
118120
sc-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409" }

pallets/utility/Cargo.toml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[package]
2+
name = "pallet-utility"
3+
version = "38.0.0"
4+
edition = "2021"
5+
license = "Apache-2.0"
6+
description = "FRAME utilities pallet"
7+
readme = "README.md"
8+
9+
[lints]
10+
workspace = true
11+
12+
[package.metadata.docs.rs]
13+
targets = ["x86_64-unknown-linux-gnu"]
14+
15+
[dependencies]
16+
codec = { workspace = true }
17+
scale-info = { features = ["derive"], workspace = true }
18+
frame-benchmarking = { workspace = true, default-features = false, optional = true }
19+
frame-support = { workspace = true, default-features = false }
20+
frame-system = { workspace = true, default-features = false }
21+
sp-core = { workspace = true, default-features = false }
22+
sp-io = { workspace = true, default-features = false}
23+
sp-runtime = { workspace = true, default-features = false}
24+
25+
[dev-dependencies]
26+
pallet-balances = { default-features = true, workspace = true }
27+
pallet-collective = { default-features = false, path = "../collective" }
28+
pallet-timestamp = { default-features = true, workspace = true }
29+
sp-core = { default-features = true, workspace = true }
30+
pallet-root-testing = { workspace = true, default-features = false }
31+
32+
[features]
33+
default = ["std"]
34+
std = [
35+
"codec/std",
36+
"frame-benchmarking?/std",
37+
"frame-support/std",
38+
"frame-system/std",
39+
"scale-info/std",
40+
"sp-core/std",
41+
"sp-io/std",
42+
"sp-runtime/std",
43+
]
44+
runtime-benchmarks = [
45+
"frame-benchmarking/runtime-benchmarks",
46+
"frame-support/runtime-benchmarks",
47+
"frame-system/runtime-benchmarks",
48+
"sp-runtime/runtime-benchmarks",
49+
]
50+
try-runtime = [
51+
"frame-support/try-runtime",
52+
"frame-system/try-runtime",
53+
"sp-runtime/try-runtime",
54+
]

pallets/utility/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Utility Module
2+
A stateless module with helpers for dispatch management which does no re-authentication.
3+
4+
- [`utility::Config`](https://docs.rs/pallet-utility/latest/pallet_utility/pallet/trait.Config.html)
5+
- [`Call`](https://docs.rs/pallet-utility/latest/pallet_utility/pallet/enum.Call.html)
6+
7+
## Overview
8+
9+
This module contains two basic pieces of functionality:
10+
- Batch dispatch: A stateless operation, allowing any origin to execute multiple calls in a
11+
single dispatch. This can be useful to amalgamate proposals, combining `set_code` with
12+
corresponding `set_storage`s, for efficient multiple payouts with just a single signature
13+
verify, or in combination with one of the other two dispatch functionality.
14+
- Pseudonymal dispatch: A stateless operation, allowing a signed origin to execute a call from
15+
an alternative signed origin. Each account has 2 * 2**16 possible "pseudonyms" (alternative
16+
account IDs) and these can be stacked. This can be useful as a key management tool, where you
17+
need multiple distinct accounts (e.g. as controllers for many staking accounts), but where
18+
it's perfectly fine to have each of them controlled by the same underlying keypair.
19+
Derivative accounts are, for the purposes of proxy filtering considered exactly the same as
20+
the origin and are thus hampered with the origin's filters.
21+
22+
Since proxy filters are respected in all dispatches of this module, it should never need to be
23+
filtered by any proxy.
24+
25+
## Interface
26+
27+
### Dispatchable Functions
28+
29+
#### For batch dispatch
30+
- `batch` - Dispatch multiple calls from the sender's origin.
31+
32+
#### For pseudonymal dispatch
33+
- `as_derivative` - Dispatch a call from a derivative signed origin.
34+
35+
[`Call`]: ./enum.Call.html
36+
[`Config`]: ./trait.Config.html
37+
38+
License: Apache-2.0
39+
40+
41+
## Release
42+
43+
Polkadot SDK stable2409
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
// Benchmarks for Utility Pallet
19+
20+
#![cfg(feature = "runtime-benchmarks")]
21+
22+
use super::*;
23+
use alloc::{vec, vec::Vec};
24+
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
25+
use frame_system::RawOrigin;
26+
27+
const SEED: u32 = 0;
28+
29+
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
30+
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
31+
}
32+
33+
benchmarks! {
34+
where_clause { where <T::RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin: Clone }
35+
batch {
36+
let c in 0 .. 1000;
37+
let mut calls: Vec<<T as Config>::RuntimeCall> = Vec::new();
38+
for i in 0 .. c {
39+
let call = frame_system::Call::remark { remark: vec![] }.into();
40+
calls.push(call);
41+
}
42+
let caller = whitelisted_caller();
43+
}: _(RawOrigin::Signed(caller), calls)
44+
verify {
45+
assert_last_event::<T>(Event::BatchCompleted.into())
46+
}
47+
48+
as_derivative {
49+
let caller = account("caller", SEED, SEED);
50+
let call = Box::new(frame_system::Call::remark { remark: vec![] }.into());
51+
// Whitelist caller account from further DB operations.
52+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
53+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
54+
}: _(RawOrigin::Signed(caller), SEED as u16, call)
55+
56+
batch_all {
57+
let c in 0 .. 1000;
58+
let mut calls: Vec<<T as Config>::RuntimeCall> = Vec::new();
59+
for i in 0 .. c {
60+
let call = frame_system::Call::remark { remark: vec![] }.into();
61+
calls.push(call);
62+
}
63+
let caller = whitelisted_caller();
64+
}: _(RawOrigin::Signed(caller), calls)
65+
verify {
66+
assert_last_event::<T>(Event::BatchCompleted.into())
67+
}
68+
69+
dispatch_as {
70+
let caller = account("caller", SEED, SEED);
71+
let call = Box::new(frame_system::Call::remark { remark: vec![] }.into());
72+
let origin: T::RuntimeOrigin = RawOrigin::Signed(caller).into();
73+
let pallets_origin: <T::RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin = origin.caller().clone();
74+
let pallets_origin = Into::<T::PalletsOrigin>::into(pallets_origin);
75+
}: _(RawOrigin::Root, Box::new(pallets_origin), call)
76+
77+
force_batch {
78+
let c in 0 .. 1000;
79+
let mut calls: Vec<<T as Config>::RuntimeCall> = Vec::new();
80+
for i in 0 .. c {
81+
let call = frame_system::Call::remark { remark: vec![] }.into();
82+
calls.push(call);
83+
}
84+
let caller = whitelisted_caller();
85+
}: _(RawOrigin::Signed(caller), calls)
86+
verify {
87+
assert_last_event::<T>(Event::BatchCompleted.into())
88+
}
89+
90+
impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::Test);
91+
}

0 commit comments

Comments
 (0)