forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from mangata-finance/feature/multiswaps
Added DisallowedInBatch to utility
- Loading branch information
Showing
11 changed files
with
1,613 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[package] | ||
name = "pallet-utility-mangata" | ||
version = "4.0.0-dev" | ||
authors = ["Parity Technologies <[email protected]>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
homepage = "https://substrate.io" | ||
repository = "https://github.com/paritytech/substrate/" | ||
description = "FRAME utilities pallet" | ||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } | ||
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-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" } | ||
sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } | ||
sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" } | ||
sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" } | ||
|
||
[dev-dependencies] | ||
pallet-balances = { version = "4.0.0-dev", path = "../balances" } | ||
sp-core = { version = "6.0.0", path = "../../primitives/core" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"frame-benchmarking?/std", | ||
"codec/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"scale-info/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
] | ||
try-runtime = [ | ||
"frame-system/try-runtime", | ||
"frame-support/try-runtime" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Utility Module | ||
A stateless module with helpers for dispatch management which does no re-authentication. | ||
|
||
- [`utility::Config`](https://docs.rs/pallet-utility/latest/pallet_utility/trait.Config.html) | ||
- [`Call`](https://docs.rs/pallet-utility/latest/pallet_utility/enum.Call.html) | ||
|
||
## Overview | ||
|
||
This module contains two basic pieces of functionality: | ||
- Batch dispatch: A stateless operation, allowing any origin to execute multiple calls in a | ||
single dispatch. This can be useful to amalgamate proposals, combining `set_code` with | ||
corresponding `set_storage`s, for efficient multiple payouts with just a single signature | ||
verify, or in combination with one of the other two dispatch functionality. | ||
- Pseudonymal dispatch: A stateless operation, allowing a signed origin to execute a call from | ||
an alternative signed origin. Each account has 2 * 2**16 possible "pseudonyms" (alternative | ||
account IDs) and these can be stacked. This can be useful as a key management tool, where you | ||
need multiple distinct accounts (e.g. as controllers for many staking accounts), but where | ||
it's perfectly fine to have each of them controlled by the same underlying keypair. | ||
Derivative accounts are, for the purposes of proxy filtering considered exactly the same as | ||
the oigin and are thus hampered with the origin's filters. | ||
|
||
Since proxy filters are respected in all dispatches of this module, it should never need to be | ||
filtered by any proxy. | ||
|
||
## Interface | ||
|
||
### Dispatchable Functions | ||
|
||
#### For batch dispatch | ||
* `batch` - Dispatch multiple calls from the sender's origin. | ||
|
||
#### For pseudonymal dispatch | ||
* `as_derivative` - Dispatch a call from a derivative signed origin. | ||
|
||
[`Call`]: ./enum.Call.html | ||
[`Config`]: ./trait.Config.html | ||
|
||
License: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2019-2022 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 Utility Pallet | ||
|
||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
use frame_benchmarking::{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! { | ||
where_clause { where <T::RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin: Clone } | ||
batch { | ||
let c in 0 .. 1000; | ||
let mut calls: Vec<<T as Config>::RuntimeCall> = Vec::new(); | ||
for i in 0 .. c { | ||
let call = frame_system::Call::remark { remark: vec![] }.into(); | ||
calls.push(call); | ||
} | ||
let caller = whitelisted_caller(); | ||
}: _(RawOrigin::Signed(caller), calls) | ||
verify { | ||
assert_last_event::<T>(Event::BatchCompleted.into()) | ||
} | ||
|
||
as_derivative { | ||
let caller = account("caller", SEED, SEED); | ||
let call = Box::new(frame_system::Call::remark { remark: vec![] }.into()); | ||
// Whitelist caller account from further DB operations. | ||
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller); | ||
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); | ||
}: _(RawOrigin::Signed(caller), SEED as u16, call) | ||
|
||
batch_all { | ||
let c in 0 .. 1000; | ||
let mut calls: Vec<<T as Config>::RuntimeCall> = Vec::new(); | ||
for i in 0 .. c { | ||
let call = frame_system::Call::remark { remark: vec![] }.into(); | ||
calls.push(call); | ||
} | ||
let caller = whitelisted_caller(); | ||
}: _(RawOrigin::Signed(caller), calls) | ||
verify { | ||
assert_last_event::<T>(Event::BatchCompleted.into()) | ||
} | ||
|
||
dispatch_as { | ||
let caller = account("caller", SEED, SEED); | ||
let call = Box::new(frame_system::Call::remark { remark: vec![] }.into()); | ||
let origin: T::RuntimeOrigin = RawOrigin::Signed(caller).into(); | ||
let pallets_origin: <T::RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin = origin.caller().clone(); | ||
let pallets_origin = Into::<T::PalletsOrigin>::into(pallets_origin); | ||
}: _(RawOrigin::Root, Box::new(pallets_origin), call) | ||
|
||
force_batch { | ||
let c in 0 .. 1000; | ||
let mut calls: Vec<<T as Config>::RuntimeCall> = Vec::new(); | ||
for i in 0 .. c { | ||
let call = frame_system::Call::remark { remark: vec![] }.into(); | ||
calls.push(call); | ||
} | ||
let caller = whitelisted_caller(); | ||
}: _(RawOrigin::Signed(caller), calls) | ||
verify { | ||
assert_last_event::<T>(Event::BatchCompleted.into()) | ||
} | ||
|
||
impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::Test); | ||
} |
Oops, something went wrong.