Unverified Commit 292ba8a7 authored by Gavin Wood's avatar Gavin Wood Committed by GitHub
Browse files

Companion to #9514 (Remove Filter and use Contains instead) (#3591)

* Remove Filter and use Contains instead

* Fixes

* Remove patch

* Formatting

* update Substrate

Co-authored-by: parity-processbot <>
parent 73dc743c
Pipeline #151781 failed with stages
in 15 minutes and 55 seconds
...@@ -31,7 +31,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; ...@@ -31,7 +31,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId; use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_support::{ use frame_support::{
construct_runtime, parameter_types, construct_runtime, parameter_types,
traits::{Filter, KeyOwnerProofSystem, LockIdentifier, OnRuntimeUpgrade}, traits::{Contains, KeyOwnerProofSystem, LockIdentifier, OnRuntimeUpgrade},
weights::Weight, weights::Weight,
PalletId, RuntimeDebug, PalletId, RuntimeDebug,
}; };
...@@ -119,8 +119,8 @@ pub fn native_version() -> NativeVersion { ...@@ -119,8 +119,8 @@ pub fn native_version() -> NativeVersion {
} }
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 {
match call { match call {
// These modules are all allowed to be called by transactions: // These modules are all allowed to be called by transactions:
Call::Democracy(_) | Call::Democracy(_) |
......
...@@ -24,7 +24,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; ...@@ -24,7 +24,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion}; use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion};
use frame_support::{ use frame_support::{
construct_runtime, parameter_types, construct_runtime, parameter_types,
traits::{All, Filter, IsInVec, KeyOwnerProofSystem, OnRuntimeUpgrade, Randomness}, traits::{Contains, Everything, IsInVec, KeyOwnerProofSystem, OnRuntimeUpgrade, Randomness},
weights::Weight, weights::Weight,
PalletId, PalletId,
}; };
...@@ -266,8 +266,8 @@ construct_runtime! { ...@@ -266,8 +266,8 @@ construct_runtime! {
} }
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 {
true true
} }
} }
...@@ -650,7 +650,7 @@ parameter_types! { ...@@ -650,7 +650,7 @@ parameter_types! {
use xcm_builder::{AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, TakeWeightCredit}; use xcm_builder::{AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, TakeWeightCredit};
pub type Barrier = ( pub type Barrier = (
TakeWeightCredit, TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<All<MultiLocation>>, AllowTopLevelPaidExecutionFrom<Everything>,
AllowUnpaidExecutionFrom<IsInVec<AllowUnpaidFrom>>, // <- Trusted parachains get free execution AllowUnpaidExecutionFrom<IsInVec<AllowUnpaidFrom>>, // <- Trusted parachains get free execution
); );
...@@ -692,8 +692,8 @@ impl pallet_xcm::Config for Runtime { ...@@ -692,8 +692,8 @@ impl pallet_xcm::Config for Runtime {
// ...but they must match our filter, which right now rejects everything. // ...but they must match our filter, which right now rejects everything.
type XcmExecuteFilter = (); type XcmExecuteFilter = ();
type XcmExecutor = XcmExecutor<XcmConfig>; type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>; type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>; type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call>; type Weigher = FixedWeightBounds<BaseXcmWeight, Call>;
type LocationInverter = LocationInverter<Ancestry>; type LocationInverter = LocationInverter<Ancestry>;
} }
...@@ -833,7 +833,7 @@ impl pallet_bridge_dispatch::Config<AtWococoFromRococoMessagesDispatch> for Runt ...@@ -833,7 +833,7 @@ impl pallet_bridge_dispatch::Config<AtWococoFromRococoMessagesDispatch> for Runt
type Event = Event; type Event = Event;
type MessageId = (bp_messages::LaneId, bp_messages::MessageNonce); type MessageId = (bp_messages::LaneId, bp_messages::MessageNonce);
type Call = Call; type Call = Call;
type CallFilter = frame_support::traits::AllowAll; type CallFilter = frame_support::traits::Everything;
type EncodedCall = bridge_messages::FromRococoEncodedCall; type EncodedCall = bridge_messages::FromRococoEncodedCall;
type SourceChainAccountId = bp_wococo::AccountId; type SourceChainAccountId = bp_wococo::AccountId;
type TargetChainAccountPublic = sp_runtime::MultiSigner; type TargetChainAccountPublic = sp_runtime::MultiSigner;
...@@ -847,7 +847,7 @@ impl pallet_bridge_dispatch::Config<AtRococoFromWococoMessagesDispatch> for Runt ...@@ -847,7 +847,7 @@ impl pallet_bridge_dispatch::Config<AtRococoFromWococoMessagesDispatch> for Runt
type Event = Event; type Event = Event;
type MessageId = (bp_messages::LaneId, bp_messages::MessageNonce); type MessageId = (bp_messages::LaneId, bp_messages::MessageNonce);
type Call = Call; type Call = Call;
type CallFilter = frame_support::traits::AllowAll; type CallFilter = frame_support::traits::Everything;
type EncodedCall = bridge_messages::FromWococoEncodedCall; type EncodedCall = bridge_messages::FromWococoEncodedCall;
type SourceChainAccountId = bp_rococo::AccountId; type SourceChainAccountId = bp_rococo::AccountId;
type TargetChainAccountPublic = sp_runtime::MultiSigner; type TargetChainAccountPublic = sp_runtime::MultiSigner;
......
...@@ -123,7 +123,7 @@ parameter_types! { ...@@ -123,7 +123,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 = BlockWeights; type BlockWeights = BlockWeights;
type BlockLength = BlockLength; type BlockLength = BlockLength;
type DbWeight = (); type DbWeight = ();
......
...@@ -58,7 +58,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; ...@@ -58,7 +58,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId; use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_support::{ use frame_support::{
construct_runtime, parameter_types, construct_runtime, parameter_types,
traits::{All, Filter, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade}, traits::{Contains, Everything, InstanceFilter, KeyOwnerProofSystem, OnRuntimeUpgrade},
weights::Weight, weights::Weight,
PalletId, RuntimeDebug, PalletId, RuntimeDebug,
}; };
...@@ -136,8 +136,8 @@ pub fn native_version() -> NativeVersion { ...@@ -136,8 +136,8 @@ pub fn native_version() -> NativeVersion {
/// Allow everything. /// Allow everything.
pub struct BaseFilter; pub struct BaseFilter;
impl Filter<Call> for BaseFilter { impl Contains<Call> for BaseFilter {
fn filter(_: &Call) -> bool { fn contains(_: &Call) -> bool {
true true
} }
} }
...@@ -917,7 +917,7 @@ pub type Barrier = ( ...@@ -917,7 +917,7 @@ pub type Barrier = (
// Weight that is paid for may be consumed. // Weight that is paid for may be consumed.
TakeWeightCredit, TakeWeightCredit,
// If the message is one that immediately attemps to pay for execution, then allow it. // If the message is one that immediately attemps to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<All<MultiLocation>>, AllowTopLevelPaidExecutionFrom<Everything>,
// Messages coming from system parachains need not pay for execution. // Messages coming from system parachains need not pay for execution.
AllowUnpaidExecutionFrom<IsChildSystemParachain<ParaId>>, AllowUnpaidExecutionFrom<IsChildSystemParachain<ParaId>>,
); );
...@@ -953,8 +953,8 @@ impl pallet_xcm::Config for Runtime { ...@@ -953,8 +953,8 @@ impl pallet_xcm::Config for Runtime {
// ...but they must match our filter, which rejects everything. // ...but they must match our filter, which rejects everything.
type XcmExecuteFilter = (); type XcmExecuteFilter = ();
type XcmExecutor = XcmExecutor<XcmConfig>; type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>; type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>; type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call>; type Weigher = FixedWeightBounds<BaseXcmWeight, Call>;
type LocationInverter = LocationInverter<Ancestry>; type LocationInverter = LocationInverter<Ancestry>;
} }
......
...@@ -24,7 +24,7 @@ mod mock; ...@@ -24,7 +24,7 @@ mod mock;
mod tests; mod tests;
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use frame_support::traits::{Contains, EnsureOrigin, Filter, Get, OriginTrait}; use frame_support::traits::{Contains, EnsureOrigin, Get, OriginTrait};
use sp_runtime::{traits::BadOrigin, RuntimeDebug}; use sp_runtime::{traits::BadOrigin, RuntimeDebug};
use sp_std::{boxed::Box, convert::TryInto, marker::PhantomData, prelude::*, vec}; use sp_std::{boxed::Box, convert::TryInto, marker::PhantomData, prelude::*, vec};
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
...@@ -352,10 +352,10 @@ where ...@@ -352,10 +352,10 @@ where
/// ///
/// May reasonably be used with `EnsureXcm`. /// May reasonably be used with `EnsureXcm`.
pub struct IsMajorityOfBody<Prefix, Body>(PhantomData<(Prefix, Body)>); pub struct IsMajorityOfBody<Prefix, Body>(PhantomData<(Prefix, Body)>);
impl<Prefix: Get<MultiLocation>, Body: Get<BodyId>> Filter<MultiLocation> impl<Prefix: Get<MultiLocation>, Body: Get<BodyId>> Contains<MultiLocation>
for IsMajorityOfBody<Prefix, Body> for IsMajorityOfBody<Prefix, Body>
{ {
fn filter(l: &MultiLocation) -> bool { fn contains(l: &MultiLocation) -> bool {
let maybe_suffix = l.match_and_split(&Prefix::get()); let maybe_suffix = l.match_and_split(&Prefix::get());
matches!(maybe_suffix, Some(Plurality { id, part }) if id == &Body::get() && part.is_majority()) matches!(maybe_suffix, Some(Plurality { id, part }) if id == &Body::get() && part.is_majority())
} }
...@@ -364,7 +364,7 @@ impl<Prefix: Get<MultiLocation>, Body: Get<BodyId>> Filter<MultiLocation> ...@@ -364,7 +364,7 @@ impl<Prefix: Get<MultiLocation>, Body: Get<BodyId>> Filter<MultiLocation>
/// `EnsureOrigin` implementation succeeding with a `MultiLocation` value to recognize and filter the /// `EnsureOrigin` implementation succeeding with a `MultiLocation` value to recognize and filter the
/// `Origin::Xcm` item. /// `Origin::Xcm` item.
pub struct EnsureXcm<F>(PhantomData<F>); pub struct EnsureXcm<F>(PhantomData<F>);
impl<O: OriginTrait + From<Origin>, F: Filter<MultiLocation>> EnsureOrigin<O> for EnsureXcm<F> impl<O: OriginTrait + From<Origin>, F: Contains<MultiLocation>> EnsureOrigin<O> for EnsureXcm<F>
where where
O::PalletsOrigin: From<Origin> + TryInto<Origin, Error = O::PalletsOrigin>, O::PalletsOrigin: From<Origin> + TryInto<Origin, Error = O::PalletsOrigin>,
{ {
...@@ -373,7 +373,7 @@ where ...@@ -373,7 +373,7 @@ where
fn try_origin(outer: O) -> Result<Self::Success, O> { fn try_origin(outer: O) -> Result<Self::Success, O> {
outer.try_with_caller(|caller| { outer.try_with_caller(|caller| {
caller.try_into().and_then(|Origin::Xcm(location)| { caller.try_into().and_then(|Origin::Xcm(location)| {
if F::filter(&location) { if F::contains(&location) {
Ok(location) Ok(location)
} else { } else {
Err(Origin::Xcm(location).into()) Err(Origin::Xcm(location).into())
......
...@@ -14,11 +14,7 @@ ...@@ -14,11 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. // along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{ use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight};
construct_runtime, parameter_types,
traits::{All, AllowAll},
weights::Weight,
};
use polkadot_parachain::primitives::Id as ParaId; use polkadot_parachain::primitives::Id as ParaId;
use polkadot_runtime_parachains::origin; use polkadot_runtime_parachains::origin;
use sp_core::H256; use sp_core::H256;
...@@ -108,7 +104,7 @@ impl frame_system::Config for Test { ...@@ -108,7 +104,7 @@ impl frame_system::Config for Test {
type OnNewAccount = (); type OnNewAccount = ();
type OnKilledAccount = (); type OnKilledAccount = ();
type DbWeight = (); type DbWeight = ();
type BaseCallFilter = AllowAll; type BaseCallFilter = Everything;
type SystemWeightInfo = (); type SystemWeightInfo = ();
type SS58Prefix = (); type SS58Prefix = ();
type OnSetCode = (); type OnSetCode = ();
...@@ -157,7 +153,7 @@ parameter_types! { ...@@ -157,7 +153,7 @@ parameter_types! {
pub CurrencyPerSecond: (AssetId, u128) = (Concrete(RelayLocation::get()), 1); pub CurrencyPerSecond: (AssetId, u128) = (Concrete(RelayLocation::get()), 1);
} }
pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom<All<MultiLocation>>); pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom<Everything>);
pub struct XcmConfig; pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig { impl xcm_executor::Config for XcmConfig {
...@@ -181,10 +177,10 @@ impl pallet_xcm::Config for Test { ...@@ -181,10 +177,10 @@ impl pallet_xcm::Config for Test {
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>; type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmRouter = (TestSendXcmErrX8, TestSendXcm); type XcmRouter = (TestSendXcmErrX8, TestSendXcm);
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>; type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmExecuteFilter = All<(MultiLocation, xcm::latest::Xcm<Call>)>; type XcmExecuteFilter = Everything;
type XcmExecutor = XcmExecutor<XcmConfig>; type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>; type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>; type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call>; type Weigher = FixedWeightBounds<BaseXcmWeight, Call>;
type LocationInverter = LocationInverter<Ancestry>; type LocationInverter = LocationInverter<Ancestry>;
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use frame_support::{ use frame_support::{
construct_runtime, parameter_types, construct_runtime, parameter_types,
traits::{All, AllowAll}, traits::Everything,
weights::{constants::WEIGHT_PER_SECOND, Weight}, weights::{constants::WEIGHT_PER_SECOND, Weight},
}; };
use sp_core::H256; use sp_core::H256;
...@@ -71,7 +71,7 @@ impl frame_system::Config for Runtime { ...@@ -71,7 +71,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = (); type OnNewAccount = ();
type OnKilledAccount = (); type OnKilledAccount = ();
type DbWeight = (); type DbWeight = ();
type BaseCallFilter = AllowAll; type BaseCallFilter = Everything;
type SystemWeightInfo = (); type SystemWeightInfo = ();
type SS58Prefix = (); type SS58Prefix = ();
type OnSetCode = (); type OnSetCode = ();
...@@ -127,7 +127,7 @@ pub type LocalAssetTransactor = ...@@ -127,7 +127,7 @@ pub type LocalAssetTransactor =
XcmCurrencyAdapter<Balances, IsConcrete<KsmLocation>, LocationToAccountId, AccountId, ()>; XcmCurrencyAdapter<Balances, IsConcrete<KsmLocation>, LocationToAccountId, AccountId, ()>;
pub type XcmRouter = super::ParachainXcmRouter<MsgQueue>; pub type XcmRouter = super::ParachainXcmRouter<MsgQueue>;
pub type Barrier = AllowUnpaidExecutionFrom<All<MultiLocation>>; pub type Barrier = AllowUnpaidExecutionFrom<Everything>;
pub struct XcmConfig; pub struct XcmConfig;
impl Config for XcmConfig { impl Config for XcmConfig {
...@@ -288,10 +288,10 @@ impl pallet_xcm::Config for Runtime { ...@@ -288,10 +288,10 @@ impl pallet_xcm::Config for Runtime {
type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>; type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmRouter = XcmRouter; type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>; type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmExecuteFilter = All<(MultiLocation, Xcm<Call>)>; type XcmExecuteFilter = Everything;
type XcmExecutor = XcmExecutor<XcmConfig>; type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = (); type XcmTeleportFilter = ();
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>; type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>; type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
type LocationInverter = LocationInverter<Ancestry>; type LocationInverter = LocationInverter<Ancestry>;
} }
......
...@@ -16,11 +16,7 @@ ...@@ -16,11 +16,7 @@
//! Relay chain runtime mock. //! Relay chain runtime mock.
use frame_support::{ use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight};
construct_runtime, parameter_types,
traits::{All, AllowAll},
weights::Weight,
};
use sp_core::H256; use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
...@@ -62,7 +58,7 @@ impl frame_system::Config for Runtime { ...@@ -62,7 +58,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = (); type OnNewAccount = ();
type OnKilledAccount = (); type OnKilledAccount = ();
type DbWeight = (); type DbWeight = ();
type BaseCallFilter = AllowAll; type BaseCallFilter = Everything;
type SystemWeightInfo = (); type SystemWeightInfo = ();
type SS58Prefix = (); type SS58Prefix = ();
type OnSetCode = (); type OnSetCode = ();
...@@ -117,7 +113,7 @@ parameter_types! { ...@@ -117,7 +113,7 @@ parameter_types! {
} }
pub type XcmRouter = super::RelayChainXcmRouter; pub type XcmRouter = super::RelayChainXcmRouter;
pub type Barrier = AllowUnpaidExecutionFrom<All<MultiLocation>>; pub type Barrier = AllowUnpaidExecutionFrom<Everything>;
pub struct XcmConfig; pub struct XcmConfig;
impl Config for XcmConfig { impl Config for XcmConfig {
...@@ -144,8 +140,8 @@ impl pallet_xcm::Config for Runtime { ...@@ -144,8 +140,8 @@ impl pallet_xcm::Config for Runtime {
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>; type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmExecuteFilter = (); type XcmExecuteFilter = ();
type XcmExecutor = XcmExecutor<XcmConfig>; type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>; type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>; type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call>; type Weigher = FixedWeightBounds<BaseXcmWeight, Call>;
type LocationInverter = LocationInverter<Ancestry>; type LocationInverter = LocationInverter<Ancestry>;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment