diff --git a/Cargo.lock b/Cargo.lock index 8b0643d07b..7d60b8684c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4648,7 +4648,6 @@ dependencies = [ "pallet-authorship", "pallet-balances", "pallet-did-lookup", - "pallet-dyn-filter", "pallet-grandpa", "pallet-indices", "pallet-proxy", @@ -5493,26 +5492,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-dyn-filter" -version = "1.7.3" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "itertools", - "lazy_static", - "log", - "pallet-balances", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-io", - "sp-keystore", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" @@ -5886,29 +5865,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-relay-migration" -version = "1.7.3" -dependencies = [ - "cumulus-pallet-parachain-system", - "cumulus-primitives-core", - "frame-benchmarking", - "frame-support", - "frame-system", - "kilt-support", - "log", - "pallet-xcm", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-runtime-common", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", - "xcm", -] - [[package]] name = "pallet-scheduler" version = "4.0.0-dev" @@ -6468,14 +6424,12 @@ dependencies = [ "pallet-collective", "pallet-democracy", "pallet-did-lookup", - "pallet-dyn-filter", "pallet-indices", "pallet-inflation", "pallet-membership", "pallet-preimage", "pallet-proxy", "pallet-randomness-collective-flip", - "pallet-relay-migration", "pallet-scheduler", "pallet-session", "pallet-sudo", @@ -10796,14 +10750,12 @@ dependencies = [ "pallet-collective", "pallet-democracy", "pallet-did-lookup", - "pallet-dyn-filter", "pallet-indices", "pallet-inflation", "pallet-membership", "pallet-preimage", "pallet-proxy", "pallet-randomness-collective-flip", - "pallet-relay-migration", "pallet-scheduler", "pallet-session", "pallet-timestamp", diff --git a/pallets/pallet-dyn-filter/Cargo.toml b/pallets/pallet-dyn-filter/Cargo.toml deleted file mode 100644 index a1b2fd8507..0000000000 --- a/pallets/pallet-dyn-filter/Cargo.toml +++ /dev/null @@ -1,60 +0,0 @@ -[package] -authors = ["KILT "] -description = "Dynamically filter calls." -edition = "2021" -name = "pallet-dyn-filter" -repository = "https://github.com/KILTprotocol/kilt-node" -version = "1.7.3" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dev-dependencies] -itertools = "0.10.3" -lazy_static = "1.4.0" -pallet-balances = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -sp-core = {branch = "polkadot-v0.9.27", git = "https://github.com/paritytech/substrate"} -sp-io = {branch = "polkadot-v0.9.27", git = "https://github.com/paritytech/substrate"} -sp-keystore = {branch = "polkadot-v0.9.27", git = "https://github.com/paritytech/substrate"} - -[dependencies] -codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]} -log = "0.4.17" -scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} - -# Substrate dependencies -frame-support = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -frame-system = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -sp-core = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -sp-io = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -sp-runtime = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -sp-std = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} - -# benchmarking -frame-benchmarking = {branch = "polkadot-v0.9.27", optional = true, default-features = false, git = "https://github.com/paritytech/substrate"} - -[features] -default = ["std"] - -runtime-benchmarks = [ - "frame-benchmarking", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", -] - -std = [ - "codec/std", - "frame-benchmarking/std", - "frame-support/std", - "frame-system/std", - "log/std", - "scale-info/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", - "sp-std/std", -] - -try-runtime = [ - "frame-support/try-runtime", -] diff --git a/pallets/pallet-dyn-filter/src/benchmarking.rs b/pallets/pallet-dyn-filter/src/benchmarking.rs deleted file mode 100644 index 0a20f15d2f..0000000000 --- a/pallets/pallet-dyn-filter/src/benchmarking.rs +++ /dev/null @@ -1,42 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The KILT Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; -use frame_support::traits::EnsureOrigin; - -use super::*; -use crate::setting::FilterSettings; - -benchmarks! { - set_filter { - let new_filter = FilterSettings { - transfer_disabled: true, - feature_disabled: true, - xcm_disabled: true, - }; - let origin = T::ApproveOrigin::successful_origin(); - }: _(origin, new_filter) - verify { - } -} - -impl_benchmark_test_suite! { - Pallet, - crate::mock::ExtBuilder::default().build_with_keystore(), - crate::mock::Test -} diff --git a/pallets/pallet-dyn-filter/src/default_weights.rs b/pallets/pallet-dyn-filter/src/default_weights.rs deleted file mode 100644 index afd9480460..0000000000 --- a/pallets/pallet-dyn-filter/src/default_weights.rs +++ /dev/null @@ -1,47 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The KILT Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_runtime::traits::Saturating; -use sp_std::marker::PhantomData; - -/// Weight functions needed for did. -pub trait WeightInfo { - fn set_filter() -> Weight; - -} - -/// Weights for did using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - fn set_filter() -> Weight { - 1_000_000.saturating_add(T::DbWeight::get().reads(1 as Weight)) - } - -} - -// For backwards compatibility and tests -impl WeightInfo for () { - fn set_filter() -> Weight { - 1_000_000.saturating_add(RocksDbWeight::get().reads(1 as Weight)) - } -} diff --git a/pallets/pallet-dyn-filter/src/lib.rs b/pallets/pallet-dyn-filter/src/lib.rs deleted file mode 100644 index 894497b6f4..0000000000 --- a/pallets/pallet-dyn-filter/src/lib.rs +++ /dev/null @@ -1,129 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The KILT Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -//! # Dynamic Call Filter -//! -//! Enable or disable specific features without a runtime upgrade. -//! -//! - [`Pallet`] - -#![cfg_attr(not(feature = "std"), no_std)] - -pub mod default_weights; - -#[cfg(test)] -mod tests; - -#[cfg(test)] -mod mock; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; -pub mod setting; - -pub use crate::{default_weights::WeightInfo, pallet::*}; - -#[frame_support::pallet] -pub mod pallet { - - use frame_support::{ - pallet_prelude::*, - traits::{Contains, StorageVersion}, - }; - use frame_system::pallet_prelude::*; - - use crate::{setting::FilterSettings, WeightInfo}; - - pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); - - #[pallet::config] - pub trait Config: frame_system::Config { - type Event: From> + IsType<::Event>; - - /// The origin check for the authorised entities that can change the - /// filter. - type ApproveOrigin: EnsureOrigin<::Origin>; - - /// TransferCall filters all calls that allow to transfer funds. - type TransferCall: Contains<::Call>; - - /// FeatureCall filters all calls that provide the utility of the chain. - type FeatureCall: Contains<::Call>; - - /// XcmCall filters all calls that send messages to other chains - type XcmCall: Contains<::Call>; - - /// System calls are not filtered. (SystemCall contains all calls that - /// are needed for block production, return true if system call) - type SystemCall: Contains<::Call>; - - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; - } - - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - #[pallet::storage_version(STORAGE_VERSION)] - pub struct Pallet(_); - - #[pallet::storage] - #[pallet::getter(fn filter_setting)] - pub type Filter = StorageValue<_, FilterSettings, ValueQuery>; - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - NewFilterRules { rules: FilterSettings }, - } - - #[pallet::error] - pub enum Error {} - - #[pallet::call] - impl Pallet { - #[pallet::weight(::WeightInfo::set_filter())] - pub fn set_filter(origin: OriginFor, filter: FilterSettings) -> DispatchResult { - T::ApproveOrigin::ensure_origin(origin)?; - - Filter::::set(filter); - Self::deposit_event(Event::::NewFilterRules { rules: filter }); - Ok(()) - } - } - - impl Contains for Pallet { - /// The provided call goes through if this returns `true`. Else, it - /// fails. - fn contains(t: &T::Call) -> bool { - // System relevant calls cannot be filtered - if T::SystemCall::contains(t) { - return true; - } - - let FilterSettings { - transfer_disabled, - feature_disabled, - xcm_disabled, - } = Filter::::get(); - - !((transfer_disabled && T::TransferCall::contains(t)) - || (feature_disabled && T::FeatureCall::contains(t)) - || (xcm_disabled && T::XcmCall::contains(t))) - } - } -} diff --git a/pallets/pallet-dyn-filter/src/mock.rs b/pallets/pallet-dyn-filter/src/mock.rs deleted file mode 100644 index 75dccb413b..0000000000 --- a/pallets/pallet-dyn-filter/src/mock.rs +++ /dev/null @@ -1,170 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The KILT Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -use frame_support::{parameter_types, traits::Contains}; -use frame_system::EnsureRoot; -use lazy_static::lazy_static; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify}, - MultiSignature, -}; - -pub(crate) type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -pub(crate) type Block = frame_system::mocking::MockBlock; -pub(crate) type Hash = sp_core::H256; -pub(crate) type Signature = MultiSignature; -pub(crate) type AccountPublic = ::Signer; -pub(crate) type AccountId = ::AccountId; -pub(crate) type Index = u64; -pub(crate) type BlockNumber = u64; - -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - DynFilter: crate::{Pallet, Storage, Call, Event}, - } -); - -parameter_types! { - pub const SS58Prefix: u8 = 38; - pub const BlockHashCount: BlockNumber = 2400; -} - -impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Origin = Origin; - type Call = Call; - type Index = Index; - type BlockNumber = BlockNumber; - type Hash = Hash; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -impl crate::Config for Test { - type Event = Event; - type WeightInfo = (); - - type ApproveOrigin = EnsureRoot; - type FeatureCall = FeatureCalls; - type TransferCall = TransferCalls; - type XcmCall = XcmCalls; - type SystemCall = SystemCalls; -} - -const TRANSFER: &[u8] = b"trf"; -const FEATURE: &[u8] = b"fet"; -const XCM: &[u8] = b"xcm"; -const SYSTEM: &[u8] = b"system"; - -lazy_static! { - pub static ref CALL_TRANSFER: Call = Call::System(frame_system::Call::remark { - remark: TRANSFER.to_vec() - }); - pub static ref CALL_FEATURE: Call = Call::System(frame_system::Call::remark { - remark: FEATURE.to_vec() - }); - pub static ref CALL_XCM: Call = Call::System(frame_system::Call::remark { remark: XCM.to_vec() }); - pub static ref CALL_SYSTEM: Call = Call::System(frame_system::Call::remark { - remark: SYSTEM.to_vec() - }); -} - -pub struct TransferCalls; -impl Contains for TransferCalls { - fn contains(t: &Call) -> bool { - if let Call::System(frame_system::Call::remark { remark }) = t { - &remark[..] == TRANSFER - } else { - false - } - } -} - -pub struct FeatureCalls; -impl Contains for FeatureCalls { - fn contains(t: &Call) -> bool { - if let Call::System(frame_system::Call::remark { remark }) = t { - &remark[..] == FEATURE - } else { - false - } - } -} -pub struct XcmCalls; -impl Contains for XcmCalls { - fn contains(t: &Call) -> bool { - if let Call::System(frame_system::Call::remark { remark }) = t { - &remark[..] == XCM - } else { - false - } - } -} - -pub struct SystemCalls; -impl Contains for SystemCalls { - fn contains(t: &Call) -> bool { - if let Call::System(frame_system::Call::remark { remark }) = t { - &remark[..] == SYSTEM - } else { - false - } - } -} - -#[derive(Clone, Default)] -pub struct ExtBuilder {} - -impl ExtBuilder { - pub fn build(self) -> sp_io::TestExternalities { - let storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); - sp_io::TestExternalities::new(storage) - } - - #[cfg(feature = "runtime-benchmarks")] - pub fn build_with_keystore(self) -> sp_io::TestExternalities { - let mut ext = self.build(); - - let keystore = sp_keystore::testing::KeyStore::new(); - ext.register_extension(sp_keystore::KeystoreExt(std::sync::Arc::new(keystore))); - - ext - } -} diff --git a/pallets/pallet-dyn-filter/src/setting.rs b/pallets/pallet-dyn-filter/src/setting.rs deleted file mode 100644 index d0737253dc..0000000000 --- a/pallets/pallet-dyn-filter/src/setting.rs +++ /dev/null @@ -1,28 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The KILT Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::RuntimeDebug; -use scale_info::TypeInfo; - -#[derive(Copy, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Default, RuntimeDebug, PartialEq, Eq)] -pub struct FilterSettings { - pub transfer_disabled: bool, - pub feature_disabled: bool, - pub xcm_disabled: bool, -} diff --git a/pallets/pallet-dyn-filter/src/tests.rs b/pallets/pallet-dyn-filter/src/tests.rs deleted file mode 100644 index ed3bad16b7..0000000000 --- a/pallets/pallet-dyn-filter/src/tests.rs +++ /dev/null @@ -1,67 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The KILT Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -use frame_support::{assert_ok, traits::Contains}; -use itertools::Itertools; - -use crate::{ - mock::{ExtBuilder, Origin, Test, CALL_FEATURE, CALL_SYSTEM, CALL_TRANSFER, CALL_XCM}, - setting::FilterSettings, - Pallet, -}; - -#[test] -fn check_filter() { - ExtBuilder::default().build().execute_with(|| { - assert!(Pallet::::contains(&CALL_TRANSFER)); - assert!(Pallet::::contains(&CALL_FEATURE)); - assert!(Pallet::::contains(&CALL_XCM)); - assert!(Pallet::::contains(&CALL_SYSTEM)); - - for items in [true, false].iter().combinations_with_replacement(3) { - assert_ok!(Pallet::::set_filter( - Origin::root(), - FilterSettings { - transfer_disabled: *items[0], - feature_disabled: *items[1], - xcm_disabled: *items[2], - }, - )); - - assert!(Pallet::::contains(&CALL_SYSTEM)); - assert_ne!( - *items[0], - Pallet::::contains(&CALL_TRANSFER), - "Didn't filter transfer, Setting: {:?}", - items - ); - assert_ne!( - *items[1], - Pallet::::contains(&CALL_FEATURE), - "Didn't filter feature, Setting: {:?}", - items - ); - assert_ne!( - *items[2], - Pallet::::contains(&CALL_XCM), - "Didn't filter xcm, Setting: {:?}", - items - ); - } - }); -} diff --git a/pallets/relay-migration/Cargo.toml b/pallets/relay-migration/Cargo.toml deleted file mode 100644 index 8f53ee7b62..0000000000 --- a/pallets/relay-migration/Cargo.toml +++ /dev/null @@ -1,61 +0,0 @@ -[package] -authors = ["KILT "] -description = "Initiate migration to another relay chain" -edition = "2021" -name = "pallet-relay-migration" -repository = "https://github.com/KILTprotocol/kilt-node" -version = "1.7.3" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]} -cumulus-pallet-parachain-system = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.27"} -cumulus-primitives-core = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.27"} -log = "0.4.17" -pallet-xcm = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.27"} -polkadot-core-primitives = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.27"} -polkadot-runtime-common = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.27"} -scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} -xcm = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.27"} - -# KILT -kilt-support = {default-features = false, path = "../../support"} - -# Substrate dependencies -frame-support = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -frame-system = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -sp-core = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -sp-io = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -sp-runtime = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} -sp-std = {branch = "polkadot-v0.9.27", default-features = false, git = "https://github.com/paritytech/substrate"} - -# benchmarking -frame-benchmarking = {branch = "polkadot-v0.9.27", optional = true, default-features = false, git = "https://github.com/paritytech/substrate"} - -[features] -default = ["std"] -std = [ - "codec/std", - "cumulus-pallet-parachain-system/std", - "cumulus-primitives-core/std", - "frame-benchmarking/std", - "frame-support/std", - "frame-system/std", - "kilt-support/std", - "log/std", - "pallet-xcm/std", - "polkadot-core-primitives/std", - "polkadot-runtime-common/std", - "scale-info/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", - "sp-std/std", - "xcm/std", -] -try-runtime = [ - "frame-support/try-runtime", - "kilt-support/try-runtime", -] diff --git a/pallets/relay-migration/src/lib.rs b/pallets/relay-migration/src/lib.rs deleted file mode 100644 index 8c458c2718..0000000000 --- a/pallets/relay-migration/src/lib.rs +++ /dev/null @@ -1,144 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The KILT Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -//! # Relay migration initialization pallet -//! -//! This pallet provides means of sending an XCM messages to the relay chain by -//! a configurable origin and switching the associated relay number block checks -//! between strictly and any. -//! -//! - [`Pallet`] - -#![cfg_attr(not(feature = "std"), no_std)] - -pub use pallet::*; - -#[frame_support::pallet] -pub mod pallet { - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - use kilt_support::traits::RelayCallBuilder; - use sp_std::vec::Vec; - use xcm::v2::{Junctions::Here, Parent}; - - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config + pallet_xcm::Config { - type Event: From> + IsType<::Event>; - - /// Origin from which calls of this pallet can be made. - type ApproveOrigin: EnsureOrigin<::Origin>; - - /// The Call builder for communicating with RelayChain via XCM - /// messaging. - type RelayChainCallBuilder: RelayCallBuilder< - AccountId = Self::AccountId, - Balance = polkadot_core_primitives::Balance, - >; - } - - /// Switch between RelayNumberStrictlyIncreases and AnyRelayNumber. - #[pallet::storage] - #[pallet::getter(fn relay_block_number_strictly_increases)] - pub(crate) type RelayNumberStrictlyIncreases = StorageValue<_, bool, ValueQuery>; - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// The parachain lease swap was initiated. - LeaseSwapInitiated, - /// The requirement for associated relay block numbers was set - RelayNumberCheckSet { - /// Reflects setting to RelayNumberStrictlyIncreases - strict: bool, - }, - } - - #[pallet::error] - pub enum Error {} - - #[pallet::call] - impl Pallet { - /// Set an XCM call to the relay chain. - /// - /// Has to be done pre migration. - #[pallet::weight(1_000_000 + T::DbWeight::get().reads_writes(10, 10))] - pub fn send_swap_call_bytes( - origin: OriginFor, - relay_call: Vec, - relay_balance: u128, - max_weight: u64, - ) -> DispatchResult { - T::ApproveOrigin::ensure_origin(origin)?; - let xcm_message = - T::RelayChainCallBuilder::finalize_call_into_xcm_message(relay_call, relay_balance, max_weight); - - let result = pallet_xcm::Pallet::::send_xcm(Here, Parent, xcm_message); - log::debug!("Sending XCM with result: {:?}", result); - - Self::deposit_event(Event::LeaseSwapInitiated); - - Ok(()) - } - - /// Set the associated relay block number to be - /// RelayNumberStrictlyIncreases. - /// - /// Has to be done post migration. - #[pallet::weight(100_000 + T::DbWeight::get().reads_writes(1, 1))] - pub fn enable_strict_relay_number_check(origin: OriginFor) -> DispatchResult { - T::ApproveOrigin::ensure_origin(origin)?; - RelayNumberStrictlyIncreases::::put(true); - - Self::deposit_event(Event::RelayNumberCheckSet { strict: true }); - - Ok(()) - } - - /// Set the associated relay block number to be AnyRelayNumber. - /// - /// Has to be done pre migration. - #[pallet::weight(100_000 + T::DbWeight::get().reads_writes(1, 1))] - pub fn disable_strict_relay_number_check(origin: OriginFor) -> DispatchResult { - T::ApproveOrigin::ensure_origin(origin)?; - RelayNumberStrictlyIncreases::::put(false); - - Self::deposit_event(Event::RelayNumberCheckSet { strict: false }); - - Ok(()) - } - } - - impl cumulus_pallet_parachain_system::CheckAssociatedRelayNumber for Pallet { - fn check_associated_relay_number( - current: polkadot_core_primitives::BlockNumber, - previous: polkadot_core_primitives::BlockNumber, - ) { - if RelayNumberStrictlyIncreases::::get() { - cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases::check_associated_relay_number( - current, previous, - ) - } else { - cumulus_pallet_parachain_system::AnyRelayNumber::check_associated_relay_number(current, previous) - } - } - } -} diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs index 93d54fefd1..05028e5368 100644 --- a/runtimes/common/src/migrations.rs +++ b/runtimes/common/src/migrations.rs @@ -15,3 +15,68 @@ // along with this program. If not, see . // If you feel like getting in touch with us, you can do so at info@botlabs.org + +use sp_std::marker::PhantomData; + +use frame_support::{ + traits::{Get, OnRuntimeUpgrade}, + StorageHasher, Twox128, +}; + +pub struct RemoveRelocationPallets(PhantomData); + +impl OnRuntimeUpgrade for RemoveRelocationPallets { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + log::info!("Pre check RemoveRelocationPallets."); + let has_migration_storage = frame_support::storage::migration::have_storage_value( + b"RelayMigration", + b"RelayNumberStrictlyIncreases", + b"", + ); + let has_filter_storage = frame_support::storage::migration::have_storage_value(b"DynFilter", b"Filter", b""); + + match (has_migration_storage, has_filter_storage) { + (false, false) => Err("Pallets not present"), + (true, false) => Err("DynFilter not present"), + (false, true) => Err("RelayMigration not present"), + _ => Ok(()), + } + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let entries: u32 = 1; + if frame_support::storage::unhashed::clear_prefix(&Twox128::hash(b"RelayMigration"), Some(entries), None) + .maybe_cursor + .is_some() + { + log::warn!("Pallet RelayMigration not removed entirely") + } + if frame_support::storage::unhashed::clear_prefix(&Twox128::hash(b"DynFilter"), Some(entries), None) + .maybe_cursor + .is_some() + { + log::warn!("Pallet DynFilter not removed entirely") + } + + ::DbWeight::get().writes((entries * 2).into()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + log::info!("Post check RemoveRelocationPallets."); + let has_migration_storage = frame_support::storage::migration::have_storage_value( + b"RelayMigration", + b"RelayNumberStrictlyIncreases", + b"", + ); + let has_filter_storage = frame_support::storage::migration::have_storage_value(b"DynFilter", b"Filter", b""); + + match (has_migration_storage, has_filter_storage) { + (false, false) => Ok(()), + (true, false) => Err("RelayMigration still present"), + (false, true) => Err("DynFilter still present"), + (true, true) => Err("Pallets still present"), + } + } +} diff --git a/runtimes/peregrine/Cargo.toml b/runtimes/peregrine/Cargo.toml index a2a840a352..245feb8adf 100644 --- a/runtimes/peregrine/Cargo.toml +++ b/runtimes/peregrine/Cargo.toml @@ -29,9 +29,7 @@ delegation = {path = "../../pallets/delegation", default-features = false} did = {path = "../../pallets/did", default-features = false} kilt-support = {path = "../../support", default-features = false} pallet-did-lookup = {path = "../../pallets/pallet-did-lookup", default-features = false} -pallet-dyn-filter = {path = "../../pallets/pallet-dyn-filter", default-features = false} pallet-inflation = {path = "../../pallets/pallet-inflation", default-features = false} -pallet-relay-migration = {path = "../../pallets/relay-migration", default-features = false} pallet-web3-names = {path = "../../pallets/pallet-web3-names", default-features = false} parachain-staking = {path = "../../pallets/parachain-staking", default-features = false} runtime-common = {path = "../../runtimes/common", default-features = false} @@ -120,7 +118,6 @@ runtime-benchmarks = [ "pallet-collective/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-did-lookup/runtime-benchmarks", - "pallet-dyn-filter/runtime-benchmarks", "pallet-indices/runtime-benchmarks", "pallet-inflation/runtime-benchmarks", "pallet-membership/runtime-benchmarks", @@ -165,11 +162,9 @@ std = [ "pallet-collective/std", "pallet-democracy/std", "pallet-did-lookup/std", - "pallet-dyn-filter/std", "pallet-indices/std", "pallet-inflation/std", "pallet-membership/std", - "pallet-relay-migration/std", "pallet-preimage/std", "pallet-proxy/std", "pallet-randomness-collective-flip/std", @@ -222,7 +217,6 @@ try-runtime = [ "pallet-collective/try-runtime", "pallet-democracy/try-runtime", "pallet-did-lookup/try-runtime", - "pallet-dyn-filter/try-runtime", "pallet-indices/try-runtime", "pallet-membership/try-runtime", "pallet-preimage/try-runtime", diff --git a/runtimes/peregrine/src/filter.rs b/runtimes/peregrine/src/filter.rs deleted file mode 100644 index d95b7e6025..0000000000 --- a/runtimes/peregrine/src/filter.rs +++ /dev/null @@ -1,48 +0,0 @@ -use frame_support::traits::Contains; - -use super::Call; - -pub struct TransferCalls; -impl Contains for TransferCalls { - fn contains(t: &Call) -> bool { - matches!( - t, - Call::Balances(..) - | Call::Indices(pallet_indices::Call::force_transfer { .. } | pallet_indices::Call::transfer { .. }) - | Call::Vesting( - pallet_vesting::Call::force_vested_transfer { .. } | pallet_vesting::Call::vested_transfer { .. } - ) - ) - } -} - -pub struct FeatureCalls; -impl Contains for FeatureCalls { - fn contains(t: &Call) -> bool { - matches!( - t, - Call::Attestation(..) - | Call::Ctype(..) - | Call::Delegation(..) - | Call::Did(..) | Call::DidLookup(..) - | Call::Web3Names(..) - ) - } -} - -pub struct XcmCalls; -impl Contains for XcmCalls { - fn contains(t: &Call) -> bool { - matches!(t, Call::PolkadotXcm(..)) - } -} - -pub struct SystemCalls; -impl Contains for SystemCalls { - fn contains(t: &Call) -> bool { - matches!( - t, - Call::System(_) | Call::ParachainSystem(..) | Call::Timestamp(..) | Call::Sudo(..) - ) - } -} diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index bb509ed313..fe4e7da5b3 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -26,9 +26,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use codec::{Decode, Encode, MaxEncodedLen}; +use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use frame_support::{ construct_runtime, parameter_types, - traits::{EitherOfDiverse, InstanceFilter, PrivilegeCmp}, + traits::{EitherOfDiverse, Everything, InstanceFilter, PrivilegeCmp}, weights::{constants::RocksDbWeight, ConstantMultiplier, Weight}, }; use frame_system::EnsureRoot; @@ -47,13 +48,12 @@ use xcm_executor::XcmExecutor; use delegation::DelegationAc; pub use parachain_staking::InflationInfo; -use kilt_support::relay::RelayChainCallBuilder; use runtime_common::{ authorization::{AuthorizationId, PalletAuthorize}, constants::{self, EXISTENTIAL_DEPOSIT, KILT}, fees::{ToAuthor, WeightToFee}, - pallet_id, AccountId, AuthorityId, Balance, BlockHashCount, BlockLength, BlockNumber, BlockWeights, DidIdentifier, - FeeSplit, Hash, Header, Index, Signature, SlowAdjustingFeeUpdate, + migrations, pallet_id, AccountId, AuthorityId, Balance, BlockHashCount, BlockLength, BlockNumber, BlockWeights, + DidIdentifier, FeeSplit, Hash, Header, Index, Signature, SlowAdjustingFeeUpdate, }; use crate::xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; @@ -63,13 +63,12 @@ use sp_version::NativeVersion; #[cfg(feature = "runtime-benchmarks")] use {frame_system::EnsureSigned, kilt_support::signature::AlwaysVerify, runtime_common::benchmarks::DummySignature}; -mod filter; -#[cfg(test)] -mod tests; - #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; +#[cfg(test)] +mod tests; + mod weights; mod xcm_config; @@ -140,7 +139,7 @@ impl frame_system::Config for Runtime { type OnNewAccount = (); type OnKilledAccount = (); type DbWeight = RocksDbWeight; - type BaseCallFilter = DynFilter; + type BaseCallFilter = Everything; type SystemWeightInfo = weights::frame_system::WeightInfo; type BlockWeights = BlockWeights; type BlockLength = BlockLength; @@ -219,9 +218,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedDmpWeight = ReservedDmpWeight; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; - // We temporarily control this via the RelayMigration pallet which can toggle - // between strict and any. - type CheckAssociatedRelayNumber = RelayMigration; + type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; } impl parachain_info::Config for Runtime {} @@ -666,12 +663,6 @@ impl parachain_staking::Config for Runtime { const BLOCKS_PER_YEAR: Self::BlockNumber = constants::BLOCKS_PER_YEAR; } -impl pallet_relay_migration::Config for Runtime { - type Event = Event; - type ApproveOrigin = ApproveOrigin; - type RelayChainCallBuilder = RelayChainCallBuilder; -} - impl pallet_utility::Config for Runtime { type Event = Event; type Call = Call; @@ -846,23 +837,6 @@ impl InstanceFilter for ProxyType { } } -type DynFilterOrigin = EitherOfDiverse< - EnsureRoot, - pallet_collective::EnsureProportionAtLeast, ->; - -impl pallet_dyn_filter::Config for Runtime { - type Event = Event; - type WeightInfo = pallet_dyn_filter::default_weights::SubstrateWeight; - - type ApproveOrigin = DynFilterOrigin; - - type TransferCall = filter::TransferCalls; - type FeatureCall = filter::FeatureCalls; - type XcmCall = filter::XcmCalls; - type SystemCall = filter::SystemCalls; -} - impl pallet_proxy::Config for Runtime { type Event = Event; type Call = Call; @@ -908,8 +882,8 @@ construct_runtime! { // placeholder: parachain council election = 33, TechnicalMembership: pallet_membership:: = 34, Treasury: pallet_treasury = 35, - RelayMigration: pallet_relay_migration::{Pallet, Call, Storage, Event} = 36, - DynFilter: pallet_dyn_filter = 37, + // DELETED: RelayMigration: pallet_relay_migration::{Pallet, Call, Storage, Event} = 36, + // DELETED: DynFilter: pallet_dyn_filter = 37, // Utility module. Utility: pallet_utility = 40, @@ -1038,7 +1012,7 @@ pub type Executive = frame_executive::Executive< // Executes pallet hooks in reverse order of definition in construct_runtime // If we want to switch to AllPalletsWithSystem, we need to reorder the staking pallets AllPalletsReversedWithSystemFirst, - (), + migrations::RemoveRelocationPallets, >; impl_runtime_apis! { diff --git a/runtimes/spiritnet/Cargo.toml b/runtimes/spiritnet/Cargo.toml index 0a96c3d800..a7a1795228 100644 --- a/runtimes/spiritnet/Cargo.toml +++ b/runtimes/spiritnet/Cargo.toml @@ -29,9 +29,7 @@ delegation = {path = "../../pallets/delegation", default-features = false} did = {path = "../../pallets/did", default-features = false} kilt-support = {path = "../../support", default-features = false} pallet-did-lookup = {path = "../../pallets/pallet-did-lookup", default-features = false} -pallet-dyn-filter = {path = "../../pallets/pallet-dyn-filter", default-features = false} pallet-inflation = {path = "../../pallets/pallet-inflation", default-features = false} -pallet-relay-migration = {path = "../../pallets/relay-migration", default-features = false} pallet-web3-names = {path = "../../pallets/pallet-web3-names", default-features = false} parachain-staking = {path = "../../pallets/parachain-staking", default-features = false} runtime-common = {path = "../../runtimes/common", default-features = false} @@ -119,7 +117,6 @@ runtime-benchmarks = [ "pallet-collective/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-did-lookup/runtime-benchmarks", - "pallet-dyn-filter/runtime-benchmarks", "pallet-indices/runtime-benchmarks", "pallet-inflation/runtime-benchmarks", "pallet-membership/runtime-benchmarks", @@ -165,11 +162,9 @@ std = [ "pallet-collective/std", "pallet-democracy/std", "pallet-did-lookup/std", - "pallet-dyn-filter/std", "pallet-indices/std", "pallet-inflation/std", "pallet-membership/std", - "pallet-relay-migration/std", "pallet-preimage/std", "pallet-proxy/std", "pallet-randomness-collective-flip/std", @@ -221,7 +216,6 @@ try-runtime = [ "pallet-collective/try-runtime", "pallet-democracy/try-runtime", "pallet-did-lookup/try-runtime", - "pallet-dyn-filter/try-runtime", "pallet-indices/try-runtime", "pallet-membership/try-runtime", "pallet-preimage/try-runtime", diff --git a/runtimes/spiritnet/src/filter.rs b/runtimes/spiritnet/src/filter.rs deleted file mode 100644 index c655a5411d..0000000000 --- a/runtimes/spiritnet/src/filter.rs +++ /dev/null @@ -1,45 +0,0 @@ -use frame_support::traits::Contains; - -use super::Call; - -pub struct TransferCalls; -impl Contains for TransferCalls { - fn contains(t: &Call) -> bool { - matches!( - t, - Call::Balances(..) - | Call::Indices(pallet_indices::Call::force_transfer { .. } | pallet_indices::Call::transfer { .. }) - | Call::Vesting( - pallet_vesting::Call::force_vested_transfer { .. } | pallet_vesting::Call::vested_transfer { .. } - ) - ) - } -} - -pub struct FeatureCalls; -impl Contains for FeatureCalls { - fn contains(t: &Call) -> bool { - matches!( - t, - Call::Attestation(..) - | Call::Ctype(..) - | Call::Delegation(..) - | Call::Did(..) | Call::DidLookup(..) - | Call::Web3Names(..) - ) - } -} - -pub struct XcmCalls; -impl Contains for XcmCalls { - fn contains(t: &Call) -> bool { - matches!(t, Call::PolkadotXcm(..)) - } -} - -pub struct SystemCalls; -impl Contains for SystemCalls { - fn contains(t: &Call) -> bool { - matches!(t, Call::System(_) | Call::ParachainSystem(..) | Call::Timestamp(..)) - } -} diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index 1a0f1a8500..9de688ae77 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -26,9 +26,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use codec::{Decode, Encode, MaxEncodedLen}; +use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use frame_support::{ construct_runtime, parameter_types, - traits::{EitherOfDiverse, InstanceFilter, PrivilegeCmp}, + traits::{EitherOfDiverse, Everything, InstanceFilter, PrivilegeCmp}, weights::{constants::RocksDbWeight, ConstantMultiplier, Weight}, }; use frame_system::EnsureRoot; @@ -47,13 +48,12 @@ use xcm_executor::XcmExecutor; use delegation::DelegationAc; pub use parachain_staking::InflationInfo; -use kilt_support::relay::RelayChainCallBuilder; use runtime_common::{ authorization::{AuthorizationId, PalletAuthorize}, constants::{self, EXISTENTIAL_DEPOSIT, KILT}, fees::{ToAuthor, WeightToFee}, - pallet_id, AccountId, AuthorityId, Balance, BlockHashCount, BlockLength, BlockNumber, BlockWeights, DidIdentifier, - FeeSplit, Hash, Header, Index, Signature, SlowAdjustingFeeUpdate, + migrations, pallet_id, AccountId, AuthorityId, Balance, BlockHashCount, BlockLength, BlockNumber, BlockWeights, + DidIdentifier, FeeSplit, Hash, Header, Index, Signature, SlowAdjustingFeeUpdate, }; use crate::xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; @@ -63,7 +63,6 @@ use sp_version::NativeVersion; #[cfg(feature = "runtime-benchmarks")] use {frame_system::EnsureSigned, kilt_support::signature::AlwaysVerify, runtime_common::benchmarks::DummySignature}; -mod filter; #[cfg(test)] mod tests; @@ -140,7 +139,7 @@ impl frame_system::Config for Runtime { type OnNewAccount = (); type OnKilledAccount = (); type DbWeight = RocksDbWeight; - type BaseCallFilter = DynFilter; + type BaseCallFilter = Everything; type SystemWeightInfo = weights::frame_system::WeightInfo; type BlockWeights = BlockWeights; type BlockLength = BlockLength; @@ -216,7 +215,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; // We temporarily control this via the RelayMigration pallet which can toggle // between strict and any. - type CheckAssociatedRelayNumber = RelayMigration; + type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; } impl parachain_info::Config for Runtime {} @@ -660,12 +659,6 @@ impl parachain_staking::Config for Runtime { const BLOCKS_PER_YEAR: Self::BlockNumber = constants::BLOCKS_PER_YEAR; } -impl pallet_relay_migration::Config for Runtime { - type Event = Event; - type ApproveOrigin = ApproveOrigin; - type RelayChainCallBuilder = RelayChainCallBuilder; -} - impl pallet_utility::Config for Runtime { type Event = Event; type Call = Call; @@ -854,23 +847,6 @@ impl pallet_proxy::Config for Runtime { type WeightInfo = weights::pallet_proxy::WeightInfo; } -type DynFilterOrigin = EitherOfDiverse< - EnsureRoot, - pallet_collective::EnsureProportionAtLeast, ->; - -impl pallet_dyn_filter::Config for Runtime { - type Event = Event; - type WeightInfo = pallet_dyn_filter::default_weights::SubstrateWeight; - - type ApproveOrigin = DynFilterOrigin; - - type TransferCall = filter::TransferCalls; - type FeatureCall = filter::FeatureCalls; - type XcmCall = filter::XcmCalls; - type SystemCall = filter::SystemCalls; -} - construct_runtime! { pub enum Runtime where Block = Block, @@ -900,8 +876,8 @@ construct_runtime! { // placeholder: parachain council election = 33, TechnicalMembership: pallet_membership:: = 34, Treasury: pallet_treasury = 35, - RelayMigration: pallet_relay_migration::{Pallet, Call, Storage, Event} = 36, - DynFilter: pallet_dyn_filter = 37, + // DELETED: RelayMigration: pallet_relay_migration::{Pallet, Call, Storage, Event} = 36, + // DELETED: DynFilter: pallet_dyn_filter = 37, // Utility module. Utility: pallet_utility = 40, @@ -1030,7 +1006,7 @@ pub type Executive = frame_executive::Executive< // Executes pallet hooks in reverse order of definition in construct_runtime // If we want to switch to AllPalletsWithSystem, we need to reorder the staking pallets AllPalletsReversedWithSystemFirst, - (), + migrations::RemoveRelocationPallets, >; impl_runtime_apis! { diff --git a/runtimes/standalone/Cargo.toml b/runtimes/standalone/Cargo.toml index 096f7811a9..9bdb116fcc 100644 --- a/runtimes/standalone/Cargo.toml +++ b/runtimes/standalone/Cargo.toml @@ -23,7 +23,6 @@ delegation = {default-features = false, path = "../../pallets/delegation"} did = {default-features = false, path = "../../pallets/did"} kilt-support = {path = "../../support", default-features = false, optional = true} pallet-did-lookup = {default-features = false, path = "../../pallets/pallet-did-lookup"} -pallet-dyn-filter = {default-features = false, path = "../../pallets/pallet-dyn-filter"} pallet-web3-names = {default-features = false, path = "../../pallets/pallet-web3-names"} runtime-common = {path = "../../runtimes/common", default-features = false} @@ -86,7 +85,6 @@ runtime-benchmarks = [ "kilt-support/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-did-lookup/runtime-benchmarks", - "pallet-dyn-filter/runtime-benchmarks", "pallet-indices/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-web3-names/runtime-benchmarks", @@ -111,7 +109,6 @@ std = [ "pallet-authorship/std", "pallet-balances/std", "pallet-did-lookup/std", - "pallet-dyn-filter/std", "pallet-grandpa/std", "pallet-indices/std", "pallet-proxy/std", @@ -152,7 +149,6 @@ try-runtime = [ "pallet-authorship/try-runtime", "pallet-balances/try-runtime", "pallet-did-lookup/try-runtime", - "pallet-dyn-filter/try-runtime", "pallet-grandpa/try-runtime", "pallet-indices/try-runtime", "pallet-proxy/try-runtime", diff --git a/runtimes/standalone/src/filter.rs b/runtimes/standalone/src/filter.rs deleted file mode 100644 index 08f59a3bbd..0000000000 --- a/runtimes/standalone/src/filter.rs +++ /dev/null @@ -1,42 +0,0 @@ -use frame_support::traits::Contains; - -use super::Call; - -pub struct TransferCalls; -impl Contains for TransferCalls { - fn contains(t: &Call) -> bool { - matches!( - t, - Call::Balances(..) - | Call::Indices(pallet_indices::Call::force_transfer { .. } | pallet_indices::Call::transfer { .. }) - ) - } -} - -pub struct FeatureCalls; -impl Contains for FeatureCalls { - fn contains(t: &Call) -> bool { - matches!( - t, - Call::Attestation(..) - | Call::Ctype(..) - | Call::Delegation(..) - | Call::Did(..) | Call::DidLookup(..) - | Call::Web3Names(..) - ) - } -} - -pub struct XcmCalls; -impl Contains for XcmCalls { - fn contains(_: &Call) -> bool { - false - } -} - -pub struct SystemCalls; -impl Contains for SystemCalls { - fn contains(t: &Call) -> bool { - matches!(t, Call::System(..) | Call::Sudo(..) | Call::Timestamp(..)) - } -} diff --git a/runtimes/standalone/src/lib.rs b/runtimes/standalone/src/lib.rs index dc1029624d..ce8dc703c9 100644 --- a/runtimes/standalone/src/lib.rs +++ b/runtimes/standalone/src/lib.rs @@ -30,7 +30,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{ construct_runtime, parameter_types, - traits::{Currency, InstanceFilter, KeyOwnerProofSystem}, + traits::{Currency, Everything, InstanceFilter, KeyOwnerProofSystem}, weights::{constants::RocksDbWeight, ConstantMultiplier, IdentityFee}, }; pub use frame_system::Call as SystemCall; @@ -76,8 +76,6 @@ use frame_system::EnsureSigned; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -mod filter; - /// Digest item type. pub type DigestItem = generic::DigestItem; @@ -142,7 +140,7 @@ parameter_types! { impl frame_system::Config for Runtime { /// The basic call filter to use in dispatchable. - type BaseCallFilter = DynFilter; + type BaseCallFilter = Everything; /// Block & extrinsics weights: base values and limits. type BlockWeights = runtime_common::BlockWeights; /// The maximum length of a block (in bytes). @@ -613,18 +611,6 @@ impl pallet_proxy::Config for Runtime { type WeightInfo = (); } -impl pallet_dyn_filter::Config for Runtime { - type Event = Event; - type WeightInfo = pallet_dyn_filter::default_weights::SubstrateWeight; - - type ApproveOrigin = EnsureRoot; - - type TransferCall = filter::TransferCalls; - type FeatureCall = filter::FeatureCalls; - type XcmCall = filter::XcmCalls; - type SystemCall = filter::SystemCalls; -} - construct_runtime!( pub enum Runtime where Block = Block, @@ -658,7 +644,6 @@ construct_runtime!( // ElectionsPhragmen: pallet_elections_phragmen = 28, // TechnicalMembership: pallet_membership = 29, // Treasury: pallet_treasury = 30, - DynFilter: pallet_dyn_filter = 31, // // System scheduler. // Scheduler: pallet_scheduler = 32, diff --git a/support/src/lib.rs b/support/src/lib.rs index 1cb723b63c..7a58831778 100644 --- a/support/src/lib.rs +++ b/support/src/lib.rs @@ -24,7 +24,6 @@ use sp_runtime::traits::Zero; pub mod deposit; #[cfg(any(feature = "runtime-benchmarks", feature = "mock"))] pub mod mock; -pub mod relay; pub mod signature; pub mod traits; diff --git a/support/src/relay.rs b/support/src/relay.rs deleted file mode 100644 index 7bd0187ba0..0000000000 --- a/support/src/relay.rs +++ /dev/null @@ -1,113 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The KILT Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -//! # RelayChain Support Module -//! -//! Provides means of of handling relaychain related utilities and -//! business logic such as finalizing XCM calls. - -#![cfg_attr(not(feature = "std"), no_std)] -#![allow(clippy::unused_unit)] - -use codec::{Decode, Encode, FullCodec}; -use frame_support::{traits::Get, weights::Weight}; -use frame_system::Config; -use scale_info::TypeInfo; -use sp_std::{boxed::Box, marker::PhantomData, prelude::*}; -use xcm::latest::prelude::*; - -pub use cumulus_primitives_core::ParaId; - -use crate::traits::RelayCallBuilder; - -#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)] -pub enum UtilityCall { - #[codec(index = 1)] - AsDerivative(u16, RelayChainCall), - #[codec(index = 2)] - BatchAll(Vec), -} - -#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)] -pub enum RegistrarCall { - #[codec(index = 4)] - Swap(ParaId, ParaId), -} - -/// The encoded index correspondes to Kusama's Runtime module configuration. -/// https://github.com/paritytech/polkadot/blob/444e96ae34bcec8362f0f947a07bd912b32ca48f/runtime/kusama/src/lib.rs#L1379 -#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)] -pub enum RelayChainCall { - #[codec(index = 24)] - Utility(Box>), - #[codec(index = 70)] - Registrar(RegistrarCall), -} - -#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)] -pub struct RelayChainCallBuilder>(PhantomData<(T, ParachainId)>); - -impl> RelayCallBuilder for RelayChainCallBuilder -where - T::AccountId: FullCodec, - RelayChainCall: FullCodec, -{ - type AccountId = T::AccountId; - type Balance = polkadot_core_primitives::Balance; - type RelayChainCall = RelayChainCall; - - fn utility_batch_call(calls: Vec) -> Self::RelayChainCall { - RelayChainCall::Utility(Box::new(UtilityCall::BatchAll(calls))) - } - - fn utility_as_derivative_call(call: Self::RelayChainCall, index: u16) -> Self::RelayChainCall { - RelayChainCall::Utility(Box::new(UtilityCall::AsDerivative(index, call))) - } - - fn swap_call(id: ParaId, other: ParaId) -> Self::RelayChainCall { - RelayChainCall::Registrar(RegistrarCall::Swap(id, other)) - } - - fn finalize_call_into_xcm_message(call: Vec, extra_fee: Self::Balance, weight: Weight) -> Xcm<()> { - let asset = MultiAsset { - id: Concrete(MultiLocation::here()), - fun: Fungibility::Fungible(extra_fee), - }; - Xcm(vec![ - WithdrawAsset(asset.clone().into()), - BuyExecution { - fees: asset, - weight_limit: Unlimited, - }, - Transact { - origin_type: OriginKind::Native, - require_weight_at_most: weight, - call: call.into(), - }, - RefundSurplus, - DepositAsset { - assets: All.into(), - max_assets: 1, - beneficiary: MultiLocation { - parents: 0, - interior: X1(Parachain(ParachainId::get().into())), - }, - }, - ]) - } -} diff --git a/support/src/traits.rs b/support/src/traits.rs index 99ae91ce31..07448b8a99 100644 --- a/support/src/traits.rs +++ b/support/src/traits.rs @@ -16,13 +16,6 @@ // If you feel like getting in touch with us, you can do so at info@botlabs.org -use codec::{EncodeLike, FullCodec}; -use cumulus_primitives_core::ParaId; -use frame_support::weights::Weight; -use scale_info::TypeInfo; -use sp_std::vec::Vec; -use xcm::latest::Xcm; - /// The sources of a call struct. /// /// This trait allows to differentiate between the sender of a call and the @@ -75,40 +68,3 @@ pub trait VersionMigratorTrait: Sized { pub trait GenerateBenchmarkOrigin { fn generate_origin(sender: AccountId, subject: SubjectId) -> OuterOrigin; } - -/// Trait to reflect calls to the relaychain which we support on the pallet -/// level. -pub trait RelayCallBuilder { - type AccountId: FullCodec; - type Balance: FullCodec; - type RelayChainCall: FullCodec + EncodeLike + sp_std::fmt::Debug + Clone + PartialEq + Eq + TypeInfo; - - /// Execute multiple calls in a batch. - /// - /// * calls: The list of calls to be executed. - fn utility_batch_call(calls: Vec) -> Self::RelayChainCall; - - /// Execute a call, replacing the `Origin` with a sub-account. - /// - /// * call: The call to be executed. Can be nested with - /// `utility_batch_call`. - /// * index: The index of the sub-account to be used as the new origin. - fn utility_as_derivative_call(call: Self::RelayChainCall, index: u16) -> Self::RelayChainCall; - - /// Execute a parachain lease swap call. - /// - /// * id: One of the two para ids. Typically, this should be the one of the - /// parachain that executes this XCM call, e.g. the source. - /// * other: The target para id with which the lease swap should be - /// executed. - fn swap_call(id: ParaId, other: ParaId) -> Self::RelayChainCall; - - /// Wrap the final calls into the latest Xcm format. - /// - /// * call: The relaychain call to be executed - /// * extra_fee: The extra fee (in relaychain currency) used for buying the - /// `weight` and `debt`. - /// * weight: The weight limit used for XCM. - /// * debt: The weight limit used to process the call. - fn finalize_call_into_xcm_message(call: Vec, extra_fee: Self::Balance, weight: Weight) -> Xcm<()>; -}