From df81863fd300b8de33b950cb36200b219bc5cc65 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 6 Sep 2023 13:29:42 -0400 Subject: [PATCH 001/177] import `sam-tasks` branch from old `substrate` repository --- Cargo.lock | 15 ++ Cargo.toml | 1 + .../pallets/template/src/mock.rs | 1 + .../bin/node-template/runtime/src/lib.rs | 3 + substrate/bin/node/runtime/src/lib.rs | 9 + substrate/frame/alliance/src/mock.rs | 2 + substrate/frame/asset-conversion/src/mock.rs | 2 + substrate/frame/asset-rate/src/mock.rs | 2 + substrate/frame/assets/src/mock.rs | 2 + substrate/frame/atomic-swap/src/tests.rs | 2 + substrate/frame/aura/src/mock.rs | 1 + .../frame/authority-discovery/src/lib.rs | 1 + substrate/frame/authorship/src/lib.rs | 1 + substrate/frame/babe/src/mock.rs | 2 + substrate/frame/bags-list/src/mock.rs | 1 + substrate/frame/balances/src/lib.rs | 4 + substrate/frame/balances/src/tests/mod.rs | 2 + substrate/frame/beefy-mmr/src/mock.rs | 1 + substrate/frame/beefy/src/mock.rs | 2 + substrate/frame/benchmarking/pov/src/tests.rs | 1 + substrate/frame/benchmarking/src/tests.rs | 1 + .../frame/benchmarking/src/tests_instance.rs | 1 + substrate/frame/bounties/src/tests.rs | 2 + substrate/frame/broker/src/mock.rs | 1 + substrate/frame/child-bounties/src/tests.rs | 2 + substrate/frame/collective/src/tests.rs | 1 + substrate/frame/contracts/src/tests.rs | 2 + .../frame/conviction-voting/src/tests.rs | 2 + substrate/frame/core-fellowship/src/tests.rs | 1 + substrate/frame/democracy/src/tests.rs | 2 + .../election-provider-multi-phase/src/mock.rs | 2 + .../test-staking-e2e/src/mock.rs | 2 + .../election-provider-support/src/onchain.rs | 1 + substrate/frame/elections-phragmen/src/lib.rs | 2 + substrate/frame/examples/basic/src/tests.rs | 2 + .../frame/examples/default-config/src/lib.rs | 4 + .../frame/examples/dev-mode/src/tests.rs | 2 + .../frame/examples/kitchensink/src/tests.rs | 2 + .../examples/offchain-worker/src/tests.rs | 1 + .../frame/examples/tasks-example/Cargo.toml | 38 ++++ .../frame/examples/tasks-example/src/lib.rs | 179 ++++++++++++++++++ substrate/frame/executive/src/lib.rs | 2 + substrate/frame/fast-unstake/src/mock.rs | 2 + substrate/frame/glutton/src/mock.rs | 1 + substrate/frame/grandpa/src/mock.rs | 2 + substrate/frame/identity/src/tests.rs | 2 + substrate/frame/im-online/src/mock.rs | 1 + substrate/frame/indices/src/mock.rs | 2 + .../src/lib.rs | 1 + substrate/frame/lottery/src/mock.rs | 2 + substrate/frame/membership/src/lib.rs | 1 + .../frame/merkle-mountain-range/src/mock.rs | 1 + .../message-queue/src/integration_test.rs | 1 + substrate/frame/message-queue/src/mock.rs | 1 + substrate/frame/multisig/src/tests.rs | 2 + .../frame/nft-fractionalization/src/mock.rs | 2 + substrate/frame/nfts/src/mock.rs | 2 + substrate/frame/nicks/src/lib.rs | 2 + substrate/frame/nis/src/mock.rs | 3 + .../frame/node-authorization/src/mock.rs | 1 + substrate/frame/nomination-pools/src/mock.rs | 2 + .../nomination-pools/test-staking/src/mock.rs | 2 + substrate/frame/offences/src/mock.rs | 1 + substrate/frame/paged-list/src/mock.rs | 1 + substrate/frame/preimage/src/mock.rs | 2 + substrate/frame/proxy/src/tests.rs | 2 + .../frame/ranked-collective/src/tests.rs | 1 + substrate/frame/recovery/src/mock.rs | 2 + substrate/frame/referenda/src/mock.rs | 2 + substrate/frame/remark/src/mock.rs | 1 + substrate/frame/root-offences/src/mock.rs | 2 + substrate/frame/safe-mode/src/mock.rs | 2 + substrate/frame/salary/src/tests.rs | 1 + substrate/frame/scheduler/src/mock.rs | 1 + substrate/frame/scored-pool/src/mock.rs | 2 + substrate/frame/session/src/mock.rs | 1 + substrate/frame/society/src/mock.rs | 2 + substrate/frame/staking/src/mock.rs | 2 + .../frame/state-trie-migration/src/lib.rs | 2 + substrate/frame/statement/src/mock.rs | 2 + substrate/frame/sudo/src/mock.rs | 1 + .../src/construct_runtime/expand/mod.rs | 2 + .../src/construct_runtime/expand/task.rs | 105 ++++++++++ .../procedural/src/construct_runtime/mod.rs | 3 + .../procedural/src/construct_runtime/parse.rs | 8 +- substrate/frame/support/procedural/src/lib.rs | 6 +- .../src/pallet/expand/tt_default_parts.rs | 15 +- .../procedural/src/pallet/parse/composite.rs | 9 +- .../procedural/src/pallet/parse/mod.rs | 22 +++ .../procedural/src/pallet/parse/tasks.rs | 121 ++++++++++++ substrate/frame/support/src/dispatch.rs | 2 + substrate/frame/support/src/lib.rs | 5 +- .../support/src/storage/generator/mod.rs | 2 + substrate/frame/support/src/tests/mod.rs | 5 + substrate/frame/support/src/traits.rs | 3 + substrate/frame/support/src/traits/tasks.rs | 74 ++++++++ .../support/test/compile_pass/src/lib.rs | 1 + substrate/frame/support/test/src/lib.rs | 2 + .../support/test/tests/construct_runtime.rs | 1 + .../frame/support/test/tests/final_keys.rs | 1 + .../frame/support/test/tests/genesisconfig.rs | 1 + .../frame/support/test/tests/instance.rs | 1 + .../frame/support/test/tests/issue2219.rs | 1 + substrate/frame/support/test/tests/origin.rs | 1 + substrate/frame/support/test/tests/pallet.rs | 1 + .../support/test/tests/pallet_instance.rs | 1 + .../test/tests/pallet_outer_enums_explicit.rs | 3 + .../test/tests/pallet_outer_enums_implicit.rs | 3 + .../support/test/tests/runtime_metadata.rs | 1 + .../support/test/tests/storage_layers.rs | 1 + .../support/test/tests/storage_transaction.rs | 1 + substrate/frame/system/src/lib.rs | 38 ++++ substrate/frame/system/src/mock.rs | 1 + substrate/frame/timestamp/src/mock.rs | 1 + substrate/frame/tips/src/tests.rs | 2 + .../asset-conversion-tx-payment/src/mock.rs | 2 + .../asset-tx-payment/src/mock.rs | 2 + .../frame/transaction-payment/src/mock.rs | 2 + .../frame/transaction-storage/src/mock.rs | 2 + substrate/frame/treasury/src/tests.rs | 2 + substrate/frame/tx-pause/src/mock.rs | 2 + substrate/frame/uniques/src/mock.rs | 2 + substrate/frame/utility/src/tests.rs | 2 + substrate/frame/vesting/src/mock.rs | 2 + substrate/frame/whitelist/src/mock.rs | 2 + substrate/test-utils/runtime/src/lib.rs | 2 + 126 files changed, 828 insertions(+), 8 deletions(-) create mode 100644 substrate/frame/examples/tasks-example/Cargo.toml create mode 100644 substrate/frame/examples/tasks-example/src/lib.rs create mode 100644 substrate/frame/support/procedural/src/construct_runtime/expand/task.rs create mode 100644 substrate/frame/support/procedural/src/pallet/parse/tasks.rs create mode 100644 substrate/frame/support/src/traits/tasks.rs diff --git a/Cargo.lock b/Cargo.lock index 2fff57879891..5c24e6c20d15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18514,6 +18514,21 @@ version = "0.12.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" +[[package]] +name = "tasks-example" +version = "4.0.0-dev" +dependencies = [ + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "tempfile" version = "3.8.0" diff --git a/Cargo.toml b/Cargo.toml index 4db27b98e907..35d4809ade09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -294,6 +294,7 @@ members = [ "substrate/frame/examples/kitchensink", "substrate/frame/examples/offchain-worker", "substrate/frame/examples/split", + "substrate/frame/examples/tasks-example", "substrate/frame/executive", "substrate/frame/fast-unstake", "substrate/frame/glutton", diff --git a/substrate/bin/node-template/pallets/template/src/mock.rs b/substrate/bin/node-template/pallets/template/src/mock.rs index 244ae1b37859..39c58d03efac 100644 --- a/substrate/bin/node-template/pallets/template/src/mock.rs +++ b/substrate/bin/node-template/pallets/template/src/mock.rs @@ -24,6 +24,7 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 216be9588bca..249841e546b9 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -165,6 +165,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type that is available for extrinsics. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The type for storing how many extrinsics an account has signed. @@ -243,6 +245,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU128; type AccountStore = System; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 4f34e4ecd812..0558798de572 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -87,6 +87,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; +use tasks_example; #[cfg(any(feature = "std", test))] pub use frame_system::Call as SystemCall; @@ -287,6 +288,7 @@ impl frame_system::Config for Runtime { type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = Hash; type Hashing = BlakeTwo256; @@ -308,6 +310,11 @@ impl frame_system::Config for Runtime { impl pallet_insecure_randomness_collective_flip::Config for Runtime {} +impl tasks_example::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; +} + impl pallet_utility::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -512,6 +519,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type WeightInfo = pallet_balances::weights::SubstrateWeight; @@ -2171,6 +2179,7 @@ mod benches { [pallet_conviction_voting, ConvictionVoting] [pallet_contracts, Contracts] [pallet_core_fellowship, CoreFellowship] + [tasks_example, TasksExample] [pallet_democracy, Democracy] [pallet_asset_conversion, AssetConversion] [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index f04e7e414ed9..cfd47e60a3e8 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -51,6 +51,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -79,6 +80,7 @@ impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/asset-conversion/src/mock.rs b/substrate/frame/asset-conversion/src/mock.rs index 3a19f39e7ca6..faf7d769a167 100644 --- a/substrate/frame/asset-conversion/src/mock.rs +++ b/substrate/frame/asset-conversion/src/mock.rs @@ -54,6 +54,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -88,6 +89,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl pallet_assets::Config for Test { diff --git a/substrate/frame/asset-rate/src/mock.rs b/substrate/frame/asset-rate/src/mock.rs index 5fe0d4240af5..38c92d80ed59 100644 --- a/substrate/frame/asset-rate/src/mock.rs +++ b/substrate/frame/asset-rate/src/mock.rs @@ -42,6 +42,7 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; @@ -76,6 +77,7 @@ impl pallet_balances::Config for Test { type FreezeIdentifier = (); type MaxHolds = (); type MaxFreezes = (); + type RuntimeTask = RuntimeTask; } impl pallet_asset_rate::Config for Test { diff --git a/substrate/frame/assets/src/mock.rs b/substrate/frame/assets/src/mock.rs index 32ad02da9041..d7ab85c4eb20 100644 --- a/substrate/frame/assets/src/mock.rs +++ b/substrate/frame/assets/src/mock.rs @@ -52,6 +52,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -86,6 +87,7 @@ impl pallet_balances::Config for Test { type FreezeIdentifier = (); type MaxHolds = (); type MaxFreezes = (); + type RuntimeTask = RuntimeTask; } pub struct AssetsCallbackHandle; diff --git a/substrate/frame/atomic-swap/src/tests.rs b/substrate/frame/atomic-swap/src/tests.rs index e20e1df564c7..493727570860 100644 --- a/substrate/frame/atomic-swap/src/tests.rs +++ b/substrate/frame/atomic-swap/src/tests.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; @@ -78,6 +79,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/aura/src/mock.rs b/substrate/frame/aura/src/mock.rs index 39b798c2f684..fe3479e34f22 100644 --- a/substrate/frame/aura/src/mock.rs +++ b/substrate/frame/aura/src/mock.rs @@ -49,6 +49,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/authority-discovery/src/lib.rs b/substrate/frame/authority-discovery/src/lib.rs index 87b743ae1967..0e6150f3d65f 100644 --- a/substrate/frame/authority-discovery/src/lib.rs +++ b/substrate/frame/authority-discovery/src/lib.rs @@ -233,6 +233,7 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AuthorityId; diff --git a/substrate/frame/authorship/src/lib.rs b/substrate/frame/authorship/src/lib.rs index a9bd0c38cb67..a434b0956afe 100644 --- a/substrate/frame/authorship/src/lib.rs +++ b/substrate/frame/authorship/src/lib.rs @@ -143,6 +143,7 @@ mod tests { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = RuntimeTask; } impl pallet::Config for Test { diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index dbffe9f312e6..85143f9e5709 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -71,6 +71,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Version = (); type Hashing = sp_runtime::traits::BlakeTwo256; @@ -139,6 +140,7 @@ impl pallet_balances::Config for Test { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/bags-list/src/mock.rs b/substrate/frame/bags-list/src/mock.rs index ae50adabd508..a6226b6f0324 100644 --- a/substrate/frame/bags-list/src/mock.rs +++ b/substrate/frame/bags-list/src/mock.rs @@ -54,6 +54,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index 5da6600d8796..f5be4b4456c3 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -249,6 +249,10 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// The overarching task type. + #[pallet::no_default] + type RuntimeTask: AggregatedTask; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; diff --git a/substrate/frame/balances/src/tests/mod.rs b/substrate/frame/balances/src/tests/mod.rs index d15f8e89118c..acfbc4e453b0 100644 --- a/substrate/frame/balances/src/tests/mod.rs +++ b/substrate/frame/balances/src/tests/mod.rs @@ -94,6 +94,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = u64; @@ -135,6 +136,7 @@ impl Config for Test { type FreezeIdentifier = TestId; type MaxFreezes = ConstU32<2>; type MaxHolds = ConstU32<2>; + type RuntimeTask = RuntimeTask; } #[derive(Clone)] diff --git a/substrate/frame/beefy-mmr/src/mock.rs b/substrate/frame/beefy-mmr/src/mock.rs index b2d8758a04be..441771723ad6 100644 --- a/substrate/frame/beefy-mmr/src/mock.rs +++ b/substrate/frame/beefy-mmr/src/mock.rs @@ -67,6 +67,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/beefy/src/mock.rs b/substrate/frame/beefy/src/mock.rs index b55a65dbd73a..fa440bad8d90 100644 --- a/substrate/frame/beefy/src/mock.rs +++ b/substrate/frame/beefy/src/mock.rs @@ -78,6 +78,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; @@ -155,6 +156,7 @@ impl pallet_balances::Config for Test { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/benchmarking/pov/src/tests.rs b/substrate/frame/benchmarking/pov/src/tests.rs index f09e37a5288a..94aea232c6cf 100644 --- a/substrate/frame/benchmarking/pov/src/tests.rs +++ b/substrate/frame/benchmarking/pov/src/tests.rs @@ -182,6 +182,7 @@ mod mock { type RuntimeOrigin = RuntimeOrigin; type Nonce = u32; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = u32; diff --git a/substrate/frame/benchmarking/src/tests.rs b/substrate/frame/benchmarking/src/tests.rs index e5bacbdb2361..43b48476ed3a 100644 --- a/substrate/frame/benchmarking/src/tests.rs +++ b/substrate/frame/benchmarking/src/tests.rs @@ -84,6 +84,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/benchmarking/src/tests_instance.rs b/substrate/frame/benchmarking/src/tests_instance.rs index f2c721c8114c..ca8b56e8c902 100644 --- a/substrate/frame/benchmarking/src/tests_instance.rs +++ b/substrate/frame/benchmarking/src/tests_instance.rs @@ -91,6 +91,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/bounties/src/tests.rs b/substrate/frame/bounties/src/tests.rs index a6fb89bb8601..6b32278f3ab4 100644 --- a/substrate/frame/bounties/src/tests.rs +++ b/substrate/frame/bounties/src/tests.rs @@ -64,6 +64,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account @@ -88,6 +89,7 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index cab6b7389c06..cfd3368d5f1e 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -54,6 +54,7 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index 24a6410f29f7..52ff3e6b8116 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -67,6 +67,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; @@ -91,6 +92,7 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/collective/src/tests.rs b/substrate/frame/collective/src/tests.rs index 86b85e07a8bd..0e89ab01bdce 100644 --- a/substrate/frame/collective/src/tests.rs +++ b/substrate/frame/collective/src/tests.rs @@ -114,6 +114,7 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = RuntimeTask; } impl Config for Test { type RuntimeOrigin = RuntimeOrigin; diff --git a/substrate/frame/contracts/src/tests.rs b/substrate/frame/contracts/src/tests.rs index 8d6c5c5ac728..8dcb0e8cc4a5 100644 --- a/substrate/frame/contracts/src/tests.rs +++ b/substrate/frame/contracts/src/tests.rs @@ -340,6 +340,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = AccountId32; type Lookup = IdentityLookup; @@ -363,6 +364,7 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/conviction-voting/src/tests.rs b/substrate/frame/conviction-voting/src/tests.rs index 656112deebfb..8558b376225b 100644 --- a/substrate/frame/conviction-voting/src/tests.rs +++ b/substrate/frame/conviction-voting/src/tests.rs @@ -59,6 +59,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; @@ -83,6 +84,7 @@ impl pallet_balances::Config for Test { type MaxLocks = ConstU32<10>; type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/core-fellowship/src/tests.rs b/substrate/frame/core-fellowship/src/tests.rs index a02c010718c9..25c547a34270 100644 --- a/substrate/frame/core-fellowship/src/tests.rs +++ b/substrate/frame/core-fellowship/src/tests.rs @@ -74,6 +74,7 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = RuntimeTask; } thread_local! { diff --git a/substrate/frame/democracy/src/tests.rs b/substrate/frame/democracy/src/tests.rs index e5cfcc5b4002..eaeeb47f34ed 100644 --- a/substrate/frame/democracy/src/tests.rs +++ b/substrate/frame/democracy/src/tests.rs @@ -85,6 +85,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; @@ -134,6 +135,7 @@ impl pallet_balances::Config for Test { type MaxLocks = ConstU32<10>; type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/election-provider-multi-phase/src/mock.rs b/substrate/frame/election-provider-multi-phase/src/mock.rs index 05d151e51ecc..56b30ff9622b 100644 --- a/substrate/frame/election-provider-multi-phase/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/src/mock.rs @@ -210,6 +210,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; @@ -254,6 +255,7 @@ impl pallet_balances::Config for Runtime { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } #[derive(Default, Eq, PartialEq, Debug, Clone, Copy)] diff --git a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs index 501f9f89ab7a..f25b7163413b 100644 --- a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs @@ -92,6 +92,7 @@ impl frame_system::Config for Runtime { type BaseCallFilter = frame_support::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); @@ -115,6 +116,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/election-provider-support/src/onchain.rs b/substrate/frame/election-provider-support/src/onchain.rs index 8ac245a360bb..fa875261f201 100644 --- a/substrate/frame/election-provider-support/src/onchain.rs +++ b/substrate/frame/election-provider-support/src/onchain.rs @@ -206,6 +206,7 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = Nonce; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; diff --git a/substrate/frame/elections-phragmen/src/lib.rs b/substrate/frame/elections-phragmen/src/lib.rs index 6912649bd122..2622e32ee145 100644 --- a/substrate/frame/elections-phragmen/src/lib.rs +++ b/substrate/frame/elections-phragmen/src/lib.rs @@ -1326,6 +1326,7 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; @@ -1347,6 +1348,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = frame_system::Pallet; diff --git a/substrate/frame/examples/basic/src/tests.rs b/substrate/frame/examples/basic/src/tests.rs index addf219dc3c3..3b21ce98b18a 100644 --- a/substrate/frame/examples/basic/src/tests.rs +++ b/substrate/frame/examples/basic/src/tests.rs @@ -53,6 +53,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type Hash = H256; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; @@ -85,6 +86,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/examples/default-config/src/lib.rs b/substrate/frame/examples/default-config/src/lib.rs index d2eade0ccff1..15096e53e4e3 100644 --- a/substrate/frame/examples/default-config/src/lib.rs +++ b/substrate/frame/examples/default-config/src/lib.rs @@ -47,6 +47,9 @@ pub mod pallet { #[pallet::no_default] // optional. `RuntimeEvent` is automatically excluded as well. type RuntimeEvent: From> + IsType<::RuntimeEvent>; + #[pallet::no_default] + type RuntimeTask: AggregatedTask; + /// An input parameter to this pallet. This value can have a default, because it is not /// reliant on `frame_system::Config` or the overarching runtime in any way. type WithDefaultValue: Get; @@ -198,6 +201,7 @@ pub mod tests { type OverwrittenDefaultValue = frame_support::traits::ConstU32<678>; type OverwrittenDefaultType = u128; + type RuntimeTask = RuntimeTask; } #[test] diff --git a/substrate/frame/examples/dev-mode/src/tests.rs b/substrate/frame/examples/dev-mode/src/tests.rs index ba98f5174ce2..3ce72c858848 100644 --- a/substrate/frame/examples/dev-mode/src/tests.rs +++ b/substrate/frame/examples/dev-mode/src/tests.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type Hash = H256; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; @@ -79,6 +80,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = RuntimeHoldReason; type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/examples/kitchensink/src/tests.rs b/substrate/frame/examples/kitchensink/src/tests.rs index b2af7c8983f5..da83fe846c15 100644 --- a/substrate/frame/examples/kitchensink/src/tests.rs +++ b/substrate/frame/examples/kitchensink/src/tests.rs @@ -43,6 +43,7 @@ impl frame_system::Config for Test { type Block = Block; type BlockHashCount = ConstU64<10>; type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; @@ -65,6 +66,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/examples/offchain-worker/src/tests.rs b/substrate/frame/examples/offchain-worker/src/tests.rs index 203a59a8af03..38e9a48701b2 100644 --- a/substrate/frame/examples/offchain-worker/src/tests.rs +++ b/substrate/frame/examples/offchain-worker/src/tests.rs @@ -53,6 +53,7 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/examples/tasks-example/Cargo.toml b/substrate/frame/examples/tasks-example/Cargo.toml new file mode 100644 index 000000000000..d90de4fae960 --- /dev/null +++ b/substrate/frame/examples/tasks-example/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "tasks-example" +version = "4.0.0-dev" +authors = ["Parity Technologies "] +edition = "2021" +license = "MIT-0" +homepage = "https://substrate.io" +repository = "https://github.com/paritytech/substrate/" +description = "FRAME example pallet" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } +log = { version = "0.4.17", default-features = false } +scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +frame-support = { version = "4.0.0-dev", default-features = false, path = "../../support" } +frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" } +sp-io = { version = "23.0.0", default-features = false, path = "../../../primitives/io" } +sp-runtime = { version = "24.0.0", default-features = false, path = "../../../primitives/runtime" } +sp-std = { version = "8.0.0", default-features = false, path = "../../../primitives/std" } +sp-core = { version = "21.0.0", default-features = false, path = "../../../primitives/core" } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "log/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "sp-core/std", +] +try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs new file mode 100644 index 000000000000..2223ecbd0d30 --- /dev/null +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -0,0 +1,179 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#![cfg_attr(not(feature = "std"), no_std)] + +use core::marker::PhantomData; + +use codec::{Decode, Encode}; +use frame_support::dispatch::DispatchResult; +// Re-export pallet items so that they can be accessed from the crate namespace. +pub use pallet::*; +use sp_runtime::DispatchError; + +#[frame_support::pallet(dev_mode)] +pub mod pallet { + + use super::*; + use frame_support::{pallet_prelude::*, traits::AggregatedTask}; + use frame_system::pallet_prelude::*; + + // this can be auto-generated from the macros + #[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo)] + pub enum Task { + Increment, + Decrement, + #[doc(hidden)] + #[codec(skip)] + __Ignore(PhantomData, frame_support::Never), + } + + // this can be auto-generated from the macros and will always be the same + impl core::fmt::Debug for Task { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Task").field("value", self).finish() + } + } + + // we can automatically inject `InvalidTask` into an existing Error enum by finding it via + // visitor pattern, otherwise we can just emit an error enum containing just our + // `InvalidTask` variant. Alternatively we could just expect that `InvalidTask` is included + // in the error enum, by convention, or we could use something like + // `InvalidTransaction::Custom(1u8)` but this seems bad to me. + #[pallet::error] + pub enum Error { + InvalidTask, + ValueOverflow, + ValueUnderflow, + } + + // this will be auto-generated from `#[pallet::tasks]` + impl frame_support::traits::Task for Task + where + T: TypeInfo, + { + type Enumeration = sp_std::vec::IntoIter>; + + const TASK_INDEX: u64 = 0; + + fn enumerate() -> Self::Enumeration { + sp_std::vec![Task::Increment, Task::Decrement].into_iter() + } + + fn is_valid(&self) -> bool { + let value = Value::::get().unwrap(); + match self { + Task::Increment => value < 255, + Task::Decrement => value > 0, + Task::__Ignore(_, _) => unreachable!(), + } + } + + fn run(&self) -> Result<(), DispatchError> { + match self { + Task::Increment => { + // Get the value and check if it can be incremented + let value = Value::::get().unwrap_or_default(); + if value >= 255 { + Err(Error::::ValueOverflow.into()) + } else { + let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Incremented { new_val }); + Ok(()) + } + }, + Task::Decrement => { + // Get the value and check if it can be decremented + let value = Value::::get().unwrap_or_default(); + if value == 0 { + Err(Error::::ValueUnderflow.into()) + } else { + let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Decremented { new_val }); + Ok(()) + } + }, + Task::__Ignore(_, _) => unreachable!(), + } + } + + fn weight(&self) -> Weight { + Weight::default() + } + } + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type RuntimeTask: AggregatedTask; + } + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn value)] + pub type Value = StorageValue<_, u8>; + + #[pallet::call] + impl Pallet + where + T: TypeInfo, + { + pub fn increment(origin: OriginFor) -> DispatchResult { + ensure_root(origin)?; + + // Increment the value and emit an event + let new_val = Value::::get().unwrap().checked_add(1).ok_or("Value overflow")?; + Value::::put(new_val); + Self::deposit_event(Event::Incremented { new_val }); + + Ok(()) + } + + pub fn decrement(origin: OriginFor) -> DispatchResult { + ensure_root(origin)?; + + // Decrement the value and emit an event + let new_val = Value::::get().unwrap().checked_sub(1).ok_or("Value underflow")?; + Value::::put(new_val); + Self::deposit_event(Event::Decremented { new_val }); + + Ok(()) + } + + // this will be auto-generated by the macros and will always be the same + pub fn do_task(origin: OriginFor, task: Task) -> DispatchResult { + use frame_support::traits::Task; + ensure_root(origin)?; + if task.is_valid() { + task.run() + } else { + Err(Error::::InvalidTask.into()) + } + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + Incremented { new_val: u8 }, + Decremented { new_val: u8 }, + } +} diff --git a/substrate/frame/executive/src/lib.rs b/substrate/frame/executive/src/lib.rs index 1d9afdfa60aa..f7d71be3e97b 100644 --- a/substrate/frame/executive/src/lib.rs +++ b/substrate/frame/executive/src/lib.rs @@ -872,6 +872,7 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = BlakeTwo256; type AccountId = u64; @@ -905,6 +906,7 @@ mod tests { type MaxFreezes = ConstU32<1>; type RuntimeHoldReason = (); type MaxHolds = ConstU32<1>; + type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/fast-unstake/src/mock.rs b/substrate/frame/fast-unstake/src/mock.rs index dc24a823c0db..18a16be778e7 100644 --- a/substrate/frame/fast-unstake/src/mock.rs +++ b/substrate/frame/fast-unstake/src/mock.rs @@ -52,6 +52,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = Nonce; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; @@ -87,6 +88,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/glutton/src/mock.rs b/substrate/frame/glutton/src/mock.rs index 4bc40b547887..90a7a59dca11 100644 --- a/substrate/frame/glutton/src/mock.rs +++ b/substrate/frame/glutton/src/mock.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/grandpa/src/mock.rs b/substrate/frame/grandpa/src/mock.rs index fd4d737dc493..ce3df8f50dda 100644 --- a/substrate/frame/grandpa/src/mock.rs +++ b/substrate/frame/grandpa/src/mock.rs @@ -74,6 +74,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = u64; @@ -135,6 +136,7 @@ impl pallet_balances::Config for Test { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index 1532980574c2..13de690e6768 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -52,6 +52,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; @@ -84,6 +85,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/im-online/src/mock.rs b/substrate/frame/im-online/src/mock.rs index 85da061fe904..a9a1350076f2 100644 --- a/substrate/frame/im-online/src/mock.rs +++ b/substrate/frame/im-online/src/mock.rs @@ -121,6 +121,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/indices/src/mock.rs b/substrate/frame/indices/src/mock.rs index d63081e0b73f..7941b3291abf 100644 --- a/substrate/frame/indices/src/mock.rs +++ b/substrate/frame/indices/src/mock.rs @@ -42,6 +42,7 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; @@ -75,6 +76,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs index 474087777c46..f7119f63a6f9 100644 --- a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs +++ b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs @@ -197,6 +197,7 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/lottery/src/mock.rs b/substrate/frame/lottery/src/mock.rs index aefb6a1cce2b..b462a5a736e6 100644 --- a/substrate/frame/lottery/src/mock.rs +++ b/substrate/frame/lottery/src/mock.rs @@ -55,6 +55,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; @@ -79,6 +80,7 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/membership/src/lib.rs b/substrate/frame/membership/src/lib.rs index 6fb61f0e491b..f2433a7d70ca 100644 --- a/substrate/frame/membership/src/lib.rs +++ b/substrate/frame/membership/src/lib.rs @@ -560,6 +560,7 @@ mod tests { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/merkle-mountain-range/src/mock.rs b/substrate/frame/merkle-mountain-range/src/mock.rs index ecc254278bf0..ff46c0c9c3cf 100644 --- a/substrate/frame/merkle-mountain-range/src/mock.rs +++ b/substrate/frame/merkle-mountain-range/src/mock.rs @@ -41,6 +41,7 @@ impl frame_system::Config for Test { type BaseCallFilter = frame_support::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/message-queue/src/integration_test.rs b/substrate/frame/message-queue/src/integration_test.rs index a1003edf3c92..20bc4412210b 100644 --- a/substrate/frame/message-queue/src/integration_test.rs +++ b/substrate/frame/message-queue/src/integration_test.rs @@ -59,6 +59,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/message-queue/src/mock.rs b/substrate/frame/message-queue/src/mock.rs index 473c5faac4c5..8ee0d9a0a6cc 100644 --- a/substrate/frame/message-queue/src/mock.rs +++ b/substrate/frame/message-queue/src/mock.rs @@ -52,6 +52,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/multisig/src/tests.rs b/substrate/frame/multisig/src/tests.rs index e7fc5b3e4aae..7dab8a10a758 100644 --- a/substrate/frame/multisig/src/tests.rs +++ b/substrate/frame/multisig/src/tests.rs @@ -44,6 +44,7 @@ impl frame_system::Config for Test { type Block = Block; type BlockHashCount = ConstU32<250>; type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type BaseCallFilter = TestBaseCallFilter; @@ -61,6 +62,7 @@ impl pallet_balances::Config for Test { type DustRemoval = (); type AccountStore = System; type ExistentialDeposit = ConstU64<1>; + type RuntimeTask = RuntimeTask; } pub struct TestBaseCallFilter; diff --git a/substrate/frame/nft-fractionalization/src/mock.rs b/substrate/frame/nft-fractionalization/src/mock.rs index c690f0e580ed..3b0b998fb16e 100644 --- a/substrate/frame/nft-fractionalization/src/mock.rs +++ b/substrate/frame/nft-fractionalization/src/mock.rs @@ -55,6 +55,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -79,6 +80,7 @@ impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU64<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/nfts/src/mock.rs b/substrate/frame/nfts/src/mock.rs index f091a53f8d7c..cb4bba74dae4 100644 --- a/substrate/frame/nfts/src/mock.rs +++ b/substrate/frame/nfts/src/mock.rs @@ -52,6 +52,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -86,6 +87,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/nicks/src/lib.rs b/substrate/frame/nicks/src/lib.rs index 0a68f7d7142d..36491752d550 100644 --- a/substrate/frame/nicks/src/lib.rs +++ b/substrate/frame/nicks/src/lib.rs @@ -282,6 +282,7 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type Hash = H256; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; @@ -314,6 +315,7 @@ mod tests { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } ord_parameter_types! { diff --git a/substrate/frame/nis/src/mock.rs b/substrate/frame/nis/src/mock.rs index 76fdf5f3f069..65f41fc34ff6 100644 --- a/substrate/frame/nis/src/mock.rs +++ b/substrate/frame/nis/src/mock.rs @@ -56,6 +56,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -90,6 +91,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = RuntimeHoldReason; type MaxHolds = ConstU32<1>; + type RuntimeTask = RuntimeTask; } impl pallet_balances::Config for Test { @@ -110,6 +112,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/node-authorization/src/mock.rs b/substrate/frame/node-authorization/src/mock.rs index 84e3336b3bd6..f98ae4f1ecb6 100644 --- a/substrate/frame/node-authorization/src/mock.rs +++ b/substrate/frame/node-authorization/src/mock.rs @@ -67,6 +67,7 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = RuntimeTask; } ord_parameter_types! { diff --git a/substrate/frame/nomination-pools/src/mock.rs b/substrate/frame/nomination-pools/src/mock.rs index 28c24c428035..cacc97baa589 100644 --- a/substrate/frame/nomination-pools/src/mock.rs +++ b/substrate/frame/nomination-pools/src/mock.rs @@ -187,6 +187,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; @@ -217,6 +218,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/nomination-pools/test-staking/src/mock.rs b/substrate/frame/nomination-pools/test-staking/src/mock.rs index 02c253e62c01..2f7446e5e44f 100644 --- a/substrate/frame/nomination-pools/test-staking/src/mock.rs +++ b/substrate/frame/nomination-pools/test-staking/src/mock.rs @@ -46,6 +46,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = Nonce; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; @@ -89,6 +90,7 @@ impl pallet_balances::Config for Runtime { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } pallet_staking_reward_curve::build! { diff --git a/substrate/frame/offences/src/mock.rs b/substrate/frame/offences/src/mock.rs index 990ceae5ac01..0c6ba68fdd4e 100644 --- a/substrate/frame/offences/src/mock.rs +++ b/substrate/frame/offences/src/mock.rs @@ -82,6 +82,7 @@ impl frame_system::Config for Runtime { type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/paged-list/src/mock.rs b/substrate/frame/paged-list/src/mock.rs index 390b4a8530dc..d92067601856 100644 --- a/substrate/frame/paged-list/src/mock.rs +++ b/substrate/frame/paged-list/src/mock.rs @@ -45,6 +45,7 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/preimage/src/mock.rs b/substrate/frame/preimage/src/mock.rs index 2fb9f36dec45..d782975ef027 100644 --- a/substrate/frame/preimage/src/mock.rs +++ b/substrate/frame/preimage/src/mock.rs @@ -49,6 +49,7 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; @@ -83,6 +84,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } ord_parameter_types! { diff --git a/substrate/frame/proxy/src/tests.rs b/substrate/frame/proxy/src/tests.rs index 0667be6e1e52..3080a92537ad 100644 --- a/substrate/frame/proxy/src/tests.rs +++ b/substrate/frame/proxy/src/tests.rs @@ -48,6 +48,7 @@ impl frame_system::Config for Test { type BlockHashCount = ConstU64<250>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); @@ -64,6 +65,7 @@ impl pallet_balances::Config for Test { type DustRemoval = (); type AccountStore = System; type ExistentialDeposit = ConstU64<1>; + type RuntimeTask = RuntimeTask; } impl pallet_utility::Config for Test { diff --git a/substrate/frame/ranked-collective/src/tests.rs b/substrate/frame/ranked-collective/src/tests.rs index ba8c5a0f937b..b491dc6756d7 100644 --- a/substrate/frame/ranked-collective/src/tests.rs +++ b/substrate/frame/ranked-collective/src/tests.rs @@ -69,6 +69,7 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = RuntimeTask; } #[derive(Clone, PartialEq, Eq, Debug)] diff --git a/substrate/frame/recovery/src/mock.rs b/substrate/frame/recovery/src/mock.rs index 2f2bd866a719..e87ceba66430 100644 --- a/substrate/frame/recovery/src/mock.rs +++ b/substrate/frame/recovery/src/mock.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; @@ -85,6 +86,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/referenda/src/mock.rs b/substrate/frame/referenda/src/mock.rs index e44167ed561c..8521bd830001 100644 --- a/substrate/frame/referenda/src/mock.rs +++ b/substrate/frame/referenda/src/mock.rs @@ -67,6 +67,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; @@ -110,6 +111,7 @@ impl pallet_balances::Config for Test { type MaxLocks = ConstU32<10>; type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/remark/src/mock.rs b/substrate/frame/remark/src/mock.rs index e597a1ca4dfe..367cc0d16936 100644 --- a/substrate/frame/remark/src/mock.rs +++ b/substrate/frame/remark/src/mock.rs @@ -41,6 +41,7 @@ impl frame_system::Config for Test { type BlockWeights = (); type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; diff --git a/substrate/frame/root-offences/src/mock.rs b/substrate/frame/root-offences/src/mock.rs index 2d2a5476149f..4f39822e5541 100644 --- a/substrate/frame/root-offences/src/mock.rs +++ b/substrate/frame/root-offences/src/mock.rs @@ -93,6 +93,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; @@ -124,6 +125,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } pallet_staking_reward_curve::build! { diff --git a/substrate/frame/safe-mode/src/mock.rs b/substrate/frame/safe-mode/src/mock.rs index 635ee0cfedc0..461edd356aa3 100644 --- a/substrate/frame/safe-mode/src/mock.rs +++ b/substrate/frame/safe-mode/src/mock.rs @@ -39,6 +39,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -72,6 +73,7 @@ impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU64<2>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/salary/src/tests.rs b/substrate/frame/salary/src/tests.rs index 1136ea746f60..928aeb2890ff 100644 --- a/substrate/frame/salary/src/tests.rs +++ b/substrate/frame/salary/src/tests.rs @@ -73,6 +73,7 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = RuntimeTask; } thread_local! { diff --git a/substrate/frame/scheduler/src/mock.rs b/substrate/frame/scheduler/src/mock.rs index 28e334958d92..68a5c1d18640 100644 --- a/substrate/frame/scheduler/src/mock.rs +++ b/substrate/frame/scheduler/src/mock.rs @@ -125,6 +125,7 @@ impl system::Config for Test { type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/scored-pool/src/mock.rs b/substrate/frame/scored-pool/src/mock.rs index 591c910488b1..f4b7b55822fd 100644 --- a/substrate/frame/scored-pool/src/mock.rs +++ b/substrate/frame/scored-pool/src/mock.rs @@ -59,6 +59,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type Hash = H256; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; @@ -91,6 +92,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/session/src/mock.rs b/substrate/frame/session/src/mock.rs index 2db54e1a5975..2dce98710a71 100644 --- a/substrate/frame/session/src/mock.rs +++ b/substrate/frame/session/src/mock.rs @@ -240,6 +240,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/society/src/mock.rs b/substrate/frame/society/src/mock.rs index a318c2e794b7..455e064171c0 100644 --- a/substrate/frame/society/src/mock.rs +++ b/substrate/frame/society/src/mock.rs @@ -67,6 +67,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u128; type Lookup = IdentityLookup; @@ -90,6 +91,7 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/staking/src/mock.rs b/substrate/frame/staking/src/mock.rs index cf08f8be1f27..6f617e20f7bf 100644 --- a/substrate/frame/staking/src/mock.rs +++ b/substrate/frame/staking/src/mock.rs @@ -129,6 +129,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = Nonce; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; @@ -152,6 +153,7 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 3e69b219bb52..b69c88d1a5e1 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -1086,6 +1086,7 @@ mod mock { type BlockWeights = (); type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; @@ -1127,6 +1128,7 @@ mod mock { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } /// Test only Weights for state migration. diff --git a/substrate/frame/statement/src/mock.rs b/substrate/frame/statement/src/mock.rs index 79d2aa7d891d..ceae41a3019f 100644 --- a/substrate/frame/statement/src/mock.rs +++ b/substrate/frame/statement/src/mock.rs @@ -53,6 +53,7 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; @@ -87,6 +88,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = RuntimeHoldReason; type MaxHolds = (); + type RuntimeTask = RuntimeTask; } ord_parameter_types! { diff --git a/substrate/frame/sudo/src/mock.rs b/substrate/frame/sudo/src/mock.rs index 9e78e474f4e5..dba9676fe0b5 100644 --- a/substrate/frame/sudo/src/mock.rs +++ b/substrate/frame/sudo/src/mock.rs @@ -132,6 +132,7 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = RuntimeTask; } // Implement the logger module's `Config` on the Test runtime. diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/mod.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/mod.rs index 830338f9265f..9dab9f664094 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/mod.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/mod.rs @@ -25,6 +25,7 @@ mod metadata; mod origin; mod outer_enums; mod slash_reason; +mod task; mod unsigned; pub use call::expand_outer_dispatch; @@ -37,4 +38,5 @@ pub use metadata::expand_runtime_metadata; pub use origin::expand_outer_origin; pub use outer_enums::{expand_outer_enum, OuterEnumType}; pub use slash_reason::expand_outer_slash_reason; +pub use task::expand_outer_task; pub use unsigned::expand_outer_validate_unsigned; diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs new file mode 100644 index 000000000000..34d62a7c3594 --- /dev/null +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -0,0 +1,105 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License + +use crate::construct_runtime::{parse::PalletPath, Pallet}; +use proc_macro2::{Ident, TokenStream}; +use quote::quote; + +/// Expands aggregate `RuntimeTask` enum. +pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream) -> TokenStream { + let mut conversion_fns = Vec::new(); + let mut task_variants = Vec::new(); + for decl in pallet_decls { + if let Some(_) = decl.find_part("Task") { + // TODO: for some reason `find_part` above never finds `Task` even when it is + // clearly in the pallet + let variant_name = &decl.name; + let path = &decl.path; + let index = decl.index; + + conversion_fns.push(expand_conversion_fn(path, variant_name)); + + task_variants.push(expand_variant(index, path, variant_name)); + } + } + use quote::ToTokens; + if !task_variants.is_empty() { + println!( + "{:#?}", + task_variants + .iter() + .map(|item| item.to_token_stream().to_string()) + .collect::>() + ); + } + + quote! { + /// An aggregation of all `Task` enums across all pallets included in the current runtime. + #[derive( + Clone, Eq, PartialEq, + #scrate::__private::codec::Encode, #scrate::__private::codec::Decode, + // #scrate::__private::codec::MaxEncodedLen, + #scrate::__private::scale_info::TypeInfo, + #scrate::__private::RuntimeDebug, + )] + pub enum RuntimeTask { + #( #task_variants )* + } + + impl #scrate::traits::AggregatedTask for RuntimeTask { + fn is_valid(&self) -> bool { + use #scrate::traits::tasks::prelude::*; + todo!(); + } + + fn run(&self) -> Result<(), #scrate::traits::tasks::prelude::DispatchError> { + todo!(); + } + + fn weight(&self) -> #scrate::pallet_prelude::Weight { + todo!(); + } + + fn task_index(&self) -> u64 { + todo!(); + } + } + + #( #conversion_fns )* + } +} + +fn expand_conversion_fn(path: &PalletPath, variant_name: &Ident) -> TokenStream { + // Todo: Replace `Runtime` with the actual runtime ident + // `pallet` will probably not be needed when `Task` is generated by macro + quote! { + impl From<#path::pallet::Task> for RuntimeTask { + fn from(hr: #path::pallet::Task) -> Self { + RuntimeTask::#variant_name(hr) + } + } + } +} + +fn expand_variant(index: u8, path: &PalletPath, variant_name: &Ident) -> TokenStream { + // Todo: Replace `Runtime` with the actual runtime ident + // `pallet` will probably not be needed when `Task` is generated by macro + quote! { + #[codec(index = #index)] + #variant_name(#path::pallet::Task), + } +} diff --git a/substrate/frame/support/procedural/src/construct_runtime/mod.rs b/substrate/frame/support/procedural/src/construct_runtime/mod.rs index f42dd837e3a9..605571381942 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/mod.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/mod.rs @@ -385,6 +385,7 @@ fn construct_runtime_final_expansion( let pallet_to_index = decl_pallet_runtime_setup(&name, &pallets, &scrate); let dispatch = expand::expand_outer_dispatch(&name, system_pallet, &pallets, &scrate); + let tasks = expand::expand_outer_task(&pallets, &scrate); let metadata = expand::expand_runtime_metadata( &name, &pallets, @@ -472,6 +473,8 @@ fn construct_runtime_final_expansion( #dispatch + #tasks + #metadata #outer_config diff --git a/substrate/frame/support/procedural/src/construct_runtime/parse.rs b/substrate/frame/support/procedural/src/construct_runtime/parse.rs index 9b08e1646975..88f3f14dc86c 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/parse.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/parse.rs @@ -42,6 +42,7 @@ mod keyword { syn::custom_keyword!(ValidateUnsigned); syn::custom_keyword!(FreezeReason); syn::custom_keyword!(HoldReason); + syn::custom_keyword!(Task); syn::custom_keyword!(LockId); syn::custom_keyword!(SlashReason); syn::custom_keyword!(exclude_parts); @@ -404,6 +405,7 @@ pub enum PalletPartKeyword { ValidateUnsigned(keyword::ValidateUnsigned), FreezeReason(keyword::FreezeReason), HoldReason(keyword::HoldReason), + Task(keyword::Task), LockId(keyword::LockId), SlashReason(keyword::SlashReason), } @@ -434,6 +436,8 @@ impl Parse for PalletPartKeyword { Ok(Self::FreezeReason(input.parse()?)) } else if lookahead.peek(keyword::HoldReason) { Ok(Self::HoldReason(input.parse()?)) + } else if lookahead.peek(keyword::Task) { + Ok(Self::Task(input.parse()?)) } else if lookahead.peek(keyword::LockId) { Ok(Self::LockId(input.parse()?)) } else if lookahead.peek(keyword::SlashReason) { @@ -459,6 +463,7 @@ impl PalletPartKeyword { Self::ValidateUnsigned(_) => "ValidateUnsigned", Self::FreezeReason(_) => "FreezeReason", Self::HoldReason(_) => "HoldReason", + Self::Task(_) => "Task", Self::LockId(_) => "LockId", Self::SlashReason(_) => "SlashReason", } @@ -471,7 +476,7 @@ impl PalletPartKeyword { /// Returns the names of all pallet parts that allow to have a generic argument. fn all_generic_arg() -> &'static [&'static str] { - &["Event", "Error", "Origin", "Config"] + &["Event", "Error", "Origin", "Config", "Task"] } } @@ -489,6 +494,7 @@ impl ToTokens for PalletPartKeyword { Self::ValidateUnsigned(inner) => inner.to_tokens(tokens), Self::FreezeReason(inner) => inner.to_tokens(tokens), Self::HoldReason(inner) => inner.to_tokens(tokens), + Self::Task(inner) => inner.to_tokens(tokens), Self::LockId(inner) => inner.to_tokens(tokens), Self::SlashReason(inner) => inner.to_tokens(tokens), } diff --git a/substrate/frame/support/procedural/src/lib.rs b/substrate/frame/support/procedural/src/lib.rs index 9957cf1cff85..8d26f4ed1837 100644 --- a/substrate/frame/support/procedural/src/lib.rs +++ b/substrate/frame/support/procedural/src/lib.rs @@ -646,7 +646,6 @@ pub fn storage_alias(attributes: TokenStream, input: TokenStream) -> TokenStream /// ``` /// /// where `TestDefaultConfig` was defined and registered as follows: -/// /// ```ignore /// pub struct TestDefaultConfig; /// @@ -673,7 +672,6 @@ pub fn storage_alias(attributes: TokenStream, input: TokenStream) -> TokenStream /// ``` /// /// The above call to `derive_impl` would expand to roughly the following: -/// /// ```ignore /// impl frame_system::Config for Test { /// use frame_system::config_preludes::TestDefaultConfig; @@ -876,12 +874,14 @@ pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream { let item = syn::parse_macro_input!(item as TraitItemType); if item.ident != "RuntimeCall" && item.ident != "RuntimeEvent" && + item.ident != "RuntimeTask" && item.ident != "RuntimeOrigin" && item.ident != "PalletInfo" { return syn::Error::new_spanned( item, - "`#[inject_runtime_type]` can only be attached to `RuntimeCall`, `RuntimeEvent`, `RuntimeOrigin` or `PalletInfo`", + "`#[inject_runtime_type]` can only be attached to `RuntimeCall`, `RuntimeEvent`, \ + `RuntimeTask`, `RuntimeOrigin` or `PalletInfo`", ) .to_compile_error() .into(); diff --git a/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs b/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs index 86db56c776df..f322fe17a7c4 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs @@ -31,6 +31,19 @@ pub fn expand_tt_default_parts(def: &mut Def) -> proc_macro2::TokenStream { let call_part = def.call.as_ref().map(|_| quote::quote!(Call,)); + // TODO: maybe allow `task_enum: Option` to sit on `Def` itself? + let task_part = def.item.content.as_ref().and_then(|(_, items)| { + items.iter().find_map(|item| { + if let syn::Item::Enum(item_enum) = item { + if item_enum.ident == "Task" { + println!("found task enum in tt_default_parts!"); + return Some(item_enum) + } + } + None + }) + }); + let storage_part = (!def.storages.is_empty()).then(|| quote::quote!(Storage,)); let event_part = def.event.as_ref().map(|event| { @@ -101,7 +114,7 @@ pub fn expand_tt_default_parts(def: &mut Def) -> proc_macro2::TokenStream { tokens = [{ expanded::{ Pallet, #call_part #storage_part #event_part #error_part #origin_part #config_part - #inherent_part #validate_unsigned_part #freeze_reason_part + #inherent_part #validate_unsigned_part #freeze_reason_part #task_part #hold_reason_part #lock_id_part #slash_reason_part } }] diff --git a/substrate/frame/support/procedural/src/pallet/parse/composite.rs b/substrate/frame/support/procedural/src/pallet/parse/composite.rs index cb554a116175..6c21e469ca67 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/composite.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/composite.rs @@ -25,11 +25,14 @@ pub mod keyword { syn::custom_keyword!(HoldReason); syn::custom_keyword!(LockId); syn::custom_keyword!(SlashReason); + syn::custom_keyword!(Task); + pub enum CompositeKeyword { FreezeReason(FreezeReason), HoldReason(HoldReason), LockId(LockId), SlashReason(SlashReason), + Task(Task), } impl ToTokens for CompositeKeyword { @@ -40,6 +43,7 @@ pub mod keyword { HoldReason(inner) => inner.to_tokens(tokens), LockId(inner) => inner.to_tokens(tokens), SlashReason(inner) => inner.to_tokens(tokens), + Task(inner) => inner.to_tokens(tokens), } } } @@ -55,6 +59,8 @@ pub mod keyword { Ok(Self::LockId(input.parse()?)) } else if lookahead.peek(SlashReason) { Ok(Self::SlashReason(input.parse()?)) + } else if lookahead.peek(Task) { + Ok(Self::Task(input.parse()?)) } else { Err(lookahead.error()) } @@ -70,6 +76,7 @@ pub mod keyword { match self { FreezeReason(_) => "FreezeReason", HoldReason(_) => "HoldReason", + Task(_) => "Task", LockId(_) => "LockId", SlashReason(_) => "SlashReason", } @@ -79,7 +86,7 @@ pub mod keyword { } pub struct CompositeDef { - /// The index of the HoldReason item in the pallet module. + /// The index of the CompositeDef item in the pallet module. pub index: usize, /// The composite keyword used (contains span). pub composite_keyword: keyword::CompositeKeyword, diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 0f5e5f113661..44bf12dc19f7 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -33,6 +33,7 @@ pub mod inherent; pub mod origin; pub mod pallet_struct; pub mod storage; +pub mod tasks; pub mod type_value; pub mod validate_unsigned; @@ -49,6 +50,8 @@ pub struct Def { pub pallet_struct: pallet_struct::PalletStructDef, pub hooks: Option, pub call: Option, + pub tasks: Option, + pub task_enum: Option, pub storages: Vec, pub error: Option, pub event: Option, @@ -84,6 +87,8 @@ impl Def { let mut pallet_struct = None; let mut hooks = None; let mut call = None; + let mut tasks = None; + let mut task_enum = None; let mut error = None; let mut event = None; let mut origin = None; @@ -97,6 +102,14 @@ impl Def { let mut composites: Vec = vec![]; for (index, item) in items.iter_mut().enumerate() { + // find manually specified `Task` enum, if present + if let syn::Item::Enum(item_enum) = item { + if item_enum.ident == "Task" { + println!("found task enum while parsing Def!"); + task_enum = Some(item_enum.clone()); + } + } + let pallet_attr: Option = helper::take_first_item_pallet_attr(item)?; match pallet_attr { @@ -118,6 +131,8 @@ impl Def { }, Some(PalletAttr::RuntimeCall(cw, span)) if call.is_none() => call = Some(call::CallDef::try_from(span, index, item, dev_mode, cw)?), + Some(PalletAttr::Tasks(span)) if tasks.is_none() => + tasks = Some(tasks::TasksDef::try_from(span, index, item)?), Some(PalletAttr::Error(span)) if error.is_none() => error = Some(error::ErrorDef::try_from(span, index, item)?), Some(PalletAttr::RuntimeEvent(span)) if event.is_none() => @@ -198,6 +213,8 @@ impl Def { .ok_or_else(|| syn::Error::new(item_span, "Missing `#[pallet::pallet]`"))?, hooks, call, + tasks, + task_enum, extra_constants, genesis_config, genesis_build, @@ -408,6 +425,7 @@ impl GenericKind { mod keyword { syn::custom_keyword!(origin); syn::custom_keyword!(call); + syn::custom_keyword!(tasks); syn::custom_keyword!(weight); syn::custom_keyword!(event); syn::custom_keyword!(config); @@ -471,6 +489,7 @@ enum PalletAttr { /// to zero. Now when there is a `weight` attribute on the `#[pallet::call]`, then that is used /// instead of the zero weight. So to say: it works together with `dev_mode`. RuntimeCall(Option, proc_macro2::Span), + Tasks(proc_macro2::Span), Error(proc_macro2::Span), RuntimeEvent(proc_macro2::Span), RuntimeOrigin(proc_macro2::Span), @@ -491,6 +510,7 @@ impl PalletAttr { Self::Pallet(span) => *span, Self::Hooks(span) => *span, Self::RuntimeCall(_, span) => *span, + Self::Tasks(span) => *span, Self::Error(span) => *span, Self::RuntimeEvent(span) => *span, Self::RuntimeOrigin(span) => *span, @@ -535,6 +555,8 @@ impl syn::parse::Parse for PalletAttr { false => Some(InheritedCallWeightAttr::parse(&content)?), }; Ok(PalletAttr::RuntimeCall(attr, span)) + } else if lookahead.peek(keyword::tasks) { + Ok(PalletAttr::Tasks(content.parse::()?.span())) } else if lookahead.peek(keyword::error) { Ok(PalletAttr::Error(content.parse::()?.span())) } else if lookahead.peek(keyword::event) { diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs new file mode 100644 index 000000000000..23715014585a --- /dev/null +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -0,0 +1,121 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use derive_syn_parse::Parse; +use proc_macro2::Span; +use syn::{ + token::{Bracket, Paren}, + Expr, Ident, Item, LitInt, Result, Token, +}; + +pub mod keywords { + use syn::custom_keyword; + + custom_keyword!(tasks); + custom_keyword!(task_list); + custom_keyword!(condition); + custom_keyword!(task_index); + custom_keyword!(pallet); +} + +pub struct TasksDef; + +impl TasksDef { + pub fn try_from(_span: Span, _index: usize, _item: &mut Item) -> Result { + // TODO: fill in + Ok(TasksDef {}) + } +} + +#[derive(Parse)] +pub enum TaskAttrType { + #[peek(keywords::task_list, name = "#[pallet::task_list(..)]")] + TaskList { + _tasks: keywords::task_list, + #[paren] + _paren: Paren, + #[inside(_paren)] + expr: Expr, + }, + #[peek(keywords::task_index, name = "#[pallet::task_index(..)")] + TaskIndex { + _task_index: keywords::task_index, + #[paren] + _paren: Paren, + #[inside(_paren)] + index: LitInt, + }, + #[peek(keywords::condition, name = "#[pallet::condition(..)")] + Condition { + _condition: keywords::condition, + #[paren] + _paren: Paren, + #[inside(_paren)] + _pipe1: Token![|], + #[inside(_paren)] + _ident: Ident, + #[inside(_paren)] + _pipe2: Token![|], + #[inside(_paren)] + expr: Expr, + }, + // TODO: Tasks +} + +#[derive(Parse)] +pub struct PalletTaskAttr { + _pound: Token![#], + #[bracket] + _bracket: Bracket, + #[inside(_bracket)] + _pallet: keywords::pallet, + #[inside(_bracket)] + _colons: Token![::], + #[inside(_bracket)] + _attr: TaskAttrType, +} + +#[cfg(test)] +use syn::parse2; + +#[cfg(test)] +use quote::quote; + +#[test] +fn test_parse_pallet_task_list_() { + parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); + assert!(parse2::(quote!(#[pallet::task_list()])).is_err()); + assert!(parse2::(quote!(#[pallet::tasks_list(iter())])).is_err()); + assert!(parse2::(quote!(#[pallet::task_list])).is_err()); +} + +#[test] +fn test_parse_pallet_task_index() { + parse2::(quote!(#[pallet::task_index(3)])).unwrap(); + parse2::(quote!(#[pallet::task_index(0)])).unwrap(); + parse2::(quote!(#[pallet::task_index(17)])).unwrap(); + assert!(parse2::(quote!(#[pallet::task_index])).is_err()); + assert!(parse2::(quote!(#[pallet::task_index("hey")])).is_err()); +} + +#[test] +fn test_parse_pallet_condition() { + parse2::(quote!(#[pallet::condition(|x| x.is_some())])).unwrap(); + parse2::(quote!(#[pallet::condition(|_x| some_expr())])).unwrap(); + assert!(parse2::(quote!(#[pallet::condition(x.is_some())])).is_err()); + assert!(parse2::(quote!(#[pallet::condition(|| something())])).is_err()); +} diff --git a/substrate/frame/support/src/dispatch.rs b/substrate/frame/support/src/dispatch.rs index eb1fc524200b..b39c7856f41f 100644 --- a/substrate/frame/support/src/dispatch.rs +++ b/substrate/frame/support/src/dispatch.rs @@ -671,6 +671,7 @@ mod weight_tests { type BaseCallFilter: crate::traits::Contains; type RuntimeOrigin; type RuntimeCall; + type RuntimeTask; type PalletInfo: crate::traits::PalletInfo; type DbWeight: Get; } @@ -767,6 +768,7 @@ mod weight_tests { type BaseCallFilter = crate::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type DbWeight = DbWeight; type PalletInfo = PalletInfo; } diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index a7106780e021..35ad47583e92 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -819,8 +819,9 @@ pub mod pallet_prelude { StorageList, }, traits::{ - BuildGenesisConfig, ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks, - IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion, TypedGet, + AggregatedTask, BuildGenesisConfig, ConstU32, EnsureOrigin, Get, GetDefault, + GetStorageVersion, Hooks, IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion, + Task, TypedGet, }, Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity, PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat, diff --git a/substrate/frame/support/src/storage/generator/mod.rs b/substrate/frame/support/src/storage/generator/mod.rs index bac9f642e37d..71a32135030c 100644 --- a/substrate/frame/support/src/storage/generator/mod.rs +++ b/substrate/frame/support/src/storage/generator/mod.rs @@ -63,6 +63,7 @@ mod tests { type BaseCallFilter: crate::traits::Contains; type RuntimeOrigin; type RuntimeCall; + type RuntimeTask; type PalletInfo: crate::traits::PalletInfo; type DbWeight: Get; } @@ -129,6 +130,7 @@ mod tests { type BaseCallFilter = crate::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type PalletInfo = PalletInfo; type DbWeight = (); } diff --git a/substrate/frame/support/src/tests/mod.rs b/substrate/frame/support/src/tests/mod.rs index db458880db68..96ac05d38764 100644 --- a/substrate/frame/support/src/tests/mod.rs +++ b/substrate/frame/support/src/tests/mod.rs @@ -49,6 +49,8 @@ pub mod frame_system { type RuntimeCall = (); #[inject_runtime_type] type PalletInfo = (); + #[inject_runtime_type] + type RuntimeTask = (); type DbWeight = (); } } @@ -69,6 +71,8 @@ pub mod frame_system { #[pallet::no_default_bounds] type RuntimeCall; #[pallet::no_default_bounds] + type RuntimeTask; + #[pallet::no_default_bounds] type PalletInfo: crate::traits::PalletInfo; type DbWeight: Get; } @@ -196,6 +200,7 @@ crate::construct_runtime!( impl Config for Runtime { type Block = Block; type AccountId = AccountId; + type RuntimeTask = RuntimeTask; } fn new_test_ext() -> TestExternalities { diff --git a/substrate/frame/support/src/traits.rs b/substrate/frame/support/src/traits.rs index f669046f858f..fbc70e584b34 100644 --- a/substrate/frame/support/src/traits.rs +++ b/substrate/frame/support/src/traits.rs @@ -122,6 +122,9 @@ pub use safe_mode::{SafeMode, SafeModeError, SafeModeNotify}; mod tx_pause; pub use tx_pause::{TransactionPause, TransactionPauseError}; +pub mod tasks; +pub use tasks::{AggregatedTask, Task}; + #[cfg(feature = "try-runtime")] mod try_runtime; #[cfg(feature = "try-runtime")] diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs new file mode 100644 index 000000000000..c52fc7d17917 --- /dev/null +++ b/substrate/frame/support/src/traits/tasks.rs @@ -0,0 +1,74 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Contains the [`Task`] trait, which defines a general-purpose way for defining and executing +//! service work, and supporting types. + +/// Contain's re-exports of all the supporting types for the [`Task`] trait. Used in the macro +/// expansion of `RuntimeTask`. +pub mod prelude { + pub use codec::FullCodec; + pub use scale_info::TypeInfo; + pub use sp_runtime::DispatchError; + pub use sp_std::{fmt::Debug, iter::Iterator}; + pub use sp_weights::Weight; +} + +use prelude::*; + +/// A general-purpose trait which defines a type of service work (i.e., work to performed by an +/// off-chain worker) including methods for enumerating, validating, indexing, and running +/// tasks of this type. +pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { + type Enumeration: Iterator; + + /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks. + const TASK_INDEX: u64; + + /// Inspects the pallet's state and enumerates tasks of this type. + fn enumerate() -> Self::Enumeration; + + /// Checks if a particular instance of this `Task` variant is a valid piece of work. + fn is_valid(&self) -> bool; + + /// Performs the work for this particular `Task` variant. + fn run(&self) -> Result<(), DispatchError>; + + /// Returns the weight of executing this `Task`. + fn weight(&self) -> Weight; + + /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks. + fn task_index(&self) -> u64 { + Self::TASK_INDEX + } +} + +/// Contains a subset of [`Task`] that can be generalized over the aggregated `RuntimeTask` +/// enum. +pub trait AggregatedTask: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { + /// Checks if a particular instance of this `Task` variant is a valid piece of work. + fn is_valid(&self) -> bool; + + /// Performs the work for this particular `Task` variant. + fn run(&self) -> Result<(), DispatchError>; + + /// Returns the weight of executing this `Task`. + fn weight(&self) -> Weight; + + /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks. + fn task_index(&self) -> u64; +} diff --git a/substrate/frame/support/test/compile_pass/src/lib.rs b/substrate/frame/support/test/compile_pass/src/lib.rs index bf90d73acb32..24d8b88e94af 100644 --- a/substrate/frame/support/test/compile_pass/src/lib.rs +++ b/substrate/frame/support/test/compile_pass/src/lib.rs @@ -67,6 +67,7 @@ impl frame_system::Config for Runtime { type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type DbWeight = (); type OnNewAccount = (); type OnKilledAccount = (); diff --git a/substrate/frame/support/test/src/lib.rs b/substrate/frame/support/test/src/lib.rs index 6b38d42d33d0..a8a723375033 100644 --- a/substrate/frame/support/test/src/lib.rs +++ b/substrate/frame/support/test/src/lib.rs @@ -50,6 +50,8 @@ pub mod pallet { + From>; /// The runtime call type. type RuntimeCall; + /// Contains an aggregation of all tasks in this runtime. + type RuntimeTask; /// The runtime event type. type RuntimeEvent: Parameter + Member diff --git a/substrate/frame/support/test/tests/construct_runtime.rs b/substrate/frame/support/test/tests/construct_runtime.rs index 9ad51ad530eb..dbb20851aacd 100644 --- a/substrate/frame/support/test/tests/construct_runtime.rs +++ b/substrate/frame/support/test/tests/construct_runtime.rs @@ -282,6 +282,7 @@ impl frame_system::Config for Runtime { type BaseCallFilter = frame_support::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/final_keys.rs b/substrate/frame/support/test/tests/final_keys.rs index 765afaf1e660..8989e8da69a2 100644 --- a/substrate/frame/support/test/tests/final_keys.rs +++ b/substrate/frame/support/test/tests/final_keys.rs @@ -217,6 +217,7 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/genesisconfig.rs b/substrate/frame/support/test/tests/genesisconfig.rs index c6781220692a..cf10a0f762ba 100644 --- a/substrate/frame/support/test/tests/genesisconfig.rs +++ b/substrate/frame/support/test/tests/genesisconfig.rs @@ -86,6 +86,7 @@ impl frame_system::Config for Test { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/instance.rs b/substrate/frame/support/test/tests/instance.rs index 43a93df9dea4..ea8e52747434 100644 --- a/substrate/frame/support/test/tests/instance.rs +++ b/substrate/frame/support/test/tests/instance.rs @@ -306,6 +306,7 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/issue2219.rs b/substrate/frame/support/test/tests/issue2219.rs index 4016707b51a8..7373d70fe574 100644 --- a/substrate/frame/support/test/tests/issue2219.rs +++ b/substrate/frame/support/test/tests/issue2219.rs @@ -168,6 +168,7 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU64<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/origin.rs b/substrate/frame/support/test/tests/origin.rs index 5682bb500c7e..fedeb344a139 100644 --- a/substrate/frame/support/test/tests/origin.rs +++ b/substrate/frame/support/test/tests/origin.rs @@ -177,6 +177,7 @@ impl frame_system::Config for RuntimeOriginTest { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index 1898246470c7..da07b57b24bb 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -692,6 +692,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/pallet_instance.rs b/substrate/frame/support/test/tests/pallet_instance.rs index 8d2d52d18852..dee671da35ea 100644 --- a/substrate/frame/support/test/tests/pallet_instance.rs +++ b/substrate/frame/support/test/tests/pallet_instance.rs @@ -296,6 +296,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = sp_runtime::testing::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = u64; 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 a8250f8b1532..c90c5ecf6971 100644 --- a/substrate/frame/support/test/tests/pallet_outer_enums_explicit.rs +++ b/substrate/frame/support/test/tests/pallet_outer_enums_explicit.rs @@ -32,6 +32,7 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); @@ -90,6 +91,8 @@ fn module_error_outer_enum_expand_explicit() { frame_system::Error::NonDefaultComposite => (), frame_system::Error::NonZeroRefCount => (), frame_system::Error::CallFiltered => (), + frame_system::Error::InvalidTask => (), + 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 191f095f5d78..ed08bf66287e 100644 --- a/substrate/frame/support/test/tests/pallet_outer_enums_implicit.rs +++ b/substrate/frame/support/test/tests/pallet_outer_enums_implicit.rs @@ -32,6 +32,7 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); @@ -90,6 +91,8 @@ fn module_error_outer_enum_expand_implicit() { frame_system::Error::NonDefaultComposite => (), frame_system::Error::NonZeroRefCount => (), frame_system::Error::CallFiltered => (), + frame_system::Error::InvalidTask => (), + frame_system::Error::FailedTask => (), frame_system::Error::__Ignore(_, _) => (), }, diff --git a/substrate/frame/support/test/tests/runtime_metadata.rs b/substrate/frame/support/test/tests/runtime_metadata.rs index a545735f2b1e..debdce9289ff 100644 --- a/substrate/frame/support/test/tests/runtime_metadata.rs +++ b/substrate/frame/support/test/tests/runtime_metadata.rs @@ -35,6 +35,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = sp_runtime::testing::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/support/test/tests/storage_layers.rs b/substrate/frame/support/test/tests/storage_layers.rs index b825c85f9564..34230af622fa 100644 --- a/substrate/frame/support/test/tests/storage_layers.rs +++ b/substrate/frame/support/test/tests/storage_layers.rs @@ -70,6 +70,7 @@ impl frame_system::Config for Runtime { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = sp_runtime::testing::H256; type Hashing = sp_runtime::traits::BlakeTwo256; diff --git a/substrate/frame/support/test/tests/storage_transaction.rs b/substrate/frame/support/test/tests/storage_transaction.rs index c47743308609..7a61a44714b3 100644 --- a/substrate/frame/support/test/tests/storage_transaction.rs +++ b/substrate/frame/support/test/tests/storage_transaction.rs @@ -95,6 +95,7 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 84b6dc031457..0d24f1c7f08e 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -240,6 +240,8 @@ pub mod pallet { type RuntimeCall = (); #[inject_runtime_type] type PalletInfo = (); + #[inject_runtime_type] + type RuntimeTask = (); type BaseCallFilter = frame_support::traits::Everything; type BlockHashCount = frame_support::traits::ConstU64<10>; type OnSetCode = (); @@ -293,6 +295,10 @@ pub mod pallet { + Debug + From>; + /// The aggregated `RuntimeTask` type. + #[pallet::no_default_bounds] + type RuntimeTask: AggregatedTask; + /// This stores the number of previous transactions associated with a sender account. type Nonce: Parameter + Member @@ -520,6 +526,28 @@ pub mod pallet { Self::deposit_event(Event::Remarked { sender: who, hash }); Ok(().into()) } + + #[pallet::call_index(8)] + #[pallet::weight(task.weight())] + pub fn do_task(origin: OriginFor, task: T::RuntimeTask) -> DispatchResultWithPostInfo { + ensure_signed(origin)?; + + if !task.is_valid() { + return Err(Error::::InvalidTask.into()) + } + + Self::deposit_event(Event::TaskStarted { task: task.clone() }); + if let Err(err) = task.run() { + Self::deposit_event(Event::TaskFailed { task, err }); + return Err(Error::::FailedTask.into()) + } + + // Emit a success event, if your design includes events for this pallet. + Self::deposit_event(Event::TaskCompleted { task }); + + // Return success. + Ok(().into()) + } } /// Event for the System pallet. @@ -537,6 +565,12 @@ pub mod pallet { KilledAccount { account: T::AccountId }, /// On on-chain remark happened. Remarked { sender: T::AccountId, hash: T::Hash }, + /// A [`Task`] has started executing + TaskStarted { task: T::RuntimeTask }, + /// A [`Task`] has finished executing. + TaskCompleted { task: T::RuntimeTask }, + /// A [`Task`] failed during execution. + TaskFailed { task: T::RuntimeTask, err: DispatchError }, } /// Error for the System pallet @@ -558,6 +592,10 @@ pub mod pallet { NonZeroRefCount, /// The origin filter prevent the call to be dispatched. CallFiltered, + /// The specified [`Task`] is not valid. + InvalidTask, + /// The specified [`Task`] failed during execution. + FailedTask, } /// Exposed trait-generic origin type. diff --git a/substrate/frame/system/src/mock.rs b/substrate/frame/system/src/mock.rs index c016ea9e1cd1..670dbb266b03 100644 --- a/substrate/frame/system/src/mock.rs +++ b/substrate/frame/system/src/mock.rs @@ -91,6 +91,7 @@ impl Config for Test { type BlockLength = RuntimeBlockLength; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/timestamp/src/mock.rs b/substrate/frame/timestamp/src/mock.rs index 418d257b3f00..f56b5eaab445 100644 --- a/substrate/frame/timestamp/src/mock.rs +++ b/substrate/frame/timestamp/src/mock.rs @@ -50,6 +50,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/tips/src/tests.rs b/substrate/frame/tips/src/tests.rs index a700892d4270..1282d42d13d0 100644 --- a/substrate/frame/tips/src/tests.rs +++ b/substrate/frame/tips/src/tests.rs @@ -61,6 +61,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account @@ -85,6 +86,7 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs index bfbe8b4178ce..b694a2017c6c 100644 --- a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs @@ -86,6 +86,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; @@ -111,6 +112,7 @@ parameter_types! { impl pallet_balances::Config for Runtime { type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<10>; type AccountStore = System; diff --git a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs index b8d7b523ca25..dd6b4e0dbd0f 100644 --- a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs @@ -78,6 +78,7 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; @@ -114,6 +115,7 @@ impl pallet_balances::Config for Runtime { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl WeightToFeeT for WeightToFee { diff --git a/substrate/frame/transaction-payment/src/mock.rs b/substrate/frame/transaction-payment/src/mock.rs index 97253be46305..0f9b4369d645 100644 --- a/substrate/frame/transaction-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/src/mock.rs @@ -76,6 +76,7 @@ impl frame_system::Config for Runtime { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hash = H256; type Hashing = BlakeTwo256; @@ -109,6 +110,7 @@ impl pallet_balances::Config for Runtime { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl WeightToFeeT for WeightToFee { diff --git a/substrate/frame/transaction-storage/src/mock.rs b/substrate/frame/transaction-storage/src/mock.rs index 243e26b55905..f72eb905ddc9 100644 --- a/substrate/frame/transaction-storage/src/mock.rs +++ b/substrate/frame/transaction-storage/src/mock.rs @@ -48,6 +48,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -82,6 +83,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl pallet_transaction_storage::Config for Test { diff --git a/substrate/frame/treasury/src/tests.rs b/substrate/frame/treasury/src/tests.rs index ba45d5f6ff16..ef5fded42048 100644 --- a/substrate/frame/treasury/src/tests.rs +++ b/substrate/frame/treasury/src/tests.rs @@ -56,6 +56,7 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account @@ -87,6 +88,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl pallet_utility::Config for Test { diff --git a/substrate/frame/tx-pause/src/mock.rs b/substrate/frame/tx-pause/src/mock.rs index 60c5fc1eced5..0ce7aa5b808e 100644 --- a/substrate/frame/tx-pause/src/mock.rs +++ b/substrate/frame/tx-pause/src/mock.rs @@ -42,6 +42,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -80,6 +81,7 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; + type RuntimeTask = RuntimeTask; } impl pallet_utility::Config for Test { diff --git a/substrate/frame/uniques/src/mock.rs b/substrate/frame/uniques/src/mock.rs index 5c44a7ed7a53..0aacdb0d45f0 100644 --- a/substrate/frame/uniques/src/mock.rs +++ b/substrate/frame/uniques/src/mock.rs @@ -46,6 +46,7 @@ impl frame_system::Config for Test { type BlockWeights = (); type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; @@ -81,6 +82,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/utility/src/tests.rs b/substrate/frame/utility/src/tests.rs index 183853c4e8ac..934ee8f6ce76 100644 --- a/substrate/frame/utility/src/tests.rs +++ b/substrate/frame/utility/src/tests.rs @@ -153,6 +153,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; @@ -177,6 +178,7 @@ impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU64<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/vesting/src/mock.rs b/substrate/frame/vesting/src/mock.rs index fe1779475a69..d2bb06d8eaa7 100644 --- a/substrate/frame/vesting/src/mock.rs +++ b/substrate/frame/vesting/src/mock.rs @@ -46,6 +46,7 @@ impl frame_system::Config for Test { type BlockHashCount = ConstU64<250>; type BlockLength = (); type BlockWeights = (); + type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type DbWeight = (); type RuntimeEvent = RuntimeEvent; @@ -79,6 +80,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } parameter_types! { pub const MinVestedTransfer: u64 = 256 * 2; diff --git a/substrate/frame/whitelist/src/mock.rs b/substrate/frame/whitelist/src/mock.rs index d91f43b33af9..593d539b95b6 100644 --- a/substrate/frame/whitelist/src/mock.rs +++ b/substrate/frame/whitelist/src/mock.rs @@ -53,6 +53,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; @@ -84,6 +85,7 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = (); type MaxHolds = (); + type RuntimeTask = RuntimeTask; } impl pallet_preimage::Config for Test { diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index b116c8556815..d342d2ae48a2 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -349,6 +349,7 @@ impl frame_system::pallet::Config for Runtime { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = H256; type Hashing = Hashing; @@ -391,6 +392,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; From cbc24c70ea52d2bc7771901a3f8f0f2cd8e6cfdf Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 6 Sep 2023 15:29:35 -0400 Subject: [PATCH 002/177] add missing RuntimeTask defs, still getting From> error --- Cargo.lock | 1 + cumulus/parachain-template/runtime/src/lib.rs | 3 +++ cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 2 ++ .../parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs | 2 ++ .../parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 2 ++ .../runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs | 3 +++ .../runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs | 3 +++ .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 3 +++ .../runtimes/collectives/collectives-polkadot/src/lib.rs | 2 ++ .../parachains/runtimes/contracts/contracts-rococo/src/lib.rs | 2 ++ cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs | 1 + cumulus/parachains/runtimes/starters/seedling/src/lib.rs | 2 ++ cumulus/parachains/runtimes/starters/shell/src/lib.rs | 2 ++ cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 3 +++ .../parachains/runtimes/testing/rococo-parachain/src/lib.rs | 3 +++ cumulus/test/runtime/src/lib.rs | 3 +++ polkadot/runtime/kusama/src/lib.rs | 3 +++ polkadot/runtime/polkadot/src/lib.rs | 2 ++ polkadot/runtime/rococo/src/lib.rs | 3 +++ polkadot/runtime/test-runtime/src/lib.rs | 2 ++ polkadot/runtime/westend/src/lib.rs | 2 ++ polkadot/xcm/xcm-simulator/example/src/parachain.rs | 2 ++ polkadot/xcm/xcm-simulator/example/src/relay_chain.rs | 2 ++ polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs | 2 ++ polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs | 2 ++ substrate/bin/node/runtime/Cargo.toml | 1 + 26 files changed, 58 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 5c24e6c20d15..c9e089730149 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6873,6 +6873,7 @@ dependencies = [ "sp-version", "static_assertions", "substrate-wasm-builder", + "tasks-example", ] [[package]] diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index 038597096f6a..c0d3d3cb0798 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -277,6 +277,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. @@ -353,6 +355,7 @@ impl pallet_balances::Config for Runtime { type FreezeIdentifier = (); type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; + type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 828d1b4750a3..fa68d9ed7d31 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -172,6 +172,7 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; @@ -215,6 +216,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index 0051af21f9a3..c422f11e5ac7 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -182,6 +182,7 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; @@ -225,6 +226,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 4887fce1b0a4..299216eacb2e 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -151,6 +151,7 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; @@ -194,6 +195,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 54b15e6b327b..9db79108a474 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -174,6 +174,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. @@ -239,6 +241,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = weights::pallet_balances::WeightInfo; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index dbfdc249a3cd..b9f407c2470d 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -174,6 +174,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. @@ -239,6 +241,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = weights::pallet_balances::WeightInfo; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 4311a6a629f9..c7d116c7d429 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -190,6 +190,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. @@ -256,6 +258,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = weights::pallet_balances::WeightInfo; diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 238db08a0c9e..aa751adfebcd 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -158,6 +158,7 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; @@ -201,6 +202,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 399ada1be2c7..590196c46cd4 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -172,6 +172,7 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; @@ -211,6 +212,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU128; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs index dde8f747d463..9c77693ee66f 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs @@ -147,6 +147,7 @@ impl frame_system::Config for Runtime { type Hashing = BlakeTwo256; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type Version = Version; diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index 5f6733faf706..e9b4e1e2f8b7 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -122,6 +122,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index ef914a246efc..734bc65f0179 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -130,6 +130,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 9a758cdd9782..70522b94e1b3 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -323,6 +323,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. @@ -389,6 +391,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 362ad0383a23..fad024119c2c 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -184,6 +184,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. @@ -238,6 +240,7 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index ccf624c0ffa4..8b7193a5b815 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -185,6 +185,8 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; + /// The aggregated task type. + type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = IdentityLookup; /// The index type for storing how many extrinsics an account has signed. @@ -242,6 +244,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 659a7052d2b7..8c627dde8714 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -176,6 +176,7 @@ impl frame_system::Config for Runtime { type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = Hash; type Hashing = BlakeTwo256; @@ -304,6 +305,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = MaxLocks; @@ -1391,6 +1393,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU128<10_000_000_000>; // One KTC cent type AccountStore = StorageMapShim< pallet_balances::Account, diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 45ea561b33fa..7f22aed51e58 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -159,6 +159,7 @@ impl frame_system::Config for Runtime { type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = Hash; type Hashing = BlakeTwo256; @@ -289,6 +290,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = MaxLocks; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index e043852901f1..55c9f1c6ec70 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -154,6 +154,7 @@ impl frame_system::Config for Runtime { type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = Hash; type Hashing = BlakeTwo256; @@ -277,6 +278,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = MaxLocks; @@ -1227,6 +1229,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU128<10_000_000_000>; // One RTC cent type AccountStore = StorageMapShim< pallet_balances::Account, diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index 94852ad39f5a..1a5090349836 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -144,6 +144,7 @@ impl frame_system::Config for Runtime { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = HashT; type Hashing = BlakeTwo256; @@ -220,6 +221,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = MaxLocks; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 7dfc781d2467..65eae97216a3 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -152,6 +152,7 @@ impl frame_system::Config for Runtime { type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = Hash; type Hashing = BlakeTwo256; @@ -260,6 +261,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = MaxLocks; diff --git a/polkadot/xcm/xcm-simulator/example/src/parachain.rs b/polkadot/xcm/xcm-simulator/example/src/parachain.rs index bc7cba313828..d3d2fc267490 100644 --- a/polkadot/xcm/xcm-simulator/example/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/parachain.rs @@ -66,6 +66,7 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; @@ -99,6 +100,7 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs index 4e9195a8454f..8352325b68af 100644 --- a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs @@ -52,6 +52,7 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; @@ -85,6 +86,7 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs index 95f875eca06e..6d6409958e61 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -55,6 +55,7 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; @@ -88,6 +89,7 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index a29ead9e6c3b..b7148b41b4fc 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -51,6 +51,7 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; @@ -84,6 +85,7 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 09c1fd9c6f31..6a0866785f95 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -131,6 +131,7 @@ pallet-vesting = { path = "../../../frame/vesting", default-features = false} pallet-whitelist = { path = "../../../frame/whitelist", default-features = false} pallet-tx-pause = { path = "../../../frame/tx-pause", default-features = false} pallet-safe-mode = { path = "../../../frame/safe-mode", default-features = false} +tasks-example = { path = "../../../frame/examples/tasks-example", default-features = false } [build-dependencies] substrate-wasm-builder = { path = "../../../utils/wasm-builder", optional = true } From e7c2721a2dfe7d908c6853358d95c88d2b32b189 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 6 Sep 2023 17:59:14 -0400 Subject: [PATCH 003/177] fix `RuntimeEvent: From>` not satisfied * but now getting expected keyword error on construct_runtime! --- substrate/bin/node/runtime/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 0558798de572..2bd12695f3cf 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2093,6 +2093,7 @@ construct_runtime!( SafeMode: pallet_safe_mode, Statement: pallet_statement, Broker: pallet_broker, + TasksExample: tasks_example, } ); From 7f77ce2ed58ee4edd42ca128a86fbaa3f40d82a3 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 6 Sep 2023 23:01:53 -0400 Subject: [PATCH 004/177] add some missing RuntimeTasks --- cumulus/bridges/bin/runtime-common/src/mock.rs | 2 ++ polkadot/runtime/common/src/assigned_slots/mod.rs | 2 ++ polkadot/runtime/common/src/auctions.rs | 2 ++ polkadot/runtime/common/src/claims.rs | 2 ++ polkadot/runtime/common/src/crowdloan/mod.rs | 2 ++ polkadot/runtime/common/src/impls.rs | 2 ++ polkadot/runtime/common/src/integration_tests.rs | 2 ++ polkadot/runtime/common/src/paras_registrar/mod.rs | 2 ++ polkadot/runtime/common/src/purchase.rs | 2 ++ polkadot/runtime/common/src/slots/mod.rs | 2 ++ polkadot/xcm/pallet-xcm/src/mock.rs | 2 ++ 11 files changed, 22 insertions(+) diff --git a/cumulus/bridges/bin/runtime-common/src/mock.rs b/cumulus/bridges/bin/runtime-common/src/mock.rs index 45ef790d7448..8a40b5a139f4 100644 --- a/cumulus/bridges/bin/runtime-common/src/mock.rs +++ b/cumulus/bridges/bin/runtime-common/src/mock.rs @@ -150,6 +150,7 @@ impl frame_system::Config for TestRuntime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = ThisChainHash; type Hashing = ThisChainHasher; type AccountId = ThisChainAccountId; @@ -182,6 +183,7 @@ impl pallet_utility::Config for TestRuntime { impl pallet_balances::Config for TestRuntime { type Balance = ThisChainBalance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/assigned_slots/mod.rs b/polkadot/runtime/common/src/assigned_slots/mod.rs index cc8ec339c118..854067f84784 100644 --- a/polkadot/runtime/common/src/assigned_slots/mod.rs +++ b/polkadot/runtime/common/src/assigned_slots/mod.rs @@ -685,6 +685,7 @@ mod tests { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -712,6 +713,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/auctions.rs b/polkadot/runtime/common/src/auctions.rs index e35303912fa1..d3d6e26056db 100644 --- a/polkadot/runtime/common/src/auctions.rs +++ b/polkadot/runtime/common/src/auctions.rs @@ -712,6 +712,7 @@ mod tests { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -740,6 +741,7 @@ mod tests { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); diff --git a/polkadot/runtime/common/src/claims.rs b/polkadot/runtime/common/src/claims.rs index 0c736a632842..4f873f4cae7e 100644 --- a/polkadot/runtime/common/src/claims.rs +++ b/polkadot/runtime/common/src/claims.rs @@ -746,6 +746,7 @@ mod tests { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -772,6 +773,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/crowdloan/mod.rs b/polkadot/runtime/common/src/crowdloan/mod.rs index 5a2939145925..200afaabe373 100644 --- a/polkadot/runtime/common/src/crowdloan/mod.rs +++ b/polkadot/runtime/common/src/crowdloan/mod.rs @@ -907,6 +907,7 @@ mod tests { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -933,6 +934,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/impls.rs b/polkadot/runtime/common/src/impls.rs index 0d0dee2e9ad9..a845bfeee4b9 100644 --- a/polkadot/runtime/common/src/impls.rs +++ b/polkadot/runtime/common/src/impls.rs @@ -149,6 +149,7 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; @@ -173,6 +174,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/polkadot/runtime/common/src/integration_tests.rs b/polkadot/runtime/common/src/integration_tests.rs index f14db68267d5..1f56f98a4b89 100644 --- a/polkadot/runtime/common/src/integration_tests.rs +++ b/polkadot/runtime/common/src/integration_tests.rs @@ -116,6 +116,7 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -174,6 +175,7 @@ impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/paras_registrar/mod.rs b/polkadot/runtime/common/src/paras_registrar/mod.rs index f2751803a413..f7c342fdca50 100644 --- a/polkadot/runtime/common/src/paras_registrar/mod.rs +++ b/polkadot/runtime/common/src/paras_registrar/mod.rs @@ -755,6 +755,7 @@ mod tests { type BaseCallFilter = frame_support::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -785,6 +786,7 @@ mod tests { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = (); diff --git a/polkadot/runtime/common/src/purchase.rs b/polkadot/runtime/common/src/purchase.rs index 58ca19d0288c..349c2606d24a 100644 --- a/polkadot/runtime/common/src/purchase.rs +++ b/polkadot/runtime/common/src/purchase.rs @@ -518,6 +518,7 @@ mod tests { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -544,6 +545,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/slots/mod.rs b/polkadot/runtime/common/src/slots/mod.rs index a3efd5bfa30a..d52145f8438d 100644 --- a/polkadot/runtime/common/src/slots/mod.rs +++ b/polkadot/runtime/common/src/slots/mod.rs @@ -535,6 +535,7 @@ mod tests { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -562,6 +563,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/pallet-xcm/src/mock.rs b/polkadot/xcm/pallet-xcm/src/mock.rs index b09bcb80ed67..ff3ba7860546 100644 --- a/polkadot/xcm/pallet-xcm/src/mock.rs +++ b/polkadot/xcm/pallet-xcm/src/mock.rs @@ -200,6 +200,7 @@ parameter_types! { impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; @@ -233,6 +234,7 @@ impl pallet_balances::Config for Test { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; From 5161f609adaa4c3c52e466ae47233b2a0444c5f4 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 6 Sep 2023 23:40:58 -0400 Subject: [PATCH 005/177] add even _more_ missing RuntimeTasks --- cumulus/bridges/modules/parachains/src/mock.rs | 1 + cumulus/parachains/common/src/impls.rs | 2 ++ polkadot/runtime/parachains/src/mock.rs | 2 ++ 3 files changed, 5 insertions(+) diff --git a/cumulus/bridges/modules/parachains/src/mock.rs b/cumulus/bridges/modules/parachains/src/mock.rs index 14afe3841710..5a187131dc29 100644 --- a/cumulus/bridges/modules/parachains/src/mock.rs +++ b/cumulus/bridges/modules/parachains/src/mock.rs @@ -163,6 +163,7 @@ impl frame_system::Config for TestRuntime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Block = Block; type Hash = H256; type Hashing = RegularParachainHasher; diff --git a/cumulus/parachains/common/src/impls.rs b/cumulus/parachains/common/src/impls.rs index 107cd5c68732..b429ae80fcb6 100644 --- a/cumulus/parachains/common/src/impls.rs +++ b/cumulus/parachains/common/src/impls.rs @@ -160,6 +160,7 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; @@ -184,6 +185,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index ded7de08e4fa..0984d624f854 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -101,6 +101,7 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -138,6 +139,7 @@ impl pallet_balances::Config for Test { type FreezeIdentifier = (); type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; + type RuntimeTask = RuntimeTask; } parameter_types! { From 54095623bd8178389b3d0c307a212f56f11a8ee0 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 7 Sep 2023 10:45:12 +0530 Subject: [PATCH 006/177] Fixes kitchensink build --- .../support/procedural/src/pallet/expand/tt_default_parts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs b/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs index f322fe17a7c4..8bac7fc293d8 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs @@ -37,7 +37,7 @@ pub fn expand_tt_default_parts(def: &mut Def) -> proc_macro2::TokenStream { if let syn::Item::Enum(item_enum) = item { if item_enum.ident == "Task" { println!("found task enum in tt_default_parts!"); - return Some(item_enum) + return Some(quote::quote!(Task, )) } } None From 1dfc5d01e9cc547dc2f20181cc99ae0d94e0b1db Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 7 Sep 2023 12:42:15 -0400 Subject: [PATCH 007/177] add remaining missing RuntimeTasks, cargo check green without --workspace --- cumulus/bridges/modules/relayers/src/mock.rs | 2 ++ cumulus/bridges/modules/xcm-bridge-hub-router/src/mock.rs | 1 + polkadot/xcm/xcm-builder/src/tests/pay/mock.rs | 1 + polkadot/xcm/xcm-builder/tests/mock/mod.rs | 2 ++ 4 files changed, 6 insertions(+) diff --git a/cumulus/bridges/modules/relayers/src/mock.rs b/cumulus/bridges/modules/relayers/src/mock.rs index 4713ec91658a..e1d6309edb89 100644 --- a/cumulus/bridges/modules/relayers/src/mock.rs +++ b/cumulus/bridges/modules/relayers/src/mock.rs @@ -65,6 +65,7 @@ impl frame_system::Config for TestRuntime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Block = Block; type Hash = H256; type Hashing = BlakeTwo256; @@ -92,6 +93,7 @@ impl pallet_balances::Config for TestRuntime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type WeightInfo = (); diff --git a/cumulus/bridges/modules/xcm-bridge-hub-router/src/mock.rs b/cumulus/bridges/modules/xcm-bridge-hub-router/src/mock.rs index cd50b98a1688..fd55f6b027b5 100644 --- a/cumulus/bridges/modules/xcm-bridge-hub-router/src/mock.rs +++ b/cumulus/bridges/modules/xcm-bridge-hub-router/src/mock.rs @@ -61,6 +61,7 @@ impl frame_system::Config for TestRuntime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Block = Block; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs index c663b0a4d76f..3c186ae889a0 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs @@ -78,6 +78,7 @@ impl pallet_balances::Config for Test { type MaxLocks = ConstU32<0>; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-builder/tests/mock/mod.rs b/polkadot/xcm/xcm-builder/tests/mock/mod.rs index 363748940ca6..a66f229a3aaa 100644 --- a/polkadot/xcm/xcm-builder/tests/mock/mod.rs +++ b/polkadot/xcm/xcm-builder/tests/mock/mod.rs @@ -79,6 +79,7 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; @@ -112,6 +113,7 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; From f2276301fb033ae6ecfebe01b57081ef6c0bb8ac Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 7 Sep 2023 19:41:25 -0400 Subject: [PATCH 008/177] add more missing RuntimeTasks --- cumulus/bridges/modules/grandpa/src/mock.rs | 1 + cumulus/pallets/parachain-system/src/tests.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/cumulus/bridges/modules/grandpa/src/mock.rs b/cumulus/bridges/modules/grandpa/src/mock.rs index f88a0a3e6a6e..af9852fd7df8 100644 --- a/cumulus/bridges/modules/grandpa/src/mock.rs +++ b/cumulus/bridges/modules/grandpa/src/mock.rs @@ -59,6 +59,7 @@ impl frame_system::Config for TestRuntime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; diff --git a/cumulus/pallets/parachain-system/src/tests.rs b/cumulus/pallets/parachain-system/src/tests.rs index 626196790bc9..d866becf4faf 100755 --- a/cumulus/pallets/parachain-system/src/tests.rs +++ b/cumulus/pallets/parachain-system/src/tests.rs @@ -75,6 +75,7 @@ parameter_types! { impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; From 92b1865e8b6e9b684678b03ad1ba08e9af7c68cb Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 8 Sep 2023 15:42:37 -0400 Subject: [PATCH 009/177] re-organize traits WIP --- substrate/frame/balances/src/lib.rs | 2 +- .../frame/examples/default-config/src/lib.rs | 2 +- .../frame/examples/tasks-example/src/lib.rs | 4 ++-- .../src/construct_runtime/expand/task.rs | 6 +++++- substrate/frame/support/src/lib.rs | 5 ++--- substrate/frame/support/src/traits.rs | 2 +- substrate/frame/support/src/traits/tasks.rs | 16 ---------------- substrate/frame/system/src/lib.rs | 2 +- 8 files changed, 13 insertions(+), 26 deletions(-) diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index f5be4b4456c3..819f49cc33f7 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -251,7 +251,7 @@ pub mod pallet { /// The overarching task type. #[pallet::no_default] - type RuntimeTask: AggregatedTask; + type RuntimeTask: Task; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; diff --git a/substrate/frame/examples/default-config/src/lib.rs b/substrate/frame/examples/default-config/src/lib.rs index 15096e53e4e3..37cf6c861e6a 100644 --- a/substrate/frame/examples/default-config/src/lib.rs +++ b/substrate/frame/examples/default-config/src/lib.rs @@ -48,7 +48,7 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; #[pallet::no_default] - type RuntimeTask: AggregatedTask; + type RuntimeTask: Task; /// An input parameter to this pallet. This value can have a default, because it is not /// reliant on `frame_system::Config` or the overarching runtime in any way. diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index 2223ecbd0d30..4ce6017d7f9d 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -29,7 +29,7 @@ use sp_runtime::DispatchError; pub mod pallet { use super::*; - use frame_support::{pallet_prelude::*, traits::AggregatedTask}; + use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; // this can be auto-generated from the macros @@ -121,7 +121,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type RuntimeTask: AggregatedTask; + type RuntimeTask: frame_support::traits::Task; } #[pallet::pallet] diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 34d62a7c3594..59821373c7da 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -60,7 +60,11 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream) -> Token #( #task_variants )* } - impl #scrate::traits::AggregatedTask for RuntimeTask { + impl #scrate::traits::Task for RuntimeTask { + type Enumeration: Iterator; + + const TASK_INDEX: u64 = 0; + fn is_valid(&self) -> bool { use #scrate::traits::tasks::prelude::*; todo!(); diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 35ad47583e92..03398d60881b 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -819,9 +819,8 @@ pub mod pallet_prelude { StorageList, }, traits::{ - AggregatedTask, BuildGenesisConfig, ConstU32, EnsureOrigin, Get, GetDefault, - GetStorageVersion, Hooks, IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion, - Task, TypedGet, + BuildGenesisConfig, ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks, + IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion, Task, TypedGet, }, Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity, PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat, diff --git a/substrate/frame/support/src/traits.rs b/substrate/frame/support/src/traits.rs index fbc70e584b34..c63160ac5006 100644 --- a/substrate/frame/support/src/traits.rs +++ b/substrate/frame/support/src/traits.rs @@ -123,7 +123,7 @@ mod tx_pause; pub use tx_pause::{TransactionPause, TransactionPauseError}; pub mod tasks; -pub use tasks::{AggregatedTask, Task}; +pub use tasks::Task; #[cfg(feature = "try-runtime")] mod try_runtime; diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index c52fc7d17917..e7e75b9d832a 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -56,19 +56,3 @@ pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { Self::TASK_INDEX } } - -/// Contains a subset of [`Task`] that can be generalized over the aggregated `RuntimeTask` -/// enum. -pub trait AggregatedTask: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { - /// Checks if a particular instance of this `Task` variant is a valid piece of work. - fn is_valid(&self) -> bool; - - /// Performs the work for this particular `Task` variant. - fn run(&self) -> Result<(), DispatchError>; - - /// Returns the weight of executing this `Task`. - fn weight(&self) -> Weight; - - /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks. - fn task_index(&self) -> u64; -} diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 0d24f1c7f08e..de86c43ee7ad 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -297,7 +297,7 @@ pub mod pallet { /// The aggregated `RuntimeTask` type. #[pallet::no_default_bounds] - type RuntimeTask: AggregatedTask; + type RuntimeTask: Task; /// This stores the number of previous transactions associated with a sender account. type Nonce: Parameter From 5a768367efcd970c868cd57ed9ba629ead98b9df Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 8 Sep 2023 16:16:26 -0400 Subject: [PATCH 010/177] clean up WIP --- .../frame/examples/tasks-example/src/lib.rs | 2 +- .../src/construct_runtime/expand/task.rs | 63 ++++++++----------- substrate/frame/support/src/traits/tasks.rs | 12 ++-- 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index 4ce6017d7f9d..fd95f36e5776 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -68,7 +68,7 @@ pub mod pallet { { type Enumeration = sp_std::vec::IntoIter>; - const TASK_INDEX: u64 = 0; + const TASK_INDEX: Option = Some(0); fn enumerate() -> Self::Enumeration { sp_std::vec![Task::Increment, Task::Decrement].into_iter() diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 59821373c7da..570497a471ae 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -15,25 +15,35 @@ // See the License for the specific language governing permissions and // limitations under the License -use crate::construct_runtime::{parse::PalletPath, Pallet}; -use proc_macro2::{Ident, TokenStream}; +use crate::construct_runtime::Pallet; +use proc_macro2::TokenStream as TokenStream2; use quote::quote; /// Expands aggregate `RuntimeTask` enum. -pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream) -> TokenStream { - let mut conversion_fns = Vec::new(); +pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> TokenStream2 { + let mut from_impls = Vec::new(); let mut task_variants = Vec::new(); for decl in pallet_decls { if let Some(_) = decl.find_part("Task") { - // TODO: for some reason `find_part` above never finds `Task` even when it is - // clearly in the pallet let variant_name = &decl.name; let path = &decl.path; let index = decl.index; - conversion_fns.push(expand_conversion_fn(path, variant_name)); - - task_variants.push(expand_variant(index, path, variant_name)); + // Todo: Replace `Runtime` with the actual runtime ident + // `pallet` will probably not be needed when `Task` is generated by macro + + from_impls.push(quote! { + impl From<#path::pallet::Task> for RuntimeTask { + fn from(hr: #path::pallet::Task) -> Self { + RuntimeTask::#variant_name(hr) + } + } + }); + + task_variants.push(quote! { + #[codec(index = #index)] + #variant_name(#path::pallet::Task), + }); } } use quote::ToTokens; @@ -47,6 +57,8 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream) -> Token ); } + let prelude = quote!(#scrate::traits::tasks::prelude); + quote! { /// An aggregation of all `Task` enums across all pallets included in the current runtime. #[derive( @@ -61,12 +73,12 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream) -> Token } impl #scrate::traits::Task for RuntimeTask { - type Enumeration: Iterator; + type Enumeration = #prelude::IntoIter<#scrate::traits::Task>; - const TASK_INDEX: u64 = 0; + const TASK_INDEX: Option = None; fn is_valid(&self) -> bool { - use #scrate::traits::tasks::prelude::*; + use #prelude::*; todo!(); } @@ -77,33 +89,8 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream) -> Token fn weight(&self) -> #scrate::pallet_prelude::Weight { todo!(); } - - fn task_index(&self) -> u64 { - todo!(); - } } - #( #conversion_fns )* - } -} - -fn expand_conversion_fn(path: &PalletPath, variant_name: &Ident) -> TokenStream { - // Todo: Replace `Runtime` with the actual runtime ident - // `pallet` will probably not be needed when `Task` is generated by macro - quote! { - impl From<#path::pallet::Task> for RuntimeTask { - fn from(hr: #path::pallet::Task) -> Self { - RuntimeTask::#variant_name(hr) - } - } - } -} - -fn expand_variant(index: u8, path: &PalletPath, variant_name: &Ident) -> TokenStream { - // Todo: Replace `Runtime` with the actual runtime ident - // `pallet` will probably not be needed when `Task` is generated by macro - quote! { - #[codec(index = #index)] - #variant_name(#path::pallet::Task), + #( #from_impls )* } } diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index e7e75b9d832a..2039f2202e5e 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -24,7 +24,7 @@ pub mod prelude { pub use codec::FullCodec; pub use scale_info::TypeInfo; pub use sp_runtime::DispatchError; - pub use sp_std::{fmt::Debug, iter::Iterator}; + pub use sp_std::{fmt::Debug, iter::Iterator, vec::IntoIter}; pub use sp_weights::Weight; } @@ -37,7 +37,9 @@ pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { type Enumeration: Iterator; /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks. - const TASK_INDEX: u64; + /// + /// Set to [`None`] for the aggregated `RuntimeTask` type. + const TASK_INDEX: Option; /// Inspects the pallet's state and enumerates tasks of this type. fn enumerate() -> Self::Enumeration; @@ -51,8 +53,10 @@ pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { /// Returns the weight of executing this `Task`. fn weight(&self) -> Weight; - /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks. - fn task_index(&self) -> u64 { + /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks.' + /// + /// Set to [`None`] for the aggregated `RuntimeTask` type. + fn task_index(&self) -> Option { Self::TASK_INDEX } } From 594f21e60fb62035b04d6682ec637f30e2c53165 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sat, 9 Sep 2023 00:23:05 -0400 Subject: [PATCH 011/177] impls for RuntimeTask is_valid, run, and weight --- Cargo.lock | 23 +++++++++++++ substrate/frame/support/procedural/Cargo.toml | 1 + .../src/construct_runtime/expand/task.rs | 33 ++++++++++--------- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9e089730149..ae09659eaf79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5409,6 +5409,7 @@ dependencies = [ "macro_magic", "proc-macro-warning", "proc-macro2", + "proc-utils", "quote", "syn 2.0.31", ] @@ -13450,6 +13451,28 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proc-util-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45e6073edb3261de7793bbde3002e69e6a4baaa34f5e321e299dd30e3c7489ad" +dependencies = [ + "syn 2.0.31", +] + +[[package]] +name = "proc-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "842fd9aaf81ebd6351f2419bd99dd4dae9d97ae2824243e82c69323df4fd1e6b" +dependencies = [ + "prettyplease 0.2.12", + "proc-macro2", + "proc-util-macros", + "quote", + "syn 2.0.31", +] + [[package]] name = "prometheus" version = "0.13.3" diff --git a/substrate/frame/support/procedural/Cargo.toml b/substrate/frame/support/procedural/Cargo.toml index 9ca86b9fccb1..c82c39a7f00e 100644 --- a/substrate/frame/support/procedural/Cargo.toml +++ b/substrate/frame/support/procedural/Cargo.toml @@ -26,6 +26,7 @@ frame-support-procedural-tools = { path = "tools" } proc-macro-warning = { version = "0.4.2", default-features = false } macro_magic = { version = "0.4.2", features = ["proc_support"] } expander = "2.0.0" +proc-utils = "0" [features] default = [ "std" ] diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 570497a471ae..b4b54e698b0b 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -17,12 +17,14 @@ use crate::construct_runtime::Pallet; use proc_macro2::TokenStream as TokenStream2; +use proc_utils::*; use quote::quote; /// Expands aggregate `RuntimeTask` enum. pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> TokenStream2 { let mut from_impls = Vec::new(); let mut task_variants = Vec::new(); + let mut variant_names = Vec::new(); for decl in pallet_decls { if let Some(_) = decl.find_part("Task") { let variant_name = &decl.name; @@ -44,22 +46,14 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke #[codec(index = #index)] #variant_name(#path::pallet::Task), }); + + variant_names.push(quote!(#variant_name)); } } - use quote::ToTokens; - if !task_variants.is_empty() { - println!( - "{:#?}", - task_variants - .iter() - .map(|item| item.to_token_stream().to_string()) - .collect::>() - ); - } let prelude = quote!(#scrate::traits::tasks::prelude); - quote! { + let output = quote! { /// An aggregation of all `Task` enums across all pallets included in the current runtime. #[derive( Clone, Eq, PartialEq, @@ -78,19 +72,26 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke const TASK_INDEX: Option = None; fn is_valid(&self) -> bool { - use #prelude::*; - todo!(); + match self { + #(#variant_names(val) => val.is_valid()),* + } } fn run(&self) -> Result<(), #scrate::traits::tasks::prelude::DispatchError> { - todo!(); + match self { + #(#variant_names(val) => val.run()),* + } } fn weight(&self) -> #scrate::pallet_prelude::Weight { - todo!(); + match self { + #(#variant_names(val) => val.weight()),* + } } } #( #from_impls )* - } + }; + output.pretty_print(); + output } From d380b4f83df063c904a82670fb7619dacc5e6daf Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 11 Sep 2023 01:46:02 -0400 Subject: [PATCH 012/177] WIP --- substrate/frame/support/src/traits/tasks.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index 2039f2202e5e..e701bfc18e0e 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -34,7 +34,8 @@ use prelude::*; /// off-chain worker) including methods for enumerating, validating, indexing, and running /// tasks of this type. pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { - type Enumeration: Iterator; + /// An [`Iterator`] over tasks of this type used as the return type for `enumerate`. + type Enumeration: Iterator; /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks. /// From 42d85ab6dbed28a97849cdc702f570feb26bce7b Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 11 Sep 2023 13:16:48 -0400 Subject: [PATCH 013/177] collective enumerate working, some unrelated compile issue still --- .../procedural/src/construct_runtime/expand/task.rs | 11 ++++++++++- substrate/frame/support/src/traits/tasks.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index b4b54e698b0b..e01ceaa81dbb 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -25,6 +25,7 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke let mut from_impls = Vec::new(); let mut task_variants = Vec::new(); let mut variant_names = Vec::new(); + let mut task_paths = Vec::new(); for decl in pallet_decls { if let Some(_) = decl.find_part("Task") { let variant_name = &decl.name; @@ -48,6 +49,8 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke }); variant_names.push(quote!(#variant_name)); + + task_paths.push(quote!(#path::pallet::Task)); } } @@ -67,7 +70,7 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke } impl #scrate::traits::Task for RuntimeTask { - type Enumeration = #prelude::IntoIter<#scrate::traits::Task>; + type Enumeration = #prelude::IntoIter; const TASK_INDEX: Option = None; @@ -88,6 +91,12 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke #(#variant_names(val) => val.weight()),* } } + + fn enumerate() -> Self::Enumeration { + let mut all_tasks = Vec::new(); + #(all_tasks.extend(#task_paths::enumerate().map(RuntimeTask::from).collect::>());)* + all_tasks.into_iter() + } } #( #from_impls )* diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index e701bfc18e0e..4e99840bf790 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -24,7 +24,7 @@ pub mod prelude { pub use codec::FullCodec; pub use scale_info::TypeInfo; pub use sp_runtime::DispatchError; - pub use sp_std::{fmt::Debug, iter::Iterator, vec::IntoIter}; + pub use sp_std::{fmt::Debug, iter::Iterator, vec, vec::IntoIter}; pub use sp_weights::Weight; } From 082249804d528c308fbfcd8263a0ff329667cd1c Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 11 Sep 2023 13:57:15 -0400 Subject: [PATCH 014/177] update syn in lockfile --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3556971263e9..523db9865d87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13392,7 +13392,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45e6073edb3261de7793bbde3002e69e6a4baaa34f5e321e299dd30e3c7489ad" dependencies = [ - "syn 2.0.31", + "syn 2.0.32", ] [[package]] @@ -13405,7 +13405,7 @@ dependencies = [ "proc-macro2", "proc-util-macros", "quote", - "syn 2.0.31", + "syn 2.0.32", ] [[package]] From aa964feea6fd48ac70600729f9d897029114bd7e Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 11 Sep 2023 21:46:33 +0200 Subject: [PATCH 015/177] indeed --- .../support/procedural/src/construct_runtime/expand/task.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index e01ceaa81dbb..4e177e2d1b59 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -76,19 +76,19 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke fn is_valid(&self) -> bool { match self { - #(#variant_names(val) => val.is_valid()),* + #(RuntimeTask::#variant_names(val) => val.is_valid()),* } } fn run(&self) -> Result<(), #scrate::traits::tasks::prelude::DispatchError> { match self { - #(#variant_names(val) => val.run()),* + #(RuntimeTask::#variant_names(val) => val.run()),* } } fn weight(&self) -> #scrate::pallet_prelude::Weight { match self { - #(#variant_names(val) => val.weight()),* + #(RuntimeTask::#variant_names(val) => val.weight()),* } } From f411bd1ebabb12753c85d15a2226966ad6f94f29 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 12 Sep 2023 13:18:14 -0400 Subject: [PATCH 016/177] fix handling of runtimes without any tasks --- .../procedural/src/construct_runtime/expand/task.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 4e177e2d1b59..4c332670528f 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -56,6 +56,9 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke let prelude = quote!(#scrate::traits::tasks::prelude); + const INCOMPLETE_MATCH_QED: &'static str = + "cannot have an instantiated RuntimeTask without some Task variant in the runtime. QED"; + let output = quote! { /// An aggregation of all `Task` enums across all pallets included in the current runtime. #[derive( @@ -76,19 +79,22 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke fn is_valid(&self) -> bool { match self { - #(RuntimeTask::#variant_names(val) => val.is_valid()),* + #(RuntimeTask::#variant_names(val) => val.is_valid(),)* + _ => unreachable!(#INCOMPLETE_MATCH_QED), } } fn run(&self) -> Result<(), #scrate::traits::tasks::prelude::DispatchError> { match self { - #(RuntimeTask::#variant_names(val) => val.run()),* + #(RuntimeTask::#variant_names(val) => val.run(),)* + _ => unreachable!(#INCOMPLETE_MATCH_QED), } } fn weight(&self) -> #scrate::pallet_prelude::Weight { match self { - #(RuntimeTask::#variant_names(val) => val.weight()),* + #(RuntimeTask::#variant_names(val) => val.weight(),)* + _ => unreachable!(#INCOMPLETE_MATCH_QED), } } From 359ea3543e9678694673bb036a560a3aabe05590 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 12 Sep 2023 13:52:29 -0400 Subject: [PATCH 017/177] add remaining missing RuntimeTasks, `cargo test --workspace` green :boom: --- bridges/modules/messages/src/mock.rs | 2 ++ cumulus/pallets/collator-selection/src/mock.rs | 2 ++ cumulus/pallets/dmp-queue/src/lib.rs | 1 + cumulus/pallets/xcmp-queue/src/mock.rs | 2 ++ cumulus/parachain-template/pallets/template/src/mock.rs | 1 + polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs | 2 ++ polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs | 1 + 7 files changed, 11 insertions(+) diff --git a/bridges/modules/messages/src/mock.rs b/bridges/modules/messages/src/mock.rs index aebb7eafa787..0308466edb44 100644 --- a/bridges/modules/messages/src/mock.rs +++ b/bridges/modules/messages/src/mock.rs @@ -97,6 +97,7 @@ impl frame_system::Config for TestRuntime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; @@ -124,6 +125,7 @@ impl pallet_balances::Config for TestRuntime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU64<1>; type AccountStore = frame_system::Pallet; type WeightInfo = (); diff --git a/cumulus/pallets/collator-selection/src/mock.rs b/cumulus/pallets/collator-selection/src/mock.rs index 44d531c971ee..92a382893637 100644 --- a/cumulus/pallets/collator-selection/src/mock.rs +++ b/cumulus/pallets/collator-selection/src/mock.rs @@ -57,6 +57,7 @@ impl system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -84,6 +85,7 @@ parameter_types! { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/pallets/dmp-queue/src/lib.rs b/cumulus/pallets/dmp-queue/src/lib.rs index eff4a625ef1b..7a989233bb7b 100644 --- a/cumulus/pallets/dmp-queue/src/lib.rs +++ b/cumulus/pallets/dmp-queue/src/lib.rs @@ -456,6 +456,7 @@ mod tests { impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/cumulus/pallets/xcmp-queue/src/mock.rs b/cumulus/pallets/xcmp-queue/src/mock.rs index a3f10fa5428c..076fe2571c85 100644 --- a/cumulus/pallets/xcmp-queue/src/mock.rs +++ b/cumulus/pallets/xcmp-queue/src/mock.rs @@ -61,6 +61,7 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; @@ -88,6 +89,7 @@ parameter_types! { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachain-template/pallets/template/src/mock.rs b/cumulus/parachain-template/pallets/template/src/mock.rs index 8fae1019f42d..2e352b22f6e5 100644 --- a/cumulus/parachain-template/pallets/template/src/mock.rs +++ b/cumulus/parachain-template/pallets/template/src/mock.rs @@ -29,6 +29,7 @@ impl system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index f5759afc0646..c20b81cf7d0f 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -54,6 +54,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; @@ -82,6 +83,7 @@ impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index 1b244f316de9..af4fb26948a3 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -59,6 +59,7 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; From 58aec8d9bc5909a7a05f3bf7c9d27d89bbe18682 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 12 Sep 2023 14:58:39 -0400 Subject: [PATCH 018/177] disable debug pretty printing so RA settles --- .../support/procedural/src/construct_runtime/expand/task.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 4c332670528f..a416e7196216 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -17,7 +17,6 @@ use crate::construct_runtime::Pallet; use proc_macro2::TokenStream as TokenStream2; -use proc_utils::*; use quote::quote; /// Expands aggregate `RuntimeTask` enum. @@ -107,6 +106,7 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke #( #from_impls )* }; - output.pretty_print(); + // use proc_utils::*; + // output.pretty_print(); output } From 197c2376e6e686e31b0fc08a0e639a03e5e995c8 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 12 Sep 2023 16:35:54 -0400 Subject: [PATCH 019/177] add minimal mock runtime for tasks-example (not using derive_impl yet) --- .../frame/examples/tasks-example/src/lib.rs | 3 + .../frame/examples/tasks-example/src/mock.rs | 64 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 substrate/frame/examples/tasks-example/src/mock.rs diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index fd95f36e5776..dbb11ff89a9b 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -25,6 +25,9 @@ use frame_support::dispatch::DispatchResult; pub use pallet::*; use sp_runtime::DispatchError; +#[cfg(test)] +pub mod mock; + #[frame_support::pallet(dev_mode)] pub mod pallet { diff --git a/substrate/frame/examples/tasks-example/src/mock.rs b/substrate/frame/examples/tasks-example/src/mock.rs new file mode 100644 index 000000000000..3fb0b2453a7d --- /dev/null +++ b/substrate/frame/examples/tasks-example/src/mock.rs @@ -0,0 +1,64 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Mock runtime for tasks-example tests. + +use crate::{self as tasks_example}; + +pub type AccountId = u32; +pub type Balance = u32; + +type Block = frame_system::mocking::MockBlock; +frame_support::construct_runtime!( + pub struct Runtime + { + System: frame_system::{Pallet, Call, Storage, Event, Config}, + TasksExample: tasks_example::{Pallet, Call, Storage, Event, Task}, + } +); + +impl frame_system::Config for Runtime { + type SS58Prefix = (); + type BaseCallFilter = frame_support::traits::Everything; + type RuntimeOrigin = RuntimeOrigin; + type Nonce = u64; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Hash = sp_core::H256; + type Hashing = sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = sp_runtime::traits::IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = (); + type DbWeight = (); + type BlockLength = (); + type BlockWeights = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = (); + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +impl tasks_example::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; +} From a97c7a0f2545a15e8fa294dc0a27f39824c2b545 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 12 Sep 2023 16:38:49 -0400 Subject: [PATCH 020/177] add TODO for using derive_impl --- substrate/frame/examples/tasks-example/src/mock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/examples/tasks-example/src/mock.rs b/substrate/frame/examples/tasks-example/src/mock.rs index 3fb0b2453a7d..4df1f9c6612d 100644 --- a/substrate/frame/examples/tasks-example/src/mock.rs +++ b/substrate/frame/examples/tasks-example/src/mock.rs @@ -31,6 +31,7 @@ frame_support::construct_runtime!( } ); +// TODO: use derive_impl impl frame_system::Config for Runtime { type SS58Prefix = (); type BaseCallFilter = frame_support::traits::Everything; From bc66b43c52f8f796e27819481fc523591f5fd7b1 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 12 Sep 2023 17:27:34 -0400 Subject: [PATCH 021/177] add working new_test_ext() (but tasks_example stuff not in it?) --- .../frame/examples/tasks-example/src/lib.rs | 4 +-- .../frame/examples/tasks-example/src/mock.rs | 3 +- .../frame/examples/tasks-example/src/tests.rs | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 substrate/frame/examples/tasks-example/src/tests.rs diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index dbb11ff89a9b..f00a40c06646 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -25,8 +25,8 @@ use frame_support::dispatch::DispatchResult; pub use pallet::*; use sp_runtime::DispatchError; -#[cfg(test)] pub mod mock; +pub mod tests; #[frame_support::pallet(dev_mode)] pub mod pallet { @@ -162,7 +162,7 @@ pub mod pallet { } // this will be auto-generated by the macros and will always be the same - pub fn do_task(origin: OriginFor, task: Task) -> DispatchResult { + pub fn do_task(origin: OriginFor, task: crate::pallet::Task) -> DispatchResult { use frame_support::traits::Task; ensure_root(origin)?; if task.is_valid() { diff --git a/substrate/frame/examples/tasks-example/src/mock.rs b/substrate/frame/examples/tasks-example/src/mock.rs index 4df1f9c6612d..56b7581b100d 100644 --- a/substrate/frame/examples/tasks-example/src/mock.rs +++ b/substrate/frame/examples/tasks-example/src/mock.rs @@ -15,7 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Mock runtime for tasks-example tests. +//! Mock runtime for `tasks-example` tests. +#![cfg(test)] use crate::{self as tasks_example}; diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs new file mode 100644 index 000000000000..28d73679ed1f --- /dev/null +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -0,0 +1,33 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Tests for `tasks-example`. +#![cfg(test)] +use crate::mock::*; +use sp_runtime::BuildStorage; + +// This function basically just builds a genesis storage key/value store according to +// our desired mockup. +pub fn new_test_ext() -> sp_io::TestExternalities { + let t = RuntimeGenesisConfig { + // We use default for brevity, but you can configure as desired if needed. + system: Default::default(), + } + .build_storage() + .unwrap(); + t.into() +} From a656faa3279d7f25438f79321c58f7e150440d3e Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 12 Sep 2023 17:51:30 -0400 Subject: [PATCH 022/177] add test for increment/decrement on tasks_example --- substrate/frame/examples/tasks-example/src/lib.rs | 4 ++-- .../frame/examples/tasks-example/src/tests.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index f00a40c06646..6ef812bc45a7 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -143,7 +143,7 @@ pub mod pallet { ensure_root(origin)?; // Increment the value and emit an event - let new_val = Value::::get().unwrap().checked_add(1).ok_or("Value overflow")?; + let new_val = Value::::get().unwrap_or(0).checked_add(1).ok_or("Value overflow")?; Value::::put(new_val); Self::deposit_event(Event::Incremented { new_val }); @@ -154,7 +154,7 @@ pub mod pallet { ensure_root(origin)?; // Decrement the value and emit an event - let new_val = Value::::get().unwrap().checked_sub(1).ok_or("Value underflow")?; + let new_val = Value::::get().unwrap_or(0).checked_sub(1).ok_or("Value underflow")?; Value::::put(new_val); Self::deposit_event(Event::Decremented { new_val }); diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs index 28d73679ed1f..cc19b9fa4bd7 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -31,3 +31,17 @@ pub fn new_test_ext() -> sp_io::TestExternalities { .unwrap(); t.into() } + +#[test] +fn incrementing_and_decrementing_works() { + new_test_ext().execute_with(|| { + assert!(TasksExample::decrement(RuntimeOrigin::root()).is_err()); + TasksExample::increment(RuntimeOrigin::root()).unwrap(); + TasksExample::decrement(RuntimeOrigin::root()).unwrap(); + TasksExample::increment(RuntimeOrigin::root()).unwrap(); + TasksExample::increment(RuntimeOrigin::root()).unwrap(); + TasksExample::decrement(RuntimeOrigin::root()).unwrap(); + TasksExample::decrement(RuntimeOrigin::root()).unwrap(); + assert!(TasksExample::decrement(RuntimeOrigin::root()).is_err()); + }); +} From 7d371dfc6691e0d090777583bead1fc5560dee06 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 12 Sep 2023 17:54:44 -0400 Subject: [PATCH 023/177] add coverage for increment overflowing --- substrate/frame/examples/tasks-example/src/tests.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs index cc19b9fa4bd7..fd412bfd355c 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -43,5 +43,9 @@ fn incrementing_and_decrementing_works() { TasksExample::decrement(RuntimeOrigin::root()).unwrap(); TasksExample::decrement(RuntimeOrigin::root()).unwrap(); assert!(TasksExample::decrement(RuntimeOrigin::root()).is_err()); + for _ in 0..255 { + TasksExample::increment(RuntimeOrigin::root()).unwrap(); + } + assert!(TasksExample::increment(RuntimeOrigin::root()).is_err()); }); } From ed735c45d0d6be70855b5646e6109c1e72979d45 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 13 Sep 2023 10:42:01 -0400 Subject: [PATCH 024/177] test task-level enumerate --- substrate/frame/examples/tasks-example/src/tests.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs index fd412bfd355c..65291facd92e 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -18,6 +18,7 @@ //! Tests for `tasks-example`. #![cfg(test)] use crate::mock::*; +use frame_support::traits::Task; use sp_runtime::BuildStorage; // This function basically just builds a genesis storage key/value store according to @@ -49,3 +50,10 @@ fn incrementing_and_decrementing_works() { assert!(TasksExample::increment(RuntimeOrigin::root()).is_err()); }); } + +#[test] +fn task_enumerate_works() { + new_test_ext().execute_with(|| { + assert_eq!(crate::pallet::Task::::enumerate().collect::>().len(), 2); + }); +} From 88430c5d0e27f830045054d7439939dfaea64fea Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 13 Sep 2023 10:45:10 -0400 Subject: [PATCH 025/177] test RuntimeTask-level enumerate --- .../frame/examples/tasks-example/src/tests.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs index 65291facd92e..750e0da62760 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -57,3 +57,27 @@ fn task_enumerate_works() { assert_eq!(crate::pallet::Task::::enumerate().collect::>().len(), 2); }); } + +#[test] +fn runtime_task_enumerate_works_via_frame_system_config() { + new_test_ext().execute_with(|| { + assert_eq!( + ::RuntimeTask::enumerate() + .collect::>() + .len(), + 2 + ); + }); +} + +#[test] +fn runtime_task_enumerate_works_via_pallet_config() { + new_test_ext().execute_with(|| { + assert_eq!( + ::RuntimeTask::enumerate() + .collect::>() + .len(), + 2 + ); + }); +} From 6fd2e1081ae748588bf94e9df3b8f5164ab04c22 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 18 Sep 2023 12:04:26 -0400 Subject: [PATCH 026/177] rename pallet::condition => pallet::task_condition to be consistent --- Cargo.lock | 4 ++-- .../procedural/src/pallet/parse/tasks.rs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a14ddc7cb86..40ac369cf7e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13393,7 +13393,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45e6073edb3261de7793bbde3002e69e6a4baaa34f5e321e299dd30e3c7489ad" dependencies = [ - "syn 2.0.32", + "syn 2.0.33", ] [[package]] @@ -13406,7 +13406,7 @@ dependencies = [ "proc-macro2", "proc-util-macros", "quote", - "syn 2.0.32", + "syn 2.0.33", ] [[package]] diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 23715014585a..074626b40281 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -27,7 +27,7 @@ pub mod keywords { custom_keyword!(tasks); custom_keyword!(task_list); - custom_keyword!(condition); + custom_keyword!(task_condition); custom_keyword!(task_index); custom_keyword!(pallet); } @@ -36,7 +36,6 @@ pub struct TasksDef; impl TasksDef { pub fn try_from(_span: Span, _index: usize, _item: &mut Item) -> Result { - // TODO: fill in Ok(TasksDef {}) } } @@ -59,9 +58,9 @@ pub enum TaskAttrType { #[inside(_paren)] index: LitInt, }, - #[peek(keywords::condition, name = "#[pallet::condition(..)")] + #[peek(keywords::task_condition, name = "#[pallet::task_condition(..)")] Condition { - _condition: keywords::condition, + _condition: keywords::task_condition, #[paren] _paren: Paren, #[inside(_paren)] @@ -113,9 +112,9 @@ fn test_parse_pallet_task_index() { } #[test] -fn test_parse_pallet_condition() { - parse2::(quote!(#[pallet::condition(|x| x.is_some())])).unwrap(); - parse2::(quote!(#[pallet::condition(|_x| some_expr())])).unwrap(); - assert!(parse2::(quote!(#[pallet::condition(x.is_some())])).is_err()); - assert!(parse2::(quote!(#[pallet::condition(|| something())])).is_err()); +fn test_parse_pallet_task_condition() { + parse2::(quote!(#[pallet::task_condition(|x| x.is_some())])).unwrap(); + parse2::(quote!(#[pallet::task_condition(|_x| some_expr())])).unwrap(); + assert!(parse2::(quote!(#[pallet::task_condition(x.is_some())])).is_err()); + assert!(parse2::(quote!(#[pallet::task_condition(|| something())])).is_err()); } From 51c2e2e07c56d14f57b88c9605d7aed571cf7aa4 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 18 Sep 2023 12:28:56 -0400 Subject: [PATCH 027/177] add unit tests for `#[pallet::tasks]` --- .../support/procedural/src/pallet/parse/tasks.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 074626b40281..c7cae71fa37d 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -59,7 +59,7 @@ pub enum TaskAttrType { index: LitInt, }, #[peek(keywords::task_condition, name = "#[pallet::task_condition(..)")] - Condition { + TaskCondition { _condition: keywords::task_condition, #[paren] _paren: Paren, @@ -72,7 +72,8 @@ pub enum TaskAttrType { #[inside(_paren)] expr: Expr, }, - // TODO: Tasks + #[peek(keywords::tasks, name = "#[pallet::tasks]")] + Tasks { _tasks: keywords::tasks }, } #[derive(Parse)] @@ -118,3 +119,11 @@ fn test_parse_pallet_task_condition() { assert!(parse2::(quote!(#[pallet::task_condition(x.is_some())])).is_err()); assert!(parse2::(quote!(#[pallet::task_condition(|| something())])).is_err()); } + +#[test] +fn test_parse_pallet_tasks() { + parse2::(quote!(#[pallet::tasks])).unwrap(); + assert!(parse2::(quote!(#[pallet::taskss])).is_err()); + assert!(parse2::(quote!(#[pallet::tasks_])).is_err()); + assert!(parse2::(quote!(#[pallet::tasks()])).is_err()); +} From ee472eb76a3735c67aca3efd9ade4cece863bff6 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 19 Sep 2023 04:42:18 -0400 Subject: [PATCH 028/177] Parse impl for TaskDef --- .../procedural/src/pallet/parse/tasks.rs | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index c7cae71fa37d..5e0df543655c 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -15,11 +15,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +use core::panic; + use derive_syn_parse::Parse; -use proc_macro2::Span; +use proc_macro2::{Punct, Span, TokenTree}; +use quote::ToTokens; use syn::{ + parse2, token::{Bracket, Paren}, - Expr, Ident, Item, LitInt, Result, Token, + Expr, Ident, ImplItemFn, Item, LitInt, Result, Token, }; pub mod keywords { @@ -40,7 +44,45 @@ impl TasksDef { } } -#[derive(Parse)] +pub struct TaskDef { + task_attrs: Vec, + item: ImplItemFn, +} + +impl syn::parse::Parse for TaskDef { + fn parse(input: syn::parse::ParseStream) -> Result { + let mut item = input.parse::()?; + // we only want to activate TaskAttrType parsing errors for tasks-related attributes, + // so we filter them here + let (task_attrs, normal_attrs) = item.attrs.into_iter().partition(|attr| { + let mut path_tokens = attr.path().to_token_stream().into_iter(); + let ( + Some(TokenTree::Ident(prefix)), + Some(TokenTree::Punct(_)), + Some(TokenTree::Ident(suffix)), + ) = (path_tokens.next(), path_tokens.next(), path_tokens.next()) + else { + return false + }; + // N.B: the `PartialEq` impl between `Ident` and `&str` is more efficient than + // parsing and makes no allocations + prefix == "pallet" && + (suffix == "tasks" || + suffix == "tasks_list" || + suffix == "task_condition" || + suffix == "task_index") + }); + item.attrs = normal_attrs; + let task_attrs: Vec = task_attrs + .into_iter() + .map(|attr| parse2::(attr.to_token_stream())) + .collect::>()?; // Propagate the error if any of the `parse2` calls fail. + + Ok(TaskDef { task_attrs, item }) + } +} + +#[derive(Parse, Debug)] pub enum TaskAttrType { #[peek(keywords::task_list, name = "#[pallet::task_list(..)]")] TaskList { @@ -76,7 +118,7 @@ pub enum TaskAttrType { Tasks { _tasks: keywords::tasks }, } -#[derive(Parse)] +#[derive(Parse, Debug)] pub struct PalletTaskAttr { _pound: Token![#], #[bracket] @@ -89,9 +131,6 @@ pub struct PalletTaskAttr { _attr: TaskAttrType, } -#[cfg(test)] -use syn::parse2; - #[cfg(test)] use quote::quote; @@ -110,6 +149,12 @@ fn test_parse_pallet_task_index() { parse2::(quote!(#[pallet::task_index(17)])).unwrap(); assert!(parse2::(quote!(#[pallet::task_index])).is_err()); assert!(parse2::(quote!(#[pallet::task_index("hey")])).is_err()); + assert_eq!( + parse2::(quote!(#[pallet::task_index("hey")])) + .unwrap_err() + .to_string(), + "expected integer literal" + ); } #[test] From 7beb8ffeb6a5e6a3562871ab8f9640e748e4cf94 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 19 Sep 2023 11:59:08 -0400 Subject: [PATCH 029/177] fix: tasks_list => task_list --- substrate/frame/support/procedural/src/pallet/parse/tasks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 5e0df543655c..dd5fd4ed627a 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -68,7 +68,7 @@ impl syn::parse::Parse for TaskDef { // parsing and makes no allocations prefix == "pallet" && (suffix == "tasks" || - suffix == "tasks_list" || + suffix == "task_list" || suffix == "task_condition" || suffix == "task_index") }); @@ -138,7 +138,7 @@ use quote::quote; fn test_parse_pallet_task_list_() { parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); assert!(parse2::(quote!(#[pallet::task_list()])).is_err()); - assert!(parse2::(quote!(#[pallet::tasks_list(iter())])).is_err()); + assert!(parse2::(quote!(#[pallet::task_list(iter())])).is_err()); assert!(parse2::(quote!(#[pallet::task_list])).is_err()); } From f8fff6d95408693298f0620c351045b34b15c968 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 19 Sep 2023 12:05:31 -0400 Subject: [PATCH 030/177] fix bad test --- .../frame/support/procedural/src/pallet/parse/tasks.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index dd5fd4ed627a..833a2aa8b5d8 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -15,10 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::panic; - use derive_syn_parse::Parse; -use proc_macro2::{Punct, Span, TokenTree}; +use proc_macro2::{Span, TokenTree}; use quote::ToTokens; use syn::{ parse2, @@ -137,8 +135,8 @@ use quote::quote; #[test] fn test_parse_pallet_task_list_() { parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); + parse2::(quote!(#[pallet::task_list(iter())])).unwrap(); assert!(parse2::(quote!(#[pallet::task_list()])).is_err()); - assert!(parse2::(quote!(#[pallet::task_list(iter())])).is_err()); assert!(parse2::(quote!(#[pallet::task_list])).is_err()); } From d2b8b470bfa2a90a455832c8fa0186e1456dfb3f Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 19 Sep 2023 12:55:50 -0400 Subject: [PATCH 031/177] experimental macro for testing parsing errors with patterns --- Cargo.lock | 1 + substrate/frame/support/procedural/Cargo.toml | 3 + .../procedural/src/pallet/parse/tasks.rs | 61 +++++++++++++++---- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40ac369cf7e8..cc5a44101d31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5360,6 +5360,7 @@ dependencies = [ "proc-macro2", "proc-utils", "quote", + "regex", "syn 2.0.33", ] diff --git a/substrate/frame/support/procedural/Cargo.toml b/substrate/frame/support/procedural/Cargo.toml index 2b88fcf3a815..e6329c5096ff 100644 --- a/substrate/frame/support/procedural/Cargo.toml +++ b/substrate/frame/support/procedural/Cargo.toml @@ -28,6 +28,9 @@ macro_magic = { version = "0.4.2", features = ["proc_support"] } expander = "2.0.0" proc-utils = "0" +[dev-dependencies] +regex = "1" + [features] default = [ "std" ] std = [] diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 833a2aa8b5d8..cb23ed4471a5 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -24,6 +24,25 @@ use syn::{ Expr, Ident, ImplItemFn, Item, LitInt, Result, Token, }; +#[cfg(test)] +macro_rules! assert_error_matches { + ($expr:expr, $reg:literal) => { + match $expr { + Ok(_) => panic!("Expected an `Error(..)`, but got Ok(..)"), + Err(e) => { + let error_message = e.to_string(); + let re = regex::Regex::new($reg).expect("Invalid regex pattern"); + assert!( + re.is_match(&error_message), + "Error message \"{}\" does not match the pattern \"{}\"", + error_message, + $reg + ); + }, + } + }; +} + pub mod keywords { use syn::custom_keyword; @@ -136,8 +155,14 @@ use quote::quote; fn test_parse_pallet_task_list_() { parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); parse2::(quote!(#[pallet::task_list(iter())])).unwrap(); - assert!(parse2::(quote!(#[pallet::task_list()])).is_err()); - assert!(parse2::(quote!(#[pallet::task_list])).is_err()); + assert_error_matches!( + parse2::(quote!(#[pallet::task_list()])), + "expected an expression" + ); + assert_error_matches!( + parse2::(quote!(#[pallet::task_list])), + "expected parentheses" + ); } #[test] @@ -145,12 +170,16 @@ fn test_parse_pallet_task_index() { parse2::(quote!(#[pallet::task_index(3)])).unwrap(); parse2::(quote!(#[pallet::task_index(0)])).unwrap(); parse2::(quote!(#[pallet::task_index(17)])).unwrap(); - assert!(parse2::(quote!(#[pallet::task_index])).is_err()); - assert!(parse2::(quote!(#[pallet::task_index("hey")])).is_err()); - assert_eq!( - parse2::(quote!(#[pallet::task_index("hey")])) - .unwrap_err() - .to_string(), + assert_error_matches!( + parse2::(quote!(#[pallet::task_index])), + "expected parentheses" + ); + assert_error_matches!( + parse2::(quote!(#[pallet::task_index("hey")])), + "expected integer literal" + ); + assert_error_matches!( + parse2::(quote!(#[pallet::task_index(0.3)])), "expected integer literal" ); } @@ -159,14 +188,20 @@ fn test_parse_pallet_task_index() { fn test_parse_pallet_task_condition() { parse2::(quote!(#[pallet::task_condition(|x| x.is_some())])).unwrap(); parse2::(quote!(#[pallet::task_condition(|_x| some_expr())])).unwrap(); - assert!(parse2::(quote!(#[pallet::task_condition(x.is_some())])).is_err()); - assert!(parse2::(quote!(#[pallet::task_condition(|| something())])).is_err()); + assert_error_matches!( + parse2::(quote!(#[pallet::task_condition(x.is_some())])), + "expected `|`" + ); + assert_error_matches!( + parse2::(quote!(#[pallet::task_condition(|| something())])), + "expected identifier" + ); } #[test] fn test_parse_pallet_tasks() { parse2::(quote!(#[pallet::tasks])).unwrap(); - assert!(parse2::(quote!(#[pallet::taskss])).is_err()); - assert!(parse2::(quote!(#[pallet::tasks_])).is_err()); - assert!(parse2::(quote!(#[pallet::tasks()])).is_err()); + assert_error_matches!(parse2::(quote!(#[pallet::taskss])), "expected one of"); + assert_error_matches!(parse2::(quote!(#[pallet::tasks_])), "expected one of"); + assert_error_matches!(parse2::(quote!(#[pallet::tasks()])), "unexpected token"); } From abca627ef0fea4b3c5b6f63ab572c28a14fcd7a2 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 19 Sep 2023 15:31:27 -0400 Subject: [PATCH 032/177] clean up --- substrate/frame/support/procedural/src/pallet/parse/tasks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index cb23ed4471a5..1e4206ac6540 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -93,7 +93,7 @@ impl syn::parse::Parse for TaskDef { let task_attrs: Vec = task_attrs .into_iter() .map(|attr| parse2::(attr.to_token_stream())) - .collect::>()?; // Propagate the error if any of the `parse2` calls fail. + .collect::>()?; Ok(TaskDef { task_attrs, item }) } From cd4b90a41bc7bbe54dd4fa49354ab138a4d9280e Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 20 Sep 2023 14:12:21 -0400 Subject: [PATCH 033/177] fix comment --- substrate/frame/support/procedural/src/pallet/parse/tasks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 1e4206ac6540..24d72d7f7179 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -82,7 +82,7 @@ impl syn::parse::Parse for TaskDef { return false }; // N.B: the `PartialEq` impl between `Ident` and `&str` is more efficient than - // parsing and makes no allocations + // parsing and makes no stack or heap allocations prefix == "pallet" && (suffix == "tasks" || suffix == "task_list" || From 1a75ac3f984f10fa07b5779bf0be9d3c3e838ed1 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 21 Sep 2023 13:28:48 -0400 Subject: [PATCH 034/177] scaffold for tasks expansion --- .../frame/support/procedural/src/pallet/expand/mod.rs | 3 +++ .../frame/support/procedural/src/pallet/expand/tasks.rs | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 substrate/frame/support/procedural/src/pallet/expand/tasks.rs diff --git a/substrate/frame/support/procedural/src/pallet/expand/mod.rs b/substrate/frame/support/procedural/src/pallet/expand/mod.rs index 2b998227c1d8..cbc08a9158e5 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/mod.rs @@ -31,6 +31,7 @@ mod origin; mod pallet_struct; mod storage; mod store_trait; +mod tasks; mod tt_default_parts; mod type_value; mod validate_unsigned; @@ -59,6 +60,7 @@ pub fn expand(mut def: Def) -> proc_macro2::TokenStream { let pallet_struct = pallet_struct::expand_pallet_struct(&mut def); let config = config::expand_config(&mut def); let call = call::expand_call(&mut def); + let tasks = tasks::expand_tasks(&mut def); let error = error::expand_error(&mut def); let event = event::expand_event(&mut def); let storages = storage::expand_storages(&mut def); @@ -99,6 +101,7 @@ storage item. Otherwise, all storage items are listed among [*Type Definitions*] #pallet_struct #config #call + #tasks #error #event #storages diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs new file mode 100644 index 000000000000..2b743a460cef --- /dev/null +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -0,0 +1,7 @@ +use crate::pallet::Def; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +pub fn expand_tasks(_def: &mut Def) -> TokenStream2 { + quote!() +} From d781b73438fca92142e0960e9417b4cb2be0ec86 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 21 Sep 2023 16:05:35 -0400 Subject: [PATCH 035/177] add parsing for `TasksDef`, gav's example syntax now parses :boom: --- .../procedural/src/pallet/parse/tasks.rs | 126 ++++++++++++++---- 1 file changed, 99 insertions(+), 27 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 24d72d7f7179..bdd707af5ef6 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -16,12 +16,14 @@ // limitations under the License. use derive_syn_parse::Parse; -use proc_macro2::{Span, TokenTree}; +use proc_macro2::Span; use quote::ToTokens; use syn::{ + parse::ParseStream, parse2, + spanned::Spanned, token::{Bracket, Paren}, - Expr, Ident, ImplItemFn, Item, LitInt, Result, Token, + Attribute, Error, Expr, Ident, ImplItemFn, Item, ItemImpl, LitInt, Result, Token, }; #[cfg(test)] @@ -53,46 +55,91 @@ pub mod keywords { custom_keyword!(pallet); } -pub struct TasksDef; +pub struct TasksDef { + normal_attrs: Vec, + tasks_attr: PalletTasksAttr, + tasks: Vec, +} + +impl syn::parse::Parse for TasksDef { + fn parse(input: ParseStream) -> Result { + let item_impl: ItemImpl = input.parse()?; + let (tasks_attrs, normal_attrs): (Vec<_>, Vec<_>) = + item_impl.attrs.into_iter().partition(|attr| { + let mut path_segs = attr.path().segments.iter(); + let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { + return false + }; + prefix.ident == "pallet" && suffix.ident == "tasks" + }); + let Some(tasks_attr) = tasks_attrs.first() else { + return Err(Error::new( + item_impl.impl_token.span(), + "expected `#[pallet::tasks]` attribute", + )) + }; + if let Some(extra_tasks_attr) = tasks_attrs.get(1) { + return Err(Error::new( + extra_tasks_attr.span(), + "unexpected extra `#[pallet::tasks]` attribute", + )) + } + let tasks_attr = parse2::(tasks_attr.to_token_stream())?; + let tasks: Vec = item_impl + .items + .into_iter() + .map(|item| parse2::(item.to_token_stream())) + .collect::>()?; + Ok(TasksDef { normal_attrs, tasks_attr, tasks }) + } +} impl TasksDef { pub fn try_from(_span: Span, _index: usize, _item: &mut Item) -> Result { - Ok(TasksDef {}) + todo!() } } +#[derive(Parse, Debug)] +pub struct PalletTasksAttr { + _pound: Token![#], + #[bracket] + _bracket: Bracket, + #[inside(_bracket)] + _pallet: keywords::pallet, + #[inside(_bracket)] + _colons: Token![::], + #[inside(_bracket)] + _attr: keywords::tasks, +} + pub struct TaskDef { - task_attrs: Vec, + task_attrs: Vec, item: ImplItemFn, } impl syn::parse::Parse for TaskDef { - fn parse(input: syn::parse::ParseStream) -> Result { + fn parse(input: ParseStream) -> Result { let mut item = input.parse::()?; // we only want to activate TaskAttrType parsing errors for tasks-related attributes, // so we filter them here let (task_attrs, normal_attrs) = item.attrs.into_iter().partition(|attr| { - let mut path_tokens = attr.path().to_token_stream().into_iter(); - let ( - Some(TokenTree::Ident(prefix)), - Some(TokenTree::Punct(_)), - Some(TokenTree::Ident(suffix)), - ) = (path_tokens.next(), path_tokens.next(), path_tokens.next()) - else { + let mut path_segs = attr.path().segments.iter(); + let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { return false }; // N.B: the `PartialEq` impl between `Ident` and `&str` is more efficient than // parsing and makes no stack or heap allocations - prefix == "pallet" && - (suffix == "tasks" || - suffix == "task_list" || - suffix == "task_condition" || - suffix == "task_index") + prefix.ident == "pallet" && + (suffix.ident == "tasks" || + suffix.ident == "task_list" || + suffix.ident == "task_condition" || + suffix.ident == "task_index") }); item.attrs = normal_attrs; - let task_attrs: Vec = task_attrs + let task_attrs: Vec = task_attrs .into_iter() - .map(|attr| parse2::(attr.to_token_stream())) + .map(|attr| parse2(attr.to_token_stream())) .collect::>()?; Ok(TaskDef { task_attrs, item }) @@ -131,8 +178,6 @@ pub enum TaskAttrType { #[inside(_paren)] expr: Expr, }, - #[peek(keywords::tasks, name = "#[pallet::tasks]")] - Tasks { _tasks: keywords::tasks }, } #[derive(Parse, Debug)] @@ -154,6 +199,7 @@ use quote::quote; #[test] fn test_parse_pallet_task_list_() { parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); + parse2::(quote!(#[pallet::task_list(Numbers::::iter_keys())])).unwrap(); parse2::(quote!(#[pallet::task_list(iter())])).unwrap(); assert_error_matches!( parse2::(quote!(#[pallet::task_list()])), @@ -199,9 +245,35 @@ fn test_parse_pallet_task_condition() { } #[test] -fn test_parse_pallet_tasks() { - parse2::(quote!(#[pallet::tasks])).unwrap(); - assert_error_matches!(parse2::(quote!(#[pallet::taskss])), "expected one of"); - assert_error_matches!(parse2::(quote!(#[pallet::tasks_])), "expected one of"); - assert_error_matches!(parse2::(quote!(#[pallet::tasks()])), "unexpected token"); +fn test_parse_pallet_tasks_attr() { + parse2::(quote!(#[pallet::tasks])).unwrap(); + assert_error_matches!(parse2::(quote!(#[pallet::taskss])), "expected `tasks`"); + assert_error_matches!(parse2::(quote!(#[pallet::tasks_])), "expected `tasks`"); + assert_error_matches!(parse2::(quote!(#[pal::tasks])), "expected `pallet`"); + assert_error_matches!( + parse2::(quote!(#[pallet::tasks()])), + "unexpected token" + ); +} + +#[test] +fn test_parse_tasks_def_basic() { + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + /// Add a pair of numbers into the totals and remove them. + #[pallet::task_list(Numbers::::iter_keys())] + #[pallet::task_condition(|i| Numbers::::contains_key(i))] + #[pallet::task_index(0)] + pub fn add_number_into_total(i: u32) -> DispatchResult { + let v = Numbers::::take(i).ok_or(Error::::NotFound)?; + Total::::mutate(|(total_keys, total_values)| { + *total_keys += i; + *total_values += v; + }); + Ok(()) + } + } + }) + .unwrap(); } From cb0b0f8f031a3c0c80e88a341234f7e87f617c53 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 22 Sep 2023 10:13:54 -0400 Subject: [PATCH 036/177] rename TaskAttrType => TaskAttrMeta --- substrate/frame/support/procedural/src/pallet/parse/tasks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index bdd707af5ef6..996e423994a7 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -147,7 +147,7 @@ impl syn::parse::Parse for TaskDef { } #[derive(Parse, Debug)] -pub enum TaskAttrType { +pub enum TaskAttrMeta { #[peek(keywords::task_list, name = "#[pallet::task_list(..)]")] TaskList { _tasks: keywords::task_list, @@ -190,7 +190,7 @@ pub struct PalletTaskAttr { #[inside(_bracket)] _colons: Token![::], #[inside(_bracket)] - _attr: TaskAttrType, + _attr: TaskAttrMeta, } #[cfg(test)] From d3cc4d2863cf52c60ffcd5b239135b0c4c62a3c1 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 22 Sep 2023 10:20:41 -0400 Subject: [PATCH 037/177] refactor TaskAttrMeta to use explicit instantiable struct variants --- .../procedural/src/pallet/parse/tasks.rs | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 996e423994a7..772cb00fa559 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -149,35 +149,44 @@ impl syn::parse::Parse for TaskDef { #[derive(Parse, Debug)] pub enum TaskAttrMeta { #[peek(keywords::task_list, name = "#[pallet::task_list(..)]")] - TaskList { - _tasks: keywords::task_list, - #[paren] - _paren: Paren, - #[inside(_paren)] - expr: Expr, - }, + TaskList(TaskListAttrMeta), #[peek(keywords::task_index, name = "#[pallet::task_index(..)")] - TaskIndex { - _task_index: keywords::task_index, - #[paren] - _paren: Paren, - #[inside(_paren)] - index: LitInt, - }, + TaskIndex(TaskIndexAttrMeta), #[peek(keywords::task_condition, name = "#[pallet::task_condition(..)")] - TaskCondition { - _condition: keywords::task_condition, - #[paren] - _paren: Paren, - #[inside(_paren)] - _pipe1: Token![|], - #[inside(_paren)] - _ident: Ident, - #[inside(_paren)] - _pipe2: Token![|], - #[inside(_paren)] - expr: Expr, - }, + TaskCondition(TaskConditionAttrMeta), +} + +#[derive(Parse, Debug)] +pub struct TaskListAttrMeta { + _tasks: keywords::task_list, + #[paren] + _paren: Paren, + #[inside(_paren)] + expr: Expr, +} + +#[derive(Parse, Debug)] +pub struct TaskIndexAttrMeta { + _task_index: keywords::task_index, + #[paren] + _paren: Paren, + #[inside(_paren)] + index: LitInt, +} + +#[derive(Parse, Debug)] +pub struct TaskConditionAttrMeta { + _condition: keywords::task_condition, + #[paren] + _paren: Paren, + #[inside(_paren)] + _pipe1: Token![|], + #[inside(_paren)] + _ident: Ident, + #[inside(_paren)] + _pipe2: Token![|], + #[inside(_paren)] + expr: Expr, } #[derive(Parse, Debug)] From e615f67b2626754724cf0b52b0a42775180e0f5c Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 22 Sep 2023 13:05:09 -0400 Subject: [PATCH 038/177] even more generic --- .../procedural/src/pallet/parse/tasks.rs | 66 ++++++++----------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 772cb00fa559..14767bb9b3f3 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -15,6 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::collections::HashSet; + use derive_syn_parse::Parse; use proc_macro2::Span; use quote::ToTokens; @@ -22,7 +24,7 @@ use syn::{ parse::ParseStream, parse2, spanned::Spanned, - token::{Bracket, Paren}, + token::{Brace, Bracket, Paren, PathSep, Pound}, Attribute, Error, Expr, Ident, ImplItemFn, Item, ItemImpl, LitInt, Result, Token, }; @@ -90,6 +92,8 @@ impl syn::parse::Parse for TasksDef { .into_iter() .map(|item| parse2::(item.to_token_stream())) .collect::>()?; + let mut task_indices = HashSet::::new(); + //for task in tasks {} Ok(TasksDef { normal_attrs, tasks_attr, tasks }) } } @@ -100,21 +104,10 @@ impl TasksDef { } } -#[derive(Parse, Debug)] -pub struct PalletTasksAttr { - _pound: Token![#], - #[bracket] - _bracket: Bracket, - #[inside(_bracket)] - _pallet: keywords::pallet, - #[inside(_bracket)] - _colons: Token![::], - #[inside(_bracket)] - _attr: keywords::tasks, -} +pub type PalletTasksAttr = PalletTaskAttr; pub struct TaskDef { - task_attrs: Vec, + task_attrs: Vec>, item: ImplItemFn, } @@ -137,7 +130,7 @@ impl syn::parse::Parse for TaskDef { suffix.ident == "task_index") }); item.attrs = normal_attrs; - let task_attrs: Vec = task_attrs + let task_attrs: Vec = task_attrs .into_iter() .map(|attr| parse2(attr.to_token_stream())) .collect::>()?; @@ -190,65 +183,64 @@ pub struct TaskConditionAttrMeta { } #[derive(Parse, Debug)] -pub struct PalletTaskAttr { - _pound: Token![#], +pub struct PalletTaskAttr { + _pound: Pound, #[bracket] _bracket: Bracket, #[inside(_bracket)] _pallet: keywords::pallet, #[inside(_bracket)] - _colons: Token![::], + _colons: PathSep, #[inside(_bracket)] - _attr: TaskAttrMeta, + attr: T, } +pub type TaskAttr = PalletTaskAttr; + #[cfg(test)] use quote::quote; #[test] fn test_parse_pallet_task_list_() { - parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); - parse2::(quote!(#[pallet::task_list(Numbers::::iter_keys())])).unwrap(); - parse2::(quote!(#[pallet::task_list(iter())])).unwrap(); + parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); + parse2::(quote!(#[pallet::task_list(Numbers::::iter_keys())])).unwrap(); + parse2::(quote!(#[pallet::task_list(iter())])).unwrap(); assert_error_matches!( - parse2::(quote!(#[pallet::task_list()])), + parse2::(quote!(#[pallet::task_list()])), "expected an expression" ); - assert_error_matches!( - parse2::(quote!(#[pallet::task_list])), - "expected parentheses" - ); + assert_error_matches!(parse2::(quote!(#[pallet::task_list])), "expected parentheses"); } #[test] fn test_parse_pallet_task_index() { - parse2::(quote!(#[pallet::task_index(3)])).unwrap(); - parse2::(quote!(#[pallet::task_index(0)])).unwrap(); - parse2::(quote!(#[pallet::task_index(17)])).unwrap(); + parse2::(quote!(#[pallet::task_index(3)])).unwrap(); + parse2::(quote!(#[pallet::task_index(0)])).unwrap(); + parse2::(quote!(#[pallet::task_index(17)])).unwrap(); assert_error_matches!( - parse2::(quote!(#[pallet::task_index])), + parse2::(quote!(#[pallet::task_index])), "expected parentheses" ); assert_error_matches!( - parse2::(quote!(#[pallet::task_index("hey")])), + parse2::(quote!(#[pallet::task_index("hey")])), "expected integer literal" ); assert_error_matches!( - parse2::(quote!(#[pallet::task_index(0.3)])), + parse2::(quote!(#[pallet::task_index(0.3)])), "expected integer literal" ); } #[test] fn test_parse_pallet_task_condition() { - parse2::(quote!(#[pallet::task_condition(|x| x.is_some())])).unwrap(); - parse2::(quote!(#[pallet::task_condition(|_x| some_expr())])).unwrap(); + parse2::(quote!(#[pallet::task_condition(|x| x.is_some())])).unwrap(); + parse2::(quote!(#[pallet::task_condition(|_x| some_expr())])).unwrap(); assert_error_matches!( - parse2::(quote!(#[pallet::task_condition(x.is_some())])), + parse2::(quote!(#[pallet::task_condition(x.is_some())])), "expected `|`" ); assert_error_matches!( - parse2::(quote!(#[pallet::task_condition(|| something())])), + parse2::(quote!(#[pallet::task_condition(|| something())])), "expected identifier" ); } From fbae809eb851e2481cb6699f4d16e058fb125f8a Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 22 Sep 2023 14:42:03 -0400 Subject: [PATCH 039/177] refactor + detection of duplicate task indices working :boom: --- .../procedural/src/pallet/parse/tasks.rs | 231 ++++++++++++++---- 1 file changed, 190 insertions(+), 41 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 14767bb9b3f3..79d6efa3322b 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -18,13 +18,13 @@ use std::collections::HashSet; use derive_syn_parse::Parse; -use proc_macro2::Span; -use quote::ToTokens; +use proc_macro2::{Span, TokenStream as TokenStream2}; +use quote::{quote, ToTokens}; use syn::{ parse::ParseStream, parse2, spanned::Spanned, - token::{Brace, Bracket, Paren, PathSep, Pound}, + token::{Bracket, Paren, PathSep, Pound}, Attribute, Error, Expr, Ident, ImplItemFn, Item, ItemImpl, LitInt, Result, Token, }; @@ -93,7 +93,15 @@ impl syn::parse::Parse for TasksDef { .map(|item| parse2::(item.to_token_stream())) .collect::>()?; let mut task_indices = HashSet::::new(); - //for task in tasks {} + for task in tasks.iter() { + let task_index = &task.index_attr.meta.index; + if !task_indices.insert(task_index.clone()) { + return Err(Error::new( + task_index.span(), + format!("duplicate task index `{}`", task_index), + )) + } + } Ok(TasksDef { normal_attrs, tasks_attr, tasks }) } } @@ -105,41 +113,86 @@ impl TasksDef { } pub type PalletTasksAttr = PalletTaskAttr; +pub type TaskAttr = PalletTaskAttr; +pub type TaskIndexAttr = PalletTaskAttr; +pub type TaskConditionAttr = PalletTaskAttr; +pub type TaskListAttr = PalletTaskAttr; +#[derive(Debug, Clone)] pub struct TaskDef { - task_attrs: Vec>, - item: ImplItemFn, + index_attr: TaskIndexAttr, + condition_attr: TaskConditionAttr, + list_attr: TaskListAttr, + normal_attrs: Vec, } impl syn::parse::Parse for TaskDef { fn parse(input: ParseStream) -> Result { - let mut item = input.parse::()?; + let item = input.parse::()?; // we only want to activate TaskAttrType parsing errors for tasks-related attributes, // so we filter them here - let (task_attrs, normal_attrs) = item.attrs.into_iter().partition(|attr| { - let mut path_segs = attr.path().segments.iter(); - let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { - return false - }; - // N.B: the `PartialEq` impl between `Ident` and `&str` is more efficient than - // parsing and makes no stack or heap allocations - prefix.ident == "pallet" && - (suffix.ident == "tasks" || - suffix.ident == "task_list" || - suffix.ident == "task_condition" || - suffix.ident == "task_index") - }); - item.attrs = normal_attrs; + let (task_attrs, normal_attrs): (Vec<_>, Vec<_>) = + item.attrs.into_iter().partition(|attr| { + let mut path_segs = attr.path().segments.iter(); + let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { + return false + }; + // N.B: the `PartialEq` impl between `Ident` and `&str` is more efficient than + // parsing and makes no stack or heap allocations + prefix.ident == "pallet" && + (suffix.ident == "tasks" || + suffix.ident == "task_list" || + suffix.ident == "task_condition" || + suffix.ident == "task_index") + }); + let task_attrs: Vec = task_attrs .into_iter() .map(|attr| parse2(attr.to_token_stream())) .collect::>()?; - Ok(TaskDef { task_attrs, item }) + let Some(index_attr) = task_attrs + .iter() + .find(|attr| matches!(attr.meta, TaskAttrMeta::TaskIndex(_))) + .cloned() + else { + return Err(Error::new( + item.sig.ident.span(), + "missing `#[pallet::task_index(..)]` attribute", + )) + }; + + let Some(condition_attr) = task_attrs + .iter() + .find(|attr| matches!(attr.meta, TaskAttrMeta::TaskCondition(_))) + .cloned() + else { + return Err(Error::new( + item.sig.ident.span(), + "missing `#[pallet::task_index(..)]` attribute", + )) + }; + + let Some(list_attr) = task_attrs + .iter() + .find(|attr| matches!(attr.meta, TaskAttrMeta::TaskList(_))) + .cloned() + else { + return Err(Error::new( + item.sig.ident.span(), + "missing `#[pallet::task_index(..)]` attribute", + )) + }; + + let index_attr = index_attr.try_into().expect("we check the type above; QED"); + let condition_attr = condition_attr.try_into().expect("we check the type above; QED"); + let list_attr = list_attr.try_into().expect("we check the type above; QED"); + + Ok(TaskDef { index_attr, condition_attr, list_attr, normal_attrs }) } } -#[derive(Parse, Debug)] +#[derive(Parse, Debug, Clone)] pub enum TaskAttrMeta { #[peek(keywords::task_list, name = "#[pallet::task_list(..)]")] TaskList(TaskListAttrMeta), @@ -149,56 +202,152 @@ pub enum TaskAttrMeta { TaskCondition(TaskConditionAttrMeta), } -#[derive(Parse, Debug)] +#[derive(Parse, Debug, Clone)] pub struct TaskListAttrMeta { - _tasks: keywords::task_list, + task_list: keywords::task_list, #[paren] _paren: Paren, #[inside(_paren)] expr: Expr, } -#[derive(Parse, Debug)] +#[derive(Parse, Debug, Clone)] pub struct TaskIndexAttrMeta { - _task_index: keywords::task_index, + task_index: keywords::task_index, #[paren] _paren: Paren, #[inside(_paren)] index: LitInt, } -#[derive(Parse, Debug)] +#[derive(Parse, Debug, Clone)] pub struct TaskConditionAttrMeta { - _condition: keywords::task_condition, + task_condition: keywords::task_condition, #[paren] _paren: Paren, #[inside(_paren)] - _pipe1: Token![|], + pipe1: Token![|], #[inside(_paren)] - _ident: Ident, + ident: Ident, #[inside(_paren)] - _pipe2: Token![|], + pipe2: Token![|], #[inside(_paren)] expr: Expr, } -#[derive(Parse, Debug)] -pub struct PalletTaskAttr { - _pound: Pound, +#[derive(Parse, Debug, Clone)] +pub struct PalletTaskAttr { + pound: Pound, #[bracket] _bracket: Bracket, #[inside(_bracket)] - _pallet: keywords::pallet, + pallet: keywords::pallet, #[inside(_bracket)] - _colons: PathSep, + colons: PathSep, #[inside(_bracket)] - attr: T, + meta: T, } -pub type TaskAttr = PalletTaskAttr; +impl ToTokens for TaskListAttrMeta { + fn to_tokens(&self, tokens: &mut TokenStream2) { + let task_list = self.task_list; + let expr = &self.expr; + tokens.extend(quote!(#task_list(#expr))); + } +} -#[cfg(test)] -use quote::quote; +impl ToTokens for TaskConditionAttrMeta { + fn to_tokens(&self, tokens: &mut TokenStream2) { + let task_condition = self.task_condition; + let pipe1 = self.pipe1; + let ident = &self.ident; + let pipe2 = self.pipe2; + let expr = &self.expr; + tokens.extend(quote!(#task_condition(#pipe1 #ident #pipe2 #expr))); + } +} + +impl ToTokens for TaskIndexAttrMeta { + fn to_tokens(&self, tokens: &mut TokenStream2) { + let task_index = self.task_index; + let index = &self.index; + tokens.extend(quote!(#task_index(#index))) + } +} + +impl ToTokens for TaskAttrMeta { + fn to_tokens(&self, tokens: &mut TokenStream2) { + match self { + TaskAttrMeta::TaskList(list) => tokens.extend(list.to_token_stream()), + TaskAttrMeta::TaskIndex(index) => tokens.extend(index.to_token_stream()), + TaskAttrMeta::TaskCondition(condition) => tokens.extend(condition.to_token_stream()), + } + } +} + +impl ToTokens for PalletTaskAttr { + fn to_tokens(&self, tokens: &mut TokenStream2) { + let pound = self.pound; + let pallet = self.pallet; + let colons = self.colons; + let meta = &self.meta; + tokens.extend(quote!(#pound[#pallet #colons #meta])); + } +} + +impl TryFrom> for TaskIndexAttr { + type Error = syn::Error; + + fn try_from(value: PalletTaskAttr) -> Result { + let pound = value.pound; + let pallet = value.pallet; + let colons = value.colons; + match value.meta { + TaskAttrMeta::TaskIndex(meta) => parse2(quote!(#pound[#pallet #colons #meta])), + _ => + return Err(Error::new( + value.span(), + format!("`{:?}` cannot be converted to a `TaskIndexAttr`", value.meta), + )), + } + } +} + +impl TryFrom> for TaskConditionAttr { + type Error = syn::Error; + + fn try_from(value: PalletTaskAttr) -> Result { + let pound = value.pound; + let pallet = value.pallet; + let colons = value.colons; + match value.meta { + TaskAttrMeta::TaskCondition(meta) => parse2(quote!(#pound[#pallet #colons #meta])), + _ => + return Err(Error::new( + value.span(), + format!("`{:?}` cannot be converted to a `TaskConditionAttr`", value.meta), + )), + } + } +} + +impl TryFrom> for TaskListAttr { + type Error = syn::Error; + + fn try_from(value: PalletTaskAttr) -> Result { + let pound = value.pound; + let pallet = value.pallet; + let colons = value.colons; + match value.meta { + TaskAttrMeta::TaskList(meta) => parse2(quote!(#pound[#pallet #colons #meta])), + _ => + return Err(Error::new( + value.span(), + format!("`{:?}` cannot be converted to a `TaskListAttr`", value.meta), + )), + } + } +} #[test] fn test_parse_pallet_task_list_() { From 3e92ef64e6f7a458e9a024d9972118bc31b8cd93 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 12:23:57 -0400 Subject: [PATCH 040/177] test covering duplicate task indices --- .../procedural/src/pallet/parse/tasks.rs | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 79d6efa3322b..42719f7ce399 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -350,7 +350,7 @@ impl TryFrom> for TaskListAttr { } #[test] -fn test_parse_pallet_task_list_() { +fn test_parse_task_list_() { parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); parse2::(quote!(#[pallet::task_list(Numbers::::iter_keys())])).unwrap(); parse2::(quote!(#[pallet::task_list(iter())])).unwrap(); @@ -362,7 +362,7 @@ fn test_parse_pallet_task_list_() { } #[test] -fn test_parse_pallet_task_index() { +fn test_parse_task_index() { parse2::(quote!(#[pallet::task_index(3)])).unwrap(); parse2::(quote!(#[pallet::task_index(0)])).unwrap(); parse2::(quote!(#[pallet::task_index(17)])).unwrap(); @@ -381,7 +381,7 @@ fn test_parse_pallet_task_index() { } #[test] -fn test_parse_pallet_task_condition() { +fn test_parse_task_condition() { parse2::(quote!(#[pallet::task_condition(|x| x.is_some())])).unwrap(); parse2::(quote!(#[pallet::task_condition(|_x| some_expr())])).unwrap(); assert_error_matches!( @@ -395,7 +395,7 @@ fn test_parse_pallet_task_condition() { } #[test] -fn test_parse_pallet_tasks_attr() { +fn test_parse_tasks_attr() { parse2::(quote!(#[pallet::tasks])).unwrap(); assert_error_matches!(parse2::(quote!(#[pallet::taskss])), "expected `tasks`"); assert_error_matches!(parse2::(quote!(#[pallet::tasks_])), "expected `tasks`"); @@ -427,3 +427,28 @@ fn test_parse_tasks_def_basic() { }) .unwrap(); } + +#[test] +fn test_parse_tasks_def_duplicate_index() { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_list(Something::iter())] + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_index(0)] + pub fn bar(i: u32) -> DispatchResult { + Ok(()) + } + + #[pallet::task_list(Numbers::::iter_keys())] + #[pallet::task_condition(|i| Numbers::::contains_key(i))] + #[pallet::task_index(0)] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } + } + }), + "duplicate task index `0`" + ); +} From 008e3d2ad291e0a9f3f75cd30b2a809e01dd1431 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 12:36:28 -0400 Subject: [PATCH 041/177] add test covering missing `#[pallet::task_list(..)]` --- .../procedural/src/pallet/parse/tasks.rs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 42719f7ce399..b55d88505bed 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -169,7 +169,7 @@ impl syn::parse::Parse for TaskDef { else { return Err(Error::new( item.sig.ident.span(), - "missing `#[pallet::task_index(..)]` attribute", + "missing `#[pallet::task_condition(..)]` attribute", )) }; @@ -180,7 +180,7 @@ impl syn::parse::Parse for TaskDef { else { return Err(Error::new( item.sig.ident.span(), - "missing `#[pallet::task_index(..)]` attribute", + "missing `#[pallet::task_list(..)]` attribute", )) }; @@ -437,14 +437,14 @@ fn test_parse_tasks_def_duplicate_index() { #[pallet::task_list(Something::iter())] #[pallet::task_condition(|i| i % 2 == 0)] #[pallet::task_index(0)] - pub fn bar(i: u32) -> DispatchResult { + pub fn foo(i: u32) -> DispatchResult { Ok(()) } #[pallet::task_list(Numbers::::iter_keys())] #[pallet::task_condition(|i| Numbers::::contains_key(i))] #[pallet::task_index(0)] - pub fn foo(i: u32) -> DispatchResult { + pub fn bar(i: u32) -> DispatchResult { Ok(()) } } @@ -452,3 +452,20 @@ fn test_parse_tasks_def_duplicate_index() { "duplicate task index `0`" ); } + +#[test] +fn test_parse_tasks_def_missing_task_list() { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_index(0)] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } + } + }), + r"missing `#\[pallet::task_list\(\.\.\)\]`" + ); +} From c9f17fe00753f5937c61313e9a59351b02878484 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 12:59:30 -0400 Subject: [PATCH 042/177] add test covering missing `#[pallet::task_condition(..)]` --- .../procedural/src/pallet/parse/tasks.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index b55d88505bed..8accde2322e4 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -469,3 +469,20 @@ fn test_parse_tasks_def_missing_task_list() { r"missing `#\[pallet::task_list\(\.\.\)\]`" ); } + +#[test] +fn test_parse_tasks_def_missing_task_condition() { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_list(Something::iter())] + #[pallet::task_index(0)] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } + } + }), + r"missing `#\[pallet::task_condition\(\.\.\)\]`" + ); +} From a7180da31209d05eae6f0a6d66beb012d72341ed Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 13:03:42 -0400 Subject: [PATCH 043/177] add test covering missing `#[pallet::task_index(..)]` --- .../procedural/src/pallet/parse/tasks.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 8accde2322e4..ddb9f873ccb5 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -486,3 +486,20 @@ fn test_parse_tasks_def_missing_task_condition() { r"missing `#\[pallet::task_condition\(\.\.\)\]`" ); } + +#[test] +fn test_parse_tasks_def_missing_task_index() { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_list(Something::iter())] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } + } + }), + r"missing `#\[pallet::task_index\(\.\.\)\]`" + ); +} From 7b7c7f844221fcb4e0264fdf26a722a18542dfbb Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 13:19:31 -0400 Subject: [PATCH 044/177] add compile errors for duplicate tasks attributes + tests --- .../procedural/src/pallet/parse/tasks.rs | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index ddb9f873ccb5..0d9de851f550 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -184,6 +184,42 @@ impl syn::parse::Parse for TaskDef { )) }; + if let Some(duplicate) = task_attrs + .iter() + .filter(|attr| matches!(attr.meta, TaskAttrMeta::TaskCondition(_))) + .collect::>() + .get(1) + { + return Err(Error::new( + duplicate.span(), + "duplicate `#[pallet::task_condition(..)]` attribute", + )) + } + + if let Some(duplicate) = task_attrs + .iter() + .filter(|attr| matches!(attr.meta, TaskAttrMeta::TaskList(_))) + .collect::>() + .get(1) + { + return Err(Error::new( + duplicate.span(), + "duplicate `#[pallet::task_list(..)]` attribute", + )) + } + + if let Some(duplicate) = task_attrs + .iter() + .filter(|attr| matches!(attr.meta, TaskAttrMeta::TaskIndex(_))) + .collect::>() + .get(1) + { + return Err(Error::new( + duplicate.span(), + "duplicate `#[pallet::task_index(..)]` attribute", + )) + } + let index_attr = index_attr.try_into().expect("we check the type above; QED"); let condition_attr = condition_attr.try_into().expect("we check the type above; QED"); let list_attr = list_attr.try_into().expect("we check the type above; QED"); @@ -503,3 +539,60 @@ fn test_parse_tasks_def_missing_task_index() { r"missing `#\[pallet::task_index\(\.\.\)\]`" ); } + +#[test] +fn test_parse_tasks_def_duplicate_task_list_attr() { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_index(0)] + #[pallet::task_list(Something::iter())] + #[pallet::task_list(SomethingElse::iter())] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } + } + }), + r"duplicate `#\[pallet::task_list\(\.\.\)\]`" + ); +} + +#[test] +fn test_parse_tasks_def_duplicate_task_condition_attr() { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_condition(|i| i % 4 == 0)] + #[pallet::task_index(0)] + #[pallet::task_list(Something::iter())] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } + } + }), + r"duplicate `#\[pallet::task_condition\(\.\.\)\]`" + ); +} + +#[test] +fn test_parse_tasks_def_duplicate_task_index_attr() { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_index(0)] + #[pallet::task_index(0)] + #[pallet::task_list(Something::iter())] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } + } + }), + r"duplicate `#\[pallet::task_index\(\.\.\)\]`" + ); +} From 4d4f3f21a7b8fa94d400d73c0920f779535e14a8 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 13:21:45 -0400 Subject: [PATCH 045/177] refactor "duplicate" => "unexpected extra" for consistency --- .../procedural/src/pallet/parse/tasks.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 0d9de851f550..b758d66d7ce4 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -192,7 +192,7 @@ impl syn::parse::Parse for TaskDef { { return Err(Error::new( duplicate.span(), - "duplicate `#[pallet::task_condition(..)]` attribute", + "unexpected extra `#[pallet::task_condition(..)]` attribute", )) } @@ -204,7 +204,7 @@ impl syn::parse::Parse for TaskDef { { return Err(Error::new( duplicate.span(), - "duplicate `#[pallet::task_list(..)]` attribute", + "unexpected extra `#[pallet::task_list(..)]` attribute", )) } @@ -216,7 +216,7 @@ impl syn::parse::Parse for TaskDef { { return Err(Error::new( duplicate.span(), - "duplicate `#[pallet::task_index(..)]` attribute", + "unexpected extra `#[pallet::task_index(..)]` attribute", )) } @@ -541,7 +541,7 @@ fn test_parse_tasks_def_missing_task_index() { } #[test] -fn test_parse_tasks_def_duplicate_task_list_attr() { +fn test_parse_tasks_def_unexpected_extra_task_list_attr() { assert_error_matches!( parse2::(quote! { #[pallet::tasks] @@ -555,12 +555,12 @@ fn test_parse_tasks_def_duplicate_task_list_attr() { } } }), - r"duplicate `#\[pallet::task_list\(\.\.\)\]`" + r"unexpected extra `#\[pallet::task_list\(\.\.\)\]`" ); } #[test] -fn test_parse_tasks_def_duplicate_task_condition_attr() { +fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { assert_error_matches!( parse2::(quote! { #[pallet::tasks] @@ -574,12 +574,12 @@ fn test_parse_tasks_def_duplicate_task_condition_attr() { } } }), - r"duplicate `#\[pallet::task_condition\(\.\.\)\]`" + r"unexpected extra `#\[pallet::task_condition\(\.\.\)\]`" ); } #[test] -fn test_parse_tasks_def_duplicate_task_index_attr() { +fn test_parse_tasks_def_unexpected_extra_task_index_attr() { assert_error_matches!( parse2::(quote! { #[pallet::tasks] @@ -593,6 +593,6 @@ fn test_parse_tasks_def_duplicate_task_index_attr() { } } }), - r"duplicate `#\[pallet::task_index\(\.\.\)\]`" + r"unexpected extra `#\[pallet::task_index\(\.\.\)\]`" ); } From 3520fe310c3d100d174f8f88c1358618d0b3d4d9 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 13:28:31 -0400 Subject: [PATCH 046/177] add test covering extra `#[pallet::tasks]` attribute --- .../support/procedural/src/pallet/parse/tasks.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index b758d66d7ce4..e69ed4a36e0c 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -596,3 +596,15 @@ fn test_parse_tasks_def_unexpected_extra_task_index_attr() { r"unexpected extra `#\[pallet::task_index\(\.\.\)\]`" ); } + +#[test] +fn test_parse_tasks_def_extra_tasks_attribute() { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + #[pallet::tasks] + impl, I: 'static> Pallet {} + }), + r"unexpected extra `#\[pallet::tasks\]` attribute" + ); +} From 6228074101468fc9b317759645144a7a17362be0 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 14:08:59 -0400 Subject: [PATCH 047/177] use proper runtime name in construct_runtime tasks expansion --- .../src/construct_runtime/expand/task.rs | 17 ++++++++++------- .../procedural/src/construct_runtime/mod.rs | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index a416e7196216..5c0b4b1f30fa 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -16,11 +16,15 @@ // limitations under the License use crate::construct_runtime::Pallet; -use proc_macro2::TokenStream as TokenStream2; +use proc_macro2::{Ident, TokenStream as TokenStream2}; use quote::quote; /// Expands aggregate `RuntimeTask` enum. -pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> TokenStream2 { +pub fn expand_outer_task( + runtime_name: &Ident, + pallet_decls: &[Pallet], + scrate: &TokenStream2, +) -> TokenStream2 { let mut from_impls = Vec::new(); let mut task_variants = Vec::new(); let mut variant_names = Vec::new(); @@ -31,12 +35,11 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke let path = &decl.path; let index = decl.index; - // Todo: Replace `Runtime` with the actual runtime ident - // `pallet` will probably not be needed when `Task` is generated by macro + // TODO: `pallet` will probably not be needed when `Task` is generated by macro from_impls.push(quote! { - impl From<#path::pallet::Task> for RuntimeTask { - fn from(hr: #path::pallet::Task) -> Self { + impl From<#path::pallet::Task<#runtime_name>> for RuntimeTask { + fn from(hr: #path::pallet::Task<#runtime_name>) -> Self { RuntimeTask::#variant_name(hr) } } @@ -44,7 +47,7 @@ pub fn expand_outer_task(pallet_decls: &[Pallet], scrate: &TokenStream2) -> Toke task_variants.push(quote! { #[codec(index = #index)] - #variant_name(#path::pallet::Task), + #variant_name(#path::pallet::Task<#runtime_name>), }); variant_names.push(quote!(#variant_name)); diff --git a/substrate/frame/support/procedural/src/construct_runtime/mod.rs b/substrate/frame/support/procedural/src/construct_runtime/mod.rs index 605571381942..dce5ed873076 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/mod.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/mod.rs @@ -385,7 +385,7 @@ fn construct_runtime_final_expansion( let pallet_to_index = decl_pallet_runtime_setup(&name, &pallets, &scrate); let dispatch = expand::expand_outer_dispatch(&name, system_pallet, &pallets, &scrate); - let tasks = expand::expand_outer_task(&pallets, &scrate); + let tasks = expand::expand_outer_task(&name, &pallets, &scrate); let metadata = expand::expand_runtime_metadata( &name, &pallets, From 70da716048af8b4f2ef472a03bbc1fc3809f4288 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 14:32:15 -0400 Subject: [PATCH 048/177] clean up tt_default_parts --- .../support/procedural/src/pallet/expand/tt_default_parts.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs b/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs index 8bac7fc293d8..24ca672c864c 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs @@ -31,13 +31,11 @@ pub fn expand_tt_default_parts(def: &mut Def) -> proc_macro2::TokenStream { let call_part = def.call.as_ref().map(|_| quote::quote!(Call,)); - // TODO: maybe allow `task_enum: Option` to sit on `Def` itself? let task_part = def.item.content.as_ref().and_then(|(_, items)| { items.iter().find_map(|item| { if let syn::Item::Enum(item_enum) = item { if item_enum.ident == "Task" { - println!("found task enum in tt_default_parts!"); - return Some(quote::quote!(Task, )) + return Some(quote::quote!(Task,)) } } None From 872f879c6f6321df8aab4d4daf66a93ace565cb4 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 25 Sep 2023 15:11:36 -0400 Subject: [PATCH 049/177] clean up task enum parse --- substrate/frame/support/procedural/src/pallet/parse/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 44bf12dc19f7..992d298119f7 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -105,7 +105,6 @@ impl Def { // find manually specified `Task` enum, if present if let syn::Item::Enum(item_enum) = item { if item_enum.ident == "Task" { - println!("found task enum while parsing Def!"); task_enum = Some(item_enum.clone()); } } From 51032303bc109ee08e94c5454baf13ba0670caf2 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 26 Sep 2023 10:38:53 -0400 Subject: [PATCH 050/177] rename enumerate() => iter() to fix RA issue --- substrate/frame/examples/tasks-example/src/tests.rs | 6 ++---- .../support/procedural/src/construct_runtime/expand/task.rs | 2 +- .../frame/support/procedural/src/pallet/expand/tasks.rs | 4 ++-- substrate/frame/support/src/traits/tasks.rs | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs index 750e0da62760..5631264ab28d 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -62,9 +62,7 @@ fn task_enumerate_works() { fn runtime_task_enumerate_works_via_frame_system_config() { new_test_ext().execute_with(|| { assert_eq!( - ::RuntimeTask::enumerate() - .collect::>() - .len(), + ::RuntimeTask::iter().collect::>().len(), 2 ); }); @@ -74,7 +72,7 @@ fn runtime_task_enumerate_works_via_frame_system_config() { fn runtime_task_enumerate_works_via_pallet_config() { new_test_ext().execute_with(|| { assert_eq!( - ::RuntimeTask::enumerate() + ::RuntimeTask::iter() .collect::>() .len(), 2 diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 5c0b4b1f30fa..e27f26dd1f3f 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -100,7 +100,7 @@ pub fn expand_outer_task( } } - fn enumerate() -> Self::Enumeration { + fn iter() -> Self::Enumeration { let mut all_tasks = Vec::new(); #(all_tasks.extend(#task_paths::enumerate().map(RuntimeTask::from).collect::>());)* all_tasks.into_iter() diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 2b743a460cef..92f99d63baa8 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -2,6 +2,6 @@ use crate::pallet::Def; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -pub fn expand_tasks(_def: &mut Def) -> TokenStream2 { - quote!() +pub fn expand_tasks(def: &mut Def) -> TokenStream2 { + todo!() } diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index 4e99840bf790..60f11d051932 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -43,7 +43,7 @@ pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { const TASK_INDEX: Option; /// Inspects the pallet's state and enumerates tasks of this type. - fn enumerate() -> Self::Enumeration; + fn iter() -> Self::Enumeration; /// Checks if a particular instance of this `Task` variant is a valid piece of work. fn is_valid(&self) -> bool; From 28a5083e66f3ea026dc6a3113fed01ef5147f109 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 26 Sep 2023 11:34:08 -0400 Subject: [PATCH 051/177] fix identification of Task enum + finish enumerate() => iter() --- substrate/frame/examples/tasks-example/src/lib.rs | 2 +- substrate/frame/examples/tasks-example/src/tests.rs | 2 +- .../procedural/src/construct_runtime/expand/task.rs | 2 +- .../support/procedural/src/pallet/expand/tasks.rs | 2 +- .../procedural/src/pallet/expand/tt_default_parts.rs | 11 +---------- .../frame/support/procedural/src/pallet/parse/mod.rs | 9 ++++++++- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index 6ef812bc45a7..2c027a4683a4 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -73,7 +73,7 @@ pub mod pallet { const TASK_INDEX: Option = Some(0); - fn enumerate() -> Self::Enumeration { + fn iter() -> Self::Enumeration { sp_std::vec![Task::Increment, Task::Decrement].into_iter() } diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs index 5631264ab28d..e364e6fb7657 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -54,7 +54,7 @@ fn incrementing_and_decrementing_works() { #[test] fn task_enumerate_works() { new_test_ext().execute_with(|| { - assert_eq!(crate::pallet::Task::::enumerate().collect::>().len(), 2); + assert_eq!(crate::pallet::Task::::iter().collect::>().len(), 2); }); } diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index e27f26dd1f3f..14bc2f65f8f6 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -102,7 +102,7 @@ pub fn expand_outer_task( fn iter() -> Self::Enumeration { let mut all_tasks = Vec::new(); - #(all_tasks.extend(#task_paths::enumerate().map(RuntimeTask::from).collect::>());)* + #(all_tasks.extend(#task_paths::iter().map(RuntimeTask::from).collect::>());)* all_tasks.into_iter() } } diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 92f99d63baa8..134b1bb8ecbb 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -3,5 +3,5 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; pub fn expand_tasks(def: &mut Def) -> TokenStream2 { - todo!() + quote!() } diff --git a/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs b/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs index 24ca672c864c..7041bf3c4a47 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tt_default_parts.rs @@ -31,16 +31,7 @@ pub fn expand_tt_default_parts(def: &mut Def) -> proc_macro2::TokenStream { let call_part = def.call.as_ref().map(|_| quote::quote!(Call,)); - let task_part = def.item.content.as_ref().and_then(|(_, items)| { - items.iter().find_map(|item| { - if let syn::Item::Enum(item_enum) = item { - if item_enum.ident == "Task" { - return Some(quote::quote!(Task,)) - } - } - None - }) - }); + let task_part = def.task_enum.as_ref().map(|_| quote::quote!(Task,)); let storage_part = (!def.storages.is_empty()).then(|| quote::quote!(Storage,)); diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 992d298119f7..3af3d18d4ea8 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -104,7 +104,14 @@ impl Def { for (index, item) in items.iter_mut().enumerate() { // find manually specified `Task` enum, if present if let syn::Item::Enum(item_enum) = item { - if item_enum.ident == "Task" { + if let Some(_) = item_enum.attrs.iter().find(|attr| { + let segs = attr.path().segments.iter().collect::>(); + let (Some(seg1), Some(seg2), None) = (segs.get(0), segs.get(1), segs.get(2)) + else { + return false + }; + seg1.ident == "pallet" && seg2.ident == "task" + }) { task_enum = Some(item_enum.clone()); } } From f750fccf40bebc175ad27dfb48288785a6eadf24 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 26 Sep 2023 12:00:23 -0400 Subject: [PATCH 052/177] ensure that either both or none of (task_enum, tasks) is specified --- .../frame/support/procedural/src/pallet/parse/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 3af3d18d4ea8..e8fad918fe0e 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -211,6 +211,15 @@ impl Def { return Err(syn::Error::new(item_span, msg)) } + // ensure either both or none of `(task_enum, tasks)` are specified + match (&task_enum, &tasks) { + (Some(_), None) => + return Err(syn::Error::new(item_span, "Missing `#[pallet::tasks]` impl")), + (None, Some(_)) => + return Err(syn::Error::new(item_span, "Missing `#[pallet::task]` enum")), + _ => (), + } + let def = Def { item, config: config From 4793c41bd7e224026ac12e6038e136a730c324fa Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 26 Sep 2023 13:27:43 -0400 Subject: [PATCH 053/177] proper access to tasks enum --- .../procedural/src/pallet/parse/mod.rs | 37 ++++++++++--------- .../procedural/src/pallet/parse/tasks.rs | 16 ++++---- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index e8fad918fe0e..c0f64e5bfa28 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -39,6 +39,7 @@ pub mod validate_unsigned; use composite::{keyword::CompositeKeyword, CompositeDef}; use frame_support_procedural_tools::generate_crate_access_2018; +use quote::ToTokens; use syn::spanned::Spanned; /// Parsed definition of a pallet. @@ -51,7 +52,7 @@ pub struct Def { pub hooks: Option, pub call: Option, pub tasks: Option, - pub task_enum: Option, + pub task_enum: Option, pub storages: Vec, pub error: Option, pub event: Option, @@ -101,20 +102,13 @@ impl Def { let mut type_values = vec![]; let mut composites: Vec = vec![]; + let mut item_tokens: Option = None; + for (index, item) in items.iter_mut().enumerate() { - // find manually specified `Task` enum, if present - if let syn::Item::Enum(item_enum) = item { - if let Some(_) = item_enum.attrs.iter().find(|attr| { - let segs = attr.path().segments.iter().collect::>(); - let (Some(seg1), Some(seg2), None) = (segs.get(0), segs.get(1), segs.get(2)) - else { - return false - }; - seg1.ident == "pallet" && seg2.ident == "task" - }) { - task_enum = Some(item_enum.clone()); - } - } + // provides lazy access to the item's underlying `TokenStream2` + let mut get_tokens = |item: &syn::Item| { + item_tokens.get_or_insert_with(|| item.clone().to_token_stream()).clone() + }; let pallet_attr: Option = helper::take_first_item_pallet_attr(item)?; @@ -137,8 +131,10 @@ impl Def { }, Some(PalletAttr::RuntimeCall(cw, span)) if call.is_none() => call = Some(call::CallDef::try_from(span, index, item, dev_mode, cw)?), - Some(PalletAttr::Tasks(span)) if tasks.is_none() => - tasks = Some(tasks::TasksDef::try_from(span, index, item)?), + Some(PalletAttr::Tasks(_)) if tasks.is_none() => + tasks = Some(syn::parse2::(get_tokens(item))?), + Some(PalletAttr::RuntimeTask(_)) if task_enum.is_none() => + task_enum = Some(syn::parse2::(get_tokens(item))?), Some(PalletAttr::Error(span)) if error.is_none() => error = Some(error::ErrorDef::try_from(span, index, item)?), Some(PalletAttr::RuntimeEvent(span)) if event.is_none() => @@ -441,6 +437,7 @@ mod keyword { syn::custom_keyword!(origin); syn::custom_keyword!(call); syn::custom_keyword!(tasks); + syn::custom_keyword!(task); syn::custom_keyword!(weight); syn::custom_keyword!(event); syn::custom_keyword!(config); @@ -504,8 +501,9 @@ enum PalletAttr { /// to zero. Now when there is a `weight` attribute on the `#[pallet::call]`, then that is used /// instead of the zero weight. So to say: it works together with `dev_mode`. RuntimeCall(Option, proc_macro2::Span), - Tasks(proc_macro2::Span), Error(proc_macro2::Span), + Tasks(proc_macro2::Span), + RuntimeTask(proc_macro2::Span), RuntimeEvent(proc_macro2::Span), RuntimeOrigin(proc_macro2::Span), Inherent(proc_macro2::Span), @@ -524,9 +522,10 @@ impl PalletAttr { Self::Config(span, _) => *span, Self::Pallet(span) => *span, Self::Hooks(span) => *span, - Self::RuntimeCall(_, span) => *span, Self::Tasks(span) => *span, Self::Error(span) => *span, + Self::RuntimeTask(span) => *span, + Self::RuntimeCall(_, span) => *span, Self::RuntimeEvent(span) => *span, Self::RuntimeOrigin(span) => *span, Self::Inherent(span) => *span, @@ -572,6 +571,8 @@ impl syn::parse::Parse for PalletAttr { Ok(PalletAttr::RuntimeCall(attr, span)) } else if lookahead.peek(keyword::tasks) { Ok(PalletAttr::Tasks(content.parse::()?.span())) + } else if lookahead.peek(keyword::task) { + Ok(PalletAttr::RuntimeTask(content.parse::()?.span())) } else if lookahead.peek(keyword::error) { Ok(PalletAttr::Error(content.parse::()?.span())) } else if lookahead.peek(keyword::event) { diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index e69ed4a36e0c..064bc704fd36 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -25,7 +25,7 @@ use syn::{ parse2, spanned::Spanned, token::{Bracket, Paren, PathSep, Pound}, - Attribute, Error, Expr, Ident, ImplItemFn, Item, ItemImpl, LitInt, Result, Token, + Attribute, Error, Expr, Ident, ImplItemFn, Item, ItemEnum, ItemImpl, LitInt, Result, Token, }; #[cfg(test)] @@ -51,6 +51,7 @@ pub mod keywords { use syn::custom_keyword; custom_keyword!(tasks); + custom_keyword!(task); custom_keyword!(task_list); custom_keyword!(task_condition); custom_keyword!(task_index); @@ -106,17 +107,18 @@ impl syn::parse::Parse for TasksDef { } } -impl TasksDef { - pub fn try_from(_span: Span, _index: usize, _item: &mut Item) -> Result { - todo!() - } -} - pub type PalletTasksAttr = PalletTaskAttr; pub type TaskAttr = PalletTaskAttr; pub type TaskIndexAttr = PalletTaskAttr; pub type TaskConditionAttr = PalletTaskAttr; pub type TaskListAttr = PalletTaskAttr; +pub type PalletTaskEnumAttr = PalletTaskAttr; + +#[derive(Parse, Clone, Debug)] +pub struct TaskEnumDef { + attr: PalletTaskEnumAttr, + item_enum: ItemEnum, +} #[derive(Debug, Clone)] pub struct TaskDef { From 8fb1e0892950759b7e8bbb3be1b7f80521785618 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 26 Sep 2023 13:40:09 -0400 Subject: [PATCH 054/177] add tests for TaskEnumDef parsing --- .../procedural/src/pallet/parse/tasks.rs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 064bc704fd36..7e497dd653c6 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -610,3 +610,64 @@ fn test_parse_tasks_def_extra_tasks_attribute() { r"unexpected extra `#\[pallet::tasks\]` attribute" ); } + +#[test] +fn test_parse_task_enum_def_basic() { + parse2::(quote! { + #[pallet::task] + pub enum Task { + Increment, + Decrement, + } + }) + .unwrap(); +} + +#[test] +fn test_parse_task_enum_def_non_task_name() { + parse2::(quote! { + #[pallet::task] + pub enum Something { + Foo + } + }) + .unwrap(); +} + +#[test] +fn test_parse_task_enum_def_missing_attr() { + assert_error_matches!( + parse2::(quote! { + pub enum Task { + Increment, + Decrement, + } + }), + "expected `#`" + ) +} + +#[test] +fn test_parse_task_enum_def_wrong_attr() { + assert_error_matches!( + parse2::(quote! { + #[pallet::something] + pub enum Task { + Increment, + Decrement, + } + }), + "expected `task`" + ) +} + +#[test] +fn test_parse_task_enum_def_wrong_item() { + assert_error_matches!( + parse2::(quote! { + #[pallet::task] + pub struct Something; + }), + "expected `enum`" + ) +} From 50a9b2ca663dc28a0a9a52448e401416af8e64ad Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 27 Sep 2023 15:45:41 -0400 Subject: [PATCH 055/177] working simulate_manifest_dir function --- substrate/frame/support/procedural/src/pallet/parse/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index c0f64e5bfa28..69c2d56ff7c9 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -37,6 +37,9 @@ pub mod tasks; pub mod type_value; pub mod validate_unsigned; +#[cfg(test)] +pub mod tests; + use composite::{keyword::CompositeKeyword, CompositeDef}; use frame_support_procedural_tools::generate_crate_access_2018; use quote::ToTokens; From d9cbab72119358d8d152905ee1bce1845508739a Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 27 Sep 2023 15:46:23 -0400 Subject: [PATCH 056/177] WIP --- .../procedural/src/pallet/parse/tasks.rs | 24 +-- .../procedural/src/pallet/parse/tests/mod.rs | 88 +++++++++ .../src/pallet/parse/tests/tasks.rs | 185 ++++++++++++++++++ 3 files changed, 277 insertions(+), 20 deletions(-) create mode 100644 substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs create mode 100644 substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 7e497dd653c6..c9993bce4e34 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -17,6 +17,9 @@ use std::collections::HashSet; +#[cfg(test)] +use crate::assert_error_matches; + use derive_syn_parse::Parse; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{quote, ToTokens}; @@ -25,28 +28,9 @@ use syn::{ parse2, spanned::Spanned, token::{Bracket, Paren, PathSep, Pound}, - Attribute, Error, Expr, Ident, ImplItemFn, Item, ItemEnum, ItemImpl, LitInt, Result, Token, + Attribute, Error, Expr, Ident, ImplItemFn, ItemEnum, ItemImpl, LitInt, Result, Token, }; -#[cfg(test)] -macro_rules! assert_error_matches { - ($expr:expr, $reg:literal) => { - match $expr { - Ok(_) => panic!("Expected an `Error(..)`, but got Ok(..)"), - Err(e) => { - let error_message = e.to_string(); - let re = regex::Regex::new($reg).expect("Invalid regex pattern"); - assert!( - re.is_match(&error_message), - "Error message \"{}\" does not match the pattern \"{}\"", - error_message, - $reg - ); - }, - } - }; -} - pub mod keywords { use syn::custom_keyword; diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs new file mode 100644 index 000000000000..8ccdff7fa845 --- /dev/null +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -0,0 +1,88 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +use super::*; + +#[macro_export] +macro_rules! assert_error_matches { + ($expr:expr, $reg:literal) => { + match $expr { + Ok(_) => panic!("Expected an `Error(..)`, but got Ok(..)"), + Err(e) => { + let error_message = e.to_string(); + let re = regex::Regex::new($reg).expect("Invalid regex pattern"); + assert!( + re.is_match(&error_message), + "Error message \"{}\" does not match the pattern \"{}\"", + error_message, + $reg + ); + }, + } + }; +} + +/// Implementation detail of [`simulate_manifest_dir`] that allows us to safely run a closure +/// under an alternative `CARGO_MANIFEST_DIR` such that it will always be set back to the +/// original value even if the closure panics. +struct ManifestContext, F: FnMut()> { + path: P, + closure: F, + orig: Option, +} + +impl, F: FnMut()> ManifestContext { + fn run(&mut self) { + use std::{env::*, path::*}; + + // obtain the current/original `CARGO_MANIFEST_DIR` + let orig = PathBuf::from( + var("CARGO_MANIFEST_DIR").expect("failed to read ENV var `CARGO_MANIFEST_DIR`"), + ); + + // set `CARGO_MANIFEST_DIR` to the provided path, relative to current working dir + set_var("CARGO_MANIFEST_DIR", orig.join(self.path.as_ref())); + + // cache the original `CARGO_MANIFEST_DIR` on this context + self.orig = Some(orig); + + // run the closure + (self.closure)(); + } +} + +impl, F: FnMut()> Drop for ManifestContext { + fn drop(&mut self) { + let Some(orig) = &self.orig else { unreachable!() }; + // ensures that `CARGO_MANIFEST_DIR` is set back to its original value even if closure() + // panicked or had a failed assertion. + std::env::set_var("CARGO_MANIFEST_DIR", orig); + } +} + +/// Safely runs the specified `closure` while simulating an alternative +/// `CARGO_MANIFEST_DIR`, restoring `CARGO_MANIFEST_DIR` to its original value upon completion +/// regardless of whether the closure panics. +/// +/// This useful in tests of `Def::try_from` and other pallet-related methods that internally +/// make use of [`generate_crate_access_2018`], which is sensitive to entries in the "current" +/// `Cargo.toml` files. +pub fn simulate_manifest_dir, F: FnMut()>(path: P, closure: F) { + let mut context = ManifestContext { path, closure, orig: None }; + context.run(); +} + +mod tasks; diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs new file mode 100644 index 000000000000..fb8c99f101a6 --- /dev/null +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -0,0 +1,185 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; +use syn::parse_quote; + +#[test] +fn test_pallet_with_task_enum_missing_tasks_impl() { + simulate_manifest_dir("../../examples/tasks-example", || { + assert_error_matches!( + Def::try_from( + parse_quote! { + #[frame_support::pallet(dev_mode)] + pub mod pallet { + + use super::*; + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + // this can be auto-generated from the macros + #[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo)] + pub enum Task { + Increment, + Decrement, + #[doc(hidden)] + #[codec(skip)] + __Ignore(PhantomData, frame_support::Never), + } + + // this can be auto-generated from the macros and will always be the same + impl core::fmt::Debug for Task { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Task").field("value", self).finish() + } + } + + // we can automatically inject `InvalidTask` into an existing Error enum by finding it via + // visitor pattern, otherwise we can just emit an error enum containing just our + // `InvalidTask` variant. Alternatively we could just expect that `InvalidTask` is included + // in the error enum, by convention, or we could use something like + // `InvalidTransaction::Custom(1u8)` but this seems bad to me. + #[pallet::error] + pub enum Error { + InvalidTask, + ValueOverflow, + ValueUnderflow, + } + + // this will be auto-generated from `#[pallet::tasks]` + impl frame_support::traits::Task for Task + where + T: TypeInfo, + { + type Enumeration = sp_std::vec::IntoIter>; + + const TASK_INDEX: Option = Some(0); + + fn iter() -> Self::Enumeration { + sp_std::vec![Task::Increment, Task::Decrement].into_iter() + } + + fn is_valid(&self) -> bool { + let value = Value::::get().unwrap(); + match self { + Task::Increment => value < 255, + Task::Decrement => value > 0, + Task::__Ignore(_, _) => unreachable!(), + } + } + + fn run(&self) -> Result<(), DispatchError> { + match self { + Task::Increment => { + // Get the value and check if it can be incremented + let value = Value::::get().unwrap_or_default(); + if value >= 255 { + Err(Error::::ValueOverflow.into()) + } else { + let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Incremented { new_val }); + Ok(()) + } + }, + Task::Decrement => { + // Get the value and check if it can be decremented + let value = Value::::get().unwrap_or_default(); + if value == 0 { + Err(Error::::ValueUnderflow.into()) + } else { + let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Decremented { new_val }); + Ok(()) + } + }, + Task::__Ignore(_, _) => unreachable!(), + } + } + + fn weight(&self) -> Weight { + Weight::default() + } + } + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type RuntimeTask: frame_support::traits::Task; + } + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn value)] + pub type Value = StorageValue<_, u8>; + + #[pallet::call] + impl Pallet + where + T: TypeInfo, + { + pub fn increment(origin: OriginFor) -> DispatchResult { + ensure_root(origin)?; + + // Increment the value and emit an event + let new_val = Value::::get().unwrap_or(0).checked_add(1).ok_or("Value overflow")?; + Value::::put(new_val); + Self::deposit_event(Event::Incremented { new_val }); + + Ok(()) + } + + pub fn decrement(origin: OriginFor) -> DispatchResult { + ensure_root(origin)?; + + // Decrement the value and emit an event + let new_val = Value::::get().unwrap_or(0).checked_sub(1).ok_or("Value underflow")?; + Value::::put(new_val); + Self::deposit_event(Event::Decremented { new_val }); + + Ok(()) + } + + // this will be auto-generated by the macros and will always be the same + pub fn do_task(origin: OriginFor, task: crate::pallet::Task) -> DispatchResult { + use frame_support::traits::Task; + ensure_root(origin)?; + if task.is_valid() { + task.run() + } else { + Err(Error::::InvalidTask.into()) + } + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + Incremented { new_val: u8 }, + Decremented { new_val: u8 }, + } + } + }, + true + ), + "expected `#` asdf" + ); + }); +} From ccde9283773cda915a16ef832f1d621d2750c778 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 28 Sep 2023 12:12:25 -0400 Subject: [PATCH 057/177] fix dev mode to use parse_quote for empty weight --- substrate/frame/support/procedural/src/pallet/parse/call.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/call.rs b/substrate/frame/support/procedural/src/pallet/parse/call.rs index 90631f264b92..3f9071b4508f 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/call.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/call.rs @@ -241,8 +241,7 @@ impl CallDef { if weight_attrs.is_empty() && dev_mode { // inject a default O(1) weight when dev mode is enabled and no weight has // been specified on the call - let empty_weight: syn::Expr = syn::parse(quote::quote!(0).into()) - .expect("we are parsing a quoted string; qed"); + let empty_weight: syn::Expr = syn::parse_quote!(0); weight_attrs.push(FunctionAttr::Weight(empty_weight)); } From b53bb1280106bde1dc1d104b22ae6f02de68ca9c Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 28 Sep 2023 12:54:08 -0400 Subject: [PATCH 058/177] full-pallet parse tests working, start task-related ones --- .../procedural/src/pallet/parse/tests/mod.rs | 59 +++++++ .../src/pallet/parse/tests/tasks.rs | 151 ++---------------- 2 files changed, 69 insertions(+), 141 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 8ccdff7fa845..0454f74c782d 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -15,6 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. use super::*; +use syn::parse_quote; #[macro_export] macro_rules! assert_error_matches { @@ -86,3 +87,61 @@ pub fn simulate_manifest_dir, F: FnMut()>(path: P, clo } mod tasks; + +#[test] +fn test_parse_minimal_pallet() { + simulate_manifest_dir("../../examples/basic", || { + Def::try_from( + parse_quote! { + #[frame_support::pallet] + pub mod pallet { + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + }, + false, + ) + .unwrap(); + }); +} + +#[test] +fn test_parse_pallet_missing_config() { + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + Def::try_from( + parse_quote! { + #[frame_support::pallet] + pub mod pallet { + #[pallet::config] + pub trait Config: frame_system::Config {} + } + }, + false + ), + "Missing `\\#\\[pallet::pallet\\]`" + ); + }); +} + +#[test] +fn test_parse_pallet_missing_pallet() { + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + Def::try_from( + parse_quote! { + #[frame_support::pallet] + pub mod pallet { + #[pallet::pallet] + pub struct Pallet(_); + } + }, + false + ), + "Missing `\\#\\[pallet::config\\]`" + ); + }); +} diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index fb8c99f101a6..ffe73cb32581 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -18,168 +18,37 @@ use super::*; use syn::parse_quote; +const MANIFEST_DIR: &'static str = "../../examples/basic"; + #[test] fn test_pallet_with_task_enum_missing_tasks_impl() { - simulate_manifest_dir("../../examples/tasks-example", || { + simulate_manifest_dir(MANIFEST_DIR, || { assert_error_matches!( Def::try_from( parse_quote! { - #[frame_support::pallet(dev_mode)] + #[frame_support::pallet] pub mod pallet { - - use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - - // this can be auto-generated from the macros - #[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo)] + #[pallet::task] pub enum Task { - Increment, - Decrement, - #[doc(hidden)] - #[codec(skip)] - __Ignore(PhantomData, frame_support::Never), - } - - // this can be auto-generated from the macros and will always be the same - impl core::fmt::Debug for Task { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("Task").field("value", self).finish() - } - } - - // we can automatically inject `InvalidTask` into an existing Error enum by finding it via - // visitor pattern, otherwise we can just emit an error enum containing just our - // `InvalidTask` variant. Alternatively we could just expect that `InvalidTask` is included - // in the error enum, by convention, or we could use something like - // `InvalidTransaction::Custom(1u8)` but this seems bad to me. - #[pallet::error] - pub enum Error { - InvalidTask, - ValueOverflow, - ValueUnderflow, + Something, } - // this will be auto-generated from `#[pallet::tasks]` + #[pallet::tasks] impl frame_support::traits::Task for Task where T: TypeInfo, - { - type Enumeration = sp_std::vec::IntoIter>; - - const TASK_INDEX: Option = Some(0); - - fn iter() -> Self::Enumeration { - sp_std::vec![Task::Increment, Task::Decrement].into_iter() - } - - fn is_valid(&self) -> bool { - let value = Value::::get().unwrap(); - match self { - Task::Increment => value < 255, - Task::Decrement => value > 0, - Task::__Ignore(_, _) => unreachable!(), - } - } - - fn run(&self) -> Result<(), DispatchError> { - match self { - Task::Increment => { - // Get the value and check if it can be incremented - let value = Value::::get().unwrap_or_default(); - if value >= 255 { - Err(Error::::ValueOverflow.into()) - } else { - let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Incremented { new_val }); - Ok(()) - } - }, - Task::Decrement => { - // Get the value and check if it can be decremented - let value = Value::::get().unwrap_or_default(); - if value == 0 { - Err(Error::::ValueUnderflow.into()) - } else { - let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Decremented { new_val }); - Ok(()) - } - }, - Task::__Ignore(_, _) => unreachable!(), - } - } - - fn weight(&self) -> Weight { - Weight::default() - } - } + {} #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type RuntimeTask: frame_support::traits::Task; - } + pub trait Config: frame_system::Config {} #[pallet::pallet] pub struct Pallet(_); - - #[pallet::storage] - #[pallet::getter(fn value)] - pub type Value = StorageValue<_, u8>; - - #[pallet::call] - impl Pallet - where - T: TypeInfo, - { - pub fn increment(origin: OriginFor) -> DispatchResult { - ensure_root(origin)?; - - // Increment the value and emit an event - let new_val = Value::::get().unwrap_or(0).checked_add(1).ok_or("Value overflow")?; - Value::::put(new_val); - Self::deposit_event(Event::Incremented { new_val }); - - Ok(()) - } - - pub fn decrement(origin: OriginFor) -> DispatchResult { - ensure_root(origin)?; - - // Decrement the value and emit an event - let new_val = Value::::get().unwrap_or(0).checked_sub(1).ok_or("Value underflow")?; - Value::::put(new_val); - Self::deposit_event(Event::Decremented { new_val }); - - Ok(()) - } - - // this will be auto-generated by the macros and will always be the same - pub fn do_task(origin: OriginFor, task: crate::pallet::Task) -> DispatchResult { - use frame_support::traits::Task; - ensure_root(origin)?; - if task.is_valid() { - task.run() - } else { - Err(Error::::InvalidTask.into()) - } - } - } - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - Incremented { new_val: u8 }, - Decremented { new_val: u8 }, - } } }, true ), - "expected `#` asdf" + "expected `#`" ); }); } From 01c42d4dcc6eecd4323d9b4cb41d51e4efdb2abc Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 28 Sep 2023 15:02:53 -0400 Subject: [PATCH 059/177] parsing fixes --- .../procedural/src/pallet/parse/mod.rs | 26 ++++++- .../procedural/src/pallet/parse/tasks.rs | 73 ++++++++++++++----- .../src/pallet/parse/tests/tasks.rs | 43 +++++++++-- 3 files changed, 115 insertions(+), 27 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 69c2d56ff7c9..db028cf96b80 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -136,6 +136,11 @@ impl Def { call = Some(call::CallDef::try_from(span, index, item, dev_mode, cw)?), Some(PalletAttr::Tasks(_)) if tasks.is_none() => tasks = Some(syn::parse2::(get_tokens(item))?), + Some( + PalletAttr::TaskCondition(_) | + PalletAttr::TaskIndex(_) | + PalletAttr::TaskList(_), + ) => (), Some(PalletAttr::RuntimeTask(_)) if task_enum.is_none() => task_enum = Some(syn::parse2::(get_tokens(item))?), Some(PalletAttr::Error(span)) if error.is_none() => @@ -440,7 +445,10 @@ mod keyword { syn::custom_keyword!(origin); syn::custom_keyword!(call); syn::custom_keyword!(tasks); - syn::custom_keyword!(task); + syn::custom_keyword!(task_enum); + syn::custom_keyword!(task_list); + syn::custom_keyword!(task_condition); + syn::custom_keyword!(task_index); syn::custom_keyword!(weight); syn::custom_keyword!(event); syn::custom_keyword!(config); @@ -506,6 +514,9 @@ enum PalletAttr { RuntimeCall(Option, proc_macro2::Span), Error(proc_macro2::Span), Tasks(proc_macro2::Span), + TaskList(proc_macro2::Span), + TaskCondition(proc_macro2::Span), + TaskIndex(proc_macro2::Span), RuntimeTask(proc_macro2::Span), RuntimeEvent(proc_macro2::Span), RuntimeOrigin(proc_macro2::Span), @@ -526,6 +537,9 @@ impl PalletAttr { Self::Pallet(span) => *span, Self::Hooks(span) => *span, Self::Tasks(span) => *span, + Self::TaskCondition(span) => *span, + Self::TaskIndex(span) => *span, + Self::TaskList(span) => *span, Self::Error(span) => *span, Self::RuntimeTask(span) => *span, Self::RuntimeCall(_, span) => *span, @@ -574,8 +588,14 @@ impl syn::parse::Parse for PalletAttr { Ok(PalletAttr::RuntimeCall(attr, span)) } else if lookahead.peek(keyword::tasks) { Ok(PalletAttr::Tasks(content.parse::()?.span())) - } else if lookahead.peek(keyword::task) { - Ok(PalletAttr::RuntimeTask(content.parse::()?.span())) + } else if lookahead.peek(keyword::task_enum) { + Ok(PalletAttr::RuntimeTask(content.parse::()?.span())) + } else if lookahead.peek(keyword::task_condition) { + Ok(PalletAttr::TaskCondition(content.parse::()?.span())) + } else if lookahead.peek(keyword::task_index) { + Ok(PalletAttr::TaskIndex(content.parse::()?.span())) + } else if lookahead.peek(keyword::task_list) { + Ok(PalletAttr::TaskList(content.parse::()?.span())) } else if lookahead.peek(keyword::error) { Ok(PalletAttr::Error(content.parse::()?.span())) } else if lookahead.peek(keyword::event) { diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index c9993bce4e34..6fe65c4d911d 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -35,7 +35,7 @@ pub mod keywords { use syn::custom_keyword; custom_keyword!(tasks); - custom_keyword!(task); + custom_keyword!(task_enum); custom_keyword!(task_list); custom_keyword!(task_condition); custom_keyword!(task_index); @@ -96,14 +96,43 @@ pub type TaskAttr = PalletTaskAttr; pub type TaskIndexAttr = PalletTaskAttr; pub type TaskConditionAttr = PalletTaskAttr; pub type TaskListAttr = PalletTaskAttr; -pub type PalletTaskEnumAttr = PalletTaskAttr; +pub type PalletTaskEnumAttr = PalletTaskAttr; -#[derive(Parse, Clone, Debug)] +#[derive(Clone, Debug)] pub struct TaskEnumDef { - attr: PalletTaskEnumAttr, + attr: Option, item_enum: ItemEnum, } +impl syn::parse::Parse for TaskEnumDef { + fn parse(input: ParseStream) -> Result { + let item_enum = input.parse::()?; + let mut attr = None; + for found_attr in &item_enum.attrs { + let segs = found_attr + .path() + .segments + .iter() + .map(|seg| seg.ident.clone()) + .collect::>(); + let (Some(seg1), Some(_), None) = (segs.get(0), segs.get(1), segs.get(2)) else { + continue + }; + if seg1 != "pallet" { + continue + } + if attr.is_some() { + return Err(Error::new( + found_attr.span(), + "only one `#[pallet::_]` attribute is supported on this item", + )) + } + attr = Some(parse2(found_attr.to_token_stream())?); + } + Ok(TaskEnumDef { attr, item_enum }) + } +} + #[derive(Debug, Clone)] pub struct TaskDef { index_attr: TaskIndexAttr, @@ -598,7 +627,7 @@ fn test_parse_tasks_def_extra_tasks_attribute() { #[test] fn test_parse_task_enum_def_basic() { parse2::(quote! { - #[pallet::task] + #[pallet::task_enum] pub enum Task { Increment, Decrement, @@ -610,7 +639,7 @@ fn test_parse_task_enum_def_basic() { #[test] fn test_parse_task_enum_def_non_task_name() { parse2::(quote! { - #[pallet::task] + #[pallet::task_enum] pub enum Something { Foo } @@ -619,16 +648,24 @@ fn test_parse_task_enum_def_non_task_name() { } #[test] -fn test_parse_task_enum_def_missing_attr() { - assert_error_matches!( - parse2::(quote! { - pub enum Task { - Increment, - Decrement, - } - }), - "expected `#`" - ) +fn test_parse_task_enum_def_missing_attr_allowed() { + parse2::(quote! { + pub enum Task { + Increment, + Decrement, + } + }) + .unwrap(); +} + +#[test] +fn test_parse_task_enum_def_missing_attr_alternate_name_allowed() { + parse2::(quote! { + pub enum Foo { + Red, + } + }) + .unwrap(); } #[test] @@ -641,7 +678,7 @@ fn test_parse_task_enum_def_wrong_attr() { Decrement, } }), - "expected `task`" + "expected `task_enum`" ) } @@ -649,7 +686,7 @@ fn test_parse_task_enum_def_wrong_attr() { fn test_parse_task_enum_def_wrong_item() { assert_error_matches!( parse2::(quote! { - #[pallet::task] + #[pallet::task_enum] pub struct Something; }), "expected `enum`" diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index ffe73cb32581..75260e74ffea 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -18,22 +18,53 @@ use super::*; use syn::parse_quote; -const MANIFEST_DIR: &'static str = "../../examples/basic"; +#[test] +fn test_pallet_with_task_enum_missing_impl() { + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + Def::try_from( + parse_quote! { + #[frame_support::pallet] + pub mod pallet { + #[pallet::task_enum] + pub enum Task { + Something, + } + + #[pallet::task_list] + impl frame_support::traits::Task for Task + where + T: TypeInfo, + {} + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + }, + true + ), + "Missing `\\#\\[pallet::tasks\\]` impl" + ); + }); +} #[test] -fn test_pallet_with_task_enum_missing_tasks_impl() { - simulate_manifest_dir(MANIFEST_DIR, || { +fn test_pallet_with_task_enum_wrong_attribute() { + simulate_manifest_dir("../../examples/basic", || { assert_error_matches!( Def::try_from( parse_quote! { #[frame_support::pallet] pub mod pallet { - #[pallet::task] + #[pallet::wrong_attribute] pub enum Task { Something, } - #[pallet::tasks] + #[pallet::task_list] impl frame_support::traits::Task for Task where T: TypeInfo, @@ -48,7 +79,7 @@ fn test_pallet_with_task_enum_missing_tasks_impl() { }, true ), - "expected `#`" + "expected one of" ); }); } From 13f92085871477aee81e28c785f0214ab7f660af Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 28 Sep 2023 15:29:03 -0400 Subject: [PATCH 060/177] allow omitting `#[pallet::tasks]` attribute --- .../procedural/src/pallet/parse/tasks.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 6fe65c4d911d..ea789ed99b6a 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -43,27 +43,25 @@ pub mod keywords { } pub struct TasksDef { - normal_attrs: Vec, - tasks_attr: PalletTasksAttr, + tasks_attr: Option, tasks: Vec, + item_impl: ItemImpl, } impl syn::parse::Parse for TasksDef { fn parse(input: ParseStream) -> Result { let item_impl: ItemImpl = input.parse()?; let (tasks_attrs, normal_attrs): (Vec<_>, Vec<_>) = - item_impl.attrs.into_iter().partition(|attr| { + item_impl.attrs.clone().into_iter().partition(|attr| { let mut path_segs = attr.path().segments.iter(); let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { return false }; prefix.ident == "pallet" && suffix.ident == "tasks" }); - let Some(tasks_attr) = tasks_attrs.first() else { - return Err(Error::new( - item_impl.impl_token.span(), - "expected `#[pallet::tasks]` attribute", - )) + let tasks_attr = match tasks_attrs.first() { + Some(attr) => Some(parse2::(attr.to_token_stream())?), + None => None, }; if let Some(extra_tasks_attr) = tasks_attrs.get(1) { return Err(Error::new( @@ -71,9 +69,9 @@ impl syn::parse::Parse for TasksDef { "unexpected extra `#[pallet::tasks]` attribute", )) } - let tasks_attr = parse2::(tasks_attr.to_token_stream())?; let tasks: Vec = item_impl .items + .clone() .into_iter() .map(|item| parse2::(item.to_token_stream())) .collect::>()?; @@ -87,7 +85,9 @@ impl syn::parse::Parse for TasksDef { )) } } - Ok(TasksDef { normal_attrs, tasks_attr, tasks }) + let mut item_impl = item_impl; + item_impl.attrs = normal_attrs; + Ok(TasksDef { tasks_attr, item_impl, tasks }) } } From d270adc8b1334d8b858025a8158b3c45ca3cccb6 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 29 Sep 2023 11:54:48 -0400 Subject: [PATCH 061/177] add assert_pallet_parses! --- .../procedural/src/pallet/parse/tests/mod.rs | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 0454f74c782d..f50e238063e3 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -36,6 +36,17 @@ macro_rules! assert_error_matches { }; } +#[macro_export] +macro_rules! assert_pallet_parses { + (#[manifest_dir($manifest_dir:literal)] $($tokens:tt)*) => { + $crate::pallet::parse::tests::simulate_manifest_dir($manifest_dir, || { + $crate::pallet::parse::Def::try_from(syn::parse_quote! { + $($tokens)* + }, false).unwrap(); + }); + } +} + /// Implementation detail of [`simulate_manifest_dir`] that allows us to safely run a closure /// under an alternative `CARGO_MANIFEST_DIR` such that it will always be set back to the /// original value even if the closure panics. @@ -90,22 +101,17 @@ mod tasks; #[test] fn test_parse_minimal_pallet() { - simulate_manifest_dir("../../examples/basic", || { - Def::try_from( - parse_quote! { - #[frame_support::pallet] - pub mod pallet { - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - }, - false, - ) - .unwrap(); - }); + assert_pallet_parses!( + #[manifest_dir("../../examples/basic")] + #[frame_support::pallet] + pub mod pallet { + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + ); } #[test] From cd80bb154acf884a5d99762c0fb30d47ba56a140 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 29 Sep 2023 12:39:37 -0400 Subject: [PATCH 062/177] add assert_pallet_parse_error! shorthand --- .../procedural/src/pallet/parse/tests/mod.rs | 79 +++++++++------- .../src/pallet/parse/tests/tasks.rs | 93 ++++++++----------- 2 files changed, 85 insertions(+), 87 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index f50e238063e3..ca363cec1120 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -14,7 +14,6 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -use super::*; use syn::parse_quote; #[macro_export] @@ -38,7 +37,10 @@ macro_rules! assert_error_matches { #[macro_export] macro_rules! assert_pallet_parses { - (#[manifest_dir($manifest_dir:literal)] $($tokens:tt)*) => { + ( + #[manifest_dir($manifest_dir:literal)] + $($tokens:tt)* + ) => { $crate::pallet::parse::tests::simulate_manifest_dir($manifest_dir, || { $crate::pallet::parse::Def::try_from(syn::parse_quote! { $($tokens)* @@ -47,6 +49,27 @@ macro_rules! assert_pallet_parses { } } +#[macro_export] +macro_rules! assert_pallet_parse_error { + ( + #[manifest_dir($manifest_dir:literal)] + #[error_regex($reg:literal)] + $($tokens:tt)* + ) => { + $crate::pallet::parse::tests::simulate_manifest_dir($manifest_dir, || { + $crate::assert_error_matches!( + $crate::pallet::parse::Def::try_from( + parse_quote! { + $($tokens)* + }, + false + ), + $reg + ); + }); + } +} + /// Implementation detail of [`simulate_manifest_dir`] that allows us to safely run a closure /// under an alternative `CARGO_MANIFEST_DIR` such that it will always be set back to the /// original value even if the closure panics. @@ -115,39 +138,27 @@ fn test_parse_minimal_pallet() { } #[test] -fn test_parse_pallet_missing_config() { - simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( - Def::try_from( - parse_quote! { - #[frame_support::pallet] - pub mod pallet { - #[pallet::config] - pub trait Config: frame_system::Config {} - } - }, - false - ), - "Missing `\\#\\[pallet::pallet\\]`" - ); - }); +fn test_parse_pallet_missing_pallet() { + assert_pallet_parse_error! { + #[manifest_dir("../../examples/basic")] + #[error_regex("Missing `\\#\\[pallet::pallet\\]`")] + #[frame_support::pallet] + pub mod pallet { + #[pallet::config] + pub trait Config: frame_system::Config {} + } + } } #[test] -fn test_parse_pallet_missing_pallet() { - simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( - Def::try_from( - parse_quote! { - #[frame_support::pallet] - pub mod pallet { - #[pallet::pallet] - pub struct Pallet(_); - } - }, - false - ), - "Missing `\\#\\[pallet::config\\]`" - ); - }); +fn test_parse_pallet_missing_config() { + assert_pallet_parse_error! { + #[manifest_dir("../../examples/basic")] + #[error_regex("Missing `\\#\\[pallet::config\\]`")] + #[frame_support::pallet] + pub mod pallet { + #[pallet::pallet] + pub struct Pallet(_); + } + } } diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index 75260e74ffea..b76ada1b60eb 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -15,71 +15,58 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::*; use syn::parse_quote; #[test] fn test_pallet_with_task_enum_missing_impl() { - simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( - Def::try_from( - parse_quote! { - #[frame_support::pallet] - pub mod pallet { - #[pallet::task_enum] - pub enum Task { - Something, - } + assert_pallet_parse_error! { + #[manifest_dir("../../examples/basic")] + #[error_regex("Missing `\\#\\[pallet::tasks\\]` impl")] + #[frame_support::pallet] + pub mod pallet { + #[pallet::task_enum] + pub enum Task { + Something, + } - #[pallet::task_list] - impl frame_support::traits::Task for Task - where - T: TypeInfo, - {} + #[pallet::task_list] + impl frame_support::traits::Task for Task + where + T: TypeInfo, + {} - #[pallet::config] - pub trait Config: frame_system::Config {} + #[pallet::config] + pub trait Config: frame_system::Config {} - #[pallet::pallet] - pub struct Pallet(_); - } - }, - true - ), - "Missing `\\#\\[pallet::tasks\\]` impl" - ); - }); + #[pallet::pallet] + pub struct Pallet(_); + } + } } #[test] fn test_pallet_with_task_enum_wrong_attribute() { - simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( - Def::try_from( - parse_quote! { - #[frame_support::pallet] - pub mod pallet { - #[pallet::wrong_attribute] - pub enum Task { - Something, - } + assert_pallet_parse_error! { + #[manifest_dir("../../examples/basic")] + #[error_regex("expected one of")] + #[frame_support::pallet] + pub mod pallet { + #[pallet::wrong_attribute] + pub enum Task { + Something, + } - #[pallet::task_list] - impl frame_support::traits::Task for Task - where - T: TypeInfo, - {} + #[pallet::task_list] + impl frame_support::traits::Task for Task + where + T: TypeInfo, + {} - #[pallet::config] - pub trait Config: frame_system::Config {} + #[pallet::config] + pub trait Config: frame_system::Config {} - #[pallet::pallet] - pub struct Pallet(_); - } - }, - true - ), - "expected one of" - ); - }); + #[pallet::pallet] + pub struct Pallet(_); + } + } } From a6ca40be26e98a585356640d1ded93beda83eae7 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 29 Sep 2023 12:54:51 -0400 Subject: [PATCH 063/177] fix: ensure CARGO_MANIFEST_DIR is always restored --- .../frame/support/procedural/src/pallet/parse/tests/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index ca363cec1120..37d16a4cd9d3 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -92,10 +92,13 @@ impl, F: FnMut()> ManifestContext { set_var("CARGO_MANIFEST_DIR", orig.join(self.path.as_ref())); // cache the original `CARGO_MANIFEST_DIR` on this context - self.orig = Some(orig); + self.orig = Some(orig.clone()); // run the closure (self.closure)(); + + // defensively ensure that dir is restored if closure succeeded + set_var("CARGO_MANIFEST_DIR", orig); } } From 7387a17cc08831f5129e0484fc9c24acbc248606 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 29 Sep 2023 12:57:43 -0400 Subject: [PATCH 064/177] add explicit drop of ManifestContext --- substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 37d16a4cd9d3..a7b4fabc9d2a 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -121,6 +121,7 @@ impl, F: FnMut()> Drop for ManifestContext { pub fn simulate_manifest_dir, F: FnMut()>(path: P, closure: F) { let mut context = ManifestContext { path, closure, orig: None }; context.run(); + drop(context) } mod tasks; From bbb04d18da09d486c2878bc710e18aa1b26cc33e Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 29 Sep 2023 12:58:47 -0400 Subject: [PATCH 065/177] make drop impl safer --- .../frame/support/procedural/src/pallet/parse/tests/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index a7b4fabc9d2a..9dcbc8c9944d 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -104,7 +104,7 @@ impl, F: FnMut()> ManifestContext { impl, F: FnMut()> Drop for ManifestContext { fn drop(&mut self) { - let Some(orig) = &self.orig else { unreachable!() }; + let Some(orig) = &self.orig else { return }; // ensures that `CARGO_MANIFEST_DIR` is set back to its original value even if closure() // panicked or had a failed assertion. std::env::set_var("CARGO_MANIFEST_DIR", orig); From 68ccb76e56a0ed0b6da6312266391a17a8f052ee Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 29 Sep 2023 13:01:13 -0400 Subject: [PATCH 066/177] clean up --- .../support/procedural/src/pallet/parse/tests/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 9dcbc8c9944d..f5331a8f8cb4 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -111,11 +111,11 @@ impl, F: FnMut()> Drop for ManifestContext { } } -/// Safely runs the specified `closure` while simulating an alternative -/// `CARGO_MANIFEST_DIR`, restoring `CARGO_MANIFEST_DIR` to its original value upon completion -/// regardless of whether the closure panics. +/// Safely runs the specified `closure` while simulating an alternative `CARGO_MANIFEST_DIR`, +/// restoring `CARGO_MANIFEST_DIR` to its original value upon completion regardless of whether +/// the closure panics. /// -/// This useful in tests of `Def::try_from` and other pallet-related methods that internally +/// This is useful in tests of `Def::try_from` and other pallet-related methods that internally /// make use of [`generate_crate_access_2018`], which is sensitive to entries in the "current" /// `Cargo.toml` files. pub fn simulate_manifest_dir, F: FnMut()>(path: P, closure: F) { From 8128108d229832f24c0b8a6cd80c8ce0a41919cb Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 29 Sep 2023 13:12:06 -0400 Subject: [PATCH 067/177] test missing task enum --- .../procedural/src/pallet/parse/mod.rs | 2 +- .../procedural/src/pallet/parse/tasks.rs | 1 + .../src/pallet/parse/tests/tasks.rs | 26 +++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index db028cf96b80..953ffc99aae7 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -220,7 +220,7 @@ impl Def { (Some(_), None) => return Err(syn::Error::new(item_span, "Missing `#[pallet::tasks]` impl")), (None, Some(_)) => - return Err(syn::Error::new(item_span, "Missing `#[pallet::task]` enum")), + return Err(syn::Error::new(item_span, "Missing `#[pallet::task_enum]` enum")), _ => (), } diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index ea789ed99b6a..04343cffa530 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -42,6 +42,7 @@ pub mod keywords { custom_keyword!(pallet); } +#[derive(Clone, Debug)] pub struct TasksDef { tasks_attr: Option, tasks: Vec, diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index b76ada1b60eb..3ed48af5cd6a 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -18,7 +18,7 @@ use syn::parse_quote; #[test] -fn test_pallet_with_task_enum_missing_impl() { +fn test_parse_pallet_with_task_enum_missing_impl() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] #[error_regex("Missing `\\#\\[pallet::tasks\\]` impl")] @@ -45,7 +45,7 @@ fn test_pallet_with_task_enum_missing_impl() { } #[test] -fn test_pallet_with_task_enum_wrong_attribute() { +fn test_parse_pallet_with_task_enum_wrong_attribute() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] #[error_regex("expected one of")] @@ -70,3 +70,25 @@ fn test_pallet_with_task_enum_wrong_attribute() { } } } + +#[test] +fn test_parse_pallet_missing_task_enum() { + assert_pallet_parse_error! { + #[manifest_dir("../../examples/basic")] + #[error_regex("Missing `\\#\\[pallet::task_enum\\]` enum")] + #[frame_support::pallet] + pub mod pallet { + #[pallet::tasks] + impl frame_support::traits::Task for Task + where + T: TypeInfo, + {} + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + } +} From c72ec4dd6080bbadf08b28f17f3ae6143481c409 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 29 Sep 2023 13:37:31 -0400 Subject: [PATCH 068/177] fix race condition in testing support code --- Cargo.lock | 1 + substrate/frame/support/procedural/Cargo.toml | 1 + .../procedural/src/pallet/parse/tests/mod.rs | 76 ++++++++----------- 3 files changed, 34 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ccf16a4ecd0..7727794ba062 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5358,6 +5358,7 @@ dependencies = [ "frame-support-procedural-tools", "itertools 0.10.5", "macro_magic", + "once_cell", "proc-macro-warning", "proc-macro2", "proc-utils", diff --git a/substrate/frame/support/procedural/Cargo.toml b/substrate/frame/support/procedural/Cargo.toml index c26dc104c8ad..6f14416e7261 100644 --- a/substrate/frame/support/procedural/Cargo.toml +++ b/substrate/frame/support/procedural/Cargo.toml @@ -27,6 +27,7 @@ proc-macro-warning = { version = "0.4.2", default-features = false } macro_magic = { version = "0.4.2", features = ["proc_support"] } expander = "2.0.0" proc-utils = "0" +once_cell = "1.18.0" [dev-dependencies] regex = "1" diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index f5331a8f8cb4..68dbbb1e7fad 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -14,8 +14,13 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + +use once_cell::sync::Lazy; +use std::{panic, sync::Mutex}; use syn::parse_quote; +static MANIFEST_DIR_LOCK: Lazy> = Lazy::new(|| Mutex::new(())); + #[macro_export] macro_rules! assert_error_matches { ($expr:expr, $reg:literal) => { @@ -70,58 +75,41 @@ macro_rules! assert_pallet_parse_error { } } -/// Implementation detail of [`simulate_manifest_dir`] that allows us to safely run a closure -/// under an alternative `CARGO_MANIFEST_DIR` such that it will always be set back to the -/// original value even if the closure panics. -struct ManifestContext, F: FnMut()> { +/// Safely runs the specified `closure` while simulating an alternative `CARGO_MANIFEST_DIR`, +/// restoring `CARGO_MANIFEST_DIR` to its original value upon completion regardless of whether +/// the closure panics. +/// +/// This is useful in tests of `Def::try_from` and other pallet-related methods that internally +/// make use of [`generate_crate_access_2018`], which is sensitive to entries in the "current" +/// `Cargo.toml` files. +/// +/// This function uses a [`Mutex`] to avoid a race condition created when multiple tests try to +/// modify and then restore the `CARGO_MANIFEST_DIR` ENV var in an overlapping way. +pub fn simulate_manifest_dir, F: FnMut() + std::panic::UnwindSafe>( path: P, closure: F, - orig: Option, -} - -impl, F: FnMut()> ManifestContext { - fn run(&mut self) { - use std::{env::*, path::*}; - - // obtain the current/original `CARGO_MANIFEST_DIR` - let orig = PathBuf::from( - var("CARGO_MANIFEST_DIR").expect("failed to read ENV var `CARGO_MANIFEST_DIR`"), - ); +) { + use std::{env::*, path::*}; - // set `CARGO_MANIFEST_DIR` to the provided path, relative to current working dir - set_var("CARGO_MANIFEST_DIR", orig.join(self.path.as_ref())); + // avoid race condition when swapping out `CARGO_MANIFEST_DIR` + let _guard = MANIFEST_DIR_LOCK.lock().unwrap(); - // cache the original `CARGO_MANIFEST_DIR` on this context - self.orig = Some(orig.clone()); + // obtain the current/original `CARGO_MANIFEST_DIR` + let orig = PathBuf::from( + var("CARGO_MANIFEST_DIR").expect("failed to read ENV var `CARGO_MANIFEST_DIR`"), + ); - // run the closure - (self.closure)(); + // set `CARGO_MANIFEST_DIR` to the provided path, relative to current working dir + set_var("CARGO_MANIFEST_DIR", orig.join(path.as_ref())); - // defensively ensure that dir is restored if closure succeeded - set_var("CARGO_MANIFEST_DIR", orig); - } -} + // safely run closure catching any panics + let result = panic::catch_unwind(closure); -impl, F: FnMut()> Drop for ManifestContext { - fn drop(&mut self) { - let Some(orig) = &self.orig else { return }; - // ensures that `CARGO_MANIFEST_DIR` is set back to its original value even if closure() - // panicked or had a failed assertion. - std::env::set_var("CARGO_MANIFEST_DIR", orig); - } -} + // restore original `CARGO_MANIFEST_DIR` before unwinding + set_var("CARGO_MANIFEST_DIR", &orig); -/// Safely runs the specified `closure` while simulating an alternative `CARGO_MANIFEST_DIR`, -/// restoring `CARGO_MANIFEST_DIR` to its original value upon completion regardless of whether -/// the closure panics. -/// -/// This is useful in tests of `Def::try_from` and other pallet-related methods that internally -/// make use of [`generate_crate_access_2018`], which is sensitive to entries in the "current" -/// `Cargo.toml` files. -pub fn simulate_manifest_dir, F: FnMut()>(path: P, closure: F) { - let mut context = ManifestContext { path, closure, orig: None }; - context.run(); - drop(context) + // unwind any panics originally encountered when running closure + result.unwrap(); } mod tasks; From 34dc54ac75ad1dc955bf336dff8e1a6adcd1cbf3 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 29 Sep 2023 13:49:23 -0400 Subject: [PATCH 069/177] fix --- .../frame/support/procedural/src/pallet/parse/tests/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 68dbbb1e7fad..1361546402cd 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -19,6 +19,8 @@ use once_cell::sync::Lazy; use std::{panic, sync::Mutex}; use syn::parse_quote; +/// Ensures that only one thread can modify/restore the `CARGO_MANIFEST_DIR` ENV var at a time, +/// avoiding a race condition because `cargo test` runs tests in parallel. static MANIFEST_DIR_LOCK: Lazy> = Lazy::new(|| Mutex::new(())); #[macro_export] @@ -92,7 +94,7 @@ pub fn simulate_manifest_dir, F: FnMut() + std::panic: use std::{env::*, path::*}; // avoid race condition when swapping out `CARGO_MANIFEST_DIR` - let _guard = MANIFEST_DIR_LOCK.lock().unwrap(); + let guard = MANIFEST_DIR_LOCK.lock().unwrap(); // obtain the current/original `CARGO_MANIFEST_DIR` let orig = PathBuf::from( @@ -108,6 +110,9 @@ pub fn simulate_manifest_dir, F: FnMut() + std::panic: // restore original `CARGO_MANIFEST_DIR` before unwinding set_var("CARGO_MANIFEST_DIR", &orig); + // unlock the mutex so we don't poison it if there is a panic + drop(guard); + // unwind any panics originally encountered when running closure result.unwrap(); } From 95964d9013227f3557d42956ec0bd1330c03f9e4 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 4 Oct 2023 14:54:14 -0400 Subject: [PATCH 070/177] allow omitting `#[pallet::task_enum]` if enough info is provided --- .../procedural/src/pallet/parse/mod.rs | 43 ++++++++-- .../procedural/src/pallet/parse/tasks.rs | 44 +++++----- .../src/pallet/parse/tests/tasks.rs | 82 +++++++++++++++++-- 3 files changed, 136 insertions(+), 33 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 953ffc99aae7..35342d77e6fb 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -136,11 +136,18 @@ impl Def { call = Some(call::CallDef::try_from(span, index, item, dev_mode, cw)?), Some(PalletAttr::Tasks(_)) if tasks.is_none() => tasks = Some(syn::parse2::(get_tokens(item))?), - Some( - PalletAttr::TaskCondition(_) | - PalletAttr::TaskIndex(_) | - PalletAttr::TaskList(_), - ) => (), + Some(PalletAttr::TaskCondition(span)) => return Err(syn::Error::new( + span, + "`#[pallet::task_condition]` can only be used on items within an `impl` statement." + )), + Some(PalletAttr::TaskIndex(span)) => return Err(syn::Error::new( + span, + "`#[pallet::task_index]` can only be used on items within an `impl` statement." + )), + Some(PalletAttr::TaskList(span)) => return Err(syn::Error::new( + span, + "`#[pallet::task_list]` can only be used on items within an `impl` statement." + )), Some(PalletAttr::RuntimeTask(_)) if task_enum.is_none() => task_enum = Some(syn::parse2::(get_tokens(item))?), Some(PalletAttr::Error(span)) if error.is_none() => @@ -215,6 +222,8 @@ impl Def { return Err(syn::Error::new(item_span, msg)) } + Self::resolve_manual_task_enum(&tasks, &mut task_enum, &items)?; + // ensure either both or none of `(task_enum, tasks)` are specified match (&task_enum, &tasks) { (Some(_), None) => @@ -256,6 +265,30 @@ impl Def { Ok(def) } + /// Tries to locate task enum based on the tasks impl target if attribute is not specified + /// but impl is present. If one is found, `task_enum` is set appropriately. + fn resolve_manual_task_enum( + tasks: &Option, + task_enum: &mut Option, + items: &Vec, + ) -> syn::Result<()> { + let (None, Some(tasks)) = (&task_enum, &tasks) else { return Ok(()) }; + let syn::Type::Path(type_path) = &*tasks.item_impl.self_ty else { return Ok(()) }; + let type_path = type_path.path.segments.iter().collect::>(); + let (Some(seg), None) = (type_path.get(0), type_path.get(1)) else { return Ok(()) }; + let mut result = None; + for item in items { + if let syn::Item::Enum(item_enum) = item { + if item_enum.ident == seg.ident { + result = Some(syn::parse2::(item_enum.to_token_stream())?); + break + } + } + } + *task_enum = result; + Ok(()) + } + /// Check that usage of trait `Event` is consistent with the definition, i.e. it is declared /// and trait defines type RuntimeEvent, or not declared and no trait associated type. fn check_event_usage(&self) -> syn::Result<()> { diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 04343cffa530..a1c97c95062c 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -44,9 +44,9 @@ pub mod keywords { #[derive(Clone, Debug)] pub struct TasksDef { - tasks_attr: Option, - tasks: Vec, - item_impl: ItemImpl, + pub tasks_attr: Option, + pub tasks: Vec, + pub item_impl: ItemImpl, } impl syn::parse::Parse for TasksDef { @@ -101,8 +101,8 @@ pub type PalletTaskEnumAttr = PalletTaskAttr; #[derive(Clone, Debug)] pub struct TaskEnumDef { - attr: Option, - item_enum: ItemEnum, + pub attr: Option, + pub item_enum: ItemEnum, } impl syn::parse::Parse for TaskEnumDef { @@ -136,10 +136,10 @@ impl syn::parse::Parse for TaskEnumDef { #[derive(Debug, Clone)] pub struct TaskDef { - index_attr: TaskIndexAttr, - condition_attr: TaskConditionAttr, - list_attr: TaskListAttr, - normal_attrs: Vec, + pub index_attr: TaskIndexAttr, + pub condition_attr: TaskConditionAttr, + pub list_attr: TaskListAttr, + pub normal_attrs: Vec, } impl syn::parse::Parse for TaskDef { @@ -256,48 +256,48 @@ pub enum TaskAttrMeta { #[derive(Parse, Debug, Clone)] pub struct TaskListAttrMeta { - task_list: keywords::task_list, + pub task_list: keywords::task_list, #[paren] _paren: Paren, #[inside(_paren)] - expr: Expr, + pub expr: Expr, } #[derive(Parse, Debug, Clone)] pub struct TaskIndexAttrMeta { - task_index: keywords::task_index, + pub task_index: keywords::task_index, #[paren] _paren: Paren, #[inside(_paren)] - index: LitInt, + pub index: LitInt, } #[derive(Parse, Debug, Clone)] pub struct TaskConditionAttrMeta { - task_condition: keywords::task_condition, + pub task_condition: keywords::task_condition, #[paren] _paren: Paren, #[inside(_paren)] - pipe1: Token![|], + pub pipe1: Token![|], #[inside(_paren)] - ident: Ident, + pub ident: Ident, #[inside(_paren)] - pipe2: Token![|], + pub pipe2: Token![|], #[inside(_paren)] - expr: Expr, + pub expr: Expr, } #[derive(Parse, Debug, Clone)] pub struct PalletTaskAttr { - pound: Pound, + pub pound: Pound, #[bracket] _bracket: Bracket, #[inside(_bracket)] - pallet: keywords::pallet, + pub pallet: keywords::pallet, #[inside(_bracket)] - colons: PathSep, + pub colons: PathSep, #[inside(_bracket)] - meta: T, + pub meta: T, } impl ToTokens for TaskListAttrMeta { diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index 3ed48af5cd6a..f2964dbbed91 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -29,12 +29,6 @@ fn test_parse_pallet_with_task_enum_missing_impl() { Something, } - #[pallet::task_list] - impl frame_support::traits::Task for Task - where - T: TypeInfo, - {} - #[pallet::config] pub trait Config: frame_system::Config {} @@ -92,3 +86,79 @@ fn test_parse_pallet_missing_task_enum() { } } } + +#[test] +fn test_parse_pallet_task_list_in_wrong_place() { + assert_pallet_parse_error! { + #[manifest_dir("../../examples/basic")] + #[error_regex("can only be used on items within an `impl` statement.")] + #[frame_support::pallet] + pub mod pallet { + pub enum MyCustomTaskEnum { + Something, + } + + #[pallet::task_list] + pub fn something() { + println!("hey"); + } + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + } +} + +#[test] +fn test_parse_pallet_manual_task_enum_non_manual_impl() { + assert_pallet_parses! { + #[manifest_dir("../../examples/basic")] + #[frame_support::pallet] + pub mod pallet { + pub enum MyCustomTaskEnum { + Something, + } + + #[pallet::tasks] + impl frame_support::traits::Task for MyCustomTaskEnum + where + T: TypeInfo, + {} + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + } +} + +#[test] +fn test_parse_pallet_manual_task_enum_mismatch_ident() { + assert_pallet_parse_error! { + #[manifest_dir("../../examples/basic")] + #[error_regex("Missing `\\#\\[pallet::task_enum\\]` enum")] + #[frame_support::pallet] + pub mod pallet { + pub enum WrongIdent { + Something, + } + + #[pallet::tasks] + impl frame_support::traits::Task for MyCustomTaskEnum + where + T: TypeInfo, + {} + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + } +} From 802c9e70decf95fbcbe60ed7d0b218b741680d48 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 5 Oct 2023 10:41:15 -0400 Subject: [PATCH 071/177] allow omitting `#[pallet::tasks]` attribute --- .../procedural/src/pallet/parse/mod.rs | 67 ++++++++++++++++--- .../procedural/src/pallet/parse/tasks.rs | 19 ++++-- .../src/pallet/parse/tests/tasks.rs | 25 +++++++ 3 files changed, 94 insertions(+), 17 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 35342d77e6fb..aaf80ae248b2 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -222,16 +222,7 @@ impl Def { return Err(syn::Error::new(item_span, msg)) } - Self::resolve_manual_task_enum(&tasks, &mut task_enum, &items)?; - - // ensure either both or none of `(task_enum, tasks)` are specified - match (&task_enum, &tasks) { - (Some(_), None) => - return Err(syn::Error::new(item_span, "Missing `#[pallet::tasks]` impl")), - (None, Some(_)) => - return Err(syn::Error::new(item_span, "Missing `#[pallet::task_enum]` enum")), - _ => (), - } + Self::resolve_tasks(&item_span, &mut tasks, &mut task_enum, &items)?; let def = Def { item, @@ -265,6 +256,30 @@ impl Def { Ok(def) } + /// Performs extra logic checks necessary for the `#[pallet::tasks]` feature. + fn resolve_tasks( + item_span: &proc_macro2::Span, + tasks: &mut Option, + task_enum: &mut Option, + items: &Vec, + ) -> syn::Result<()> { + // fallback for manual (without macros) definition of tasks impl + Self::resolve_manual_tasks_impl(tasks, task_enum, items)?; + + // fallback for manual (without macros) definition of task enum + Self::resolve_manual_task_enum(tasks, task_enum, items)?; + + // ensure either both or none of `(task_enum, tasks)` are specified + match (&task_enum, &tasks) { + (Some(_), None) => + return Err(syn::Error::new(*item_span, "Missing `#[pallet::tasks]` impl")), + (None, Some(_)) => + return Err(syn::Error::new(*item_span, "Missing `#[pallet::task_enum]` enum")), + _ => (), + } + + Ok(()) + } /// Tries to locate task enum based on the tasks impl target if attribute is not specified /// but impl is present. If one is found, `task_enum` is set appropriately. fn resolve_manual_task_enum( @@ -289,6 +304,38 @@ impl Def { Ok(()) } + /// Tries to locate a manual tasks impl (an impl impling a trait whose last path segment is + /// `Task`) in the event that one has not been found already via the attribute macro + pub fn resolve_manual_tasks_impl( + tasks: &mut Option, + task_enum: &Option, + items: &Vec, + ) -> syn::Result<()> { + let None = tasks else { return Ok(()) }; + let mut result = None; + for item in items { + if let syn::Item::Impl(item_impl) = item { + let Some((_, path, _)) = &item_impl.trait_ else { continue }; + let Some(trait_last_seg) = path.segments.last() else { continue }; + let syn::Type::Path(target_path) = &*item_impl.self_ty else { continue }; + let target_path = target_path.path.segments.iter().collect::>(); + let (Some(target_ident), None) = (target_path.get(0), target_path.get(1)) else { + continue + }; + let matches_task_enum = match task_enum { + Some(task_enum) => task_enum.item_enum.ident == target_ident.ident, + None => true, + }; + if trait_last_seg.ident == "Task" && matches_task_enum { + result = Some(syn::parse2::(item_impl.to_token_stream())?); + break + } + } + } + *tasks = result; + Ok(()) + } + /// Check that usage of trait `Event` is consistent with the definition, i.e. it is declared /// and trait defines type RuntimeEvent, or not declared and no trait associated type. fn check_event_usage(&self) -> syn::Result<()> { diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index a1c97c95062c..bdb6ec6d6ae4 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -28,7 +28,7 @@ use syn::{ parse2, spanned::Spanned, token::{Bracket, Paren, PathSep, Pound}, - Attribute, Error, Expr, Ident, ImplItemFn, ItemEnum, ItemImpl, LitInt, Result, Token, + Attribute, Error, Expr, Ident, ImplItem, ImplItemFn, ItemEnum, ItemImpl, LitInt, Result, Token, }; pub mod keywords { @@ -70,12 +70,17 @@ impl syn::parse::Parse for TasksDef { "unexpected extra `#[pallet::tasks]` attribute", )) } - let tasks: Vec = item_impl - .items - .clone() - .into_iter() - .map(|item| parse2::(item.to_token_stream())) - .collect::>()?; + let tasks: Vec = if tasks_attr.is_some() { + item_impl + .items + .clone() + .into_iter() + .filter(|impl_item| matches!(impl_item, ImplItem::Fn(_))) + .map(|item| parse2::(item.to_token_stream())) + .collect::>()? + } else { + Vec::new() + }; let mut task_indices = HashSet::::new(); for task in tasks.iter() { let task_index = &task.index_attr.meta.index; diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index f2964dbbed91..fd11e8cce024 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -137,6 +137,31 @@ fn test_parse_pallet_manual_task_enum_non_manual_impl() { } } +#[test] +fn test_parse_pallet_non_manual_task_enum_manual_impl() { + assert_pallet_parses! { + #[manifest_dir("../../examples/basic")] + #[frame_support::pallet] + pub mod pallet { + #[pallet::task_enum] + pub enum MyCustomTaskEnum { + Something, + } + + impl frame_support::traits::Task for MyCustomTaskEnum + where + T: TypeInfo, + {} + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + } +} + #[test] fn test_parse_pallet_manual_task_enum_mismatch_ident() { assert_pallet_parse_error! { From a2f9e33cc3060b2edd39bfd5d66cc00652447553 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 5 Oct 2023 10:44:27 -0400 Subject: [PATCH 072/177] test omitting both `#[pallet::tasks]` and `#[pallet::task_enum]` --- .../src/pallet/parse/tests/tasks.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index fd11e8cce024..9f86fcbc3847 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -162,6 +162,30 @@ fn test_parse_pallet_non_manual_task_enum_manual_impl() { } } +#[test] +fn test_parse_pallet_manual_task_enum_manual_impl() { + assert_pallet_parses! { + #[manifest_dir("../../examples/basic")] + #[frame_support::pallet] + pub mod pallet { + pub enum MyCustomTaskEnum { + Something, + } + + impl frame_support::traits::Task for MyCustomTaskEnum + where + T: TypeInfo, + {} + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + } +} + #[test] fn test_parse_pallet_manual_task_enum_mismatch_ident() { assert_pallet_parse_error! { From cf388f67ae16500ffeed9eb7cb106cad697a1536 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 6 Oct 2023 00:31:50 -0400 Subject: [PATCH 073/177] fix task indices --- .../frame/examples/tasks-example/src/lib.rs | 10 +++- .../frame/examples/tasks-example/src/tests.rs | 49 ++++++++++++------- .../src/construct_runtime/expand/task.rs | 30 +++++++++++- substrate/frame/support/src/traits/tasks.rs | 18 +++---- 4 files changed, 77 insertions(+), 30 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index 2c027a4683a4..a4168562fdb2 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -71,12 +71,18 @@ pub mod pallet { { type Enumeration = sp_std::vec::IntoIter>; - const TASK_INDEX: Option = Some(0); - fn iter() -> Self::Enumeration { sp_std::vec![Task::Increment, Task::Decrement].into_iter() } + fn task_index(&self) -> u32 { + match self { + Task::Increment => 1, + Task::Decrement => 2, + Task::__Ignore(_, _) => unreachable!(), + } + } + fn is_valid(&self) -> bool { let value = Value::::get().unwrap(); match self { diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs index e364e6fb7657..047d9f8d7649 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -53,29 +53,44 @@ fn incrementing_and_decrementing_works() { #[test] fn task_enumerate_works() { - new_test_ext().execute_with(|| { - assert_eq!(crate::pallet::Task::::iter().collect::>().len(), 2); - }); + assert_eq!(crate::pallet::Task::::iter().collect::>().len(), 2); } #[test] fn runtime_task_enumerate_works_via_frame_system_config() { - new_test_ext().execute_with(|| { - assert_eq!( - ::RuntimeTask::iter().collect::>().len(), - 2 - ); - }); + assert_eq!(::RuntimeTask::iter().collect::>().len(), 2); } #[test] fn runtime_task_enumerate_works_via_pallet_config() { - new_test_ext().execute_with(|| { - assert_eq!( - ::RuntimeTask::iter() - .collect::>() - .len(), - 2 - ); - }); + assert_eq!( + ::RuntimeTask::iter() + .collect::>() + .len(), + 2 + ); +} + +#[test] +fn task_index_works_at_pallet_level() { + assert_eq!(crate::pallet::Task::::Increment.task_index(), 1); + assert_eq!(crate::pallet::Task::::Decrement.task_index(), 2); +} + +#[test] +fn task_index_works_at_runtime_level() { + assert_eq!( + ::RuntimeTask::TasksExample( + crate::pallet::Task::::Increment + ) + .task_index(), + 1 + ); + assert_eq!( + ::RuntimeTask::TasksExample( + crate::pallet::Task::::Decrement + ) + .task_index(), + 2 + ); } diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 14bc2f65f8f6..60ad46a746ee 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -29,6 +29,7 @@ pub fn expand_outer_task( let mut task_variants = Vec::new(); let mut variant_names = Vec::new(); let mut task_paths = Vec::new(); + let mut iter_generalizations = Vec::new(); for decl in pallet_decls { if let Some(_) = decl.find_part("Task") { let variant_name = &decl.name; @@ -53,6 +54,17 @@ pub fn expand_outer_task( variant_names.push(quote!(#variant_name)); task_paths.push(quote!(#path::pallet::Task)); + + iter_generalizations.push(quote! { + RuntimeTask::#variant_name(val) => { + for variant in #path::pallet::Task::<#runtime_name>::iter() { + let index = variant.task_index(); + if !all_task_indices.insert(index) { + panic!("duplicate task index `{index}` within pallet `{}`", stringify!(#path)); + } + } + } + }) } } @@ -77,8 +89,6 @@ pub fn expand_outer_task( impl #scrate::traits::Task for RuntimeTask { type Enumeration = #prelude::IntoIter; - const TASK_INDEX: Option = None; - fn is_valid(&self) -> bool { match self { #(RuntimeTask::#variant_names(val) => val.is_valid(),)* @@ -100,6 +110,22 @@ pub fn expand_outer_task( } } + fn task_index(&self) -> u32 { + // for debug builds, ensure at runtime there are no duplicate task indices + // within the pallet being accessed + #[cfg(debug_assertions)] { + let mut all_task_indices: std::collections::HashSet = std::collections::HashSet::new(); + match self { + #(#iter_generalizations,)* + _ => unreachable!(#INCOMPLETE_MATCH_QED), + } + } + match self { + #(RuntimeTask::#variant_names(val) => val.task_index(),)* + _ => unreachable!(#INCOMPLETE_MATCH_QED), + } + } + fn iter() -> Self::Enumeration { let mut all_tasks = Vec::new(); #(all_tasks.extend(#task_paths::iter().map(RuntimeTask::from).collect::>());)* diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index 60f11d051932..86ac7e95bb98 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -37,11 +37,6 @@ pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { /// An [`Iterator`] over tasks of this type used as the return type for `enumerate`. type Enumeration: Iterator; - /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks. - /// - /// Set to [`None`] for the aggregated `RuntimeTask` type. - const TASK_INDEX: Option; - /// Inspects the pallet's state and enumerates tasks of this type. fn iter() -> Self::Enumeration; @@ -54,10 +49,15 @@ pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { /// Returns the weight of executing this `Task`. fn weight(&self) -> Weight; - /// A unique value representing this `Task`. Analogous to `call_index`, but for tasks.' + /// A unique value representing this `Task` within the current pallet. Analogous to + /// `call_index`, but for tasks.' /// - /// Set to [`None`] for the aggregated `RuntimeTask` type. - fn task_index(&self) -> Option { - Self::TASK_INDEX + /// This value should be unique within the current pallet and can overlap with task indices + /// in other pallets. + fn task_index(&self) -> u32; + + /// Convenience method that provides access to `Self::iter()` on a particular task instance. + fn instance_iter(&self) -> Self::Enumeration { + Self::iter() } } From 9722741e18729111a8027fda6b70b5231fbbb687 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 6 Oct 2023 00:47:45 -0400 Subject: [PATCH 074/177] clean up --- substrate/frame/support/src/traits/tasks.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index 86ac7e95bb98..9ef3272a47ba 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -55,9 +55,4 @@ pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { /// This value should be unique within the current pallet and can overlap with task indices /// in other pallets. fn task_index(&self) -> u32; - - /// Convenience method that provides access to `Self::iter()` on a particular task instance. - fn instance_iter(&self) -> Self::Enumeration { - Self::iter() - } } From b3baffb3a5e1d35a824350a99775e0a7c98c3735 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 6 Oct 2023 12:10:22 -0400 Subject: [PATCH 075/177] add TasksDef::generate() --- .../procedural/src/pallet/parse/tasks.rs | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index bdb6ec6d6ae4..1819de848c8e 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -25,7 +25,7 @@ use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{quote, ToTokens}; use syn::{ parse::ParseStream, - parse2, + parse2, parse_quote, spanned::Spanned, token::{Bracket, Paren, PathSep, Pound}, Attribute, Error, Expr, Ident, ImplItem, ImplItemFn, ItemEnum, ItemImpl, LitInt, Result, Token, @@ -110,6 +110,25 @@ pub struct TaskEnumDef { pub item_enum: ItemEnum, } +impl TaskEnumDef { + pub fn generate(tasks: &TasksDef, instance: bool) -> Self { + let variants = tasks.tasks.iter().map(|task| task.item.sig.ident.clone()); + let type_impl_generics = match instance { + false => quote!(T: Config), + true => quote!(T: Config, I: 'static), + }; + parse_quote! { + #[pallet::task_enum] + pub enum Task<#type_impl_generics> { + #( + #[allow(non_camel_case_types)] + #variants + ),* + } + } + } +} + impl syn::parse::Parse for TaskEnumDef { fn parse(input: ParseStream) -> Result { let item_enum = input.parse::()?; @@ -145,6 +164,7 @@ pub struct TaskDef { pub condition_attr: TaskConditionAttr, pub list_attr: TaskListAttr, pub normal_attrs: Vec, + pub item: ImplItemFn, } impl syn::parse::Parse for TaskDef { @@ -153,7 +173,7 @@ impl syn::parse::Parse for TaskDef { // we only want to activate TaskAttrType parsing errors for tasks-related attributes, // so we filter them here let (task_attrs, normal_attrs): (Vec<_>, Vec<_>) = - item.attrs.into_iter().partition(|attr| { + item.attrs.clone().into_iter().partition(|attr| { let mut path_segs = attr.path().segments.iter(); let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { return false @@ -245,7 +265,7 @@ impl syn::parse::Parse for TaskDef { let condition_attr = condition_attr.try_into().expect("we check the type above; QED"); let list_attr = list_attr.try_into().expect("we check the type above; QED"); - Ok(TaskDef { index_attr, condition_attr, list_attr, normal_attrs }) + Ok(TaskDef { index_attr, condition_attr, list_attr, normal_attrs, item }) } } From d9903d414ee01732adb52ee17d41ab58c3de928d Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 6 Oct 2023 15:20:03 -0400 Subject: [PATCH 076/177] auto-generate task enum if it is not specified --- .../procedural/src/pallet/expand/tasks.rs | 13 +++++++++++- .../procedural/src/pallet/parse/mod.rs | 11 ++++------ .../procedural/src/pallet/parse/tasks.rs | 10 +++------- .../procedural/src/pallet/parse/tests/mod.rs | 20 +++++++++++-------- .../src/pallet/parse/tests/tasks.rs | 18 ++++++++--------- 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 134b1bb8ecbb..522fc98e2be1 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -1,7 +1,18 @@ -use crate::pallet::Def; +use crate::pallet::{parse::tasks::*, Def}; use proc_macro2::TokenStream as TokenStream2; use quote::quote; +use syn::spanned::Spanned; pub fn expand_tasks(def: &mut Def) -> TokenStream2 { + let tasks = &def.tasks; + if let Some(tasks_def) = tasks { + if def.task_enum.is_none() { + def.task_enum = Some(TaskEnumDef::generate( + &tasks_def, + def.type_decl_bounded_generics(tasks_def.item_impl.span()), + )); + } + } + let _task_enum = &def.task_enum; quote!() } diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index aaf80ae248b2..b449e507c647 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -269,17 +269,14 @@ impl Def { // fallback for manual (without macros) definition of task enum Self::resolve_manual_task_enum(tasks, task_enum, items)?; - // ensure either both or none of `(task_enum, tasks)` are specified - match (&task_enum, &tasks) { - (Some(_), None) => - return Err(syn::Error::new(*item_span, "Missing `#[pallet::tasks]` impl")), - (None, Some(_)) => - return Err(syn::Error::new(*item_span, "Missing `#[pallet::task_enum]` enum")), - _ => (), + // ensure that if `task_enum` is specified, `tasks` is also specified + if let (Some(_), None) = (&task_enum, &tasks) { + return Err(syn::Error::new(*item_span, "Missing `#[pallet::tasks]` impl")) } Ok(()) } + /// Tries to locate task enum based on the tasks impl target if attribute is not specified /// but impl is present. If one is found, `task_enum` is set appropriately. fn resolve_manual_task_enum( diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 1819de848c8e..3dc02c5206e7 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -21,7 +21,7 @@ use std::collections::HashSet; use crate::assert_error_matches; use derive_syn_parse::Parse; -use proc_macro2::{Span, TokenStream as TokenStream2}; +use proc_macro2::TokenStream as TokenStream2; use quote::{quote, ToTokens}; use syn::{ parse::ParseStream, @@ -111,15 +111,11 @@ pub struct TaskEnumDef { } impl TaskEnumDef { - pub fn generate(tasks: &TasksDef, instance: bool) -> Self { + pub fn generate(tasks: &TasksDef, type_decl_bounded_generics: TokenStream2) -> Self { let variants = tasks.tasks.iter().map(|task| task.item.sig.ident.clone()); - let type_impl_generics = match instance { - false => quote!(T: Config), - true => quote!(T: Config, I: 'static), - }; parse_quote! { #[pallet::task_enum] - pub enum Task<#type_impl_generics> { + pub enum Task<#type_decl_bounded_generics> { #( #[allow(non_camel_case_types)] #variants diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 1361546402cd..25ea137ffb6a 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -48,11 +48,15 @@ macro_rules! assert_pallet_parses { #[manifest_dir($manifest_dir:literal)] $($tokens:tt)* ) => { - $crate::pallet::parse::tests::simulate_manifest_dir($manifest_dir, || { - $crate::pallet::parse::Def::try_from(syn::parse_quote! { - $($tokens)* - }, false).unwrap(); - }); + { + let mut pallet: Option<$crate::pallet::parse::Def> = None; + $crate::pallet::parse::tests::simulate_manifest_dir($manifest_dir, core::panic::AssertUnwindSafe(|| { + pallet = Some($crate::pallet::parse::Def::try_from(syn::parse_quote! { + $($tokens)* + }, false).unwrap()); + })); + pallet.unwrap() + } } } @@ -87,7 +91,7 @@ macro_rules! assert_pallet_parse_error { /// /// This function uses a [`Mutex`] to avoid a race condition created when multiple tests try to /// modify and then restore the `CARGO_MANIFEST_DIR` ENV var in an overlapping way. -pub fn simulate_manifest_dir, F: FnMut() + std::panic::UnwindSafe>( +pub fn simulate_manifest_dir, F: FnOnce() + std::panic::UnwindSafe>( path: P, closure: F, ) { @@ -121,7 +125,7 @@ mod tasks; #[test] fn test_parse_minimal_pallet() { - assert_pallet_parses!( + assert_pallet_parses! { #[manifest_dir("../../examples/basic")] #[frame_support::pallet] pub mod pallet { @@ -131,7 +135,7 @@ fn test_parse_minimal_pallet() { #[pallet::pallet] pub struct Pallet(_); } - ); + }; } #[test] diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index 9f86fcbc3847..7b0babd2db01 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -67,9 +67,8 @@ fn test_parse_pallet_with_task_enum_wrong_attribute() { #[test] fn test_parse_pallet_missing_task_enum() { - assert_pallet_parse_error! { + assert_pallet_parses! { #[manifest_dir("../../examples/basic")] - #[error_regex("Missing `\\#\\[pallet::task_enum\\]` enum")] #[frame_support::pallet] pub mod pallet { #[pallet::tasks] @@ -84,7 +83,7 @@ fn test_parse_pallet_missing_task_enum() { #[pallet::pallet] pub struct Pallet(_); } - } + }; } #[test] @@ -134,7 +133,7 @@ fn test_parse_pallet_manual_task_enum_non_manual_impl() { #[pallet::pallet] pub struct Pallet(_); } - } + }; } #[test] @@ -159,7 +158,7 @@ fn test_parse_pallet_non_manual_task_enum_manual_impl() { #[pallet::pallet] pub struct Pallet(_); } - } + }; } #[test] @@ -183,14 +182,13 @@ fn test_parse_pallet_manual_task_enum_manual_impl() { #[pallet::pallet] pub struct Pallet(_); } - } + }; } #[test] fn test_parse_pallet_manual_task_enum_mismatch_ident() { - assert_pallet_parse_error! { + let pallet = assert_pallet_parses! { #[manifest_dir("../../examples/basic")] - #[error_regex("Missing `\\#\\[pallet::task_enum\\]` enum")] #[frame_support::pallet] pub mod pallet { pub enum WrongIdent { @@ -209,5 +207,7 @@ fn test_parse_pallet_manual_task_enum_mismatch_ident() { #[pallet::pallet] pub struct Pallet(_); } - } + }; + assert!(pallet.task_enum.is_none()); // note: will be filled in by expansion + assert!(pallet.tasks.is_some()); } From 0c355580fc59d9a4897059f685bea71f02bec3b4 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 6 Oct 2023 15:27:57 -0400 Subject: [PATCH 077/177] change auto-generated task enum name to _Task to prevent collisions --- substrate/frame/support/procedural/src/pallet/parse/tasks.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 3dc02c5206e7..272ccf516263 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -114,8 +114,9 @@ impl TaskEnumDef { pub fn generate(tasks: &TasksDef, type_decl_bounded_generics: TokenStream2) -> Self { let variants = tasks.tasks.iter().map(|task| task.item.sig.ident.clone()); parse_quote! { + #[allow(non_camel_case_types)] #[pallet::task_enum] - pub enum Task<#type_decl_bounded_generics> { + pub enum _Task<#type_decl_bounded_generics> { #( #[allow(non_camel_case_types)] #variants From bee216f02e0975e04d26caf85aa5ce024ee3e262 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 6 Oct 2023 15:35:43 -0400 Subject: [PATCH 078/177] add TODOs --- substrate/frame/support/procedural/src/pallet/expand/tasks.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 522fc98e2be1..c0e6171e4e4f 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -14,5 +14,7 @@ pub fn expand_tasks(def: &mut Def) -> TokenStream2 { } } let _task_enum = &def.task_enum; + // TODO: add ToTokens impl for TaskEnumDef so we can output it here + // TODO: add ToTokens impl for TasksDef so we can output it here quote!() } From cd280abf172fe3e32ead9ef8d2be41569429bf34 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 9 Oct 2023 13:43:43 -0400 Subject: [PATCH 079/177] expansion for task enum --- .../frame/examples/tasks-example/src/lib.rs | 10 ++- .../procedural/src/pallet/expand/tasks.rs | 80 +++++++++++++++++-- .../procedural/src/pallet/parse/mod.rs | 10 ++- .../procedural/src/pallet/parse/tasks.rs | 25 ++---- 4 files changed, 98 insertions(+), 27 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index a4168562fdb2..3b3f9c1115de 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -19,7 +19,6 @@ use core::marker::PhantomData; -use codec::{Decode, Encode}; use frame_support::dispatch::DispatchResult; // Re-export pallet items so that they can be accessed from the crate namespace. pub use pallet::*; @@ -36,7 +35,14 @@ pub mod pallet { use frame_system::pallet_prelude::*; // this can be auto-generated from the macros - #[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo)] + #[derive( + Clone, + PartialEq, + Eq, + frame_support::pallet_prelude::Encode, + frame_support::pallet_prelude::Decode, + frame_support::pallet_prelude::TypeInfo, + )] pub enum Task { Increment, Decrement, diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index c0e6171e4e4f..212f848261a4 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -1,7 +1,75 @@ use crate::pallet::{parse::tasks::*, Def}; use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use syn::spanned::Spanned; +use quote::{quote, ToTokens}; +use syn::{parse_quote, spanned::Spanned}; + +impl TaskEnumDef { + pub fn generate( + tasks: &TasksDef, + type_decl_bounded_generics: TokenStream2, + type_use_generics: TokenStream2, + ) -> Self { + let variants = tasks.tasks.iter().map(|task| task.item.sig.ident.clone()); + let mut task_enum_def: TaskEnumDef = parse_quote! { + /// Auto-generated enum that encapsulates all tasks defined by this pallet. + /// + /// Conceptually similar to the [`Call`] enum, but for tasks. This is only + /// generated if there are tasks present in this pallet. + #[allow(non_camel_case_types)] + #[pallet::task_enum] + pub enum Task<#type_decl_bounded_generics> { + #( + #[allow(non_camel_case_types)] + #variants + ),* + } + }; + task_enum_def.type_use_generics = type_use_generics; + task_enum_def + } +} + +impl ToTokens for TaskEnumDef { + fn to_tokens(&self, tokens: &mut TokenStream2) { + let item_enum = &self.item_enum; + let ident = &item_enum.ident; + let vis = &item_enum.vis; + let attrs = &item_enum.attrs; + let generics = &item_enum.generics; + let variants = &item_enum.variants; + let scrate = &self.scrate; + let type_use_generics = &self.type_use_generics; + if self.attr.is_some() { + // `item_enum` is short-hand / generated enum + tokens.extend(quote! { + #(#attrs)* + #[derive( + Clone, + PartialEq, + Eq, + #scrate::pallet_prelude::Encode, + #scrate::pallet_prelude::Decode, + #scrate::pallet_prelude::TypeInfo, + )] + #vis enum #ident #generics { + #variants + #[doc(hidden)] + #[codec(skip)] + __Ignore(core::marker::PhantomData, #scrate::Never), + } + + impl core::fmt::Debug for #ident<#type_use_generics> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct(stringify!(#ident)).field("value", self).finish() + } + } + }); + } else { + // `item_enum` is a manually specified enum (no attribute) + tokens.extend(item_enum.to_token_stream()); + } + } +} pub fn expand_tasks(def: &mut Def) -> TokenStream2 { let tasks = &def.tasks; @@ -10,11 +78,13 @@ pub fn expand_tasks(def: &mut Def) -> TokenStream2 { def.task_enum = Some(TaskEnumDef::generate( &tasks_def, def.type_decl_bounded_generics(tasks_def.item_impl.span()), + def.type_use_generics(tasks_def.item_impl.span()), )); } } - let _task_enum = &def.task_enum; - // TODO: add ToTokens impl for TaskEnumDef so we can output it here + let task_enum = &def.task_enum; // TODO: add ToTokens impl for TasksDef so we can output it here - quote!() + quote! { + #task_enum + } } diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index b449e507c647..a3cf4b57a9af 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -222,7 +222,7 @@ impl Def { return Err(syn::Error::new(item_span, msg)) } - Self::resolve_tasks(&item_span, &mut tasks, &mut task_enum, &items)?; + Self::resolve_tasks(&item_span, &mut tasks, &mut task_enum, items)?; let def = Def { item, @@ -261,7 +261,7 @@ impl Def { item_span: &proc_macro2::Span, tasks: &mut Option, task_enum: &mut Option, - items: &Vec, + items: &mut Vec, ) -> syn::Result<()> { // fallback for manual (without macros) definition of tasks impl Self::resolve_manual_tasks_impl(tasks, task_enum, items)?; @@ -282,7 +282,7 @@ impl Def { fn resolve_manual_task_enum( tasks: &Option, task_enum: &mut Option, - items: &Vec, + items: &mut Vec, ) -> syn::Result<()> { let (None, Some(tasks)) = (&task_enum, &tasks) else { return Ok(()) }; let syn::Type::Path(type_path) = &*tasks.item_impl.self_ty else { return Ok(()) }; @@ -293,6 +293,10 @@ impl Def { if let syn::Item::Enum(item_enum) = item { if item_enum.ident == seg.ident { result = Some(syn::parse2::(item_enum.to_token_stream())?); + // replace item with a no-op because it will be handled by the expansion of + // `task_enum`. We use a no-op instead of simply removing it from the vec + // so that any indices collected by `Def::try_from` remain accurate + *item = syn::Item::Verbatim(quote::quote!()); break } } diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 272ccf516263..005d86fbda17 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -21,6 +21,7 @@ use std::collections::HashSet; use crate::assert_error_matches; use derive_syn_parse::Parse; +use frame_support_procedural_tools::generate_crate_access_2018; use proc_macro2::TokenStream as TokenStream2; use quote::{quote, ToTokens}; use syn::{ @@ -108,22 +109,8 @@ pub type PalletTaskEnumAttr = PalletTaskAttr; pub struct TaskEnumDef { pub attr: Option, pub item_enum: ItemEnum, -} - -impl TaskEnumDef { - pub fn generate(tasks: &TasksDef, type_decl_bounded_generics: TokenStream2) -> Self { - let variants = tasks.tasks.iter().map(|task| task.item.sig.ident.clone()); - parse_quote! { - #[allow(non_camel_case_types)] - #[pallet::task_enum] - pub enum _Task<#type_decl_bounded_generics> { - #( - #[allow(non_camel_case_types)] - #variants - ),* - } - } - } + pub scrate: Ident, + pub type_use_generics: TokenStream2, } impl syn::parse::Parse for TaskEnumDef { @@ -151,7 +138,11 @@ impl syn::parse::Parse for TaskEnumDef { } attr = Some(parse2(found_attr.to_token_stream())?); } - Ok(TaskEnumDef { attr, item_enum }) + // We do this here because it would be improper to do something fallible like this at + // the expansion phase. Fallible stuff should happen during parsing. + let scrate = generate_crate_access_2018("frame-support")?; + let type_use_generics = quote!(T); + Ok(TaskEnumDef { attr, item_enum, scrate, type_use_generics }) } } From 13d28f1d7a4f022c487380defffe0c8a668a7c31 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 9 Oct 2023 18:29:59 -0400 Subject: [PATCH 080/177] enum expansion WIP --- .../frame/examples/tasks-example/src/lib.rs | 40 +--- .../procedural/src/pallet/expand/tasks.rs | 12 +- .../procedural/src/pallet/parse/mod.rs | 12 +- .../procedural/src/pallet/parse/tasks.rs | 176 +++++++++++------- .../src/pallet/parse/tests/tasks.rs | 34 +++- 5 files changed, 164 insertions(+), 110 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index 3b3f9c1115de..87e2ca1c3741 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -17,8 +17,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -use core::marker::PhantomData; - use frame_support::dispatch::DispatchResult; // Re-export pallet items so that they can be accessed from the crate namespace. pub use pallet::*; @@ -34,30 +32,6 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; - // this can be auto-generated from the macros - #[derive( - Clone, - PartialEq, - Eq, - frame_support::pallet_prelude::Encode, - frame_support::pallet_prelude::Decode, - frame_support::pallet_prelude::TypeInfo, - )] - pub enum Task { - Increment, - Decrement, - #[doc(hidden)] - #[codec(skip)] - __Ignore(PhantomData, frame_support::Never), - } - - // this can be auto-generated from the macros and will always be the same - impl core::fmt::Debug for Task { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("Task").field("value", self).finish() - } - } - // we can automatically inject `InvalidTask` into an existing Error enum by finding it via // visitor pattern, otherwise we can just emit an error enum containing just our // `InvalidTask` variant. Alternatively we could just expect that `InvalidTask` is included @@ -78,13 +52,13 @@ pub mod pallet { type Enumeration = sp_std::vec::IntoIter>; fn iter() -> Self::Enumeration { - sp_std::vec![Task::Increment, Task::Decrement].into_iter() + sp_std::vec![Task::increment, Task::decrement].into_iter() } fn task_index(&self) -> u32 { match self { - Task::Increment => 1, - Task::Decrement => 2, + Task::increment => 1, + Task::decrement => 2, Task::__Ignore(_, _) => unreachable!(), } } @@ -92,15 +66,15 @@ pub mod pallet { fn is_valid(&self) -> bool { let value = Value::::get().unwrap(); match self { - Task::Increment => value < 255, - Task::Decrement => value > 0, + Task::increment => value < 255, + Task::decrement => value > 0, Task::__Ignore(_, _) => unreachable!(), } } fn run(&self) -> Result<(), DispatchError> { match self { - Task::Increment => { + Task::increment => { // Get the value and check if it can be incremented let value = Value::::get().unwrap_or_default(); if value >= 255 { @@ -112,7 +86,7 @@ pub mod pallet { Ok(()) } }, - Task::Decrement => { + Task::decrement => { // Get the value and check if it can be decremented let value = Value::::get().unwrap_or_default(); if value == 0 { diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 212f848261a4..eb8ef09fb6f4 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -1,5 +1,6 @@ use crate::pallet::{parse::tasks::*, Def}; use proc_macro2::TokenStream as TokenStream2; +use proc_utils::PrettyPrint; use quote::{quote, ToTokens}; use syn::{parse_quote, spanned::Spanned}; @@ -9,7 +10,10 @@ impl TaskEnumDef { type_decl_bounded_generics: TokenStream2, type_use_generics: TokenStream2, ) -> Self { - let variants = tasks.tasks.iter().map(|task| task.item.sig.ident.clone()); + let variants = match tasks.tasks_attr.is_some() { + true => tasks.tasks.iter().map(|task| task.item.sig.ident.clone()).collect::>(), + false => Vec::new(), + }; let mut task_enum_def: TaskEnumDef = parse_quote! { /// Auto-generated enum that encapsulates all tasks defined by this pallet. /// @@ -84,7 +88,9 @@ pub fn expand_tasks(def: &mut Def) -> TokenStream2 { } let task_enum = &def.task_enum; // TODO: add ToTokens impl for TasksDef so we can output it here - quote! { + let output = quote! { #task_enum - } + }; + output.pretty_print(); + output } diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index a3cf4b57a9af..a1c932b81ccc 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -270,8 +270,16 @@ impl Def { Self::resolve_manual_task_enum(tasks, task_enum, items)?; // ensure that if `task_enum` is specified, `tasks` is also specified - if let (Some(_), None) = (&task_enum, &tasks) { - return Err(syn::Error::new(*item_span, "Missing `#[pallet::tasks]` impl")) + match (&task_enum, &tasks) { + (Some(_), None) => + return Err(syn::Error::new(*item_span, "Missing `#[pallet::tasks]` impl")), + (None, Some(tasks)) if tasks.tasks_attr.is_none() => + return Err(syn::Error::new( + tasks.item_impl.impl_token.span(), + "A `#[pallet::tasks]` attribute must be attached to your `Task` impl if the \ + task enum has been omitted", + )), + _ => (), } Ok(()) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 005d86fbda17..41e9ab703e3b 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -20,13 +20,17 @@ use std::collections::HashSet; #[cfg(test)] use crate::assert_error_matches; +#[cfg(test)] +use crate::pallet::parse::tests::simulate_manifest_dir; + use derive_syn_parse::Parse; use frame_support_procedural_tools::generate_crate_access_2018; use proc_macro2::TokenStream as TokenStream2; +use proc_utils::PrettyPrint; use quote::{quote, ToTokens}; use syn::{ parse::ParseStream, - parse2, parse_quote, + parse2, spanned::Spanned, token::{Bracket, Paren, PathSep, Pound}, Attribute, Error, Expr, Ident, ImplItem, ImplItemFn, ItemEnum, ItemImpl, LitInt, Result, Token, @@ -53,10 +57,15 @@ pub struct TasksDef { impl syn::parse::Parse for TasksDef { fn parse(input: ParseStream) -> Result { let item_impl: ItemImpl = input.parse()?; + println!("________"); + item_impl.pretty_print(); + println!("________"); let (tasks_attrs, normal_attrs): (Vec<_>, Vec<_>) = item_impl.attrs.clone().into_iter().partition(|attr| { let mut path_segs = attr.path().segments.iter(); - let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { + let (Some(prefix), Some(suffix), None) = + (path_segs.next(), path_segs.next(), path_segs.next()) + else { return false }; prefix.ident == "pallet" && suffix.ident == "tasks" @@ -71,6 +80,7 @@ impl syn::parse::Parse for TasksDef { "unexpected extra `#[pallet::tasks]` attribute", )) } + println!("IS_SOME: {}", tasks_attr.is_some()); let tasks: Vec = if tasks_attr.is_some() { item_impl .items @@ -115,29 +125,44 @@ pub struct TaskEnumDef { impl syn::parse::Parse for TaskEnumDef { fn parse(input: ParseStream) -> Result { - let item_enum = input.parse::()?; + let mut item_enum = input.parse::()?; let mut attr = None; - for found_attr in &item_enum.attrs { - let segs = found_attr - .path() - .segments - .iter() - .map(|seg| seg.ident.clone()) - .collect::>(); - let (Some(seg1), Some(_), None) = (segs.get(0), segs.get(1), segs.get(2)) else { - continue - }; - if seg1 != "pallet" { - continue - } - if attr.is_some() { - return Err(Error::new( - found_attr.span(), - "only one `#[pallet::_]` attribute is supported on this item", - )) - } - attr = Some(parse2(found_attr.to_token_stream())?); + let mut duplicate = None; + item_enum.attrs = item_enum + .attrs + .iter() + .filter(|found_attr| { + let segs = found_attr + .path() + .segments + .iter() + .map(|seg| seg.ident.clone()) + .collect::>(); + let (Some(seg1), Some(_), None) = (segs.get(0), segs.get(1), segs.get(2)) else { + return true + }; + if seg1 != "pallet" { + return true + } + if attr.is_some() { + duplicate = Some(found_attr.span()); + } + attr = Some(found_attr.to_token_stream()); + false + }) + .cloned() + .collect(); + if let Some(span) = duplicate { + return Err(Error::new( + span, + "only one `#[pallet::_]` attribute is supported on this item", + )) } + let attr = match attr { + Some(attr) => Some(parse2(attr)?), + None => None, + }; + // We do this here because it would be improper to do something fallible like this at // the expansion phase. Fallible stuff should happen during parsing. let scrate = generate_crate_access_2018("frame-support")?; @@ -473,7 +498,7 @@ fn test_parse_tasks_attr() { #[test] fn test_parse_tasks_def_basic() { - parse2::(quote! { + let parsed = parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { /// Add a pair of numbers into the totals and remove them. @@ -491,6 +516,7 @@ fn test_parse_tasks_def_basic() { } }) .unwrap(); + assert_eq!(parsed.tasks.len(), 1); } #[test] @@ -640,69 +666,81 @@ fn test_parse_tasks_def_extra_tasks_attribute() { #[test] fn test_parse_task_enum_def_basic() { - parse2::(quote! { - #[pallet::task_enum] - pub enum Task { - Increment, - Decrement, - } - }) - .unwrap(); + simulate_manifest_dir("../../examples/basic", || { + parse2::(quote! { + #[pallet::task_enum] + pub enum Task { + Increment, + Decrement, + } + }) + .unwrap(); + }); } #[test] fn test_parse_task_enum_def_non_task_name() { - parse2::(quote! { - #[pallet::task_enum] - pub enum Something { - Foo - } - }) - .unwrap(); + simulate_manifest_dir("../../examples/basic", || { + parse2::(quote! { + #[pallet::task_enum] + pub enum Something { + Foo + } + }) + .unwrap(); + }); } #[test] fn test_parse_task_enum_def_missing_attr_allowed() { - parse2::(quote! { - pub enum Task { - Increment, - Decrement, - } - }) - .unwrap(); + simulate_manifest_dir("../../examples/basic", || { + parse2::(quote! { + pub enum Task { + Increment, + Decrement, + } + }) + .unwrap(); + }); } #[test] fn test_parse_task_enum_def_missing_attr_alternate_name_allowed() { - parse2::(quote! { - pub enum Foo { - Red, - } - }) - .unwrap(); + simulate_manifest_dir("../../examples/basic", || { + parse2::(quote! { + pub enum Foo { + Red, + } + }) + .unwrap(); + }); } #[test] fn test_parse_task_enum_def_wrong_attr() { - assert_error_matches!( - parse2::(quote! { - #[pallet::something] - pub enum Task { - Increment, - Decrement, - } - }), - "expected `task_enum`" - ) + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::something] + pub enum Task { + Increment, + Decrement, + } + }), + "expected `task_enum`" + ); + }); } #[test] fn test_parse_task_enum_def_wrong_item() { - assert_error_matches!( - parse2::(quote! { - #[pallet::task_enum] - pub struct Something; - }), - "expected `enum`" - ) + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::task_enum] + pub struct Something; + }), + "expected `enum`" + ); + }); } diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index 7b0babd2db01..4ba1d20a3b58 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -72,6 +72,7 @@ fn test_parse_pallet_missing_task_enum() { #[frame_support::pallet] pub mod pallet { #[pallet::tasks] + #[cfg(test)] // aha, this means it's being eaten impl frame_support::traits::Task for Task where T: TypeInfo, @@ -111,6 +112,34 @@ fn test_parse_pallet_task_list_in_wrong_place() { } } +#[test] +fn test_parse_pallet_manual_tasks_impl_without_manual_tasks_enum() { + assert_pallet_parse_error! { + #[manifest_dir("../../examples/basic")] + #[error_regex(".*attribute must be attached to your.*")] + #[frame_support::pallet] + pub mod pallet { + + impl frame_support::traits::Task for Task + where + T: TypeInfo, + { + type Enumeration = sp_std::vec::IntoIter>; + + fn iter() -> Self::Enumeration { + sp_std::vec![Task::increment, Task::decrement].into_iter() + } + } + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + } + } +} + #[test] fn test_parse_pallet_manual_task_enum_non_manual_impl() { assert_pallet_parses! { @@ -187,8 +216,9 @@ fn test_parse_pallet_manual_task_enum_manual_impl() { #[test] fn test_parse_pallet_manual_task_enum_mismatch_ident() { - let pallet = assert_pallet_parses! { + assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] + #[error_regex(".*attribute must be attached to your.*")] #[frame_support::pallet] pub mod pallet { pub enum WrongIdent { @@ -208,6 +238,4 @@ fn test_parse_pallet_manual_task_enum_mismatch_ident() { pub struct Pallet(_); } }; - assert!(pallet.task_enum.is_none()); // note: will be filled in by expansion - assert!(pallet.tasks.is_some()); } From f525a4153f0c9ec1410473b5b76ecf180e0fad37 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 13 Oct 2023 13:35:03 -0400 Subject: [PATCH 081/177] fix handling of missing attr --- .../procedural/src/pallet/parse/mod.rs | 26 +++++++++++++------ .../procedural/src/pallet/parse/tasks.rs | 4 --- .../src/pallet/parse/tests/tasks.rs | 3 +-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index a1c932b81ccc..5c87d11953b2 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -134,8 +134,15 @@ impl Def { }, Some(PalletAttr::RuntimeCall(cw, span)) if call.is_none() => call = Some(call::CallDef::try_from(span, index, item, dev_mode, cw)?), - Some(PalletAttr::Tasks(_)) if tasks.is_none() => - tasks = Some(syn::parse2::(get_tokens(item))?), + Some(PalletAttr::Tasks(_)) if tasks.is_none() => { + let item_tokens = get_tokens(item); + // `TasksDef::parse` needs to know if attr was provided so we artificially + // re-insert it here + tasks = Some(syn::parse2::(quote::quote! { + #[pallet::tasks] + #item_tokens + })?); + } Some(PalletAttr::TaskCondition(span)) => return Err(syn::Error::new( span, "`#[pallet::task_condition]` can only be used on items within an `impl` statement." @@ -273,12 +280,15 @@ impl Def { match (&task_enum, &tasks) { (Some(_), None) => return Err(syn::Error::new(*item_span, "Missing `#[pallet::tasks]` impl")), - (None, Some(tasks)) if tasks.tasks_attr.is_none() => - return Err(syn::Error::new( - tasks.item_impl.impl_token.span(), - "A `#[pallet::tasks]` attribute must be attached to your `Task` impl if the \ - task enum has been omitted", - )), + (None, Some(tasks)) => + if tasks.tasks_attr.is_none() { + return Err(syn::Error::new( + tasks.item_impl.impl_token.span(), + "A `#[pallet::tasks]` attribute must be attached to your `Task` impl if the \ + task enum has been omitted", + )) + } else { + }, _ => (), } diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 41e9ab703e3b..e1028ca6e6ca 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -57,9 +57,6 @@ pub struct TasksDef { impl syn::parse::Parse for TasksDef { fn parse(input: ParseStream) -> Result { let item_impl: ItemImpl = input.parse()?; - println!("________"); - item_impl.pretty_print(); - println!("________"); let (tasks_attrs, normal_attrs): (Vec<_>, Vec<_>) = item_impl.attrs.clone().into_iter().partition(|attr| { let mut path_segs = attr.path().segments.iter(); @@ -80,7 +77,6 @@ impl syn::parse::Parse for TasksDef { "unexpected extra `#[pallet::tasks]` attribute", )) } - println!("IS_SOME: {}", tasks_attr.is_some()); let tasks: Vec = if tasks_attr.is_some() { item_impl .items diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index 4ba1d20a3b58..0623f031d049 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -216,9 +216,8 @@ fn test_parse_pallet_manual_task_enum_manual_impl() { #[test] fn test_parse_pallet_manual_task_enum_mismatch_ident() { - assert_pallet_parse_error! { + assert_pallet_parses! { #[manifest_dir("../../examples/basic")] - #[error_regex(".*attribute must be attached to your.*")] #[frame_support::pallet] pub mod pallet { pub enum WrongIdent { From 5890ffcfa4d74d67936bdbda406e3633a01fedd1 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 13 Oct 2023 15:12:21 -0400 Subject: [PATCH 082/177] include scrate on TasksDef because we need it in expansion --- .../procedural/src/pallet/expand/tasks.rs | 68 +++++ .../procedural/src/pallet/parse/tasks.rs | 273 ++++++++++-------- 2 files changed, 217 insertions(+), 124 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index eb8ef09fb6f4..16ef3d353c6b 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -75,6 +75,74 @@ impl ToTokens for TaskEnumDef { } } +impl ToTokens for TasksDef { + fn to_tokens(&self, tokens: &mut TokenStream2) { + tokens.extend(quote! { + impl frame_support::traits::Task for Task + where + T: TypeInfo, + { + type Enumeration = sp_std::vec::IntoIter>; + + fn iter() -> Self::Enumeration { + sp_std::vec![Task::increment, Task::decrement].into_iter() + } + + fn task_index(&self) -> u32 { + match self { + Task::increment => 1, + Task::decrement => 2, + Task::__Ignore(_, _) => unreachable!(), + } + } + + fn is_valid(&self) -> bool { + let value = Value::::get().unwrap(); + match self { + Task::increment => value < 255, + Task::decrement => value > 0, + Task::__Ignore(_, _) => unreachable!(), + } + } + + fn run(&self) -> Result<(), DispatchError> { + match self { + Task::increment => { + // Get the value and check if it can be incremented + let value = Value::::get().unwrap_or_default(); + if value >= 255 { + Err(Error::::ValueOverflow.into()) + } else { + let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Incremented { new_val }); + Ok(()) + } + }, + Task::decrement => { + // Get the value and check if it can be decremented + let value = Value::::get().unwrap_or_default(); + if value == 0 { + Err(Error::::ValueUnderflow.into()) + } else { + let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Decremented { new_val }); + Ok(()) + } + }, + Task::__Ignore(_, _) => unreachable!(), + } + } + + fn weight(&self) -> Weight { + Weight::default() + } + } + }) + } +} + pub fn expand_tasks(def: &mut Def) -> TokenStream2 { let tasks = &def.tasks; if let Some(tasks_def) = tasks { diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index e1028ca6e6ca..afb28d97f3f8 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -26,7 +26,6 @@ use crate::pallet::parse::tests::simulate_manifest_dir; use derive_syn_parse::Parse; use frame_support_procedural_tools::generate_crate_access_2018; use proc_macro2::TokenStream as TokenStream2; -use proc_utils::PrettyPrint; use quote::{quote, ToTokens}; use syn::{ parse::ParseStream, @@ -52,6 +51,7 @@ pub struct TasksDef { pub tasks_attr: Option, pub tasks: Vec, pub item_impl: ItemImpl, + pub scrate: Ident, } impl syn::parse::Parse for TasksDef { @@ -100,7 +100,12 @@ impl syn::parse::Parse for TasksDef { } let mut item_impl = item_impl; item_impl.attrs = normal_attrs; - Ok(TasksDef { tasks_attr, item_impl, tasks }) + + // We do this here because it would be improper to do something fallible like this at + // the expansion phase. Fallible stuff should happen during parsing. + let scrate = generate_crate_access_2018("frame-support")?; + + Ok(TasksDef { tasks_attr, item_impl, tasks, scrate }) } } @@ -162,7 +167,9 @@ impl syn::parse::Parse for TaskEnumDef { // We do this here because it would be improper to do something fallible like this at // the expansion phase. Fallible stuff should happen during parsing. let scrate = generate_crate_access_2018("frame-support")?; + let type_use_generics = quote!(T); + Ok(TaskEnumDef { attr, item_enum, scrate, type_use_generics }) } } @@ -494,170 +501,188 @@ fn test_parse_tasks_attr() { #[test] fn test_parse_tasks_def_basic() { - let parsed = parse2::(quote! { - #[pallet::tasks] - impl, I: 'static> Pallet { - /// Add a pair of numbers into the totals and remove them. - #[pallet::task_list(Numbers::::iter_keys())] - #[pallet::task_condition(|i| Numbers::::contains_key(i))] - #[pallet::task_index(0)] - pub fn add_number_into_total(i: u32) -> DispatchResult { - let v = Numbers::::take(i).ok_or(Error::::NotFound)?; - Total::::mutate(|(total_keys, total_values)| { - *total_keys += i; - *total_values += v; - }); - Ok(()) - } - } - }) - .unwrap(); - assert_eq!(parsed.tasks.len(), 1); -} - -#[test] -fn test_parse_tasks_def_duplicate_index() { - assert_error_matches!( - parse2::(quote! { + simulate_manifest_dir("../../examples/basic", || { + let parsed = parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { - #[pallet::task_list(Something::iter())] - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_index(0)] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) - } - + /// Add a pair of numbers into the totals and remove them. #[pallet::task_list(Numbers::::iter_keys())] #[pallet::task_condition(|i| Numbers::::contains_key(i))] #[pallet::task_index(0)] - pub fn bar(i: u32) -> DispatchResult { + pub fn add_number_into_total(i: u32) -> DispatchResult { + let v = Numbers::::take(i).ok_or(Error::::NotFound)?; + Total::::mutate(|(total_keys, total_values)| { + *total_keys += i; + *total_values += v; + }); Ok(()) } } - }), - "duplicate task index `0`" - ); + }) + .unwrap(); + assert_eq!(parsed.tasks.len(), 1); + }); +} + +#[test] +fn test_parse_tasks_def_duplicate_index() { + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_list(Something::iter())] + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_index(0)] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } + + #[pallet::task_list(Numbers::::iter_keys())] + #[pallet::task_condition(|i| Numbers::::contains_key(i))] + #[pallet::task_index(0)] + pub fn bar(i: u32) -> DispatchResult { + Ok(()) + } + } + }), + "duplicate task index `0`" + ); + }); } #[test] fn test_parse_tasks_def_missing_task_list() { - assert_error_matches!( - parse2::(quote! { - #[pallet::tasks] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_index(0)] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_index(0)] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } } - } - }), - r"missing `#\[pallet::task_list\(\.\.\)\]`" - ); + }), + r"missing `#\[pallet::task_list\(\.\.\)\]`" + ); + }); } #[test] fn test_parse_tasks_def_missing_task_condition() { - assert_error_matches!( - parse2::(quote! { - #[pallet::tasks] - impl, I: 'static> Pallet { - #[pallet::task_list(Something::iter())] - #[pallet::task_index(0)] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_list(Something::iter())] + #[pallet::task_index(0)] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } } - } - }), - r"missing `#\[pallet::task_condition\(\.\.\)\]`" - ); + }), + r"missing `#\[pallet::task_condition\(\.\.\)\]`" + ); + }); } #[test] fn test_parse_tasks_def_missing_task_index() { - assert_error_matches!( - parse2::(quote! { - #[pallet::tasks] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_list(Something::iter())] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_list(Something::iter())] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } } - } - }), - r"missing `#\[pallet::task_index\(\.\.\)\]`" - ); + }), + r"missing `#\[pallet::task_index\(\.\.\)\]`" + ); + }); } #[test] fn test_parse_tasks_def_unexpected_extra_task_list_attr() { - assert_error_matches!( - parse2::(quote! { - #[pallet::tasks] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_index(0)] - #[pallet::task_list(Something::iter())] - #[pallet::task_list(SomethingElse::iter())] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_index(0)] + #[pallet::task_list(Something::iter())] + #[pallet::task_list(SomethingElse::iter())] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } } - } - }), - r"unexpected extra `#\[pallet::task_list\(\.\.\)\]`" - ); + }), + r"unexpected extra `#\[pallet::task_list\(\.\.\)\]`" + ); + }); } #[test] fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { - assert_error_matches!( - parse2::(quote! { - #[pallet::tasks] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_condition(|i| i % 4 == 0)] - #[pallet::task_index(0)] - #[pallet::task_list(Something::iter())] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_condition(|i| i % 4 == 0)] + #[pallet::task_index(0)] + #[pallet::task_list(Something::iter())] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } } - } - }), - r"unexpected extra `#\[pallet::task_condition\(\.\.\)\]`" - ); + }), + r"unexpected extra `#\[pallet::task_condition\(\.\.\)\]`" + ); + }); } #[test] fn test_parse_tasks_def_unexpected_extra_task_index_attr() { - assert_error_matches!( - parse2::(quote! { - #[pallet::tasks] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_index(0)] - #[pallet::task_index(0)] - #[pallet::task_list(Something::iter())] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_index(0)] + #[pallet::task_index(0)] + #[pallet::task_list(Something::iter())] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } } - } - }), - r"unexpected extra `#\[pallet::task_index\(\.\.\)\]`" - ); + }), + r"unexpected extra `#\[pallet::task_index\(\.\.\)\]`" + ); + }); } #[test] fn test_parse_tasks_def_extra_tasks_attribute() { - assert_error_matches!( - parse2::(quote! { - #[pallet::tasks] - #[pallet::tasks] - impl, I: 'static> Pallet {} - }), - r"unexpected extra `#\[pallet::tasks\]` attribute" - ); + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + #[pallet::tasks] + impl, I: 'static> Pallet {} + }), + r"unexpected extra `#\[pallet::tasks\]` attribute" + ); + }); } #[test] From b2271f9432bd61090dca9be9a0f843611fbc629b Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 16 Oct 2023 11:48:48 -0400 Subject: [PATCH 083/177] before switching to individual task structs --- .../frame/examples/tasks-example/src/lib.rs | 2 +- .../procedural/src/pallet/expand/tasks.rs | 21 ++++++++++++------- .../procedural/src/pallet/parse/tasks.rs | 20 ++++++++++++++++-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index 87e2ca1c3741..68c74ccbf073 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -51,7 +51,7 @@ pub mod pallet { { type Enumeration = sp_std::vec::IntoIter>; - fn iter() -> Self::Enumeration { + fn iter(&self) -> Self::Enumeration { sp_std::vec![Task::increment, Task::decrement].into_iter() } diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 16ef3d353c6b..89987f664d49 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -77,15 +77,22 @@ impl ToTokens for TaskEnumDef { impl ToTokens for TasksDef { fn to_tokens(&self, tokens: &mut TokenStream2) { + let scrate = &self.scrate; + let enum_ident = &self.enum_ident; + let enum_arguments = &self.enum_arguments; + let enum_use = quote!(#enum_ident #enum_arguments); + let task_fn_idents = self.tasks.iter().map(|task| &task.item.sig.ident); + let sp_std = quote!(#scrate::__private::sp_std); + let impl_generics = &self.item_impl.generics; tokens.extend(quote! { - impl frame_support::traits::Task for Task + impl #impl_generics #scrate::traits::Task for #enum_use where - T: TypeInfo, + T: #scrate::pallet_prelude::TypeInfo, { - type Enumeration = sp_std::vec::IntoIter>; + type Enumeration = #sp_std::vec::IntoIter<#enum_use>; fn iter() -> Self::Enumeration { - sp_std::vec![Task::increment, Task::decrement].into_iter() + #sp_std::vec![#(#enum_ident::#task_fn_idents),*].into_iter() } fn task_index(&self) -> u32 { @@ -105,7 +112,7 @@ impl ToTokens for TasksDef { } } - fn run(&self) -> Result<(), DispatchError> { + fn run(&self) -> Result<(), #scrate::pallet_prelude::DispatchError> { match self { Task::increment => { // Get the value and check if it can be incremented @@ -135,8 +142,8 @@ impl ToTokens for TasksDef { } } - fn weight(&self) -> Weight { - Weight::default() + fn weight(&self) -> #scrate::pallet_prelude::Weight { + #scrate::pallet_prelude::Weight::default() } } }) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index afb28d97f3f8..d25504e0a49e 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -32,7 +32,8 @@ use syn::{ parse2, spanned::Spanned, token::{Bracket, Paren, PathSep, Pound}, - Attribute, Error, Expr, Ident, ImplItem, ImplItemFn, ItemEnum, ItemImpl, LitInt, Result, Token, + Attribute, Error, Expr, Ident, ImplItem, ImplItemFn, ItemEnum, ItemImpl, LitInt, PathArguments, + Result, Token, TypePath, }; pub mod keywords { @@ -52,6 +53,8 @@ pub struct TasksDef { pub tasks: Vec, pub item_impl: ItemImpl, pub scrate: Ident, + pub enum_ident: Ident, + pub enum_arguments: PathArguments, } impl syn::parse::Parse for TasksDef { @@ -101,11 +104,24 @@ impl syn::parse::Parse for TasksDef { let mut item_impl = item_impl; item_impl.attrs = normal_attrs; + // we require the path on the impl to be a TypePath + let enum_path = parse2::(item_impl.self_ty.to_token_stream())?; + let segments = enum_path.path.segments.iter().collect::>(); + let (Some(last_seg), None) = (segments.get(0), segments.get(1)) else { + return Err(Error::new( + enum_path.span(), + "if specified manually, the task enum must be defined locally in this \ + pallet and cannot be a re-export", + )) + }; + let enum_ident = last_seg.ident.clone(); + let enum_arguments = last_seg.arguments.clone(); + // We do this here because it would be improper to do something fallible like this at // the expansion phase. Fallible stuff should happen during parsing. let scrate = generate_crate_access_2018("frame-support")?; - Ok(TasksDef { tasks_attr, item_impl, tasks, scrate }) + Ok(TasksDef { tasks_attr, item_impl, tasks, scrate, enum_ident, enum_arguments }) } } From ff8bc5edf54f18f19b283fc5b139764b83154508 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 16 Oct 2023 12:25:46 -0400 Subject: [PATCH 084/177] WIP --- .../frame/examples/tasks-example/src/lib.rs | 88 +++++++------------ .../procedural/src/pallet/expand/tasks.rs | 11 ++- .../procedural/src/pallet/parse/tasks.rs | 23 +---- 3 files changed, 47 insertions(+), 75 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index 68c74ccbf073..9ababaf1be6c 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -44,67 +44,45 @@ pub mod pallet { ValueUnderflow, } - // this will be auto-generated from `#[pallet::tasks]` - impl frame_support::traits::Task for Task - where - T: TypeInfo, - { - type Enumeration = sp_std::vec::IntoIter>; - - fn iter(&self) -> Self::Enumeration { - sp_std::vec![Task::increment, Task::decrement].into_iter() - } - - fn task_index(&self) -> u32 { - match self { - Task::increment => 1, - Task::decrement => 2, - Task::__Ignore(_, _) => unreachable!(), - } - } - - fn is_valid(&self) -> bool { + #[pallet::tasks] + impl frame_support::traits::Task for Task { + #[pallet::task_index(0)] + #[pallet::task_condition(|| { let value = Value::::get().unwrap(); - match self { - Task::increment => value < 255, - Task::decrement => value > 0, - Task::__Ignore(_, _) => unreachable!(), + value < 255 + })] + #[pallet::task_list(Vec::>::new())] + fn increment() -> DispatchResult { + // Get the value and check if it can be incremented + let value = Value::::get().unwrap_or_default(); + if value >= 255 { + Err(Error::::ValueOverflow.into()) + } else { + let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Incremented { new_val }); + Ok(()) } } - fn run(&self) -> Result<(), DispatchError> { - match self { - Task::increment => { - // Get the value and check if it can be incremented - let value = Value::::get().unwrap_or_default(); - if value >= 255 { - Err(Error::::ValueOverflow.into()) - } else { - let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Incremented { new_val }); - Ok(()) - } - }, - Task::decrement => { - // Get the value and check if it can be decremented - let value = Value::::get().unwrap_or_default(); - if value == 0 { - Err(Error::::ValueUnderflow.into()) - } else { - let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Decremented { new_val }); - Ok(()) - } - }, - Task::__Ignore(_, _) => unreachable!(), + #[pallet::task_index(1)] + #[pallet::task_condition(|| { + let value = Value::::get().unwrap(); + value > 0 + })] + #[pallet::task_list(Vec::>::new())] + fn decrement() -> DispatchResult { + // Get the value and check if it can be decremented + let value = Value::::get().unwrap_or_default(); + if value == 0 { + Err(Error::::ValueUnderflow.into()) + } else { + let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Decremented { new_val }); + Ok(()) } } - - fn weight(&self) -> Weight { - Weight::default() - } } #[pallet::config] diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 89987f664d49..98c1de92a85c 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -11,7 +11,15 @@ impl TaskEnumDef { type_use_generics: TokenStream2, ) -> Self { let variants = match tasks.tasks_attr.is_some() { - true => tasks.tasks.iter().map(|task| task.item.sig.ident.clone()).collect::>(), + true => tasks + .tasks + .iter() + .map(|task| { + let ident = &task.item.sig.ident; + let args = &task.item.sig.inputs; + quote!(#ident(#args)) + }) + .collect::>(), false => Vec::new(), }; let mut task_enum_def: TaskEnumDef = parse_quote! { @@ -29,6 +37,7 @@ impl TaskEnumDef { } }; task_enum_def.type_use_generics = type_use_generics; + task_enum_def.pretty_print(); task_enum_def } } diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index d25504e0a49e..d0644830927d 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -33,7 +33,7 @@ use syn::{ spanned::Spanned, token::{Bracket, Paren, PathSep, Pound}, Attribute, Error, Expr, Ident, ImplItem, ImplItemFn, ItemEnum, ItemImpl, LitInt, PathArguments, - Result, Token, TypePath, + Result, TypePath, }; pub mod keywords { @@ -335,12 +335,6 @@ pub struct TaskConditionAttrMeta { #[paren] _paren: Paren, #[inside(_paren)] - pub pipe1: Token![|], - #[inside(_paren)] - pub ident: Ident, - #[inside(_paren)] - pub pipe2: Token![|], - #[inside(_paren)] pub expr: Expr, } @@ -368,11 +362,8 @@ impl ToTokens for TaskListAttrMeta { impl ToTokens for TaskConditionAttrMeta { fn to_tokens(&self, tokens: &mut TokenStream2) { let task_condition = self.task_condition; - let pipe1 = self.pipe1; - let ident = &self.ident; - let pipe2 = self.pipe2; let expr = &self.expr; - tokens.extend(quote!(#task_condition(#pipe1 #ident #pipe2 #expr))); + tokens.extend(quote!(#task_condition(#expr))); } } @@ -493,14 +484,8 @@ fn test_parse_task_index() { fn test_parse_task_condition() { parse2::(quote!(#[pallet::task_condition(|x| x.is_some())])).unwrap(); parse2::(quote!(#[pallet::task_condition(|_x| some_expr())])).unwrap(); - assert_error_matches!( - parse2::(quote!(#[pallet::task_condition(x.is_some())])), - "expected `|`" - ); - assert_error_matches!( - parse2::(quote!(#[pallet::task_condition(|| something())])), - "expected identifier" - ); + parse2::(quote!(#[pallet::task_condition(|| some_expr())])).unwrap(); + parse2::(quote!(#[pallet::task_condition(some_expr())])).unwrap(); } #[test] From 4a59c3397ac4f5075ee9a48d6c53e870a3e7dfc3 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 16 Oct 2023 14:14:18 -0400 Subject: [PATCH 085/177] expansion almost working --- .../procedural/src/pallet/expand/tasks.rs | 66 ++++++++++++++----- .../procedural/src/pallet/parse/tasks.rs | 50 ++++++++++++++ 2 files changed, 100 insertions(+), 16 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 98c1de92a85c..cb9bc78c08d5 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -1,8 +1,9 @@ use crate::pallet::{parse::tasks::*, Def}; +use derive_syn_parse::Parse; use proc_macro2::TokenStream as TokenStream2; use proc_utils::PrettyPrint; use quote::{quote, ToTokens}; -use syn::{parse_quote, spanned::Spanned}; +use syn::{parse_quote, spanned::Spanned, Item, ItemEnum, ItemImpl}; impl TaskEnumDef { pub fn generate( @@ -16,8 +17,12 @@ impl TaskEnumDef { .iter() .map(|task| { let ident = &task.item.sig.ident; - let args = &task.item.sig.inputs; - quote!(#ident(#args)) + let args = task.item.sig.inputs.iter().collect::>(); + if args.is_empty() { + quote!(#ident) + } else { + quote!(#ident(#(#args),*)) + } }) .collect::>(), false => Vec::new(), @@ -32,12 +37,11 @@ impl TaskEnumDef { pub enum Task<#type_decl_bounded_generics> { #( #[allow(non_camel_case_types)] - #variants - ),* + #variants, + )* } }; task_enum_def.type_use_generics = type_use_generics; - task_enum_def.pretty_print(); task_enum_def } } @@ -155,13 +159,44 @@ impl ToTokens for TasksDef { #scrate::pallet_prelude::Weight::default() } } - }) + }); + } +} + +pub fn expand_tasks_impl(def: &mut Def) -> TokenStream2 { + let Some(tasks) = &mut def.tasks else { return quote!() }; + let output: ItemImpl = parse_quote!(#tasks); + output.pretty_print(); + let Some(content) = &mut def.item.content else { return quote!() }; + for item in content.1.iter_mut() { + let Item::Impl(item_impl) = item else { continue }; + let Some(trait_) = &item_impl.trait_ else { continue }; + let Some(last_seg) = trait_.1.segments.last() else { continue }; + if last_seg.ident == "Task" { + *item_impl = output; + break + } } + quote!() +} + +#[derive(Parse)] +pub struct ExpandedTaskEnum { + pub item_enum: ItemEnum, + pub debug_impl: ItemImpl, +} + +pub fn expand_task_enum(def: &mut Def) -> TokenStream2 { + let Some(task_enum) = &mut def.task_enum else { return quote!() }; + let ExpandedTaskEnum { item_enum, debug_impl } = parse_quote!(#task_enum); + item_enum.pretty_print(); + debug_impl.pretty_print(); + task_enum.item_enum = item_enum; + quote!(#debug_impl) } pub fn expand_tasks(def: &mut Def) -> TokenStream2 { - let tasks = &def.tasks; - if let Some(tasks_def) = tasks { + if let Some(tasks_def) = &def.tasks { if def.task_enum.is_none() { def.task_enum = Some(TaskEnumDef::generate( &tasks_def, @@ -170,11 +205,10 @@ pub fn expand_tasks(def: &mut Def) -> TokenStream2 { )); } } - let task_enum = &def.task_enum; - // TODO: add ToTokens impl for TasksDef so we can output it here - let output = quote! { - #task_enum - }; - output.pretty_print(); - output + let tasks_extra_output = expand_tasks_impl(def); + let task_enum_extra_output = expand_task_enum(def); + quote! { + #tasks_extra_output + #task_enum_extra_output + } } diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index d0644830927d..004c5aa1301e 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -525,6 +525,56 @@ fn test_parse_tasks_def_basic() { }); } +#[test] +fn test_parse_tasks_def_basic_increment_decrement() { + simulate_manifest_dir("../../examples/basic", || { + let parsed = parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + /// Get the value and check if it can be incremented + #[pallet::task_index(0)] + #[pallet::task_condition(|| { + let value = Value::::get().unwrap(); + value < 255 + })] + #[pallet::task_list(Vec::>::new())] + fn increment() -> DispatchResult { + let value = Value::::get().unwrap_or_default(); + if value >= 255 { + Err(Error::::ValueOverflow.into()) + } else { + let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Incremented { new_val }); + Ok(()) + } + } + + // Get the value and check if it can be decremented + #[pallet::task_index(1)] + #[pallet::task_condition(|| { + let value = Value::::get().unwrap(); + value > 0 + })] + #[pallet::task_list(Vec::>::new())] + fn decrement() -> DispatchResult { + let value = Value::::get().unwrap_or_default(); + if value == 0 { + Err(Error::::ValueUnderflow.into()) + } else { + let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; + Value::::put(new_val); + Pallet::::deposit_event(Event::Decremented { new_val }); + Ok(()) + } + } + } + }) + .unwrap(); + assert_eq!(parsed.tasks.len(), 2); + }); +} + #[test] fn test_parse_tasks_def_duplicate_index() { simulate_manifest_dir("../../examples/basic", || { From 80d515ccfede567f45bc6bd4888bbd37df0ec4c3 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 16 Oct 2023 14:53:26 -0400 Subject: [PATCH 086/177] example pallet tests passing :boom: --- substrate/frame/examples/tasks-example/src/tests.rs | 8 ++++---- .../support/procedural/src/pallet/expand/tasks.rs | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs index 047d9f8d7649..5eaf6820cfa1 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -73,22 +73,22 @@ fn runtime_task_enumerate_works_via_pallet_config() { #[test] fn task_index_works_at_pallet_level() { - assert_eq!(crate::pallet::Task::::Increment.task_index(), 1); - assert_eq!(crate::pallet::Task::::Decrement.task_index(), 2); + assert_eq!(crate::pallet::Task::::increment.task_index(), 1); + assert_eq!(crate::pallet::Task::::decrement.task_index(), 2); } #[test] fn task_index_works_at_runtime_level() { assert_eq!( ::RuntimeTask::TasksExample( - crate::pallet::Task::::Increment + crate::pallet::Task::::increment ) .task_index(), 1 ); assert_eq!( ::RuntimeTask::TasksExample( - crate::pallet::Task::::Decrement + crate::pallet::Task::::decrement ) .task_index(), 2 diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index cb9bc78c08d5..2518b08976a6 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -166,7 +166,7 @@ impl ToTokens for TasksDef { pub fn expand_tasks_impl(def: &mut Def) -> TokenStream2 { let Some(tasks) = &mut def.tasks else { return quote!() }; let output: ItemImpl = parse_quote!(#tasks); - output.pretty_print(); + // output.pretty_print(); let Some(content) = &mut def.item.content else { return quote!() }; for item in content.1.iter_mut() { let Item::Impl(item_impl) = item else { continue }; @@ -189,10 +189,13 @@ pub struct ExpandedTaskEnum { pub fn expand_task_enum(def: &mut Def) -> TokenStream2 { let Some(task_enum) = &mut def.task_enum else { return quote!() }; let ExpandedTaskEnum { item_enum, debug_impl } = parse_quote!(#task_enum); - item_enum.pretty_print(); - debug_impl.pretty_print(); - task_enum.item_enum = item_enum; - quote!(#debug_impl) + // item_enum.pretty_print(); + // debug_impl.pretty_print(); + // task_enum.item_enum = item_enum; + quote! { + #item_enum + #debug_impl + } } pub fn expand_tasks(def: &mut Def) -> TokenStream2 { From cc24864b0cc0bd99a2611e215c0ca11907cf5b80 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 16 Oct 2023 15:19:36 -0400 Subject: [PATCH 087/177] clean up --- substrate/frame/support/procedural/src/pallet/expand/tasks.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 2518b08976a6..1a4007ec8a4d 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -191,7 +191,6 @@ pub fn expand_task_enum(def: &mut Def) -> TokenStream2 { let ExpandedTaskEnum { item_enum, debug_impl } = parse_quote!(#task_enum); // item_enum.pretty_print(); // debug_impl.pretty_print(); - // task_enum.item_enum = item_enum; quote! { #item_enum #debug_impl From 29a7ce64c869f5061b0b9c453c99c218da70fd6f Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 16 Oct 2023 16:20:07 -0400 Subject: [PATCH 088/177] upgrade syntax --- .../support/procedural/src/pallet/parse/mod.rs | 4 +--- .../support/procedural/src/pallet/parse/tasks.rs | 14 +++++++------- .../procedural/src/pallet/parse/tests/mod.rs | 4 ++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 0d0f7df88e80..4b7cbb21dca3 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -41,9 +41,7 @@ pub mod validate_unsigned; pub mod tests; use composite::{keyword::CompositeKeyword, CompositeDef}; -use frame_support_procedural_tools::{ - generate_access_from_frame_or_crate, generate_crate_access_2018, -}; +use frame_support_procedural_tools::generate_access_from_frame_or_crate; use quote::ToTokens; use syn::spanned::Spanned; diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 004c5aa1301e..9be9085a7778 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -24,7 +24,7 @@ use crate::assert_error_matches; use crate::pallet::parse::tests::simulate_manifest_dir; use derive_syn_parse::Parse; -use frame_support_procedural_tools::generate_crate_access_2018; +use frame_support_procedural_tools::generate_access_from_frame_or_crate; use proc_macro2::TokenStream as TokenStream2; use quote::{quote, ToTokens}; use syn::{ @@ -32,8 +32,8 @@ use syn::{ parse2, spanned::Spanned, token::{Bracket, Paren, PathSep, Pound}, - Attribute, Error, Expr, Ident, ImplItem, ImplItemFn, ItemEnum, ItemImpl, LitInt, PathArguments, - Result, TypePath, + Attribute, Error, Expr, Ident, ImplItem, ImplItemFn, ItemEnum, ItemImpl, LitInt, Path, + PathArguments, Result, TypePath, }; pub mod keywords { @@ -52,7 +52,7 @@ pub struct TasksDef { pub tasks_attr: Option, pub tasks: Vec, pub item_impl: ItemImpl, - pub scrate: Ident, + pub scrate: Path, pub enum_ident: Ident, pub enum_arguments: PathArguments, } @@ -119,7 +119,7 @@ impl syn::parse::Parse for TasksDef { // We do this here because it would be improper to do something fallible like this at // the expansion phase. Fallible stuff should happen during parsing. - let scrate = generate_crate_access_2018("frame-support")?; + let scrate = generate_access_from_frame_or_crate("frame-support")?; Ok(TasksDef { tasks_attr, item_impl, tasks, scrate, enum_ident, enum_arguments }) } @@ -136,7 +136,7 @@ pub type PalletTaskEnumAttr = PalletTaskAttr; pub struct TaskEnumDef { pub attr: Option, pub item_enum: ItemEnum, - pub scrate: Ident, + pub scrate: Path, pub type_use_generics: TokenStream2, } @@ -182,7 +182,7 @@ impl syn::parse::Parse for TaskEnumDef { // We do this here because it would be improper to do something fallible like this at // the expansion phase. Fallible stuff should happen during parsing. - let scrate = generate_crate_access_2018("frame-support")?; + let scrate = generate_access_from_frame_or_crate("frame-support")?; let type_use_generics = quote!(T); diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 25ea137ffb6a..2e96700ba0cf 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -86,8 +86,8 @@ macro_rules! assert_pallet_parse_error { /// the closure panics. /// /// This is useful in tests of `Def::try_from` and other pallet-related methods that internally -/// make use of [`generate_crate_access_2018`], which is sensitive to entries in the "current" -/// `Cargo.toml` files. +/// make use of [`generate_access_from_frame_or_crate`], which is sensitive to entries in the +/// "current" `Cargo.toml` files. /// /// This function uses a [`Mutex`] to avoid a race condition created when multiple tests try to /// modify and then restore the `CARGO_MANIFEST_DIR` ENV var in an overlapping way. From e9901c610740398814ddb8f496f15f2256b79114 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 18 Oct 2023 13:52:24 -0400 Subject: [PATCH 089/177] add missing RuntimeTask --- cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index a0eef7e43a4b..10bc16a09486 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -188,6 +188,7 @@ impl frame_system::Config for Runtime { type Block = Block; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; + type RuntimeTask = RuntimeTask; type BlockHashCount = BlockHashCount; type DbWeight = RocksDbWeight; type Version = Version; @@ -224,6 +225,7 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; From 71d20dfbb0258a1fa9a0ddca07337348e48079aa Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 18 Oct 2023 16:08:28 -0400 Subject: [PATCH 090/177] fix warnings --- substrate/frame/examples/tasks-example/src/lib.rs | 1 - substrate/frame/support/procedural/src/pallet/expand/tasks.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index 9ababaf1be6c..51da9596dd5a 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -20,7 +20,6 @@ use frame_support::dispatch::DispatchResult; // Re-export pallet items so that they can be accessed from the crate namespace. pub use pallet::*; -use sp_runtime::DispatchError; pub mod mock; pub mod tests; diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 1a4007ec8a4d..10fec9bf9d8c 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -1,7 +1,6 @@ use crate::pallet::{parse::tasks::*, Def}; use derive_syn_parse::Parse; use proc_macro2::TokenStream as TokenStream2; -use proc_utils::PrettyPrint; use quote::{quote, ToTokens}; use syn::{parse_quote, spanned::Spanned, Item, ItemEnum, ItemImpl}; From b0302c322c1e5f91be73bb1b15ccbe63f794100d Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 19 Oct 2023 01:32:52 -0400 Subject: [PATCH 091/177] fix unreachable code issue --- .../support/procedural/src/construct_runtime/expand/task.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 60ad46a746ee..0e6599c513a4 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -89,6 +89,7 @@ pub fn expand_outer_task( impl #scrate::traits::Task for RuntimeTask { type Enumeration = #prelude::IntoIter; + #[allow(unreachable_code)] fn is_valid(&self) -> bool { match self { #(RuntimeTask::#variant_names(val) => val.is_valid(),)* @@ -96,6 +97,7 @@ pub fn expand_outer_task( } } + #[allow(unreachable_code)] fn run(&self) -> Result<(), #scrate::traits::tasks::prelude::DispatchError> { match self { #(RuntimeTask::#variant_names(val) => val.run(),)* @@ -103,6 +105,7 @@ pub fn expand_outer_task( } } + #[allow(unreachable_code)] fn weight(&self) -> #scrate::pallet_prelude::Weight { match self { #(RuntimeTask::#variant_names(val) => val.weight(),)* @@ -110,6 +113,7 @@ pub fn expand_outer_task( } } + #[allow(unreachable_code)] fn task_index(&self) -> u32 { // for debug builds, ensure at runtime there are no duplicate task indices // within the pallet being accessed From e62dea3554c8bbfd45aa4c1d354a95aa99297862 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <> Date: Fri, 27 Oct 2023 15:26:55 +0530 Subject: [PATCH 092/177] Adds task index expansion --- .../frame/support/procedural/src/pallet/expand/tasks.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 10fec9bf9d8c..b9879be616eb 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -94,6 +94,8 @@ impl ToTokens for TasksDef { let enum_arguments = &self.enum_arguments; let enum_use = quote!(#enum_ident #enum_arguments); let task_fn_idents = self.tasks.iter().map(|task| &task.item.sig.ident); + let task_fn_idents_clone = task_fn_idents.clone(); + let task_indices = self.tasks.iter().map(|task| &task.index_attr.meta.index); let sp_std = quote!(#scrate::__private::sp_std); let impl_generics = &self.item_impl.generics; tokens.extend(quote! { @@ -109,8 +111,7 @@ impl ToTokens for TasksDef { fn task_index(&self) -> u32 { match self { - Task::increment => 1, - Task::decrement => 2, + #(#enum_ident::#task_fn_idents_clone => #task_indices),*, Task::__Ignore(_, _) => unreachable!(), } } From 3ab1e574db23b76550fcb4aa6bb91734cff6a06f Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <> Date: Fri, 27 Oct 2023 15:35:15 +0530 Subject: [PATCH 093/177] Adds task condition expansion --- .../support/procedural/src/pallet/expand/tasks.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index b9879be616eb..2cb4a2508463 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -93,9 +93,11 @@ impl ToTokens for TasksDef { let enum_ident = &self.enum_ident; let enum_arguments = &self.enum_arguments; let enum_use = quote!(#enum_ident #enum_arguments); - let task_fn_idents = self.tasks.iter().map(|task| &task.item.sig.ident); - let task_fn_idents_clone = task_fn_idents.clone(); + + let task_fn_idents = self.tasks.iter().map(|task| &task.item.sig.ident).collect::>(); let task_indices = self.tasks.iter().map(|task| &task.index_attr.meta.index); + let task_conditions = self.tasks.iter().map(|task| &task.condition_attr.meta.expr); + let sp_std = quote!(#scrate::__private::sp_std); let impl_generics = &self.item_impl.generics; tokens.extend(quote! { @@ -111,16 +113,14 @@ impl ToTokens for TasksDef { fn task_index(&self) -> u32 { match self { - #(#enum_ident::#task_fn_idents_clone => #task_indices),*, + #(#enum_ident::#task_fn_idents => #task_indices),*, Task::__Ignore(_, _) => unreachable!(), } } fn is_valid(&self) -> bool { - let value = Value::::get().unwrap(); match self { - Task::increment => value < 255, - Task::decrement => value > 0, + #(#enum_ident::#task_fn_idents => (#task_conditions)()),*, Task::__Ignore(_, _) => unreachable!(), } } From 62145622e6b8c23359a334f8c4c5e94a9351195e Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <> Date: Fri, 27 Oct 2023 18:11:05 +0530 Subject: [PATCH 094/177] Adds task function expansion --- .../procedural/src/pallet/expand/tasks.rs | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 2cb4a2508463..3608e26979ad 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -97,6 +97,7 @@ impl ToTokens for TasksDef { let task_fn_idents = self.tasks.iter().map(|task| &task.item.sig.ident).collect::>(); let task_indices = self.tasks.iter().map(|task| &task.index_attr.meta.index); let task_conditions = self.tasks.iter().map(|task| &task.condition_attr.meta.expr); + let task_fn_blocks = self.tasks.iter().map(|task| &task.item.block); let sp_std = quote!(#scrate::__private::sp_std); let impl_generics = &self.item_impl.generics; @@ -127,30 +128,7 @@ impl ToTokens for TasksDef { fn run(&self) -> Result<(), #scrate::pallet_prelude::DispatchError> { match self { - Task::increment => { - // Get the value and check if it can be incremented - let value = Value::::get().unwrap_or_default(); - if value >= 255 { - Err(Error::::ValueOverflow.into()) - } else { - let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Incremented { new_val }); - Ok(()) - } - }, - Task::decrement => { - // Get the value and check if it can be decremented - let value = Value::::get().unwrap_or_default(); - if value == 0 { - Err(Error::::ValueUnderflow.into()) - } else { - let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Decremented { new_val }); - Ok(()) - } - }, + #(#enum_ident::#task_fn_idents => #task_fn_blocks),*, Task::__Ignore(_, _) => unreachable!(), } } From 3b59b32ad769e3bc88a79412b494e187e0a3dc07 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <> Date: Fri, 27 Oct 2023 18:27:42 +0530 Subject: [PATCH 095/177] Adds RuntimeTask in SoloChainDefaultConfig --- substrate/frame/system/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 3ae0e837b87b..7259ae3f36b8 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -288,6 +288,8 @@ pub mod pallet { #[inject_runtime_type] type RuntimeCall = (); #[inject_runtime_type] + type RuntimeTask = (); + #[inject_runtime_type] type PalletInfo = (); type BaseCallFilter = frame_support::traits::Everything; type BlockHashCount = frame_support::traits::ConstU32<256>; From e1ffb1547bb555a67eda0f08c535f490fae56b3c Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <> Date: Fri, 27 Oct 2023 18:28:08 +0530 Subject: [PATCH 096/177] FMT --- substrate/frame/support/procedural/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/lib.rs b/substrate/frame/support/procedural/src/lib.rs index 64644ed1c9e9..837665436c77 100644 --- a/substrate/frame/support/procedural/src/lib.rs +++ b/substrate/frame/support/procedural/src/lib.rs @@ -891,7 +891,7 @@ pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream { `RuntimeTask`, `RuntimeOrigin` or `PalletInfo`", ) .to_compile_error() - .into(); + .into() } tokens } From fa7f74a6f76f971d8089e8b6f078cad719a8438b Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:30:00 +0530 Subject: [PATCH 097/177] Adds License --- .../procedural/src/pallet/expand/tasks.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 3608e26979ad..84fc94aa32fe 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -1,3 +1,20 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use crate::pallet::{parse::tasks::*, Def}; use derive_syn_parse::Parse; use proc_macro2::TokenStream as TokenStream2; From 8933bfa1c3fa05a79296cfdf8f1aa33f37e76c6a Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:44:00 +0530 Subject: [PATCH 098/177] Makes clippy happy --- substrate/frame/examples/tasks-example/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index 51da9596dd5a..fce42c1e5061 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -54,7 +54,7 @@ pub mod pallet { fn increment() -> DispatchResult { // Get the value and check if it can be incremented let value = Value::::get().unwrap_or_default(); - if value >= 255 { + if value == 255 { Err(Error::::ValueOverflow.into()) } else { let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; From 74b3698647bc7b731b35d577dde29d64ef9e1b97 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:50:25 +0530 Subject: [PATCH 099/177] Fixes minimal runtime build --- substrate/frame/balances/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index f93445e0a4bd..9e5ebb2d77e8 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -231,6 +231,8 @@ pub mod pallet { type RuntimeHoldReason = (); #[inject_runtime_type] type RuntimeFreezeReason = (); + #[inject_runtime_type] + type RuntimeTask = (); type Balance = u64; type ExistentialDeposit = ConstU64<1>; @@ -257,7 +259,7 @@ pub mod pallet { + IsType<::RuntimeEvent>; /// The overarching task type. - #[pallet::no_default] + #[pallet::no_default_bounds] type RuntimeTask: Task; /// The overarching hold reason. From 45c4a6f23393244f2c3e03c337974c60fdbf2c53 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 27 Oct 2023 19:09:58 +0530 Subject: [PATCH 100/177] Fixes bench build --- substrate/frame/system/benches/bench.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/system/benches/bench.rs b/substrate/frame/system/benches/bench.rs index da8bb10fd4e4..6061fef6ae6e 100644 --- a/substrate/frame/system/benches/bench.rs +++ b/substrate/frame/system/benches/bench.rs @@ -81,6 +81,7 @@ impl frame_system::Config for Runtime { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = RuntimeTask; } impl module::Config for Runtime { From 12373feda74182c59e994ec978a227ef1da0e8b9 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:54:33 +0530 Subject: [PATCH 101/177] Fixes std propagation --- substrate/bin/node/runtime/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 76a68bf327f4..3502481c8942 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -251,6 +251,7 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "tasks-example/std", ] runtime-benchmarks = [ "frame-benchmarking-pallet-pov/runtime-benchmarks", From a24da395ee9a3f3a0654cdd00a2550b55d5c60af Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:40:07 +0530 Subject: [PATCH 102/177] Adds arg support in Task and updates example --- .../frame/examples/tasks-example/src/lib.rs | 87 +++++-------------- .../frame/examples/tasks-example/src/tests.rs | 77 ++++++++-------- .../procedural/src/pallet/expand/tasks.rs | 50 ++++++++--- 3 files changed, 98 insertions(+), 116 deletions(-) diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks-example/src/lib.rs index fce42c1e5061..ebb3021c98fe 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks-example/src/lib.rs @@ -39,48 +39,22 @@ pub mod pallet { #[pallet::error] pub enum Error { InvalidTask, - ValueOverflow, - ValueUnderflow, + NotFound, } #[pallet::tasks] impl frame_support::traits::Task for Task { + /// Add a pair of numbers into the totals and remove them. + #[pallet::task_list(Numbers::::iter_keys())] + #[pallet::task_condition(|i| Numbers::::contains_key(i))] #[pallet::task_index(0)] - #[pallet::task_condition(|| { - let value = Value::::get().unwrap(); - value < 255 - })] - #[pallet::task_list(Vec::>::new())] - fn increment() -> DispatchResult { - // Get the value and check if it can be incremented - let value = Value::::get().unwrap_or_default(); - if value == 255 { - Err(Error::::ValueOverflow.into()) - } else { - let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Incremented { new_val }); - Ok(()) - } - } - - #[pallet::task_index(1)] - #[pallet::task_condition(|| { - let value = Value::::get().unwrap(); - value > 0 - })] - #[pallet::task_list(Vec::>::new())] - fn decrement() -> DispatchResult { - // Get the value and check if it can be decremented - let value = Value::::get().unwrap_or_default(); - if value == 0 { - Err(Error::::ValueUnderflow.into()) - } else { - let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Decremented { new_val }); - Ok(()) - } + pub fn add_number_into_total(i: u32) -> DispatchResult { + let v = Numbers::::take(i).ok_or(Error::::NotFound)?; + Total::::mutate(|(total_keys, total_values)| { + *total_keys += i; + *total_values += v; + }); + Ok(()) } } @@ -93,43 +67,29 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(_); + /// Some running total. + #[pallet::storage] + pub type Total = StorageValue<_, (u32, u32), ValueQuery>; + + /// Numbers to be added into the total. #[pallet::storage] - #[pallet::getter(fn value)] - pub type Value = StorageValue<_, u8>; + pub type Numbers = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>; #[pallet::call] impl Pallet where T: TypeInfo, { - pub fn increment(origin: OriginFor) -> DispatchResult { - ensure_root(origin)?; - - // Increment the value and emit an event - let new_val = Value::::get().unwrap_or(0).checked_add(1).ok_or("Value overflow")?; - Value::::put(new_val); - Self::deposit_event(Event::Incremented { new_val }); - - Ok(()) - } - - pub fn decrement(origin: OriginFor) -> DispatchResult { - ensure_root(origin)?; - - // Decrement the value and emit an event - let new_val = Value::::get().unwrap_or(0).checked_sub(1).ok_or("Value underflow")?; - Value::::put(new_val); - Self::deposit_event(Event::Decremented { new_val }); - - Ok(()) - } - // this will be auto-generated by the macros and will always be the same pub fn do_task(origin: OriginFor, task: crate::pallet::Task) -> DispatchResult { use frame_support::traits::Task; ensure_root(origin)?; if task.is_valid() { - task.run() + let result = task.run(); + if result.is_ok() { + Self::deposit_event(Event::TaskExecuted { task }); + } + result } else { Err(Error::::InvalidTask.into()) } @@ -139,7 +99,6 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { - Incremented { new_val: u8 }, - Decremented { new_val: u8 }, + TaskExecuted { task: Task }, } } diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks-example/src/tests.rs index 5eaf6820cfa1..b574de85c0d9 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks-example/src/tests.rs @@ -17,7 +17,7 @@ //! Tests for `tasks-example`. #![cfg(test)] -use crate::mock::*; +use crate::{mock::*, Numbers}; use frame_support::traits::Task; use sp_runtime::BuildStorage; @@ -34,63 +34,56 @@ pub fn new_test_ext() -> sp_io::TestExternalities { } #[test] -fn incrementing_and_decrementing_works() { +fn task_enumerate_works() { new_test_ext().execute_with(|| { - assert!(TasksExample::decrement(RuntimeOrigin::root()).is_err()); - TasksExample::increment(RuntimeOrigin::root()).unwrap(); - TasksExample::decrement(RuntimeOrigin::root()).unwrap(); - TasksExample::increment(RuntimeOrigin::root()).unwrap(); - TasksExample::increment(RuntimeOrigin::root()).unwrap(); - TasksExample::decrement(RuntimeOrigin::root()).unwrap(); - TasksExample::decrement(RuntimeOrigin::root()).unwrap(); - assert!(TasksExample::decrement(RuntimeOrigin::root()).is_err()); - for _ in 0..255 { - TasksExample::increment(RuntimeOrigin::root()).unwrap(); - } - assert!(TasksExample::increment(RuntimeOrigin::root()).is_err()); + Numbers::::insert(0, 1); + assert_eq!(crate::pallet::Task::::iter().collect::>().len(), 1); }); } -#[test] -fn task_enumerate_works() { - assert_eq!(crate::pallet::Task::::iter().collect::>().len(), 2); -} - #[test] fn runtime_task_enumerate_works_via_frame_system_config() { - assert_eq!(::RuntimeTask::iter().collect::>().len(), 2); + new_test_ext().execute_with(|| { + Numbers::::insert(0, 1); + Numbers::::insert(1, 4); + assert_eq!( + ::RuntimeTask::iter().collect::>().len(), + 2 + ); + }); } #[test] fn runtime_task_enumerate_works_via_pallet_config() { - assert_eq!( - ::RuntimeTask::iter() - .collect::>() - .len(), - 2 - ); + new_test_ext().execute_with(|| { + Numbers::::insert(1, 4); + assert_eq!( + ::RuntimeTask::iter() + .collect::>() + .len(), + 1 + ); + }); } #[test] fn task_index_works_at_pallet_level() { - assert_eq!(crate::pallet::Task::::increment.task_index(), 1); - assert_eq!(crate::pallet::Task::::decrement.task_index(), 2); + new_test_ext().execute_with(|| { + assert_eq!(crate::pallet::Task::::AddNumberIntoTotal { i: 2u32 }.task_index(), 0); + }); } #[test] fn task_index_works_at_runtime_level() { - assert_eq!( - ::RuntimeTask::TasksExample( - crate::pallet::Task::::increment - ) - .task_index(), - 1 - ); - assert_eq!( - ::RuntimeTask::TasksExample( - crate::pallet::Task::::decrement - ) - .task_index(), - 2 - ); + new_test_ext().execute_with(|| { + assert_eq!( + ::RuntimeTask::TasksExample(crate::pallet::Task::< + Runtime, + >::AddNumberIntoTotal { + i: 1u32 + }) + .task_index(), + 0 + ); + }); } diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 84fc94aa32fe..8083f048a92c 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -17,8 +17,9 @@ use crate::pallet::{parse::tasks::*, Def}; use derive_syn_parse::Parse; +use inflector::Inflector; use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, ToTokens}; +use quote::{format_ident, quote, ToTokens}; use syn::{parse_quote, spanned::Spanned, Item, ItemEnum, ItemImpl}; impl TaskEnumDef { @@ -33,11 +34,16 @@ impl TaskEnumDef { .iter() .map(|task| { let ident = &task.item.sig.ident; + let ident = format_ident!("{}", ident.to_string().to_class_case()); + let args = task.item.sig.inputs.iter().collect::>(); + if args.is_empty() { quote!(#ident) } else { - quote!(#ident(#(#args),*)) + quote!(#ident { + #(#args),* + }) } }) .collect::>(), @@ -48,11 +54,9 @@ impl TaskEnumDef { /// /// Conceptually similar to the [`Call`] enum, but for tasks. This is only /// generated if there are tasks present in this pallet. - #[allow(non_camel_case_types)] #[pallet::task_enum] pub enum Task<#type_decl_bounded_generics> { #( - #[allow(non_camel_case_types)] #variants, )* } @@ -111,10 +115,34 @@ impl ToTokens for TasksDef { let enum_arguments = &self.enum_arguments; let enum_use = quote!(#enum_ident #enum_arguments); - let task_fn_idents = self.tasks.iter().map(|task| &task.item.sig.ident).collect::>(); + let task_fn_idents = self + .tasks + .iter() + .map(|task| format_ident!("{}", &task.item.sig.ident.to_string().to_class_case())) + .collect::>(); let task_indices = self.tasks.iter().map(|task| &task.index_attr.meta.index); let task_conditions = self.tasks.iter().map(|task| &task.condition_attr.meta.expr); + let task_iters = self.tasks.iter().map(|task| &task.list_attr.meta.expr); let task_fn_blocks = self.tasks.iter().map(|task| &task.item.block); + let task_arg_names = self + .tasks + .iter() + .map(|task| { + task.item + .sig + .inputs + .iter() + .map(|input| match input { + // Todo: This should be checked in the parsing stage. + syn::FnArg::Typed(pat_type) => match &*pat_type.pat { + syn::Pat::Ident(ident) => quote!(#ident), + _ => panic!("unexpected pattern type"), + }, + _ => panic!("unexpected function argument type"), + }) + .collect::>() + }) + .collect::>(); let sp_std = quote!(#scrate::__private::sp_std); let impl_generics = &self.item_impl.generics; @@ -126,26 +154,28 @@ impl ToTokens for TasksDef { type Enumeration = #sp_std::vec::IntoIter<#enum_use>; fn iter() -> Self::Enumeration { - #sp_std::vec![#(#enum_ident::#task_fn_idents),*].into_iter() + let mut all_tasks = #sp_std::vec![]; + #(all_tasks.extend(#task_iters.map(|i| #enum_ident::#task_fn_idents { i }).collect::>());)* + all_tasks.into_iter() } fn task_index(&self) -> u32 { match self { - #(#enum_ident::#task_fn_idents => #task_indices),*, + #(#enum_ident::#task_fn_idents { .. } => #task_indices),*, Task::__Ignore(_, _) => unreachable!(), } } fn is_valid(&self) -> bool { match self { - #(#enum_ident::#task_fn_idents => (#task_conditions)()),*, + #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => (#task_conditions)(#(#task_arg_names),* )),*, Task::__Ignore(_, _) => unreachable!(), } } fn run(&self) -> Result<(), #scrate::pallet_prelude::DispatchError> { - match self { - #(#enum_ident::#task_fn_idents => #task_fn_blocks),*, + match self.clone() { + #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => #task_fn_blocks),*, Task::__Ignore(_, _) => unreachable!(), } } From 824ae34d07b45ac8cf566e6887ef16564a086602 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:28:17 +0530 Subject: [PATCH 103/177] Fixes build --- substrate/bin/node/runtime/Cargo.toml | 1 + substrate/frame/support/procedural/src/pallet/expand/tasks.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 3502481c8942..22d1adc4e3ce 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -397,4 +397,5 @@ try-runtime = [ "pallet-vesting/try-runtime", "pallet-whitelist/try-runtime", "sp-runtime/try-runtime", + "tasks-example/try-runtime", ] diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 8083f048a92c..9adbdce91bfe 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -155,7 +155,7 @@ impl ToTokens for TasksDef { fn iter() -> Self::Enumeration { let mut all_tasks = #sp_std::vec![]; - #(all_tasks.extend(#task_iters.map(|i| #enum_ident::#task_fn_idents { i }).collect::>());)* + #(all_tasks.extend(#task_iters.map(|i| #enum_ident::#task_fn_idents { i }).collect::<#sp_std::vec::Vec<_>>());)* all_tasks.into_iter() } From 10adf61338cfbaca7b428e82e2502c7fec091732 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:53:32 +0530 Subject: [PATCH 104/177] Removes task example from kitchensik --- Cargo.lock | 1 - substrate/bin/node/runtime/Cargo.toml | 3 --- substrate/bin/node/runtime/src/lib.rs | 8 -------- 3 files changed, 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efa566f88c12..68c217c62337 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6968,7 +6968,6 @@ dependencies = [ "sp-version", "static_assertions", "substrate-wasm-builder", - "tasks-example", ] [[package]] diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 22d1adc4e3ce..a9d685523f6c 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -134,7 +134,6 @@ pallet-vesting = { path = "../../../frame/vesting", default-features = false} pallet-whitelist = { path = "../../../frame/whitelist", default-features = false} pallet-tx-pause = { path = "../../../frame/tx-pause", default-features = false} pallet-safe-mode = { path = "../../../frame/safe-mode", default-features = false} -tasks-example = { path = "../../../frame/examples/tasks-example", default-features = false } [build-dependencies] substrate-wasm-builder = { path = "../../../utils/wasm-builder", optional = true } @@ -251,7 +250,6 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", - "tasks-example/std", ] runtime-benchmarks = [ "frame-benchmarking-pallet-pov/runtime-benchmarks", @@ -397,5 +395,4 @@ try-runtime = [ "pallet-vesting/try-runtime", "pallet-whitelist/try-runtime", "sp-runtime/try-runtime", - "tasks-example/try-runtime", ] diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 43c17eb65023..c7dd22b9dbe8 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -90,7 +90,6 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; -use tasks_example; #[cfg(any(feature = "std", test))] pub use frame_system::Call as SystemCall; @@ -313,11 +312,6 @@ impl frame_system::Config for Runtime { impl pallet_insecure_randomness_collective_flip::Config for Runtime {} -impl tasks_example::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; -} - impl pallet_utility::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -2140,7 +2134,6 @@ construct_runtime!( SafeMode: pallet_safe_mode, Statement: pallet_statement, Broker: pallet_broker, - TasksExample: tasks_example, Mixnet: pallet_mixnet, } ); @@ -2228,7 +2221,6 @@ mod benches { [pallet_conviction_voting, ConvictionVoting] [pallet_contracts, Contracts] [pallet_core_fellowship, CoreFellowship] - [tasks_example, TasksExample] [pallet_democracy, Democracy] [pallet_asset_conversion, AssetConversion] [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] From fba32289d546a9d67155f0df429ebb9072a36973 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:30:51 +0530 Subject: [PATCH 105/177] Fixes build --- .../src/construct_runtime/expand/task.rs | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 0e6599c513a4..f5580d25e384 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -29,7 +29,6 @@ pub fn expand_outer_task( let mut task_variants = Vec::new(); let mut variant_names = Vec::new(); let mut task_paths = Vec::new(); - let mut iter_generalizations = Vec::new(); for decl in pallet_decls { if let Some(_) = decl.find_part("Task") { let variant_name = &decl.name; @@ -54,17 +53,6 @@ pub fn expand_outer_task( variant_names.push(quote!(#variant_name)); task_paths.push(quote!(#path::pallet::Task)); - - iter_generalizations.push(quote! { - RuntimeTask::#variant_name(val) => { - for variant in #path::pallet::Task::<#runtime_name>::iter() { - let index = variant.task_index(); - if !all_task_indices.insert(index) { - panic!("duplicate task index `{index}` within pallet `{}`", stringify!(#path)); - } - } - } - }) } } @@ -115,15 +103,6 @@ pub fn expand_outer_task( #[allow(unreachable_code)] fn task_index(&self) -> u32 { - // for debug builds, ensure at runtime there are no duplicate task indices - // within the pallet being accessed - #[cfg(debug_assertions)] { - let mut all_task_indices: std::collections::HashSet = std::collections::HashSet::new(); - match self { - #(#iter_generalizations,)* - _ => unreachable!(#INCOMPLETE_MATCH_QED), - } - } match self { #(RuntimeTask::#variant_names(val) => val.task_index(),)* _ => unreachable!(#INCOMPLETE_MATCH_QED), From 5a94a0403d07d219645f8aedf4d27053c28dfb1e Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:47:06 +0530 Subject: [PATCH 106/177] Revert "Removes task example from kitchensik" This reverts commit 10adf61338cfbaca7b428e82e2502c7fec091732. --- Cargo.lock | 1 + substrate/bin/node/runtime/Cargo.toml | 3 +++ substrate/bin/node/runtime/src/lib.rs | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 68c217c62337..efa566f88c12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6968,6 +6968,7 @@ dependencies = [ "sp-version", "static_assertions", "substrate-wasm-builder", + "tasks-example", ] [[package]] diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index a9d685523f6c..22d1adc4e3ce 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -134,6 +134,7 @@ pallet-vesting = { path = "../../../frame/vesting", default-features = false} pallet-whitelist = { path = "../../../frame/whitelist", default-features = false} pallet-tx-pause = { path = "../../../frame/tx-pause", default-features = false} pallet-safe-mode = { path = "../../../frame/safe-mode", default-features = false} +tasks-example = { path = "../../../frame/examples/tasks-example", default-features = false } [build-dependencies] substrate-wasm-builder = { path = "../../../utils/wasm-builder", optional = true } @@ -250,6 +251,7 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "tasks-example/std", ] runtime-benchmarks = [ "frame-benchmarking-pallet-pov/runtime-benchmarks", @@ -395,4 +397,5 @@ try-runtime = [ "pallet-vesting/try-runtime", "pallet-whitelist/try-runtime", "sp-runtime/try-runtime", + "tasks-example/try-runtime", ] diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index c7dd22b9dbe8..43c17eb65023 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -90,6 +90,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; +use tasks_example; #[cfg(any(feature = "std", test))] pub use frame_system::Call as SystemCall; @@ -312,6 +313,11 @@ impl frame_system::Config for Runtime { impl pallet_insecure_randomness_collective_flip::Config for Runtime {} +impl tasks_example::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; +} + impl pallet_utility::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -2134,6 +2140,7 @@ construct_runtime!( SafeMode: pallet_safe_mode, Statement: pallet_statement, Broker: pallet_broker, + TasksExample: tasks_example, Mixnet: pallet_mixnet, } ); @@ -2221,6 +2228,7 @@ mod benches { [pallet_conviction_voting, ConvictionVoting] [pallet_contracts, Contracts] [pallet_core_fellowship, CoreFellowship] + [tasks_example, TasksExample] [pallet_democracy, Democracy] [pallet_asset_conversion, AssetConversion] [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] From a3932f6bf3c924d032c87e02f6c687daa460a798 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:53:36 +0530 Subject: [PATCH 107/177] Removes RuntimeTask for pallet_balances --- bridges/bin/runtime-common/src/mock.rs | 1 - bridges/modules/messages/src/mock.rs | 1 - bridges/modules/relayers/src/mock.rs | 1 - cumulus/pallets/collator-selection/src/mock.rs | 1 - cumulus/pallets/xcmp-queue/src/mock.rs | 1 - cumulus/parachain-template/runtime/src/lib.rs | 1 - cumulus/parachains/common/src/impls.rs | 1 - .../runtimes/assets/asset-hub-kusama/src/lib.rs | 1 - .../runtimes/assets/asset-hub-polkadot/src/lib.rs | 1 - .../runtimes/assets/asset-hub-rococo/src/lib.rs | 1 - .../runtimes/assets/asset-hub-westend/src/lib.rs | 1 - .../runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs | 1 - .../runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs | 1 - .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 1 - .../runtimes/collectives/collectives-polkadot/src/lib.rs | 1 - .../runtimes/contracts/contracts-rococo/src/lib.rs | 1 - cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 1 - .../runtimes/testing/rococo-parachain/src/lib.rs | 1 - cumulus/test/runtime/src/lib.rs | 1 - polkadot/runtime/common/src/assigned_slots/mod.rs | 1 - polkadot/runtime/common/src/auctions.rs | 1 - polkadot/runtime/common/src/claims.rs | 1 - polkadot/runtime/common/src/crowdloan/mod.rs | 1 - polkadot/runtime/common/src/impls.rs | 1 - polkadot/runtime/common/src/integration_tests.rs | 1 - polkadot/runtime/common/src/paras_registrar/mod.rs | 1 - polkadot/runtime/common/src/purchase.rs | 1 - polkadot/runtime/common/src/slots/mod.rs | 1 - polkadot/runtime/parachains/src/mock.rs | 1 - polkadot/runtime/rococo/src/lib.rs | 2 -- polkadot/runtime/test-runtime/src/lib.rs | 1 - polkadot/runtime/westend/src/lib.rs | 1 - polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs | 1 - polkadot/xcm/pallet-xcm/src/mock.rs | 1 - polkadot/xcm/xcm-builder/src/tests/pay/mock.rs | 1 - polkadot/xcm/xcm-builder/tests/mock/mod.rs | 1 - polkadot/xcm/xcm-simulator/example/src/parachain.rs | 1 - polkadot/xcm/xcm-simulator/example/src/relay_chain.rs | 1 - polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs | 1 - polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs | 1 - substrate/bin/node-template/runtime/src/lib.rs | 1 - substrate/bin/node/runtime/src/lib.rs | 1 - substrate/frame/alliance/src/mock.rs | 1 - substrate/frame/asset-conversion/src/mock.rs | 1 - substrate/frame/asset-rate/src/mock.rs | 1 - substrate/frame/assets/src/mock.rs | 1 - substrate/frame/atomic-swap/src/tests.rs | 1 - substrate/frame/babe/src/mock.rs | 1 - substrate/frame/balances/src/lib.rs | 8 +------- substrate/frame/beefy/src/mock.rs | 1 - substrate/frame/bounties/src/tests.rs | 1 - substrate/frame/child-bounties/src/tests.rs | 1 - substrate/frame/contracts/src/tests.rs | 1 - substrate/frame/conviction-voting/src/tests.rs | 1 - substrate/frame/democracy/src/tests.rs | 1 - substrate/frame/election-provider-multi-phase/src/mock.rs | 1 - .../test-staking-e2e/src/mock.rs | 1 - substrate/frame/elections-phragmen/src/lib.rs | 1 - substrate/frame/examples/basic/src/tests.rs | 1 - substrate/frame/examples/dev-mode/src/tests.rs | 1 - substrate/frame/examples/kitchensink/src/tests.rs | 1 - substrate/frame/executive/src/lib.rs | 1 - substrate/frame/fast-unstake/src/mock.rs | 1 - substrate/frame/grandpa/src/mock.rs | 1 - substrate/frame/identity/src/tests.rs | 1 - substrate/frame/indices/src/mock.rs | 1 - substrate/frame/lottery/src/mock.rs | 1 - substrate/frame/multisig/src/tests.rs | 1 - substrate/frame/nft-fractionalization/src/mock.rs | 1 - substrate/frame/nfts/src/mock.rs | 1 - substrate/frame/nicks/src/lib.rs | 1 - substrate/frame/nis/src/mock.rs | 2 -- substrate/frame/nomination-pools/src/mock.rs | 1 - substrate/frame/nomination-pools/test-staking/src/mock.rs | 1 - substrate/frame/preimage/src/mock.rs | 1 - substrate/frame/proxy/src/tests.rs | 1 - substrate/frame/recovery/src/mock.rs | 1 - substrate/frame/referenda/src/mock.rs | 1 - substrate/frame/root-offences/src/mock.rs | 1 - substrate/frame/safe-mode/src/mock.rs | 1 - substrate/frame/scored-pool/src/mock.rs | 1 - substrate/frame/society/src/mock.rs | 1 - substrate/frame/staking/src/mock.rs | 1 - substrate/frame/state-trie-migration/src/lib.rs | 1 - substrate/frame/statement/src/mock.rs | 1 - substrate/frame/tips/src/tests.rs | 1 - .../asset-conversion-tx-payment/src/mock.rs | 1 - .../transaction-payment/asset-tx-payment/src/mock.rs | 1 - substrate/frame/transaction-payment/src/mock.rs | 1 - substrate/frame/treasury/src/tests.rs | 1 - substrate/frame/tx-pause/src/mock.rs | 1 - substrate/frame/uniques/src/mock.rs | 1 - substrate/frame/utility/src/tests.rs | 1 - substrate/frame/vesting/src/mock.rs | 1 - substrate/frame/whitelist/src/mock.rs | 1 - substrate/test-utils/runtime/src/lib.rs | 1 - 96 files changed, 1 insertion(+), 104 deletions(-) diff --git a/bridges/bin/runtime-common/src/mock.rs b/bridges/bin/runtime-common/src/mock.rs index 8c89da5bb523..43b4bd163b6b 100644 --- a/bridges/bin/runtime-common/src/mock.rs +++ b/bridges/bin/runtime-common/src/mock.rs @@ -183,7 +183,6 @@ impl pallet_utility::Config for TestRuntime { impl pallet_balances::Config for TestRuntime { type Balance = ThisChainBalance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/bridges/modules/messages/src/mock.rs b/bridges/modules/messages/src/mock.rs index 34b37a367091..400e751aac84 100644 --- a/bridges/modules/messages/src/mock.rs +++ b/bridges/modules/messages/src/mock.rs @@ -125,7 +125,6 @@ impl pallet_balances::Config for TestRuntime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU64<1>; type AccountStore = frame_system::Pallet; type WeightInfo = (); diff --git a/bridges/modules/relayers/src/mock.rs b/bridges/modules/relayers/src/mock.rs index ddfbe0f1267b..120d27084175 100644 --- a/bridges/modules/relayers/src/mock.rs +++ b/bridges/modules/relayers/src/mock.rs @@ -93,7 +93,6 @@ impl pallet_balances::Config for TestRuntime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type WeightInfo = (); diff --git a/cumulus/pallets/collator-selection/src/mock.rs b/cumulus/pallets/collator-selection/src/mock.rs index f0ba73e9d4ec..a937055abb12 100644 --- a/cumulus/pallets/collator-selection/src/mock.rs +++ b/cumulus/pallets/collator-selection/src/mock.rs @@ -85,7 +85,6 @@ parameter_types! { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/pallets/xcmp-queue/src/mock.rs b/cumulus/pallets/xcmp-queue/src/mock.rs index 5a3517215764..d948893b7735 100644 --- a/cumulus/pallets/xcmp-queue/src/mock.rs +++ b/cumulus/pallets/xcmp-queue/src/mock.rs @@ -91,7 +91,6 @@ pub type Balance = u64; impl pallet_balances::Config for Test { type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index dfe5c5801c46..a53ceaddf85e 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -359,7 +359,6 @@ impl pallet_balances::Config for Runtime { type FreezeIdentifier = (); type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/cumulus/parachains/common/src/impls.rs b/cumulus/parachains/common/src/impls.rs index 8c4a7c6baa95..38401d65fa9e 100644 --- a/cumulus/parachains/common/src/impls.rs +++ b/cumulus/parachains/common/src/impls.rs @@ -185,7 +185,6 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 792e69433c54..942e0b1dfbf1 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -219,7 +219,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index be852de2867c..7a4a121907b3 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -229,7 +229,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index d704388c0265..e2809377200a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -225,7 +225,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index d158f0e68159..4a92b829abf0 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -197,7 +197,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 8ba81a4261a7..70cedbde2a53 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -244,7 +244,6 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = weights::pallet_balances::WeightInfo; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 5fb348d7bac6..3ef261e917b3 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -244,7 +244,6 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = weights::pallet_balances::WeightInfo; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index c882ae0267d5..21f2ea9ed0ee 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -300,7 +300,6 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = weights::pallet_balances::WeightInfo; diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index b6159be00c00..01678aebecf0 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -209,7 +209,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index fec7bb4f319b..76311f912f6d 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -213,7 +213,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU128; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 493505923b2c..09460a067137 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -394,7 +394,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 16365724b851..4a551158ff67 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -243,7 +243,6 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 636b1ea19388..e22dd2b5260b 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -244,7 +244,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/assigned_slots/mod.rs b/polkadot/runtime/common/src/assigned_slots/mod.rs index eb6543d3df72..a094d1c1e4cb 100644 --- a/polkadot/runtime/common/src/assigned_slots/mod.rs +++ b/polkadot/runtime/common/src/assigned_slots/mod.rs @@ -713,7 +713,6 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/auctions.rs b/polkadot/runtime/common/src/auctions.rs index 9d3c71c5ef73..840f556d94c0 100644 --- a/polkadot/runtime/common/src/auctions.rs +++ b/polkadot/runtime/common/src/auctions.rs @@ -741,7 +741,6 @@ mod tests { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); diff --git a/polkadot/runtime/common/src/claims.rs b/polkadot/runtime/common/src/claims.rs index 8cfa68a4d995..e4563faffdb9 100644 --- a/polkadot/runtime/common/src/claims.rs +++ b/polkadot/runtime/common/src/claims.rs @@ -773,7 +773,6 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/crowdloan/mod.rs b/polkadot/runtime/common/src/crowdloan/mod.rs index f79b3a59da66..593eff4482b7 100644 --- a/polkadot/runtime/common/src/crowdloan/mod.rs +++ b/polkadot/runtime/common/src/crowdloan/mod.rs @@ -934,7 +934,6 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/impls.rs b/polkadot/runtime/common/src/impls.rs index e0f446b032b4..35db5ac2d5e3 100644 --- a/polkadot/runtime/common/src/impls.rs +++ b/polkadot/runtime/common/src/impls.rs @@ -267,7 +267,6 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/polkadot/runtime/common/src/integration_tests.rs b/polkadot/runtime/common/src/integration_tests.rs index b9e38ee32c2e..ce88328aa0ca 100644 --- a/polkadot/runtime/common/src/integration_tests.rs +++ b/polkadot/runtime/common/src/integration_tests.rs @@ -175,7 +175,6 @@ impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/paras_registrar/mod.rs b/polkadot/runtime/common/src/paras_registrar/mod.rs index 440fcda19fcf..52ba088f2364 100644 --- a/polkadot/runtime/common/src/paras_registrar/mod.rs +++ b/polkadot/runtime/common/src/paras_registrar/mod.rs @@ -786,7 +786,6 @@ mod tests { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = (); diff --git a/polkadot/runtime/common/src/purchase.rs b/polkadot/runtime/common/src/purchase.rs index 93544dfbf92b..fafcf0a22bcb 100644 --- a/polkadot/runtime/common/src/purchase.rs +++ b/polkadot/runtime/common/src/purchase.rs @@ -545,7 +545,6 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/common/src/slots/mod.rs b/polkadot/runtime/common/src/slots/mod.rs index 527b7b01ddbf..f68f6381bb7f 100644 --- a/polkadot/runtime/common/src/slots/mod.rs +++ b/polkadot/runtime/common/src/slots/mod.rs @@ -563,7 +563,6 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index a1dad683d873..305ecd924801 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -140,7 +140,6 @@ impl pallet_balances::Config for Test { type FreezeIdentifier = (); type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index b3a1c8c592e5..3ccc6070866d 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -290,7 +290,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = MaxLocks; @@ -1078,7 +1077,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU128<10_000_000_000>; // One RTC cent type AccountStore = StorageMapShim< pallet_balances::Account, diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index 94ebc3fed7b7..5d8c09f5cf6c 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -223,7 +223,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = MaxLocks; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 5b82d7eaf3e1..cb40dc1c6967 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -287,7 +287,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = MaxLocks; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index 11810b6c9129..d48941b20c87 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -80,7 +80,6 @@ parameter_types! { impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type AccountStore = System; - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/polkadot/xcm/pallet-xcm/src/mock.rs b/polkadot/xcm/pallet-xcm/src/mock.rs index 4d9922a94094..ae15f0e43bcd 100644 --- a/polkadot/xcm/pallet-xcm/src/mock.rs +++ b/polkadot/xcm/pallet-xcm/src/mock.rs @@ -268,7 +268,6 @@ impl pallet_balances::Config for Test { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs index 3bf5789bfcb5..e51bd952177b 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs @@ -68,7 +68,6 @@ impl pallet_balances::Config for Test { type MaxLocks = ConstU32<0>; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-builder/tests/mock/mod.rs b/polkadot/xcm/xcm-builder/tests/mock/mod.rs index ae1d900fbca9..40d0a9692de1 100644 --- a/polkadot/xcm/xcm-builder/tests/mock/mod.rs +++ b/polkadot/xcm/xcm-builder/tests/mock/mod.rs @@ -113,7 +113,6 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-simulator/example/src/parachain.rs b/polkadot/xcm/xcm-simulator/example/src/parachain.rs index ff4321659c4f..4a082943165a 100644 --- a/polkadot/xcm/xcm-simulator/example/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/parachain.rs @@ -100,7 +100,6 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs index de23b42f2e03..111bfd3126f8 100644 --- a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs @@ -86,7 +86,6 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs index bfbfbe58d5d3..3800ac9090b3 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -89,7 +89,6 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index 6923985054b7..e8cfa75ca514 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -85,7 +85,6 @@ impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 9b9c34977fa2..06981b1210bc 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -246,7 +246,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU128; type AccountStore = System; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 43c17eb65023..d48cb2849985 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -528,7 +528,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = frame_system::Pallet; type WeightInfo = pallet_balances::weights::SubstrateWeight; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index ab3d4caa063d..a5970bc7af67 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -60,7 +60,6 @@ impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/asset-conversion/src/mock.rs b/substrate/frame/asset-conversion/src/mock.rs index f4d3f24cf8b6..ba3dbf1bb8d1 100644 --- a/substrate/frame/asset-conversion/src/mock.rs +++ b/substrate/frame/asset-conversion/src/mock.rs @@ -90,7 +90,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl pallet_assets::Config for Test { diff --git a/substrate/frame/asset-rate/src/mock.rs b/substrate/frame/asset-rate/src/mock.rs index a6f81b0e9fb9..151db8a6e915 100644 --- a/substrate/frame/asset-rate/src/mock.rs +++ b/substrate/frame/asset-rate/src/mock.rs @@ -78,7 +78,6 @@ impl pallet_balances::Config for Test { type FreezeIdentifier = (); type MaxHolds = (); type MaxFreezes = (); - type RuntimeTask = RuntimeTask; } impl pallet_asset_rate::Config for Test { diff --git a/substrate/frame/assets/src/mock.rs b/substrate/frame/assets/src/mock.rs index a6d9e409c06c..fb01ae93503e 100644 --- a/substrate/frame/assets/src/mock.rs +++ b/substrate/frame/assets/src/mock.rs @@ -88,7 +88,6 @@ impl pallet_balances::Config for Test { type FreezeIdentifier = (); type MaxHolds = (); type MaxFreezes = (); - type RuntimeTask = RuntimeTask; } pub struct AssetsCallbackHandle; diff --git a/substrate/frame/atomic-swap/src/tests.rs b/substrate/frame/atomic-swap/src/tests.rs index 3d3e8694bc11..768c2f97798e 100644 --- a/substrate/frame/atomic-swap/src/tests.rs +++ b/substrate/frame/atomic-swap/src/tests.rs @@ -80,7 +80,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index f6e7e1349de4..3529c9170039 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -120,7 +120,6 @@ impl pallet_balances::Config for Test { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index 3ea15f2f3450..68c9d3ad3067 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -231,8 +231,6 @@ pub mod pallet { type RuntimeHoldReason = (); #[inject_runtime_type] type RuntimeFreezeReason = (); - #[inject_runtime_type] - type RuntimeTask = (); type Balance = u64; type ExistentialDeposit = ConstU64<1>; @@ -257,11 +255,7 @@ pub mod pallet { #[pallet::no_default_bounds] type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// The overarching task type. - #[pallet::no_default_bounds] - type RuntimeTask: Task; - + /// The overarching hold reason. #[pallet::no_default_bounds] type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Copy + VariantCount; diff --git a/substrate/frame/beefy/src/mock.rs b/substrate/frame/beefy/src/mock.rs index 581447076246..d46fe3877f98 100644 --- a/substrate/frame/beefy/src/mock.rs +++ b/substrate/frame/beefy/src/mock.rs @@ -132,7 +132,6 @@ impl pallet_balances::Config for Test { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/bounties/src/tests.rs b/substrate/frame/bounties/src/tests.rs index 9a4e42928d61..5de616922bc5 100644 --- a/substrate/frame/bounties/src/tests.rs +++ b/substrate/frame/bounties/src/tests.rs @@ -92,7 +92,6 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index 29b72cf921cb..bc43967428c7 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -95,7 +95,6 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/contracts/src/tests.rs b/substrate/frame/contracts/src/tests.rs index 99050ddba0eb..2a1bd030ce08 100644 --- a/substrate/frame/contracts/src/tests.rs +++ b/substrate/frame/contracts/src/tests.rs @@ -364,7 +364,6 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/conviction-voting/src/tests.rs b/substrate/frame/conviction-voting/src/tests.rs index f2f7d0b3b03f..128d47d2a65b 100644 --- a/substrate/frame/conviction-voting/src/tests.rs +++ b/substrate/frame/conviction-voting/src/tests.rs @@ -84,7 +84,6 @@ impl pallet_balances::Config for Test { type MaxLocks = ConstU32<10>; type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/democracy/src/tests.rs b/substrate/frame/democracy/src/tests.rs index d012989f4520..ec26db62db68 100644 --- a/substrate/frame/democracy/src/tests.rs +++ b/substrate/frame/democracy/src/tests.rs @@ -134,7 +134,6 @@ impl pallet_balances::Config for Test { type MaxLocks = ConstU32<10>; type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/election-provider-multi-phase/src/mock.rs b/substrate/frame/election-provider-multi-phase/src/mock.rs index 27d036aab2d3..837cf1187d94 100644 --- a/substrate/frame/election-provider-multi-phase/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/src/mock.rs @@ -256,7 +256,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } #[derive(Default, Eq, PartialEq, Debug, Clone, Copy)] diff --git a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs index 5a59d75710d9..9195945f6cac 100644 --- a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs @@ -108,7 +108,6 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/elections-phragmen/src/lib.rs b/substrate/frame/elections-phragmen/src/lib.rs index 1db215b06dbf..4384b8985502 100644 --- a/substrate/frame/elections-phragmen/src/lib.rs +++ b/substrate/frame/elections-phragmen/src/lib.rs @@ -1351,7 +1351,6 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = frame_system::Pallet; diff --git a/substrate/frame/examples/basic/src/tests.rs b/substrate/frame/examples/basic/src/tests.rs index e463275eff4a..407166135e9d 100644 --- a/substrate/frame/examples/basic/src/tests.rs +++ b/substrate/frame/examples/basic/src/tests.rs @@ -87,7 +87,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/examples/dev-mode/src/tests.rs b/substrate/frame/examples/dev-mode/src/tests.rs index 9d060340783c..962b009d4444 100644 --- a/substrate/frame/examples/dev-mode/src/tests.rs +++ b/substrate/frame/examples/dev-mode/src/tests.rs @@ -81,7 +81,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/examples/kitchensink/src/tests.rs b/substrate/frame/examples/kitchensink/src/tests.rs index ac500bd2382e..3b88f68d1c39 100644 --- a/substrate/frame/examples/kitchensink/src/tests.rs +++ b/substrate/frame/examples/kitchensink/src/tests.rs @@ -58,7 +58,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/executive/src/lib.rs b/substrate/frame/executive/src/lib.rs index bdbd39e2a231..b1251e9bdb9c 100644 --- a/substrate/frame/executive/src/lib.rs +++ b/substrate/frame/executive/src/lib.rs @@ -896,7 +896,6 @@ mod tests { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = ConstU32<1>; - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/fast-unstake/src/mock.rs b/substrate/frame/fast-unstake/src/mock.rs index 4b17f3109b6d..6b866224ab99 100644 --- a/substrate/frame/fast-unstake/src/mock.rs +++ b/substrate/frame/fast-unstake/src/mock.rs @@ -69,7 +69,6 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/grandpa/src/mock.rs b/substrate/frame/grandpa/src/mock.rs index 9ff2448c68cd..13d5df361234 100644 --- a/substrate/frame/grandpa/src/mock.rs +++ b/substrate/frame/grandpa/src/mock.rs @@ -136,7 +136,6 @@ impl pallet_balances::Config for Test { type Balance = u128; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU128<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index 8ee232e93e0d..1b2aa88f7e9d 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -89,7 +89,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/indices/src/mock.rs b/substrate/frame/indices/src/mock.rs index b3824f7ab7f4..13f861ac473b 100644 --- a/substrate/frame/indices/src/mock.rs +++ b/substrate/frame/indices/src/mock.rs @@ -77,7 +77,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/lottery/src/mock.rs b/substrate/frame/lottery/src/mock.rs index 2f26e09e676a..050a76a2d14a 100644 --- a/substrate/frame/lottery/src/mock.rs +++ b/substrate/frame/lottery/src/mock.rs @@ -80,7 +80,6 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/multisig/src/tests.rs b/substrate/frame/multisig/src/tests.rs index 41d1a4c81372..179827255291 100644 --- a/substrate/frame/multisig/src/tests.rs +++ b/substrate/frame/multisig/src/tests.rs @@ -51,7 +51,6 @@ impl frame_system::Config for Test { impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type AccountStore = System; - type RuntimeTask = RuntimeTask; } pub struct TestBaseCallFilter; diff --git a/substrate/frame/nft-fractionalization/src/mock.rs b/substrate/frame/nft-fractionalization/src/mock.rs index a97d64b8a83e..a9aa98cbf560 100644 --- a/substrate/frame/nft-fractionalization/src/mock.rs +++ b/substrate/frame/nft-fractionalization/src/mock.rs @@ -80,7 +80,6 @@ impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU64<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/nfts/src/mock.rs b/substrate/frame/nfts/src/mock.rs index d364341b4e64..5acbd081a4da 100644 --- a/substrate/frame/nfts/src/mock.rs +++ b/substrate/frame/nfts/src/mock.rs @@ -88,7 +88,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/nicks/src/lib.rs b/substrate/frame/nicks/src/lib.rs index 2ba156bb25a3..f31b596e57fd 100644 --- a/substrate/frame/nicks/src/lib.rs +++ b/substrate/frame/nicks/src/lib.rs @@ -316,7 +316,6 @@ mod tests { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } ord_parameter_types! { diff --git a/substrate/frame/nis/src/mock.rs b/substrate/frame/nis/src/mock.rs index b37901231d0e..8ae90a9563d5 100644 --- a/substrate/frame/nis/src/mock.rs +++ b/substrate/frame/nis/src/mock.rs @@ -92,7 +92,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type MaxHolds = ConstU32<1>; - type RuntimeTask = RuntimeTask; } impl pallet_balances::Config for Test { @@ -114,7 +113,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/nomination-pools/src/mock.rs b/substrate/frame/nomination-pools/src/mock.rs index f2660d1fe29d..7d0860fded3e 100644 --- a/substrate/frame/nomination-pools/src/mock.rs +++ b/substrate/frame/nomination-pools/src/mock.rs @@ -241,7 +241,6 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/nomination-pools/test-staking/src/mock.rs b/substrate/frame/nomination-pools/test-staking/src/mock.rs index 5dc3364f7553..d72a6fac575a 100644 --- a/substrate/frame/nomination-pools/test-staking/src/mock.rs +++ b/substrate/frame/nomination-pools/test-staking/src/mock.rs @@ -91,7 +91,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } pallet_staking_reward_curve::build! { diff --git a/substrate/frame/preimage/src/mock.rs b/substrate/frame/preimage/src/mock.rs index 946d5e5955ac..0a52bde8503b 100644 --- a/substrate/frame/preimage/src/mock.rs +++ b/substrate/frame/preimage/src/mock.rs @@ -84,7 +84,6 @@ impl pallet_balances::Config for Test { type MaxFreezes = ConstU32<1>; type RuntimeHoldReason = (); type RuntimeFreezeReason = (); - type RuntimeTask = RuntimeTask; type MaxHolds = ConstU32<2>; } diff --git a/substrate/frame/proxy/src/tests.rs b/substrate/frame/proxy/src/tests.rs index cc7569b46622..89bd8b68f091 100644 --- a/substrate/frame/proxy/src/tests.rs +++ b/substrate/frame/proxy/src/tests.rs @@ -53,7 +53,6 @@ impl frame_system::Config for Test { impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type AccountStore = System; - type RuntimeTask = RuntimeTask; } impl pallet_utility::Config for Test { diff --git a/substrate/frame/recovery/src/mock.rs b/substrate/frame/recovery/src/mock.rs index 8909d4a26fe3..6fb552f2243a 100644 --- a/substrate/frame/recovery/src/mock.rs +++ b/substrate/frame/recovery/src/mock.rs @@ -87,7 +87,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/referenda/src/mock.rs b/substrate/frame/referenda/src/mock.rs index 35238767d1a8..f501898a2749 100644 --- a/substrate/frame/referenda/src/mock.rs +++ b/substrate/frame/referenda/src/mock.rs @@ -110,7 +110,6 @@ impl pallet_balances::Config for Test { type MaxLocks = ConstU32<10>; type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/root-offences/src/mock.rs b/substrate/frame/root-offences/src/mock.rs index ac8ec8b55cad..2484692df90b 100644 --- a/substrate/frame/root-offences/src/mock.rs +++ b/substrate/frame/root-offences/src/mock.rs @@ -126,7 +126,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } pallet_staking_reward_curve::build! { diff --git a/substrate/frame/safe-mode/src/mock.rs b/substrate/frame/safe-mode/src/mock.rs index 0b1e425d89e2..e3caa70c98ae 100644 --- a/substrate/frame/safe-mode/src/mock.rs +++ b/substrate/frame/safe-mode/src/mock.rs @@ -73,7 +73,6 @@ impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU64<2>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/scored-pool/src/mock.rs b/substrate/frame/scored-pool/src/mock.rs index 022021da8907..d4f929e3a9be 100644 --- a/substrate/frame/scored-pool/src/mock.rs +++ b/substrate/frame/scored-pool/src/mock.rs @@ -93,7 +93,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } parameter_types! { diff --git a/substrate/frame/society/src/mock.rs b/substrate/frame/society/src/mock.rs index db5c51e9bb9d..f6058bfbedaf 100644 --- a/substrate/frame/society/src/mock.rs +++ b/substrate/frame/society/src/mock.rs @@ -91,7 +91,6 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/staking/src/mock.rs b/substrate/frame/staking/src/mock.rs index 2a4143c0a370..46b2e12fdcd4 100644 --- a/substrate/frame/staking/src/mock.rs +++ b/substrate/frame/staking/src/mock.rs @@ -156,7 +156,6 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 3d632e745d2f..f20a82ccd55f 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -1129,7 +1129,6 @@ mod mock { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } /// Test only Weights for state migration. diff --git a/substrate/frame/statement/src/mock.rs b/substrate/frame/statement/src/mock.rs index 81af4f447e9f..743d0dd78730 100644 --- a/substrate/frame/statement/src/mock.rs +++ b/substrate/frame/statement/src/mock.rs @@ -89,7 +89,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type MaxHolds = (); - type RuntimeTask = RuntimeTask; } ord_parameter_types! { diff --git a/substrate/frame/tips/src/tests.rs b/substrate/frame/tips/src/tests.rs index 136e1f1ea178..a37b994b139f 100644 --- a/substrate/frame/tips/src/tests.rs +++ b/substrate/frame/tips/src/tests.rs @@ -89,7 +89,6 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type Balance = u64; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<1>; type AccountStore = System; diff --git a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs index b5657cb1465d..c60935673f00 100644 --- a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs @@ -112,7 +112,6 @@ parameter_types! { impl pallet_balances::Config for Runtime { type Balance = Balance; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type DustRemoval = (); type ExistentialDeposit = ConstU64<10>; type AccountStore = System; diff --git a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs index 9129597f38c7..93e52c812c48 100644 --- a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs @@ -116,7 +116,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl WeightToFeeT for WeightToFee { diff --git a/substrate/frame/transaction-payment/src/mock.rs b/substrate/frame/transaction-payment/src/mock.rs index 7c0874391fd5..d42c0c08f2c5 100644 --- a/substrate/frame/transaction-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/src/mock.rs @@ -111,7 +111,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl WeightToFeeT for WeightToFee { diff --git a/substrate/frame/treasury/src/tests.rs b/substrate/frame/treasury/src/tests.rs index 8291b29899eb..d1f0290b5305 100644 --- a/substrate/frame/treasury/src/tests.rs +++ b/substrate/frame/treasury/src/tests.rs @@ -95,7 +95,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl pallet_utility::Config for Test { diff --git a/substrate/frame/tx-pause/src/mock.rs b/substrate/frame/tx-pause/src/mock.rs index a32fdfe614a3..27fdd393d19a 100644 --- a/substrate/frame/tx-pause/src/mock.rs +++ b/substrate/frame/tx-pause/src/mock.rs @@ -82,7 +82,6 @@ impl pallet_balances::Config for Test { type RuntimeFreezeReason = RuntimeFreezeReason; type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; - type RuntimeTask = RuntimeTask; } impl pallet_utility::Config for Test { diff --git a/substrate/frame/uniques/src/mock.rs b/substrate/frame/uniques/src/mock.rs index 50f61f49fc8b..52f3da87e906 100644 --- a/substrate/frame/uniques/src/mock.rs +++ b/substrate/frame/uniques/src/mock.rs @@ -83,7 +83,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl Config for Test { diff --git a/substrate/frame/utility/src/tests.rs b/substrate/frame/utility/src/tests.rs index 8a08124f5c8a..6b87b3cce6dc 100644 --- a/substrate/frame/utility/src/tests.rs +++ b/substrate/frame/utility/src/tests.rs @@ -178,7 +178,6 @@ impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ConstU64<1>; type AccountStore = System; type WeightInfo = (); diff --git a/substrate/frame/vesting/src/mock.rs b/substrate/frame/vesting/src/mock.rs index e80c21cc9da5..29e92241f3c0 100644 --- a/substrate/frame/vesting/src/mock.rs +++ b/substrate/frame/vesting/src/mock.rs @@ -81,7 +81,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } parameter_types! { pub const MinVestedTransfer: u64 = 256 * 2; diff --git a/substrate/frame/whitelist/src/mock.rs b/substrate/frame/whitelist/src/mock.rs index f8f2ae8d6405..935d4ef9c0ab 100644 --- a/substrate/frame/whitelist/src/mock.rs +++ b/substrate/frame/whitelist/src/mock.rs @@ -86,7 +86,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = (); type RuntimeFreezeReason = (); type MaxHolds = (); - type RuntimeTask = RuntimeTask; } impl pallet_preimage::Config for Test { diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 87c5636fd74f..b2f4e9cc7d80 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -391,7 +391,6 @@ impl pallet_balances::Config for Runtime { type Balance = Balance; type DustRemoval = (); type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; From 824808751136cd61d2efd897638afd7487d6c060 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:07:52 +0530 Subject: [PATCH 108/177] Minor fix --- substrate/frame/balances/src/tests/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/balances/src/tests/mod.rs b/substrate/frame/balances/src/tests/mod.rs index 19520c2c3e54..61362b467c12 100644 --- a/substrate/frame/balances/src/tests/mod.rs +++ b/substrate/frame/balances/src/tests/mod.rs @@ -141,7 +141,6 @@ impl Config for Test { type FreezeIdentifier = TestId; type MaxFreezes = ConstU32<2>; type MaxHolds = ConstU32<3>; - type RuntimeTask = RuntimeTask; } #[derive(Clone)] From 8101437c117040c9c6f79fb1c8dff93b9064f3dc Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:14:11 +0530 Subject: [PATCH 109/177] Adds setup for benchmarking --- Cargo.lock | 33 ++++---- Cargo.toml | 2 +- substrate/bin/node/runtime/Cargo.toml | 7 +- substrate/bin/node/runtime/src/lib.rs | 6 +- substrate/frame/balances/src/lib.rs | 2 +- .../frame/examples/tasks-example/Cargo.toml | 38 --------- substrate/frame/examples/tasks/Cargo.toml | 52 ++++++++++++ .../frame/examples/tasks/src/benchmarking.rs | 37 ++++++++ .../{tasks-example => tasks}/src/lib.rs | 7 ++ .../{tasks-example => tasks}/src/mock.rs | 1 + .../{tasks-example => tasks}/src/tests.rs | 2 +- substrate/frame/examples/tasks/src/weights.rs | 84 +++++++++++++++++++ 12 files changed, 208 insertions(+), 63 deletions(-) delete mode 100644 substrate/frame/examples/tasks-example/Cargo.toml create mode 100644 substrate/frame/examples/tasks/Cargo.toml create mode 100644 substrate/frame/examples/tasks/src/benchmarking.rs rename substrate/frame/examples/{tasks-example => tasks}/src/lib.rs (96%) rename substrate/frame/examples/{tasks-example => tasks}/src/mock.rs (98%) rename substrate/frame/examples/{tasks-example => tasks}/src/tests.rs (98%) create mode 100644 substrate/frame/examples/tasks/src/weights.rs diff --git a/Cargo.lock b/Cargo.lock index c378c3b77a18..9334b3146192 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7084,6 +7084,7 @@ dependencies = [ "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", "pallet-elections-phragmen", + "pallet-example-tasks", "pallet-fast-unstake", "pallet-glutton", "pallet-grandpa", @@ -7160,7 +7161,6 @@ dependencies = [ "sp-version", "static_assertions", "substrate-wasm-builder", - "tasks-example", ] [[package]] @@ -9881,6 +9881,22 @@ dependencies = [ "sp-std 8.0.0", ] +[[package]] +name = "pallet-example-tasks" +version = "4.0.0-dev" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 8.0.0", +] + [[package]] name = "pallet-examples" version = "4.0.0-dev" @@ -18805,21 +18821,6 @@ version = "0.12.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" -[[package]] -name = "tasks-example" -version = "4.0.0-dev" -dependencies = [ - "frame-support", - "frame-system", - "log", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", -] - [[package]] name = "tempfile" version = "3.8.0" diff --git a/Cargo.toml b/Cargo.toml index 9fd474ad3e05..ecdc5f795d20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -299,7 +299,7 @@ members = [ "substrate/frame/examples/kitchensink", "substrate/frame/examples/offchain-worker", "substrate/frame/examples/split", - "substrate/frame/examples/tasks-example", + "substrate/frame/examples/tasks", "substrate/frame/executive", "substrate/frame/fast-unstake", "substrate/frame/glutton", diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 22d1adc4e3ce..e7b4f8d81039 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -134,7 +134,7 @@ pallet-vesting = { path = "../../../frame/vesting", default-features = false} pallet-whitelist = { path = "../../../frame/whitelist", default-features = false} pallet-tx-pause = { path = "../../../frame/tx-pause", default-features = false} pallet-safe-mode = { path = "../../../frame/safe-mode", default-features = false} -tasks-example = { path = "../../../frame/examples/tasks-example", default-features = false } +pallet-example-tasks = { path = "../../../frame/examples/tasks", default-features = false } [build-dependencies] substrate-wasm-builder = { path = "../../../utils/wasm-builder", optional = true } @@ -218,6 +218,7 @@ std = [ "pallet-state-trie-migration/std", "pallet-statement/std", "pallet-sudo/std", + "pallet-example-tasks/std", "pallet-timestamp/std", "pallet-tips/std", "pallet-transaction-payment-rpc-runtime-api/std", @@ -251,7 +252,6 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", - "tasks-example/std", ] runtime-benchmarks = [ "frame-benchmarking-pallet-pov/runtime-benchmarks", @@ -312,6 +312,7 @@ runtime-benchmarks = [ "pallet-staking/runtime-benchmarks", "pallet-state-trie-migration/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", + "pallet-example-tasks/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-tips/runtime-benchmarks", "pallet-transaction-storage/runtime-benchmarks", @@ -386,6 +387,7 @@ try-runtime = [ "pallet-state-trie-migration/try-runtime", "pallet-statement/try-runtime", "pallet-sudo/try-runtime", + "pallet-example-tasks/try-runtime", "pallet-timestamp/try-runtime", "pallet-tips/try-runtime", "pallet-transaction-payment/try-runtime", @@ -397,5 +399,4 @@ try-runtime = [ "pallet-vesting/try-runtime", "pallet-whitelist/try-runtime", "sp-runtime/try-runtime", - "tasks-example/try-runtime", ] diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 2069008ace76..907e3ac3e1fa 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -90,7 +90,6 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use static_assertions::const_assert; -use tasks_example; #[cfg(any(feature = "std", test))] pub use frame_system::Call as SystemCall; @@ -313,9 +312,10 @@ impl frame_system::Config for Runtime { impl pallet_insecure_randomness_collective_flip::Config for Runtime {} -impl tasks_example::Config for Runtime { +impl pallet_example_tasks::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeTask = RuntimeTask; + type WeightInfo = pallet_example_tasks::weights::SubstrateWeight; } impl pallet_utility::Config for Runtime { @@ -2139,7 +2139,7 @@ construct_runtime!( SafeMode: pallet_safe_mode, Statement: pallet_statement, Broker: pallet_broker, - TasksExample: tasks_example, + TasksExample: pallet_example_tasks, Mixnet: pallet_mixnet, } ); diff --git a/substrate/frame/balances/src/lib.rs b/substrate/frame/balances/src/lib.rs index 68c9d3ad3067..d518f933df8d 100644 --- a/substrate/frame/balances/src/lib.rs +++ b/substrate/frame/balances/src/lib.rs @@ -255,7 +255,7 @@ pub mod pallet { #[pallet::no_default_bounds] type RuntimeEvent: From> + IsType<::RuntimeEvent>; - + /// The overarching hold reason. #[pallet::no_default_bounds] type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Copy + VariantCount; diff --git a/substrate/frame/examples/tasks-example/Cargo.toml b/substrate/frame/examples/tasks-example/Cargo.toml deleted file mode 100644 index d90de4fae960..000000000000 --- a/substrate/frame/examples/tasks-example/Cargo.toml +++ /dev/null @@ -1,38 +0,0 @@ -[package] -name = "tasks-example" -version = "4.0.0-dev" -authors = ["Parity Technologies "] -edition = "2021" -license = "MIT-0" -homepage = "https://substrate.io" -repository = "https://github.com/paritytech/substrate/" -description = "FRAME example pallet" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } -log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } -frame-support = { version = "4.0.0-dev", default-features = false, path = "../../support" } -frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" } -sp-io = { version = "23.0.0", default-features = false, path = "../../../primitives/io" } -sp-runtime = { version = "24.0.0", default-features = false, path = "../../../primitives/runtime" } -sp-std = { version = "8.0.0", default-features = false, path = "../../../primitives/std" } -sp-core = { version = "21.0.0", default-features = false, path = "../../../primitives/core" } - -[features] -default = ["std"] -std = [ - "codec/std", - "frame-support/std", - "frame-system/std", - "log/std", - "scale-info/std", - "sp-io/std", - "sp-runtime/std", - "sp-std/std", - "sp-core/std", -] -try-runtime = ["frame-support/try-runtime"] diff --git a/substrate/frame/examples/tasks/Cargo.toml b/substrate/frame/examples/tasks/Cargo.toml new file mode 100644 index 000000000000..5f169e3bbeb5 --- /dev/null +++ b/substrate/frame/examples/tasks/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "pallet-example-tasks" +version = "4.0.0-dev" +authors = ["Parity Technologies "] +edition = "2021" +license = "MIT-0" +homepage = "https://substrate.io" +repository = "https://github.com/paritytech/substrate/" +description = "FRAME example pallet" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } +log = { version = "0.4.17", default-features = false } +scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } + +frame-support = { path = "../../support", default-features = false} +frame-system = { path = "../../system", default-features = false} + +sp-io = { path = "../../../primitives/io", default-features = false} +sp-runtime = { path = "../../../primitives/runtime", default-features = false} +sp-std = { path = "../../../primitives/std", default-features = false} +sp-core = { version = "21.0.0", default-features = false, path = "../../../primitives/core" } + +frame-benchmarking = { path = "../../benchmarking", default-features = false, optional = true} + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "log/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "sp-core/std", +] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "sp-runtime/try-runtime", +] diff --git a/substrate/frame/examples/tasks/src/benchmarking.rs b/substrate/frame/examples/tasks/src/benchmarking.rs new file mode 100644 index 000000000000..02d9a20e6ce8 --- /dev/null +++ b/substrate/frame/examples/tasks/src/benchmarking.rs @@ -0,0 +1,37 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Benchmarking for `pallet-example-tasks`. + +#![cfg(feature = "runtime-benchmarks")] +use super::*; + +#[allow(unused)] +use crate::Pallet as TasksExample; + +use frame_benchmarking::v2::*; +use frame_system::RawOrigin; + +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn add_number_into_total() {} + + impl_benchmark_test_suite!(TasksExample, crate::tests::new_test_ext(), crate::tests::Test); +} diff --git a/substrate/frame/examples/tasks-example/src/lib.rs b/substrate/frame/examples/tasks/src/lib.rs similarity index 96% rename from substrate/frame/examples/tasks-example/src/lib.rs rename to substrate/frame/examples/tasks/src/lib.rs index ebb3021c98fe..408209db5db3 100644 --- a/substrate/frame/examples/tasks-example/src/lib.rs +++ b/substrate/frame/examples/tasks/src/lib.rs @@ -24,6 +24,12 @@ pub use pallet::*; pub mod mock; pub mod tests; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + +pub mod weights; +pub use weights::*; + #[frame_support::pallet(dev_mode)] pub mod pallet { @@ -62,6 +68,7 @@ pub mod pallet { pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type RuntimeTask: frame_support::traits::Task; + type WeightInfo: WeightInfo; } #[pallet::pallet] diff --git a/substrate/frame/examples/tasks-example/src/mock.rs b/substrate/frame/examples/tasks/src/mock.rs similarity index 98% rename from substrate/frame/examples/tasks-example/src/mock.rs rename to substrate/frame/examples/tasks/src/mock.rs index 56b7581b100d..d2f52a8e8339 100644 --- a/substrate/frame/examples/tasks-example/src/mock.rs +++ b/substrate/frame/examples/tasks/src/mock.rs @@ -63,4 +63,5 @@ impl frame_system::Config for Runtime { impl tasks_example::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeTask = RuntimeTask; + type WeightInfo = (); } diff --git a/substrate/frame/examples/tasks-example/src/tests.rs b/substrate/frame/examples/tasks/src/tests.rs similarity index 98% rename from substrate/frame/examples/tasks-example/src/tests.rs rename to substrate/frame/examples/tasks/src/tests.rs index b574de85c0d9..ae60f48dc809 100644 --- a/substrate/frame/examples/tasks-example/src/tests.rs +++ b/substrate/frame/examples/tasks/src/tests.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Tests for `tasks-example`. +//! Tests for `pallet-example-tasks`. #![cfg(test)] use crate::{mock::*, Numbers}; use frame_support::traits::Task; diff --git a/substrate/frame/examples/tasks/src/weights.rs b/substrate/frame/examples/tasks/src/weights.rs new file mode 100644 index 000000000000..793af6e96220 --- /dev/null +++ b/substrate/frame/examples/tasks/src/weights.rs @@ -0,0 +1,84 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Autogenerated weights for `pallet_example_tasks` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-06-02, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `MacBook.local`, CPU: `` +//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/node-template +// benchmark +// pallet +// --chain +// dev +// --pallet +// pallet_example_tasks +// --extrinsic +// * +// --steps +// 20 +// --repeat +// 10 +// --output +// frame/examples/tasks/src/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for pallet_template. +pub trait WeightInfo { + fn add_number_into_total() -> Weight; +} + +/// Weight functions for `pallet_example_kitchensink`. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: Kitchensink OtherFoo (r:0 w:1) + /// Proof Skipped: Kitchensink OtherFoo (max_values: Some(1), max_size: None, mode: Measured) + fn add_number_into_total() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_000_000 picoseconds. + Weight::from_parts(1_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} + +impl WeightInfo for () { + /// Storage: Kitchensink OtherFoo (r:0 w:1) + /// Proof Skipped: Kitchensink OtherFoo (max_values: Some(1), max_size: None, mode: Measured) + fn add_number_into_total() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_000_000 picoseconds. + Weight::from_parts(1_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(RocksDbWeight::get().writes(1)) + } +} From 962f2eecf99e984a4ca47e52556e3f06805c7fef Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:26:22 +0530 Subject: [PATCH 110/177] Adds task weight parsing --- .../frame/examples/kitchensink/Cargo.toml | 1 + substrate/frame/examples/tasks/src/lib.rs | 1 + .../procedural/src/pallet/parse/tasks.rs | 56 ++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/substrate/frame/examples/kitchensink/Cargo.toml b/substrate/frame/examples/kitchensink/Cargo.toml index 1275ef0b53f6..eae362178152 100644 --- a/substrate/frame/examples/kitchensink/Cargo.toml +++ b/substrate/frame/examples/kitchensink/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT-0" homepage = "https://substrate.io" repository.workspace = true description = "FRAME example kitchensink pallet" +publish = false [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/substrate/frame/examples/tasks/src/lib.rs b/substrate/frame/examples/tasks/src/lib.rs index 408209db5db3..3d677762be7d 100644 --- a/substrate/frame/examples/tasks/src/lib.rs +++ b/substrate/frame/examples/tasks/src/lib.rs @@ -53,6 +53,7 @@ pub mod pallet { /// Add a pair of numbers into the totals and remove them. #[pallet::task_list(Numbers::::iter_keys())] #[pallet::task_condition(|i| Numbers::::contains_key(i))] + #[pallet::task_weight(T::WeightInfo::add_number_into_total())] #[pallet::task_index(0)] pub fn add_number_into_total(i: u32) -> DispatchResult { let v = Numbers::::take(i).ok_or(Error::::NotFound)?; diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 9be9085a7778..16672f8a16b1 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -44,6 +44,7 @@ pub mod keywords { custom_keyword!(task_list); custom_keyword!(task_condition); custom_keyword!(task_index); + custom_keyword!(task_weight); custom_keyword!(pallet); } @@ -130,6 +131,7 @@ pub type TaskAttr = PalletTaskAttr; pub type TaskIndexAttr = PalletTaskAttr; pub type TaskConditionAttr = PalletTaskAttr; pub type TaskListAttr = PalletTaskAttr; +pub type TaskWeightAttr = PalletTaskAttr; pub type PalletTaskEnumAttr = PalletTaskAttr; #[derive(Clone, Debug)] @@ -195,6 +197,7 @@ pub struct TaskDef { pub index_attr: TaskIndexAttr, pub condition_attr: TaskConditionAttr, pub list_attr: TaskListAttr, + pub weight_attr: TaskWeightAttr, pub normal_attrs: Vec, pub item: ImplItemFn, } @@ -216,6 +219,7 @@ impl syn::parse::Parse for TaskDef { (suffix.ident == "tasks" || suffix.ident == "task_list" || suffix.ident == "task_condition" || + suffix.ident == "task_weight" || suffix.ident == "task_index") }); @@ -257,6 +261,17 @@ impl syn::parse::Parse for TaskDef { )) }; + let Some(weight_attr) = task_attrs + .iter() + .find(|attr| matches!(attr.meta, TaskAttrMeta::TaskWeight(_))) + .cloned() + else { + return Err(Error::new( + item.sig.ident.span(), + "missing `#[pallet::task_weight(..)]` attribute", + )) + }; + if let Some(duplicate) = task_attrs .iter() .filter(|attr| matches!(attr.meta, TaskAttrMeta::TaskCondition(_))) @@ -296,8 +311,9 @@ impl syn::parse::Parse for TaskDef { let index_attr = index_attr.try_into().expect("we check the type above; QED"); let condition_attr = condition_attr.try_into().expect("we check the type above; QED"); let list_attr = list_attr.try_into().expect("we check the type above; QED"); + let weight_attr = weight_attr.try_into().expect("we check the type above; QED"); - Ok(TaskDef { index_attr, condition_attr, list_attr, normal_attrs, item }) + Ok(TaskDef { index_attr, condition_attr, list_attr, weight_attr, normal_attrs, item }) } } @@ -309,6 +325,8 @@ pub enum TaskAttrMeta { TaskIndex(TaskIndexAttrMeta), #[peek(keywords::task_condition, name = "#[pallet::task_condition(..)")] TaskCondition(TaskConditionAttrMeta), + #[peek(keywords::task_weight, name = "#[pallet::task_weight(..)")] + TaskWeight(TaskWeightAttrMeta), } #[derive(Parse, Debug, Clone)] @@ -338,6 +356,15 @@ pub struct TaskConditionAttrMeta { pub expr: Expr, } +#[derive(Parse, Debug, Clone)] +pub struct TaskWeightAttrMeta { + pub task_weight: keywords::task_weight, + #[paren] + _paren: Paren, + #[inside(_paren)] + pub expr: Expr, +} + #[derive(Parse, Debug, Clone)] pub struct PalletTaskAttr { pub pound: Pound, @@ -367,6 +394,14 @@ impl ToTokens for TaskConditionAttrMeta { } } +impl ToTokens for TaskWeightAttrMeta { + fn to_tokens(&self, tokens: &mut TokenStream2) { + let task_weight = self.task_weight; + let expr = &self.expr; + tokens.extend(quote!(#task_weight(#expr))); + } +} + impl ToTokens for TaskIndexAttrMeta { fn to_tokens(&self, tokens: &mut TokenStream2) { let task_index = self.task_index; @@ -381,6 +416,7 @@ impl ToTokens for TaskAttrMeta { TaskAttrMeta::TaskList(list) => tokens.extend(list.to_token_stream()), TaskAttrMeta::TaskIndex(index) => tokens.extend(index.to_token_stream()), TaskAttrMeta::TaskCondition(condition) => tokens.extend(condition.to_token_stream()), + TaskAttrMeta::TaskWeight(weight) => tokens.extend(weight.to_token_stream()), } } } @@ -431,6 +467,24 @@ impl TryFrom> for TaskConditionAttr { } } +impl TryFrom> for TaskWeightAttr { + type Error = syn::Error; + + fn try_from(value: PalletTaskAttr) -> Result { + let pound = value.pound; + let pallet = value.pallet; + let colons = value.colons; + match value.meta { + TaskAttrMeta::TaskWeight(meta) => parse2(quote!(#pound[#pallet #colons #meta])), + _ => + return Err(Error::new( + value.span(), + format!("`{:?}` cannot be converted to a `TaskWeightAttr`", value.meta), + )), + } + } +} + impl TryFrom> for TaskListAttr { type Error = syn::Error; From b5734a244fd7758c6fc69f4a8a8febb229bd7c28 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:53:31 +0530 Subject: [PATCH 111/177] Adds weight support for tasks --- substrate/frame/examples/tasks/Cargo.toml | 1 + .../frame/examples/tasks/src/benchmarking.rs | 14 +++++-- .../procedural/src/pallet/expand/tasks.rs | 38 +++++++++++++++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/substrate/frame/examples/tasks/Cargo.toml b/substrate/frame/examples/tasks/Cargo.toml index 5f169e3bbeb5..aa7a528c2ccf 100644 --- a/substrate/frame/examples/tasks/Cargo.toml +++ b/substrate/frame/examples/tasks/Cargo.toml @@ -30,6 +30,7 @@ frame-benchmarking = { path = "../../benchmarking", default-features = false, op default = ["std"] std = [ "codec/std", + "frame-benchmarking?/std", "frame-support/std", "frame-system/std", "log/std", diff --git a/substrate/frame/examples/tasks/src/benchmarking.rs b/substrate/frame/examples/tasks/src/benchmarking.rs index 02d9a20e6ce8..109e9526fb57 100644 --- a/substrate/frame/examples/tasks/src/benchmarking.rs +++ b/substrate/frame/examples/tasks/src/benchmarking.rs @@ -24,14 +24,22 @@ use super::*; use crate::Pallet as TasksExample; use frame_benchmarking::v2::*; -use frame_system::RawOrigin; #[benchmarks] mod benchmarks { use super::*; #[benchmark] - fn add_number_into_total() {} + fn add_number_into_total() { + Numbers::::insert(0, 1); - impl_benchmark_test_suite!(TasksExample, crate::tests::new_test_ext(), crate::tests::Test); + #[block] + { + Task::::add_number_into_total(0).unwrap(); + } + + assert_eq!(Numbers::::get(0), None); + } + + impl_benchmark_test_suite!(TasksExample, crate::tests::new_test_ext(), crate::mock::Runtime); } diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 9adbdce91bfe..c99ba5638ffe 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -108,6 +108,12 @@ impl ToTokens for TaskEnumDef { } } +#[derive(Parse)] +pub struct ExpandedTasksDef { + pub task_item_impl: ItemImpl, + pub task_trait_impl: ItemImpl, +} + impl ToTokens for TasksDef { fn to_tokens(&self, tokens: &mut TokenStream2) { let scrate = &self.scrate; @@ -122,8 +128,16 @@ impl ToTokens for TasksDef { .collect::>(); let task_indices = self.tasks.iter().map(|task| &task.index_attr.meta.index); let task_conditions = self.tasks.iter().map(|task| &task.condition_attr.meta.expr); + let task_weights = self.tasks.iter().map(|task| &task.weight_attr.meta.expr); let task_iters = self.tasks.iter().map(|task| &task.list_attr.meta.expr); - let task_fn_blocks = self.tasks.iter().map(|task| &task.item.block); + + let task_fn_impls = self.tasks.iter().map(|task| { + let mut task_fn_impl = task.item.clone(); + task_fn_impl.attrs = vec![]; + task_fn_impl + }); + + let task_fn_names = self.tasks.iter().map(|task| &task.item.sig.ident); let task_arg_names = self .tasks .iter() @@ -147,6 +161,11 @@ impl ToTokens for TasksDef { let sp_std = quote!(#scrate::__private::sp_std); let impl_generics = &self.item_impl.generics; tokens.extend(quote! { + impl #impl_generics #enum_use + { + #(#task_fn_impls)* + } + impl #impl_generics #scrate::traits::Task for #enum_use where T: #scrate::pallet_prelude::TypeInfo, @@ -175,13 +194,19 @@ impl ToTokens for TasksDef { fn run(&self) -> Result<(), #scrate::pallet_prelude::DispatchError> { match self.clone() { - #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => #task_fn_blocks),*, + #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => { + <#enum_use>::#task_fn_names(#( #task_arg_names, )* ) + }),*, Task::__Ignore(_, _) => unreachable!(), } } + #[allow(unused_variables)] fn weight(&self) -> #scrate::pallet_prelude::Weight { - #scrate::pallet_prelude::Weight::default() + match self.clone() { + #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => #task_weights),*, + Task::__Ignore(_, _) => unreachable!(), + } } } }); @@ -190,19 +215,18 @@ impl ToTokens for TasksDef { pub fn expand_tasks_impl(def: &mut Def) -> TokenStream2 { let Some(tasks) = &mut def.tasks else { return quote!() }; - let output: ItemImpl = parse_quote!(#tasks); - // output.pretty_print(); + let ExpandedTasksDef { task_item_impl, task_trait_impl } = parse_quote!(#tasks); let Some(content) = &mut def.item.content else { return quote!() }; for item in content.1.iter_mut() { let Item::Impl(item_impl) = item else { continue }; let Some(trait_) = &item_impl.trait_ else { continue }; let Some(last_seg) = trait_.1.segments.last() else { continue }; if last_seg.ident == "Task" { - *item_impl = output; + *item_impl = task_item_impl; break } } - quote!() + quote!(#task_trait_impl) } #[derive(Parse)] From 9d1e31b161338a26f49460e682e278173cbb162e Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:24:16 +0530 Subject: [PATCH 112/177] Adds RuntimeTask in Config --- .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 458876ce46c1..89b2cc3751bc 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -227,6 +227,8 @@ impl frame_system::Config for Runtime { type Block = Block; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; + /// The ubiquitous task type. + type RuntimeTask = RuntimeTask; /// The ubiquitous origin type. type RuntimeOrigin = RuntimeOrigin; /// Maximum number of block number to block hash mappings to keep (oldest pruned first). From 418e3384bc0140a47b91689aef6deacaaa41ab93 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 10 Nov 2023 15:36:11 +0530 Subject: [PATCH 113/177] Fixes tests --- .../procedural/src/pallet/parse/tasks.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 16672f8a16b1..7bd392fa7687 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -592,6 +592,7 @@ fn test_parse_tasks_def_basic_increment_decrement() { value < 255 })] #[pallet::task_list(Vec::>::new())] + #[pallet::task_weight(0)] fn increment() -> DispatchResult { let value = Value::::get().unwrap_or_default(); if value >= 255 { @@ -611,6 +612,7 @@ fn test_parse_tasks_def_basic_increment_decrement() { value > 0 })] #[pallet::task_list(Vec::>::new())] + #[pallet::task_weight(0)] fn decrement() -> DispatchResult { let value = Value::::get().unwrap_or_default(); if value == 0 { @@ -639,6 +641,7 @@ fn test_parse_tasks_def_duplicate_index() { #[pallet::task_list(Something::iter())] #[pallet::task_condition(|i| i % 2 == 0)] #[pallet::task_index(0)] + #[pallet::task_weight(0)] pub fn foo(i: u32) -> DispatchResult { Ok(()) } @@ -646,6 +649,7 @@ fn test_parse_tasks_def_duplicate_index() { #[pallet::task_list(Numbers::::iter_keys())] #[pallet::task_condition(|i| Numbers::::contains_key(i))] #[pallet::task_index(0)] + #[pallet::task_weight(0)] pub fn bar(i: u32) -> DispatchResult { Ok(()) } @@ -713,6 +717,26 @@ fn test_parse_tasks_def_missing_task_index() { }); } +#[test] +fn test_parse_tasks_def_missing_task_weight() { + simulate_manifest_dir("../../examples/basic", || { + assert_error_matches!( + parse2::(quote! { + #[pallet::tasks] + impl, I: 'static> Pallet { + #[pallet::task_condition(|i| i % 2 == 0)] + #[pallet::task_list(Something::iter())] + #[pallet::task_index(0)] + pub fn foo(i: u32) -> DispatchResult { + Ok(()) + } + } + }), + r"missing `#\[pallet::task_weight\(\.\.\)\]`" + ); + }); +} + #[test] fn test_parse_tasks_def_unexpected_extra_task_list_attr() { simulate_manifest_dir("../../examples/basic", || { @@ -722,6 +746,7 @@ fn test_parse_tasks_def_unexpected_extra_task_list_attr() { impl, I: 'static> Pallet { #[pallet::task_condition(|i| i % 2 == 0)] #[pallet::task_index(0)] + #[pallet::task_weight(0)] #[pallet::task_list(Something::iter())] #[pallet::task_list(SomethingElse::iter())] pub fn foo(i: u32) -> DispatchResult { @@ -745,6 +770,7 @@ fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { #[pallet::task_condition(|i| i % 4 == 0)] #[pallet::task_index(0)] #[pallet::task_list(Something::iter())] + #[pallet::task_weight(0)] pub fn foo(i: u32) -> DispatchResult { Ok(()) } @@ -766,6 +792,7 @@ fn test_parse_tasks_def_unexpected_extra_task_index_attr() { #[pallet::task_index(0)] #[pallet::task_index(0)] #[pallet::task_list(Something::iter())] + #[pallet::task_weight(0)] pub fn foo(i: u32) -> DispatchResult { Ok(()) } From 13d5d513cd5863da4ae0e9e52115dc2e628d621e Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 10 Nov 2023 17:08:40 +0530 Subject: [PATCH 114/177] Fixes another test --- substrate/frame/support/procedural/src/pallet/parse/tasks.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 7bd392fa7687..f872e1e78785 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -564,6 +564,7 @@ fn test_parse_tasks_def_basic() { #[pallet::task_list(Numbers::::iter_keys())] #[pallet::task_condition(|i| Numbers::::contains_key(i))] #[pallet::task_index(0)] + #[pallet::task_weight(0)] pub fn add_number_into_total(i: u32) -> DispatchResult { let v = Numbers::::take(i).ok_or(Error::::NotFound)?; Total::::mutate(|(total_keys, total_values)| { From 923e768237a10798df5fc4194528c4692704b169 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:47:07 +0530 Subject: [PATCH 115/177] Fixes a todo --- polkadot/xcm/procedural/tests/ui.rs | 2 +- .../procedural/src/pallet/expand/tasks.rs | 20 +--------------- .../procedural/src/pallet/parse/tasks.rs | 23 ++++++++++++++++++- .../utils/wasm-builder/src/wasm_project.rs | 2 +- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/polkadot/xcm/procedural/tests/ui.rs b/polkadot/xcm/procedural/tests/ui.rs index a6ec35d0862a..fef7c95c6142 100644 --- a/polkadot/xcm/procedural/tests/ui.rs +++ b/polkadot/xcm/procedural/tests/ui.rs @@ -21,7 +21,7 @@ fn ui() { // Only run the ui tests when `RUN_UI_TESTS` is set. if std::env::var("RUN_UI_TESTS").is_err() { - return; + return } // As trybuild is using `cargo check`, we don't need the real WASM binaries. diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index c99ba5638ffe..e5e306c633b9 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -138,25 +138,7 @@ impl ToTokens for TasksDef { }); let task_fn_names = self.tasks.iter().map(|task| &task.item.sig.ident); - let task_arg_names = self - .tasks - .iter() - .map(|task| { - task.item - .sig - .inputs - .iter() - .map(|input| match input { - // Todo: This should be checked in the parsing stage. - syn::FnArg::Typed(pat_type) => match &*pat_type.pat { - syn::Pat::Ident(ident) => quote!(#ident), - _ => panic!("unexpected pattern type"), - }, - _ => panic!("unexpected function argument type"), - }) - .collect::>() - }) - .collect::>(); + let task_arg_names = self.tasks.iter().map(|task| &task.arg_names).collect::>(); let sp_std = quote!(#scrate::__private::sp_std); let impl_generics = &self.item_impl.generics; diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index f872e1e78785..f02d294d13d0 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -200,6 +200,7 @@ pub struct TaskDef { pub weight_attr: TaskWeightAttr, pub normal_attrs: Vec, pub item: ImplItemFn, + pub arg_names: Vec, } impl syn::parse::Parse for TaskDef { @@ -308,12 +309,32 @@ impl syn::parse::Parse for TaskDef { )) } + let mut arg_names = vec![]; + for input in item.sig.inputs.iter() { + match input { + // Todo: This should be checked in the parsing stage. + syn::FnArg::Typed(pat_type) => match &*pat_type.pat { + syn::Pat::Ident(ident) => arg_names.push(ident.ident.clone()), + _ => return Err(Error::new(input.span(), "unexpected pattern type")), + }, + _ => return Err(Error::new(input.span(), "unexpected function argument type")), + } + } + let index_attr = index_attr.try_into().expect("we check the type above; QED"); let condition_attr = condition_attr.try_into().expect("we check the type above; QED"); let list_attr = list_attr.try_into().expect("we check the type above; QED"); let weight_attr = weight_attr.try_into().expect("we check the type above; QED"); - Ok(TaskDef { index_attr, condition_attr, list_attr, weight_attr, normal_attrs, item }) + Ok(TaskDef { + index_attr, + condition_attr, + list_attr, + weight_attr, + normal_attrs, + item, + arg_names, + }) } } diff --git a/substrate/utils/wasm-builder/src/wasm_project.rs b/substrate/utils/wasm-builder/src/wasm_project.rs index 2e6f671c45ed..9c25d1aba3cf 100644 --- a/substrate/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/utils/wasm-builder/src/wasm_project.rs @@ -916,7 +916,7 @@ fn generate_rerun_if_changed_instructions( while let Some(dependency) = dependencies.pop() { // Ignore all dev dependencies if dependency.kind == DependencyKind::Development { - continue; + continue } let path_or_git_dep = From 835ed81cc269da58654902eb8c5aa5cae3a6ee21 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:49:48 +0530 Subject: [PATCH 116/177] Fixes another todo --- .../procedural/src/construct_runtime/expand/task.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index f5580d25e384..c10f479389b5 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -35,11 +35,9 @@ pub fn expand_outer_task( let path = &decl.path; let index = decl.index; - // TODO: `pallet` will probably not be needed when `Task` is generated by macro - from_impls.push(quote! { - impl From<#path::pallet::Task<#runtime_name>> for RuntimeTask { - fn from(hr: #path::pallet::Task<#runtime_name>) -> Self { + impl From<#path::Task<#runtime_name>> for RuntimeTask { + fn from(hr: #path::Task<#runtime_name>) -> Self { RuntimeTask::#variant_name(hr) } } @@ -47,12 +45,12 @@ pub fn expand_outer_task( task_variants.push(quote! { #[codec(index = #index)] - #variant_name(#path::pallet::Task<#runtime_name>), + #variant_name(#path::Task<#runtime_name>), }); variant_names.push(quote!(#variant_name)); - task_paths.push(quote!(#path::pallet::Task)); + task_paths.push(quote!(#path::Task)); } } From 0a53b36eadb9e68268d39ea86e928a83edf22240 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:01:50 +0530 Subject: [PATCH 117/177] Cleans up task example pallet --- Cargo.lock | 1 + substrate/bin/node/runtime/src/lib.rs | 1 - substrate/frame/examples/Cargo.toml | 3 ++ substrate/frame/examples/src/lib.rs | 2 ++ substrate/frame/examples/tasks/src/lib.rs | 35 ---------------------- substrate/frame/examples/tasks/src/mock.rs | 34 ++++----------------- 6 files changed, 11 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54785aaf75ea..cd44e105525a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10037,6 +10037,7 @@ dependencies = [ "pallet-example-kitchensink", "pallet-example-offchain-worker", "pallet-example-split", + "pallet-example-tasks", ] [[package]] diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index ae27c4917639..82d869d7fb20 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -313,7 +313,6 @@ impl frame_system::Config for Runtime { impl pallet_insecure_randomness_collective_flip::Config for Runtime {} impl pallet_example_tasks::Config for Runtime { - type RuntimeEvent = RuntimeEvent; type RuntimeTask = RuntimeTask; type WeightInfo = pallet_example_tasks::weights::SubstrateWeight; } diff --git a/substrate/frame/examples/Cargo.toml b/substrate/frame/examples/Cargo.toml index 1b2150227154..76709cf704a4 100644 --- a/substrate/frame/examples/Cargo.toml +++ b/substrate/frame/examples/Cargo.toml @@ -20,6 +20,7 @@ pallet-example-frame-crate = { path = "frame-crate", default-features = false } pallet-example-kitchensink = { path = "kitchensink", default-features = false} pallet-example-offchain-worker = { path = "offchain-worker", default-features = false} pallet-example-split = { path = "split", default-features = false} +pallet-example-tasks = { path = "tasks", default-features = false} [features] default = [ "std" ] @@ -31,6 +32,7 @@ std = [ "pallet-example-kitchensink/std", "pallet-example-offchain-worker/std", "pallet-example-split/std", + "pallet-example-tasks/std", ] try-runtime = [ "pallet-default-config-example/try-runtime", @@ -39,4 +41,5 @@ try-runtime = [ "pallet-example-kitchensink/try-runtime", "pallet-example-offchain-worker/try-runtime", "pallet-example-split/try-runtime", + "pallet-example-tasks/try-runtime", ] diff --git a/substrate/frame/examples/src/lib.rs b/substrate/frame/examples/src/lib.rs index 8d65639f8352..c86818876f4e 100644 --- a/substrate/frame/examples/src/lib.rs +++ b/substrate/frame/examples/src/lib.rs @@ -43,4 +43,6 @@ //! - [`pallet_example_frame_crate`]: Example pallet showcasing how one can be //! built using only the `frame` umbrella crate. //! +//! - [`pallet_example_tasks`]: This pallet demonstrates the use of `Tasks` to execute service work +//! //! **Tip**: Use `cargo doc --package --open` to view each pallet's documentation. diff --git a/substrate/frame/examples/tasks/src/lib.rs b/substrate/frame/examples/tasks/src/lib.rs index 3d677762be7d..30960c4c76b8 100644 --- a/substrate/frame/examples/tasks/src/lib.rs +++ b/substrate/frame/examples/tasks/src/lib.rs @@ -35,16 +35,9 @@ pub mod pallet { use super::*; use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - // we can automatically inject `InvalidTask` into an existing Error enum by finding it via - // visitor pattern, otherwise we can just emit an error enum containing just our - // `InvalidTask` variant. Alternatively we could just expect that `InvalidTask` is included - // in the error enum, by convention, or we could use something like - // `InvalidTransaction::Custom(1u8)` but this seems bad to me. #[pallet::error] pub enum Error { - InvalidTask, NotFound, } @@ -67,7 +60,6 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { - type RuntimeEvent: From> + IsType<::RuntimeEvent>; type RuntimeTask: frame_support::traits::Task; type WeightInfo: WeightInfo; } @@ -82,31 +74,4 @@ pub mod pallet { /// Numbers to be added into the total. #[pallet::storage] pub type Numbers = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>; - - #[pallet::call] - impl Pallet - where - T: TypeInfo, - { - // this will be auto-generated by the macros and will always be the same - pub fn do_task(origin: OriginFor, task: crate::pallet::Task) -> DispatchResult { - use frame_support::traits::Task; - ensure_root(origin)?; - if task.is_valid() { - let result = task.run(); - if result.is_ok() { - Self::deposit_event(Event::TaskExecuted { task }); - } - result - } else { - Err(Error::::InvalidTask.into()) - } - } - } - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - TaskExecuted { task: Task }, - } } diff --git a/substrate/frame/examples/tasks/src/mock.rs b/substrate/frame/examples/tasks/src/mock.rs index d2f52a8e8339..e0fbec3eb765 100644 --- a/substrate/frame/examples/tasks/src/mock.rs +++ b/substrate/frame/examples/tasks/src/mock.rs @@ -19,49 +19,25 @@ #![cfg(test)] use crate::{self as tasks_example}; +use frame_support::derive_impl; pub type AccountId = u32; pub type Balance = u32; type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub struct Runtime - { - System: frame_system::{Pallet, Call, Storage, Event, Config}, - TasksExample: tasks_example::{Pallet, Call, Storage, Event, Task}, + pub struct Runtime { + System: frame_system, + TasksExample: tasks_example, } ); -// TODO: use derive_impl +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { - type SS58Prefix = (); - type BaseCallFilter = frame_support::traits::Everything; - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; - type Hash = sp_core::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; - type AccountId = AccountId; - type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type DbWeight = (); - type BlockLength = (); - type BlockWeights = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } impl tasks_example::Config for Runtime { - type RuntimeEvent = RuntimeEvent; type RuntimeTask = RuntimeTask; type WeightInfo = (); } From 6d7d9b799f81d4948b592623d4e10c4a058640ef Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:05:50 +0530 Subject: [PATCH 118/177] Nits --- Cargo.lock | 2 +- substrate/frame/examples/tasks/Cargo.toml | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd44e105525a..6afc96a8843b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10012,7 +10012,7 @@ dependencies = [ [[package]] name = "pallet-example-tasks" -version = "4.0.0-dev" +version = "1.0.0-dev" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/substrate/frame/examples/tasks/Cargo.toml b/substrate/frame/examples/tasks/Cargo.toml index aa7a528c2ccf..eb1b87320f34 100644 --- a/substrate/frame/examples/tasks/Cargo.toml +++ b/substrate/frame/examples/tasks/Cargo.toml @@ -1,12 +1,11 @@ [package] name = "pallet-example-tasks" -version = "4.0.0-dev" -authors = ["Parity Technologies "] -edition = "2021" -license = "MIT-0" -homepage = "https://substrate.io" -repository = "https://github.com/paritytech/substrate/" -description = "FRAME example pallet" +version = "1.0.0-dev" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +description = "Pallet to demonstrate the usage of Tasks to recongnize and execute service work" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] From da208f69c3ed0b62c57397c7d066626d87487049 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:12:24 +0530 Subject: [PATCH 119/177] Fixes feature propagation --- substrate/bin/node/runtime/Cargo.toml | 6 +++--- substrate/frame/examples/tasks/Cargo.toml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 531e7bccf83a..ce45008c27a9 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -180,6 +180,7 @@ std = [ "pallet-election-provider-multi-phase/std", "pallet-election-provider-support-benchmarking?/std", "pallet-elections-phragmen/std", + "pallet-example-tasks/std", "pallet-fast-unstake/std", "pallet-glutton/std", "pallet-grandpa/std", @@ -221,7 +222,6 @@ std = [ "pallet-state-trie-migration/std", "pallet-statement/std", "pallet-sudo/std", - "pallet-example-tasks/std", "pallet-timestamp/std", "pallet-tips/std", "pallet-transaction-payment-rpc-runtime-api/std", @@ -283,6 +283,7 @@ runtime-benchmarks = [ "pallet-election-provider-multi-phase/runtime-benchmarks", "pallet-election-provider-support-benchmarking/runtime-benchmarks", "pallet-elections-phragmen/runtime-benchmarks", + "pallet-example-tasks/runtime-benchmarks", "pallet-fast-unstake/runtime-benchmarks", "pallet-glutton/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", @@ -317,7 +318,6 @@ runtime-benchmarks = [ "pallet-staking/runtime-benchmarks", "pallet-state-trie-migration/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", - "pallet-example-tasks/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-tips/runtime-benchmarks", "pallet-transaction-storage/runtime-benchmarks", @@ -358,6 +358,7 @@ try-runtime = [ "pallet-democracy/try-runtime", "pallet-election-provider-multi-phase/try-runtime", "pallet-elections-phragmen/try-runtime", + "pallet-example-tasks/try-runtime", "pallet-fast-unstake/try-runtime", "pallet-glutton/try-runtime", "pallet-grandpa/try-runtime", @@ -393,7 +394,6 @@ try-runtime = [ "pallet-state-trie-migration/try-runtime", "pallet-statement/try-runtime", "pallet-sudo/try-runtime", - "pallet-example-tasks/try-runtime", "pallet-timestamp/try-runtime", "pallet-tips/try-runtime", "pallet-transaction-payment/try-runtime", diff --git a/substrate/frame/examples/tasks/Cargo.toml b/substrate/frame/examples/tasks/Cargo.toml index eb1b87320f34..21822c39ee79 100644 --- a/substrate/frame/examples/tasks/Cargo.toml +++ b/substrate/frame/examples/tasks/Cargo.toml @@ -26,7 +26,7 @@ sp-core = { version = "21.0.0", default-features = false, path = "../../../primi frame-benchmarking = { path = "../../benchmarking", default-features = false, optional = true} [features] -default = ["std"] +default = [ "std" ] std = [ "codec/std", "frame-benchmarking?/std", @@ -34,10 +34,10 @@ std = [ "frame-system/std", "log/std", "scale-info/std", + "sp-core/std", "sp-io/std", "sp-runtime/std", "sp-std/std", - "sp-core/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", From 140679b34bbd1bc960f8779acffef93a9cd63ab3 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:37:49 +0530 Subject: [PATCH 120/177] Adds tests for task execution --- substrate/frame/examples/tasks/src/tests.rs | 41 ++++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/substrate/frame/examples/tasks/src/tests.rs b/substrate/frame/examples/tasks/src/tests.rs index ae60f48dc809..764ca89e12e7 100644 --- a/substrate/frame/examples/tasks/src/tests.rs +++ b/substrate/frame/examples/tasks/src/tests.rs @@ -17,8 +17,8 @@ //! Tests for `pallet-example-tasks`. #![cfg(test)] -use crate::{mock::*, Numbers}; -use frame_support::traits::Task; +use crate::{mock::*, Numbers, Total}; +use frame_support::{assert_noop, assert_ok, traits::Task}; use sp_runtime::BuildStorage; // This function basically just builds a genesis storage key/value store according to @@ -87,3 +87,40 @@ fn task_index_works_at_runtime_level() { ); }); } + +#[test] +fn task_execution_works() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + Numbers::::insert(0, 1); + Numbers::::insert(1, 4); + + let task = + ::RuntimeTask::TasksExample(crate::pallet::Task::< + Runtime, + >::AddNumberIntoTotal { + i: 1u32, + }); + 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)); + System::assert_last_event(frame_system::Event::::TaskCompleted { task }.into()); + }); +} + +#[test] +fn task_execution_fails_for_invalid_task() { + new_test_ext().execute_with(|| { + Numbers::::insert(1, 4); + assert_noop!( + System::do_task( + RuntimeOrigin::signed(1), + ::RuntimeTask::TasksExample( + crate::pallet::Task::::AddNumberIntoTotal { i: 0u32 } + ), + ), + frame_system::Error::::InvalidTask + ); + }); +} From 33cb94fbfbdd6704d2d9c0e9a37aeae6d9fb2815 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:09:03 +0530 Subject: [PATCH 121/177] Updates UI Tests --- .../generics_in_invalid_module.stderr | 2 +- .../invalid_module_details_keyword.stderr | 2 +- .../invalid_module_entry.stderr | 2 +- .../number_of_pallets_exceeds_tuple_size.rs | 1 + ...umber_of_pallets_exceeds_tuple_size.stderr | 16 +++- .../pallet_error_too_large.rs | 1 + .../pallet_error_too_large.stderr | 18 ++-- .../undefined_call_part.rs | 1 + .../undefined_call_part.stderr | 14 +-- .../undefined_event_part.rs | 1 + .../undefined_event_part.stderr | 30 +++--- .../undefined_genesis_config_part.rs | 1 + .../undefined_genesis_config_part.stderr | 30 +++--- .../undefined_inherent_part.rs | 1 + .../undefined_inherent_part.stderr | 94 +++++++++---------- .../undefined_origin_part.rs | 1 + .../undefined_origin_part.stderr | 30 +++--- .../undefined_validate_unsigned_part.rs | 1 + .../undefined_validate_unsigned_part.stderr | 58 ++++++------ .../inject_runtime_type_invalid.stderr | 2 +- ...mposite_enum_unsupported_identifier.stderr | 2 +- .../tests/pallet_ui/pass/dev_mode_valid.rs | 1 + .../pallet_ui/pass/no_std_genesis_config.rs | 1 + 23 files changed, 163 insertions(+), 147 deletions(-) diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/generics_in_invalid_module.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/generics_in_invalid_module.stderr index bf53f43b9ba7..8458de97f6d3 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/generics_in_invalid_module.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/generics_in_invalid_module.stderr @@ -1,4 +1,4 @@ -error: `Call` is not allowed to have generics. Only the following pallets are allowed to have generics: `Event`, `Error`, `Origin`, `Config`. +error: `Call` is not allowed to have generics. Only the following pallets are allowed to have generics: `Event`, `Error`, `Origin`, `Config`, `Task`. --> tests/construct_runtime_ui/generics_in_invalid_module.rs:24:36 | 24 | Balance: balances::::{Call, Origin}, diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/invalid_module_details_keyword.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/invalid_module_details_keyword.stderr index ad631de204e6..feb61793151d 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/invalid_module_details_keyword.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/invalid_module_details_keyword.stderr @@ -1,4 +1,4 @@ -error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Error`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`, `FreezeReason`, `HoldReason`, `LockId`, `SlashReason` +error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Error`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`, `FreezeReason`, `HoldReason`, `Task`, `LockId`, `SlashReason` --> tests/construct_runtime_ui/invalid_module_details_keyword.rs:23:20 | 23 | system: System::{enum}, diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/invalid_module_entry.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/invalid_module_entry.stderr index b5b89a5a270c..97943dfc1763 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/invalid_module_entry.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/invalid_module_entry.stderr @@ -1,4 +1,4 @@ -error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Error`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`, `FreezeReason`, `HoldReason`, `LockId`, `SlashReason` +error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Error`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`, `FreezeReason`, `HoldReason`, `Task`, `LockId`, `SlashReason` --> tests/construct_runtime_ui/invalid_module_entry.rs:24:23 | 24 | Balance: balances::{Unexpected}, diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs index ea52293a6732..f0a65707e147 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.stderr index af9069edc80d..15c45d8f3c30 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.stderr @@ -1,7 +1,7 @@ error: The number of pallets exceeds the maximum number of tuple elements. To increase this limit, enable the tuples-96 feature of [frame_support]. - --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:66:2 + --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:67:2 | -66 | pub struct Runtime +67 | pub struct Runtime | ^^^ error[E0412]: cannot find type `RuntimeCall` in this scope @@ -45,15 +45,21 @@ error[E0412]: cannot find type `RuntimeEvent` in this scope 49 | type RuntimeEvent = RuntimeEvent; | ^^^^^^^^^^^^ help: you might have meant to use the associated type: `Self::RuntimeEvent` +error[E0412]: cannot find type `RuntimeTask` in this scope + --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:50:21 + | +50 | type RuntimeTask = RuntimeTask; + | ^^^^^^^^^^^ help: you might have meant to use the associated type: `Self::RuntimeTask` + error[E0412]: cannot find type `PalletInfo` in this scope - --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:55:20 + --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:56:20 | -55 | type PalletInfo = PalletInfo; +56 | type PalletInfo = PalletInfo; | ^^^^^^^^^^ | help: you might have meant to use the associated type | -55 | type PalletInfo = Self::PalletInfo; +56 | type PalletInfo = Self::PalletInfo; | ~~~~~~~~~~~~~~~~ help: consider importing one of these items | diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs index 2834b5b8f2a8..694ec4354f1b 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs @@ -72,6 +72,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr index 0ad408b81230..ebbb9ffb0eb0 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr @@ -1,13 +1,13 @@ error[E0080]: evaluation of constant value failed - --> tests/construct_runtime_ui/pallet_error_too_large.rs:90:1 + --> tests/construct_runtime_ui/pallet_error_too_large.rs:91:1 | -90 | / construct_runtime! { -91 | | pub struct Runtime -92 | | { -93 | | System: frame_system::{Pallet, Call, Storage, Config, Event}, -94 | | Pallet: pallet::{Pallet}, -95 | | } -96 | | } - | |_^ the evaluated program panicked at 'The maximum encoded size of the error type in the `Pallet` pallet exceeds `MAX_MODULE_ERROR_ENCODED_SIZE`', $DIR/tests/construct_runtime_ui/pallet_error_too_large.rs:90:1 +91 | / construct_runtime! { +92 | | pub struct Runtime +93 | | { +94 | | System: frame_system::{Pallet, Call, Storage, Config, Event}, +95 | | Pallet: pallet::{Pallet}, +96 | | } +97 | | } + | |_^ the evaluated program panicked at 'The maximum encoded size of the error type in the `Pallet` pallet exceeds `MAX_MODULE_ERROR_ENCODED_SIZE`', $DIR/tests/construct_runtime_ui/pallet_error_too_large.rs:91:1 | = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs index 62c4b1327e0a..383645a32316 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr index c6dfeb792b8e..b9cf58542f20 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.stderr @@ -4,13 +4,13 @@ error: `Pallet` does not have #[pallet::call] defined, perhaps you should remove 22 | #[frame_support::pallet] | ^^^^^^^^^^^^^^^^^^^^^^^^ ... -65 | / construct_runtime! { -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet::{Pallet, Call}, -70 | | } -71 | | } +66 | / construct_runtime! { +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet::{Pallet, Call}, +71 | | } +72 | | } | |_- in this macro invocation | = note: this error originates in the macro `pallet::__substrate_call_check::is_call_part_defined` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs index 893690501a83..b98dc0a6df24 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr index 6dd332630ada..6f412fe89eab 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.stderr @@ -4,27 +4,27 @@ error: `Pallet` does not have #[pallet::event] defined, perhaps you should remov 22 | #[frame_support::pallet] | ^^^^^^^^^^^^^^^^^^^^^^^^ ... -65 | / construct_runtime! { -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Event}, -70 | | } -71 | | } +66 | / construct_runtime! { +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Event}, +71 | | } +72 | | } | |_- in this macro invocation | = note: this error originates in the macro `pallet::__substrate_event_check::is_event_part_defined` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0412]: cannot find type `Event` in module `pallet` - --> tests/construct_runtime_ui/undefined_event_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_event_part.rs:66:1 | -65 | / construct_runtime! { -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Event}, -70 | | } -71 | | } +66 | / construct_runtime! { +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Event}, +71 | | } +72 | | } | |_^ not found in `pallet` | = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs index a3501ca31a37..44ec3fd7c110 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr index 00b5a1370036..10093b26f5a8 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.stderr @@ -4,27 +4,27 @@ error: `Pallet` does not have #[pallet::genesis_config] defined, perhaps you sho 22 | #[frame_support::pallet] | ^^^^^^^^^^^^^^^^^^^^^^^^ ... -65 | / construct_runtime! { -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Config}, -70 | | } -71 | | } +66 | / construct_runtime! { +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Config}, +71 | | } +72 | | } | |_- in this macro invocation | = note: this error originates in the macro `pallet::__substrate_genesis_config_check::is_genesis_config_defined` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0412]: cannot find type `GenesisConfig` in module `pallet` - --> tests/construct_runtime_ui/undefined_genesis_config_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_genesis_config_part.rs:66:1 | -65 | / construct_runtime! { -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Config}, -70 | | } -71 | | } +66 | / construct_runtime! { +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Config}, +71 | | } +72 | | } | |_^ not found in `pallet` | = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs index e22745930d69..e6a1177e3ea3 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr index 749d2d9c159e..a4c7ecf78658 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.stderr @@ -4,31 +4,31 @@ error: `Pallet` does not have #[pallet::inherent] defined, perhaps you should re 22 | #[frame_support::pallet] | ^^^^^^^^^^^^^^^^^^^^^^^^ ... -65 | / construct_runtime! { -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, -70 | | } -71 | | } +66 | / construct_runtime! { +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, +71 | | } +72 | | } | |_- in this macro invocation | = note: this error originates in the macro `pallet::__substrate_inherent_check::is_inherent_part_defined` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no function or associated item named `create_inherent` found for struct `pallet::Pallet` in the current scope - --> tests/construct_runtime_ui/undefined_inherent_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_inherent_part.rs:66:1 | 28 | pub struct Pallet(_); | -------------------- function or associated item `create_inherent` not found for this struct ... -65 | construct_runtime! { +66 | construct_runtime! { | _^ -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, -70 | | } -71 | | } +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, +71 | | } +72 | | } | |_^ function or associated item not found in `Pallet` | = help: items from traits can only be used if the trait is implemented and in scope @@ -37,19 +37,19 @@ error[E0599]: no function or associated item named `create_inherent` found for s = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no function or associated item named `is_inherent` found for struct `pallet::Pallet` in the current scope - --> tests/construct_runtime_ui/undefined_inherent_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_inherent_part.rs:66:1 | 28 | pub struct Pallet(_); | -------------------- function or associated item `is_inherent` not found for this struct ... -65 | construct_runtime! { +66 | construct_runtime! { | _^ -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, -70 | | } -71 | | } +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, +71 | | } +72 | | } | |_^ function or associated item not found in `Pallet` | = help: items from traits can only be used if the trait is implemented and in scope @@ -58,19 +58,19 @@ error[E0599]: no function or associated item named `is_inherent` found for struc = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no function or associated item named `check_inherent` found for struct `pallet::Pallet` in the current scope - --> tests/construct_runtime_ui/undefined_inherent_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_inherent_part.rs:66:1 | 28 | pub struct Pallet(_); | -------------------- function or associated item `check_inherent` not found for this struct ... -65 | construct_runtime! { +66 | construct_runtime! { | _^ -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, -70 | | } -71 | | } +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, +71 | | } +72 | | } | |_^ function or associated item not found in `Pallet` | = help: items from traits can only be used if the trait is implemented and in scope @@ -79,19 +79,19 @@ error[E0599]: no function or associated item named `check_inherent` found for st = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no associated item named `INHERENT_IDENTIFIER` found for struct `pallet::Pallet` in the current scope - --> tests/construct_runtime_ui/undefined_inherent_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_inherent_part.rs:66:1 | 28 | pub struct Pallet(_); | -------------------- associated item `INHERENT_IDENTIFIER` not found for this struct ... -65 | construct_runtime! { +66 | construct_runtime! { | _^ -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, -70 | | } -71 | | } +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, +71 | | } +72 | | } | |_^ associated item not found in `Pallet` | = help: items from traits can only be used if the trait is implemented and in scope @@ -100,19 +100,19 @@ error[E0599]: no associated item named `INHERENT_IDENTIFIER` found for struct `p = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no function or associated item named `is_inherent_required` found for struct `pallet::Pallet` in the current scope - --> tests/construct_runtime_ui/undefined_inherent_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_inherent_part.rs:66:1 | 28 | pub struct Pallet(_); | -------------------- function or associated item `is_inherent_required` not found for this struct ... -65 | construct_runtime! { +66 | construct_runtime! { | _^ -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, -70 | | } -71 | | } +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Inherent}, +71 | | } +72 | | } | |_^ function or associated item not found in `Pallet` | = help: items from traits can only be used if the trait is implemented and in scope diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs index 656365279b88..66e487642041 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr index 13612233e868..d0f4b44ab0d5 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.stderr @@ -4,27 +4,27 @@ error: `Pallet` does not have #[pallet::origin] defined, perhaps you should remo 22 | #[frame_support::pallet] | ^^^^^^^^^^^^^^^^^^^^^^^^ ... -65 | / construct_runtime! { -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Origin}, -70 | | } -71 | | } +66 | / construct_runtime! { +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Origin}, +71 | | } +72 | | } | |_- in this macro invocation | = note: this error originates in the macro `pallet::__substrate_origin_check::is_origin_part_defined` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0412]: cannot find type `Origin` in module `pallet` - --> tests/construct_runtime_ui/undefined_origin_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_origin_part.rs:66:1 | -65 | / construct_runtime! { -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet expanded::{}::{Pallet, Origin}, -70 | | } -71 | | } +66 | / construct_runtime! { +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet expanded::{}::{Pallet, Origin}, +71 | | } +72 | | } | |_^ not found in `pallet` | = note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs index 05545821ab02..ed3f4a3e0683 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs @@ -47,6 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr index 64677728c8b7..f527cc2ff773 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.stderr @@ -4,46 +4,46 @@ error: `Pallet` does not have #[pallet::validate_unsigned] defined, perhaps you 22 | #[frame_support::pallet] | ^^^^^^^^^^^^^^^^^^^^^^^^ ... -65 | / construct_runtime! { -66 | | pub struct Runtime -67 | | { -68 | | System: frame_system::{Pallet, Call, Storage, Config, Event}, -69 | | Pallet: pallet::{Pallet, ValidateUnsigned}, -70 | | } -71 | | } +66 | / construct_runtime! { +67 | | pub struct Runtime +68 | | { +69 | | System: frame_system::{Pallet, Call, Storage, Config, Event}, +70 | | Pallet: pallet::{Pallet, ValidateUnsigned}, +71 | | } +72 | | } | |_- in this macro invocation | = note: this error originates in the macro `pallet::__substrate_validate_unsigned_check::is_validate_unsigned_part_defined` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no variant or associated item named `Pallet` found for enum `RuntimeCall` in the current scope - --> tests/construct_runtime_ui/undefined_validate_unsigned_part.rs:69:3 + --> tests/construct_runtime_ui/undefined_validate_unsigned_part.rs:70:3 | -65 | // construct_runtime! { -66 | || pub struct Runtime -67 | || { -68 | || System: frame_system::{Pallet, Call, Storage, Config, Event}, -69 | || Pallet: pallet::{Pallet, ValidateUnsigned}, +66 | // construct_runtime! { +67 | || pub struct Runtime +68 | || { +69 | || System: frame_system::{Pallet, Call, Storage, Config, Event}, +70 | || Pallet: pallet::{Pallet, ValidateUnsigned}, | || -^^^^^^ variant or associated item not found in `RuntimeCall` | ||________| | | ... | error[E0599]: no function or associated item named `pre_dispatch` found for struct `pallet::Pallet` in the current scope - --> tests/construct_runtime_ui/undefined_validate_unsigned_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_validate_unsigned_part.rs:66:1 | 28 | pub struct Pallet(_); | -------------------- function or associated item `pre_dispatch` not found for this struct ... -65 | construct_runtime! { +66 | construct_runtime! { | __^ | | _| | || -66 | || pub struct Runtime -67 | || { -68 | || System: frame_system::{Pallet, Call, Storage, Config, Event}, -69 | || Pallet: pallet::{Pallet, ValidateUnsigned}, -70 | || } -71 | || } +67 | || pub struct Runtime +68 | || { +69 | || System: frame_system::{Pallet, Call, Storage, Config, Event}, +70 | || Pallet: pallet::{Pallet, ValidateUnsigned}, +71 | || } +72 | || } | ||_- in this macro invocation ... | | @@ -54,21 +54,21 @@ error[E0599]: no function or associated item named `pre_dispatch` found for stru = note: this error originates in the macro `frame_support::construct_runtime` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no function or associated item named `validate_unsigned` found for struct `pallet::Pallet` in the current scope - --> tests/construct_runtime_ui/undefined_validate_unsigned_part.rs:65:1 + --> tests/construct_runtime_ui/undefined_validate_unsigned_part.rs:66:1 | 28 | pub struct Pallet(_); | -------------------- function or associated item `validate_unsigned` not found for this struct ... -65 | construct_runtime! { +66 | construct_runtime! { | __^ | | _| | || -66 | || pub struct Runtime -67 | || { -68 | || System: frame_system::{Pallet, Call, Storage, Config, Event}, -69 | || Pallet: pallet::{Pallet, ValidateUnsigned}, -70 | || } -71 | || } +67 | || pub struct Runtime +68 | || { +69 | || System: frame_system::{Pallet, Call, Storage, Config, Event}, +70 | || Pallet: pallet::{Pallet, ValidateUnsigned}, +71 | || } +72 | || } | ||_- in this macro invocation ... | | diff --git a/substrate/frame/support/test/tests/derive_impl_ui/inject_runtime_type_invalid.stderr b/substrate/frame/support/test/tests/derive_impl_ui/inject_runtime_type_invalid.stderr index 501aad0419f8..cda20288984a 100644 --- a/substrate/frame/support/test/tests/derive_impl_ui/inject_runtime_type_invalid.stderr +++ b/substrate/frame/support/test/tests/derive_impl_ui/inject_runtime_type_invalid.stderr @@ -1,4 +1,4 @@ -error: `#[inject_runtime_type]` can only be attached to `RuntimeCall`, `RuntimeEvent`, `RuntimeOrigin` or `PalletInfo` +error: `#[inject_runtime_type]` can only be attached to `RuntimeCall`, `RuntimeEvent`, `RuntimeTask`, `RuntimeOrigin` or `PalletInfo` --> tests/derive_impl_ui/inject_runtime_type_invalid.rs:32:5 | 32 | type RuntimeInfo = (); diff --git a/substrate/frame/support/test/tests/pallet_ui/composite_enum_unsupported_identifier.stderr b/substrate/frame/support/test/tests/pallet_ui/composite_enum_unsupported_identifier.stderr index cdc8f623142b..8de9c8990b00 100644 --- a/substrate/frame/support/test/tests/pallet_ui/composite_enum_unsupported_identifier.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/composite_enum_unsupported_identifier.stderr @@ -1,4 +1,4 @@ -error: expected one of: `FreezeReason`, `HoldReason`, `LockId`, `SlashReason` +error: expected one of: `FreezeReason`, `HoldReason`, `LockId`, `SlashReason`, `Task` --> tests/pallet_ui/composite_enum_unsupported_identifier.rs:27:11 | 27 | pub enum HoldReasons {} diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs b/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs index bf26cfd95b19..1ff83e9d186d 100644 --- a/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs +++ b/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs @@ -81,6 +81,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs b/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs index 9ab486c718c4..1943a4809770 100644 --- a/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs +++ b/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs @@ -38,6 +38,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); From ee6bd4bf64322aa1b8e77e59b26807e49619295e Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:27:44 +0530 Subject: [PATCH 122/177] Adds RuntimeTask in mock pallet contracts --- substrate/frame/contracts/mock-network/src/parachain.rs | 1 + substrate/frame/contracts/mock-network/src/relay_chain.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/substrate/frame/contracts/mock-network/src/parachain.rs b/substrate/frame/contracts/mock-network/src/parachain.rs index 1465b02f903b..36202e5a6d9a 100644 --- a/substrate/frame/contracts/mock-network/src/parachain.rs +++ b/substrate/frame/contracts/mock-network/src/parachain.rs @@ -63,6 +63,7 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; type Lookup = IdentityLookup; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = BlockHashCount; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/contracts/mock-network/src/relay_chain.rs b/substrate/frame/contracts/mock-network/src/relay_chain.rs index c59c8e4bfa84..1a239b3a04f3 100644 --- a/substrate/frame/contracts/mock-network/src/relay_chain.rs +++ b/substrate/frame/contracts/mock-network/src/relay_chain.rs @@ -57,6 +57,7 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; type Lookup = IdentityLookup; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = BlockHashCount; type BlockWeights = (); type BlockLength = (); From 5ccabe6939b596ae9da5a97199cdaa10b58f8635 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:19:13 +0530 Subject: [PATCH 123/177] Adds RuntimeTask in a couple of missing places --- substrate/frame/nomination-pools/benchmarking/src/mock.rs | 1 + substrate/utils/frame/rpc/support/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/substrate/frame/nomination-pools/benchmarking/src/mock.rs b/substrate/frame/nomination-pools/benchmarking/src/mock.rs index 9a7f2197a7b2..5fc362110fd5 100644 --- a/substrate/frame/nomination-pools/benchmarking/src/mock.rs +++ b/substrate/frame/nomination-pools/benchmarking/src/mock.rs @@ -42,6 +42,7 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/utils/frame/rpc/support/src/lib.rs b/substrate/utils/frame/rpc/support/src/lib.rs index 2d8e45cbfc69..92dd9e192cfd 100644 --- a/substrate/utils/frame/rpc/support/src/lib.rs +++ b/substrate/utils/frame/rpc/support/src/lib.rs @@ -62,6 +62,7 @@ use sp_storage::{StorageData, StorageKey}; /// # type Lookup = IdentityLookup; /// # type Block = frame_system::mocking::MockBlock; /// # type RuntimeEvent = RuntimeEvent; +/// # type RuntimeTask = RuntimeTask; /// # type BlockHashCount = (); /// # type DbWeight = (); /// # type Version = (); From 1bd2422fedb002d025d622b808543259b6be0c1d Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:31:46 +0530 Subject: [PATCH 124/177] Minor update --- substrate/frame/examples/tasks/src/benchmarking.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/substrate/frame/examples/tasks/src/benchmarking.rs b/substrate/frame/examples/tasks/src/benchmarking.rs index 109e9526fb57..ce29f405d78d 100644 --- a/substrate/frame/examples/tasks/src/benchmarking.rs +++ b/substrate/frame/examples/tasks/src/benchmarking.rs @@ -18,11 +18,8 @@ //! Benchmarking for `pallet-example-tasks`. #![cfg(feature = "runtime-benchmarks")] -use super::*; - -#[allow(unused)] -use crate::Pallet as TasksExample; +use crate::*; use frame_benchmarking::v2::*; #[benchmarks] From 53f8270e5ee2e70fa35a871e8444b43b6221abcb Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:45:05 +0530 Subject: [PATCH 125/177] Adds RuntimeTask in missing places --- substrate/frame/nomination-pools/src/mock.rs | 1 + substrate/frame/offences/benchmarking/src/mock.rs | 1 + substrate/frame/session/benchmarking/src/mock.rs | 1 + substrate/frame/system/benchmarking/src/mock.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/substrate/frame/nomination-pools/src/mock.rs b/substrate/frame/nomination-pools/src/mock.rs index 0abfdc0ad581..47e94ef7312e 100644 --- a/substrate/frame/nomination-pools/src/mock.rs +++ b/substrate/frame/nomination-pools/src/mock.rs @@ -222,6 +222,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = (); type DbWeight = (); type BlockLength = (); diff --git a/substrate/frame/offences/benchmarking/src/mock.rs b/substrate/frame/offences/benchmarking/src/mock.rs index 1a458ec90d58..03b7dd6c04e2 100644 --- a/substrate/frame/offences/benchmarking/src/mock.rs +++ b/substrate/frame/offences/benchmarking/src/mock.rs @@ -54,6 +54,7 @@ impl frame_system::Config for Test { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/frame/session/benchmarking/src/mock.rs b/substrate/frame/session/benchmarking/src/mock.rs index 47c337569a02..3c4e81090e78 100644 --- a/substrate/frame/session/benchmarking/src/mock.rs +++ b/substrate/frame/session/benchmarking/src/mock.rs @@ -59,6 +59,7 @@ impl frame_system::Config for Test { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/frame/system/benchmarking/src/mock.rs b/substrate/frame/system/benchmarking/src/mock.rs index 4e6b1221da35..140fb58bbfa2 100644 --- a/substrate/frame/system/benchmarking/src/mock.rs +++ b/substrate/frame/system/benchmarking/src/mock.rs @@ -48,6 +48,7 @@ impl frame_system::Config for Test { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; From c2261057b083df4079604a8a3d2c5c0e9b294699 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:50:58 +0530 Subject: [PATCH 126/177] Minor update --- substrate/frame/nomination-pools/src/mock.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/nomination-pools/src/mock.rs b/substrate/frame/nomination-pools/src/mock.rs index 47e94ef7312e..0abfdc0ad581 100644 --- a/substrate/frame/nomination-pools/src/mock.rs +++ b/substrate/frame/nomination-pools/src/mock.rs @@ -222,7 +222,6 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = (); type DbWeight = (); type BlockLength = (); From 2b6146cb4a26729bdf67ec8e95f8c4f0ed186055 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 15 Nov 2023 16:48:30 +0530 Subject: [PATCH 127/177] Restructures Task impl and adds a couple of UI Tests --- substrate/frame/examples/tasks/src/lib.rs | 2 +- .../procedural/src/pallet/expand/tasks.rs | 27 +++++-------- .../procedural/src/pallet/parse/mod.rs | 3 ++ .../task_can_only_be_attached_to_impl.rs | 34 +++++++++++++++++ .../task_can_only_be_attached_to_impl.stderr | 5 +++ .../tests/pallet_ui/task_missing_index.rs | 38 +++++++++++++++++++ .../tests/pallet_ui/task_missing_index.stderr | 5 +++ 7 files changed, 95 insertions(+), 19 deletions(-) create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.stderr create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_missing_index.stderr diff --git a/substrate/frame/examples/tasks/src/lib.rs b/substrate/frame/examples/tasks/src/lib.rs index 30960c4c76b8..1de66bc5a877 100644 --- a/substrate/frame/examples/tasks/src/lib.rs +++ b/substrate/frame/examples/tasks/src/lib.rs @@ -42,7 +42,7 @@ pub mod pallet { } #[pallet::tasks] - impl frame_support::traits::Task for Task { + impl Pallet { /// Add a pair of numbers into the totals and remove them. #[pallet::task_list(Numbers::::iter_keys())] #[pallet::task_condition(|i| Numbers::::contains_key(i))] diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index e5e306c633b9..53476f6e06cc 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -20,7 +20,7 @@ use derive_syn_parse::Parse; use inflector::Inflector; use proc_macro2::TokenStream as TokenStream2; use quote::{format_ident, quote, ToTokens}; -use syn::{parse_quote, spanned::Spanned, Item, ItemEnum, ItemImpl}; +use syn::{parse_quote, spanned::Spanned, ItemEnum, ItemImpl}; impl TaskEnumDef { pub fn generate( @@ -117,7 +117,7 @@ pub struct ExpandedTasksDef { impl ToTokens for TasksDef { fn to_tokens(&self, tokens: &mut TokenStream2) { let scrate = &self.scrate; - let enum_ident = &self.enum_ident; + let enum_ident = syn::Ident::new("Task", self.enum_ident.span()); let enum_arguments = &self.enum_arguments; let enum_use = quote!(#enum_ident #enum_arguments); @@ -162,14 +162,14 @@ impl ToTokens for TasksDef { fn task_index(&self) -> u32 { match self { - #(#enum_ident::#task_fn_idents { .. } => #task_indices),*, + #(#enum_ident::#task_fn_idents { .. } => #task_indices,)* Task::__Ignore(_, _) => unreachable!(), } } fn is_valid(&self) -> bool { match self { - #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => (#task_conditions)(#(#task_arg_names),* )),*, + #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => (#task_conditions)(#(#task_arg_names),* ),)* Task::__Ignore(_, _) => unreachable!(), } } @@ -178,7 +178,7 @@ impl ToTokens for TasksDef { match self.clone() { #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => { <#enum_use>::#task_fn_names(#( #task_arg_names, )* ) - }),*, + },)* Task::__Ignore(_, _) => unreachable!(), } } @@ -186,7 +186,7 @@ impl ToTokens for TasksDef { #[allow(unused_variables)] fn weight(&self) -> #scrate::pallet_prelude::Weight { match self.clone() { - #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => #task_weights),*, + #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => #task_weights,)* Task::__Ignore(_, _) => unreachable!(), } } @@ -198,17 +198,10 @@ impl ToTokens for TasksDef { pub fn expand_tasks_impl(def: &mut Def) -> TokenStream2 { let Some(tasks) = &mut def.tasks else { return quote!() }; let ExpandedTasksDef { task_item_impl, task_trait_impl } = parse_quote!(#tasks); - let Some(content) = &mut def.item.content else { return quote!() }; - for item in content.1.iter_mut() { - let Item::Impl(item_impl) = item else { continue }; - let Some(trait_) = &item_impl.trait_ else { continue }; - let Some(last_seg) = trait_.1.segments.last() else { continue }; - if last_seg.ident == "Task" { - *item_impl = task_item_impl; - break - } + quote! { + #task_item_impl + #task_trait_impl } - quote!(#task_trait_impl) } #[derive(Parse)] @@ -220,8 +213,6 @@ pub struct ExpandedTaskEnum { pub fn expand_task_enum(def: &mut Def) -> TokenStream2 { let Some(task_enum) = &mut def.task_enum else { return quote!() }; let ExpandedTaskEnum { item_enum, debug_impl } = parse_quote!(#task_enum); - // item_enum.pretty_print(); - // debug_impl.pretty_print(); quote! { #item_enum #debug_impl diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 4b7cbb21dca3..e3c5c316ca31 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -142,6 +142,9 @@ impl Def { #[pallet::tasks] #item_tokens })?); + + // replace item with a no-op because it will be handled by the expansion of tasks + *item = syn::Item::Verbatim(quote::quote!()); } Some(PalletAttr::TaskCondition(span)) => return Err(syn::Error::new( span, diff --git a/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.rs b/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.rs new file mode 100644 index 000000000000..791a250cd350 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.rs @@ -0,0 +1,34 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + pub struct Task; +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.stderr b/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.stderr new file mode 100644 index 000000000000..eaa8e718840e --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.stderr @@ -0,0 +1,5 @@ +error: expected `impl` + --> tests/pallet_ui/task_can_only_be_attached_to_impl.rs:30:5 + | +30 | pub struct Task; + | ^^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs new file mode 100644 index 000000000000..42d0f9b9d0ab --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs @@ -0,0 +1,38 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + fn foo() -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_index.stderr b/substrate/frame/support/test/tests/pallet_ui/task_missing_index.stderr new file mode 100644 index 000000000000..ba3c9d132b81 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_index.stderr @@ -0,0 +1,5 @@ +error: missing `#[pallet::task_index(..)]` attribute + --> tests/pallet_ui/task_missing_index.rs:31:6 + | +31 | fn foo() -> DispatchResult { + | ^^^ From ac1c57e7ecaab2114fbab31bb000c1c02374b04a Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 15 Nov 2023 16:55:07 +0530 Subject: [PATCH 128/177] Adds more UI Tests --- .../tests/pallet_ui/task_invalid_index.rs | 39 ++++++++++++++++++ .../tests/pallet_ui/task_invalid_index.stderr | 5 +++ .../tests/pallet_ui/task_missing_condition.rs | 39 ++++++++++++++++++ .../pallet_ui/task_missing_condition.stderr | 5 +++ .../tests/pallet_ui/task_missing_index.rs | 2 +- .../test/tests/pallet_ui/task_missing_list.rs | 40 +++++++++++++++++++ .../tests/pallet_ui/task_missing_list.stderr | 5 +++ 7 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_invalid_index.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_invalid_index.stderr create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_missing_condition.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_missing_condition.stderr create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_missing_list.stderr diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.rs b/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.rs new file mode 100644 index 000000000000..00c5112a0ec5 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.rs @@ -0,0 +1,39 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + #[pallet::task_index("0")] + fn foo() -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.stderr b/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.stderr new file mode 100644 index 000000000000..d33600455bf8 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.stderr @@ -0,0 +1,5 @@ +error: expected integer literal + --> tests/pallet_ui/task_invalid_index.rs:31:24 + | +31 | #[pallet::task_index("0")] + | ^^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.rs new file mode 100644 index 000000000000..814b2241ca32 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.rs @@ -0,0 +1,39 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + #[pallet::task_index(0)] + fn foo() -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.stderr b/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.stderr new file mode 100644 index 000000000000..c709ec7eac94 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.stderr @@ -0,0 +1,5 @@ +error: missing `#[pallet::task_condition(..)]` attribute + --> tests/pallet_ui/task_missing_condition.rs:32:6 + | +32 | fn foo() -> DispatchResult { + | ^^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs index 42d0f9b9d0ab..55a947e906e4 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs @@ -31,7 +31,7 @@ mod pallet { fn foo() -> DispatchResult { Ok(()) } - } + } } fn main() { diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs new file mode 100644 index 000000000000..804782141901 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs @@ -0,0 +1,40 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + #[pallet::task_index(0)] + #[pallet::task_condition(|_| true)] + fn foo() -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_list.stderr b/substrate/frame/support/test/tests/pallet_ui/task_missing_list.stderr new file mode 100644 index 000000000000..f4ae26a75add --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_list.stderr @@ -0,0 +1,5 @@ +error: missing `#[pallet::task_list(..)]` attribute + --> tests/pallet_ui/task_missing_list.rs:33:6 + | +33 | fn foo() -> DispatchResult { + | ^^^ From 16bf1afd29e2d53f68b382b17ebf6c638537e775 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:08:19 +0530 Subject: [PATCH 129/177] Adds more UI Tests --- .../procedural/src/pallet/parse/tasks.rs | 1 - .../tests/pallet_ui/task_invalid_condition.rs | 42 +++++++++++++++++++ .../pallet_ui/task_invalid_condition.stderr | 25 +++++++++++ .../test/tests/pallet_ui/task_invalid_list.rs | 42 +++++++++++++++++++ .../tests/pallet_ui/task_invalid_list.stderr | 28 +++++++++++++ .../tests/pallet_ui/task_invalid_weight.rs | 42 +++++++++++++++++++ .../pallet_ui/task_invalid_weight.stderr | 25 +++++++++++ .../tests/pallet_ui/task_missing_weight.rs | 41 ++++++++++++++++++ .../pallet_ui/task_missing_weight.stderr | 5 +++ 9 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.stderr create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_invalid_list.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_invalid_list.stderr create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.stderr create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_missing_weight.stderr diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index f02d294d13d0..f9dbe873ff2c 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -312,7 +312,6 @@ impl syn::parse::Parse for TaskDef { let mut arg_names = vec![]; for input in item.sig.inputs.iter() { match input { - // Todo: This should be checked in the parsing stage. syn::FnArg::Typed(pat_type) => match &*pat_type.pat { syn::Pat::Ident(ident) => arg_names.push(ident.ident.clone()), _ => return Err(Error::new(input.span(), "unexpected pattern type")), diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.rs b/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.rs new file mode 100644 index 000000000000..95a4a5793446 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.rs @@ -0,0 +1,42 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + #[pallet::task_index(0)] + #[pallet::task_condition(0)] + #[pallet::task_list(vec![1, 2].iter())] + #[pallet::task_weight(0.into())] + fn foo() -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.stderr b/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.stderr new file mode 100644 index 000000000000..45b080728f4c --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.stderr @@ -0,0 +1,25 @@ +error: unused import: `frame_system::pallet_prelude::OriginFor` + --> tests/pallet_ui/task_invalid_condition.rs:21:6 + | +21 | use frame_system::pallet_prelude::OriginFor; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D unused-imports` implied by `-D warnings` + +error[E0559]: variant `pallet::Task<_>::Foo` has no field named `i` + --> tests/pallet_ui/task_invalid_condition.rs:18:1 + | +18 | #[frame_support::pallet(dev_mode)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pallet::Task<_>::Foo` does not have this field + | + = note: all struct fields are already assigned + = note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0618]: expected function, found `{integer}` + --> tests/pallet_ui/task_invalid_condition.rs:32:28 + | +18 | #[frame_support::pallet(dev_mode)] + | ---------------------------------- call expression requires function +... +32 | #[pallet::task_condition(0)] + | ^ diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.rs b/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.rs new file mode 100644 index 000000000000..516f89687d12 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.rs @@ -0,0 +1,42 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + #[pallet::task_index(0)] + #[pallet::task_condition(|| true)] + #[pallet::task_list(0)] + #[pallet::task_weight(0.into())] + fn foo() -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.stderr b/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.stderr new file mode 100644 index 000000000000..b12ba2dcd8f6 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.stderr @@ -0,0 +1,28 @@ +error: unused import: `frame_system::pallet_prelude::OriginFor` + --> tests/pallet_ui/task_invalid_list.rs:21:6 + | +21 | use frame_system::pallet_prelude::OriginFor; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D unused-imports` implied by `-D warnings` + +error[E0689]: can't call method `map` on ambiguous numeric type `{integer}` + --> tests/pallet_ui/task_invalid_list.rs:18:1 + | +18 | #[frame_support::pallet(dev_mode)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info) +help: you must specify a concrete type for this numeric value, like `i32` + | +33 | #[pallet::task_list(0_i32)] + | ~~~~~ + +error[E0559]: variant `pallet::Task<_>::Foo` has no field named `i` + --> tests/pallet_ui/task_invalid_list.rs:18:1 + | +18 | #[frame_support::pallet(dev_mode)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pallet::Task<_>::Foo` does not have this field + | + = note: all struct fields are already assigned + = note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.rs b/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.rs new file mode 100644 index 000000000000..392446173a80 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.rs @@ -0,0 +1,42 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + #[pallet::task_index(0)] + #[pallet::task_condition(|| true)] + #[pallet::task_list(vec![1, 2].iter())] + #[pallet::task_weight("0")] + fn foo() -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.stderr b/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.stderr new file mode 100644 index 000000000000..b959da5f1cbf --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.stderr @@ -0,0 +1,25 @@ +error: unused import: `frame_system::pallet_prelude::OriginFor` + --> tests/pallet_ui/task_invalid_weight.rs:21:6 + | +21 | use frame_system::pallet_prelude::OriginFor; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D unused-imports` implied by `-D warnings` + +error[E0559]: variant `pallet::Task<_>::Foo` has no field named `i` + --> tests/pallet_ui/task_invalid_weight.rs:18:1 + | +18 | #[frame_support::pallet(dev_mode)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pallet::Task<_>::Foo` does not have this field + | + = note: all struct fields are already assigned + = note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0308]: mismatched types + --> tests/pallet_ui/task_invalid_weight.rs:34:25 + | +18 | #[frame_support::pallet(dev_mode)] + | ---------------------------------- expected `Weight` because of return type +... +34 | #[pallet::task_weight("0")] + | ^^^ expected `Weight`, found `&str` diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs new file mode 100644 index 000000000000..7ca279980537 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs @@ -0,0 +1,41 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + #[pallet::task_index(0)] + #[pallet::task_condition(|_| true)] + #[pallet::task_list(vec![1, 2].iter())] + fn foo() -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.stderr b/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.stderr new file mode 100644 index 000000000000..de7b2eb17205 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.stderr @@ -0,0 +1,5 @@ +error: missing `#[pallet::task_weight(..)]` attribute + --> tests/pallet_ui/task_missing_weight.rs:34:6 + | +34 | fn foo() -> DispatchResult { + | ^^^ From 9624f0ccf75a6e2cf3c8c8ff72e193410f5ae398 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 15 Nov 2023 15:20:16 -0500 Subject: [PATCH 130/177] add docs and a few doc tests for task-related stuff --- .../procedural/src/pallet/expand/tasks.rs | 15 +++ .../procedural/src/pallet/parse/tasks.rs | 25 +++++ .../procedural/src/pallet/parse/tests/mod.rs | 94 +++++++++++++++++++ 3 files changed, 134 insertions(+) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 53476f6e06cc..64bfae435789 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -1,3 +1,5 @@ +//! Contains logic for expanding task-related items. + // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -23,6 +25,9 @@ use quote::{format_ident, quote, ToTokens}; use syn::{parse_quote, spanned::Spanned, ItemEnum, ItemImpl}; impl TaskEnumDef { + /// Since we optionally allow users to manually specify a `#[pallet::task_enum]`, in the + /// event they _don't_ specify one (which is actually the most common behavior) we have to + /// generate one based on the existing [`TasksDef`]. This method performs that generation. pub fn generate( tasks: &TasksDef, type_decl_bounded_generics: TokenStream2, @@ -108,6 +113,7 @@ impl ToTokens for TaskEnumDef { } } +/// Represents an already-expanded [`TasksDef`]. #[derive(Parse)] pub struct ExpandedTasksDef { pub task_item_impl: ItemImpl, @@ -195,6 +201,9 @@ impl ToTokens for TasksDef { } } +/// Expands the [`TasksDef`] in the enclosing [`Def`], if present, and returns its tokens. +/// +/// This modifies the underlying [`Def`] in addition to returning any tokens that were added. pub fn expand_tasks_impl(def: &mut Def) -> TokenStream2 { let Some(tasks) = &mut def.tasks else { return quote!() }; let ExpandedTasksDef { task_item_impl, task_trait_impl } = parse_quote!(#tasks); @@ -204,12 +213,16 @@ pub fn expand_tasks_impl(def: &mut Def) -> TokenStream2 { } } +/// Represents a fully-expanded [`TaskEnumDef`]. #[derive(Parse)] pub struct ExpandedTaskEnum { pub item_enum: ItemEnum, pub debug_impl: ItemImpl, } +/// Modifies a [`Def`] to expand the underlying [`TaskEnumDef`] if present, and also returns +/// its tokens. A blank [`TokenStream2`] is returned if no [`TaskEnumDef`] has been generated +/// or defined. pub fn expand_task_enum(def: &mut Def) -> TokenStream2 { let Some(task_enum) = &mut def.task_enum else { return quote!() }; let ExpandedTaskEnum { item_enum, debug_impl } = parse_quote!(#task_enum); @@ -219,6 +232,8 @@ pub fn expand_task_enum(def: &mut Def) -> TokenStream2 { } } +/// Modifies a [`Def`] to expand the underlying [`TasksDef`] and also generate a +/// [`TaskEnumDef`] if applicable. The tokens for these items are returned if they are created. pub fn expand_tasks(def: &mut Def) -> TokenStream2 { if let Some(tasks_def) = &def.tasks { if def.task_enum.is_none() { diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index f9dbe873ff2c..9f00b8cbb0ac 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -48,11 +48,14 @@ pub mod keywords { custom_keyword!(pallet); } +/// Represents the `#[pallet::tasks]` attribute and its attached item. Also includes metadata +/// about the linked [`TaskEnumDef`] if applicable. #[derive(Clone, Debug)] pub struct TasksDef { pub tasks_attr: Option, pub tasks: Vec, pub item_impl: ItemImpl, + /// Path to `frame_support` pub scrate: Path, pub enum_ident: Ident, pub enum_arguments: PathArguments, @@ -126,14 +129,29 @@ impl syn::parse::Parse for TasksDef { } } +/// Parsing for a `#[pallet::tasks]` attr. pub type PalletTasksAttr = PalletTaskAttr; + +/// Parsing for any of the attributes that can be used within a `#[pallet::tasks]` [`ItemImpl`]. pub type TaskAttr = PalletTaskAttr; + +/// Parsing for a `#[pallet::task_index]` attr. pub type TaskIndexAttr = PalletTaskAttr; + +/// Parsing for a `#[pallet::task_condition]` attr. pub type TaskConditionAttr = PalletTaskAttr; + +/// Parsing for a `#[pallet::task_list]` attr. pub type TaskListAttr = PalletTaskAttr; + +/// Parsing for a `#[pallet::task_weight]` attr. pub type TaskWeightAttr = PalletTaskAttr; + +/// Parsing for a `#[pallet:task_enum]` attr. pub type PalletTaskEnumAttr = PalletTaskAttr; +/// Parsing for a manually-specified (or auto-generated) task enum, optionally including the +/// attached `#[pallet::task_enum]` attribute. #[derive(Clone, Debug)] pub struct TaskEnumDef { pub attr: Option, @@ -192,6 +210,7 @@ impl syn::parse::Parse for TaskEnumDef { } } +/// Represents an individual tasks within a [`TasksDef`]. #[derive(Debug, Clone)] pub struct TaskDef { pub index_attr: TaskIndexAttr, @@ -337,6 +356,7 @@ impl syn::parse::Parse for TaskDef { } } +/// The contents of a [`TasksDef`]-related attribute. #[derive(Parse, Debug, Clone)] pub enum TaskAttrMeta { #[peek(keywords::task_list, name = "#[pallet::task_list(..)]")] @@ -349,6 +369,7 @@ pub enum TaskAttrMeta { TaskWeight(TaskWeightAttrMeta), } +/// The contents of a `#[pallet::task_list]` attribute. #[derive(Parse, Debug, Clone)] pub struct TaskListAttrMeta { pub task_list: keywords::task_list, @@ -358,6 +379,7 @@ pub struct TaskListAttrMeta { pub expr: Expr, } +/// The contents of a `#[pallet::task_index]` attribute. #[derive(Parse, Debug, Clone)] pub struct TaskIndexAttrMeta { pub task_index: keywords::task_index, @@ -367,6 +389,7 @@ pub struct TaskIndexAttrMeta { pub index: LitInt, } +/// The contents of a `#[pallet::task_condition]` attribute. #[derive(Parse, Debug, Clone)] pub struct TaskConditionAttrMeta { pub task_condition: keywords::task_condition, @@ -376,6 +399,7 @@ pub struct TaskConditionAttrMeta { pub expr: Expr, } +/// The contents of a `#[pallet::task_weight]` attribute. #[derive(Parse, Debug, Clone)] pub struct TaskWeightAttrMeta { pub task_weight: keywords::task_weight, @@ -385,6 +409,7 @@ pub struct TaskWeightAttrMeta { pub expr: Expr, } +/// The contents of a `#[pallet::task]` attribute. #[derive(Parse, Debug, Clone)] pub struct PalletTaskAttr { pub pound: Pound, diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 2e96700ba0cf..0ca5186a763b 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -21,8 +21,50 @@ use syn::parse_quote; /// Ensures that only one thread can modify/restore the `CARGO_MANIFEST_DIR` ENV var at a time, /// avoiding a race condition because `cargo test` runs tests in parallel. +/// +/// Although this forces all tests that use [`simulate_manifest_dir`] to run sequentially with +/// respect to each other, this is still several orders of magnitude faster than using UI +/// tests, even if they are run in parallel. static MANIFEST_DIR_LOCK: Lazy> = Lazy::new(|| Mutex::new(())); +/// Allows you to assert that the input expression resolves to an error whose string +/// representation matches the specified regex literal. +/// +/// ## Example: +/// +/// ``` +/// use super::tasks::*; +/// +/// assert_error_matches!( +/// parse2::(quote! { +/// #[pallet::task_enum] +/// pub struct Something; +/// }), +/// "expected `enum`" +/// ); +/// ``` +/// +/// More complex regular expressions are also possible (anything that could pass as a regex for +/// use with the [`regex`] crate.): +/// +/// ```ignore +/// assert_error_matches!( +/// parse2::(quote! { +/// #[pallet::tasks] +/// impl, I: 'static> Pallet { +/// #[pallet::task_condition(|i| i % 2 == 0)] +/// #[pallet::task_index(0)] +/// pub fn foo(i: u32) -> DispatchResult { +/// Ok(()) +/// } +/// } +/// }), +/// r"missing `#\[pallet::task_list\(\.\.\)\]`" +/// ); +/// ``` +/// +/// Although this is primarily intended to be used with parsing errors, this macro is general +/// enough that it will work with any error with a reasonable [`core::fmt::Display`] impl. #[macro_export] macro_rules! assert_error_matches { ($expr:expr, $reg:literal) => { @@ -42,6 +84,36 @@ macro_rules! assert_error_matches { }; } +/// Allows you to assert that an entire pallet parses successfully. A custom syntax is used for +/// specifying arguments so please pay attention to the docs below. +/// +/// The general syntax is: +/// +/// ```ignore +/// assert_pallet_parses! { +/// #[manifest_dir("../../examples/basic")] +/// #[frame_support::pallet] +/// pub mod pallet { +/// #[pallet::config] +/// pub trait Config: frame_system::Config {} +/// +/// #[pallet::pallet] +/// pub struct Pallet(_); +/// } +/// }; +/// ``` +/// +/// The `#[manifest_dir(..)]` attribute _must_ be specified as the _first_ attribute on the +/// pallet module, and should reference the relative (to your current directory) path of a +/// directory containing containing the `Cargo.toml` of a valid pallet. Typically you will only +/// ever need to use the `examples/basic` pallet, but sometimes it might be advantageous to +/// specify a different one that has additional dependencies. +/// +/// The reason this must be specified is that our underlying parsing of pallets depends on +/// reaching out into the file system to look for particular `Cargo.toml` dependencies via the +/// [`generate_access_from_frame_or_crate`] method, so to simulate this properly in a proc +/// macro crate, we need to temporarily convince this function that we are running from the +/// directory of a valid pallet. #[macro_export] macro_rules! assert_pallet_parses { ( @@ -60,6 +132,28 @@ macro_rules! assert_pallet_parses { } } +/// Similar to [`assert_pallet_parses`], except this instead expects the pallet not to parse, +/// and allows you to specify a regex matching the expected parse error. +/// +/// This is identical syntactically to [`assert_pallet_parses`] in every way except there is a +/// second attribute that must be specified immediately after `#[manifest_dir(..)]` which is +/// `#[error_regex(..)]` which should contain a string/regex literal designed to match what you +/// consider to be the correct parsing error we should see when we try to parse this particular +/// pallet. +/// +/// ## Example: +/// +/// ``` +/// assert_pallet_parse_error! { +/// #[manifest_dir("../../examples/basic")] +/// #[error_regex("Missing `\\#\\[pallet::pallet\\]`")] +/// #[frame_support::pallet] +/// pub mod pallet { +/// #[pallet::config] +/// pub trait Config: frame_system::Config {} +/// } +/// } +/// ``` #[macro_export] macro_rules! assert_pallet_parse_error { ( From 61a254977d3366dcba951f20b9da8e7e968c4a73 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:42:23 +0530 Subject: [PATCH 131/177] Adds ability to handle multiple args in tasks and other fixes --- .../procedural/src/pallet/expand/tasks.rs | 9 ++-- .../test/tests/pallet_ui/pass/task_valid.rs | 42 +++++++++++++++++++ .../pallet_ui/task_condition_invalid_arg.rs | 42 +++++++++++++++++++ .../task_condition_invalid_arg.stderr | 30 +++++++++++++ .../test/tests/pallet_ui/task_missing_list.rs | 2 +- .../tests/pallet_ui/task_missing_weight.rs | 2 +- 6 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.rs create mode 100644 substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.stderr diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 53476f6e06cc..08741c61f1b1 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -156,19 +156,22 @@ impl ToTokens for TasksDef { fn iter() -> Self::Enumeration { let mut all_tasks = #sp_std::vec![]; - #(all_tasks.extend(#task_iters.map(|i| #enum_ident::#task_fn_idents { i }).collect::<#sp_std::vec::Vec<_>>());)* + #(all_tasks + .extend(#task_iters.map(|#(#task_arg_names),*| #enum_ident::#task_fn_idents { #(#task_arg_names: #task_arg_names.clone()),* }) + .collect::<#sp_std::vec::Vec<_>>()); + )* all_tasks.into_iter() } fn task_index(&self) -> u32 { - match self { + match self.clone() { #(#enum_ident::#task_fn_idents { .. } => #task_indices,)* Task::__Ignore(_, _) => unreachable!(), } } fn is_valid(&self) -> bool { - match self { + match self.clone() { #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => (#task_conditions)(#(#task_arg_names),* ),)* Task::__Ignore(_, _) => unreachable!(), } diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs b/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs new file mode 100644 index 000000000000..d6be08071801 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs @@ -0,0 +1,42 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + #[pallet::task_index(0)] + #[pallet::task_condition(|i| i == 0u32)] + #[pallet::task_list(vec![1u32, 2u32].iter())] + #[pallet::task_weight(0.into())] + fn foo(i: u32) -> DispatchResult { + frame_support::ensure!(i == 0, "i must be 0"); + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.rs b/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.rs new file mode 100644 index 000000000000..1c39a28eeecc --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.rs @@ -0,0 +1,42 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[frame_support::pallet(dev_mode)] +mod pallet { + use frame_support::pallet_prelude::DispatchResult; + use frame_system::pallet_prelude::OriginFor; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::tasks] + impl Pallet { + #[pallet::task_index(0)] + #[pallet::task_condition(|flag: bool| flag)] + #[pallet::task_list(vec![1, 2].iter())] + #[pallet::task_weight(0.into())] + fn foo(_i: u32) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.stderr b/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.stderr new file mode 100644 index 000000000000..5642e407a503 --- /dev/null +++ b/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.stderr @@ -0,0 +1,30 @@ +error: unused import: `frame_system::pallet_prelude::OriginFor` + --> tests/pallet_ui/task_condition_invalid_arg.rs:21:6 + | +21 | use frame_system::pallet_prelude::OriginFor; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D unused-imports` implied by `-D warnings` + +error[E0559]: variant `pallet::Task<_>::Foo` has no field named `i` + --> tests/pallet_ui/task_condition_invalid_arg.rs:18:1 + | +18 | #[frame_support::pallet(dev_mode)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a field with a similar name exists: `_i` + | + = note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0308]: mismatched types + --> tests/pallet_ui/task_condition_invalid_arg.rs:35:10 + | +32 | #[pallet::task_condition(|flag: bool| flag)] + | ----------------- arguments to this function are incorrect +... +35 | fn foo(_i: u32) -> DispatchResult { + | ^^ expected `bool`, found `u32` + | +note: closure parameter defined here + --> tests/pallet_ui/task_condition_invalid_arg.rs:32:29 + | +32 | #[pallet::task_condition(|flag: bool| flag)] + | ^^^^^^^^^^ diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs index 804782141901..c83e0ba2c614 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs @@ -29,7 +29,7 @@ mod pallet { #[pallet::tasks] impl Pallet { #[pallet::task_index(0)] - #[pallet::task_condition(|_| true)] + #[pallet::task_condition(|| true)] fn foo() -> DispatchResult { Ok(()) } diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs index 7ca279980537..2f2186337e86 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs @@ -29,7 +29,7 @@ mod pallet { #[pallet::tasks] impl Pallet { #[pallet::task_index(0)] - #[pallet::task_condition(|_| true)] + #[pallet::task_condition(|| true)] #[pallet::task_list(vec![1, 2].iter())] fn foo() -> DispatchResult { Ok(()) From 09cae7824c0a6cb2deca29172e870a0afd6cebb8 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:43:04 +0530 Subject: [PATCH 132/177] Minor fix --- substrate/frame/support/procedural/src/pallet/expand/tasks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 08741c61f1b1..a4f0283b903a 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -157,7 +157,7 @@ impl ToTokens for TasksDef { fn iter() -> Self::Enumeration { let mut all_tasks = #sp_std::vec![]; #(all_tasks - .extend(#task_iters.map(|#(#task_arg_names),*| #enum_ident::#task_fn_idents { #(#task_arg_names: #task_arg_names.clone()),* }) + .extend(#task_iters.map(|(#(#task_arg_names),*)| #enum_ident::#task_fn_idents { #(#task_arg_names: #task_arg_names.clone()),* }) .collect::<#sp_std::vec::Vec<_>>()); )* all_tasks.into_iter() From a4338052071854640f330a888517d945b8d95a01 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:57:54 +0530 Subject: [PATCH 133/177] Adds RuntimeTask in missing places --- cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index 60107281c22f..c7966c4fee6e 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -177,6 +177,7 @@ impl frame_system::Config for Runtime { type Hashing = BlakeTwo256; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type Version = Version; From e85c1e7af94d35b3b88756a06fed5a8ae3d85c8b Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:08:59 +0530 Subject: [PATCH 134/177] Fix --- .../runtimes/collectives/collectives-westend/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 8c5593e154d7..e6cc4a16a471 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -166,6 +166,7 @@ impl frame_system::Config for Runtime { type Hashing = BlakeTwo256; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = RocksDbWeight; From e57cf9829a90f116d9fe96e2b1d4074cfc6ceb84 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 17 Nov 2023 10:49:43 +0530 Subject: [PATCH 135/177] Adds UI Test for passing case with multiple args --- .../support/test/tests/pallet_ui/pass/task_valid.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs b/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs index d6be08071801..76dade939454 100644 --- a/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs +++ b/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs @@ -17,7 +17,7 @@ #[frame_support::pallet(dev_mode)] mod pallet { - use frame_support::pallet_prelude::DispatchResult; + use frame_support::{ensure, pallet_prelude::DispatchResult}; #[pallet::config] pub trait Config: frame_system::Config {} @@ -28,11 +28,12 @@ mod pallet { #[pallet::tasks] impl Pallet { #[pallet::task_index(0)] - #[pallet::task_condition(|i| i == 0u32)] - #[pallet::task_list(vec![1u32, 2u32].iter())] + #[pallet::task_condition(|i, j| i == 0u32 && j == 2u64)] + #[pallet::task_list(vec![(0u32, 2u64), (2u32, 4u64)].iter())] #[pallet::task_weight(0.into())] - fn foo(i: u32) -> DispatchResult { - frame_support::ensure!(i == 0, "i must be 0"); + fn foo(i: u32, j: u64) -> DispatchResult { + ensure!(i == 0, "i must be 0"); + ensure!(j == 2, "j must be 2"); Ok(()) } } From cdc8e3def5ba696f86938a1cce4127b7dc0b5b9b Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:17:49 +0530 Subject: [PATCH 136/177] Adds Docs --- substrate/frame/support/procedural/src/lib.rs | 50 +++++++++++++++ .../procedural/src/pallet/expand/tasks.rs | 11 ++-- substrate/frame/support/src/lib.rs | 50 +++++++++++++++ substrate/frame/support/src/tests/mod.rs | 37 ++++++++++- substrate/frame/support/src/tests/tasks.rs | 62 +++++++++++++++++++ substrate/frame/support/src/traits/tasks.rs | 24 +++++++ 6 files changed, 226 insertions(+), 8 deletions(-) create mode 100644 substrate/frame/support/src/tests/tasks.rs diff --git a/substrate/frame/support/procedural/src/lib.rs b/substrate/frame/support/procedural/src/lib.rs index 7f2a9ebcff45..47144ea6e934 100644 --- a/substrate/frame/support/procedural/src/lib.rs +++ b/substrate/frame/support/procedural/src/lib.rs @@ -1546,6 +1546,56 @@ pub fn composite_enum(_: TokenStream, _: TokenStream) -> TokenStream { pallet_macro_stub() } +/// +/// --- +/// +/// **Rust-Analyzer users**: See the documentation of the Rust item in +/// `frame_support::pallet_macros::tasks`. +#[proc_macro_attribute] +pub fn tasks(_: TokenStream, _: TokenStream) -> TokenStream { + pallet_macro_stub() +} + +/// +/// --- +/// +/// **Rust-Analyzer users**: See the documentation of the Rust item in +/// `frame_support::pallet_macros::task_list`. +#[proc_macro_attribute] +pub fn task_list(_: TokenStream, _: TokenStream) -> TokenStream { + pallet_macro_stub() +} + +/// +/// --- +/// +/// **Rust-Analyzer users**: See the documentation of the Rust item in +/// `frame_support::pallet_macros::task_condition`. +#[proc_macro_attribute] +pub fn task_condition(_: TokenStream, _: TokenStream) -> TokenStream { + pallet_macro_stub() +} + +/// +/// --- +/// +/// **Rust-Analyzer users**: See the documentation of the Rust item in +/// `frame_support::pallet_macros::task_weight`. +#[proc_macro_attribute] +pub fn task_weight(_: TokenStream, _: TokenStream) -> TokenStream { + pallet_macro_stub() +} + +/// +/// --- +/// +/// **Rust-Analyzer users**: See the documentation of the Rust item in +/// `frame_support::pallet_macros::task_index`. +#[proc_macro_attribute] +pub fn task_index(_: TokenStream, _: TokenStream) -> TokenStream { + pallet_macro_stub() +} + /// Can be attached to a module. Doing so will declare that module as importable into a pallet /// via [`#[import_section]`](`macro@import_section`). /// diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 59914d4a71cd..20dd2d21a9b9 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -86,13 +86,16 @@ impl ToTokens for TaskEnumDef { tokens.extend(quote! { #(#attrs)* #[derive( - Clone, - PartialEq, - Eq, + #scrate::CloneNoBound, + #scrate::EqNoBound, + #scrate::PartialEqNoBound, #scrate::pallet_prelude::Encode, #scrate::pallet_prelude::Decode, #scrate::pallet_prelude::TypeInfo, )] + #[codec(encode_bound())] + #[codec(decode_bound())] + #[scale_info(skip_type_params(#type_use_generics))] #vis enum #ident #generics { #variants #[doc(hidden)] @@ -155,8 +158,6 @@ impl ToTokens for TasksDef { } impl #impl_generics #scrate::traits::Task for #enum_use - where - T: #scrate::pallet_prelude::TypeInfo, { type Enumeration = #sp_std::vec::IntoIter<#enum_use>; diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 58b0fc2cfb12..70d0114b361d 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -2526,6 +2526,56 @@ pub mod pallet_macros { /// } /// ``` pub use frame_support_procedural::storage; + /// Allows you to define some service work that can be recognized by a script or an + /// off-chain worker. Such a script can then create and submit all such work items at any + /// given time. + /// + /// These work items are defined as instances of the [`Task`](frame_support::traits::Task) + /// trait. [`pallet:tasks`](`tasks`) when attached to an `impl` block inside a pallet, will + /// generate an enum `Task` whose variants are mapped to functions inside this `impl` + /// block. + /// + /// Each such function must have the following set of attributes: + /// + /// * [`pallet::task_list`](`task_list`) + /// * [`pallet::task_condition`](`task_condition`) + /// * [`pallet::task_weight`](`task_weight`) + /// * [`pallet::task_index`](`task_index`) + /// + /// All of such Tasks are then aggregated into a `RuntimeTask` by + /// [`construct_runtime`](frame_support::construct_runtime). + /// + /// Finally, the `RuntimeTask` can then used by a script or off-chain worker to create and + /// submit such tasks via an extrinsic defined in `frame_system` called `do_task`. + /// + /// ## Example + #[doc = docify::embed!("src/tests/tasks.rs", tasks_example)] + /// Now, this can be executed as follows: + #[doc = docify::embed!("src/tests/tasks.rs", tasks_work)] + pub use frame_support_procedural::tasks; + /// This attribute is attached to a function inside an `impl` block annoated with + /// [`pallet::tasks`](`tasks`) to define the conditions for a given work item to be valid. + /// + /// It takes a closure as input, which is then used to define the condition. The closure + /// should have the same signature as the function it is attached to, except that it should + /// return a `bool` instead. + pub use frame_support_procedural::task_condition; + /// This attribute is attached to a function inside an `impl` block annoated with + /// [`pallet::tasks`](`tasks`) to define the index of a given work item. + /// + /// It takes an integer literal as input, which is then used to define the index. This index + /// should be unique for each function in the `impl` block. + pub use frame_support_procedural::task_index; + /// This attribute is attached to a function inside an `impl` block annoated with + /// [`pallet::tasks`](`tasks`) to define an iterator over the available work items for a task. + /// + /// It takes an iterator as input that yields a tuple with same types as the function arguments. + pub use frame_support_procedural::task_list; + /// This attribute is attached to a function inside an `impl` block annoated with + /// [`pallet::tasks`](`tasks`) define the weight of a given work item. + /// + /// It takes a closure as input, which should return a `Weight` value. + pub use frame_support_procedural::task_weight; } #[deprecated(note = "Will be removed after July 2023; Use `sp_runtime::traits` directly instead.")] diff --git a/substrate/frame/support/src/tests/mod.rs b/substrate/frame/support/src/tests/mod.rs index ed2e7317c5ab..6b01e6daa6af 100644 --- a/substrate/frame/support/src/tests/mod.rs +++ b/substrate/frame/support/src/tests/mod.rs @@ -16,6 +16,7 @@ // limitations under the License. use super::*; +use frame_support_procedural::import_section; use sp_io::{MultiRemovalResults, TestExternalities}; use sp_metadata_ir::{ PalletStorageMetadataIR, StorageEntryMetadataIR, StorageEntryModifierIR, StorageEntryTypeIR, @@ -27,13 +28,15 @@ pub use self::frame_system::{pallet_prelude::*, Config, Pallet}; mod inject_runtime_type; mod storage_alias; +mod tasks; +#[import_section(tasks::tasks_example)] #[pallet] pub mod frame_system { #[allow(unused)] use super::{frame_system, frame_system::pallet_prelude::*}; pub use crate::dispatch::RawOrigin; - use crate::pallet_prelude::*; + use crate::{pallet_prelude::*, traits::tasks::Task as TaskTrait}; pub mod config_preludes { use super::{inject_runtime_type, DefaultConfig}; @@ -71,7 +74,7 @@ pub mod frame_system { #[pallet::no_default_bounds] type RuntimeCall; #[pallet::no_default_bounds] - type RuntimeTask; + type RuntimeTask: crate::traits::tasks::Task; #[pallet::no_default_bounds] type PalletInfo: crate::traits::PalletInfo; type DbWeight: Get; @@ -81,13 +84,33 @@ pub mod frame_system { pub enum Error { /// Required by construct_runtime CallFiltered, + /// Used in tasks example + NotFound, + /// The specified [`Task`] is not valid. + InvalidTask, + /// The specified [`Task`] failed during execution. + FailedTask, } #[pallet::origin] pub type Origin = RawOrigin<::AccountId>; #[pallet::call] - impl Pallet {} + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(task.weight())] + pub fn do_task(_origin: OriginFor, task: T::RuntimeTask) -> DispatchResultWithPostInfo { + if !task.is_valid() { + return Err(Error::::InvalidTask.into()) + } + + if let Err(_err) = task.run() { + return Err(Error::::FailedTask.into()) + } + + Ok(().into()) + } + } #[pallet::storage] pub type Data = StorageMap<_, Twox64Concat, u32, u64, ValueQuery>; @@ -173,6 +196,14 @@ pub mod frame_system { } } + /// Some running total. + #[pallet::storage] + pub type Total = StorageValue<_, (u32, u32), ValueQuery>; + + /// Numbers to be added into the total. + #[pallet::storage] + pub type Numbers = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>; + pub mod pallet_prelude { pub type OriginFor = ::RuntimeOrigin; diff --git a/substrate/frame/support/src/tests/tasks.rs b/substrate/frame/support/src/tests/tasks.rs new file mode 100644 index 000000000000..4a09642d20da --- /dev/null +++ b/substrate/frame/support/src/tests/tasks.rs @@ -0,0 +1,62 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::{ + assert_ok, + tests::{ + frame_system::{Numbers, Total}, + new_test_ext, Runtime, RuntimeOrigin, RuntimeTask, System, + }, +}; +use frame_support_procedural::pallet_section; + +#[pallet_section] +mod tasks_example { + #[docify::export(tasks_example)] + #[pallet::tasks] + impl Pallet { + /// Add a pair of numbers into the totals and remove them. + #[pallet::task_list(Numbers::::iter_keys())] + #[pallet::task_condition(|i| Numbers::::contains_key(i))] + #[pallet::task_weight(0.into())] + #[pallet::task_index(0)] + pub fn add_number_into_total(i: u32) -> DispatchResult { + let v = Numbers::::take(i).ok_or(Error::::NotFound)?; + Total::::mutate(|(total_keys, total_values)| { + *total_keys += i; + *total_values += v; + }); + Ok(()) + } + } +} + +#[docify::export] +#[test] +fn tasks_work() { + new_test_ext().execute_with(|| { + Numbers::::insert(0, 1); + + let task = RuntimeTask::System(super::frame_system::Task::::AddNumberIntoTotal { + i: 0u32, + }); + + assert_ok!(System::do_task(RuntimeOrigin::signed(1), task.clone(),)); + assert_eq!(Numbers::::get(0), None); + assert_eq!(Total::::get(), (0, 1)); + }); +} diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index 9ef3272a47ba..7a11cc98a201 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -56,3 +56,27 @@ pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq { /// in other pallets. fn task_index(&self) -> u32; } + +impl Task for () { + type Enumeration = IntoIter; + + fn iter() -> Self::Enumeration { + vec![].into_iter() + } + + fn is_valid(&self) -> bool { + true + } + + fn run(&self) -> Result<(), DispatchError> { + Ok(()) + } + + fn weight(&self) -> Weight { + 0.into() + } + + fn task_index(&self) -> u32 { + 0 + } +} From 1f677e69ab451aa06204bc80f7b2fc4c165e6cdf Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 17 Nov 2023 07:53:18 +0000 Subject: [PATCH 137/177] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/frame/support/src/lib.rs | 48 ++++++++++++++++-------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 70d0114b361d..8fdfe6bf1e94 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -2526,6 +2526,31 @@ pub mod pallet_macros { /// } /// ``` pub use frame_support_procedural::storage; + /// This attribute is attached to a function inside an `impl` block annoated with + /// [`pallet::tasks`](`tasks`) to define the conditions for a given work item to be valid. + /// + /// It takes a closure as input, which is then used to define the condition. The closure + /// should have the same signature as the function it is attached to, except that it should + /// return a `bool` instead. + pub use frame_support_procedural::task_condition; + /// This attribute is attached to a function inside an `impl` block annoated with + /// [`pallet::tasks`](`tasks`) to define the index of a given work item. + /// + /// It takes an integer literal as input, which is then used to define the index. This + /// index should be unique for each function in the `impl` block. + pub use frame_support_procedural::task_index; + /// This attribute is attached to a function inside an `impl` block annoated with + /// [`pallet::tasks`](`tasks`) to define an iterator over the available work items for a + /// task. + /// + /// It takes an iterator as input that yields a tuple with same types as the function + /// arguments. + pub use frame_support_procedural::task_list; + /// This attribute is attached to a function inside an `impl` block annoated with + /// [`pallet::tasks`](`tasks`) define the weight of a given work item. + /// + /// It takes a closure as input, which should return a `Weight` value. + pub use frame_support_procedural::task_weight; /// Allows you to define some service work that can be recognized by a script or an /// off-chain worker. Such a script can then create and submit all such work items at any /// given time. @@ -2553,29 +2578,6 @@ pub mod pallet_macros { /// Now, this can be executed as follows: #[doc = docify::embed!("src/tests/tasks.rs", tasks_work)] pub use frame_support_procedural::tasks; - /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks`](`tasks`) to define the conditions for a given work item to be valid. - /// - /// It takes a closure as input, which is then used to define the condition. The closure - /// should have the same signature as the function it is attached to, except that it should - /// return a `bool` instead. - pub use frame_support_procedural::task_condition; - /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks`](`tasks`) to define the index of a given work item. - /// - /// It takes an integer literal as input, which is then used to define the index. This index - /// should be unique for each function in the `impl` block. - pub use frame_support_procedural::task_index; - /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks`](`tasks`) to define an iterator over the available work items for a task. - /// - /// It takes an iterator as input that yields a tuple with same types as the function arguments. - pub use frame_support_procedural::task_list; - /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks`](`tasks`) define the weight of a given work item. - /// - /// It takes a closure as input, which should return a `Weight` value. - pub use frame_support_procedural::task_weight; } #[deprecated(note = "Will be removed after July 2023; Use `sp_runtime::traits` directly instead.")] From b199039383f1dd2e36dc4a91ae51d4e1d86accbc Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:30:06 +0530 Subject: [PATCH 138/177] Minor fix --- substrate/frame/support/src/traits/tasks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index 7a11cc98a201..171308d8bb1e 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -73,7 +73,7 @@ impl Task for () { } fn weight(&self) -> Weight { - 0.into() + Weight::default() } fn task_index(&self) -> u32 { From 0053aee4ca2f35f546141e8638dddfb2b73aa624 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:46:23 +0530 Subject: [PATCH 139/177] Minor fix --- substrate/frame/examples/tasks/src/benchmarking.rs | 2 +- substrate/frame/support/procedural/src/benchmark.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/examples/tasks/src/benchmarking.rs b/substrate/frame/examples/tasks/src/benchmarking.rs index ce29f405d78d..81f7d3d3b21c 100644 --- a/substrate/frame/examples/tasks/src/benchmarking.rs +++ b/substrate/frame/examples/tasks/src/benchmarking.rs @@ -38,5 +38,5 @@ mod benchmarks { assert_eq!(Numbers::::get(0), None); } - impl_benchmark_test_suite!(TasksExample, crate::tests::new_test_ext(), crate::mock::Runtime); + impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::mock::Runtime); } diff --git a/substrate/frame/support/procedural/src/benchmark.rs b/substrate/frame/support/procedural/src/benchmark.rs index fb55e8c9f662..6ded82d91aa5 100644 --- a/substrate/frame/support/procedural/src/benchmark.rs +++ b/substrate/frame/support/procedural/src/benchmark.rs @@ -517,7 +517,7 @@ pub fn benchmarks( components, // TODO: Not supported by V2 syntax as of yet. // https://github.com/paritytech/substrate/issues/13132 - pov_modes: vec![], + pov_modes: #krate::__private::vec![], } }).collect::<#krate::__private::Vec<_>>() } From e45eb4c8908da55fa9de4fdf8395d4073bd48e39 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:52:04 +0530 Subject: [PATCH 140/177] Minor fix --- substrate/frame/asset-rate/src/benchmarking.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/asset-rate/src/benchmarking.rs b/substrate/frame/asset-rate/src/benchmarking.rs index 21d53a89e397..6fcc7c7fadb2 100644 --- a/substrate/frame/asset-rate/src/benchmarking.rs +++ b/substrate/frame/asset-rate/src/benchmarking.rs @@ -25,7 +25,6 @@ use frame_benchmarking::v2::*; use frame_support::assert_ok; use frame_system::RawOrigin; use sp_core::crypto::FromEntropy; -use sp_std::vec; /// Trait describing the factory function for the `AssetKind` parameter. pub trait AssetKindFactory { From 86fb3c1ba2b57a5ae81a7e3a7e3dba7452ed8f56 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 17 Nov 2023 14:01:43 +0530 Subject: [PATCH 141/177] Minor fix --- substrate/bin/node-template/pallets/template/src/benchmarking.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/bin/node-template/pallets/template/src/benchmarking.rs b/substrate/bin/node-template/pallets/template/src/benchmarking.rs index 6c3cae6066b4..5a262417629c 100644 --- a/substrate/bin/node-template/pallets/template/src/benchmarking.rs +++ b/substrate/bin/node-template/pallets/template/src/benchmarking.rs @@ -1,7 +1,6 @@ //! Benchmarking setup for pallet-template #![cfg(feature = "runtime-benchmarks")] use super::*; -use sp_std::vec; #[allow(unused)] use crate::Pallet as Template; From e2fda09ce3b13a7b4d005e9fd856347b55af55db Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 17 Nov 2023 14:45:05 +0530 Subject: [PATCH 142/177] Minor fixes --- .../frame/benchmarking/pov/src/benchmarking.rs | 1 + substrate/frame/support/src/tests/mod.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/substrate/frame/benchmarking/pov/src/benchmarking.rs b/substrate/frame/benchmarking/pov/src/benchmarking.rs index 473947b171ac..1b7f7ca6c59e 100644 --- a/substrate/frame/benchmarking/pov/src/benchmarking.rs +++ b/substrate/frame/benchmarking/pov/src/benchmarking.rs @@ -368,6 +368,7 @@ mod mock { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/frame/support/src/tests/mod.rs b/substrate/frame/support/src/tests/mod.rs index 6b01e6daa6af..2b71b2fcf568 100644 --- a/substrate/frame/support/src/tests/mod.rs +++ b/substrate/frame/support/src/tests/mod.rs @@ -658,6 +658,24 @@ fn expected_metadata() -> PalletStorageMetadataIR { default: vec![0], docs: vec![], }, + StorageEntryMetadataIR { + name: "Total", + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Plain(scale_info::meta_type::<(u32, u32)>()), + default: vec![0, 0, 0, 0, 0, 0, 0, 0], + docs: vec![" Some running total."], + }, + StorageEntryMetadataIR { + name: "Numbers", + modifier: StorageEntryModifierIR::Optional, + ty: StorageEntryTypeIR::Map { + hashers: vec![StorageHasherIR::Twox64Concat], + key: scale_info::meta_type::(), + value: scale_info::meta_type::(), + }, + default: vec![0], + docs: vec![" Numbers to be added into the total."], + }, ], } } From 82e79ea88423d4a957338a165af93d7583f31631 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Fri, 17 Nov 2023 14:48:13 +0530 Subject: [PATCH 143/177] Updates UI Test outputs --- .../tests/pallet_ui/task_condition_invalid_arg.stderr | 8 -------- .../test/tests/pallet_ui/task_invalid_condition.stderr | 8 +++++--- .../test/tests/pallet_ui/task_invalid_list.stderr | 9 --------- .../test/tests/pallet_ui/task_invalid_weight.stderr | 8 +++++--- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.stderr b/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.stderr index 5642e407a503..ef259656688a 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.stderr @@ -6,14 +6,6 @@ error: unused import: `frame_system::pallet_prelude::OriginFor` | = note: `-D unused-imports` implied by `-D warnings` -error[E0559]: variant `pallet::Task<_>::Foo` has no field named `i` - --> tests/pallet_ui/task_condition_invalid_arg.rs:18:1 - | -18 | #[frame_support::pallet(dev_mode)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a field with a similar name exists: `_i` - | - = note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0308]: mismatched types --> tests/pallet_ui/task_condition_invalid_arg.rs:35:10 | diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.stderr b/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.stderr index 45b080728f4c..ff57017b3fdb 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.stderr @@ -6,13 +6,15 @@ error: unused import: `frame_system::pallet_prelude::OriginFor` | = note: `-D unused-imports` implied by `-D warnings` -error[E0559]: variant `pallet::Task<_>::Foo` has no field named `i` +error[E0308]: mismatched types --> tests/pallet_ui/task_invalid_condition.rs:18:1 | 18 | #[frame_support::pallet(dev_mode)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pallet::Task<_>::Foo` does not have this field + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected integer, found `()` + | expected due to this | - = note: all struct fields are already assigned = note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0618]: expected function, found `{integer}` diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.stderr b/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.stderr index b12ba2dcd8f6..8dda0c3a1aaa 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.stderr @@ -17,12 +17,3 @@ help: you must specify a concrete type for this numeric value, like `i32` | 33 | #[pallet::task_list(0_i32)] | ~~~~~ - -error[E0559]: variant `pallet::Task<_>::Foo` has no field named `i` - --> tests/pallet_ui/task_invalid_list.rs:18:1 - | -18 | #[frame_support::pallet(dev_mode)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pallet::Task<_>::Foo` does not have this field - | - = note: all struct fields are already assigned - = note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.stderr b/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.stderr index b959da5f1cbf..3537bb590281 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.stderr @@ -6,13 +6,15 @@ error: unused import: `frame_system::pallet_prelude::OriginFor` | = note: `-D unused-imports` implied by `-D warnings` -error[E0559]: variant `pallet::Task<_>::Foo` has no field named `i` +error[E0308]: mismatched types --> tests/pallet_ui/task_invalid_weight.rs:18:1 | 18 | #[frame_support::pallet(dev_mode)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pallet::Task<_>::Foo` does not have this field + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected integer, found `()` + | expected due to this | - = note: all struct fields are already assigned = note: this error originates in the attribute macro `frame_support::pallet` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types From 7e8b495c30885ca5f85ea008d63ce89f0365f764 Mon Sep 17 00:00:00 2001 From: gupnik <17176722+gupnik@users.noreply.github.com> Date: Mon, 27 Nov 2023 13:15:51 +0530 Subject: [PATCH 144/177] Update substrate/frame/examples/tasks/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/frame/examples/tasks/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/examples/tasks/src/lib.rs b/substrate/frame/examples/tasks/src/lib.rs index 1de66bc5a877..d7782569a77a 100644 --- a/substrate/frame/examples/tasks/src/lib.rs +++ b/substrate/frame/examples/tasks/src/lib.rs @@ -14,7 +14,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - +//! This pallet demonstrates the use of the `pallet::task` api for service work. #![cfg_attr(not(feature = "std"), no_std)] use frame_support::dispatch::DispatchResult; From bc99c0d97a67a8c7d9845ec1b0e6da741be84315 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:23:57 +0530 Subject: [PATCH 145/177] Addresses review comments --- .../src/construct_runtime/expand/task.rs | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index c10f479389b5..f2a6cff881d6 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -41,6 +41,15 @@ pub fn expand_outer_task( RuntimeTask::#variant_name(hr) } } + + impl From for Option<#path::Task<#runtime_name>> { + fn from(rt: RuntimeTask) -> Self { + match rt { + RuntimeTask::#variant_name(hr) => Some(hr), + _ => None, + } + } + } }); task_variants.push(quote! { @@ -56,15 +65,12 @@ pub fn expand_outer_task( let prelude = quote!(#scrate::traits::tasks::prelude); - const INCOMPLETE_MATCH_QED: &'static str = - "cannot have an instantiated RuntimeTask without some Task variant in the runtime. QED"; - let output = quote! { /// An aggregation of all `Task` enums across all pallets included in the current runtime. #[derive( Clone, Eq, PartialEq, - #scrate::__private::codec::Encode, #scrate::__private::codec::Decode, - // #scrate::__private::codec::MaxEncodedLen, + #scrate::__private::codec::Encode, + #scrate::__private::codec::Decode, #scrate::__private::scale_info::TypeInfo, #scrate::__private::RuntimeDebug, )] @@ -72,38 +78,31 @@ pub fn expand_outer_task( #( #task_variants )* } + #[automatically_derived] impl #scrate::traits::Task for RuntimeTask { type Enumeration = #prelude::IntoIter; - #[allow(unreachable_code)] fn is_valid(&self) -> bool { match self { #(RuntimeTask::#variant_names(val) => val.is_valid(),)* - _ => unreachable!(#INCOMPLETE_MATCH_QED), } } - #[allow(unreachable_code)] fn run(&self) -> Result<(), #scrate::traits::tasks::prelude::DispatchError> { match self { #(RuntimeTask::#variant_names(val) => val.run(),)* - _ => unreachable!(#INCOMPLETE_MATCH_QED), } } - #[allow(unreachable_code)] fn weight(&self) -> #scrate::pallet_prelude::Weight { match self { #(RuntimeTask::#variant_names(val) => val.weight(),)* - _ => unreachable!(#INCOMPLETE_MATCH_QED), } } - #[allow(unreachable_code)] fn task_index(&self) -> u32 { match self { #(RuntimeTask::#variant_names(val) => val.task_index(),)* - _ => unreachable!(#INCOMPLETE_MATCH_QED), } } @@ -116,7 +115,6 @@ pub fn expand_outer_task( #( #from_impls )* }; - // use proc_utils::*; - // output.pretty_print(); + output } From 5b1fd64300f22db994d0ec1d14dcb81c833f603c Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:28:02 +0530 Subject: [PATCH 146/177] Fixes spans --- substrate/frame/support/procedural/src/pallet/expand/tasks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 20dd2d21a9b9..c1c6a82a0e6c 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -39,7 +39,7 @@ impl TaskEnumDef { .iter() .map(|task| { let ident = &task.item.sig.ident; - let ident = format_ident!("{}", ident.to_string().to_class_case()); + let ident = format_ident!("{}", ident.to_string().to_class_case(), span = ident.span()); let args = task.item.sig.inputs.iter().collect::>(); @@ -133,7 +133,7 @@ impl ToTokens for TasksDef { let task_fn_idents = self .tasks .iter() - .map(|task| format_ident!("{}", &task.item.sig.ident.to_string().to_class_case())) + .map(|task| format_ident!("{}", &task.item.sig.ident.to_string().to_class_case(), span = task.item.sig.ident.span())) .collect::>(); let task_indices = self.tasks.iter().map(|task| &task.index_attr.meta.index); let task_conditions = self.tasks.iter().map(|task| &task.condition_attr.meta.expr); From a9b7393322bcdaa6cf51c1a8863dbb6c85e1b7e6 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:58:11 +0530 Subject: [PATCH 147/177] Fixes build --- .../procedural/src/construct_runtime/expand/task.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index f2a6cff881d6..382633044a2c 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -65,6 +65,9 @@ pub fn expand_outer_task( let prelude = quote!(#scrate::traits::tasks::prelude); + const INCOMPLETE_MATCH_QED: &'static str = + "cannot have an instantiated RuntimeTask without some Task variant in the runtime. QED"; + let output = quote! { /// An aggregation of all `Task` enums across all pallets included in the current runtime. #[derive( @@ -85,24 +88,28 @@ pub fn expand_outer_task( fn is_valid(&self) -> bool { match self { #(RuntimeTask::#variant_names(val) => val.is_valid(),)* + _ => unreachable!(#INCOMPLETE_MATCH_QED), } } fn run(&self) -> Result<(), #scrate::traits::tasks::prelude::DispatchError> { match self { #(RuntimeTask::#variant_names(val) => val.run(),)* + _ => unreachable!(#INCOMPLETE_MATCH_QED), } } fn weight(&self) -> #scrate::pallet_prelude::Weight { match self { #(RuntimeTask::#variant_names(val) => val.weight(),)* + _ => unreachable!(#INCOMPLETE_MATCH_QED), } } fn task_index(&self) -> u32 { match self { #(RuntimeTask::#variant_names(val) => val.task_index(),)* + _ => unreachable!(#INCOMPLETE_MATCH_QED), } } From 9b6e6b7d54d1b0c2547066372982f2f3e3d32e48 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 28 Nov 2023 04:45:16 +0000 Subject: [PATCH 148/177] ".git/.scripts/commands/fmt/fmt.sh" --- .../procedural/src/construct_runtime/expand/task.rs | 2 +- .../support/procedural/src/pallet/expand/tasks.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 382633044a2c..a2d74e76e4ab 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -72,7 +72,7 @@ pub fn expand_outer_task( /// An aggregation of all `Task` enums across all pallets included in the current runtime. #[derive( Clone, Eq, PartialEq, - #scrate::__private::codec::Encode, + #scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::scale_info::TypeInfo, #scrate::__private::RuntimeDebug, diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index c1c6a82a0e6c..19d99a85028a 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -39,7 +39,8 @@ impl TaskEnumDef { .iter() .map(|task| { let ident = &task.item.sig.ident; - let ident = format_ident!("{}", ident.to_string().to_class_case(), span = ident.span()); + let ident = + format_ident!("{}", ident.to_string().to_class_case(), span = ident.span()); let args = task.item.sig.inputs.iter().collect::>(); @@ -133,7 +134,13 @@ impl ToTokens for TasksDef { let task_fn_idents = self .tasks .iter() - .map(|task| format_ident!("{}", &task.item.sig.ident.to_string().to_class_case(), span = task.item.sig.ident.span())) + .map(|task| { + format_ident!( + "{}", + &task.item.sig.ident.to_string().to_class_case(), + span = task.item.sig.ident.span() + ) + }) .collect::>(); let task_indices = self.tasks.iter().map(|task| &task.index_attr.meta.index); let task_conditions = self.tasks.iter().map(|task| &task.condition_attr.meta.expr); From 009060a01d1003d58355172de927888cf185fc93 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:34:57 +0530 Subject: [PATCH 149/177] Adds PrDoc --- prdoc/pr_1343.prdoc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 prdoc/pr_1343.prdoc diff --git a/prdoc/pr_1343.prdoc b/prdoc/pr_1343.prdoc new file mode 100644 index 000000000000..69bed2d1ccf2 --- /dev/null +++ b/prdoc/pr_1343.prdoc @@ -0,0 +1,29 @@ +# Schema: Parity PR Documentation Schema (prdoc) +# See doc at https://github.com/paritytech/prdoc + +title: Tasks API: A general system for recognizing and executing service work + +doc: + - audience: Core Dev + description: | + The Tasks API allows you to define some service work that can be recognized by a script or an + off-chain worker. Such a script can then create and submit all such work items at any + given time. + `#[pallet:tasks]` provides a convenient way to define such work items. It can be attached to an + `impl` block inside a pallet, whose functions can then be annotated by the following attributes: + 1. `#[pallet::task_list]`: Define an iterator over the available work items for a task + 2. `#[pallet::task_condition]`: Define the conditions for a given work item to be valid + 3. `#[pallet::task_weight]`: Define the weight of a given work item + 4. `#[pallet::task_index]`: Define the index of a given work item + Each such function becomes a variant of the autogenerated enum `Task` for this pallet. All such + enums are aggregated into a `RuntimeTask` by `construct_runtime`. + An example pallet that uses the Tasks API is available at `substrate/frame/example/tasks`. + +migrations: + db: [] + + runtime: [] + +crates: [] + +host_functions: [] From fc1ee33dc60824e40d7e79463fac009c9cf2c526 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:46:32 +0530 Subject: [PATCH 150/177] Adds missing RuntimeTask --- substrate/frame/benchmarking/src/baseline.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/benchmarking/src/baseline.rs b/substrate/frame/benchmarking/src/baseline.rs index 6cd23ebe028a..55c773a49821 100644 --- a/substrate/frame/benchmarking/src/baseline.rs +++ b/substrate/frame/benchmarking/src/baseline.rs @@ -138,6 +138,7 @@ pub mod mock { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; From 06fbea89ed3865fd8cc8af6c6319fb70da75aa6e Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:22:58 +0530 Subject: [PATCH 151/177] Removes RuntimeTask from configs --- cumulus/pallets/collator-selection/src/mock.rs | 1 - cumulus/pallets/xcmp-queue/src/mock.rs | 1 - cumulus/parachain-template/pallets/template/src/mock.rs | 1 - cumulus/parachain-template/runtime/src/lib.rs | 1 - cumulus/parachains/common/src/impls.rs | 1 - cumulus/parachains/pallets/collective-content/src/mock.rs | 1 - .../parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 1 - .../runtimes/assets/asset-hub-polkadot/src/lib.rs | 1 - .../parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 1 - .../parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 1 - .../runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs | 1 - .../runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs | 1 - .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 1 - .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 1 - .../runtimes/collectives/collectives-polkadot/src/lib.rs | 1 - .../runtimes/collectives/collectives-westend/src/lib.rs | 1 - .../runtimes/contracts/contracts-rococo/src/lib.rs | 1 - .../parachains/runtimes/glutton/glutton-kusama/src/lib.rs | 1 - .../parachains/runtimes/glutton/glutton-westend/src/lib.rs | 1 - cumulus/parachains/runtimes/starters/seedling/src/lib.rs | 1 - cumulus/parachains/runtimes/starters/shell/src/lib.rs | 1 - cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 1 - .../parachains/runtimes/testing/rococo-parachain/src/lib.rs | 1 - cumulus/test/runtime/src/lib.rs | 1 - polkadot/node/core/candidate-validation/src/lib.rs | 6 +++--- polkadot/node/core/candidate-validation/src/tests.rs | 2 +- polkadot/runtime/common/src/assigned_slots/mod.rs | 1 - polkadot/runtime/common/src/auctions.rs | 1 - polkadot/runtime/common/src/claims.rs | 1 - polkadot/runtime/common/src/crowdloan/mod.rs | 1 - polkadot/runtime/common/src/impls.rs | 1 - polkadot/runtime/common/src/integration_tests.rs | 1 - polkadot/runtime/common/src/paras_registrar/mod.rs | 1 - polkadot/runtime/common/src/purchase.rs | 1 - polkadot/runtime/common/src/slots/mod.rs | 1 - polkadot/runtime/parachains/src/mock.rs | 1 - polkadot/runtime/rococo/src/lib.rs | 1 - polkadot/runtime/test-runtime/src/lib.rs | 1 - polkadot/runtime/westend/src/lib.rs | 1 - polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs | 1 - polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs | 1 - polkadot/xcm/pallet-xcm/src/mock.rs | 1 - polkadot/xcm/procedural/src/builder_pattern.rs | 2 +- polkadot/xcm/xcm-builder/tests/mock/mod.rs | 1 - polkadot/xcm/xcm-simulator/example/src/parachain.rs | 1 - polkadot/xcm/xcm-simulator/example/src/relay_chain.rs | 1 - polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs | 1 - polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs | 1 - substrate/bin/node-template/pallets/template/src/mock.rs | 1 - substrate/bin/node-template/runtime/src/lib.rs | 1 - substrate/bin/node/runtime/src/lib.rs | 2 -- .../client/rpc-spec-v2/src/chain_head/subscription/inner.rs | 2 +- substrate/frame/asset-conversion/src/mock.rs | 1 - substrate/frame/asset-rate/src/mock.rs | 1 - substrate/frame/assets/src/mock.rs | 1 - substrate/frame/atomic-swap/src/tests.rs | 1 - substrate/frame/aura/src/mock.rs | 1 - substrate/frame/authority-discovery/src/lib.rs | 1 - substrate/frame/authorship/src/lib.rs | 1 - substrate/frame/babe/src/mock.rs | 1 - substrate/frame/balances/src/tests/mod.rs | 1 - substrate/frame/beefy-mmr/src/mock.rs | 1 - substrate/frame/beefy/src/mock.rs | 1 - substrate/frame/benchmarking/pov/src/benchmarking.rs | 1 - substrate/frame/benchmarking/pov/src/tests.rs | 1 - substrate/frame/benchmarking/src/baseline.rs | 1 - substrate/frame/benchmarking/src/tests.rs | 1 - substrate/frame/benchmarking/src/tests_instance.rs | 1 - substrate/frame/bounties/src/tests.rs | 1 - substrate/frame/broker/src/mock.rs | 1 - substrate/frame/child-bounties/src/tests.rs | 1 - substrate/frame/collective/src/tests.rs | 1 - substrate/frame/contracts/mock-network/src/parachain.rs | 1 - substrate/frame/contracts/mock-network/src/relay_chain.rs | 1 - substrate/frame/contracts/src/tests.rs | 1 - substrate/frame/conviction-voting/src/tests.rs | 1 - substrate/frame/core-fellowship/src/tests.rs | 1 - substrate/frame/democracy/src/tests.rs | 1 - substrate/frame/election-provider-multi-phase/src/mock.rs | 1 - substrate/frame/election-provider-support/src/onchain.rs | 1 - substrate/frame/elections-phragmen/src/lib.rs | 1 - substrate/frame/examples/basic/src/tests.rs | 1 - substrate/frame/examples/default-config/src/lib.rs | 1 - substrate/frame/examples/dev-mode/src/tests.rs | 1 - substrate/frame/examples/offchain-worker/src/tests.rs | 1 - substrate/frame/examples/tasks/src/mock.rs | 1 - substrate/frame/executive/src/lib.rs | 1 - substrate/frame/glutton/src/mock.rs | 1 - substrate/frame/grandpa/src/mock.rs | 1 - substrate/frame/identity/src/tests.rs | 1 - substrate/frame/im-online/src/mock.rs | 1 - substrate/frame/indices/src/mock.rs | 1 - .../frame/insecure-randomness-collective-flip/src/lib.rs | 1 - substrate/frame/lottery/src/mock.rs | 1 - substrate/frame/membership/src/lib.rs | 1 - substrate/frame/merkle-mountain-range/src/mock.rs | 1 - substrate/frame/message-queue/src/integration_test.rs | 1 - substrate/frame/message-queue/src/mock.rs | 1 - substrate/frame/nft-fractionalization/src/mock.rs | 1 - substrate/frame/nfts/src/mock.rs | 1 - substrate/frame/nicks/src/lib.rs | 1 - substrate/frame/nis/src/mock.rs | 1 - substrate/frame/node-authorization/src/mock.rs | 1 - substrate/frame/nomination-pools/benchmarking/src/mock.rs | 1 - substrate/frame/nomination-pools/src/mock.rs | 1 - substrate/frame/nomination-pools/test-staking/src/mock.rs | 1 - substrate/frame/offences/benchmarking/src/mock.rs | 1 - substrate/frame/offences/src/mock.rs | 1 - substrate/frame/paged-list/src/mock.rs | 1 - substrate/frame/preimage/src/mock.rs | 1 - substrate/frame/ranked-collective/src/tests.rs | 1 - substrate/frame/recovery/src/mock.rs | 1 - substrate/frame/referenda/src/mock.rs | 1 - substrate/frame/remark/src/mock.rs | 1 - substrate/frame/root-offences/src/mock.rs | 1 - substrate/frame/safe-mode/src/mock.rs | 1 - substrate/frame/salary/src/tests.rs | 1 - substrate/frame/scheduler/src/mock.rs | 1 - substrate/frame/scored-pool/src/mock.rs | 1 - substrate/frame/session/benchmarking/src/mock.rs | 1 - substrate/frame/session/src/mock.rs | 1 - substrate/frame/society/src/mock.rs | 1 - substrate/frame/staking/src/mock.rs | 1 - substrate/frame/state-trie-migration/src/lib.rs | 1 - substrate/frame/statement/src/mock.rs | 1 - substrate/frame/sudo/src/mock.rs | 1 - substrate/frame/support/src/dispatch.rs | 1 - substrate/frame/support/src/storage/generator/mod.rs | 1 - substrate/frame/support/src/tests/mod.rs | 1 - substrate/frame/support/test/compile_pass/src/lib.rs | 1 - substrate/frame/support/test/tests/construct_runtime.rs | 1 - .../number_of_pallets_exceeds_tuple_size.rs | 3 +-- .../tests/construct_runtime_ui/pallet_error_too_large.rs | 3 +-- .../test/tests/construct_runtime_ui/undefined_call_part.rs | 3 +-- .../test/tests/construct_runtime_ui/undefined_event_part.rs | 3 +-- .../construct_runtime_ui/undefined_genesis_config_part.rs | 3 +-- .../tests/construct_runtime_ui/undefined_inherent_part.rs | 3 +-- .../tests/construct_runtime_ui/undefined_origin_part.rs | 3 +-- .../undefined_validate_unsigned_part.rs | 3 +-- substrate/frame/support/test/tests/final_keys.rs | 1 - substrate/frame/support/test/tests/genesisconfig.rs | 1 - substrate/frame/support/test/tests/instance.rs | 1 - substrate/frame/support/test/tests/issue2219.rs | 1 - substrate/frame/support/test/tests/origin.rs | 1 - substrate/frame/support/test/tests/pallet.rs | 1 - substrate/frame/support/test/tests/pallet_instance.rs | 1 - .../frame/support/test/tests/pallet_outer_enums_explicit.rs | 1 - .../frame/support/test/tests/pallet_outer_enums_implicit.rs | 1 - .../support/test/tests/pallet_ui/pass/dev_mode_valid.rs | 3 +-- .../test/tests/pallet_ui/pass/no_std_genesis_config.rs | 3 +-- substrate/frame/support/test/tests/runtime_metadata.rs | 1 - substrate/frame/support/test/tests/storage_layers.rs | 1 - substrate/frame/support/test/tests/storage_transaction.rs | 1 - substrate/frame/system/benches/bench.rs | 1 - substrate/frame/system/benchmarking/src/mock.rs | 1 - substrate/frame/system/src/mock.rs | 1 - substrate/frame/system/src/tests.rs | 2 +- substrate/frame/timestamp/src/mock.rs | 1 - substrate/frame/tips/src/tests.rs | 1 - .../asset-conversion-tx-payment/src/mock.rs | 1 - .../frame/transaction-payment/asset-tx-payment/src/mock.rs | 1 - substrate/frame/transaction-payment/src/mock.rs | 1 - substrate/frame/treasury/src/tests.rs | 1 - substrate/frame/tx-pause/src/mock.rs | 1 - substrate/frame/uniques/src/mock.rs | 1 - substrate/frame/utility/src/tests.rs | 1 - substrate/frame/vesting/src/mock.rs | 1 - substrate/frame/whitelist/src/mock.rs | 1 - substrate/primitives/core/src/address_uri.rs | 2 +- substrate/primitives/core/src/crypto.rs | 4 ++-- substrate/test-utils/runtime/src/lib.rs | 1 - 171 files changed, 20 insertions(+), 185 deletions(-) diff --git a/cumulus/pallets/collator-selection/src/mock.rs b/cumulus/pallets/collator-selection/src/mock.rs index a937055abb12..46143674bb39 100644 --- a/cumulus/pallets/collator-selection/src/mock.rs +++ b/cumulus/pallets/collator-selection/src/mock.rs @@ -57,7 +57,6 @@ impl system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/cumulus/pallets/xcmp-queue/src/mock.rs b/cumulus/pallets/xcmp-queue/src/mock.rs index b5e12528e5ef..7c3a3bd1bd02 100644 --- a/cumulus/pallets/xcmp-queue/src/mock.rs +++ b/cumulus/pallets/xcmp-queue/src/mock.rs @@ -62,7 +62,6 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/cumulus/parachain-template/pallets/template/src/mock.rs b/cumulus/parachain-template/pallets/template/src/mock.rs index 2e352b22f6e5..8fae1019f42d 100644 --- a/cumulus/parachain-template/pallets/template/src/mock.rs +++ b/cumulus/parachain-template/pallets/template/src/mock.rs @@ -29,7 +29,6 @@ impl system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index 7d8e7276ed0d..69bb70d21d9f 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -283,7 +283,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/common/src/impls.rs b/cumulus/parachains/common/src/impls.rs index 38401d65fa9e..81d78baba548 100644 --- a/cumulus/parachains/common/src/impls.rs +++ b/cumulus/parachains/common/src/impls.rs @@ -160,7 +160,6 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; diff --git a/cumulus/parachains/pallets/collective-content/src/mock.rs b/cumulus/parachains/pallets/collective-content/src/mock.rs index d30ea7c2e07d..2ae5943f332a 100644 --- a/cumulus/parachains/pallets/collective-content/src/mock.rs +++ b/cumulus/parachains/pallets/collective-content/src/mock.rs @@ -62,7 +62,6 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Block = Block; type Hash = sp_core::H256; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index b60354510af2..4c76262f60a0 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -175,7 +175,6 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index 2e3ccb068c8b..78721b194d03 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -185,7 +185,6 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 1244b4ffd6db..c6c9735ecb1e 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -179,7 +179,6 @@ impl frame_system::Config for Runtime { type Block = Block; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; - type RuntimeTask = RuntimeTask; type BlockHashCount = BlockHashCount; type DbWeight = RocksDbWeight; type Version = Version; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index cfeabf22f389..a0d5a528c3f1 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -156,7 +156,6 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index cfc94fc50f9a..3b37b4b82be6 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -181,7 +181,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 22e309362613..9b9aff5ce190 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -181,7 +181,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index e9eaf92d76e1..b2322a3d533a 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -216,7 +216,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 19c960906f7b..a576b8f33160 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -228,7 +228,6 @@ impl frame_system::Config for Runtime { /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; /// The ubiquitous task type. - type RuntimeTask = RuntimeTask; /// The ubiquitous origin type. type RuntimeOrigin = RuntimeOrigin; /// Maximum number of block number to block hash mappings to keep (oldest pruned first). diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 804beb5458e4..90c44f8bfc55 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -165,7 +165,6 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 1e6db1f06833..54cb898fd6cb 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -166,7 +166,6 @@ impl frame_system::Config for Runtime { type Hashing = BlakeTwo256; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = RocksDbWeight; diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 1c185a779ee6..a7c06103c4aa 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -175,7 +175,6 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Lookup = AccountIdLookup; type Nonce = Nonce; type Hash = Hash; diff --git a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs index b910de3e29b7..ef0734df25fd 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs @@ -176,7 +176,6 @@ impl frame_system::Config for Runtime { type Hashing = BlakeTwo256; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type Version = Version; diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index 04f923964fe9..10f4d5f3307c 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -177,7 +177,6 @@ impl frame_system::Config for Runtime { type Hashing = BlakeTwo256; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type Version = Version; diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index a3a7aa652e83..a0d652ec27ab 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -140,7 +140,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index 8e6003cff929..e7ae2f7c3281 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -149,7 +149,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 00722898dc17..bc78f61490a5 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -329,7 +329,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 39de25e53936..c6411a0d531a 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -190,7 +190,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 8f5e6bbcbe34..3754b5c5cf4b 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -183,7 +183,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = IdentityLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/polkadot/node/core/candidate-validation/src/lib.rs b/polkadot/node/core/candidate-validation/src/lib.rs index 9f7b17f61299..4e02e3e92999 100644 --- a/polkadot/node/core/candidate-validation/src/lib.rs +++ b/polkadot/node/core/candidate-validation/src/lib.rs @@ -764,21 +764,21 @@ trait ValidationBackend { if num_death_retries_left > 0 { num_death_retries_left -= 1; } else { - break; + break }, Err(ValidationError::PossiblyInvalid(PossiblyInvalidError::JobError(_))) => if num_job_error_retries_left > 0 { num_job_error_retries_left -= 1; } else { - break; + break }, Err(ValidationError::Internal(_)) => if num_internal_retries_left > 0 { num_internal_retries_left -= 1; } else { - break; + break }, Ok(_) | Err(ValidationError::Invalid(_) | ValidationError::Preparation(_)) => break, diff --git a/polkadot/node/core/candidate-validation/src/tests.rs b/polkadot/node/core/candidate-validation/src/tests.rs index 110785804652..f646f8535495 100644 --- a/polkadot/node/core/candidate-validation/src/tests.rs +++ b/polkadot/node/core/candidate-validation/src/tests.rs @@ -726,7 +726,7 @@ fn candidate_validation_retry_on_error_helper( ExecutorParams::default(), exec_kind, &Default::default(), - )); + )) } #[test] diff --git a/polkadot/runtime/common/src/assigned_slots/mod.rs b/polkadot/runtime/common/src/assigned_slots/mod.rs index a094d1c1e4cb..cb2e5083b0ac 100644 --- a/polkadot/runtime/common/src/assigned_slots/mod.rs +++ b/polkadot/runtime/common/src/assigned_slots/mod.rs @@ -685,7 +685,6 @@ mod tests { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/common/src/auctions.rs b/polkadot/runtime/common/src/auctions.rs index 840f556d94c0..267413eb1bad 100644 --- a/polkadot/runtime/common/src/auctions.rs +++ b/polkadot/runtime/common/src/auctions.rs @@ -712,7 +712,6 @@ mod tests { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/common/src/claims.rs b/polkadot/runtime/common/src/claims.rs index e4563faffdb9..548adc6fbd5a 100644 --- a/polkadot/runtime/common/src/claims.rs +++ b/polkadot/runtime/common/src/claims.rs @@ -746,7 +746,6 @@ mod tests { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/common/src/crowdloan/mod.rs b/polkadot/runtime/common/src/crowdloan/mod.rs index 593eff4482b7..f67fc12a67f2 100644 --- a/polkadot/runtime/common/src/crowdloan/mod.rs +++ b/polkadot/runtime/common/src/crowdloan/mod.rs @@ -907,7 +907,6 @@ mod tests { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/common/src/impls.rs b/polkadot/runtime/common/src/impls.rs index 35db5ac2d5e3..e50ffb634b30 100644 --- a/polkadot/runtime/common/src/impls.rs +++ b/polkadot/runtime/common/src/impls.rs @@ -242,7 +242,6 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; diff --git a/polkadot/runtime/common/src/integration_tests.rs b/polkadot/runtime/common/src/integration_tests.rs index bcfdb01c6971..793f75e79cd1 100644 --- a/polkadot/runtime/common/src/integration_tests.rs +++ b/polkadot/runtime/common/src/integration_tests.rs @@ -121,7 +121,6 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/common/src/paras_registrar/mod.rs b/polkadot/runtime/common/src/paras_registrar/mod.rs index 52ba088f2364..2d33cf28993d 100644 --- a/polkadot/runtime/common/src/paras_registrar/mod.rs +++ b/polkadot/runtime/common/src/paras_registrar/mod.rs @@ -755,7 +755,6 @@ mod tests { type BaseCallFilter = frame_support::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/common/src/purchase.rs b/polkadot/runtime/common/src/purchase.rs index fafcf0a22bcb..bc95483dd7ed 100644 --- a/polkadot/runtime/common/src/purchase.rs +++ b/polkadot/runtime/common/src/purchase.rs @@ -518,7 +518,6 @@ mod tests { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/common/src/slots/mod.rs b/polkadot/runtime/common/src/slots/mod.rs index f68f6381bb7f..01f6365b791f 100644 --- a/polkadot/runtime/common/src/slots/mod.rs +++ b/polkadot/runtime/common/src/slots/mod.rs @@ -535,7 +535,6 @@ mod tests { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index 305ecd924801..9df54bf29d3e 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -101,7 +101,6 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 8b6ba9c3ead1..12388da1868d 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -193,7 +193,6 @@ impl frame_system::Config for Runtime { type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = Hash; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index cf118b4614c8..596e65eca068 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -146,7 +146,6 @@ impl frame_system::Config for Runtime { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = HashT; type Hashing = BlakeTwo256; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index b8ec16e4da2c..6bbdb2db098c 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -187,7 +187,6 @@ impl frame_system::Config for Runtime { type BlockLength = BlockLength; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = Hash; type Hashing = BlakeTwo256; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index d48941b20c87..9adc706fc18a 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -54,7 +54,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index 4ce6654ea135..710ff0d80192 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -60,7 +60,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/polkadot/xcm/pallet-xcm/src/mock.rs b/polkadot/xcm/pallet-xcm/src/mock.rs index 02be50ae9f14..0b0f795100cd 100644 --- a/polkadot/xcm/pallet-xcm/src/mock.rs +++ b/polkadot/xcm/pallet-xcm/src/mock.rs @@ -249,7 +249,6 @@ parameter_types! { impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; diff --git a/polkadot/xcm/procedural/src/builder_pattern.rs b/polkadot/xcm/procedural/src/builder_pattern.rs index 1cb795ea9b20..badeabb9df82 100644 --- a/polkadot/xcm/procedural/src/builder_pattern.rs +++ b/polkadot/xcm/procedural/src/builder_pattern.rs @@ -149,7 +149,7 @@ fn generate_builder_impl(name: &Ident, data_enum: &DataEnum) -> Result { - return list.path.is_ident("builder"); + return list.path.is_ident("builder") }, _ => false, }); diff --git a/polkadot/xcm/xcm-builder/tests/mock/mod.rs b/polkadot/xcm/xcm-builder/tests/mock/mod.rs index 7fd1fcffdce2..4f183c7a15b6 100644 --- a/polkadot/xcm/xcm-builder/tests/mock/mod.rs +++ b/polkadot/xcm/xcm-builder/tests/mock/mod.rs @@ -79,7 +79,6 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; diff --git a/polkadot/xcm/xcm-simulator/example/src/parachain.rs b/polkadot/xcm/xcm-simulator/example/src/parachain.rs index 9e61eb02c2c4..9f0411970ce7 100644 --- a/polkadot/xcm/xcm-simulator/example/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/parachain.rs @@ -66,7 +66,6 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; diff --git a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs index 2eb3d4cc4eb5..bdd7ff6d3eaf 100644 --- a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs @@ -52,7 +52,6 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs index 8947f747db23..41234837aca0 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -55,7 +55,6 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index 2f643503c2f5..c9a57db970a7 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -51,7 +51,6 @@ parameter_types! { impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; diff --git a/substrate/bin/node-template/pallets/template/src/mock.rs b/substrate/bin/node-template/pallets/template/src/mock.rs index 39c58d03efac..244ae1b37859 100644 --- a/substrate/bin/node-template/pallets/template/src/mock.rs +++ b/substrate/bin/node-template/pallets/template/src/mock.rs @@ -24,7 +24,6 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 20c88cb9ade1..2b0a1c1cea6d 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -167,7 +167,6 @@ impl frame_system::Config for Runtime { /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; /// The aggregated task type that is available for extrinsics. - type RuntimeTask = RuntimeTask; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The type for storing how many extrinsics an account has signed. diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 462660183584..457ea4109b01 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -290,7 +290,6 @@ impl frame_system::Config for Runtime { type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = Hash; type Hashing = BlakeTwo256; @@ -313,7 +312,6 @@ impl frame_system::Config for Runtime { impl pallet_insecure_randomness_collective_flip::Config for Runtime {} impl pallet_example_tasks::Config for Runtime { - type RuntimeTask = RuntimeTask; type WeightInfo = pallet_example_tasks::weights::SubstrateWeight; } diff --git a/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs b/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs index abd42ad96785..2b250f3dc2cf 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs @@ -763,7 +763,7 @@ impl> SubscriptionsInner { // blocks. for hash in hashes.clone() { if !sub.contains_block(hash) { - return Err(SubscriptionManagementError::BlockHashAbsent); + return Err(SubscriptionManagementError::BlockHashAbsent) } } diff --git a/substrate/frame/asset-conversion/src/mock.rs b/substrate/frame/asset-conversion/src/mock.rs index ba3dbf1bb8d1..4eee701f193e 100644 --- a/substrate/frame/asset-conversion/src/mock.rs +++ b/substrate/frame/asset-conversion/src/mock.rs @@ -54,7 +54,6 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/asset-rate/src/mock.rs b/substrate/frame/asset-rate/src/mock.rs index 151db8a6e915..9ca0f0f3cc38 100644 --- a/substrate/frame/asset-rate/src/mock.rs +++ b/substrate/frame/asset-rate/src/mock.rs @@ -42,7 +42,6 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; diff --git a/substrate/frame/assets/src/mock.rs b/substrate/frame/assets/src/mock.rs index fb01ae93503e..2c2203bcdada 100644 --- a/substrate/frame/assets/src/mock.rs +++ b/substrate/frame/assets/src/mock.rs @@ -52,7 +52,6 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/atomic-swap/src/tests.rs b/substrate/frame/atomic-swap/src/tests.rs index 768c2f97798e..92eb9a044585 100644 --- a/substrate/frame/atomic-swap/src/tests.rs +++ b/substrate/frame/atomic-swap/src/tests.rs @@ -47,7 +47,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/aura/src/mock.rs b/substrate/frame/aura/src/mock.rs index fe3479e34f22..39b798c2f684 100644 --- a/substrate/frame/aura/src/mock.rs +++ b/substrate/frame/aura/src/mock.rs @@ -49,7 +49,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/authority-discovery/src/lib.rs b/substrate/frame/authority-discovery/src/lib.rs index 0e6150f3d65f..87b743ae1967 100644 --- a/substrate/frame/authority-discovery/src/lib.rs +++ b/substrate/frame/authority-discovery/src/lib.rs @@ -233,7 +233,6 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AuthorityId; diff --git a/substrate/frame/authorship/src/lib.rs b/substrate/frame/authorship/src/lib.rs index 712f225432a3..56a516894dec 100644 --- a/substrate/frame/authorship/src/lib.rs +++ b/substrate/frame/authorship/src/lib.rs @@ -115,7 +115,6 @@ mod tests { #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type RuntimeTask = RuntimeTask; type Block = Block; } diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index a5fc78847cc9..0003c6f9f11a 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -65,7 +65,6 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type RuntimeTask = RuntimeTask; type Block = Block; type AccountData = pallet_balances::AccountData; } diff --git a/substrate/frame/balances/src/tests/mod.rs b/substrate/frame/balances/src/tests/mod.rs index 61362b467c12..dd3e5b7a85a2 100644 --- a/substrate/frame/balances/src/tests/mod.rs +++ b/substrate/frame/balances/src/tests/mod.rs @@ -98,7 +98,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/beefy-mmr/src/mock.rs b/substrate/frame/beefy-mmr/src/mock.rs index a1603c96ec4f..b85096813dec 100644 --- a/substrate/frame/beefy-mmr/src/mock.rs +++ b/substrate/frame/beefy-mmr/src/mock.rs @@ -59,7 +59,6 @@ construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type RuntimeTask = RuntimeTask; type Block = Block; } diff --git a/substrate/frame/beefy/src/mock.rs b/substrate/frame/beefy/src/mock.rs index fd13b7ef262b..53d523cf724d 100644 --- a/substrate/frame/beefy/src/mock.rs +++ b/substrate/frame/beefy/src/mock.rs @@ -67,7 +67,6 @@ construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type RuntimeTask = RuntimeTask; type Block = Block; type AccountData = pallet_balances::AccountData; } diff --git a/substrate/frame/benchmarking/pov/src/benchmarking.rs b/substrate/frame/benchmarking/pov/src/benchmarking.rs index 1b7f7ca6c59e..473947b171ac 100644 --- a/substrate/frame/benchmarking/pov/src/benchmarking.rs +++ b/substrate/frame/benchmarking/pov/src/benchmarking.rs @@ -368,7 +368,6 @@ mod mock { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/frame/benchmarking/pov/src/tests.rs b/substrate/frame/benchmarking/pov/src/tests.rs index 94aea232c6cf..f09e37a5288a 100644 --- a/substrate/frame/benchmarking/pov/src/tests.rs +++ b/substrate/frame/benchmarking/pov/src/tests.rs @@ -182,7 +182,6 @@ mod mock { type RuntimeOrigin = RuntimeOrigin; type Nonce = u32; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = u32; diff --git a/substrate/frame/benchmarking/src/baseline.rs b/substrate/frame/benchmarking/src/baseline.rs index 55c773a49821..6cd23ebe028a 100644 --- a/substrate/frame/benchmarking/src/baseline.rs +++ b/substrate/frame/benchmarking/src/baseline.rs @@ -138,7 +138,6 @@ pub mod mock { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/frame/benchmarking/src/tests.rs b/substrate/frame/benchmarking/src/tests.rs index 43b48476ed3a..e5bacbdb2361 100644 --- a/substrate/frame/benchmarking/src/tests.rs +++ b/substrate/frame/benchmarking/src/tests.rs @@ -84,7 +84,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/benchmarking/src/tests_instance.rs b/substrate/frame/benchmarking/src/tests_instance.rs index ca8b56e8c902..f2c721c8114c 100644 --- a/substrate/frame/benchmarking/src/tests_instance.rs +++ b/substrate/frame/benchmarking/src/tests_instance.rs @@ -91,7 +91,6 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/bounties/src/tests.rs b/substrate/frame/bounties/src/tests.rs index 5de616922bc5..233e41b474c7 100644 --- a/substrate/frame/bounties/src/tests.rs +++ b/substrate/frame/bounties/src/tests.rs @@ -67,7 +67,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index cfd3368d5f1e..cab6b7389c06 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -54,7 +54,6 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index bc43967428c7..46f8fa65dd37 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -70,7 +70,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; diff --git a/substrate/frame/collective/src/tests.rs b/substrate/frame/collective/src/tests.rs index 0e89ab01bdce..86b85e07a8bd 100644 --- a/substrate/frame/collective/src/tests.rs +++ b/substrate/frame/collective/src/tests.rs @@ -114,7 +114,6 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; - type RuntimeTask = RuntimeTask; } impl Config for Test { type RuntimeOrigin = RuntimeOrigin; diff --git a/substrate/frame/contracts/mock-network/src/parachain.rs b/substrate/frame/contracts/mock-network/src/parachain.rs index 36202e5a6d9a..1465b02f903b 100644 --- a/substrate/frame/contracts/mock-network/src/parachain.rs +++ b/substrate/frame/contracts/mock-network/src/parachain.rs @@ -63,7 +63,6 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; type Lookup = IdentityLookup; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = BlockHashCount; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/contracts/mock-network/src/relay_chain.rs b/substrate/frame/contracts/mock-network/src/relay_chain.rs index 1a239b3a04f3..c59c8e4bfa84 100644 --- a/substrate/frame/contracts/mock-network/src/relay_chain.rs +++ b/substrate/frame/contracts/mock-network/src/relay_chain.rs @@ -57,7 +57,6 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; type Lookup = IdentityLookup; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = BlockHashCount; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/contracts/src/tests.rs b/substrate/frame/contracts/src/tests.rs index 3f62fa5f3c31..76fd012852a9 100644 --- a/substrate/frame/contracts/src/tests.rs +++ b/substrate/frame/contracts/src/tests.rs @@ -341,7 +341,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = AccountId32; type Lookup = IdentityLookup; diff --git a/substrate/frame/conviction-voting/src/tests.rs b/substrate/frame/conviction-voting/src/tests.rs index 128d47d2a65b..850b98b218b0 100644 --- a/substrate/frame/conviction-voting/src/tests.rs +++ b/substrate/frame/conviction-voting/src/tests.rs @@ -59,7 +59,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/core-fellowship/src/tests.rs b/substrate/frame/core-fellowship/src/tests.rs index 25c547a34270..a02c010718c9 100644 --- a/substrate/frame/core-fellowship/src/tests.rs +++ b/substrate/frame/core-fellowship/src/tests.rs @@ -74,7 +74,6 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; - type RuntimeTask = RuntimeTask; } thread_local! { diff --git a/substrate/frame/democracy/src/tests.rs b/substrate/frame/democracy/src/tests.rs index ec26db62db68..07a0ef5c3d5a 100644 --- a/substrate/frame/democracy/src/tests.rs +++ b/substrate/frame/democracy/src/tests.rs @@ -85,7 +85,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/election-provider-multi-phase/src/mock.rs b/substrate/frame/election-provider-multi-phase/src/mock.rs index 837cf1187d94..92144351e8f8 100644 --- a/substrate/frame/election-provider-multi-phase/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/src/mock.rs @@ -210,7 +210,6 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; diff --git a/substrate/frame/election-provider-support/src/onchain.rs b/substrate/frame/election-provider-support/src/onchain.rs index fa875261f201..8ac245a360bb 100644 --- a/substrate/frame/election-provider-support/src/onchain.rs +++ b/substrate/frame/election-provider-support/src/onchain.rs @@ -206,7 +206,6 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = Nonce; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; diff --git a/substrate/frame/elections-phragmen/src/lib.rs b/substrate/frame/elections-phragmen/src/lib.rs index 4384b8985502..e4c56e68f9a5 100644 --- a/substrate/frame/elections-phragmen/src/lib.rs +++ b/substrate/frame/elections-phragmen/src/lib.rs @@ -1329,7 +1329,6 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/examples/basic/src/tests.rs b/substrate/frame/examples/basic/src/tests.rs index 407166135e9d..c7b5b9e9a845 100644 --- a/substrate/frame/examples/basic/src/tests.rs +++ b/substrate/frame/examples/basic/src/tests.rs @@ -53,7 +53,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type Hash = H256; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/examples/default-config/src/lib.rs b/substrate/frame/examples/default-config/src/lib.rs index 283ebf7a74b2..0128dcaf1561 100644 --- a/substrate/frame/examples/default-config/src/lib.rs +++ b/substrate/frame/examples/default-config/src/lib.rs @@ -202,7 +202,6 @@ pub mod tests { type OverwrittenDefaultValue = frame_support::traits::ConstU32<678>; type OverwrittenDefaultType = u128; - type RuntimeTask = RuntimeTask; } #[test] diff --git a/substrate/frame/examples/dev-mode/src/tests.rs b/substrate/frame/examples/dev-mode/src/tests.rs index 962b009d4444..c7722bc05242 100644 --- a/substrate/frame/examples/dev-mode/src/tests.rs +++ b/substrate/frame/examples/dev-mode/src/tests.rs @@ -47,7 +47,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type Hash = H256; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/examples/offchain-worker/src/tests.rs b/substrate/frame/examples/offchain-worker/src/tests.rs index 38e9a48701b2..203a59a8af03 100644 --- a/substrate/frame/examples/offchain-worker/src/tests.rs +++ b/substrate/frame/examples/offchain-worker/src/tests.rs @@ -53,7 +53,6 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/examples/tasks/src/mock.rs b/substrate/frame/examples/tasks/src/mock.rs index e0fbec3eb765..d6aa9240e900 100644 --- a/substrate/frame/examples/tasks/src/mock.rs +++ b/substrate/frame/examples/tasks/src/mock.rs @@ -38,6 +38,5 @@ impl frame_system::Config for Runtime { } impl tasks_example::Config for Runtime { - type RuntimeTask = RuntimeTask; type WeightInfo = (); } diff --git a/substrate/frame/executive/src/lib.rs b/substrate/frame/executive/src/lib.rs index 830e28c05de4..dec1fe158bd6 100644 --- a/substrate/frame/executive/src/lib.rs +++ b/substrate/frame/executive/src/lib.rs @@ -914,7 +914,6 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/glutton/src/mock.rs b/substrate/frame/glutton/src/mock.rs index 90a7a59dca11..4bc40b547887 100644 --- a/substrate/frame/glutton/src/mock.rs +++ b/substrate/frame/glutton/src/mock.rs @@ -47,7 +47,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/grandpa/src/mock.rs b/substrate/frame/grandpa/src/mock.rs index 3fafc4de1620..9afcec1c797a 100644 --- a/substrate/frame/grandpa/src/mock.rs +++ b/substrate/frame/grandpa/src/mock.rs @@ -74,7 +74,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index 1c42c9247eab..78074df933a7 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -55,7 +55,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/im-online/src/mock.rs b/substrate/frame/im-online/src/mock.rs index a9a1350076f2..85da061fe904 100644 --- a/substrate/frame/im-online/src/mock.rs +++ b/substrate/frame/im-online/src/mock.rs @@ -121,7 +121,6 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/indices/src/mock.rs b/substrate/frame/indices/src/mock.rs index 13f861ac473b..7dc6730d34e5 100644 --- a/substrate/frame/indices/src/mock.rs +++ b/substrate/frame/indices/src/mock.rs @@ -42,7 +42,6 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; diff --git a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs index f7119f63a6f9..474087777c46 100644 --- a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs +++ b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs @@ -197,7 +197,6 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/lottery/src/mock.rs b/substrate/frame/lottery/src/mock.rs index 050a76a2d14a..e50ec3441b2e 100644 --- a/substrate/frame/lottery/src/mock.rs +++ b/substrate/frame/lottery/src/mock.rs @@ -55,7 +55,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/membership/src/lib.rs b/substrate/frame/membership/src/lib.rs index f2433a7d70ca..6fb61f0e491b 100644 --- a/substrate/frame/membership/src/lib.rs +++ b/substrate/frame/membership/src/lib.rs @@ -560,7 +560,6 @@ mod tests { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/merkle-mountain-range/src/mock.rs b/substrate/frame/merkle-mountain-range/src/mock.rs index 1dd11ae896ef..d3cb4e570297 100644 --- a/substrate/frame/merkle-mountain-range/src/mock.rs +++ b/substrate/frame/merkle-mountain-range/src/mock.rs @@ -35,7 +35,6 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type RuntimeTask = RuntimeTask; type Block = Block; } diff --git a/substrate/frame/message-queue/src/integration_test.rs b/substrate/frame/message-queue/src/integration_test.rs index e263122c85d0..965b96a99ca5 100644 --- a/substrate/frame/message-queue/src/integration_test.rs +++ b/substrate/frame/message-queue/src/integration_test.rs @@ -66,7 +66,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/message-queue/src/mock.rs b/substrate/frame/message-queue/src/mock.rs index 328a581271c3..55a645743542 100644 --- a/substrate/frame/message-queue/src/mock.rs +++ b/substrate/frame/message-queue/src/mock.rs @@ -52,7 +52,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/nft-fractionalization/src/mock.rs b/substrate/frame/nft-fractionalization/src/mock.rs index a9aa98cbf560..987c65a8954f 100644 --- a/substrate/frame/nft-fractionalization/src/mock.rs +++ b/substrate/frame/nft-fractionalization/src/mock.rs @@ -55,7 +55,6 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/nfts/src/mock.rs b/substrate/frame/nfts/src/mock.rs index 5acbd081a4da..248522aafffc 100644 --- a/substrate/frame/nfts/src/mock.rs +++ b/substrate/frame/nfts/src/mock.rs @@ -52,7 +52,6 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/nicks/src/lib.rs b/substrate/frame/nicks/src/lib.rs index f31b596e57fd..ad30c628adfb 100644 --- a/substrate/frame/nicks/src/lib.rs +++ b/substrate/frame/nicks/src/lib.rs @@ -282,7 +282,6 @@ mod tests { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type Hash = H256; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/nis/src/mock.rs b/substrate/frame/nis/src/mock.rs index 8ae90a9563d5..30f7ef95f331 100644 --- a/substrate/frame/nis/src/mock.rs +++ b/substrate/frame/nis/src/mock.rs @@ -56,7 +56,6 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/node-authorization/src/mock.rs b/substrate/frame/node-authorization/src/mock.rs index f98ae4f1ecb6..84e3336b3bd6 100644 --- a/substrate/frame/node-authorization/src/mock.rs +++ b/substrate/frame/node-authorization/src/mock.rs @@ -67,7 +67,6 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; - type RuntimeTask = RuntimeTask; } ord_parameter_types! { diff --git a/substrate/frame/nomination-pools/benchmarking/src/mock.rs b/substrate/frame/nomination-pools/benchmarking/src/mock.rs index 5fc362110fd5..9a7f2197a7b2 100644 --- a/substrate/frame/nomination-pools/benchmarking/src/mock.rs +++ b/substrate/frame/nomination-pools/benchmarking/src/mock.rs @@ -42,7 +42,6 @@ impl frame_system::Config for Runtime { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/frame/nomination-pools/src/mock.rs b/substrate/frame/nomination-pools/src/mock.rs index 0abfdc0ad581..24bea0b87f22 100644 --- a/substrate/frame/nomination-pools/src/mock.rs +++ b/substrate/frame/nomination-pools/src/mock.rs @@ -215,7 +215,6 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; diff --git a/substrate/frame/nomination-pools/test-staking/src/mock.rs b/substrate/frame/nomination-pools/test-staking/src/mock.rs index 6137ddb97de0..0db24e9c2441 100644 --- a/substrate/frame/nomination-pools/test-staking/src/mock.rs +++ b/substrate/frame/nomination-pools/test-staking/src/mock.rs @@ -46,7 +46,6 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = Nonce; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = sp_core::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; diff --git a/substrate/frame/offences/benchmarking/src/mock.rs b/substrate/frame/offences/benchmarking/src/mock.rs index 03b7dd6c04e2..1a458ec90d58 100644 --- a/substrate/frame/offences/benchmarking/src/mock.rs +++ b/substrate/frame/offences/benchmarking/src/mock.rs @@ -54,7 +54,6 @@ impl frame_system::Config for Test { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/frame/offences/src/mock.rs b/substrate/frame/offences/src/mock.rs index 0c6ba68fdd4e..990ceae5ac01 100644 --- a/substrate/frame/offences/src/mock.rs +++ b/substrate/frame/offences/src/mock.rs @@ -82,7 +82,6 @@ impl frame_system::Config for Runtime { type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/paged-list/src/mock.rs b/substrate/frame/paged-list/src/mock.rs index d92067601856..390b4a8530dc 100644 --- a/substrate/frame/paged-list/src/mock.rs +++ b/substrate/frame/paged-list/src/mock.rs @@ -45,7 +45,6 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/preimage/src/mock.rs b/substrate/frame/preimage/src/mock.rs index 0a52bde8503b..0f966312d9e7 100644 --- a/substrate/frame/preimage/src/mock.rs +++ b/substrate/frame/preimage/src/mock.rs @@ -49,7 +49,6 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; diff --git a/substrate/frame/ranked-collective/src/tests.rs b/substrate/frame/ranked-collective/src/tests.rs index b491dc6756d7..ba8c5a0f937b 100644 --- a/substrate/frame/ranked-collective/src/tests.rs +++ b/substrate/frame/ranked-collective/src/tests.rs @@ -69,7 +69,6 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; - type RuntimeTask = RuntimeTask; } #[derive(Clone, PartialEq, Eq, Debug)] diff --git a/substrate/frame/recovery/src/mock.rs b/substrate/frame/recovery/src/mock.rs index 6fb552f2243a..bc81d07bec23 100644 --- a/substrate/frame/recovery/src/mock.rs +++ b/substrate/frame/recovery/src/mock.rs @@ -47,7 +47,6 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; diff --git a/substrate/frame/referenda/src/mock.rs b/substrate/frame/referenda/src/mock.rs index f501898a2749..345accbe268f 100644 --- a/substrate/frame/referenda/src/mock.rs +++ b/substrate/frame/referenda/src/mock.rs @@ -67,7 +67,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/remark/src/mock.rs b/substrate/frame/remark/src/mock.rs index 367cc0d16936..e597a1ca4dfe 100644 --- a/substrate/frame/remark/src/mock.rs +++ b/substrate/frame/remark/src/mock.rs @@ -41,7 +41,6 @@ impl frame_system::Config for Test { type BlockWeights = (); type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; diff --git a/substrate/frame/root-offences/src/mock.rs b/substrate/frame/root-offences/src/mock.rs index b26c607c9241..82da429e00a5 100644 --- a/substrate/frame/root-offences/src/mock.rs +++ b/substrate/frame/root-offences/src/mock.rs @@ -93,7 +93,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/safe-mode/src/mock.rs b/substrate/frame/safe-mode/src/mock.rs index e3caa70c98ae..10afe5bd4b5e 100644 --- a/substrate/frame/safe-mode/src/mock.rs +++ b/substrate/frame/safe-mode/src/mock.rs @@ -39,7 +39,6 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/salary/src/tests.rs b/substrate/frame/salary/src/tests.rs index 928aeb2890ff..1136ea746f60 100644 --- a/substrate/frame/salary/src/tests.rs +++ b/substrate/frame/salary/src/tests.rs @@ -73,7 +73,6 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; - type RuntimeTask = RuntimeTask; } thread_local! { diff --git a/substrate/frame/scheduler/src/mock.rs b/substrate/frame/scheduler/src/mock.rs index 1c66456bc7de..b6eb1d044fa2 100644 --- a/substrate/frame/scheduler/src/mock.rs +++ b/substrate/frame/scheduler/src/mock.rs @@ -125,7 +125,6 @@ impl system::Config for Test { type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/scored-pool/src/mock.rs b/substrate/frame/scored-pool/src/mock.rs index d4f929e3a9be..32a66c0cdc5c 100644 --- a/substrate/frame/scored-pool/src/mock.rs +++ b/substrate/frame/scored-pool/src/mock.rs @@ -59,7 +59,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type Hash = H256; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/session/benchmarking/src/mock.rs b/substrate/frame/session/benchmarking/src/mock.rs index 3c4e81090e78..47c337569a02 100644 --- a/substrate/frame/session/benchmarking/src/mock.rs +++ b/substrate/frame/session/benchmarking/src/mock.rs @@ -59,7 +59,6 @@ impl frame_system::Config for Test { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/frame/session/src/mock.rs b/substrate/frame/session/src/mock.rs index 2dce98710a71..2db54e1a5975 100644 --- a/substrate/frame/session/src/mock.rs +++ b/substrate/frame/session/src/mock.rs @@ -240,7 +240,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/society/src/mock.rs b/substrate/frame/society/src/mock.rs index f6058bfbedaf..0bee08236f74 100644 --- a/substrate/frame/society/src/mock.rs +++ b/substrate/frame/society/src/mock.rs @@ -67,7 +67,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u128; type Lookup = IdentityLookup; diff --git a/substrate/frame/staking/src/mock.rs b/substrate/frame/staking/src/mock.rs index f865f100fb72..364d125792b8 100644 --- a/substrate/frame/staking/src/mock.rs +++ b/substrate/frame/staking/src/mock.rs @@ -132,7 +132,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = Nonce; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index f20a82ccd55f..ac3996459cd4 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -1086,7 +1086,6 @@ mod mock { type BlockWeights = (); type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; diff --git a/substrate/frame/statement/src/mock.rs b/substrate/frame/statement/src/mock.rs index 743d0dd78730..10a74e100df8 100644 --- a/substrate/frame/statement/src/mock.rs +++ b/substrate/frame/statement/src/mock.rs @@ -53,7 +53,6 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = RocksDbWeight; type RuntimeOrigin = RuntimeOrigin; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; diff --git a/substrate/frame/sudo/src/mock.rs b/substrate/frame/sudo/src/mock.rs index 54d105dabe5d..6f123b7c82b2 100644 --- a/substrate/frame/sudo/src/mock.rs +++ b/substrate/frame/sudo/src/mock.rs @@ -132,7 +132,6 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; - type RuntimeTask = RuntimeTask; } // Implement the logger module's `Config` on the Test runtime. diff --git a/substrate/frame/support/src/dispatch.rs b/substrate/frame/support/src/dispatch.rs index 04ca0c3aacb5..78858dc6634d 100644 --- a/substrate/frame/support/src/dispatch.rs +++ b/substrate/frame/support/src/dispatch.rs @@ -791,7 +791,6 @@ mod weight_tests { type BaseCallFilter = crate::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type DbWeight = DbWeight; type PalletInfo = PalletInfo; } diff --git a/substrate/frame/support/src/storage/generator/mod.rs b/substrate/frame/support/src/storage/generator/mod.rs index dd6d622852db..d21519ee0d85 100644 --- a/substrate/frame/support/src/storage/generator/mod.rs +++ b/substrate/frame/support/src/storage/generator/mod.rs @@ -130,7 +130,6 @@ mod tests { type BaseCallFilter = crate::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type PalletInfo = PalletInfo; type DbWeight = (); } diff --git a/substrate/frame/support/src/tests/mod.rs b/substrate/frame/support/src/tests/mod.rs index 2b71b2fcf568..dc8f78d64ae8 100644 --- a/substrate/frame/support/src/tests/mod.rs +++ b/substrate/frame/support/src/tests/mod.rs @@ -231,7 +231,6 @@ crate::construct_runtime!( impl Config for Runtime { type Block = Block; type AccountId = AccountId; - type RuntimeTask = RuntimeTask; } fn new_test_ext() -> TestExternalities { diff --git a/substrate/frame/support/test/compile_pass/src/lib.rs b/substrate/frame/support/test/compile_pass/src/lib.rs index 93ae59a13d8a..6ea37fb27e72 100644 --- a/substrate/frame/support/test/compile_pass/src/lib.rs +++ b/substrate/frame/support/test/compile_pass/src/lib.rs @@ -68,7 +68,6 @@ impl renamed_frame_system::Config for Runtime { type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type DbWeight = (); type OnNewAccount = (); type OnKilledAccount = (); diff --git a/substrate/frame/support/test/tests/construct_runtime.rs b/substrate/frame/support/test/tests/construct_runtime.rs index fdf60ccf31b4..b8341b25cb09 100644 --- a/substrate/frame/support/test/tests/construct_runtime.rs +++ b/substrate/frame/support/test/tests/construct_runtime.rs @@ -282,7 +282,6 @@ impl frame_system::Config for Runtime { type BaseCallFilter = frame_support::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs index f0a65707e147..a8a77a53d7b5 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs @@ -47,8 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs index 694ec4354f1b..e93950dfefe8 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs @@ -72,8 +72,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs index 383645a32316..bc2d7b3b584b 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs @@ -47,8 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs index b98dc0a6df24..98f39e6912e7 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs @@ -47,8 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs index 44ec3fd7c110..d672e1c24a68 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs @@ -47,8 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs index e6a1177e3ea3..f426d0922919 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs @@ -47,8 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs index 66e487642041..d786f00281ce 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs @@ -47,8 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs index ed3f4a3e0683..6075321d48a6 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs @@ -47,8 +47,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/final_keys.rs b/substrate/frame/support/test/tests/final_keys.rs index 8989e8da69a2..765afaf1e660 100644 --- a/substrate/frame/support/test/tests/final_keys.rs +++ b/substrate/frame/support/test/tests/final_keys.rs @@ -217,7 +217,6 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/genesisconfig.rs b/substrate/frame/support/test/tests/genesisconfig.rs index cf10a0f762ba..c6781220692a 100644 --- a/substrate/frame/support/test/tests/genesisconfig.rs +++ b/substrate/frame/support/test/tests/genesisconfig.rs @@ -86,7 +86,6 @@ impl frame_system::Config for Test { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/instance.rs b/substrate/frame/support/test/tests/instance.rs index ea8e52747434..43a93df9dea4 100644 --- a/substrate/frame/support/test/tests/instance.rs +++ b/substrate/frame/support/test/tests/instance.rs @@ -306,7 +306,6 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/issue2219.rs b/substrate/frame/support/test/tests/issue2219.rs index 7373d70fe574..4016707b51a8 100644 --- a/substrate/frame/support/test/tests/issue2219.rs +++ b/substrate/frame/support/test/tests/issue2219.rs @@ -168,7 +168,6 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU64<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/origin.rs b/substrate/frame/support/test/tests/origin.rs index fedeb344a139..5682bb500c7e 100644 --- a/substrate/frame/support/test/tests/origin.rs +++ b/substrate/frame/support/test/tests/origin.rs @@ -177,7 +177,6 @@ impl frame_system::Config for RuntimeOriginTest { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index b4951a2ef8a2..00e7adafb0b7 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -693,7 +693,6 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = ConstU32<250>; type BlockWeights = (); type BlockLength = (); diff --git a/substrate/frame/support/test/tests/pallet_instance.rs b/substrate/frame/support/test/tests/pallet_instance.rs index 6470882d97bd..724734ec4fc9 100644 --- a/substrate/frame/support/test/tests/pallet_instance.rs +++ b/substrate/frame/support/test/tests/pallet_instance.rs @@ -297,7 +297,6 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = sp_runtime::testing::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = u64; 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 c90c5ecf6971..6246ad93d678 100644 --- a/substrate/frame/support/test/tests/pallet_outer_enums_explicit.rs +++ b/substrate/frame/support/test/tests/pallet_outer_enums_explicit.rs @@ -32,7 +32,6 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); 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 ed08bf66287e..26023dfa7b72 100644 --- a/substrate/frame/support/test/tests/pallet_outer_enums_implicit.rs +++ b/substrate/frame/support/test/tests/pallet_outer_enums_implicit.rs @@ -32,7 +32,6 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs b/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs index 1ff83e9d186d..4b679df76058 100644 --- a/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs +++ b/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs @@ -81,8 +81,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = ConstU32<250>; + type BlockHashCount = ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs b/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs index 1943a4809770..a99ceadcee12 100644 --- a/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs +++ b/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs @@ -38,8 +38,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/runtime_metadata.rs b/substrate/frame/support/test/tests/runtime_metadata.rs index debdce9289ff..a545735f2b1e 100644 --- a/substrate/frame/support/test/tests/runtime_metadata.rs +++ b/substrate/frame/support/test/tests/runtime_metadata.rs @@ -35,7 +35,6 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = sp_runtime::testing::H256; type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/support/test/tests/storage_layers.rs b/substrate/frame/support/test/tests/storage_layers.rs index 34230af622fa..b825c85f9564 100644 --- a/substrate/frame/support/test/tests/storage_layers.rs +++ b/substrate/frame/support/test/tests/storage_layers.rs @@ -70,7 +70,6 @@ impl frame_system::Config for Runtime { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = sp_runtime::testing::H256; type Hashing = sp_runtime::traits::BlakeTwo256; diff --git a/substrate/frame/support/test/tests/storage_transaction.rs b/substrate/frame/support/test/tests/storage_transaction.rs index 7a61a44714b3..c47743308609 100644 --- a/substrate/frame/support/test/tests/storage_transaction.rs +++ b/substrate/frame/support/test/tests/storage_transaction.rs @@ -95,7 +95,6 @@ impl frame_system::Config for Runtime { type BlockHashCount = ConstU32<10>; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type RuntimeEvent = RuntimeEvent; type PalletInfo = PalletInfo; type OnSetCode = (); diff --git a/substrate/frame/system/benches/bench.rs b/substrate/frame/system/benches/bench.rs index 6061fef6ae6e..da8bb10fd4e4 100644 --- a/substrate/frame/system/benches/bench.rs +++ b/substrate/frame/system/benches/bench.rs @@ -81,7 +81,6 @@ impl frame_system::Config for Runtime { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; - type RuntimeTask = RuntimeTask; } impl module::Config for Runtime { diff --git a/substrate/frame/system/benchmarking/src/mock.rs b/substrate/frame/system/benchmarking/src/mock.rs index 140fb58bbfa2..4e6b1221da35 100644 --- a/substrate/frame/system/benchmarking/src/mock.rs +++ b/substrate/frame/system/benchmarking/src/mock.rs @@ -48,7 +48,6 @@ impl frame_system::Config for Test { type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type RuntimeTask = RuntimeTask; type BlockHashCount = (); type Version = (); type PalletInfo = PalletInfo; diff --git a/substrate/frame/system/src/mock.rs b/substrate/frame/system/src/mock.rs index 670dbb266b03..c016ea9e1cd1 100644 --- a/substrate/frame/system/src/mock.rs +++ b/substrate/frame/system/src/mock.rs @@ -91,7 +91,6 @@ impl Config for Test { type BlockLength = RuntimeBlockLength; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/system/src/tests.rs b/substrate/frame/system/src/tests.rs index 6fbddaaf2294..e1432725d5c8 100644 --- a/substrate/frame/system/src/tests.rs +++ b/substrate/frame/system/src/tests.rs @@ -788,7 +788,7 @@ fn last_runtime_upgrade_spec_version_usage() { // a runtime upgrade in the pipeline of being applied, you should use the spec version // of this upgrade. if System::last_runtime_upgrade_spec_version() > 1337 { - return Weight::zero(); + return Weight::zero() } // Do the migration. diff --git a/substrate/frame/timestamp/src/mock.rs b/substrate/frame/timestamp/src/mock.rs index f56b5eaab445..418d257b3f00 100644 --- a/substrate/frame/timestamp/src/mock.rs +++ b/substrate/frame/timestamp/src/mock.rs @@ -50,7 +50,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/substrate/frame/tips/src/tests.rs b/substrate/frame/tips/src/tests.rs index a37b994b139f..189623b520eb 100644 --- a/substrate/frame/tips/src/tests.rs +++ b/substrate/frame/tips/src/tests.rs @@ -64,7 +64,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account diff --git a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs index c60935673f00..76c78fb42223 100644 --- a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs @@ -86,7 +86,6 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; diff --git a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs index 93e52c812c48..5fa8a4ab27dd 100644 --- a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs @@ -78,7 +78,6 @@ impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; diff --git a/substrate/frame/transaction-payment/src/mock.rs b/substrate/frame/transaction-payment/src/mock.rs index d42c0c08f2c5..419989bef12a 100644 --- a/substrate/frame/transaction-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/src/mock.rs @@ -76,7 +76,6 @@ impl frame_system::Config for Runtime { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/treasury/src/tests.rs b/substrate/frame/treasury/src/tests.rs index d1f0290b5305..522ecf6b18fc 100644 --- a/substrate/frame/treasury/src/tests.rs +++ b/substrate/frame/treasury/src/tests.rs @@ -62,7 +62,6 @@ impl frame_system::Config for Test { type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account diff --git a/substrate/frame/tx-pause/src/mock.rs b/substrate/frame/tx-pause/src/mock.rs index 27fdd393d19a..66218c8c015c 100644 --- a/substrate/frame/tx-pause/src/mock.rs +++ b/substrate/frame/tx-pause/src/mock.rs @@ -42,7 +42,6 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; diff --git a/substrate/frame/uniques/src/mock.rs b/substrate/frame/uniques/src/mock.rs index 52f3da87e906..1f62c3c4e93b 100644 --- a/substrate/frame/uniques/src/mock.rs +++ b/substrate/frame/uniques/src/mock.rs @@ -46,7 +46,6 @@ impl frame_system::Config for Test { type BlockWeights = (); type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type Nonce = u64; type Hash = H256; diff --git a/substrate/frame/utility/src/tests.rs b/substrate/frame/utility/src/tests.rs index 8d6df0daa721..01e3f5264bff 100644 --- a/substrate/frame/utility/src/tests.rs +++ b/substrate/frame/utility/src/tests.rs @@ -153,7 +153,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/frame/vesting/src/mock.rs b/substrate/frame/vesting/src/mock.rs index 29e92241f3c0..13d6d5ba57a6 100644 --- a/substrate/frame/vesting/src/mock.rs +++ b/substrate/frame/vesting/src/mock.rs @@ -46,7 +46,6 @@ impl frame_system::Config for Test { type BlockHashCount = ConstU64<250>; type BlockLength = (); type BlockWeights = (); - type RuntimeTask = RuntimeTask; type RuntimeCall = RuntimeCall; type DbWeight = (); type RuntimeEvent = RuntimeEvent; diff --git a/substrate/frame/whitelist/src/mock.rs b/substrate/frame/whitelist/src/mock.rs index 935d4ef9c0ab..4e70a503c280 100644 --- a/substrate/frame/whitelist/src/mock.rs +++ b/substrate/frame/whitelist/src/mock.rs @@ -53,7 +53,6 @@ impl frame_system::Config for Test { type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; diff --git a/substrate/primitives/core/src/address_uri.rs b/substrate/primitives/core/src/address_uri.rs index 862747c9a4b6..211d47c0093d 100644 --- a/substrate/primitives/core/src/address_uri.rs +++ b/substrate/primitives/core/src/address_uri.rs @@ -184,7 +184,7 @@ impl<'a> AddressUri<'a> { Error::in_pass(initial_input, initial_input_len - input.len()) } else { Error::in_phrase(initial_input, initial_input_len - input.len()) - }); + }) } } diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index c9719e344d3e..211ddc2aba0a 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -434,7 +434,7 @@ impl + AsRef<[u8]> + Public + Derive> Ss58Codec for T { fn from_string(s: &str) -> Result { let cap = AddressUri::parse(s)?; if cap.pass.is_some() { - return Err(PublicError::PasswordNotAllowed); + return Err(PublicError::PasswordNotAllowed) } let s = cap.phrase.unwrap_or(DEV_ADDRESS); let addr = if let Some(stripped) = s.strip_prefix("0x") { @@ -454,7 +454,7 @@ impl + AsRef<[u8]> + Public + Derive> Ss58Codec for T { fn from_string_with_version(s: &str) -> Result<(Self, Ss58AddressFormat), PublicError> { let cap = AddressUri::parse(s)?; if cap.pass.is_some() { - return Err(PublicError::PasswordNotAllowed); + return Err(PublicError::PasswordNotAllowed) } let (addr, v) = Self::from_ss58check_with_version(cap.phrase.unwrap_or(DEV_ADDRESS))?; if cap.paths.is_empty() { diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 2ce94112162d..1a4e9fd04667 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -348,7 +348,6 @@ impl frame_system::pallet::Config for Runtime { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; type Nonce = Nonce; type Hash = H256; type Hashing = Hashing; From 5ff01c56afc63c381c742e6951ce4380106aa3f3 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 5 Dec 2023 05:12:37 +0000 Subject: [PATCH 152/177] ".git/.scripts/commands/fmt/fmt.sh" --- polkadot/xcm/procedural/src/builder_pattern.rs | 4 +--- substrate/client/authority-discovery/Cargo.toml | 10 +++++----- substrate/frame/examples/tasks/Cargo.toml | 14 +++++++------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/polkadot/xcm/procedural/src/builder_pattern.rs b/polkadot/xcm/procedural/src/builder_pattern.rs index badeabb9df82..fcb84b4dbe3f 100644 --- a/polkadot/xcm/procedural/src/builder_pattern.rs +++ b/polkadot/xcm/procedural/src/builder_pattern.rs @@ -148,9 +148,7 @@ fn generate_builder_impl(name: &Ident, data_enum: &DataEnum) -> Result { - return list.path.is_ident("builder") - }, + Meta::List(ref list) => return list.path.is_ident("builder"), _ => false, }); let builder_attr = match maybe_builder_attr { diff --git a/substrate/client/authority-discovery/Cargo.toml b/substrate/client/authority-discovery/Cargo.toml index 1a4b23d3c6d2..40c2162c7996 100644 --- a/substrate/client/authority-discovery/Cargo.toml +++ b/substrate/client/authority-discovery/Cargo.toml @@ -23,8 +23,8 @@ futures-timer = "3.0.1" ip_network = "0.4.1" libp2p = { version = "0.51.3", features = ["ed25519", "kad"] } multihash = { version = "0.18.1", default-features = false, features = [ - "sha2", - "std", + "sha2", + "std", ] } log = "0.4.17" prost = "0.11" @@ -41,9 +41,9 @@ sp-keystore = { path = "../../primitives/keystore" } sp-runtime = { path = "../../primitives/runtime" } async-trait = "0.1.56" multihash-codetable = { version = "0.1.1", features = [ - "serde", - "sha2", - "digest", + "digest", + "serde", + "sha2", ] } [dev-dependencies] diff --git a/substrate/frame/examples/tasks/Cargo.toml b/substrate/frame/examples/tasks/Cargo.toml index 21822c39ee79..e26e822e40f6 100644 --- a/substrate/frame/examples/tasks/Cargo.toml +++ b/substrate/frame/examples/tasks/Cargo.toml @@ -15,18 +15,18 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features = log = { version = "0.4.17", default-features = false } scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } -frame-support = { path = "../../support", default-features = false} -frame-system = { path = "../../system", default-features = false} +frame-support = { path = "../../support", default-features = false } +frame-system = { path = "../../system", default-features = false } -sp-io = { path = "../../../primitives/io", default-features = false} -sp-runtime = { path = "../../../primitives/runtime", default-features = false} -sp-std = { path = "../../../primitives/std", default-features = false} +sp-io = { path = "../../../primitives/io", default-features = false } +sp-runtime = { path = "../../../primitives/runtime", default-features = false } +sp-std = { path = "../../../primitives/std", default-features = false } sp-core = { version = "21.0.0", default-features = false, path = "../../../primitives/core" } -frame-benchmarking = { path = "../../benchmarking", default-features = false, optional = true} +frame-benchmarking = { path = "../../benchmarking", default-features = false, optional = true } [features] -default = [ "std" ] +default = ["std"] std = [ "codec/std", "frame-benchmarking?/std", From 8f947722e645a825d5421a3833b67be10f16e0e3 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:27:46 +0530 Subject: [PATCH 153/177] Removes unnecessary changes --- .../parachains/runtimes/starters/seedling/src/lib.rs | 1 - cumulus/parachains/runtimes/starters/shell/src/lib.rs | 1 - cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 1 - .../runtimes/testing/rococo-parachain/src/lib.rs | 1 - polkadot/node/core/candidate-validation/src/lib.rs | 6 +++--- polkadot/node/core/candidate-validation/src/tests.rs | 2 +- polkadot/xcm/procedural/src/builder_pattern.rs | 4 +++- substrate/client/authority-discovery/Cargo.toml | 10 +++++----- .../construct_runtime_ui/pallet_error_too_large.rs | 2 +- .../tests/construct_runtime_ui/undefined_call_part.rs | 2 +- .../tests/construct_runtime_ui/undefined_event_part.rs | 2 +- .../undefined_genesis_config_part.rs | 2 +- .../construct_runtime_ui/undefined_inherent_part.rs | 2 +- .../construct_runtime_ui/undefined_origin_part.rs | 2 +- .../undefined_validate_unsigned_part.rs | 2 +- .../test/tests/pallet_ui/pass/dev_mode_valid.rs | 2 +- .../test/tests/pallet_ui/pass/no_std_genesis_config.rs | 2 +- substrate/frame/system/src/tests.rs | 2 +- substrate/primitives/core/src/address_uri.rs | 2 +- substrate/primitives/core/src/crypto.rs | 4 ++-- substrate/utils/wasm-builder/src/wasm_project.rs | 2 +- 21 files changed, 26 insertions(+), 28 deletions(-) diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index 1a4f442e29c9..cb868627e799 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -141,7 +141,6 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; - /// The aggregated task type. /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index 73438cf64d39..de95969f71d1 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -149,7 +149,6 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; - /// The aggregated task type. /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index ee424fdda163..9387c454715f 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -329,7 +329,6 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; - /// The aggregated task type. /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 1fe31f2249b9..9d2ba98a67c4 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -190,7 +190,6 @@ impl frame_system::Config for Runtime { type AccountId = AccountId; /// The aggregated dispatch type that is available for extrinsics. type RuntimeCall = RuntimeCall; - /// The aggregated task type. /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. diff --git a/polkadot/node/core/candidate-validation/src/lib.rs b/polkadot/node/core/candidate-validation/src/lib.rs index 4e02e3e92999..9f7b17f61299 100644 --- a/polkadot/node/core/candidate-validation/src/lib.rs +++ b/polkadot/node/core/candidate-validation/src/lib.rs @@ -764,21 +764,21 @@ trait ValidationBackend { if num_death_retries_left > 0 { num_death_retries_left -= 1; } else { - break + break; }, Err(ValidationError::PossiblyInvalid(PossiblyInvalidError::JobError(_))) => if num_job_error_retries_left > 0 { num_job_error_retries_left -= 1; } else { - break + break; }, Err(ValidationError::Internal(_)) => if num_internal_retries_left > 0 { num_internal_retries_left -= 1; } else { - break + break; }, Ok(_) | Err(ValidationError::Invalid(_) | ValidationError::Preparation(_)) => break, diff --git a/polkadot/node/core/candidate-validation/src/tests.rs b/polkadot/node/core/candidate-validation/src/tests.rs index f646f8535495..110785804652 100644 --- a/polkadot/node/core/candidate-validation/src/tests.rs +++ b/polkadot/node/core/candidate-validation/src/tests.rs @@ -726,7 +726,7 @@ fn candidate_validation_retry_on_error_helper( ExecutorParams::default(), exec_kind, &Default::default(), - )) + )); } #[test] diff --git a/polkadot/xcm/procedural/src/builder_pattern.rs b/polkadot/xcm/procedural/src/builder_pattern.rs index fcb84b4dbe3f..1cb795ea9b20 100644 --- a/polkadot/xcm/procedural/src/builder_pattern.rs +++ b/polkadot/xcm/procedural/src/builder_pattern.rs @@ -148,7 +148,9 @@ fn generate_builder_impl(name: &Ident, data_enum: &DataEnum) -> Result return list.path.is_ident("builder"), + Meta::List(ref list) => { + return list.path.is_ident("builder"); + }, _ => false, }); let builder_attr = match maybe_builder_attr { diff --git a/substrate/client/authority-discovery/Cargo.toml b/substrate/client/authority-discovery/Cargo.toml index 40c2162c7996..3351e1d9cca0 100644 --- a/substrate/client/authority-discovery/Cargo.toml +++ b/substrate/client/authority-discovery/Cargo.toml @@ -23,8 +23,8 @@ futures-timer = "3.0.1" ip_network = "0.4.1" libp2p = { version = "0.51.3", features = ["ed25519", "kad"] } multihash = { version = "0.18.1", default-features = false, features = [ - "sha2", - "std", + "sha2", + "std", ] } log = "0.4.17" prost = "0.11" @@ -41,9 +41,9 @@ sp-keystore = { path = "../../primitives/keystore" } sp-runtime = { path = "../../primitives/runtime" } async-trait = "0.1.56" multihash-codetable = { version = "0.1.1", features = [ - "digest", - "serde", - "sha2", + "digest", + "serde", + "sha2", ] } [dev-dependencies] diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs index 996d8ed6bd50..d3e519af5515 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs @@ -73,7 +73,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs index ff8ba31b5739..8193d12120c9 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_call_part.rs @@ -48,7 +48,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs index d5a2c2bb5cd9..ef3a790b61a1 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_event_part.rs @@ -48,7 +48,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs index 1f0afac1facc..b4dd41750c88 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_genesis_config_part.rs @@ -48,7 +48,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs index 79f38b2eded0..5e0b8f3c44f5 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_inherent_part.rs @@ -48,7 +48,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs index 6c099760703a..40a4a1ebcb5d 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_origin_part.rs @@ -48,7 +48,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs index c0554ecc66c9..be9e4ac2c30d 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/undefined_validate_unsigned_part.rs @@ -48,7 +48,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs b/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs index a617fc5b6d8b..4dc33991b126 100644 --- a/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs +++ b/substrate/frame/support/test/tests/pallet_ui/pass/dev_mode_valid.rs @@ -82,7 +82,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU32<250>; + type BlockHashCount = ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs b/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs index e494f186d274..de856ddcd3e9 100644 --- a/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs +++ b/substrate/frame/support/test/tests/pallet_ui/pass/no_std_genesis_config.rs @@ -39,7 +39,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/substrate/frame/system/src/tests.rs b/substrate/frame/system/src/tests.rs index e1432725d5c8..6fbddaaf2294 100644 --- a/substrate/frame/system/src/tests.rs +++ b/substrate/frame/system/src/tests.rs @@ -788,7 +788,7 @@ fn last_runtime_upgrade_spec_version_usage() { // a runtime upgrade in the pipeline of being applied, you should use the spec version // of this upgrade. if System::last_runtime_upgrade_spec_version() > 1337 { - return Weight::zero() + return Weight::zero(); } // Do the migration. diff --git a/substrate/primitives/core/src/address_uri.rs b/substrate/primitives/core/src/address_uri.rs index 211d47c0093d..862747c9a4b6 100644 --- a/substrate/primitives/core/src/address_uri.rs +++ b/substrate/primitives/core/src/address_uri.rs @@ -184,7 +184,7 @@ impl<'a> AddressUri<'a> { Error::in_pass(initial_input, initial_input_len - input.len()) } else { Error::in_phrase(initial_input, initial_input_len - input.len()) - }) + }); } } diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index 211ddc2aba0a..c9719e344d3e 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -434,7 +434,7 @@ impl + AsRef<[u8]> + Public + Derive> Ss58Codec for T { fn from_string(s: &str) -> Result { let cap = AddressUri::parse(s)?; if cap.pass.is_some() { - return Err(PublicError::PasswordNotAllowed) + return Err(PublicError::PasswordNotAllowed); } let s = cap.phrase.unwrap_or(DEV_ADDRESS); let addr = if let Some(stripped) = s.strip_prefix("0x") { @@ -454,7 +454,7 @@ impl + AsRef<[u8]> + Public + Derive> Ss58Codec for T { fn from_string_with_version(s: &str) -> Result<(Self, Ss58AddressFormat), PublicError> { let cap = AddressUri::parse(s)?; if cap.pass.is_some() { - return Err(PublicError::PasswordNotAllowed) + return Err(PublicError::PasswordNotAllowed); } let (addr, v) = Self::from_ss58check_with_version(cap.phrase.unwrap_or(DEV_ADDRESS))?; if cap.paths.is_empty() { diff --git a/substrate/utils/wasm-builder/src/wasm_project.rs b/substrate/utils/wasm-builder/src/wasm_project.rs index 2126a49bd7ff..5bf44c2c9b20 100644 --- a/substrate/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/utils/wasm-builder/src/wasm_project.rs @@ -935,7 +935,7 @@ fn generate_rerun_if_changed_instructions( while let Some(dependency) = dependencies.pop() { // Ignore all dev dependencies if dependency.kind == DependencyKind::Development { - continue + continue; } let path_or_git_dep = From 14415006a601c62af2db7be253263f3a669dd9e9 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:30:25 +0530 Subject: [PATCH 154/177] Removes unnecessary changes --- substrate/client/authority-discovery/Cargo.toml | 2 +- .../number_of_pallets_exceeds_tuple_size.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/client/authority-discovery/Cargo.toml b/substrate/client/authority-discovery/Cargo.toml index 3351e1d9cca0..1a4b23d3c6d2 100644 --- a/substrate/client/authority-discovery/Cargo.toml +++ b/substrate/client/authority-discovery/Cargo.toml @@ -41,9 +41,9 @@ sp-keystore = { path = "../../primitives/keystore" } sp-runtime = { path = "../../primitives/runtime" } async-trait = "0.1.56" multihash-codetable = { version = "0.1.1", features = [ - "digest", "serde", "sha2", + "digest", ] } [dev-dependencies] diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs index 16a780c97fe8..78ae6f57f087 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs +++ b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs @@ -48,7 +48,7 @@ impl frame_system::Config for Runtime { type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type BlockHashCount = frame_support::traits::ConstU32<250>; + type BlockHashCount = frame_support::traits::ConstU32<250>; type BlockWeights = (); type BlockLength = (); type DbWeight = (); From dfda32d83e804c0839b70eab9296d953aa3c44a2 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:38:41 +0530 Subject: [PATCH 155/177] Fixes substrate-test-runtime build --- substrate/test-utils/runtime/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 1a4e9fd04667..8eb823b48d46 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -27,7 +27,7 @@ pub mod substrate_test_pallet; use codec::{Decode, Encode}; use frame_support::{ - construct_runtime, + construct_runtime, derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_config, create_default_config}, parameter_types, @@ -35,7 +35,7 @@ use frame_support::{ weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND}, Weight, - }, + }, derive_impl, }; use frame_system::{ limits::{BlockLength, BlockWeights}, @@ -342,6 +342,7 @@ parameter_types! { .build_or_panic(); } +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::pallet::Config for Runtime { type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = RuntimeBlockWeights; From 0c4a1092b4dc12b5c6eeb4d6d13864e93b6cd533 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:48:55 +0530 Subject: [PATCH 156/177] Fixes UI Test --- ...umber_of_pallets_exceeds_tuple_size.stderr | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.stderr index 15c45d8f3c30..5bef0b69c5c9 100644 --- a/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.stderr +++ b/substrate/frame/support/test/tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.stderr @@ -22,35 +22,29 @@ error[E0412]: cannot find type `Runtime` in this scope | ^^^^^^^ not found in this scope error[E0412]: cannot find type `Runtime` in this scope - --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:39:31 + --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:40:31 | -39 | impl frame_system::Config for Runtime { +40 | impl frame_system::Config for Runtime { | ^^^^^^^ not found in this scope error[E0412]: cannot find type `RuntimeOrigin` in this scope - --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:41:23 + --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:42:23 | -41 | type RuntimeOrigin = RuntimeOrigin; +42 | type RuntimeOrigin = RuntimeOrigin; | ^^^^^^^^^^^^^ help: you might have meant to use the associated type: `Self::RuntimeOrigin` error[E0412]: cannot find type `RuntimeCall` in this scope - --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:43:21 + --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:44:21 | -43 | type RuntimeCall = RuntimeCall; +44 | type RuntimeCall = RuntimeCall; | ^^^^^^^^^^^ help: you might have meant to use the associated type: `Self::RuntimeCall` error[E0412]: cannot find type `RuntimeEvent` in this scope - --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:49:22 + --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:50:22 | -49 | type RuntimeEvent = RuntimeEvent; +50 | type RuntimeEvent = RuntimeEvent; | ^^^^^^^^^^^^ help: you might have meant to use the associated type: `Self::RuntimeEvent` -error[E0412]: cannot find type `RuntimeTask` in this scope - --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:50:21 - | -50 | type RuntimeTask = RuntimeTask; - | ^^^^^^^^^^^ help: you might have meant to use the associated type: `Self::RuntimeTask` - error[E0412]: cannot find type `PalletInfo` in this scope --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:56:20 | @@ -67,3 +61,11 @@ help: consider importing one of these items | 18 + use frame_support::traits::PalletInfo; | + +error[E0412]: cannot find type `RuntimeTask` in this scope + --> tests/construct_runtime_ui/number_of_pallets_exceeds_tuple_size.rs:39:1 + | +39 | #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you might have meant to use the associated type: `Self::RuntimeTask` + | + = note: this error originates in the macro `frame_system::config_preludes::TestDefaultConfig` which comes from the expansion of the macro `frame_support::macro_magic::forward_tokens_verbatim` (in Nightly builds, run with -Z macro-backtrace for more info) From ba685f92f39a69294f97a426ef6f704bbeb10dfb Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 5 Dec 2023 06:20:25 +0000 Subject: [PATCH 157/177] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/client/authority-discovery/Cargo.toml | 10 +++++----- substrate/test-utils/runtime/src/lib.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/substrate/client/authority-discovery/Cargo.toml b/substrate/client/authority-discovery/Cargo.toml index 1a4b23d3c6d2..40c2162c7996 100644 --- a/substrate/client/authority-discovery/Cargo.toml +++ b/substrate/client/authority-discovery/Cargo.toml @@ -23,8 +23,8 @@ futures-timer = "3.0.1" ip_network = "0.4.1" libp2p = { version = "0.51.3", features = ["ed25519", "kad"] } multihash = { version = "0.18.1", default-features = false, features = [ - "sha2", - "std", + "sha2", + "std", ] } log = "0.4.17" prost = "0.11" @@ -41,9 +41,9 @@ sp-keystore = { path = "../../primitives/keystore" } sp-runtime = { path = "../../primitives/runtime" } async-trait = "0.1.56" multihash-codetable = { version = "0.1.1", features = [ - "serde", - "sha2", - "digest", + "digest", + "serde", + "sha2", ] } [dev-dependencies] diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 8eb823b48d46..16ab467772f2 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -35,7 +35,7 @@ use frame_support::{ weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND}, Weight, - }, derive_impl, + }, }; use frame_system::{ limits::{BlockLength, BlockWeights}, From 6b3e2390bca8aee738edc1157a9215ba77475c48 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 12:05:46 +0530 Subject: [PATCH 158/177] Fixes build --- cumulus/pallets/collator-selection/src/mock.rs | 3 ++- substrate/frame/system/src/mock.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cumulus/pallets/collator-selection/src/mock.rs b/cumulus/pallets/collator-selection/src/mock.rs index 46143674bb39..ab9ad5ec11a2 100644 --- a/cumulus/pallets/collator-selection/src/mock.rs +++ b/cumulus/pallets/collator-selection/src/mock.rs @@ -16,7 +16,7 @@ use super::*; use crate as collator_selection; use frame_support::{ - ord_parameter_types, parameter_types, + derive_impl, ord_parameter_types, parameter_types, traits::{ConstBool, ConstU32, ConstU64, FindAuthor, ValidatorRegistration}, PalletId, }; @@ -50,6 +50,7 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl system::Config for Test { type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = (); diff --git a/substrate/frame/system/src/mock.rs b/substrate/frame/system/src/mock.rs index c016ea9e1cd1..ad5d4a396377 100644 --- a/substrate/frame/system/src/mock.rs +++ b/substrate/frame/system/src/mock.rs @@ -85,6 +85,7 @@ impl OnKilledAccount for RecordKilled { } } +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl Config for Test { type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = RuntimeBlockWeights; From 04a9767c102544616108e1506f9a9a5082b0963d Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 12:17:04 +0530 Subject: [PATCH 159/177] Fixes build --- substrate/frame/support/test/compile_pass/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/frame/support/test/compile_pass/src/lib.rs b/substrate/frame/support/test/compile_pass/src/lib.rs index 6ea37fb27e72..b304dfcb2823 100644 --- a/substrate/frame/support/test/compile_pass/src/lib.rs +++ b/substrate/frame/support/test/compile_pass/src/lib.rs @@ -22,7 +22,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use renamed_frame_support::{ - construct_runtime, parameter_types, + construct_runtime, derive_impl, parameter_types, traits::{ConstU16, ConstU32, ConstU64, Everything}, }; use sp_core::{sr25519, H256}; @@ -51,6 +51,7 @@ parameter_types! { pub const Version: RuntimeVersion = VERSION; } +#[derive_impl(renamed_frame_system::config_preludes::TestDefaultConfig as renamed_frame_system::DefaultConfig)] impl renamed_frame_system::Config for Runtime { type BaseCallFilter = Everything; type BlockWeights = (); From 86e51450fd076d9be9a425f54374b072c2fc86f8 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 12:28:37 +0530 Subject: [PATCH 160/177] Minor fix --- substrate/frame/system/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/system/src/mock.rs b/substrate/frame/system/src/mock.rs index ad5d4a396377..e33ac2f56c87 100644 --- a/substrate/frame/system/src/mock.rs +++ b/substrate/frame/system/src/mock.rs @@ -17,7 +17,7 @@ use crate::{self as frame_system, *}; use frame_support::{ - parameter_types, + derive_impl, parameter_types, traits::{ConstU32, ConstU64}, }; use sp_core::H256; From c13fb8ee0ae939595cb67a1510f3627ea767cec5 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 12:44:56 +0530 Subject: [PATCH 161/177] Minor fix --- cumulus/parachain-template/pallets/template/src/mock.rs | 3 ++- substrate/frame/examples/default-config/src/lib.rs | 1 + substrate/frame/scheduler/src/mock.rs | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cumulus/parachain-template/pallets/template/src/mock.rs b/cumulus/parachain-template/pallets/template/src/mock.rs index 8fae1019f42d..411a16b116c8 100644 --- a/cumulus/parachain-template/pallets/template/src/mock.rs +++ b/cumulus/parachain-template/pallets/template/src/mock.rs @@ -1,4 +1,4 @@ -use frame_support::{parameter_types, traits::Everything}; +use frame_support::{derive_impl, parameter_types, traits::Everything}; use frame_system as system; use sp_core::H256; use sp_runtime::{ @@ -22,6 +22,7 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl system::Config for Test { type BaseCallFilter = Everything; type BlockWeights = (); diff --git a/substrate/frame/examples/default-config/src/lib.rs b/substrate/frame/examples/default-config/src/lib.rs index 0128dcaf1561..bb4d300ccc57 100644 --- a/substrate/frame/examples/default-config/src/lib.rs +++ b/substrate/frame/examples/default-config/src/lib.rs @@ -196,6 +196,7 @@ pub mod tests { impl pallet_default_config_example::Config for Runtime { // These two both cannot have defaults. type RuntimeEvent = RuntimeEvent; + type RuntimeTask = RuntimeTask; type HasNoDefault = frame_support::traits::ConstU32<1>; type CannotHaveDefault = SomeCall; diff --git a/substrate/frame/scheduler/src/mock.rs b/substrate/frame/scheduler/src/mock.rs index b6eb1d044fa2..4edcfa0a7bfd 100644 --- a/substrate/frame/scheduler/src/mock.rs +++ b/substrate/frame/scheduler/src/mock.rs @@ -21,7 +21,7 @@ use super::*; use crate as scheduler; use frame_support::{ - ord_parameter_types, parameter_types, + derive_impl, ord_parameter_types, parameter_types, traits::{ ConstU32, ConstU64, Contains, EitherOfDiverse, EqualPrivilegeOnly, OnFinalize, OnInitialize, }, @@ -118,6 +118,8 @@ parameter_types! { Weight::from_parts(2_000_000_000_000, u64::MAX), ); } + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl system::Config for Test { type BaseCallFilter = BaseFilter; type BlockWeights = BlockWeights; From 94634b48f9ce80e8caf71b77414db8ea3406076a Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 5 Dec 2023 13:00:06 +0530 Subject: [PATCH 162/177] Minor fix --- substrate/frame/support/src/dispatch.rs | 1 + substrate/frame/support/src/storage/generator/mod.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/substrate/frame/support/src/dispatch.rs b/substrate/frame/support/src/dispatch.rs index 3709de5ba49f..449b6f23165a 100644 --- a/substrate/frame/support/src/dispatch.rs +++ b/substrate/frame/support/src/dispatch.rs @@ -792,6 +792,7 @@ mod weight_tests { type BaseCallFilter = crate::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type DbWeight = DbWeight; type PalletInfo = PalletInfo; } diff --git a/substrate/frame/support/src/storage/generator/mod.rs b/substrate/frame/support/src/storage/generator/mod.rs index d21519ee0d85..dd6d622852db 100644 --- a/substrate/frame/support/src/storage/generator/mod.rs +++ b/substrate/frame/support/src/storage/generator/mod.rs @@ -130,6 +130,7 @@ mod tests { type BaseCallFilter = crate::traits::Everything; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type PalletInfo = PalletInfo; type DbWeight = (); } From c5fc02368c6bd4bff74688faca23256937daf8d2 Mon Sep 17 00:00:00 2001 From: gupnik Date: Tue, 5 Dec 2023 19:10:11 +0530 Subject: [PATCH 163/177] Update substrate/frame/examples/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/frame/examples/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/examples/src/lib.rs b/substrate/frame/examples/src/lib.rs index c86818876f4e..f38bbe52dc11 100644 --- a/substrate/frame/examples/src/lib.rs +++ b/substrate/frame/examples/src/lib.rs @@ -43,6 +43,6 @@ //! - [`pallet_example_frame_crate`]: Example pallet showcasing how one can be //! built using only the `frame` umbrella crate. //! -//! - [`pallet_example_tasks`]: This pallet demonstrates the use of `Tasks` to execute service work +//! - [`pallet_example_tasks`]: This pallet demonstrates the use of `Tasks` to execute service work. //! //! **Tip**: Use `cargo doc --package --open` to view each pallet's documentation. From 34a5780521911e79434ad2edc0bb85e1405757f9 Mon Sep 17 00:00:00 2001 From: gupnik Date: Tue, 5 Dec 2023 19:10:23 +0530 Subject: [PATCH 164/177] Update substrate/frame/examples/tasks/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/frame/examples/tasks/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/examples/tasks/src/lib.rs b/substrate/frame/examples/tasks/src/lib.rs index d7782569a77a..3a7d5d148c11 100644 --- a/substrate/frame/examples/tasks/src/lib.rs +++ b/substrate/frame/examples/tasks/src/lib.rs @@ -14,6 +14,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + //! This pallet demonstrates the use of the `pallet::task` api for service work. #![cfg_attr(not(feature = "std"), no_std)] From 2fba261e13db33e226ebad592b472f414732ef28 Mon Sep 17 00:00:00 2001 From: gupnik Date: Tue, 5 Dec 2023 19:10:38 +0530 Subject: [PATCH 165/177] Update substrate/frame/examples/tasks/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/frame/examples/tasks/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/examples/tasks/src/lib.rs b/substrate/frame/examples/tasks/src/lib.rs index 3a7d5d148c11..fcb8247451fe 100644 --- a/substrate/frame/examples/tasks/src/lib.rs +++ b/substrate/frame/examples/tasks/src/lib.rs @@ -33,7 +33,6 @@ pub use weights::*; #[frame_support::pallet(dev_mode)] pub mod pallet { - use super::*; use frame_support::pallet_prelude::*; From 73cbb3f0853f6ddc76f9e816e6d63dfd84bbe511 Mon Sep 17 00:00:00 2001 From: gupnik Date: Tue, 5 Dec 2023 19:10:48 +0530 Subject: [PATCH 166/177] Update substrate/frame/examples/tasks/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/frame/examples/tasks/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/examples/tasks/src/lib.rs b/substrate/frame/examples/tasks/src/lib.rs index fcb8247451fe..a0bbfb538e5a 100644 --- a/substrate/frame/examples/tasks/src/lib.rs +++ b/substrate/frame/examples/tasks/src/lib.rs @@ -38,6 +38,7 @@ pub mod pallet { #[pallet::error] pub enum Error { + /// The referenced task was not found. NotFound, } From 26eae6081bc36b2cf3b2e72067dee56b60060a1c Mon Sep 17 00:00:00 2001 From: gupnik Date: Tue, 5 Dec 2023 19:11:33 +0530 Subject: [PATCH 167/177] Update substrate/frame/examples/tasks/src/tests.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/frame/examples/tasks/src/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/examples/tasks/src/tests.rs b/substrate/frame/examples/tasks/src/tests.rs index 764ca89e12e7..6b255491091d 100644 --- a/substrate/frame/examples/tasks/src/tests.rs +++ b/substrate/frame/examples/tasks/src/tests.rs @@ -17,6 +17,7 @@ //! Tests for `pallet-example-tasks`. #![cfg(test)] + use crate::{mock::*, Numbers, Total}; use frame_support::{assert_noop, assert_ok, traits::Task}; use sp_runtime::BuildStorage; From 89902561ad47a1f82441ad592794ccd3ac6a1d56 Mon Sep 17 00:00:00 2001 From: gupnik Date: Tue, 5 Dec 2023 19:11:52 +0530 Subject: [PATCH 168/177] Update substrate/frame/support/src/tests/mod.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/frame/support/src/tests/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/src/tests/mod.rs b/substrate/frame/support/src/tests/mod.rs index dc8f78d64ae8..c6a0b6cde773 100644 --- a/substrate/frame/support/src/tests/mod.rs +++ b/substrate/frame/support/src/tests/mod.rs @@ -84,7 +84,7 @@ pub mod frame_system { pub enum Error { /// Required by construct_runtime CallFiltered, - /// Used in tasks example + /// Used in tasks example. NotFound, /// The specified [`Task`] is not valid. InvalidTask, From ef58f3290a73961ce20a75ef6d0c215e0b197832 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:56:38 +0530 Subject: [PATCH 169/177] Addresses some review comments --- .../frame/examples/default-config/src/lib.rs | 1 + .../src/construct_runtime/expand/task.rs | 52 ++++++++++--------- .../procedural/src/pallet/expand/tasks.rs | 41 ++++++++------- .../procedural/src/pallet/parse/mod.rs | 52 +++++++++---------- .../procedural/src/pallet/parse/tasks.rs | 2 + 5 files changed, 78 insertions(+), 70 deletions(-) diff --git a/substrate/frame/examples/default-config/src/lib.rs b/substrate/frame/examples/default-config/src/lib.rs index bb4d300ccc57..bf50b8fcc0b1 100644 --- a/substrate/frame/examples/default-config/src/lib.rs +++ b/substrate/frame/examples/default-config/src/lib.rs @@ -47,6 +47,7 @@ pub mod pallet { #[pallet::no_default] // optional. `RuntimeEvent` is automatically excluded as well. type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// The overarching task type. #[pallet::no_default] type RuntimeTask: Task; diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index a2d74e76e4ab..6d3a27c76336 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -30,37 +30,41 @@ pub fn expand_outer_task( let mut variant_names = Vec::new(); let mut task_paths = Vec::new(); for decl in pallet_decls { - if let Some(_) = decl.find_part("Task") { - let variant_name = &decl.name; - let path = &decl.path; - let index = decl.index; - - from_impls.push(quote! { - impl From<#path::Task<#runtime_name>> for RuntimeTask { - fn from(hr: #path::Task<#runtime_name>) -> Self { - RuntimeTask::#variant_name(hr) - } + if decl.find_part("Task").is_none() { + continue; + } + + let variant_name = &decl.name; + let path = &decl.path; + let index = decl.index; + + from_impls.push(quote! { + impl From<#path::Task<#runtime_name>> for RuntimeTask { + fn from(hr: #path::Task<#runtime_name>) -> Self { + RuntimeTask::#variant_name(hr) } + } + + impl TryInto<#path::Task<#runtime_name>> for RuntimeTask { + type Error = (); - impl From for Option<#path::Task<#runtime_name>> { - fn from(rt: RuntimeTask) -> Self { - match rt { - RuntimeTask::#variant_name(hr) => Some(hr), - _ => None, - } + fn try_into(self) -> Result<#path::Task<#runtime_name>, Self::Error> { + match self { + RuntimeTask::#variant_name(hr) => Ok(hr), + _ => Err(()), } } - }); + } + }); - task_variants.push(quote! { - #[codec(index = #index)] - #variant_name(#path::Task<#runtime_name>), - }); + task_variants.push(quote! { + #[codec(index = #index)] + #variant_name(#path::Task<#runtime_name>), + }); - variant_names.push(quote!(#variant_name)); + variant_names.push(quote!(#variant_name)); - task_paths.push(quote!(#path::Task)); - } + task_paths.push(quote!(#path::Task)); } let prelude = quote!(#scrate::traits::tasks::prelude); diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index 19d99a85028a..f2ae8ab238d0 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -17,6 +17,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//! Home of the expansion code for the Tasks API + use crate::pallet::{parse::tasks::*, Def}; use derive_syn_parse::Parse; use inflector::Inflector; @@ -33,27 +35,28 @@ impl TaskEnumDef { type_decl_bounded_generics: TokenStream2, type_use_generics: TokenStream2, ) -> Self { - let variants = match tasks.tasks_attr.is_some() { - true => tasks - .tasks - .iter() - .map(|task| { - let ident = &task.item.sig.ident; - let ident = - format_ident!("{}", ident.to_string().to_class_case(), span = ident.span()); + let variants = if tasks.tasks_attr.is_some() { + tasks + .tasks + .iter() + .map(|task| { + let ident = &task.item.sig.ident; + let ident = + format_ident!("{}", ident.to_string().to_class_case(), span = ident.span()); - let args = task.item.sig.inputs.iter().collect::>(); + let args = task.item.sig.inputs.iter().collect::>(); - if args.is_empty() { - quote!(#ident) - } else { - quote!(#ident { - #(#args),* - }) - } - }) - .collect::>(), - false => Vec::new(), + if args.is_empty() { + quote!(#ident) + } else { + quote!(#ident { + #(#args),* + }) + } + }) + .collect::>() + } else { + Vec::new() }; let mut task_enum_def: TaskEnumDef = parse_quote! { /// Auto-generated enum that encapsulates all tasks defined by this pallet. diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index e3c5c316ca31..6d0c8c330b07 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -138,10 +138,10 @@ impl Def { let item_tokens = get_tokens(item); // `TasksDef::parse` needs to know if attr was provided so we artificially // re-insert it here - tasks = Some(syn::parse2::(quote::quote! { + tasks = Some(syn::parse_quote! { #[pallet::tasks] #item_tokens - })?); + }); // replace item with a no-op because it will be handled by the expansion of tasks *item = syn::Item::Verbatim(quote::quote!()); @@ -311,15 +311,14 @@ impl Def { let (Some(seg), None) = (type_path.get(0), type_path.get(1)) else { return Ok(()) }; let mut result = None; for item in items { - if let syn::Item::Enum(item_enum) = item { - if item_enum.ident == seg.ident { - result = Some(syn::parse2::(item_enum.to_token_stream())?); - // replace item with a no-op because it will be handled by the expansion of - // `task_enum`. We use a no-op instead of simply removing it from the vec - // so that any indices collected by `Def::try_from` remain accurate - *item = syn::Item::Verbatim(quote::quote!()); - break - } + let syn::Item::Enum(item_enum) = item else { continue }; + if item_enum.ident == seg.ident { + result = Some(syn::parse2::(item_enum.to_token_stream())?); + // replace item with a no-op because it will be handled by the expansion of + // `task_enum`. We use a no-op instead of simply removing it from the vec + // so that any indices collected by `Def::try_from` remain accurate + *item = syn::Item::Verbatim(quote::quote!()); + break } } *task_enum = result; @@ -336,22 +335,21 @@ impl Def { let None = tasks else { return Ok(()) }; let mut result = None; for item in items { - if let syn::Item::Impl(item_impl) = item { - let Some((_, path, _)) = &item_impl.trait_ else { continue }; - let Some(trait_last_seg) = path.segments.last() else { continue }; - let syn::Type::Path(target_path) = &*item_impl.self_ty else { continue }; - let target_path = target_path.path.segments.iter().collect::>(); - let (Some(target_ident), None) = (target_path.get(0), target_path.get(1)) else { - continue - }; - let matches_task_enum = match task_enum { - Some(task_enum) => task_enum.item_enum.ident == target_ident.ident, - None => true, - }; - if trait_last_seg.ident == "Task" && matches_task_enum { - result = Some(syn::parse2::(item_impl.to_token_stream())?); - break - } + let syn::Item::Impl(item_impl) = item else { continue }; + let Some((_, path, _)) = &item_impl.trait_ else { continue }; + let Some(trait_last_seg) = path.segments.last() else { continue }; + let syn::Type::Path(target_path) = &*item_impl.self_ty else { continue }; + let target_path = target_path.path.segments.iter().collect::>(); + let (Some(target_ident), None) = (target_path.get(0), target_path.get(1)) else { + continue + }; + let matches_task_enum = match task_enum { + Some(task_enum) => task_enum.item_enum.ident == target_ident.ident, + None => true, + }; + if trait_last_seg.ident == "Task" && matches_task_enum { + result = Some(syn::parse2::(item_impl.to_token_stream())?); + break } } *tasks = result; diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 9f00b8cbb0ac..a88ad99b54c7 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -15,6 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//! Home of the parsing code for the Tasks API + use std::collections::HashSet; #[cfg(test)] From eb69f3792cb4f5b868adbe9615bd28cf3b0c9c90 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:26:14 +0530 Subject: [PATCH 170/177] Addresses more review comments --- Cargo.lock | 24 ----- substrate/frame/support/procedural/Cargo.toml | 2 - .../src/construct_runtime/expand/task.rs | 4 +- .../procedural/src/pallet/parse/mod.rs | 11 +-- .../procedural/src/pallet/parse/tasks.rs | 98 ++++++++++--------- .../procedural/src/pallet/parse/tests/mod.rs | 30 +++--- substrate/frame/support/src/traits/tasks.rs | 11 ++- 7 files changed, 81 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81556f15f073..edbc6ff456f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5531,10 +5531,8 @@ dependencies = [ "frame-support-procedural-tools", "itertools 0.10.5", "macro_magic", - "once_cell", "proc-macro-warning", "proc-macro2", - "proc-utils", "quote", "regex", "sp-core-hashing", @@ -13666,28 +13664,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "proc-util-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45e6073edb3261de7793bbde3002e69e6a4baaa34f5e321e299dd30e3c7489ad" -dependencies = [ - "syn 2.0.39", -] - -[[package]] -name = "proc-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "842fd9aaf81ebd6351f2419bd99dd4dae9d97ae2824243e82c69323df4fd1e6b" -dependencies = [ - "prettyplease 0.2.12", - "proc-macro2", - "proc-util-macros", - "quote", - "syn 2.0.39", -] - [[package]] name = "procfs" version = "0.16.0" diff --git a/substrate/frame/support/procedural/Cargo.toml b/substrate/frame/support/procedural/Cargo.toml index fde8ee1ebe0c..7c207b230f3b 100644 --- a/substrate/frame/support/procedural/Cargo.toml +++ b/substrate/frame/support/procedural/Cargo.toml @@ -26,8 +26,6 @@ frame-support-procedural-tools = { path = "tools" } macro_magic = { version = "0.5.0", features = ["proc_support"] } proc-macro-warning = { version = "1.0.0", default-features = false } expander = "2.0.0" -proc-utils = "0" -once_cell = "1.18.0" sp-core-hashing = { path = "../../../primitives/core/hashing" } [dev-dependencies] diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs index 6d3a27c76336..bd952202bbbe 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs @@ -67,7 +67,7 @@ pub fn expand_outer_task( task_paths.push(quote!(#path::Task)); } - let prelude = quote!(#scrate::traits::tasks::prelude); + let prelude = quote!(#scrate::traits::tasks::__private); const INCOMPLETE_MATCH_QED: &'static str = "cannot have an instantiated RuntimeTask without some Task variant in the runtime. QED"; @@ -96,7 +96,7 @@ pub fn expand_outer_task( } } - fn run(&self) -> Result<(), #scrate::traits::tasks::prelude::DispatchError> { + fn run(&self) -> Result<(), #scrate::traits::tasks::__private::DispatchError> { match self { #(RuntimeTask::#variant_names(val) => val.run(),)* _ => unreachable!(#INCOMPLETE_MATCH_QED), diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 6d0c8c330b07..201dc7adc66e 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -105,14 +105,7 @@ impl Def { let mut type_values = vec![]; let mut composites: Vec = vec![]; - let mut item_tokens: Option = None; - for (index, item) in items.iter_mut().enumerate() { - // provides lazy access to the item's underlying `TokenStream2` - let mut get_tokens = |item: &syn::Item| { - item_tokens.get_or_insert_with(|| item.clone().to_token_stream()).clone() - }; - let pallet_attr: Option = helper::take_first_item_pallet_attr(item)?; match pallet_attr { @@ -135,7 +128,7 @@ impl Def { Some(PalletAttr::RuntimeCall(cw, span)) if call.is_none() => call = Some(call::CallDef::try_from(span, index, item, dev_mode, cw)?), Some(PalletAttr::Tasks(_)) if tasks.is_none() => { - let item_tokens = get_tokens(item); + let item_tokens = item.to_token_stream(); // `TasksDef::parse` needs to know if attr was provided so we artificially // re-insert it here tasks = Some(syn::parse_quote! { @@ -159,7 +152,7 @@ impl Def { "`#[pallet::task_list]` can only be used on items within an `impl` statement." )), Some(PalletAttr::RuntimeTask(_)) if task_enum.is_none() => - task_enum = Some(syn::parse2::(get_tokens(item))?), + task_enum = Some(syn::parse2::(item.to_token_stream())?), Some(PalletAttr::Error(span)) if error.is_none() => error = Some(error::ErrorDef::try_from(span, index, item)?), Some(PalletAttr::RuntimeEvent(span)) if event.is_none() => diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index a88ad99b54c7..4eccf8e8ddd9 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -20,7 +20,7 @@ use std::collections::HashSet; #[cfg(test)] -use crate::assert_error_matches; +use crate::assert_parse_error_matches; #[cfg(test)] use crate::pallet::parse::tests::simulate_manifest_dir; @@ -66,16 +66,7 @@ pub struct TasksDef { impl syn::parse::Parse for TasksDef { fn parse(input: ParseStream) -> Result { let item_impl: ItemImpl = input.parse()?; - let (tasks_attrs, normal_attrs): (Vec<_>, Vec<_>) = - item_impl.attrs.clone().into_iter().partition(|attr| { - let mut path_segs = attr.path().segments.iter(); - let (Some(prefix), Some(suffix), None) = - (path_segs.next(), path_segs.next(), path_segs.next()) - else { - return false - }; - prefix.ident == "pallet" && suffix.ident == "tasks" - }); + let (tasks_attrs, normal_attrs) = extract_tasks_attrs(&item_impl); let tasks_attr = match tasks_attrs.first() { Some(attr) => Some(parse2::(attr.to_token_stream())?), None => None, @@ -229,21 +220,7 @@ impl syn::parse::Parse for TaskDef { let item = input.parse::()?; // we only want to activate TaskAttrType parsing errors for tasks-related attributes, // so we filter them here - let (task_attrs, normal_attrs): (Vec<_>, Vec<_>) = - item.attrs.clone().into_iter().partition(|attr| { - let mut path_segs = attr.path().segments.iter(); - let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { - return false - }; - // N.B: the `PartialEq` impl between `Ident` and `&str` is more efficient than - // parsing and makes no stack or heap allocations - prefix.ident == "pallet" && - (suffix.ident == "tasks" || - suffix.ident == "task_list" || - suffix.ident == "task_condition" || - suffix.ident == "task_weight" || - suffix.ident == "task_index") - }); + let (task_attrs, normal_attrs) = extract_task_attrs(&item); let task_attrs: Vec = task_attrs .into_iter() @@ -550,16 +527,45 @@ impl TryFrom> for TaskListAttr { } } +fn extract_tasks_attrs(item_impl: &ItemImpl) -> (Vec, Vec) { + item_impl.attrs.clone().into_iter().partition(|attr| { + let mut path_segs = attr.path().segments.iter(); + let (Some(prefix), Some(suffix), None) = + (path_segs.next(), path_segs.next(), path_segs.next()) + else { + return false + }; + prefix.ident == "pallet" && suffix.ident == "tasks" + }) +} + +fn extract_task_attrs(item: &ImplItemFn) -> (Vec, Vec) { + item.attrs.clone().into_iter().partition(|attr| { + let mut path_segs = attr.path().segments.iter(); + let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { + return false + }; + // N.B: the `PartialEq` impl between `Ident` and `&str` is more efficient than + // parsing and makes no stack or heap allocations + prefix.ident == "pallet" && + (suffix.ident == "tasks" || + suffix.ident == "task_list" || + suffix.ident == "task_condition" || + suffix.ident == "task_weight" || + suffix.ident == "task_index") + }) +} + #[test] fn test_parse_task_list_() { parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); parse2::(quote!(#[pallet::task_list(Numbers::::iter_keys())])).unwrap(); parse2::(quote!(#[pallet::task_list(iter())])).unwrap(); - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote!(#[pallet::task_list()])), "expected an expression" ); - assert_error_matches!(parse2::(quote!(#[pallet::task_list])), "expected parentheses"); + assert_parse_error_matches!(parse2::(quote!(#[pallet::task_list])), "expected parentheses"); } #[test] @@ -567,15 +573,15 @@ fn test_parse_task_index() { parse2::(quote!(#[pallet::task_index(3)])).unwrap(); parse2::(quote!(#[pallet::task_index(0)])).unwrap(); parse2::(quote!(#[pallet::task_index(17)])).unwrap(); - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote!(#[pallet::task_index])), "expected parentheses" ); - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote!(#[pallet::task_index("hey")])), "expected integer literal" ); - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote!(#[pallet::task_index(0.3)])), "expected integer literal" ); @@ -592,10 +598,10 @@ fn test_parse_task_condition() { #[test] fn test_parse_tasks_attr() { parse2::(quote!(#[pallet::tasks])).unwrap(); - assert_error_matches!(parse2::(quote!(#[pallet::taskss])), "expected `tasks`"); - assert_error_matches!(parse2::(quote!(#[pallet::tasks_])), "expected `tasks`"); - assert_error_matches!(parse2::(quote!(#[pal::tasks])), "expected `pallet`"); - assert_error_matches!( + assert_parse_error_matches!(parse2::(quote!(#[pallet::taskss])), "expected `tasks`"); + assert_parse_error_matches!(parse2::(quote!(#[pallet::tasks_])), "expected `tasks`"); + assert_parse_error_matches!(parse2::(quote!(#[pal::tasks])), "expected `pallet`"); + assert_parse_error_matches!( parse2::(quote!(#[pallet::tasks()])), "unexpected token" ); @@ -682,7 +688,7 @@ fn test_parse_tasks_def_basic_increment_decrement() { #[test] fn test_parse_tasks_def_duplicate_index() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { @@ -711,7 +717,7 @@ fn test_parse_tasks_def_duplicate_index() { #[test] fn test_parse_tasks_def_missing_task_list() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { @@ -730,7 +736,7 @@ fn test_parse_tasks_def_missing_task_list() { #[test] fn test_parse_tasks_def_missing_task_condition() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { @@ -749,7 +755,7 @@ fn test_parse_tasks_def_missing_task_condition() { #[test] fn test_parse_tasks_def_missing_task_index() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { @@ -768,7 +774,7 @@ fn test_parse_tasks_def_missing_task_index() { #[test] fn test_parse_tasks_def_missing_task_weight() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { @@ -788,7 +794,7 @@ fn test_parse_tasks_def_missing_task_weight() { #[test] fn test_parse_tasks_def_unexpected_extra_task_list_attr() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { @@ -810,7 +816,7 @@ fn test_parse_tasks_def_unexpected_extra_task_list_attr() { #[test] fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { @@ -832,7 +838,7 @@ fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { #[test] fn test_parse_tasks_def_unexpected_extra_task_index_attr() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::tasks] impl, I: 'static> Pallet { @@ -854,7 +860,7 @@ fn test_parse_tasks_def_unexpected_extra_task_index_attr() { #[test] fn test_parse_tasks_def_extra_tasks_attribute() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::tasks] #[pallet::tasks] @@ -920,7 +926,7 @@ fn test_parse_task_enum_def_missing_attr_alternate_name_allowed() { #[test] fn test_parse_task_enum_def_wrong_attr() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::something] pub enum Task { @@ -936,7 +942,7 @@ fn test_parse_task_enum_def_wrong_attr() { #[test] fn test_parse_task_enum_def_wrong_item() { simulate_manifest_dir("../../examples/basic", || { - assert_error_matches!( + assert_parse_error_matches!( parse2::(quote! { #[pallet::task_enum] pub struct Something; diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 0ca5186a763b..112b953213e7 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -15,17 +15,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -use once_cell::sync::Lazy; use std::{panic, sync::Mutex}; use syn::parse_quote; -/// Ensures that only one thread can modify/restore the `CARGO_MANIFEST_DIR` ENV var at a time, -/// avoiding a race condition because `cargo test` runs tests in parallel. -/// -/// Although this forces all tests that use [`simulate_manifest_dir`] to run sequentially with -/// respect to each other, this is still several orders of magnitude faster than using UI -/// tests, even if they are run in parallel. -static MANIFEST_DIR_LOCK: Lazy> = Lazy::new(|| Mutex::new(())); +#[doc(hidden)] +pub mod __private { + pub use regex; +} /// Allows you to assert that the input expression resolves to an error whose string /// representation matches the specified regex literal. @@ -35,7 +31,7 @@ static MANIFEST_DIR_LOCK: Lazy> = Lazy::new(|| Mutex::new(())); /// ``` /// use super::tasks::*; /// -/// assert_error_matches!( +/// assert_parse_error_matches!( /// parse2::(quote! { /// #[pallet::task_enum] /// pub struct Something; @@ -48,7 +44,7 @@ static MANIFEST_DIR_LOCK: Lazy> = Lazy::new(|| Mutex::new(())); /// use with the [`regex`] crate.): /// /// ```ignore -/// assert_error_matches!( +/// assert_parse_error_matches!( /// parse2::(quote! { /// #[pallet::tasks] /// impl, I: 'static> Pallet { @@ -66,13 +62,13 @@ static MANIFEST_DIR_LOCK: Lazy> = Lazy::new(|| Mutex::new(())); /// Although this is primarily intended to be used with parsing errors, this macro is general /// enough that it will work with any error with a reasonable [`core::fmt::Display`] impl. #[macro_export] -macro_rules! assert_error_matches { +macro_rules! assert_parse_error_matches { ($expr:expr, $reg:literal) => { match $expr { Ok(_) => panic!("Expected an `Error(..)`, but got Ok(..)"), Err(e) => { let error_message = e.to_string(); - let re = regex::Regex::new($reg).expect("Invalid regex pattern"); + let re = $crate::pallet::parse::tests::__private::regex::Regex::new($reg).expect("Invalid regex pattern"); assert!( re.is_match(&error_message), "Error message \"{}\" does not match the pattern \"{}\"", @@ -162,7 +158,7 @@ macro_rules! assert_pallet_parse_error { $($tokens:tt)* ) => { $crate::pallet::parse::tests::simulate_manifest_dir($manifest_dir, || { - $crate::assert_error_matches!( + $crate::assert_parse_error_matches!( $crate::pallet::parse::Def::try_from( parse_quote! { $($tokens)* @@ -191,6 +187,14 @@ pub fn simulate_manifest_dir, F: FnOnce() + std::panic ) { use std::{env::*, path::*}; + /// Ensures that only one thread can modify/restore the `CARGO_MANIFEST_DIR` ENV var at a time, + /// avoiding a race condition because `cargo test` runs tests in parallel. + /// + /// Although this forces all tests that use [`simulate_manifest_dir`] to run sequentially with + /// respect to each other, this is still several orders of magnitude faster than using UI + /// tests, even if they are run in parallel. + static MANIFEST_DIR_LOCK: Mutex<()> = Mutex::new(()); + // avoid race condition when swapping out `CARGO_MANIFEST_DIR` let guard = MANIFEST_DIR_LOCK.lock().unwrap(); diff --git a/substrate/frame/support/src/traits/tasks.rs b/substrate/frame/support/src/traits/tasks.rs index 171308d8bb1e..24f3430cf50b 100644 --- a/substrate/frame/support/src/traits/tasks.rs +++ b/substrate/frame/support/src/traits/tasks.rs @@ -18,9 +18,16 @@ //! Contains the [`Task`] trait, which defines a general-purpose way for defining and executing //! service work, and supporting types. +use codec::FullCodec; +use scale_info::TypeInfo; +use sp_runtime::DispatchError; +use sp_std::{fmt::Debug, iter::Iterator, vec, vec::IntoIter}; +use sp_weights::Weight; + /// Contain's re-exports of all the supporting types for the [`Task`] trait. Used in the macro /// expansion of `RuntimeTask`. -pub mod prelude { +#[doc(hidden)] +pub mod __private { pub use codec::FullCodec; pub use scale_info::TypeInfo; pub use sp_runtime::DispatchError; @@ -28,8 +35,6 @@ pub mod prelude { pub use sp_weights::Weight; } -use prelude::*; - /// A general-purpose trait which defines a type of service work (i.e., work to performed by an /// off-chain worker) including methods for enumerating, validating, indexing, and running /// tasks of this type. From 260fd82ad946f6beed00740442f6f1a3c94cf712 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:29:11 +0530 Subject: [PATCH 171/177] Updates PrDoc --- prdoc/pr_1343.prdoc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/prdoc/pr_1343.prdoc b/prdoc/pr_1343.prdoc index 69bed2d1ccf2..ebc169c9773f 100644 --- a/prdoc/pr_1343.prdoc +++ b/prdoc/pr_1343.prdoc @@ -4,7 +4,7 @@ title: Tasks API: A general system for recognizing and executing service work doc: - - audience: Core Dev + - audience: Runtime Dev description: | The Tasks API allows you to define some service work that can be recognized by a script or an off-chain worker. Such a script can then create and submit all such work items at any @@ -24,6 +24,10 @@ migrations: runtime: [] -crates: [] +crates: + - name: frame-system + - name: frame-support + - name: frame-support-procedural + - name: pallet-example-tasks host_functions: [] From 334f051d4b3195388c20d7c7e7b95299423c72aa Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:43:06 +0530 Subject: [PATCH 172/177] Addresses review comments --- prdoc/pr_1343.prdoc | 5 +- .../procedural/src/pallet/parse/tasks.rs | 77 ++++++++++--------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/prdoc/pr_1343.prdoc b/prdoc/pr_1343.prdoc index ebc169c9773f..11f8ec662c32 100644 --- a/prdoc/pr_1343.prdoc +++ b/prdoc/pr_1343.prdoc @@ -1,7 +1,4 @@ -# Schema: Parity PR Documentation Schema (prdoc) -# See doc at https://github.com/paritytech/prdoc - -title: Tasks API: A general system for recognizing and executing service work +title: Tasks API - A general system for recognizing and executing service work doc: - audience: Runtime Dev diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 4eccf8e8ddd9..ce3b9c5f7407 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -66,7 +66,7 @@ pub struct TasksDef { impl syn::parse::Parse for TasksDef { fn parse(input: ParseStream) -> Result { let item_impl: ItemImpl = input.parse()?; - let (tasks_attrs, normal_attrs) = extract_tasks_attrs(&item_impl); + let (tasks_attrs, normal_attrs) = partition_tasks_attrs(&item_impl); let tasks_attr = match tasks_attrs.first() { Some(attr) => Some(parse2::(attr.to_token_stream())?), None => None, @@ -156,38 +156,7 @@ pub struct TaskEnumDef { impl syn::parse::Parse for TaskEnumDef { fn parse(input: ParseStream) -> Result { let mut item_enum = input.parse::()?; - let mut attr = None; - let mut duplicate = None; - item_enum.attrs = item_enum - .attrs - .iter() - .filter(|found_attr| { - let segs = found_attr - .path() - .segments - .iter() - .map(|seg| seg.ident.clone()) - .collect::>(); - let (Some(seg1), Some(_), None) = (segs.get(0), segs.get(1), segs.get(2)) else { - return true - }; - if seg1 != "pallet" { - return true - } - if attr.is_some() { - duplicate = Some(found_attr.span()); - } - attr = Some(found_attr.to_token_stream()); - false - }) - .cloned() - .collect(); - if let Some(span) = duplicate { - return Err(Error::new( - span, - "only one `#[pallet::_]` attribute is supported on this item", - )) - } + let attr = extract_pallet_attr(&mut item_enum)?; let attr = match attr { Some(attr) => Some(parse2(attr)?), None => None, @@ -220,7 +189,7 @@ impl syn::parse::Parse for TaskDef { let item = input.parse::()?; // we only want to activate TaskAttrType parsing errors for tasks-related attributes, // so we filter them here - let (task_attrs, normal_attrs) = extract_task_attrs(&item); + let (task_attrs, normal_attrs) = partition_task_attrs(&item); let task_attrs: Vec = task_attrs .into_iter() @@ -527,7 +496,43 @@ impl TryFrom> for TaskListAttr { } } -fn extract_tasks_attrs(item_impl: &ItemImpl) -> (Vec, Vec) { +fn extract_pallet_attr(item_enum: &mut ItemEnum) -> Result> { + let mut duplicate = None; + let mut attr = None; + item_enum.attrs = item_enum + .attrs + .iter() + .filter(|found_attr| { + let segs = found_attr + .path() + .segments + .iter() + .map(|seg| seg.ident.clone()) + .collect::>(); + let (Some(seg1), Some(_), None) = (segs.get(0), segs.get(1), segs.get(2)) else { + return true + }; + if seg1 != "pallet" { + return true + } + if attr.is_some() { + duplicate = Some(found_attr.span()); + } + attr = Some(found_attr.to_token_stream()); + false + }) + .cloned() + .collect(); + if let Some(span) = duplicate { + return Err(Error::new( + span, + "only one `#[pallet::_]` attribute is supported on this item", + )) + } + Ok(attr) +} + +fn partition_tasks_attrs(item_impl: &ItemImpl) -> (Vec, Vec) { item_impl.attrs.clone().into_iter().partition(|attr| { let mut path_segs = attr.path().segments.iter(); let (Some(prefix), Some(suffix), None) = @@ -539,7 +544,7 @@ fn extract_tasks_attrs(item_impl: &ItemImpl) -> (Vec, Vec (Vec, Vec) { +fn partition_task_attrs(item: &ImplItemFn) -> (Vec, Vec) { item.attrs.clone().into_iter().partition(|attr| { let mut path_segs = attr.path().segments.iter(); let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { From 4c906b4163f5b755825813d71c1ace4cd981c75d Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:49:46 +0530 Subject: [PATCH 173/177] Updates PrDoc --- prdoc/pr_1343.prdoc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/prdoc/pr_1343.prdoc b/prdoc/pr_1343.prdoc index 11f8ec662c32..bddcdc76f541 100644 --- a/prdoc/pr_1343.prdoc +++ b/prdoc/pr_1343.prdoc @@ -3,17 +3,16 @@ title: Tasks API - A general system for recognizing and executing service work doc: - audience: Runtime Dev description: | - The Tasks API allows you to define some service work that can be recognized by a script or an - off-chain worker. Such a script can then create and submit all such work items at any - given time. + The Tasks API allows you to define some service work that can be recognized by a script or an off-chain worker. + Such a script can then create and submit all such work items at any given time. `#[pallet:tasks]` provides a convenient way to define such work items. It can be attached to an `impl` block inside a pallet, whose functions can then be annotated by the following attributes: 1. `#[pallet::task_list]`: Define an iterator over the available work items for a task 2. `#[pallet::task_condition]`: Define the conditions for a given work item to be valid 3. `#[pallet::task_weight]`: Define the weight of a given work item 4. `#[pallet::task_index]`: Define the index of a given work item - Each such function becomes a variant of the autogenerated enum `Task` for this pallet. All such - enums are aggregated into a `RuntimeTask` by `construct_runtime`. + Each such function becomes a variant of the autogenerated enum `Task` for this pallet. + All such enums are aggregated into a `RuntimeTask` by `construct_runtime`. An example pallet that uses the Tasks API is available at `substrate/frame/example/tasks`. migrations: From 84719c64a5003679186cdd5b3f55daf4f61960fd Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 6 Dec 2023 07:21:30 +0000 Subject: [PATCH 174/177] ".git/.scripts/commands/fmt/fmt.sh" --- .../frame/examples/default-config/src/lib.rs | 2 +- .../procedural/src/pallet/expand/tasks.rs | 32 +++++++++---------- .../procedural/src/pallet/parse/tasks.rs | 27 ++++++++++------ .../procedural/src/pallet/parse/tests/mod.rs | 3 +- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/substrate/frame/examples/default-config/src/lib.rs b/substrate/frame/examples/default-config/src/lib.rs index bf50b8fcc0b1..f1611bca2ce3 100644 --- a/substrate/frame/examples/default-config/src/lib.rs +++ b/substrate/frame/examples/default-config/src/lib.rs @@ -47,7 +47,7 @@ pub mod pallet { #[pallet::no_default] // optional. `RuntimeEvent` is automatically excluded as well. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// The overarching task type. + /// The overarching task type. #[pallet::no_default] type RuntimeTask: Task; diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs index f2ae8ab238d0..6697e5c822a3 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs @@ -37,24 +37,24 @@ impl TaskEnumDef { ) -> Self { let variants = if tasks.tasks_attr.is_some() { tasks - .tasks - .iter() - .map(|task| { - let ident = &task.item.sig.ident; - let ident = - format_ident!("{}", ident.to_string().to_class_case(), span = ident.span()); + .tasks + .iter() + .map(|task| { + let ident = &task.item.sig.ident; + let ident = + format_ident!("{}", ident.to_string().to_class_case(), span = ident.span()); - let args = task.item.sig.inputs.iter().collect::>(); + let args = task.item.sig.inputs.iter().collect::>(); - if args.is_empty() { - quote!(#ident) - } else { - quote!(#ident { - #(#args),* - }) - } - }) - .collect::>() + if args.is_empty() { + quote!(#ident) + } else { + quote!(#ident { + #(#args),* + }) + } + }) + .collect::>() } else { Vec::new() }; diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index ce3b9c5f7407..12fc12943ebd 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -156,7 +156,7 @@ pub struct TaskEnumDef { impl syn::parse::Parse for TaskEnumDef { fn parse(input: ParseStream) -> Result { let mut item_enum = input.parse::()?; - let attr = extract_pallet_attr(&mut item_enum)?; + let attr = extract_pallet_attr(&mut item_enum)?; let attr = match attr { Some(attr) => Some(parse2(attr)?), None => None, @@ -524,10 +524,7 @@ fn extract_pallet_attr(item_enum: &mut ItemEnum) -> Result> .cloned() .collect(); if let Some(span) = duplicate { - return Err(Error::new( - span, - "only one `#[pallet::_]` attribute is supported on this item", - )) + return Err(Error::new(span, "only one `#[pallet::_]` attribute is supported on this item")) } Ok(attr) } @@ -570,7 +567,10 @@ fn test_parse_task_list_() { parse2::(quote!(#[pallet::task_list()])), "expected an expression" ); - assert_parse_error_matches!(parse2::(quote!(#[pallet::task_list])), "expected parentheses"); + assert_parse_error_matches!( + parse2::(quote!(#[pallet::task_list])), + "expected parentheses" + ); } #[test] @@ -603,9 +603,18 @@ fn test_parse_task_condition() { #[test] fn test_parse_tasks_attr() { parse2::(quote!(#[pallet::tasks])).unwrap(); - assert_parse_error_matches!(parse2::(quote!(#[pallet::taskss])), "expected `tasks`"); - assert_parse_error_matches!(parse2::(quote!(#[pallet::tasks_])), "expected `tasks`"); - assert_parse_error_matches!(parse2::(quote!(#[pal::tasks])), "expected `pallet`"); + assert_parse_error_matches!( + parse2::(quote!(#[pallet::taskss])), + "expected `tasks`" + ); + assert_parse_error_matches!( + parse2::(quote!(#[pallet::tasks_])), + "expected `tasks`" + ); + assert_parse_error_matches!( + parse2::(quote!(#[pal::tasks])), + "expected `pallet`" + ); assert_parse_error_matches!( parse2::(quote!(#[pallet::tasks()])), "unexpected token" diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index 112b953213e7..a9a474136302 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -68,7 +68,8 @@ macro_rules! assert_parse_error_matches { Ok(_) => panic!("Expected an `Error(..)`, but got Ok(..)"), Err(e) => { let error_message = e.to_string(); - let re = $crate::pallet::parse::tests::__private::regex::Regex::new($reg).expect("Invalid regex pattern"); + let re = $crate::pallet::parse::tests::__private::regex::Regex::new($reg) + .expect("Invalid regex pattern"); assert!( re.is_match(&error_message), "Error message \"{}\" does not match the pattern \"{}\"", From 00b515ded5315746ac3a4dae02226946b2c55bc1 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:20:13 +0530 Subject: [PATCH 175/177] Moves tasks to tasks_experimental --- substrate/frame/examples/tasks/src/lib.rs | 2 +- substrate/frame/support/procedural/src/lib.rs | 4 +- .../procedural/src/pallet/parse/mod.rs | 18 +++---- .../procedural/src/pallet/parse/tasks.rs | 50 +++++++++---------- .../procedural/src/pallet/parse/tests/mod.rs | 2 +- .../src/pallet/parse/tests/tasks.rs | 8 +-- substrate/frame/support/src/lib.rs | 19 +++---- substrate/frame/support/src/tests/tasks.rs | 2 +- .../test/tests/pallet_ui/pass/task_valid.rs | 2 +- .../task_can_only_be_attached_to_impl.rs | 2 +- .../pallet_ui/task_condition_invalid_arg.rs | 2 +- .../tests/pallet_ui/task_invalid_condition.rs | 2 +- .../tests/pallet_ui/task_invalid_index.rs | 2 +- .../test/tests/pallet_ui/task_invalid_list.rs | 2 +- .../tests/pallet_ui/task_invalid_weight.rs | 2 +- .../tests/pallet_ui/task_missing_condition.rs | 2 +- .../tests/pallet_ui/task_missing_index.rs | 2 +- .../test/tests/pallet_ui/task_missing_list.rs | 2 +- .../tests/pallet_ui/task_missing_weight.rs | 2 +- 19 files changed, 64 insertions(+), 63 deletions(-) diff --git a/substrate/frame/examples/tasks/src/lib.rs b/substrate/frame/examples/tasks/src/lib.rs index a0bbfb538e5a..c65d8095bcf6 100644 --- a/substrate/frame/examples/tasks/src/lib.rs +++ b/substrate/frame/examples/tasks/src/lib.rs @@ -42,7 +42,7 @@ pub mod pallet { NotFound, } - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { /// Add a pair of numbers into the totals and remove them. #[pallet::task_list(Numbers::::iter_keys())] diff --git a/substrate/frame/support/procedural/src/lib.rs b/substrate/frame/support/procedural/src/lib.rs index cff108f97973..349b6ee6599c 100644 --- a/substrate/frame/support/procedural/src/lib.rs +++ b/substrate/frame/support/procedural/src/lib.rs @@ -1522,9 +1522,9 @@ pub fn composite_enum(_: TokenStream, _: TokenStream) -> TokenStream { /// --- /// /// **Rust-Analyzer users**: See the documentation of the Rust item in -/// `frame_support::pallet_macros::tasks`. +/// `frame_support::pallet_macros::tasks_experimental`. #[proc_macro_attribute] -pub fn tasks(_: TokenStream, _: TokenStream) -> TokenStream { +pub fn tasks_experimental(_: TokenStream, _: TokenStream) -> TokenStream { pallet_macro_stub() } diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 201dc7adc66e..b97f8b4c5ed7 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -131,10 +131,10 @@ impl Def { let item_tokens = item.to_token_stream(); // `TasksDef::parse` needs to know if attr was provided so we artificially // re-insert it here - tasks = Some(syn::parse_quote! { - #[pallet::tasks] + tasks = Some(syn::parse2::(quote::quote! { + #[pallet::tasks_experimental] #item_tokens - }); + })?); // replace item with a no-op because it will be handled by the expansion of tasks *item = syn::Item::Verbatim(quote::quote!()); @@ -259,7 +259,7 @@ impl Def { Ok(def) } - /// Performs extra logic checks necessary for the `#[pallet::tasks]` feature. + /// Performs extra logic checks necessary for the `#[pallet::tasks_experimental]` feature. fn resolve_tasks( item_span: &proc_macro2::Span, tasks: &mut Option, @@ -275,12 +275,12 @@ impl Def { // ensure that if `task_enum` is specified, `tasks` is also specified match (&task_enum, &tasks) { (Some(_), None) => - return Err(syn::Error::new(*item_span, "Missing `#[pallet::tasks]` impl")), + return Err(syn::Error::new(*item_span, "Missing `#[pallet::tasks_experimental]` impl")), (None, Some(tasks)) => if tasks.tasks_attr.is_none() { return Err(syn::Error::new( tasks.item_impl.impl_token.span(), - "A `#[pallet::tasks]` attribute must be attached to your `Task` impl if the \ + "A `#[pallet::tasks_experimental]` attribute must be attached to your `Task` impl if the \ task enum has been omitted", )) } else { @@ -537,7 +537,7 @@ impl GenericKind { mod keyword { syn::custom_keyword!(origin); syn::custom_keyword!(call); - syn::custom_keyword!(tasks); + syn::custom_keyword!(tasks_experimental); syn::custom_keyword!(task_enum); syn::custom_keyword!(task_list); syn::custom_keyword!(task_condition); @@ -679,8 +679,8 @@ impl syn::parse::Parse for PalletAttr { false => Some(InheritedCallWeightAttr::parse(&content)?), }; Ok(PalletAttr::RuntimeCall(attr, span)) - } else if lookahead.peek(keyword::tasks) { - Ok(PalletAttr::Tasks(content.parse::()?.span())) + } else if lookahead.peek(keyword::tasks_experimental) { + Ok(PalletAttr::Tasks(content.parse::()?.span())) } else if lookahead.peek(keyword::task_enum) { Ok(PalletAttr::RuntimeTask(content.parse::()?.span())) } else if lookahead.peek(keyword::task_condition) { diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 12fc12943ebd..5b8deced40d9 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -41,7 +41,7 @@ use syn::{ pub mod keywords { use syn::custom_keyword; - custom_keyword!(tasks); + custom_keyword!(tasks_experimental); custom_keyword!(task_enum); custom_keyword!(task_list); custom_keyword!(task_condition); @@ -50,7 +50,7 @@ pub mod keywords { custom_keyword!(pallet); } -/// Represents the `#[pallet::tasks]` attribute and its attached item. Also includes metadata +/// Represents the `#[pallet::tasks_experimental]` attribute and its attached item. Also includes metadata /// about the linked [`TaskEnumDef`] if applicable. #[derive(Clone, Debug)] pub struct TasksDef { @@ -74,7 +74,7 @@ impl syn::parse::Parse for TasksDef { if let Some(extra_tasks_attr) = tasks_attrs.get(1) { return Err(Error::new( extra_tasks_attr.span(), - "unexpected extra `#[pallet::tasks]` attribute", + "unexpected extra `#[pallet::tasks_experimental]` attribute", )) } let tasks: Vec = if tasks_attr.is_some() { @@ -122,10 +122,10 @@ impl syn::parse::Parse for TasksDef { } } -/// Parsing for a `#[pallet::tasks]` attr. -pub type PalletTasksAttr = PalletTaskAttr; +/// Parsing for a `#[pallet::tasks_experimental]` attr. +pub type PalletTasksAttr = PalletTaskAttr; -/// Parsing for any of the attributes that can be used within a `#[pallet::tasks]` [`ItemImpl`]. +/// Parsing for any of the attributes that can be used within a `#[pallet::tasks_experimental]` [`ItemImpl`]. pub type TaskAttr = PalletTaskAttr; /// Parsing for a `#[pallet::task_index]` attr. @@ -537,7 +537,7 @@ fn partition_tasks_attrs(item_impl: &ItemImpl) -> (Vec, Vec (Vec, Vec(quote!(#[pallet::tasks])).unwrap(); + parse2::(quote!(#[pallet::tasks_experimental])).unwrap(); assert_parse_error_matches!( parse2::(quote!(#[pallet::taskss])), - "expected `tasks`" + "expected `tasks_experimental`" ); assert_parse_error_matches!( parse2::(quote!(#[pallet::tasks_])), - "expected `tasks`" + "expected `tasks_experimental`" ); assert_parse_error_matches!( parse2::(quote!(#[pal::tasks])), "expected `pallet`" ); assert_parse_error_matches!( - parse2::(quote!(#[pallet::tasks()])), + parse2::(quote!(#[pallet::tasks_experimental()])), "unexpected token" ); } @@ -625,7 +625,7 @@ fn test_parse_tasks_attr() { fn test_parse_tasks_def_basic() { simulate_manifest_dir("../../examples/basic", || { let parsed = parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { /// Add a pair of numbers into the totals and remove them. #[pallet::task_list(Numbers::::iter_keys())] @@ -651,7 +651,7 @@ fn test_parse_tasks_def_basic() { fn test_parse_tasks_def_basic_increment_decrement() { simulate_manifest_dir("../../examples/basic", || { let parsed = parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { /// Get the value and check if it can be incremented #[pallet::task_index(0)] @@ -704,7 +704,7 @@ fn test_parse_tasks_def_duplicate_index() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { #[pallet::task_list(Something::iter())] #[pallet::task_condition(|i| i % 2 == 0)] @@ -733,7 +733,7 @@ fn test_parse_tasks_def_missing_task_list() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { #[pallet::task_condition(|i| i % 2 == 0)] #[pallet::task_index(0)] @@ -752,7 +752,7 @@ fn test_parse_tasks_def_missing_task_condition() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { #[pallet::task_list(Something::iter())] #[pallet::task_index(0)] @@ -771,7 +771,7 @@ fn test_parse_tasks_def_missing_task_index() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { #[pallet::task_condition(|i| i % 2 == 0)] #[pallet::task_list(Something::iter())] @@ -790,7 +790,7 @@ fn test_parse_tasks_def_missing_task_weight() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { #[pallet::task_condition(|i| i % 2 == 0)] #[pallet::task_list(Something::iter())] @@ -810,7 +810,7 @@ fn test_parse_tasks_def_unexpected_extra_task_list_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { #[pallet::task_condition(|i| i % 2 == 0)] #[pallet::task_index(0)] @@ -832,7 +832,7 @@ fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { #[pallet::task_condition(|i| i % 2 == 0)] #[pallet::task_condition(|i| i % 4 == 0)] @@ -854,7 +854,7 @@ fn test_parse_tasks_def_unexpected_extra_task_index_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( parse2::(quote! { - #[pallet::tasks] + #[pallet::tasks_experimental] impl, I: 'static> Pallet { #[pallet::task_condition(|i| i % 2 == 0)] #[pallet::task_index(0)] @@ -876,11 +876,11 @@ fn test_parse_tasks_def_extra_tasks_attribute() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( parse2::(quote! { - #[pallet::tasks] - #[pallet::tasks] + #[pallet::tasks_experimental] + #[pallet::tasks_experimental] impl, I: 'static> Pallet {} }), - r"unexpected extra `#\[pallet::tasks\]` attribute" + r"unexpected extra `#\[pallet::tasks_experimental\]` attribute" ); }); } diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs index a9a474136302..a3661f3076d9 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/mod.rs @@ -46,7 +46,7 @@ pub mod __private { /// ```ignore /// assert_parse_error_matches!( /// parse2::(quote! { -/// #[pallet::tasks] +/// #[pallet::tasks_experimental] /// impl, I: 'static> Pallet { /// #[pallet::task_condition(|i| i % 2 == 0)] /// #[pallet::task_index(0)] diff --git a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs index 0623f031d049..9f1436284047 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tests/tasks.rs @@ -21,7 +21,7 @@ use syn::parse_quote; fn test_parse_pallet_with_task_enum_missing_impl() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] - #[error_regex("Missing `\\#\\[pallet::tasks\\]` impl")] + #[error_regex("Missing `\\#\\[pallet::tasks_experimental\\]` impl")] #[frame_support::pallet] pub mod pallet { #[pallet::task_enum] @@ -71,7 +71,7 @@ fn test_parse_pallet_missing_task_enum() { #[manifest_dir("../../examples/basic")] #[frame_support::pallet] pub mod pallet { - #[pallet::tasks] + #[pallet::tasks_experimental] #[cfg(test)] // aha, this means it's being eaten impl frame_support::traits::Task for Task where @@ -150,7 +150,7 @@ fn test_parse_pallet_manual_task_enum_non_manual_impl() { Something, } - #[pallet::tasks] + #[pallet::tasks_experimental] impl frame_support::traits::Task for MyCustomTaskEnum where T: TypeInfo, @@ -224,7 +224,7 @@ fn test_parse_pallet_manual_task_enum_mismatch_ident() { Something, } - #[pallet::tasks] + #[pallet::tasks_experimental] impl frame_support::traits::Task for MyCustomTaskEnum where T: TypeInfo, diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 4e7e48aa7931..d7ad33ae2b20 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -2675,27 +2675,28 @@ pub mod pallet_macros { /// ``` pub use frame_support_procedural::storage; /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks`](`tasks`) to define the conditions for a given work item to be valid. + /// [`pallet::tasks_experimental`](`tasks_experimental`) to define the conditions for a + /// given work item to be valid. /// /// It takes a closure as input, which is then used to define the condition. The closure /// should have the same signature as the function it is attached to, except that it should /// return a `bool` instead. pub use frame_support_procedural::task_condition; /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks`](`tasks`) to define the index of a given work item. + /// [`pallet::tasks_experimental`](`tasks_experimental`) to define the index of a given work item. /// /// It takes an integer literal as input, which is then used to define the index. This /// index should be unique for each function in the `impl` block. pub use frame_support_procedural::task_index; /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks`](`tasks`) to define an iterator over the available work items for a - /// task. + /// [`pallet::tasks_experimental`](`tasks_experimental`) to define an iterator over the + /// available work items for a task. /// /// It takes an iterator as input that yields a tuple with same types as the function /// arguments. pub use frame_support_procedural::task_list; /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks`](`tasks`) define the weight of a given work item. + /// [`pallet::tasks_experimental`](`tasks_experimental`) define the weight of a given work item. /// /// It takes a closure as input, which should return a `Weight` value. pub use frame_support_procedural::task_weight; @@ -2704,9 +2705,9 @@ pub mod pallet_macros { /// given time. /// /// These work items are defined as instances of the [`Task`](frame_support::traits::Task) - /// trait. [`pallet:tasks`](`tasks`) when attached to an `impl` block inside a pallet, will - /// generate an enum `Task` whose variants are mapped to functions inside this `impl` - /// block. + /// trait. [`pallet:tasks_experimental`](`tasks_experimental`) when attached to an `impl` block + /// inside a pallet, will generate an enum `Task` whose variants are mapped to functions + /// inside this `impl` block. /// /// Each such function must have the following set of attributes: /// @@ -2725,7 +2726,7 @@ pub mod pallet_macros { #[doc = docify::embed!("src/tests/tasks.rs", tasks_example)] /// Now, this can be executed as follows: #[doc = docify::embed!("src/tests/tasks.rs", tasks_work)] - pub use frame_support_procedural::tasks; + pub use frame_support_procedural::tasks_experimental; } #[deprecated(note = "Will be removed after July 2023; Use `sp_runtime::traits` directly instead.")] diff --git a/substrate/frame/support/src/tests/tasks.rs b/substrate/frame/support/src/tests/tasks.rs index 4a09642d20da..2774c1300757 100644 --- a/substrate/frame/support/src/tests/tasks.rs +++ b/substrate/frame/support/src/tests/tasks.rs @@ -27,7 +27,7 @@ use frame_support_procedural::pallet_section; #[pallet_section] mod tasks_example { #[docify::export(tasks_example)] - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { /// Add a pair of numbers into the totals and remove them. #[pallet::task_list(Numbers::::iter_keys())] diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs b/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs index 76dade939454..234e220f49d8 100644 --- a/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs +++ b/substrate/frame/support/test/tests/pallet_ui/pass/task_valid.rs @@ -25,7 +25,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { #[pallet::task_index(0)] #[pallet::task_condition(|i, j| i == 0u32 && j == 2u64)] diff --git a/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.rs b/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.rs index 791a250cd350..95f5655af198 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_can_only_be_attached_to_impl.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] pub struct Task; } diff --git a/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.rs b/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.rs index 1c39a28eeecc..1db96869155b 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_condition_invalid_arg.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { #[pallet::task_index(0)] #[pallet::task_condition(|flag: bool| flag)] diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.rs b/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.rs index 95a4a5793446..6875bc13b8fa 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_condition.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { #[pallet::task_index(0)] #[pallet::task_condition(0)] diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.rs b/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.rs index 00c5112a0ec5..2a4b40523a68 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_index.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { #[pallet::task_index("0")] fn foo() -> DispatchResult { diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.rs b/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.rs index 516f89687d12..bb6438aaf105 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_list.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { #[pallet::task_index(0)] #[pallet::task_condition(|| true)] diff --git a/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.rs b/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.rs index 392446173a80..a0c4040347a0 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_invalid_weight.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { #[pallet::task_index(0)] #[pallet::task_condition(|| true)] diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.rs index 814b2241ca32..6ca6e37a5bdb 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_condition.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { #[pallet::task_index(0)] fn foo() -> DispatchResult { diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs index 55a947e906e4..ed98d229f18b 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_index.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { fn foo() -> DispatchResult { Ok(()) diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs index c83e0ba2c614..427efe127634 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_list.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { #[pallet::task_index(0)] #[pallet::task_condition(|| true)] diff --git a/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs b/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs index 2f2186337e86..704be1f1e0b8 100644 --- a/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs +++ b/substrate/frame/support/test/tests/pallet_ui/task_missing_weight.rs @@ -26,7 +26,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::tasks] + #[pallet::tasks_experimental] impl Pallet { #[pallet::task_index(0)] #[pallet::task_condition(|| true)] From 2fd452a881fb55f384d939cb2aed9eec44fd7e18 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:21:17 +0530 Subject: [PATCH 176/177] Updates PrDoc --- prdoc/pr_1343.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_1343.prdoc b/prdoc/pr_1343.prdoc index bddcdc76f541..84168230e0af 100644 --- a/prdoc/pr_1343.prdoc +++ b/prdoc/pr_1343.prdoc @@ -5,7 +5,7 @@ doc: description: | The Tasks API allows you to define some service work that can be recognized by a script or an off-chain worker. Such a script can then create and submit all such work items at any given time. - `#[pallet:tasks]` provides a convenient way to define such work items. It can be attached to an + `#[pallet:tasks_experimental]` provides a convenient way to define such work items. It can be attached to an `impl` block inside a pallet, whose functions can then be annotated by the following attributes: 1. `#[pallet::task_list]`: Define an iterator over the available work items for a task 2. `#[pallet::task_condition]`: Define the conditions for a given work item to be valid From 3c6b00afbb20cf335bdeeb044395826d20d68b22 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 7 Dec 2023 04:59:46 +0000 Subject: [PATCH 177/177] ".git/.scripts/commands/fmt/fmt.sh" --- .../support/procedural/src/pallet/parse/mod.rs | 5 ++++- .../support/procedural/src/pallet/parse/tasks.rs | 7 ++++--- substrate/frame/support/src/lib.rs | 16 +++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index b97f8b4c5ed7..e1efdbcc2027 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -275,7 +275,10 @@ impl Def { // ensure that if `task_enum` is specified, `tasks` is also specified match (&task_enum, &tasks) { (Some(_), None) => - return Err(syn::Error::new(*item_span, "Missing `#[pallet::tasks_experimental]` impl")), + return Err(syn::Error::new( + *item_span, + "Missing `#[pallet::tasks_experimental]` impl", + )), (None, Some(tasks)) => if tasks.tasks_attr.is_none() { return Err(syn::Error::new( diff --git a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs index 5b8deced40d9..6405bb415a6f 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/tasks.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/tasks.rs @@ -50,8 +50,8 @@ pub mod keywords { custom_keyword!(pallet); } -/// Represents the `#[pallet::tasks_experimental]` attribute and its attached item. Also includes metadata -/// about the linked [`TaskEnumDef`] if applicable. +/// Represents the `#[pallet::tasks_experimental]` attribute and its attached item. Also includes +/// metadata about the linked [`TaskEnumDef`] if applicable. #[derive(Clone, Debug)] pub struct TasksDef { pub tasks_attr: Option, @@ -125,7 +125,8 @@ impl syn::parse::Parse for TasksDef { /// Parsing for a `#[pallet::tasks_experimental]` attr. pub type PalletTasksAttr = PalletTaskAttr; -/// Parsing for any of the attributes that can be used within a `#[pallet::tasks_experimental]` [`ItemImpl`]. +/// Parsing for any of the attributes that can be used within a `#[pallet::tasks_experimental]` +/// [`ItemImpl`]. pub type TaskAttr = PalletTaskAttr; /// Parsing for a `#[pallet::task_index]` attr. diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index d7ad33ae2b20..af1f99be1031 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -2675,7 +2675,7 @@ pub mod pallet_macros { /// ``` pub use frame_support_procedural::storage; /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks_experimental`](`tasks_experimental`) to define the conditions for a + /// [`pallet::tasks_experimental`](`tasks_experimental`) to define the conditions for a /// given work item to be valid. /// /// It takes a closure as input, which is then used to define the condition. The closure @@ -2683,20 +2683,22 @@ pub mod pallet_macros { /// return a `bool` instead. pub use frame_support_procedural::task_condition; /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks_experimental`](`tasks_experimental`) to define the index of a given work item. + /// [`pallet::tasks_experimental`](`tasks_experimental`) to define the index of a given + /// work item. /// /// It takes an integer literal as input, which is then used to define the index. This /// index should be unique for each function in the `impl` block. pub use frame_support_procedural::task_index; /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks_experimental`](`tasks_experimental`) to define an iterator over the + /// [`pallet::tasks_experimental`](`tasks_experimental`) to define an iterator over the /// available work items for a task. /// /// It takes an iterator as input that yields a tuple with same types as the function /// arguments. pub use frame_support_procedural::task_list; /// This attribute is attached to a function inside an `impl` block annoated with - /// [`pallet::tasks_experimental`](`tasks_experimental`) define the weight of a given work item. + /// [`pallet::tasks_experimental`](`tasks_experimental`) define the weight of a given work + /// item. /// /// It takes a closure as input, which should return a `Weight` value. pub use frame_support_procedural::task_weight; @@ -2705,9 +2707,9 @@ pub mod pallet_macros { /// given time. /// /// These work items are defined as instances of the [`Task`](frame_support::traits::Task) - /// trait. [`pallet:tasks_experimental`](`tasks_experimental`) when attached to an `impl` block - /// inside a pallet, will generate an enum `Task` whose variants are mapped to functions - /// inside this `impl` block. + /// trait. [`pallet:tasks_experimental`](`tasks_experimental`) when attached to an `impl` + /// block inside a pallet, will generate an enum `Task` whose variants are mapped to + /// functions inside this `impl` block. /// /// Each such function must have the following set of attributes: ///