Skip to content

Commit c09768f

Browse files
Construct Runtime v2 (paritytech#1378)
Moved from paritytech/substrate#14788 ---- Fixes paritytech#232 This PR introduces outer-macro approach for `construct_runtime` as discussed in the linked issue. It looks like the following: ```rust #[frame_support::runtime] mod runtime { #[runtime::runtime] #[runtime::derive( RuntimeCall, RuntimeEvent, RuntimeError, RuntimeOrigin, RuntimeFreezeReason, RuntimeHoldReason, RuntimeSlashReason, RuntimeLockId, RuntimeTask, )] pub struct Runtime; #[runtime::pallet_index(0)] pub type System = frame_system; #[runtime::pallet_index(1)] pub type Timestamp = pallet_timestamp; #[runtime::pallet_index(2)] pub type Aura = pallet_aura; #[runtime::pallet_index(3)] pub type Grandpa = pallet_grandpa; #[runtime::pallet_index(4)] pub type Balances = pallet_balances; #[runtime::pallet_index(5)] pub type TransactionPayment = pallet_transaction_payment; #[runtime::pallet_index(6)] pub type Sudo = pallet_sudo; // Include the custom logic from the pallet-template in the runtime. #[runtime::pallet_index(7)] pub type TemplateModule = pallet_template; } ``` ## Features - `#[runtime::runtime]` attached to a struct defines the main runtime - `#[runtime::derive]` attached to this struct defines the types generated by runtime - `#[runtime::pallet_index]` must be attached to a pallet to define its index - `#[runtime::disable_call]` can be optionally attached to a pallet to disable its calls - `#[runtime::disable_unsigned]` can be optionally attached to a pallet to disable unsigned calls - A pallet instance can be defined as `TemplateModule: pallet_template<Instance>` - An optional attribute can be defined as `#[frame_support::runtime(legacy_ordering)]` to ensure that the order of hooks is same as the order of pallets (and not based on the pallet_index). This is to support legacy runtimes and should be avoided for new ones. ## Todo - [x] Update the latest syntax in kitchensink and tests - [x] Update UI tests - [x] Docs ## Extension - Abstract away the Executive similar to paritytech/substrate#14742 - Optionally avoid the need to specify all runtime types (TBD) --------- Co-authored-by: Francisco Aguirre <[email protected]> Co-authored-by: Nikhil Gupta <>
1 parent b764deb commit c09768f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3143
-190
lines changed

substrate/bin/node/runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ sp-io = { path = "../../../primitives/io", default-features = false }
5858
frame-executive = { path = "../../../frame/executive", default-features = false }
5959
frame-benchmarking = { path = "../../../frame/benchmarking", default-features = false }
6060
frame-benchmarking-pallet-pov = { path = "../../../frame/benchmarking/pov", default-features = false }
61-
frame-support = { path = "../../../frame/support", default-features = false, features = ["tuples-96"] }
61+
frame-support = { path = "../../../frame/support", default-features = false, features = ["experimental", "tuples-96"] }
6262
frame-system = { path = "../../../frame/system", default-features = false }
6363
frame-system-benchmarking = { path = "../../../frame/system/benchmarking", default-features = false, optional = true }
6464
frame-election-provider-support = { path = "../../../frame/election-provider-support", default-features = false }

substrate/bin/node/runtime/src/lib.rs

Lines changed: 255 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use frame_election_provider_support::{
2828
onchain, BalancingConfig, ElectionDataProvider, SequentialPhragmen, VoteWeight,
2929
};
3030
use frame_support::{
31-
construct_runtime, derive_impl,
31+
derive_impl,
3232
dispatch::DispatchClass,
3333
dynamic_params::{dynamic_pallet_params, dynamic_params},
3434
genesis_builder_helper::{build_config, create_default_config},
@@ -2196,92 +2196,260 @@ impl pallet_parameters::Config for Runtime {
21962196
type WeightInfo = ();
21972197
}
21982198

2199-
construct_runtime!(
2200-
pub enum Runtime {
2201-
System: frame_system,
2202-
Utility: pallet_utility,
2203-
Babe: pallet_babe,
2204-
Timestamp: pallet_timestamp,
2205-
// Authorship must be before session in order to note author in the correct session and era
2206-
// for im-online and staking.
2207-
Authorship: pallet_authorship,
2208-
Indices: pallet_indices,
2209-
Balances: pallet_balances,
2210-
TransactionPayment: pallet_transaction_payment,
2211-
AssetTxPayment: pallet_asset_tx_payment,
2212-
AssetConversionTxPayment: pallet_asset_conversion_tx_payment,
2213-
ElectionProviderMultiPhase: pallet_election_provider_multi_phase,
2214-
Staking: pallet_staking,
2215-
Session: pallet_session,
2216-
Democracy: pallet_democracy,
2217-
Council: pallet_collective::<Instance1>,
2218-
TechnicalCommittee: pallet_collective::<Instance2>,
2219-
Elections: pallet_elections_phragmen,
2220-
TechnicalMembership: pallet_membership::<Instance1>,
2221-
Grandpa: pallet_grandpa,
2222-
Treasury: pallet_treasury,
2223-
AssetRate: pallet_asset_rate,
2224-
Contracts: pallet_contracts,
2225-
Sudo: pallet_sudo,
2226-
ImOnline: pallet_im_online,
2227-
AuthorityDiscovery: pallet_authority_discovery,
2228-
Offences: pallet_offences,
2229-
Historical: pallet_session_historical,
2230-
RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip,
2231-
Identity: pallet_identity,
2232-
Society: pallet_society,
2233-
Recovery: pallet_recovery,
2234-
Vesting: pallet_vesting,
2235-
Scheduler: pallet_scheduler,
2236-
Glutton: pallet_glutton,
2237-
Preimage: pallet_preimage,
2238-
Proxy: pallet_proxy,
2239-
Multisig: pallet_multisig,
2240-
Bounties: pallet_bounties,
2241-
Tips: pallet_tips,
2242-
Assets: pallet_assets::<Instance1>,
2243-
PoolAssets: pallet_assets::<Instance2>,
2244-
Beefy: pallet_beefy,
2245-
// MMR leaf construction must be after session in order to have a leaf's next_auth_set
2246-
// refer to block<N>. See issue polkadot-fellows/runtimes#160 for details.
2247-
Mmr: pallet_mmr,
2248-
MmrLeaf: pallet_beefy_mmr,
2249-
Lottery: pallet_lottery,
2250-
Nis: pallet_nis,
2251-
Uniques: pallet_uniques,
2252-
Nfts: pallet_nfts,
2253-
NftFractionalization: pallet_nft_fractionalization,
2254-
Salary: pallet_salary,
2255-
CoreFellowship: pallet_core_fellowship,
2256-
TransactionStorage: pallet_transaction_storage,
2257-
VoterList: pallet_bags_list::<Instance1>,
2258-
StateTrieMigration: pallet_state_trie_migration,
2259-
ChildBounties: pallet_child_bounties,
2260-
Referenda: pallet_referenda,
2261-
Remark: pallet_remark,
2262-
RootTesting: pallet_root_testing,
2263-
ConvictionVoting: pallet_conviction_voting,
2264-
Whitelist: pallet_whitelist,
2265-
AllianceMotion: pallet_collective::<Instance3>,
2266-
Alliance: pallet_alliance,
2267-
NominationPools: pallet_nomination_pools,
2268-
RankedPolls: pallet_referenda::<Instance2>,
2269-
RankedCollective: pallet_ranked_collective,
2270-
AssetConversion: pallet_asset_conversion,
2271-
FastUnstake: pallet_fast_unstake,
2272-
MessageQueue: pallet_message_queue,
2273-
Pov: frame_benchmarking_pallet_pov,
2274-
TxPause: pallet_tx_pause,
2275-
SafeMode: pallet_safe_mode,
2276-
Statement: pallet_statement,
2277-
MultiBlockMigrations: pallet_migrations,
2278-
Broker: pallet_broker,
2279-
TasksExample: pallet_example_tasks,
2280-
Mixnet: pallet_mixnet,
2281-
Parameters: pallet_parameters,
2282-
SkipFeelessPayment: pallet_skip_feeless_payment,
2283-
}
2284-
);
2199+
#[frame_support::runtime]
2200+
mod runtime {
2201+
#[runtime::runtime]
2202+
#[runtime::derive(
2203+
RuntimeCall,
2204+
RuntimeEvent,
2205+
RuntimeError,
2206+
RuntimeOrigin,
2207+
RuntimeFreezeReason,
2208+
RuntimeHoldReason,
2209+
RuntimeSlashReason,
2210+
RuntimeLockId,
2211+
RuntimeTask
2212+
)]
2213+
pub struct Runtime;
2214+
2215+
#[runtime::pallet_index(0)]
2216+
pub type System = frame_system;
2217+
2218+
#[runtime::pallet_index(1)]
2219+
pub type Utility = pallet_utility;
2220+
2221+
#[runtime::pallet_index(2)]
2222+
pub type Babe = pallet_babe;
2223+
2224+
#[runtime::pallet_index(3)]
2225+
pub type Timestamp = pallet_timestamp;
2226+
2227+
// Authorship must be before session in order to note author in the correct session and era
2228+
// for im-online and staking.
2229+
#[runtime::pallet_index(4)]
2230+
pub type Authorship = pallet_authorship;
2231+
2232+
#[runtime::pallet_index(5)]
2233+
pub type Indices = pallet_indices;
2234+
2235+
#[runtime::pallet_index(6)]
2236+
pub type Balances = pallet_balances;
2237+
2238+
#[runtime::pallet_index(7)]
2239+
pub type TransactionPayment = pallet_transaction_payment;
2240+
2241+
#[runtime::pallet_index(8)]
2242+
pub type AssetTxPayment = pallet_asset_tx_payment;
2243+
2244+
#[runtime::pallet_index(9)]
2245+
pub type AssetConversionTxPayment = pallet_asset_conversion_tx_payment;
2246+
2247+
#[runtime::pallet_index(10)]
2248+
pub type ElectionProviderMultiPhase = pallet_election_provider_multi_phase;
2249+
2250+
#[runtime::pallet_index(11)]
2251+
pub type Staking = pallet_staking;
2252+
2253+
#[runtime::pallet_index(12)]
2254+
pub type Session = pallet_session;
2255+
2256+
#[runtime::pallet_index(13)]
2257+
pub type Democracy = pallet_democracy;
2258+
2259+
#[runtime::pallet_index(14)]
2260+
pub type Council = pallet_collective<Instance1>;
2261+
2262+
#[runtime::pallet_index(15)]
2263+
pub type TechnicalCommittee = pallet_collective<Instance2>;
2264+
2265+
#[runtime::pallet_index(16)]
2266+
pub type Elections = pallet_elections_phragmen;
2267+
2268+
#[runtime::pallet_index(17)]
2269+
pub type TechnicalMembership = pallet_membership<Instance1>;
2270+
2271+
#[runtime::pallet_index(18)]
2272+
pub type Grandpa = pallet_grandpa;
2273+
2274+
#[runtime::pallet_index(19)]
2275+
pub type Treasury = pallet_treasury;
2276+
2277+
#[runtime::pallet_index(20)]
2278+
pub type AssetRate = pallet_asset_rate;
2279+
2280+
#[runtime::pallet_index(21)]
2281+
pub type Contracts = pallet_contracts;
2282+
2283+
#[runtime::pallet_index(22)]
2284+
pub type Sudo = pallet_sudo;
2285+
2286+
#[runtime::pallet_index(23)]
2287+
pub type ImOnline = pallet_im_online;
2288+
2289+
#[runtime::pallet_index(24)]
2290+
pub type AuthorityDiscovery = pallet_authority_discovery;
2291+
2292+
#[runtime::pallet_index(25)]
2293+
pub type Offences = pallet_offences;
2294+
2295+
#[runtime::pallet_index(26)]
2296+
pub type Historical = pallet_session_historical;
2297+
2298+
#[runtime::pallet_index(27)]
2299+
pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip;
2300+
2301+
#[runtime::pallet_index(28)]
2302+
pub type Identity = pallet_identity;
2303+
2304+
#[runtime::pallet_index(29)]
2305+
pub type Society = pallet_society;
2306+
2307+
#[runtime::pallet_index(30)]
2308+
pub type Recovery = pallet_recovery;
2309+
2310+
#[runtime::pallet_index(31)]
2311+
pub type Vesting = pallet_vesting;
2312+
2313+
#[runtime::pallet_index(32)]
2314+
pub type Scheduler = pallet_scheduler;
2315+
2316+
#[runtime::pallet_index(33)]
2317+
pub type Glutton = pallet_glutton;
2318+
2319+
#[runtime::pallet_index(34)]
2320+
pub type Preimage = pallet_preimage;
2321+
2322+
#[runtime::pallet_index(35)]
2323+
pub type Proxy = pallet_proxy;
2324+
2325+
#[runtime::pallet_index(36)]
2326+
pub type Multisig = pallet_multisig;
2327+
2328+
#[runtime::pallet_index(37)]
2329+
pub type Bounties = pallet_bounties;
2330+
2331+
#[runtime::pallet_index(38)]
2332+
pub type Tips = pallet_tips;
2333+
2334+
#[runtime::pallet_index(39)]
2335+
pub type Assets = pallet_assets<Instance1>;
2336+
2337+
#[runtime::pallet_index(40)]
2338+
pub type PoolAssets = pallet_assets<Instance2>;
2339+
2340+
#[runtime::pallet_index(41)]
2341+
pub type Beefy = pallet_beefy;
2342+
2343+
// MMR leaf construction must be after session in order to have a leaf's next_auth_set
2344+
// refer to block<N>. See issue polkadot-fellows/runtimes#160 for details.
2345+
#[runtime::pallet_index(42)]
2346+
pub type Mmr = pallet_mmr;
2347+
2348+
#[runtime::pallet_index(43)]
2349+
pub type MmrLeaf = pallet_beefy_mmr;
2350+
2351+
#[runtime::pallet_index(44)]
2352+
pub type Lottery = pallet_lottery;
2353+
2354+
#[runtime::pallet_index(45)]
2355+
pub type Nis = pallet_nis;
2356+
2357+
#[runtime::pallet_index(46)]
2358+
pub type Uniques = pallet_uniques;
2359+
2360+
#[runtime::pallet_index(47)]
2361+
pub type Nfts = pallet_nfts;
2362+
2363+
#[runtime::pallet_index(48)]
2364+
pub type NftFractionalization = pallet_nft_fractionalization;
2365+
2366+
#[runtime::pallet_index(49)]
2367+
pub type Salary = pallet_salary;
2368+
2369+
#[runtime::pallet_index(50)]
2370+
pub type CoreFellowship = pallet_core_fellowship;
2371+
2372+
#[runtime::pallet_index(51)]
2373+
pub type TransactionStorage = pallet_transaction_storage;
2374+
2375+
#[runtime::pallet_index(52)]
2376+
pub type VoterList = pallet_bags_list<Instance1>;
2377+
2378+
#[runtime::pallet_index(53)]
2379+
pub type StateTrieMigration = pallet_state_trie_migration;
2380+
2381+
#[runtime::pallet_index(54)]
2382+
pub type ChildBounties = pallet_child_bounties;
2383+
2384+
#[runtime::pallet_index(55)]
2385+
pub type Referenda = pallet_referenda;
2386+
2387+
#[runtime::pallet_index(56)]
2388+
pub type Remark = pallet_remark;
2389+
2390+
#[runtime::pallet_index(57)]
2391+
pub type RootTesting = pallet_root_testing;
2392+
2393+
#[runtime::pallet_index(58)]
2394+
pub type ConvictionVoting = pallet_conviction_voting;
2395+
2396+
#[runtime::pallet_index(59)]
2397+
pub type Whitelist = pallet_whitelist;
2398+
2399+
#[runtime::pallet_index(60)]
2400+
pub type AllianceMotion = pallet_collective<Instance3>;
2401+
2402+
#[runtime::pallet_index(61)]
2403+
pub type Alliance = pallet_alliance;
2404+
2405+
#[runtime::pallet_index(62)]
2406+
pub type NominationPools = pallet_nomination_pools;
2407+
2408+
#[runtime::pallet_index(63)]
2409+
pub type RankedPolls = pallet_referenda<Instance2>;
2410+
2411+
#[runtime::pallet_index(64)]
2412+
pub type RankedCollective = pallet_ranked_collective;
2413+
2414+
#[runtime::pallet_index(65)]
2415+
pub type AssetConversion = pallet_asset_conversion;
2416+
2417+
#[runtime::pallet_index(66)]
2418+
pub type FastUnstake = pallet_fast_unstake;
2419+
2420+
#[runtime::pallet_index(67)]
2421+
pub type MessageQueue = pallet_message_queue;
2422+
2423+
#[runtime::pallet_index(68)]
2424+
pub type Pov = frame_benchmarking_pallet_pov;
2425+
2426+
#[runtime::pallet_index(69)]
2427+
pub type TxPause = pallet_tx_pause;
2428+
2429+
#[runtime::pallet_index(70)]
2430+
pub type SafeMode = pallet_safe_mode;
2431+
2432+
#[runtime::pallet_index(71)]
2433+
pub type Statement = pallet_statement;
2434+
2435+
#[runtime::pallet_index(72)]
2436+
pub type MultiBlockMigrations = pallet_migrations;
2437+
2438+
#[runtime::pallet_index(73)]
2439+
pub type Broker = pallet_broker;
2440+
2441+
#[runtime::pallet_index(74)]
2442+
pub type TasksExample = pallet_example_tasks;
2443+
2444+
#[runtime::pallet_index(75)]
2445+
pub type Mixnet = pallet_mixnet;
2446+
2447+
#[runtime::pallet_index(76)]
2448+
pub type Parameters = pallet_parameters;
2449+
2450+
#[runtime::pallet_index(77)]
2451+
pub type SkipFeelessPayment = pallet_skip_feeless_payment;
2452+
}
22852453

22862454
/// The address format for describing accounts.
22872455
pub type Address = sp_runtime::MultiAddress<AccountId, AccountIndex>;

substrate/frame/support/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ try-runtime = [
109109
"sp-debug-derive/force-debug",
110110
"sp-runtime/try-runtime",
111111
]
112-
experimental = []
112+
experimental = [
113+
"frame-support-procedural/experimental",
114+
]
113115
# By default some types have documentation, `no-metadata-docs` allows to reduce the documentation
114116
# in the metadata.
115117
no-metadata-docs = [

substrate/frame/support/procedural/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ regex = "1"
3838
default = ["std"]
3939
std = ["sp-crypto-hashing/std"]
4040
no-metadata-docs = []
41+
experimental = []
4142
# Generate impl-trait for tuples with the given number of tuples. Will be needed as the number of
4243
# pallets in a runtime grows. Does increase the compile time!
4344
tuples-96 = []

0 commit comments

Comments
 (0)