From 11edbaf6c05e9e969bd277cc6452b48f2fff3367 Mon Sep 17 00:00:00 2001 From: gupnik Date: Fri, 15 Dec 2023 11:17:19 +0530 Subject: [PATCH] Feature gate `do_task` in `frame_system` (#2707) https://github.com/paritytech/polkadot-sdk/pull/1343/ introduced Tasks API. This one moves `do_task` call in frame_system under the experimental flag, till the previous one is audited. --------- Co-authored-by: command-bot <> --- substrate/bin/node/runtime/Cargo.toml | 5 +++++ substrate/frame/examples/tasks/Cargo.toml | 1 + substrate/frame/examples/tasks/src/tests.rs | 11 ++++++++--- substrate/frame/support/test/Cargo.toml | 5 ++++- .../support/test/tests/pallet_outer_enums_explicit.rs | 2 ++ .../support/test/tests/pallet_outer_enums_implicit.rs | 2 ++ substrate/frame/system/Cargo.toml | 1 + substrate/frame/system/src/lib.rs | 10 +++++++++- 8 files changed, 32 insertions(+), 5 deletions(-) diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 1d3f71f34365..693fd673da5d 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -407,3 +407,8 @@ try-runtime = [ "pallet-whitelist/try-runtime", "sp-runtime/try-runtime", ] +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 046bad908d15..438cb60c756f 100644 --- a/substrate/frame/examples/tasks/Cargo.toml +++ b/substrate/frame/examples/tasks/Cargo.toml @@ -53,3 +53,4 @@ try-runtime = [ "frame-system/try-runtime", "sp-runtime/try-runtime", ] +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 6b255491091d..fc3c69f4aef9 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,6 +92,7 @@ fn task_index_works_at_runtime_level() { }); } +#[cfg(feature = "experimental")] #[test] fn task_execution_works() { new_test_ext().execute_with(|| { @@ -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/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", 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(_, _) => (), }, 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(_, _) => (), }, diff --git a/substrate/frame/system/Cargo.toml b/substrate/frame/system/Cargo.toml index 2491ccd220c8..c64c32b4575b 100644 --- a/substrate/frame/system/Cargo.toml +++ b/substrate/frame/system/Cargo.toml @@ -56,6 +56,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, }