From 9d867b6b4dd099ecef7bed1a1ff5a3441f41d684 Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Sat, 7 Aug 2021 21:26:40 +0200 Subject: [PATCH] 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 Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- .../pallets/template/src/mock.rs | 2 +- bin/node-template/runtime/src/lib.rs | 2 +- bin/node/runtime/src/lib.rs | 8 +- frame/assets/src/mock.rs | 2 +- frame/atomic-swap/src/tests.rs | 2 +- frame/aura/src/mock.rs | 2 +- frame/authority-discovery/src/lib.rs | 2 +- frame/authorship/src/lib.rs | 2 +- frame/babe/src/mock.rs | 2 +- frame/balances/src/tests_composite.rs | 2 +- frame/balances/src/tests_local.rs | 2 +- frame/balances/src/tests_reentrancy.rs | 2 +- frame/benchmarking/src/tests.rs | 2 +- frame/benchmarking/src/tests_instance.rs | 2 +- frame/bounties/src/tests.rs | 2 +- frame/collective/src/lib.rs | 2 +- frame/contracts/src/exec.rs | 4 +- frame/contracts/src/lib.rs | 4 +- frame/contracts/src/tests.rs | 8 +- frame/democracy/src/tests.rs | 8 +- .../election-provider-multi-phase/src/mock.rs | 2 +- frame/elections-phragmen/src/lib.rs | 2 +- frame/elections/src/mock.rs | 2 +- frame/example-offchain-worker/src/tests.rs | 2 +- frame/example-parallel/src/tests.rs | 2 +- frame/example/src/tests.rs | 2 +- frame/executive/src/lib.rs | 2 +- frame/gilt/src/mock.rs | 2 +- frame/grandpa/src/mock.rs | 2 +- frame/identity/src/tests.rs | 2 +- frame/im-online/src/mock.rs | 2 +- frame/indices/src/mock.rs | 2 +- frame/lottery/src/mock.rs | 2 +- frame/membership/src/lib.rs | 2 +- frame/merkle-mountain-range/src/mock.rs | 2 +- frame/multisig/src/tests.rs | 6 +- frame/nicks/src/lib.rs | 2 +- frame/node-authorization/src/mock.rs | 2 +- frame/offences/benchmarking/src/mock.rs | 2 +- frame/offences/src/mock.rs | 2 +- frame/proxy/src/tests.rs | 7 +- frame/randomness-collective-flip/src/lib.rs | 2 +- frame/recovery/src/mock.rs | 2 +- frame/scheduler/src/lib.rs | 18 +-- frame/scored-pool/src/mock.rs | 2 +- frame/session/benchmarking/src/mock.rs | 2 +- frame/session/src/mock.rs | 2 +- frame/society/src/mock.rs | 2 +- frame/staking/fuzzer/src/mock.rs | 2 +- frame/staking/src/lib.rs | 2 +- frame/staking/src/mock.rs | 2 +- frame/sudo/src/mock.rs | 6 +- .../src/construct_runtime/expand/origin.rs | 4 +- frame/support/src/dispatch.rs | 2 +- frame/support/src/traits.rs | 11 +- frame/support/src/traits/filter.rs | 139 ++++++++---------- frame/support/src/traits/members.rs | 29 +++- frame/support/test/tests/construct_runtime.rs | 8 +- frame/support/test/tests/instance.rs | 2 +- frame/support/test/tests/issue2219.rs | 2 +- frame/support/test/tests/pallet.rs | 2 +- .../test/tests/pallet_compatibility.rs | 2 +- .../tests/pallet_compatibility_instance.rs | 2 +- frame/support/test/tests/pallet_instance.rs | 2 +- .../tests/pallet_with_name_trait_is_valid.rs | 2 +- frame/support/test/tests/system.rs | 2 +- frame/system/benches/bench.rs | 2 +- frame/system/benchmarking/src/mock.rs | 2 +- frame/system/src/lib.rs | 4 +- frame/system/src/mock.rs | 2 +- frame/timestamp/src/lib.rs | 2 +- frame/tips/src/tests.rs | 2 +- frame/transaction-payment/src/lib.rs | 2 +- frame/transaction-storage/src/mock.rs | 2 +- frame/treasury/src/tests.rs | 2 +- frame/uniques/src/mock.rs | 2 +- frame/utility/src/tests.rs | 8 +- frame/vesting/src/mock.rs | 2 +- test-utils/runtime/src/lib.rs | 2 +- 79 files changed, 199 insertions(+), 199 deletions(-) diff --git a/bin/node-template/pallets/template/src/mock.rs b/bin/node-template/pallets/template/src/mock.rs index 76742477000fb..4532d3d09b497 100644 --- a/bin/node-template/pallets/template/src/mock.rs +++ b/bin/node-template/pallets/template/src/mock.rs @@ -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 = (); diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index afd31b8f7b5b8..63d79e604791d 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -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). diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 1cd41d6e6d966..7466c940d65d9 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -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; diff --git a/frame/assets/src/mock.rs b/frame/assets/src/mock.rs index e4f5763f149fe..1b2602792d844 100644 --- a/frame/assets/src/mock.rs +++ b/frame/assets/src/mock.rs @@ -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; diff --git a/frame/atomic-swap/src/tests.rs b/frame/atomic-swap/src/tests.rs index 2165b403dd35d..a76d0f20ffa3b 100644 --- a/frame/atomic-swap/src/tests.rs +++ b/frame/atomic-swap/src/tests.rs @@ -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 = (); diff --git a/frame/aura/src/mock.rs b/frame/aura/src/mock.rs index 8d604e527c99a..0e258fb9a67dc 100644 --- a/frame/aura/src/mock.rs +++ b/frame/aura/src/mock.rs @@ -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 = (); diff --git a/frame/authority-discovery/src/lib.rs b/frame/authority-discovery/src/lib.rs index e30bcb6296620..4577a9dd17226 100644 --- a/frame/authority-discovery/src/lib.rs +++ b/frame/authority-discovery/src/lib.rs @@ -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 = (); diff --git a/frame/authorship/src/lib.rs b/frame/authorship/src/lib.rs index 73efbbe30b014..43d48df464371 100644 --- a/frame/authorship/src/lib.rs +++ b/frame/authorship/src/lib.rs @@ -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 = (); diff --git a/frame/babe/src/mock.rs b/frame/babe/src/mock.rs index a034360c3fec5..f872fb23b12aa 100644 --- a/frame/babe/src/mock.rs +++ b/frame/babe/src/mock.rs @@ -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 = (); diff --git a/frame/balances/src/tests_composite.rs b/frame/balances/src/tests_composite.rs index e2d50e8b88aad..f6faebed39316 100644 --- a/frame/balances/src/tests_composite.rs +++ b/frame/balances/src/tests_composite.rs @@ -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 = (); diff --git a/frame/balances/src/tests_local.rs b/frame/balances/src/tests_local.rs index 668c335376c60..d8c07aa9c42e5 100644 --- a/frame/balances/src/tests_local.rs +++ b/frame/balances/src/tests_local.rs @@ -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 = (); diff --git a/frame/balances/src/tests_reentrancy.rs b/frame/balances/src/tests_reentrancy.rs index 8682949b2c55d..9c7ba3e1ec824 100644 --- a/frame/balances/src/tests_reentrancy.rs +++ b/frame/balances/src/tests_reentrancy.rs @@ -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 = (); diff --git a/frame/benchmarking/src/tests.rs b/frame/benchmarking/src/tests.rs index f092b41b65c3e..9cb5043a0dd7d 100644 --- a/frame/benchmarking/src/tests.rs +++ b/frame/benchmarking/src/tests.rs @@ -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 = (); diff --git a/frame/benchmarking/src/tests_instance.rs b/frame/benchmarking/src/tests_instance.rs index 221e9faa5c4ad..caccebd39c70b 100644 --- a/frame/benchmarking/src/tests_instance.rs +++ b/frame/benchmarking/src/tests_instance.rs @@ -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 = (); diff --git a/frame/bounties/src/tests.rs b/frame/bounties/src/tests.rs index 5ce1373ed9066..f945d0b2dbd2d 100644 --- a/frame/bounties/src/tests.rs +++ b/frame/bounties/src/tests.rs @@ -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 = (); diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index 0747e4e9ade0f..39da8e2c45fb7 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -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 = (); diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 16c4886746d1d..a3b48ca3bcc95 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -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: ::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) } } diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 74ab6578f797d..4860937c423ee 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -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<::Call>; + type CallFilter: Contains<::Call>; /// Handler for rent payments. type RentPayment: OnUnbalanced>; diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index db5f3ba92a70b..81d973221b6c7 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -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 for TestFilter { - fn filter(call: &Call) -> bool { +impl Contains for TestFilter { + fn contains(call: &Call) -> bool { CALL_FILTER.with(|fltr| fltr.borrow()(call)) } } diff --git a/frame/democracy/src/tests.rs b/frame/democracy/src/tests.rs index 64444304db673..46d3cade36eb1 100644 --- a/frame/democracy/src/tests.rs +++ b/frame/democracy/src/tests.rs @@ -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 for BaseFilter { - fn filter(call: &Call) -> bool { +impl Contains 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 { fn set_balance_proposal_is_correctly_filtered_out() { for i in 0..10 { let call = Call::decode(&mut &set_balance_proposal(i)[..]).unwrap(); - assert!(!::BaseCallFilter::filter(&call)); + assert!(!::BaseCallFilter::contains(&call)); } } diff --git a/frame/election-provider-multi-phase/src/mock.rs b/frame/election-provider-multi-phase/src/mock.rs index 56007f15f84af..94fdb45590274 100644 --- a/frame/election-provider-multi-phase/src/mock.rs +++ b/frame/election-provider-multi-phase/src/mock.rs @@ -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; diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 144997c60c2ee..b67680b9abcec 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -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 = (); diff --git a/frame/elections/src/mock.rs b/frame/elections/src/mock.rs index 78982f7af3988..91318e1e07bcc 100644 --- a/frame/elections/src/mock.rs +++ b/frame/elections/src/mock.rs @@ -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 = (); diff --git a/frame/example-offchain-worker/src/tests.rs b/frame/example-offchain-worker/src/tests.rs index 706569e0e18d0..d0a3664abf4ac 100644 --- a/frame/example-offchain-worker/src/tests.rs +++ b/frame/example-offchain-worker/src/tests.rs @@ -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 = (); diff --git a/frame/example-parallel/src/tests.rs b/frame/example-parallel/src/tests.rs index f67c5ae51b504..4c36f0d6eb858 100644 --- a/frame/example-parallel/src/tests.rs +++ b/frame/example-parallel/src/tests.rs @@ -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; diff --git a/frame/example/src/tests.rs b/frame/example/src/tests.rs index 18089888dba1a..645b5c9bc13ab 100644 --- a/frame/example/src/tests.rs +++ b/frame/example/src/tests.rs @@ -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 = (); diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 3e2cdd241f6df..8f857d2c8212c 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -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 = (); diff --git a/frame/gilt/src/mock.rs b/frame/gilt/src/mock.rs index 91606f1852313..ac3f4df1b71dd 100644 --- a/frame/gilt/src/mock.rs +++ b/frame/gilt/src/mock.rs @@ -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; diff --git a/frame/grandpa/src/mock.rs b/frame/grandpa/src/mock.rs index 882acdb4bcc12..b9c4858e353e8 100644 --- a/frame/grandpa/src/mock.rs +++ b/frame/grandpa/src/mock.rs @@ -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 = (); diff --git a/frame/identity/src/tests.rs b/frame/identity/src/tests.rs index 3e1219ad64f2e..c842b0e2f64be 100644 --- a/frame/identity/src/tests.rs +++ b/frame/identity/src/tests.rs @@ -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; diff --git a/frame/im-online/src/mock.rs b/frame/im-online/src/mock.rs index a04da49c6526d..e4031b04271b9 100644 --- a/frame/im-online/src/mock.rs +++ b/frame/im-online/src/mock.rs @@ -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 = (); diff --git a/frame/indices/src/mock.rs b/frame/indices/src/mock.rs index e026e36bc389d..f4c87016141b5 100644 --- a/frame/indices/src/mock.rs +++ b/frame/indices/src/mock.rs @@ -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 = (); diff --git a/frame/lottery/src/mock.rs b/frame/lottery/src/mock.rs index 253923de0d5e7..d1f090aa26dcb 100644 --- a/frame/lottery/src/mock.rs +++ b/frame/lottery/src/mock.rs @@ -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 = (); diff --git a/frame/membership/src/lib.rs b/frame/membership/src/lib.rs index f43c056658f3c..a9bc59a361f06 100644 --- a/frame/membership/src/lib.rs +++ b/frame/membership/src/lib.rs @@ -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 = (); diff --git a/frame/merkle-mountain-range/src/mock.rs b/frame/merkle-mountain-range/src/mock.rs index 4a6b224b051b3..3616a8d1d5242 100644 --- a/frame/merkle-mountain-range/src/mock.rs +++ b/frame/merkle-mountain-range/src/mock.rs @@ -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; diff --git a/frame/multisig/src/tests.rs b/frame/multisig/src/tests.rs index 6dba6f7d4ab5a..635906d47cd6a 100644 --- a/frame/multisig/src/tests.rs +++ b/frame/multisig/src/tests.rs @@ -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 for TestBaseCallFilter { - fn filter(c: &Call) -> bool { +impl Contains for TestBaseCallFilter { + fn contains(c: &Call) -> bool { match *c { Call::Balances(_) => true, // Needed for benchmarking diff --git a/frame/nicks/src/lib.rs b/frame/nicks/src/lib.rs index d78f1c4465651..a5c22b619a5eb 100644 --- a/frame/nicks/src/lib.rs +++ b/frame/nicks/src/lib.rs @@ -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 = (); diff --git a/frame/node-authorization/src/mock.rs b/frame/node-authorization/src/mock.rs index 302378f48ce64..6c79f601c197d 100644 --- a/frame/node-authorization/src/mock.rs +++ b/frame/node-authorization/src/mock.rs @@ -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 = (); diff --git a/frame/offences/benchmarking/src/mock.rs b/frame/offences/benchmarking/src/mock.rs index 6fc5ee8b66eb0..3416dafa3547e 100644 --- a/frame/offences/benchmarking/src/mock.rs +++ b/frame/offences/benchmarking/src/mock.rs @@ -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 = (); diff --git a/frame/offences/src/mock.rs b/frame/offences/src/mock.rs index 84114f015089c..5e4c94944b6fd 100644 --- a/frame/offences/src/mock.rs +++ b/frame/offences/src/mock.rs @@ -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; diff --git a/frame/proxy/src/tests.rs b/frame/proxy/src/tests.rs index 536a226c7b46d..df88f17b71a54 100644 --- a/frame/proxy/src/tests.rs +++ b/frame/proxy/src/tests.rs @@ -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 for ProxyType { } } pub struct BaseFilter; -impl Filter for BaseFilter { - fn filter(c: &Call) -> bool { +impl Contains 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, diff --git a/frame/randomness-collective-flip/src/lib.rs b/frame/randomness-collective-flip/src/lib.rs index 64a263dd5bbd0..1b1d5cb5cd823 100644 --- a/frame/randomness-collective-flip/src/lib.rs +++ b/frame/randomness-collective-flip/src/lib.rs @@ -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 = (); diff --git a/frame/recovery/src/mock.rs b/frame/recovery/src/mock.rs index c9c01e35bf9bb..f6d4a6b159431 100644 --- a/frame/recovery/src/mock.rs +++ b/frame/recovery/src/mock.rs @@ -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 = (); diff --git a/frame/scheduler/src/lib.rs b/frame/scheduler/src/lib.rs index 6cbf172d26d8e..cb6aaeb9a93d7 100644 --- a/frame/scheduler/src/lib.rs +++ b/frame/scheduler/src/lib.rs @@ -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 for BaseFilter { - fn filter(call: &Call) -> bool { + impl Contains 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!(!::BaseCallFilter::filter(&call)); + assert!(!::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!(!::BaseCallFilter::filter(&call)); + assert!(!::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!(!::BaseCallFilter::filter(&call)); + assert!(!::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!(!::BaseCallFilter::filter(&call)); + assert!(!::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!(!::BaseCallFilter::filter(&call)); + assert!(!::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!(!::BaseCallFilter::filter(&call)); + assert!(!::BaseCallFilter::contains(&call)); assert_eq!( Scheduler::do_schedule_named( 1u32.encode(), diff --git a/frame/scored-pool/src/mock.rs b/frame/scored-pool/src/mock.rs index 80ded36fbf0ab..5c5425ae2bdd8 100644 --- a/frame/scored-pool/src/mock.rs +++ b/frame/scored-pool/src/mock.rs @@ -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 = (); diff --git a/frame/session/benchmarking/src/mock.rs b/frame/session/benchmarking/src/mock.rs index bd61acb9de180..672862f5ed999 100644 --- a/frame/session/benchmarking/src/mock.rs +++ b/frame/session/benchmarking/src/mock.rs @@ -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 = (); diff --git a/frame/session/src/mock.rs b/frame/session/src/mock.rs index 7007286de6415..449acaff5305d 100644 --- a/frame/session/src/mock.rs +++ b/frame/session/src/mock.rs @@ -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 = (); diff --git a/frame/society/src/mock.rs b/frame/society/src/mock.rs index 2ae9f7b44ba73..38c2586323135 100644 --- a/frame/society/src/mock.rs +++ b/frame/society/src/mock.rs @@ -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 = (); diff --git a/frame/staking/fuzzer/src/mock.rs b/frame/staking/fuzzer/src/mock.rs index 98181ca2694d2..921e0d3b48d7d 100644 --- a/frame/staking/fuzzer/src/mock.rs +++ b/frame/staking/fuzzer/src/mock.rs @@ -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 = (); diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 7f8774b94efb0..a25995df6e454 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -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. diff --git a/frame/staking/src/mock.rs b/frame/staking/src/mock.rs index 9d50a43754e76..3d9465ed872dd 100644 --- a/frame/staking/src/mock.rs +++ b/frame/staking/src/mock.rs @@ -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; diff --git a/frame/sudo/src/mock.rs b/frame/sudo/src/mock.rs index 4fa24dd56ce59..7fd55a618a6b5 100644 --- a/frame/sudo/src/mock.rs +++ b/frame/sudo/src/mock.rs @@ -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 for BlockEverything { - fn filter(_: &Call) -> bool { +impl Contains for BlockEverything { + fn contains(_: &Call) -> bool { false } } diff --git a/frame/support/procedural/src/construct_runtime/expand/origin.rs b/frame/support/procedural/src/construct_runtime/expand/origin.rs index 5091867eeef5a..10ab9e9347eb5 100644 --- a/frame/support/procedural/src/construct_runtime/expand/origin.rs +++ b/frame/support/procedural/src/construct_runtime/expand/origin.rs @@ -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)); } diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index 4ee5154a6b0fc..a4644cebeeb55 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -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 = (); diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index fbb21de7ebb14..efb5559ed0622 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -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::{ diff --git a/frame/support/src/traits/filter.rs b/frame/support/src/traits/filter.rs index b9f5037abc66e..c67ffc3c3a11e 100644 --- a/frame/support/src/traits/filter.rs +++ b/frame/support/src/traits/filter.rs @@ -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 { - /// 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 Filter for AllowAll { - fn filter(_: &T) -> bool { - true - } -} - -impl Filter for DenyAll { - fn filter(_: &T) -> bool { - false - } -} - /// Trait to add a constraint onto the filter. -pub trait FilterStack: Filter { +pub trait FilterStack: Contains { /// 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 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 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 for BaseFilter { - fn filter(x: &u32) -> bool { + impl Contains 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::::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::::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::::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)); } } diff --git a/frame/support/src/traits/members.rs b/frame/support/src/traits/members.rs index dbfc2e0120e4e..1d7c1c73208d1 100644 --- a/frame/support/src/traits/members.rs +++ b/frame/support/src/traits/members.rs @@ -25,14 +25,37 @@ pub trait Contains { fn contains(t: &T) -> bool; } -/// A `Contains` implementation which always returns `true`. -pub struct All(PhantomData); -impl Contains for All { +/// A [`Contains`] implementation that contains every value. +pub enum Everything {} +impl Contains for Everything { fn contains(_: &T) -> bool { true } } +/// A [`Contains`] implementation that contains no value. +pub enum Nothing {} +impl Contains 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 { + fn filter(t: &T) -> bool; +} +#[allow(deprecated)] +impl> Filter for C { + fn filter(t: &T) -> bool { + Self::contains(t) + } +} + #[impl_trait_for_tuples::impl_for_tuples(30)] impl Contains for Tuple { fn contains(t: &T) -> bool { diff --git a/frame/support/test/tests/construct_runtime.rs b/frame/support/test/tests/construct_runtime.rs index 98669cb1add09..5ddcb89a7dca2 100644 --- a/frame/support/test/tests/construct_runtime.rs +++ b/frame/support/test/tests/construct_runtime.rs @@ -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 for BaseCallFilter { - fn filter(c: &Call) -> bool { + impl Contains for BaseCallFilter { + fn contains(c: &Call) -> bool { match c { Call::NestedModule3(_) => true, _ => false, diff --git a/frame/support/test/tests/instance.rs b/frame/support/test/tests/instance.rs index 65a2c11d0d13f..a948853ff2a44 100644 --- a/frame/support/test/tests/instance.rs +++ b/frame/support/test/tests/instance.rs @@ -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; diff --git a/frame/support/test/tests/issue2219.rs b/frame/support/test/tests/issue2219.rs index dd73700cf5ca2..17eebf2d1022e 100644 --- a/frame/support/test/tests/issue2219.rs +++ b/frame/support/test/tests/issue2219.rs @@ -157,7 +157,7 @@ pub type Block = generic::Block; pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; 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; diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index c21808dfa8f24..00af4d261c659 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -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; diff --git a/frame/support/test/tests/pallet_compatibility.rs b/frame/support/test/tests/pallet_compatibility.rs index 35c991432acdd..9814fcb392b50 100644 --- a/frame/support/test/tests/pallet_compatibility.rs +++ b/frame/support/test/tests/pallet_compatibility.rs @@ -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; diff --git a/frame/support/test/tests/pallet_compatibility_instance.rs b/frame/support/test/tests/pallet_compatibility_instance.rs index 2d92920b81d8e..b8d43b5e32bfb 100644 --- a/frame/support/test/tests/pallet_compatibility_instance.rs +++ b/frame/support/test/tests/pallet_compatibility_instance.rs @@ -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; diff --git a/frame/support/test/tests/pallet_instance.rs b/frame/support/test/tests/pallet_instance.rs index 2c6c2a7a66468..adfbc7a64f0ed 100644 --- a/frame/support/test/tests/pallet_instance.rs +++ b/frame/support/test/tests/pallet_instance.rs @@ -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; diff --git a/frame/support/test/tests/pallet_with_name_trait_is_valid.rs b/frame/support/test/tests/pallet_with_name_trait_is_valid.rs index 867d952741011..1c47d13a619f2 100644 --- a/frame/support/test/tests/pallet_with_name_trait_is_valid.rs +++ b/frame/support/test/tests/pallet_with_name_trait_is_valid.rs @@ -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; diff --git a/frame/support/test/tests/system.rs b/frame/support/test/tests/system.rs index a0947e72b194f..0419326299264 100644 --- a/frame/support/test/tests/system.rs +++ b/frame/support/test/tests/system.rs @@ -25,7 +25,7 @@ pub trait Config: 'static + Eq + Clone { type Origin: Into, Self::Origin>> + From>; - type BaseCallFilter: frame_support::traits::Filter; + type BaseCallFilter: frame_support::traits::Contains; type BlockNumber: Decode + Encode + EncodeLike + Clone + Default; type Hash; type AccountId: Encode + EncodeLike + Decode; diff --git a/frame/system/benches/bench.rs b/frame/system/benches/bench.rs index e3f60733a6237..97c19c5e8159a 100644 --- a/frame/system/benches/bench.rs +++ b/frame/system/benches/bench.rs @@ -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 = (); diff --git a/frame/system/benchmarking/src/mock.rs b/frame/system/benchmarking/src/mock.rs index b375c9fcb5093..d828fb22ff5ff 100644 --- a/frame/system/benchmarking/src/mock.rs +++ b/frame/system/benchmarking/src/mock.rs @@ -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 = (); diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 68681ea5aca60..6b967fd8925a6 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -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; + type BaseCallFilter: Contains; /// Block & extrinsics weights: base values and limits. #[pallet::constant] diff --git a/frame/system/src/mock.rs b/frame/system/src/mock.rs index 480e8b1a26bae..8039b73445ae6 100644 --- a/frame/system/src/mock.rs +++ b/frame/system/src/mock.rs @@ -88,7 +88,7 @@ impl OnKilledAccount 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; diff --git a/frame/timestamp/src/lib.rs b/frame/timestamp/src/lib.rs index 247520297d248..a5a3b319b03cb 100644 --- a/frame/timestamp/src/lib.rs +++ b/frame/timestamp/src/lib.rs @@ -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 = (); diff --git a/frame/tips/src/tests.rs b/frame/tips/src/tests.rs index ac57932563816..c357942c54e1f 100644 --- a/frame/tips/src/tests.rs +++ b/frame/tips/src/tests.rs @@ -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 = (); diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 61de183dac1b8..36bfd31a6753a 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -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 = (); diff --git a/frame/transaction-storage/src/mock.rs b/frame/transaction-storage/src/mock.rs index 17a5d8097b671..38d14129d76e2 100644 --- a/frame/transaction-storage/src/mock.rs +++ b/frame/transaction-storage/src/mock.rs @@ -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; diff --git a/frame/treasury/src/tests.rs b/frame/treasury/src/tests.rs index cf341d5ad80f5..534661b2773bb 100644 --- a/frame/treasury/src/tests.rs +++ b/frame/treasury/src/tests.rs @@ -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 = (); diff --git a/frame/uniques/src/mock.rs b/frame/uniques/src/mock.rs index 4b80aa73030cf..658e82a5143e2 100644 --- a/frame/uniques/src/mock.rs +++ b/frame/uniques/src/mock.rs @@ -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; diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index fdc738bcded93..7679df944ec0e 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -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 for TestBaseCallFilter { - fn filter(c: &Call) -> bool { +impl Contains 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( diff --git a/frame/vesting/src/mock.rs b/frame/vesting/src/mock.rs index 45bfb788ba728..4efbabefe688f 100644 --- a/frame/vesting/src/mock.rs +++ b/frame/vesting/src/mock.rs @@ -48,7 +48,7 @@ parameter_types! { impl frame_system::Config for Test { type AccountData = pallet_balances::AccountData; type AccountId = u64; - type BaseCallFilter = frame_support::traits::AllowAll; + type BaseCallFilter = frame_support::traits::Everything; type BlockHashCount = BlockHashCount; type BlockLength = (); type BlockNumber = u64; diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index e7f25ad33611b..bdb8724120813 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -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;