From 9950144822a05055cc99804a4f5ec7697e610c92 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Fri, 8 Sep 2023 18:15:40 +0200 Subject: [PATCH 1/3] disable identity --- polkadot/runtime/kusama/src/lib.rs | 17 +++++++++++------ polkadot/runtime/polkadot/src/lib.rs | 15 ++++++++++++++- polkadot/runtime/rococo/src/lib.rs | 17 +++++++++++------ polkadot/runtime/westend/src/lib.rs | 19 ++++++++++++++++--- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 659a7052d2b7..9d709a00d959 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -157,11 +157,16 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } -/// We currently allow all calls. -pub struct BaseFilter; -impl Contains for BaseFilter { - fn contains(_c: &RuntimeCall) -> bool { - true +/// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing +/// further updates to identities and sub-identities. The locked state will be the genesis state of +/// a new system chain and then removed from the Relay Chain. +pub struct DisableIdentity; +impl Contains for DisableIdentity { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Identity(_) => false, + _ => true, + } } } @@ -171,7 +176,7 @@ parameter_types! { } impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; + type BaseCallFilter = DisableIdentity; type BlockWeights = BlockWeights; type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 45ea561b33fa..1aa7882b8c91 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -153,8 +153,21 @@ parameter_types! { pub const SS58Prefix: u8 = 0; } +/// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing +/// further updates to identities and sub-identities. The locked state will be the genesis state of +/// a new system chain and then removed from the Relay Chain. +pub struct DisableIdentity; +impl Contains for DisableIdentity { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Identity(_) => false, + _ => true, + } + } +} + impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; + type BaseCallFilter = DisableIdentity; type BlockWeights = BlockWeights; type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index e043852901f1..ac06bff9427c 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -134,11 +134,16 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } -/// We currently allow all calls. -pub struct BaseFilter; -impl Contains for BaseFilter { - fn contains(_call: &RuntimeCall) -> bool { - true +/// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing +/// further updates to identities and sub-identities. The locked state will be the genesis state of +/// a new system chain and then removed from the Relay Chain. +pub struct DisableIdentity; +impl Contains for DisableIdentity { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Identity(_) => false, + _ => true, + } } } @@ -148,7 +153,7 @@ parameter_types! { } impl frame_system::Config for Runtime { - type BaseCallFilter = BaseFilter; + type BaseCallFilter = DisableIdentity; type BlockWeights = BlockWeights; type BlockLength = BlockLength; type DbWeight = RocksDbWeight; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 7dfc781d2467..e1bd3ac803d5 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -29,8 +29,8 @@ use frame_election_provider_support::{bounds::ElectionBoundsBuilder, onchain, Se use frame_support::{ construct_runtime, parameter_types, traits::{ - ConstU32, InstanceFilter, KeyOwnerProofSystem, ProcessMessage, ProcessMessageError, - WithdrawReasons, + ConstU32, Contains, InstanceFilter, KeyOwnerProofSystem, ProcessMessage, + ProcessMessageError, WithdrawReasons, }, weights::{ConstantMultiplier, WeightMeter}, PalletId, @@ -146,8 +146,21 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } +/// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing +/// further updates to identities and sub-identities. The locked state will be the genesis state of +/// a new system chain and then removed from the Relay Chain. +pub struct DisableIdentity; +impl Contains for DisableIdentity { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Identity(_) => false, + _ => true, + } + } +} + impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; + type BaseCallFilter = DisableIdentity; type BlockWeights = BlockWeights; type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; From d12c98d8303439bae193cdb130b4e1f6b4286038 Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Fri, 8 Sep 2023 19:27:24 +0200 Subject: [PATCH 2/3] more readable with EverythingBut --- polkadot/runtime/kusama/src/lib.rs | 15 ++++++++------- polkadot/runtime/polkadot/src/lib.rs | 14 +++++++------- polkadot/runtime/rococo/src/lib.rs | 15 ++++++++------- polkadot/runtime/westend/src/lib.rs | 12 ++++++------ 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 9d709a00d959..f9b8544cc1cc 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -63,8 +63,9 @@ use frame_election_provider_support::{ use frame_support::{ construct_runtime, parameter_types, traits::{ - ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, - PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, WithdrawReasons, + ConstU32, Contains, EitherOf, EitherOfDiverse, EverythingBut, InstanceFilter, + KeyOwnerProofSystem, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, + WithdrawReasons, }, weights::{ConstantMultiplier, WeightMeter}, PalletId, @@ -160,12 +161,12 @@ pub fn native_version() -> NativeVersion { /// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing /// further updates to identities and sub-identities. The locked state will be the genesis state of /// a new system chain and then removed from the Relay Chain. -pub struct DisableIdentity; -impl Contains for DisableIdentity { +pub struct IdentityCalls; +impl Contains for IdentityCalls { fn contains(c: &RuntimeCall) -> bool { match c { - RuntimeCall::Identity(_) => false, - _ => true, + RuntimeCall::Identity(_) => true, + _ => false, } } } @@ -176,7 +177,7 @@ parameter_types! { } impl frame_system::Config for Runtime { - type BaseCallFilter = DisableIdentity; + type BaseCallFilter = EverythingBut; type BlockWeights = BlockWeights; type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 1aa7882b8c91..acb147f473e9 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -47,8 +47,8 @@ use frame_election_provider_support::{ use frame_support::{ construct_runtime, parameter_types, traits::{ - ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, - PrivilegeCmp, ProcessMessage, ProcessMessageError, WithdrawReasons, + ConstU32, Contains, EitherOf, EitherOfDiverse, EverythingBut, InstanceFilter, + KeyOwnerProofSystem, PrivilegeCmp, ProcessMessage, ProcessMessageError, WithdrawReasons, }, weights::{ConstantMultiplier, WeightMeter}, PalletId, @@ -156,18 +156,18 @@ parameter_types! { /// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing /// further updates to identities and sub-identities. The locked state will be the genesis state of /// a new system chain and then removed from the Relay Chain. -pub struct DisableIdentity; -impl Contains for DisableIdentity { +pub struct IdentityCalls; +impl Contains for IdentityCalls { fn contains(c: &RuntimeCall) -> bool { match c { - RuntimeCall::Identity(_) => false, - _ => true, + RuntimeCall::Identity(_) => true, + _ => false, } } } impl frame_system::Config for Runtime { - type BaseCallFilter = DisableIdentity; + type BaseCallFilter = EverythingBut; type BlockWeights = BlockWeights; type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index ac06bff9427c..74e17ee3dd39 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -60,8 +60,9 @@ use beefy_primitives::{ use frame_support::{ construct_runtime, parameter_types, traits::{ - Contains, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, - PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, WithdrawReasons, + Contains, EitherOfDiverse, EverythingBut, InstanceFilter, KeyOwnerProofSystem, + LockIdentifier, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, + WithdrawReasons, }, weights::{ConstantMultiplier, WeightMeter}, PalletId, @@ -137,12 +138,12 @@ pub fn native_version() -> NativeVersion { /// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing /// further updates to identities and sub-identities. The locked state will be the genesis state of /// a new system chain and then removed from the Relay Chain. -pub struct DisableIdentity; -impl Contains for DisableIdentity { +pub struct IdentityCalls; +impl Contains for IdentityCalls { fn contains(c: &RuntimeCall) -> bool { match c { - RuntimeCall::Identity(_) => false, - _ => true, + RuntimeCall::Identity(_) => true, + _ => false, } } } @@ -153,7 +154,7 @@ parameter_types! { } impl frame_system::Config for Runtime { - type BaseCallFilter = DisableIdentity; + type BaseCallFilter = EverythingBut; type BlockWeights = BlockWeights; type BlockLength = BlockLength; type DbWeight = RocksDbWeight; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index e1bd3ac803d5..934f40fb3dcc 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -29,7 +29,7 @@ use frame_election_provider_support::{bounds::ElectionBoundsBuilder, onchain, Se use frame_support::{ construct_runtime, parameter_types, traits::{ - ConstU32, Contains, InstanceFilter, KeyOwnerProofSystem, ProcessMessage, + ConstU32, Contains, EverythingBut, InstanceFilter, KeyOwnerProofSystem, ProcessMessage, ProcessMessageError, WithdrawReasons, }, weights::{ConstantMultiplier, WeightMeter}, @@ -149,18 +149,18 @@ parameter_types! { /// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing /// further updates to identities and sub-identities. The locked state will be the genesis state of /// a new system chain and then removed from the Relay Chain. -pub struct DisableIdentity; -impl Contains for DisableIdentity { +pub struct IdentityCalls; +impl Contains for IdentityCalls { fn contains(c: &RuntimeCall) -> bool { match c { - RuntimeCall::Identity(_) => false, - _ => true, + RuntimeCall::Identity(_) => true, + _ => false, } } } impl frame_system::Config for Runtime { - type BaseCallFilter = DisableIdentity; + type BaseCallFilter = EverythingBut; type BlockWeights = BlockWeights; type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; From 5fa1dc346e114b718a6df3a266390e82a0d0d9ce Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Sat, 9 Sep 2023 13:41:11 +0200 Subject: [PATCH 3/3] correct docs and cleaner match --- polkadot/runtime/kusama/src/lib.rs | 12 +++++------- polkadot/runtime/polkadot/src/lib.rs | 22 ++++++++++------------ polkadot/runtime/rococo/src/lib.rs | 12 +++++------- polkadot/runtime/westend/src/lib.rs | 22 ++++++++++------------ 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index f9b8544cc1cc..89061239282b 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -158,16 +158,14 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } -/// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing -/// further updates to identities and sub-identities. The locked state will be the genesis state of -/// a new system chain and then removed from the Relay Chain. +/// A type to identify calls to the Identity pallet. These will be filtered to prevent invocation, +/// locking the state of the pallet and preventing further updates to identities and sub-identities. +/// The locked state will be the genesis state of a new system chain and then removed from the Relay +/// Chain. pub struct IdentityCalls; impl Contains for IdentityCalls { fn contains(c: &RuntimeCall) -> bool { - match c { - RuntimeCall::Identity(_) => true, - _ => false, - } + matches!(c, RuntimeCall::Identity(_)) } } diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index acb147f473e9..f10fe94d82ca 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -148,24 +148,22 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } -parameter_types! { - pub const Version: RuntimeVersion = VERSION; - pub const SS58Prefix: u8 = 0; -} - -/// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing -/// further updates to identities and sub-identities. The locked state will be the genesis state of -/// a new system chain and then removed from the Relay Chain. +/// A type to identify calls to the Identity pallet. These will be filtered to prevent invocation, +/// locking the state of the pallet and preventing further updates to identities and sub-identities. +/// The locked state will be the genesis state of a new system chain and then removed from the Relay +/// Chain. pub struct IdentityCalls; impl Contains for IdentityCalls { fn contains(c: &RuntimeCall) -> bool { - match c { - RuntimeCall::Identity(_) => true, - _ => false, - } + matches!(c, RuntimeCall::Identity(_)) } } +parameter_types! { + pub const Version: RuntimeVersion = VERSION; + pub const SS58Prefix: u8 = 0; +} + impl frame_system::Config for Runtime { type BaseCallFilter = EverythingBut; type BlockWeights = BlockWeights; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 74e17ee3dd39..1d4ef1c30de9 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -135,16 +135,14 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } -/// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing -/// further updates to identities and sub-identities. The locked state will be the genesis state of -/// a new system chain and then removed from the Relay Chain. +/// A type to identify calls to the Identity pallet. These will be filtered to prevent invocation, +/// locking the state of the pallet and preventing further updates to identities and sub-identities. +/// The locked state will be the genesis state of a new system chain and then removed from the Relay +/// Chain. pub struct IdentityCalls; impl Contains for IdentityCalls { fn contains(c: &RuntimeCall) -> bool { - match c { - RuntimeCall::Identity(_) => true, - _ => false, - } + matches!(c, RuntimeCall::Identity(_)) } } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 934f40fb3dcc..692593b832c9 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -141,24 +141,22 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } -parameter_types! { - pub const Version: RuntimeVersion = VERSION; - pub const SS58Prefix: u8 = 42; -} - -/// Disable all calls to the Identity pallet. This will lock the state of the pallet, preventing -/// further updates to identities and sub-identities. The locked state will be the genesis state of -/// a new system chain and then removed from the Relay Chain. +/// A type to identify calls to the Identity pallet. These will be filtered to prevent invocation, +/// locking the state of the pallet and preventing further updates to identities and sub-identities. +/// The locked state will be the genesis state of a new system chain and then removed from the Relay +/// Chain. pub struct IdentityCalls; impl Contains for IdentityCalls { fn contains(c: &RuntimeCall) -> bool { - match c { - RuntimeCall::Identity(_) => true, - _ => false, - } + matches!(c, RuntimeCall::Identity(_)) } } +parameter_types! { + pub const Version: RuntimeVersion = VERSION; + pub const SS58Prefix: u8 = 42; +} + impl frame_system::Config for Runtime { type BaseCallFilter = EverythingBut; type BlockWeights = BlockWeights;