From 4a6d8a9bbf8609d2bb802b976c5ffbc87fa25122 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:27:23 +0530 Subject: [PATCH 1/5] Feature gate do_task in frame_system --- substrate/bin/node/runtime/Cargo.toml | 5 +++++ substrate/frame/examples/tasks/Cargo.toml | 1 + substrate/frame/examples/tasks/src/tests.rs | 13 +++++++++---- substrate/frame/system/Cargo.toml | 1 + substrate/frame/system/src/lib.rs | 10 +++++++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 8ea2988bee07..060c28d4b1ba 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -404,3 +404,8 @@ try-runtime = [ "pallet-whitelist/try-runtime", "sp-runtime/try-runtime", ] +experimental = [ + "frame-system/experimental", + "frame-support/experimental", + "pallet-example-tasks/experimental", +] diff --git a/substrate/frame/examples/tasks/Cargo.toml b/substrate/frame/examples/tasks/Cargo.toml index e26e822e40f6..48fb11a8b0b9 100644 --- a/substrate/frame/examples/tasks/Cargo.toml +++ b/substrate/frame/examples/tasks/Cargo.toml @@ -50,3 +50,4 @@ try-runtime = [ "frame-system/try-runtime", "sp-runtime/try-runtime", ] +experimental = ["frame-system/experimental", "frame-support/experimental"] diff --git a/substrate/frame/examples/tasks/src/tests.rs b/substrate/frame/examples/tasks/src/tests.rs index 6b255491091d..557c0af00d54 100644 --- a/substrate/frame/examples/tasks/src/tests.rs +++ b/substrate/frame/examples/tasks/src/tests.rs @@ -18,10 +18,13 @@ //! Tests for `pallet-example-tasks`. #![cfg(test)] -use crate::{mock::*, Numbers, Total}; -use frame_support::{assert_noop, assert_ok, traits::Task}; +use crate::{mock::*, Numbers}; +use frame_support::traits::Task; use sp_runtime::BuildStorage; +#[cfg(feature = "experimental")] +use frame_support::{assert_noop, assert_ok}; + // This function basically just builds a genesis storage key/value store according to // our desired mockup. pub fn new_test_ext() -> sp_io::TestExternalities { @@ -89,8 +92,9 @@ fn task_index_works_at_runtime_level() { }); } +#[cfg(feature = "experimental")] #[test] -fn task_execution_works() { +fn task_execution_works() { new_test_ext().execute_with(|| { System::set_block_number(1); Numbers::::insert(0, 1); @@ -105,11 +109,12 @@ fn task_execution_works() { assert_ok!(System::do_task(RuntimeOrigin::signed(1), task.clone(),)); assert_eq!(Numbers::::get(0), Some(1)); assert_eq!(Numbers::::get(1), None); - assert_eq!(Total::::get(), (1, 4)); + assert_eq!(crate::Total::::get(), (1, 4)); System::assert_last_event(frame_system::Event::::TaskCompleted { task }.into()); }); } +#[cfg(feature = "experimental")] #[test] fn task_execution_fails_for_invalid_task() { new_test_ext().execute_with(|| { diff --git a/substrate/frame/system/Cargo.toml b/substrate/frame/system/Cargo.toml index 3b454ac18f98..7b5385c4fd2b 100644 --- a/substrate/frame/system/Cargo.toml +++ b/substrate/frame/system/Cargo.toml @@ -53,6 +53,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", ] try-runtime = ["frame-support/try-runtime", "sp-runtime/try-runtime"] +experimental = ["frame-support/experimental"] [[bench]] name = "bench" diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 3697e36f3fc0..20794d58cb6b 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -323,9 +323,11 @@ pub mod pallet { #[inject_runtime_type] type RuntimeCall = (); - /// Converts a module to the index of the module, injected by `construct_runtime!`. + /// The aggregated Task type, injected by `construct_runtime!`. #[inject_runtime_type] type RuntimeTask = (); + + /// Converts a module to the index of the module, injected by `construct_runtime!`. #[inject_runtime_type] type PalletInfo = (); @@ -637,6 +639,7 @@ pub mod pallet { Ok(().into()) } + #[cfg(feature = "experimental")] #[pallet::call_index(8)] #[pallet::weight(task.weight())] pub fn do_task(origin: OriginFor, task: T::RuntimeTask) -> DispatchResultWithPostInfo { @@ -675,10 +678,13 @@ pub mod pallet { KilledAccount { account: T::AccountId }, /// On on-chain remark happened. Remarked { sender: T::AccountId, hash: T::Hash }, + #[cfg(feature = "experimental")] /// A [`Task`] has started executing TaskStarted { task: T::RuntimeTask }, + #[cfg(feature = "experimental")] /// A [`Task`] has finished executing. TaskCompleted { task: T::RuntimeTask }, + #[cfg(feature = "experimental")] /// A [`Task`] failed during execution. TaskFailed { task: T::RuntimeTask, err: DispatchError }, } @@ -702,8 +708,10 @@ pub mod pallet { NonZeroRefCount, /// The origin filter prevent the call to be dispatched. CallFiltered, + #[cfg(feature = "experimental")] /// The specified [`Task`] is not valid. InvalidTask, + #[cfg(feature = "experimental")] /// The specified [`Task`] failed during execution. FailedTask, } From f70536fd9809724790cbc4621ac3aaa09991ada9 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 14 Dec 2023 06:04:55 +0000 Subject: [PATCH 2/5] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/bin/node/runtime/Cargo.toml | 2 +- substrate/frame/examples/tasks/Cargo.toml | 2 +- substrate/frame/examples/tasks/src/tests.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index ac8675c3852e..693fd673da5d 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -408,7 +408,7 @@ try-runtime = [ "sp-runtime/try-runtime", ] experimental = [ - "frame-system/experimental", "frame-support/experimental", + "frame-system/experimental", "pallet-example-tasks/experimental", ] diff --git a/substrate/frame/examples/tasks/Cargo.toml b/substrate/frame/examples/tasks/Cargo.toml index 177f1000f5c1..438cb60c756f 100644 --- a/substrate/frame/examples/tasks/Cargo.toml +++ b/substrate/frame/examples/tasks/Cargo.toml @@ -53,4 +53,4 @@ try-runtime = [ "frame-system/try-runtime", "sp-runtime/try-runtime", ] -experimental = ["frame-system/experimental", "frame-support/experimental"] +experimental = ["frame-support/experimental", "frame-system/experimental"] diff --git a/substrate/frame/examples/tasks/src/tests.rs b/substrate/frame/examples/tasks/src/tests.rs index 557c0af00d54..fc3c69f4aef9 100644 --- a/substrate/frame/examples/tasks/src/tests.rs +++ b/substrate/frame/examples/tasks/src/tests.rs @@ -94,7 +94,7 @@ fn task_index_works_at_runtime_level() { #[cfg(feature = "experimental")] #[test] -fn task_execution_works() { +fn task_execution_works() { new_test_ext().execute_with(|| { System::set_block_number(1); Numbers::::insert(0, 1); From 086f27d516ae3aec081af17e355655a4df038a67 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 14 Dec 2023 12:14:26 +0530 Subject: [PATCH 3/5] Fixes test --- .../frame/support/test/tests/pallet_outer_enums_implicit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substrate/frame/support/test/tests/pallet_outer_enums_implicit.rs b/substrate/frame/support/test/tests/pallet_outer_enums_implicit.rs index 26023dfa7b72..16a4b378f751 100644 --- a/substrate/frame/support/test/tests/pallet_outer_enums_implicit.rs +++ b/substrate/frame/support/test/tests/pallet_outer_enums_implicit.rs @@ -90,7 +90,9 @@ fn module_error_outer_enum_expand_implicit() { frame_system::Error::NonDefaultComposite => (), frame_system::Error::NonZeroRefCount => (), frame_system::Error::CallFiltered => (), + #[cfg(feature = "experimental")] frame_system::Error::InvalidTask => (), + #[cfg(feature = "experimental")] frame_system::Error::FailedTask => (), frame_system::Error::__Ignore(_, _) => (), }, From c845fbd7453e94d9ce48832ddaa5536a5e11599f Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 14 Dec 2023 12:25:56 +0530 Subject: [PATCH 4/5] Fixes test --- .../frame/support/test/tests/pallet_outer_enums_explicit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substrate/frame/support/test/tests/pallet_outer_enums_explicit.rs b/substrate/frame/support/test/tests/pallet_outer_enums_explicit.rs index 6246ad93d678..d2acb798a2eb 100644 --- a/substrate/frame/support/test/tests/pallet_outer_enums_explicit.rs +++ b/substrate/frame/support/test/tests/pallet_outer_enums_explicit.rs @@ -90,7 +90,9 @@ fn module_error_outer_enum_expand_explicit() { frame_system::Error::NonDefaultComposite => (), frame_system::Error::NonZeroRefCount => (), frame_system::Error::CallFiltered => (), + #[cfg(feature = "experimental")] frame_system::Error::InvalidTask => (), + #[cfg(feature = "experimental")] frame_system::Error::FailedTask => (), frame_system::Error::__Ignore(_, _) => (), }, From 15b8066be938caa69b32efd899562e1b75636a72 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:07:08 +0530 Subject: [PATCH 5/5] Minor fix --- substrate/frame/support/test/Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/test/Cargo.toml b/substrate/frame/support/test/Cargo.toml index 8ee1b4b29183..e0c263fb4a1a 100644 --- a/substrate/frame/support/test/Cargo.toml +++ b/substrate/frame/support/test/Cargo.toml @@ -61,7 +61,10 @@ std = [ "sp-version/std", "test-pallet/std", ] -experimental = ["frame-support/experimental"] +experimental = [ + "frame-support/experimental", + "frame-system/experimental", +] try-runtime = [ "frame-executive/try-runtime", "frame-support/try-runtime",