Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 20 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ members = [
"frame/uniques",
"frame/utility",
"frame/vesting",
"frame/whitelist",
"primitives/api",
"primitives/api/proc-macro",
"primitives/api/test",
Expand Down
3 changes: 3 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pallet-asset-tx-payment = { version = "4.0.0-dev", default-features = false, pat
pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, path = "../../../frame/transaction-storage" }
pallet-uniques = { version = "4.0.0-dev", default-features = false, path = "../../../frame/uniques" }
pallet-vesting = { version = "4.0.0-dev", default-features = false, path = "../../../frame/vesting" }
pallet-whitelist = { version = "4.0.0-dev", default-features = false, path = "../../../frame/whitelist" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-builder" }
Expand Down Expand Up @@ -220,6 +221,7 @@ runtime-benchmarks = [
"pallet-utility/runtime-benchmarks",
"pallet-uniques/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-whitelist/runtime-benchmarks",
"frame-system-benchmarking",
"hex-literal",
]
Expand Down Expand Up @@ -267,6 +269,7 @@ try-runtime = [
"pallet-uniques/try-runtime",
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
"pallet-whitelist/try-runtime",
]
# Make contract callable functions marked as __unstable__ available. Do not enable
# on live chains as those are subject to change.
Expand Down
11 changes: 11 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,15 @@ impl pallet_transaction_storage::Config for Runtime {
type WeightInfo = pallet_transaction_storage::weights::SubstrateWeight<Runtime>;
}

impl pallet_whitelist::Config for Runtime {
type Event = Event;
type Call = Call;
type WhitelistOrigin = EnsureRoot<AccountId>;
type DispatchWhitelistedOrigin = EnsureRoot<AccountId>;
type PreimageProvider = Preimage;
type WeightInfo = pallet_whitelist::weights::SubstrateWeight<Runtime>;
}

construct_runtime!(
pub enum Runtime where
Block = Block,
Expand Down Expand Up @@ -1411,6 +1420,7 @@ construct_runtime!(
ChildBounties: pallet_child_bounties,
Referenda: pallet_referenda,
ConvictionVoting: pallet_conviction_voting,
Whitelist: pallet_whitelist,
}
);

Expand Down Expand Up @@ -1509,6 +1519,7 @@ mod benches {
[pallet_uniques, Uniques]
[pallet_utility, Utility]
[pallet_vesting, Vesting]
[pallet_whitelist, Whitelist]
);
}

Expand Down
2 changes: 1 addition & 1 deletion frame/conviction-voting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "pallet-conviction-voting"
version = "4.0.0-dev"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
Expand Down
2 changes: 1 addition & 1 deletion frame/referenda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "pallet-referenda"
version = "4.0.0-dev"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
Expand Down
47 changes: 47 additions & 0 deletions frame/whitelist/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "pallet-whitelist"
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 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 = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.0", default-features = false, features = ["derive"] }
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" }
sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" }
sp-io = { version = "5.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "5.0.0", 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 = "5.0.0", 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"]
120 changes: 120 additions & 0 deletions frame/whitelist/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// 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 core::convert::TryInto;
use frame_benchmarking::benchmarks;
use frame_support::{ensure, traits::PreimageRecipient};
use sp_runtime::traits::Hash;

#[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),
"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),
"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_len = <T::PreimageProvider as PreimageRecipient<_>>::MaxSize::get() - 10;
let remark = sp_std::vec![1_8; remark_len as usize];

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),
"preimage still requested"
);
}

dispatch_whitelisted_call_with_preimage {
let n in 1 .. 10_000;

let origin = T::DispatchWhitelistedOrigin::successful_origin();
let remark = sp_std::vec![1u8; n as usize];

let call: <T as Config>::Call = frame_system::Call::remark { remark }.into();
let call_hash = T::Hashing::hash_of(&call);

Pallet::<T>::whitelist_call(origin.clone(), call_hash)
.expect("whitelisting call must be successful");
}: _<T::Origin>(origin, Box::new(call))
verify {
ensure!(
!WhitelistedCall::<T>::contains_key(call_hash),
"whitelist not removed"
);
ensure!(
!T::PreimageProvider::preimage_requested(&call_hash),
"preimage still requested"
);
}

impl_benchmark_test_suite!(Whitelist, crate::mock::new_test_ext(), crate::mock::Test);
}
Loading