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