Remove Filter and use Contains instead (#9514)

* Remove Filter and use Contains instead

* Fixes

* Formatting

* Update docs/Upgrading-2.0-to-3.0.md

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Typo

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Gavin Wood
2021-08-07 21:26:40 +02:00
committed by GitHub
parent e251d1cedb
commit bdda3ed612
79 changed files with 199 additions and 199 deletions
@@ -28,7 +28,7 @@ parameter_types! {
}
impl system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -144,7 +144,7 @@ parameter_types! {
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
+4 -4
View File
@@ -26,8 +26,8 @@ use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
construct_runtime, parameter_types,
traits::{
AllowAll, Currency, DenyAll, Imbalance, InstanceFilter, KeyOwnerProofSystem,
LockIdentifier, OnUnbalanced, U128CurrencyToVote,
Currency, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
Nothing, OnUnbalanced, U128CurrencyToVote,
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
@@ -192,7 +192,7 @@ parameter_types! {
const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());
impl frame_system::Config for Runtime {
type BaseCallFilter = AllowAll;
type BaseCallFilter = Everything;
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
type DbWeight = RocksDbWeight;
@@ -857,7 +857,7 @@ impl pallet_contracts::Config for Runtime {
/// and make sure they are stable. Dispatchables exposed to contracts are not allowed to
/// change because that would break already deployed contracts. The `Call` structure itself
/// is not allowed to change the indices of existing pallets, too.
type CallFilter = DenyAll;
type CallFilter = Nothing;
type RentPayment = ();
type SignedClaimHandicap = SignedClaimHandicap;
type TombstoneDeposit = TombstoneDeposit;
+1 -1
View File
@@ -46,7 +46,7 @@ parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
+1 -1
View File
@@ -31,7 +31,7 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -55,7 +55,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -202,7 +202,7 @@ mod tests {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -435,7 +435,7 @@ mod tests {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -74,7 +74,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -50,7 +50,7 @@ parameter_types! {
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -52,7 +52,7 @@ parameter_types! {
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
@@ -54,7 +54,7 @@ parameter_types! {
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -87,7 +87,7 @@ frame_support::construct_runtime!(
);
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -87,7 +87,7 @@ frame_support::construct_runtime!(
);
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -59,7 +59,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -1011,7 +1011,7 @@ mod tests {
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+2 -2
View File
@@ -26,7 +26,7 @@ use frame_support::{
dispatch::{DispatchError, DispatchResult, DispatchResultWithPostInfo, Dispatchable},
ensure,
storage::{with_transaction, TransactionOutcome},
traits::{Currency, ExistenceRequirement, Filter, Get, OriginTrait, Randomness, Time},
traits::{Contains, Currency, ExistenceRequirement, Get, OriginTrait, Randomness, Time},
weights::Weight,
DefaultNoBound,
};
@@ -1255,7 +1255,7 @@ where
fn call_runtime(&self, call: <Self::T as Config>::Call) -> DispatchResultWithPostInfo {
let mut origin: T::Origin = RawOrigin::Signed(self.address().clone()).into();
origin.add_filter(T::CallFilter::filter);
origin.add_filter(T::CallFilter::contains);
call.dispatch(origin)
}
}
+2 -2
View File
@@ -111,7 +111,7 @@ use crate::{
};
use frame_support::{
dispatch::Dispatchable,
traits::{Currency, Filter, Get, OnUnbalanced, Randomness, StorageVersion, Time},
traits::{Contains, Currency, Get, OnUnbalanced, Randomness, StorageVersion, Time},
weights::{GetDispatchInfo, PostDispatchInfo, Weight, WithPostDispatchInfo},
};
use frame_system::Pallet as System;
@@ -189,7 +189,7 @@ pub mod pallet {
/// Therefore please make sure to be restrictive about which dispatchables are allowed
/// in order to not introduce a new DoS vector like memory allocation patterns that can
/// be exploited to drive the runtime into a panic.
type CallFilter: Filter<<Self as frame_system::Config>::Call>;
type CallFilter: Contains<<Self as frame_system::Config>::Call>;
/// Handler for rent payments.
type RentPayment: OnUnbalanced<NegativeImbalanceOf<Self>>;
+4 -4
View File
@@ -33,7 +33,7 @@ use frame_support::{
dispatch::DispatchErrorWithPostInfo,
parameter_types,
storage::child,
traits::{Currency, Filter, OnInitialize, ReservableCurrency},
traits::{Contains, Currency, OnInitialize, ReservableCurrency},
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, PostDispatchInfo, Weight},
};
use frame_system::{self as system, EventRecord, Phase};
@@ -197,7 +197,7 @@ parameter_types! {
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
@@ -282,8 +282,8 @@ impl TestFilter {
}
}
impl Filter<Call> for TestFilter {
fn filter(call: &Call) -> bool {
impl Contains<Call> for TestFilter {
fn contains(call: &Call) -> bool {
CALL_FILTER.with(|fltr| fltr.borrow()(call))
}
}
+4 -4
View File
@@ -22,7 +22,7 @@ use crate as pallet_democracy;
use codec::Encode;
use frame_support::{
assert_noop, assert_ok, ord_parameter_types, parameter_types,
traits::{Filter, GenesisBuild, OnInitialize, SortedMembers},
traits::{Contains, GenesisBuild, OnInitialize, SortedMembers},
weights::Weight,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
@@ -70,8 +70,8 @@ frame_support::construct_runtime!(
// Test that a fitlered call can be dispatched.
pub struct BaseFilter;
impl Filter<Call> for BaseFilter {
fn filter(call: &Call) -> bool {
impl Contains<Call> for BaseFilter {
fn contains(call: &Call) -> bool {
!matches!(call, &Call::Balances(pallet_balances::Call::set_balance(..)))
}
}
@@ -231,7 +231,7 @@ fn set_balance_proposal(value: u64) -> Vec<u8> {
fn set_balance_proposal_is_correctly_filtered_out() {
for i in 0..10 {
let call = Call::decode(&mut &set_balance_proposal(i)[..]).unwrap();
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
}
}
@@ -195,7 +195,7 @@ pub fn witness() -> SolutionOrSnapshotSize {
impl frame_system::Config for Runtime {
type SS58Prefix = ();
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -1120,7 +1120,7 @@ mod tests {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -37,7 +37,7 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -54,7 +54,7 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -45,7 +45,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type Call = Call;
type PalletInfo = PalletInfo;
+1 -1
View File
@@ -56,7 +56,7 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -701,7 +701,7 @@ mod tests {
};
}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -51,7 +51,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
+1 -1
View File
@@ -75,7 +75,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -50,7 +50,7 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
+1 -1
View File
@@ -116,7 +116,7 @@ parameter_types! {
}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -46,7 +46,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -56,7 +56,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -499,7 +499,7 @@ mod tests {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -46,7 +46,7 @@ parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type Call = Call;
type Index = u64;
+3 -3
View File
@@ -22,7 +22,7 @@
use super::*;
use crate as pallet_multisig;
use frame_support::{assert_noop, assert_ok, parameter_types, traits::Filter};
use frame_support::{assert_noop, assert_ok, parameter_types, traits::Contains};
use sp_core::H256;
use sp_runtime::{
testing::Header,
@@ -94,8 +94,8 @@ parameter_types! {
pub const MaxSignatories: u16 = 3;
}
pub struct TestBaseCallFilter;
impl Filter<Call> for TestBaseCallFilter {
fn filter(c: &Call) -> bool {
impl Contains<Call> for TestBaseCallFilter {
fn contains(c: &Call) -> bool {
match *c {
Call::Balances(_) => true,
// Needed for benchmarking
+1 -1
View File
@@ -282,7 +282,7 @@ mod tests {
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -48,7 +48,7 @@ parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type DbWeight = ();
type BlockWeights = ();
type BlockLength = ();
@@ -40,7 +40,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -88,7 +88,7 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(2 * WEIGHT_PER_SECOND);
}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = RocksDbWeight;
+4 -3
View File
@@ -24,7 +24,8 @@ use super::*;
use crate as proxy;
use codec::{Decode, Encode};
use frame_support::{
assert_noop, assert_ok, dispatch::DispatchError, parameter_types, traits::Filter, RuntimeDebug,
assert_noop, assert_ok, dispatch::DispatchError, parameter_types, traits::Contains,
RuntimeDebug,
};
use sp_core::H256;
use sp_runtime::{
@@ -132,8 +133,8 @@ impl InstanceFilter<Call> for ProxyType {
}
}
pub struct BaseFilter;
impl Filter<Call> for BaseFilter {
fn filter(c: &Call) -> bool {
impl Contains<Call> for BaseFilter {
fn contains(c: &Call) -> bool {
match *c {
// Remark is used as a no-op call in the benchmarking
Call::System(SystemCall::remark(_)) => true,
@@ -196,7 +196,7 @@ mod tests {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = BlockLength;
type DbWeight = ();
+1 -1
View File
@@ -52,7 +52,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+9 -9
View File
@@ -833,7 +833,7 @@ mod tests {
use crate as scheduler;
use frame_support::{
assert_err, assert_noop, assert_ok, ord_parameter_types, parameter_types,
traits::{Filter, OnFinalize, OnInitialize},
traits::{Contains, OnFinalize, OnInitialize},
weights::constants::RocksDbWeight,
Hashable,
};
@@ -925,8 +925,8 @@ mod tests {
// Scheduler must dispatch with root and no filter, this tests base filter is indeed not used.
pub struct BaseFilter;
impl Filter<Call> for BaseFilter {
fn filter(call: &Call) -> bool {
impl Contains<Call> for BaseFilter {
fn contains(call: &Call) -> bool {
!matches!(call, Call::Logger(LoggerCall::log(_, _)))
}
}
@@ -1006,7 +1006,7 @@ mod tests {
fn basic_scheduling_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log(42, 1000));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_ok!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call));
run_to_block(3);
assert!(logger::log().is_empty());
@@ -1022,7 +1022,7 @@ mod tests {
new_test_ext().execute_with(|| {
run_to_block(2);
let call = Call::Logger(LoggerCall::log(42, 1000));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
// This will schedule the call 3 blocks after the next block... so block 3 + 3 = 6
assert_ok!(Scheduler::do_schedule(DispatchTime::After(3), None, 127, root(), call));
run_to_block(5);
@@ -1039,7 +1039,7 @@ mod tests {
new_test_ext().execute_with(|| {
run_to_block(2);
let call = Call::Logger(LoggerCall::log(42, 1000));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_ok!(Scheduler::do_schedule(DispatchTime::After(0), None, 127, root(), call));
// Will trigger on the next block.
run_to_block(3);
@@ -1081,7 +1081,7 @@ mod tests {
fn reschedule_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log(42, 1000));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_eq!(
Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call).unwrap(),
(4, 0)
@@ -1112,7 +1112,7 @@ mod tests {
fn reschedule_named_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log(42, 1000));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_eq!(
Scheduler::do_schedule_named(
1u32.encode(),
@@ -1154,7 +1154,7 @@ mod tests {
fn reschedule_named_perodic_works() {
new_test_ext().execute_with(|| {
let call = Call::Logger(LoggerCall::log(42, 1000));
assert!(!<Test as frame_system::Config>::BaseCallFilter::filter(&call));
assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(&call));
assert_eq!(
Scheduler::do_schedule_named(
1u32.encode(),
+1 -1
View File
@@ -58,7 +58,7 @@ ord_parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -45,7 +45,7 @@ frame_support::construct_runtime!(
);
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -234,7 +234,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -69,7 +69,7 @@ ord_parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -42,7 +42,7 @@ frame_support::construct_runtime!(
);
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -60,7 +60,7 @@
//! #### Staking
//!
//! Almost any interaction with the Staking pallet requires a process of _**bonding**_ (also known
//! as being a _staker_). To become *bonded*, a fund-holding account known as the _stash account_,
//! as being a _staker_). To become *bonded*, a fund-holding register known as the _stash account_,
//! which holds some or all of the funds that become frozen in place as part of the staking process,
//! is paired with an active **controller** account, which issues instructions on how they shall be
//! used.
+1 -1
View File
@@ -135,7 +135,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = RocksDbWeight;
+3 -3
View File
@@ -21,7 +21,7 @@ use super::*;
use crate as sudo;
use frame_support::{
parameter_types,
traits::{Filter, GenesisBuild},
traits::{Contains, GenesisBuild},
};
use frame_system::limits;
use sp_core::H256;
@@ -115,8 +115,8 @@ parameter_types! {
}
pub struct BlockEverything;
impl Filter<Call> for BlockEverything {
fn filter(_: &Call) -> bool {
impl Contains<Call> for BlockEverything {
fn contains(_: &Call) -> bool {
false
}
}
@@ -129,8 +129,8 @@ pub fn expand_outer_origin(
fn reset_filter(&mut self) {
let filter = <
<#runtime as #system_path::Config>::BaseCallFilter
as #scrate::traits::Filter<<#runtime as #system_path::Config>::Call>
>::filter;
as #scrate::traits::Contains<<#runtime as #system_path::Config>::Call>
>::contains;
self.filter = #scrate::sp_std::rc::Rc::new(Box::new(filter));
}
+1 -1
View File
@@ -2814,7 +2814,7 @@ mod tests {
type Origin = OuterOrigin;
type AccountId = u32;
type Call = ();
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockNumber = u32;
type PalletInfo = Self;
type DbWeight = ();
+5 -6
View File
@@ -31,9 +31,11 @@ pub use tokens::{
};
mod members;
#[allow(deprecated)]
pub use members::{AllowAll, DenyAll, Filter};
pub use members::{
All, AsContains, ChangeMembers, Contains, ContainsLengthBound, InitializeMembers, IsInVec,
SortedMembers,
AsContains, ChangeMembers, Contains, ContainsLengthBound, Everything, InitializeMembers,
IsInVec, Nothing, SortedMembers,
};
mod validation;
@@ -44,10 +46,7 @@ pub use validation::{
};
mod filter;
pub use filter::{
AllowAll, ClearFilterGuard, DenyAll, Filter, FilterStack, FilterStackGuard, InstanceFilter,
IntegrityTest,
};
pub use filter::{ClearFilterGuard, FilterStack, FilterStackGuard, InstanceFilter, IntegrityTest};
mod misc;
pub use misc::{
+58 -81
View File
@@ -17,34 +17,11 @@
//! Traits and associated utilities for dealing with abstract constraint filters.
pub use super::members::Contains;
use sp_std::marker::PhantomData;
/// Simple trait for providing a filter over a reference to some type.
pub trait Filter<T> {
/// Determine if a given value should be allowed through the filter (returns `true`) or not.
fn filter(_: &T) -> bool;
}
/// A [`Filter`] that allows any value.
pub enum AllowAll {}
/// A [`Filter`] that denies any value.
pub enum DenyAll {}
impl<T> Filter<T> for AllowAll {
fn filter(_: &T) -> bool {
true
}
}
impl<T> Filter<T> for DenyAll {
fn filter(_: &T) -> bool {
false
}
}
/// Trait to add a constraint onto the filter.
pub trait FilterStack<T>: Filter<T> {
pub trait FilterStack<T>: Contains<T> {
/// The type used to archive the stack.
type Stack;
@@ -135,15 +112,15 @@ macro_rules! impl_filter_stack {
mod $module {
#[allow(unused_imports)]
use super::*;
use $crate::traits::filter::{swap, take, RefCell, Vec, Box, Filter, FilterStack};
use $crate::traits::filter::{swap, take, RefCell, Vec, Box, Contains, FilterStack};
thread_local! {
static FILTER: RefCell<Vec<Box<dyn Fn(&$call) -> bool + 'static>>> = RefCell::new(Vec::new());
}
impl Filter<$call> for $target {
fn filter(call: &$call) -> bool {
<$base>::filter(call) &&
impl Contains<$call> for $target {
fn contains(call: &$call) -> bool {
<$base>::contains(call) &&
FILTER.with(|filter| filter.borrow().iter().all(|f| f(call)))
}
}
@@ -169,7 +146,7 @@ macro_rules! impl_filter_stack {
mod $module {
#[allow(unused_imports)]
use super::*;
use $crate::traits::{swap, take, RefCell, Vec, Box, Filter, FilterStack};
use $crate::traits::{swap, take, RefCell, Vec, Box, Contains, FilterStack};
struct ThisFilter(RefCell<Vec<Box<dyn Fn(&$call) -> bool + 'static>>>);
// NOTE: Safe only in wasm (guarded above) because there's only one thread.
@@ -178,9 +155,9 @@ macro_rules! impl_filter_stack {
static FILTER: ThisFilter = ThisFilter(RefCell::new(Vec::new()));
impl Filter<$call> for $target {
fn filter(call: &$call) -> bool {
<$base>::filter(call) && FILTER.0.borrow().iter().all(|f| f(call))
impl Contains<$call> for $target {
fn contains(call: &$call) -> bool {
<$base>::contains(call) && FILTER.0.borrow().iter().all(|f| f(call))
}
}
@@ -220,8 +197,8 @@ pub mod test_impl_filter_stack {
pub struct IsCallable;
pub struct BaseFilter;
impl Filter<u32> for BaseFilter {
fn filter(x: &u32) -> bool {
impl Contains<u32> for BaseFilter {
fn contains(x: &u32) -> bool {
x % 2 == 0
}
}
@@ -234,76 +211,76 @@ pub mod test_impl_filter_stack {
#[test]
fn impl_filter_stack_should_work() {
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(IsCallable::filter(&42));
assert!(!IsCallable::filter(&43));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(IsCallable::contains(&42));
assert!(!IsCallable::contains(&43));
IsCallable::push(|x| *x < 42);
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(!IsCallable::filter(&42));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(!IsCallable::contains(&42));
IsCallable::push(|x| *x % 3 == 0);
assert!(IsCallable::filter(&36));
assert!(!IsCallable::filter(&40));
assert!(IsCallable::contains(&36));
assert!(!IsCallable::contains(&40));
IsCallable::pop();
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(!IsCallable::filter(&42));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(!IsCallable::contains(&42));
let saved = IsCallable::take();
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(IsCallable::filter(&42));
assert!(!IsCallable::filter(&43));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(IsCallable::contains(&42));
assert!(!IsCallable::contains(&43));
IsCallable::restore(saved);
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(!IsCallable::filter(&42));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(!IsCallable::contains(&42));
IsCallable::pop();
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(IsCallable::filter(&42));
assert!(!IsCallable::filter(&43));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(IsCallable::contains(&42));
assert!(!IsCallable::contains(&43));
}
#[test]
fn guards_should_work() {
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(IsCallable::filter(&42));
assert!(!IsCallable::filter(&43));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(IsCallable::contains(&42));
assert!(!IsCallable::contains(&43));
{
let _guard_1 = FilterStackGuard::<IsCallable, u32>::new(|x| *x < 42);
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(!IsCallable::filter(&42));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(!IsCallable::contains(&42));
{
let _guard_2 = FilterStackGuard::<IsCallable, u32>::new(|x| *x % 3 == 0);
assert!(IsCallable::filter(&36));
assert!(!IsCallable::filter(&40));
assert!(IsCallable::contains(&36));
assert!(!IsCallable::contains(&40));
}
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(!IsCallable::filter(&42));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(!IsCallable::contains(&42));
{
let _guard_2 = ClearFilterGuard::<IsCallable, u32>::new();
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(IsCallable::filter(&42));
assert!(!IsCallable::filter(&43));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(IsCallable::contains(&42));
assert!(!IsCallable::contains(&43));
}
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(!IsCallable::filter(&42));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(!IsCallable::contains(&42));
}
assert!(IsCallable::filter(&36));
assert!(IsCallable::filter(&40));
assert!(IsCallable::filter(&42));
assert!(!IsCallable::filter(&43));
assert!(IsCallable::contains(&36));
assert!(IsCallable::contains(&40));
assert!(IsCallable::contains(&42));
assert!(!IsCallable::contains(&43));
}
}
+26 -3
View File
@@ -25,14 +25,37 @@ pub trait Contains<T> {
fn contains(t: &T) -> bool;
}
/// A `Contains` implementation which always returns `true`.
pub struct All<T>(PhantomData<T>);
impl<T> Contains<T> for All<T> {
/// A [`Contains`] implementation that contains every value.
pub enum Everything {}
impl<T> Contains<T> for Everything {
fn contains(_: &T) -> bool {
true
}
}
/// A [`Contains`] implementation that contains no value.
pub enum Nothing {}
impl<T> Contains<T> for Nothing {
fn contains(_: &T) -> bool {
false
}
}
#[deprecated = "Use `Everything` instead"]
pub type AllowAll = Everything;
#[deprecated = "Use `Nothing` instead"]
pub type DenyAll = Nothing;
#[deprecated = "Use `Contains` instead"]
pub trait Filter<T> {
fn filter(t: &T) -> bool;
}
#[allow(deprecated)]
impl<T, C: Contains<T>> Filter<T> for C {
fn filter(t: &T) -> bool {
Self::contains(t)
}
}
#[impl_trait_for_tuples::impl_for_tuples(30)]
impl<T> Contains<T> for Tuple {
fn contains(t: &T) -> bool {
@@ -229,7 +229,7 @@ pub type BlockNumber = u64;
pub type Index = u64;
impl system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Hash = H256;
type Origin = Origin;
type BlockNumber = BlockNumber;
@@ -268,14 +268,14 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature,
mod origin_test {
use super::{module3, nested, system, Block, UncheckedExtrinsic};
use frame_support::traits::{Filter, OriginTrait};
use frame_support::traits::{Contains, OriginTrait};
impl nested::module3::Config for RuntimeOriginTest {}
impl module3::Config for RuntimeOriginTest {}
pub struct BaseCallFilter;
impl Filter<Call> for BaseCallFilter {
fn filter(c: &Call) -> bool {
impl Contains<Call> for BaseCallFilter {
fn contains(c: &Call) -> bool {
match c {
Call::NestedModule3(_) => true,
_ => false,
@@ -275,7 +275,7 @@ pub type BlockNumber = u64;
pub type Index = u64;
impl system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Hash = H256;
type Origin = Origin;
type BlockNumber = BlockNumber;
@@ -157,7 +157,7 @@ pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Hash = H256;
type Origin = Origin;
type BlockNumber = BlockNumber;
+1 -1
View File
@@ -493,7 +493,7 @@ frame_support::parameter_types!(
);
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type Index = u64;
type BlockNumber = u32;
@@ -223,7 +223,7 @@ frame_support::parameter_types!(
);
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type Index = u64;
type BlockNumber = u32;
@@ -206,7 +206,7 @@ impl frame_system::Config for Runtime {
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type Index = u64;
type BlockNumber = u32;
@@ -243,7 +243,7 @@ frame_support::parameter_types!(
);
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type Index = u64;
type BlockNumber = u32;
@@ -129,7 +129,7 @@ mod tests {
}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
+1 -1
View File
@@ -25,7 +25,7 @@ pub trait Config: 'static + Eq + Clone {
type Origin: Into<Result<RawOrigin<Self::AccountId>, Self::Origin>>
+ From<RawOrigin<Self::AccountId>>;
type BaseCallFilter: frame_support::traits::Filter<Self::Call>;
type BaseCallFilter: frame_support::traits::Contains<Self::Call>;
type BlockNumber: Decode + Encode + EncodeLike + Clone + Default;
type Hash;
type AccountId: Encode + EncodeLike + Decode;
+1 -1
View File
@@ -71,7 +71,7 @@ frame_support::parameter_types! {
);
}
impl system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = BlockLength;
type DbWeight = ();
@@ -39,7 +39,7 @@ frame_support::construct_runtime!(
);
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+2 -2
View File
@@ -85,7 +85,7 @@ use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo},
storage,
traits::{
EnsureOrigin, Filter, Get, HandleLifetime, OnKilledAccount, OnNewAccount, OriginTrait,
Contains, EnsureOrigin, Get, HandleLifetime, OnKilledAccount, OnNewAccount, OriginTrait,
PalletInfo, SortedMembers, StoredMap,
},
weights::{
@@ -161,7 +161,7 @@ pub mod pallet {
pub trait Config: 'static + Eq + Clone {
/// The basic call filter to use in Origin. All origins are built with this filter as base,
/// except Root.
type BaseCallFilter: Filter<Self::Call>;
type BaseCallFilter: Contains<Self::Call>;
/// Block & extrinsics weights: base values and limits.
#[pallet::constant]
+1 -1
View File
@@ -88,7 +88,7 @@ impl OnKilledAccount<u64> for RecordKilled {
}
impl Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
type Origin = Origin;
+1 -1
View File
@@ -336,7 +336,7 @@ mod tests {
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -56,7 +56,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
@@ -742,7 +742,7 @@ mod tests {
}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
@@ -54,7 +54,7 @@ parameter_types! {
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
+1 -1
View File
@@ -56,7 +56,7 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
+1 -1
View File
@@ -46,7 +46,7 @@ parameter_types! {
pub const BlockHashCount: u64 = 250;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
+4 -4
View File
@@ -26,7 +26,7 @@ use frame_support::{
assert_err_ignore_postinfo, assert_noop, assert_ok, decl_module,
dispatch::{DispatchError, DispatchErrorWithPostInfo, Dispatchable},
parameter_types, storage,
traits::Filter,
traits::Contains,
weights::{Pays, Weight},
};
use sp_core::H256;
@@ -142,8 +142,8 @@ parameter_types! {
impl example::Config for Test {}
pub struct TestBaseCallFilter;
impl Filter<Call> for TestBaseCallFilter {
fn filter(c: &Call) -> bool {
impl Contains<Call> for TestBaseCallFilter {
fn contains(c: &Call) -> bool {
match *c {
// Transfer works. Use `transfer_keep_alive` for a call that doesn't pass the filter.
Call::Balances(pallet_balances::Call::transfer(..)) => true,
@@ -282,7 +282,7 @@ fn batch_with_root_works() {
new_test_ext().execute_with(|| {
let k = b"a".to_vec();
let call = Call::System(frame_system::Call::set_storage(vec![(k.clone(), k.clone())]));
assert!(!TestBaseCallFilter::filter(&call));
assert!(!TestBaseCallFilter::contains(&call));
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(2), 10);
assert_ok!(Utility::batch(
+1 -1
View File
@@ -48,7 +48,7 @@ parameter_types! {
impl frame_system::Config for Test {
type AccountData = pallet_balances::AccountData<u64>;
type AccountId = u64;
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockHashCount = BlockHashCount;
type BlockLength = ();
type BlockNumber = u64;
+1 -1
View File
@@ -537,7 +537,7 @@ parameter_types! {
}
impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::AllowAll;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
type Origin = Origin;