This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
722 additions
and
1 deletion.
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
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,46 @@ | ||
[package] | ||
name = "pallet-whitelist" | ||
version = "4.0.0-dev" | ||
authors = ["Parity Technologies <admin@parity.io>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
homepage = "https://substrate.io" | ||
repository = "https://github.com/paritytech/substrate/" | ||
description = "FRAME pallet for whitelisting call, and dispatch from specific origin" | ||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } | ||
scale-info = { version = "1.0", default-features = false, features = ["derive"] } | ||
sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" } | ||
sp-io = { version = "4.0.0-dev", default-features = false, path = "../../primitives/io" } | ||
sp-runtime = { version = "4.0.0-dev", default-features = false, path = "../../primitives/runtime" } | ||
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" } | ||
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" } | ||
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true } | ||
|
||
[dev-dependencies] | ||
sp-core = { version = "4.1.0-dev", path = "../../primitives/core" } | ||
pallet-preimage = { version = "4.0.0-dev", path = "../preimage/" } | ||
pallet-balances = { version = "4.0.0-dev", path = "../balances/" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"scale-info/std", | ||
"sp-std/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
] | ||
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,98 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2021 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. | ||
|
||
//! Whitelist pallet benchmarking. | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
use frame_benchmarking::benchmarks; | ||
use frame_support::{ensure, traits::PreimageRecipient}; | ||
use sp_runtime::traits::Hash; | ||
use core::convert::TryInto; | ||
|
||
#[cfg(test)] | ||
use crate::Pallet as Whitelist; | ||
|
||
benchmarks! { | ||
whitelist_call { | ||
let origin = T::WhitelistOrigin::successful_origin(); | ||
let call_hash = Default::default(); | ||
}: _<T::Origin>(origin, call_hash) | ||
verify { | ||
ensure!( | ||
WhitelistedCall::<T>::contains_key(call_hash), | ||
"call not whitelisted" | ||
); | ||
ensure!( | ||
T::PreimageProvider::preimage_requested(&call_hash) == true, | ||
"preimage not requested" | ||
); | ||
} | ||
|
||
remove_whitelisted_call { | ||
let origin = T::WhitelistOrigin::successful_origin(); | ||
let call_hash = Default::default(); | ||
Pallet::<T>::whitelist_call(origin.clone(), call_hash) | ||
.expect("whitelisting call must be successful"); | ||
}: _<T::Origin>(origin, call_hash) | ||
verify { | ||
ensure!( | ||
!WhitelistedCall::<T>::contains_key(call_hash), | ||
"whitelist not removed" | ||
); | ||
ensure!( | ||
T::PreimageProvider::preimage_requested(&call_hash) == false, | ||
"preimage still requested" | ||
); | ||
} | ||
|
||
// We benchmark with the maximum possible size for a call. | ||
// If the resulting weight is too big, maybe it worth having a weight which depends | ||
// on the size of the call, with a new witness in parameter. | ||
dispatch_whitelisted_call { | ||
let origin = T::DispatchWhitelistedOrigin::successful_origin(); | ||
// NOTE: we remove `10` because we need some bytes to encode the variants and vec length | ||
let remark = (0 .. <T::PreimageProvider as PreimageRecipient<_>>::MaxSize::get() - 10) | ||
.map(|_| 1u8) | ||
.collect(); | ||
|
||
let call: <T as Config>::Call = frame_system::Call::remark { remark }.into(); | ||
let call_weight = call.get_dispatch_info().weight; | ||
let encoded_call = call.encode(); | ||
let call_hash = T::Hashing::hash(&encoded_call[..]); | ||
|
||
Pallet::<T>::whitelist_call(origin.clone(), call_hash) | ||
.expect("whitelisting call must be successful"); | ||
|
||
let encoded_call = encoded_call.try_into().expect("encoded_call must be small enough"); | ||
T::PreimageProvider::note_preimage(encoded_call); | ||
|
||
}: _<T::Origin>(origin, call_hash, call_weight) | ||
verify { | ||
ensure!( | ||
!WhitelistedCall::<T>::contains_key(call_hash), | ||
"whitelist not removed" | ||
); | ||
ensure!( | ||
T::PreimageProvider::preimage_requested(&call_hash) == false, | ||
"preimage still requested" | ||
); | ||
} | ||
|
||
impl_benchmark_test_suite!(Whitelist, crate::mock::new_test_ext(), crate::mock::Test); | ||
} |
Oops, something went wrong.