Skip to content

Commit

Permalink
Feature gate do_task in frame_system (#2707)
Browse files Browse the repository at this point in the history
#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 <>
  • Loading branch information
gupnik committed Dec 15, 2023
1 parent 2cee874 commit 11edbaf
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
1 change: 1 addition & 0 deletions substrate/frame/examples/tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ try-runtime = [
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
experimental = ["frame-support/experimental", "frame-system/experimental"]
11 changes: 8 additions & 3 deletions substrate/frame/examples/tasks/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -89,6 +92,7 @@ fn task_index_works_at_runtime_level() {
});
}

#[cfg(feature = "experimental")]
#[test]
fn task_execution_works() {
new_test_ext().execute_with(|| {
Expand All @@ -105,11 +109,12 @@ fn task_execution_works() {
assert_ok!(System::do_task(RuntimeOrigin::signed(1), task.clone(),));
assert_eq!(Numbers::<Runtime>::get(0), Some(1));
assert_eq!(Numbers::<Runtime>::get(1), None);
assert_eq!(Total::<Runtime>::get(), (1, 4));
assert_eq!(crate::Total::<Runtime>::get(), (1, 4));
System::assert_last_event(frame_system::Event::<Runtime>::TaskCompleted { task }.into());
});
}

#[cfg(feature = "experimental")]
#[test]
fn task_execution_fails_for_invalid_task() {
new_test_ext().execute_with(|| {
Expand Down
5 changes: 4 additions & 1 deletion substrate/frame/support/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(_, _) => (),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(_, _) => (),
},
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ();

Expand Down Expand Up @@ -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<T>, task: T::RuntimeTask) -> DispatchResultWithPostInfo {
Expand Down Expand Up @@ -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 },
}
Expand All @@ -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,
}
Expand Down

0 comments on commit 11edbaf

Please sign in to comment.