From 43a8bde83a716a577dfb979af40ed1210550242e Mon Sep 17 00:00:00 2001 From: adelarja Date: Mon, 23 Oct 2023 22:24:47 -0300 Subject: [PATCH 1/9] Added draft. --- substrate/frame/root-testing/src/lib.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/substrate/frame/root-testing/src/lib.rs b/substrate/frame/root-testing/src/lib.rs index e04c7bfa13d2..4c5507327f0e 100644 --- a/substrate/frame/root-testing/src/lib.rs +++ b/substrate/frame/root-testing/src/lib.rs @@ -36,11 +36,21 @@ pub mod pallet { use frame_system::pallet_prelude::*; #[pallet::config] - pub trait Config: frame_system::Config {} + pub trait Config: frame_system::Config { + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } #[pallet::pallet] pub struct Pallet(_); + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event, I: 'static = ()> { + /// Event dispatched when the trigger_defensive extrinsic is called. + DefensiveTestCall{} + } + #[pallet::call] impl Pallet { /// A dispatch that will fill the block weight up to the given ratio. @@ -50,5 +60,13 @@ pub mod pallet { ensure_root(origin)?; Ok(()) } + + #[pallet::call_index(1)] + #[pallet::weight(0)] + pub fn trigger_defensive(origin: OriginFor) -> DispatchResult { + ensure_root(origin)?; + Self::deposit_event(Event::DefensiveTestCall{}); + Ok(()) + } } } From eb6db71ac9bebeaa36eeb3f6315f03a95f588fe7 Mon Sep 17 00:00:00 2001 From: adelarja Date: Tue, 24 Oct 2023 00:08:45 -0300 Subject: [PATCH 2/9] Fixed some issues --- substrate/frame/root-testing/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/root-testing/src/lib.rs b/substrate/frame/root-testing/src/lib.rs index 4c5507327f0e..46a973b605ba 100644 --- a/substrate/frame/root-testing/src/lib.rs +++ b/substrate/frame/root-testing/src/lib.rs @@ -25,7 +25,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use frame_support::dispatch::DispatchResult; -use sp_runtime::Perbill; +use frame_support::sp_runtime::Perbill; pub use pallet::*; @@ -46,7 +46,7 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event, I: 'static = ()> { + pub enum Event { /// Event dispatched when the trigger_defensive extrinsic is called. DefensiveTestCall{} } From dc91740d9744e97d9f382084923387b469a5861e Mon Sep 17 00:00:00 2001 From: adelarja Date: Tue, 24 Oct 2023 00:11:17 -0300 Subject: [PATCH 3/9] Applied cargo fmt --- substrate/frame/root-testing/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/substrate/frame/root-testing/src/lib.rs b/substrate/frame/root-testing/src/lib.rs index 46a973b605ba..a2b5794d0949 100644 --- a/substrate/frame/root-testing/src/lib.rs +++ b/substrate/frame/root-testing/src/lib.rs @@ -24,8 +24,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::dispatch::DispatchResult; -use frame_support::sp_runtime::Perbill; +use frame_support::{dispatch::DispatchResult, sp_runtime::Perbill}; pub use pallet::*; @@ -48,7 +47,7 @@ pub mod pallet { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { /// Event dispatched when the trigger_defensive extrinsic is called. - DefensiveTestCall{} + DefensiveTestCall, } #[pallet::call] @@ -65,7 +64,7 @@ pub mod pallet { #[pallet::weight(0)] pub fn trigger_defensive(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; - Self::deposit_event(Event::DefensiveTestCall{}); + Self::deposit_event(Event::DefensiveTestCall); Ok(()) } } From e5aa227c9e3fe69ba47605437d6b19884034b4b9 Mon Sep 17 00:00:00 2001 From: adelarja Date: Tue, 24 Oct 2023 17:17:17 -0300 Subject: [PATCH 4/9] Added frame_support::defensive! call --- substrate/frame/root-testing/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/root-testing/src/lib.rs b/substrate/frame/root-testing/src/lib.rs index a2b5794d0949..1f2627713aad 100644 --- a/substrate/frame/root-testing/src/lib.rs +++ b/substrate/frame/root-testing/src/lib.rs @@ -64,6 +64,7 @@ pub mod pallet { #[pallet::weight(0)] pub fn trigger_defensive(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; + frame_support::defensive!("root_testing::trigger_defensive was called."); Self::deposit_event(Event::DefensiveTestCall); Ok(()) } From 2e3699e7de9d1fda9cf693c38dfb40d9c6984054 Mon Sep 17 00:00:00 2001 From: adelarja Date: Thu, 26 Oct 2023 14:10:17 -0300 Subject: [PATCH 5/9] Added pallet_root_testing to rococo and westend runtimes. --- Cargo.lock | 2 ++ polkadot/runtime/rococo/Cargo.toml | 5 ++++- polkadot/runtime/rococo/src/lib.rs | 6 ++++++ polkadot/runtime/westend/Cargo.toml | 3 +++ polkadot/runtime/westend/src/lib.rs | 6 ++++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c755be63042b..a7a9c08ee4f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14314,6 +14314,7 @@ dependencies = [ "pallet-preimage", "pallet-proxy", "pallet-recovery", + "pallet-root-testing", "pallet-scheduler", "pallet-session", "pallet-society", @@ -20387,6 +20388,7 @@ dependencies = [ "pallet-preimage", "pallet-proxy", "pallet-recovery", + "pallet-root-testing", "pallet-scheduler", "pallet-session", "pallet-session-benchmarking", diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index ebb7cd9c5ef6..dd97c01a46e8 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -67,7 +67,7 @@ pallet-scheduler = { path = "../../../substrate/frame/scheduler", default-featur pallet-session = { path = "../../../substrate/frame/session", default-features = false } pallet-society = { path = "../../../substrate/frame/society", default-features = false, features = ["experimental"] } pallet-sudo = { path = "../../../substrate/frame/sudo", default-features = false } -frame-support = { path = "../../../substrate/frame/support", default-features = false } +frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["tuples-96"] } pallet-staking = { path = "../../../substrate/frame/staking", default-features = false } frame-system = { path = "../../../substrate/frame/system", default-features = false } frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false } @@ -78,6 +78,7 @@ pallet-utility = { path = "../../../substrate/frame/utility", default-features = pallet-vesting = { path = "../../../substrate/frame/vesting", default-features = false } pallet-xcm = { path = "../../xcm/pallet-xcm", default-features = false, features=["experimental"] } pallet-xcm-benchmarks = { path = "../../xcm/pallet-xcm-benchmarks", default-features = false, optional = true } +pallet-root-testing = { path = "../../../substrate/frame/root-testing", default-features = false } frame-benchmarking = { path = "../../../substrate/frame/benchmarking", default-features = false, optional = true } frame-try-runtime = { path = "../../../substrate/frame/try-runtime", default-features = false, optional = true } @@ -146,6 +147,7 @@ std = [ "pallet-preimage/std", "pallet-proxy/std", "pallet-recovery/std", + "pallet-root-testing/std", "pallet-scheduler/std", "pallet-session/std", "pallet-society/std", @@ -251,6 +253,7 @@ try-runtime = [ "pallet-preimage/try-runtime", "pallet-proxy/try-runtime", "pallet-recovery/try-runtime", + "pallet-root-testing/try-runtime", "pallet-scheduler/try-runtime", "pallet-session/try-runtime", "pallet-society/try-runtime", diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 6894bd7bbf44..76e7055c0fd0 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1382,6 +1382,10 @@ impl pallet_sudo::Config for Runtime { type WeightInfo = weights::pallet_sudo::WeightInfo; } +impl pallet_root_testing::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + construct_runtime! { pub enum Runtime { @@ -1504,6 +1508,8 @@ construct_runtime! { // Sudo. Sudo: pallet_sudo::{Pallet, Call, Storage, Event, Config} = 255, + + RootTesting: pallet_root_testing::{Pallet, Call, Storage, Event} = 249, } } diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 40664e33a3ad..5c470f983a78 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -85,6 +85,7 @@ pallet-utility = { path = "../../../substrate/frame/utility", default-features = pallet-vesting = { path = "../../../substrate/frame/vesting", default-features = false } pallet-xcm = { path = "../../xcm/pallet-xcm", default-features = false, features=["experimental"] } pallet-xcm-benchmarks = { path = "../../xcm/pallet-xcm-benchmarks", default-features = false, optional = true } +pallet-root-testing = { path = "../../../substrate/frame/root-testing", default-features = false } frame-benchmarking = { path = "../../../substrate/frame/benchmarking", default-features = false, optional = true } frame-try-runtime = { path = "../../../substrate/frame/try-runtime", default-features = false, optional = true } @@ -161,6 +162,7 @@ std = [ "pallet-preimage/std", "pallet-proxy/std", "pallet-recovery/std", + "pallet-root-testing/std", "pallet-scheduler/std", "pallet-session/std", "pallet-society/std", @@ -274,6 +276,7 @@ try-runtime = [ "pallet-preimage/try-runtime", "pallet-proxy/try-runtime", "pallet-recovery/try-runtime", + "pallet-root-testing/try-runtime", "pallet-scheduler/try-runtime", "pallet-session/try-runtime", "pallet-society/try-runtime", diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 9ae30c376010..425ad24fb2b0 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1254,6 +1254,10 @@ impl pallet_nomination_pools::Config for Runtime { type MaxPointsToBalance = MaxPointsToBalance; } +impl pallet_root_testing::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + parameter_types! { // The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high) pub const MigrationSignedDepositPerItem: Balance = 1 * CENTS; @@ -1364,6 +1368,8 @@ construct_runtime! { // Generalized message queue MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event} = 100, + + RootTesting: pallet_root_testing = 101, } } From c693199205c6436346683a3d79d1835a319802d0 Mon Sep 17 00:00:00 2001 From: adelarja Date: Thu, 26 Oct 2023 18:26:31 -0300 Subject: [PATCH 6/9] Switched pallet order in construct_runtime --- polkadot/runtime/rococo/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 76e7055c0fd0..18c20524822c 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1506,10 +1506,11 @@ construct_runtime! { // State trie migration pallet, only temporary. StateTrieMigration: pallet_state_trie_migration = 254, + // Root testing pallet. + RootTesting: pallet_root_testing::{Pallet, Call, Storage, Event} = 249, + // Sudo. Sudo: pallet_sudo::{Pallet, Call, Storage, Event, Config} = 255, - - RootTesting: pallet_root_testing::{Pallet, Call, Storage, Event} = 249, } } From b5f59d6bb308658b3524828176f74aacbbfcd524 Mon Sep 17 00:00:00 2001 From: adelarja Date: Sat, 28 Oct 2023 12:54:25 -0300 Subject: [PATCH 7/9] Changed runtime to runtime::defensive in frame_support misc trait --- substrate/frame/support/src/traits/misc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/frame/support/src/traits/misc.rs b/substrate/frame/support/src/traits/misc.rs index eb704de4353c..22811f2510b0 100644 --- a/substrate/frame/support/src/traits/misc.rs +++ b/substrate/frame/support/src/traits/misc.rs @@ -43,7 +43,7 @@ pub const DEFENSIVE_OP_INTERNAL_ERROR: &str = "Defensive failure has been trigge macro_rules! defensive { () => { frame_support::__private::log::error!( - target: "runtime", + target: "runtime::defensive", "{}", $crate::traits::DEFENSIVE_OP_PUBLIC_ERROR ); @@ -51,7 +51,7 @@ macro_rules! defensive { }; ($error:expr $(,)?) => { frame_support::__private::log::error!( - target: "runtime", + target: "runtime::defensive", "{}: {:?}", $crate::traits::DEFENSIVE_OP_PUBLIC_ERROR, $error @@ -60,7 +60,7 @@ macro_rules! defensive { }; ($error:expr, $proof:expr $(,)?) => { frame_support::__private::log::error!( - target: "runtime", + target: "runtime::defensive", "{}: {:?}: {:?}", $crate::traits::DEFENSIVE_OP_PUBLIC_ERROR, $error, From f950f72092cf0b0a5c941671af794ceb32766acb Mon Sep 17 00:00:00 2001 From: adelarja Date: Tue, 31 Oct 2023 11:11:33 -0300 Subject: [PATCH 8/9] Fixed trait implementation in pallet-utility --- substrate/bin/node/runtime/src/lib.rs | 4 +++- substrate/frame/utility/src/tests.rs | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index a2d100e1f8b5..620b83c5f780 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1014,7 +1014,9 @@ impl pallet_remark::Config for Runtime { type RuntimeEvent = RuntimeEvent; } -impl pallet_root_testing::Config for Runtime {} +impl pallet_root_testing::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} parameter_types! { pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES; diff --git a/substrate/frame/utility/src/tests.rs b/substrate/frame/utility/src/tests.rs index cbd495a5c152..01e3f5264bff 100644 --- a/substrate/frame/utility/src/tests.rs +++ b/substrate/frame/utility/src/tests.rs @@ -132,7 +132,7 @@ frame_support::construct_runtime!( System: frame_system::{Pallet, Call, Config, Storage, Event}, Timestamp: pallet_timestamp::{Call, Inherent}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - RootTesting: pallet_root_testing::{Pallet, Call, Storage}, + RootTesting: pallet_root_testing::{Pallet, Call, Storage, Event}, Council: pallet_collective::, Utility: utility::{Pallet, Call, Event}, Example: example::{Pallet, Call}, @@ -187,7 +187,9 @@ impl pallet_balances::Config for Test { type MaxHolds = (); } -impl pallet_root_testing::Config for Test {} +impl pallet_root_testing::Config for Test { + type RuntimeEvent = RuntimeEvent; +} impl pallet_timestamp::Config for Test { type Moment = u64; From 4ca615c3466bd66080b9b54f9942f0fa75437c6d Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 31 Oct 2023 15:50:55 +0100 Subject: [PATCH 9/9] Update Cargo.lock Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 4b35303b493c..2c966cd1913d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18467,7 +18467,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "rustix 0.38.8", + "rustix 0.38.21", "windows-sys 0.48.0", ]