Skip to content

Commit

Permalink
Use real rust type for pallet alias in runtime macro (paritytech#4769)
Browse files Browse the repository at this point in the history
Fixes paritytech#4723. Also,
closes paritytech#4622

As stated in the linked issue, this PR adds the ability to use a real
rust type for pallet alias in the new `runtime` macro:
```rust
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Runtime>;
```

Please note that the current syntax still continues to be supported.

CC: @shawntabrizi @kianenigma

---------

Co-authored-by: command-bot <>
Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
2 people authored and TarekkMA committed Aug 2, 2024
1 parent 5daa834 commit 0bf8e0b
Show file tree
Hide file tree
Showing 12 changed files with 538 additions and 179 deletions.
20 changes: 20 additions & 0 deletions prdoc/pr_4769.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
title: Use real rust type for pallet alias in `runtime` macro

doc:
- audience: Runtime Dev
description: |
This PR adds the ability to use a real rust type for pallet alias in the new `runtime` macro:
```rust
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Runtime>;
```

Please note that the current syntax still continues to be supported.

crates:
- name: frame-support-procedural
bump: patch
- name: frame-support
bump: patch
- name: minimal-template-runtime
bump: patch
160 changes: 80 additions & 80 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2241,248 +2241,248 @@ mod runtime {
pub struct Runtime;

#[runtime::pallet_index(0)]
pub type System = frame_system;
pub type System = frame_system::Pallet<Runtime>;

#[runtime::pallet_index(1)]
pub type Utility = pallet_utility;
pub type Utility = pallet_utility::Pallet<Runtime>;

#[runtime::pallet_index(2)]
pub type Babe = pallet_babe;
pub type Babe = pallet_babe::Pallet<Runtime>;

#[runtime::pallet_index(3)]
pub type Timestamp = pallet_timestamp;
pub type Timestamp = pallet_timestamp::Pallet<Runtime>;

// Authorship must be before session in order to note author in the correct session and era
// for im-online and staking.
#[runtime::pallet_index(4)]
pub type Authorship = pallet_authorship;
pub type Authorship = pallet_authorship::Pallet<Runtime>;

#[runtime::pallet_index(5)]
pub type Indices = pallet_indices;
pub type Indices = pallet_indices::Pallet<Runtime>;

#[runtime::pallet_index(6)]
pub type Balances = pallet_balances;
pub type Balances = pallet_balances::Pallet<Runtime>;

#[runtime::pallet_index(7)]
pub type TransactionPayment = pallet_transaction_payment;
pub type TransactionPayment = pallet_transaction_payment::Pallet<Runtime>;

#[runtime::pallet_index(8)]
pub type AssetTxPayment = pallet_asset_tx_payment;
pub type AssetTxPayment = pallet_asset_tx_payment::Pallet<Runtime>;

#[runtime::pallet_index(9)]
pub type AssetConversionTxPayment = pallet_asset_conversion_tx_payment;
pub type AssetConversionTxPayment = pallet_asset_conversion_tx_payment::Pallet<Runtime>;

#[runtime::pallet_index(10)]
pub type ElectionProviderMultiPhase = pallet_election_provider_multi_phase;
pub type ElectionProviderMultiPhase = pallet_election_provider_multi_phase::Pallet<Runtime>;

#[runtime::pallet_index(11)]
pub type Staking = pallet_staking;
pub type Staking = pallet_staking::Pallet<Runtime>;

#[runtime::pallet_index(12)]
pub type Session = pallet_session;
pub type Session = pallet_session::Pallet<Runtime>;

#[runtime::pallet_index(13)]
pub type Democracy = pallet_democracy;
pub type Democracy = pallet_democracy::Pallet<Runtime>;

#[runtime::pallet_index(14)]
pub type Council = pallet_collective<Instance1>;
pub type Council = pallet_collective::Pallet<Runtime, Instance1>;

#[runtime::pallet_index(15)]
pub type TechnicalCommittee = pallet_collective<Instance2>;
pub type TechnicalCommittee = pallet_collective::Pallet<Runtime, Instance2>;

#[runtime::pallet_index(16)]
pub type Elections = pallet_elections_phragmen;
pub type Elections = pallet_elections_phragmen::Pallet<Runtime>;

#[runtime::pallet_index(17)]
pub type TechnicalMembership = pallet_membership<Instance1>;
pub type TechnicalMembership = pallet_membership::Pallet<Runtime, Instance1>;

#[runtime::pallet_index(18)]
pub type Grandpa = pallet_grandpa;
pub type Grandpa = pallet_grandpa::Pallet<Runtime>;

#[runtime::pallet_index(19)]
pub type Treasury = pallet_treasury;
pub type Treasury = pallet_treasury::Pallet<Runtime>;

#[runtime::pallet_index(20)]
pub type AssetRate = pallet_asset_rate;
pub type AssetRate = pallet_asset_rate::Pallet<Runtime>;

#[runtime::pallet_index(21)]
pub type Contracts = pallet_contracts;
pub type Contracts = pallet_contracts::Pallet<Runtime>;

#[runtime::pallet_index(22)]
pub type Sudo = pallet_sudo;
pub type Sudo = pallet_sudo::Pallet<Runtime>;

#[runtime::pallet_index(23)]
pub type ImOnline = pallet_im_online;
pub type ImOnline = pallet_im_online::Pallet<Runtime>;

#[runtime::pallet_index(24)]
pub type AuthorityDiscovery = pallet_authority_discovery;
pub type AuthorityDiscovery = pallet_authority_discovery::Pallet<Runtime>;

#[runtime::pallet_index(25)]
pub type Offences = pallet_offences;
pub type Offences = pallet_offences::Pallet<Runtime>;

#[runtime::pallet_index(26)]
pub type Historical = pallet_session_historical;
pub type Historical = pallet_session_historical::Pallet<Runtime>;

#[runtime::pallet_index(27)]
pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip;
pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip::Pallet<Runtime>;

#[runtime::pallet_index(28)]
pub type Identity = pallet_identity;
pub type Identity = pallet_identity::Pallet<Runtime>;

#[runtime::pallet_index(29)]
pub type Society = pallet_society;
pub type Society = pallet_society::Pallet<Runtime>;

#[runtime::pallet_index(30)]
pub type Recovery = pallet_recovery;
pub type Recovery = pallet_recovery::Pallet<Runtime>;

#[runtime::pallet_index(31)]
pub type Vesting = pallet_vesting;
pub type Vesting = pallet_vesting::Pallet<Runtime>;

#[runtime::pallet_index(32)]
pub type Scheduler = pallet_scheduler;
pub type Scheduler = pallet_scheduler::Pallet<Runtime>;

#[runtime::pallet_index(33)]
pub type Glutton = pallet_glutton;
pub type Glutton = pallet_glutton::Pallet<Runtime>;

#[runtime::pallet_index(34)]
pub type Preimage = pallet_preimage;
pub type Preimage = pallet_preimage::Pallet<Runtime>;

#[runtime::pallet_index(35)]
pub type Proxy = pallet_proxy;
pub type Proxy = pallet_proxy::Pallet<Runtime>;

#[runtime::pallet_index(36)]
pub type Multisig = pallet_multisig;
pub type Multisig = pallet_multisig::Pallet<Runtime>;

#[runtime::pallet_index(37)]
pub type Bounties = pallet_bounties;
pub type Bounties = pallet_bounties::Pallet<Runtime>;

#[runtime::pallet_index(38)]
pub type Tips = pallet_tips;
pub type Tips = pallet_tips::Pallet<Runtime>;

#[runtime::pallet_index(39)]
pub type Assets = pallet_assets<Instance1>;
pub type Assets = pallet_assets::Pallet<Runtime, Instance1>;

#[runtime::pallet_index(40)]
pub type PoolAssets = pallet_assets<Instance2>;
pub type PoolAssets = pallet_assets::Pallet<Runtime, Instance2>;

#[runtime::pallet_index(41)]
pub type Beefy = pallet_beefy;
pub type Beefy = pallet_beefy::Pallet<Runtime>;

// MMR leaf construction must be after session in order to have a leaf's next_auth_set
// refer to block<N>. See issue polkadot-fellows/runtimes#160 for details.
#[runtime::pallet_index(42)]
pub type Mmr = pallet_mmr;
pub type Mmr = pallet_mmr::Pallet<Runtime>;

#[runtime::pallet_index(43)]
pub type MmrLeaf = pallet_beefy_mmr;
pub type MmrLeaf = pallet_beefy_mmr::Pallet<Runtime>;

#[runtime::pallet_index(44)]
pub type Lottery = pallet_lottery;
pub type Lottery = pallet_lottery::Pallet<Runtime>;

#[runtime::pallet_index(45)]
pub type Nis = pallet_nis;
pub type Nis = pallet_nis::Pallet<Runtime>;

#[runtime::pallet_index(46)]
pub type Uniques = pallet_uniques;
pub type Uniques = pallet_uniques::Pallet<Runtime>;

#[runtime::pallet_index(47)]
pub type Nfts = pallet_nfts;
pub type Nfts = pallet_nfts::Pallet<Runtime>;

#[runtime::pallet_index(48)]
pub type NftFractionalization = pallet_nft_fractionalization;
pub type NftFractionalization = pallet_nft_fractionalization::Pallet<Runtime>;

#[runtime::pallet_index(49)]
pub type Salary = pallet_salary;
pub type Salary = pallet_salary::Pallet<Runtime>;

#[runtime::pallet_index(50)]
pub type CoreFellowship = pallet_core_fellowship;
pub type CoreFellowship = pallet_core_fellowship::Pallet<Runtime>;

#[runtime::pallet_index(51)]
pub type TransactionStorage = pallet_transaction_storage;
pub type TransactionStorage = pallet_transaction_storage::Pallet<Runtime>;

#[runtime::pallet_index(52)]
pub type VoterList = pallet_bags_list<Instance1>;
pub type VoterList = pallet_bags_list::Pallet<Runtime, Instance1>;

#[runtime::pallet_index(53)]
pub type StateTrieMigration = pallet_state_trie_migration;
pub type StateTrieMigration = pallet_state_trie_migration::Pallet<Runtime>;

#[runtime::pallet_index(54)]
pub type ChildBounties = pallet_child_bounties;
pub type ChildBounties = pallet_child_bounties::Pallet<Runtime>;

#[runtime::pallet_index(55)]
pub type Referenda = pallet_referenda;
pub type Referenda = pallet_referenda::Pallet<Runtime>;

#[runtime::pallet_index(56)]
pub type Remark = pallet_remark;
pub type Remark = pallet_remark::Pallet<Runtime>;

#[runtime::pallet_index(57)]
pub type RootTesting = pallet_root_testing;
pub type RootTesting = pallet_root_testing::Pallet<Runtime>;

#[runtime::pallet_index(58)]
pub type ConvictionVoting = pallet_conviction_voting;
pub type ConvictionVoting = pallet_conviction_voting::Pallet<Runtime>;

#[runtime::pallet_index(59)]
pub type Whitelist = pallet_whitelist;
pub type Whitelist = pallet_whitelist::Pallet<Runtime>;

#[runtime::pallet_index(60)]
pub type AllianceMotion = pallet_collective<Instance3>;
pub type AllianceMotion = pallet_collective::Pallet<Runtime, Instance3>;

#[runtime::pallet_index(61)]
pub type Alliance = pallet_alliance;
pub type Alliance = pallet_alliance::Pallet<Runtime>;

#[runtime::pallet_index(62)]
pub type NominationPools = pallet_nomination_pools;
pub type NominationPools = pallet_nomination_pools::Pallet<Runtime>;

#[runtime::pallet_index(63)]
pub type RankedPolls = pallet_referenda<Instance2>;
pub type RankedPolls = pallet_referenda::Pallet<Runtime, Instance2>;

#[runtime::pallet_index(64)]
pub type RankedCollective = pallet_ranked_collective;
pub type RankedCollective = pallet_ranked_collective::Pallet<Runtime>;

#[runtime::pallet_index(65)]
pub type AssetConversion = pallet_asset_conversion;
pub type AssetConversion = pallet_asset_conversion::Pallet<Runtime>;

#[runtime::pallet_index(66)]
pub type FastUnstake = pallet_fast_unstake;
pub type FastUnstake = pallet_fast_unstake::Pallet<Runtime>;

#[runtime::pallet_index(67)]
pub type MessageQueue = pallet_message_queue;
pub type MessageQueue = pallet_message_queue::Pallet<Runtime>;

#[runtime::pallet_index(68)]
pub type Pov = frame_benchmarking_pallet_pov;
pub type Pov = frame_benchmarking_pallet_pov::Pallet<Runtime>;

#[runtime::pallet_index(69)]
pub type TxPause = pallet_tx_pause;
pub type TxPause = pallet_tx_pause::Pallet<Runtime>;

#[runtime::pallet_index(70)]
pub type SafeMode = pallet_safe_mode;
pub type SafeMode = pallet_safe_mode::Pallet<Runtime>;

#[runtime::pallet_index(71)]
pub type Statement = pallet_statement;
pub type Statement = pallet_statement::Pallet<Runtime>;

#[runtime::pallet_index(72)]
pub type MultiBlockMigrations = pallet_migrations;
pub type MultiBlockMigrations = pallet_migrations::Pallet<Runtime>;

#[runtime::pallet_index(73)]
pub type Broker = pallet_broker;
pub type Broker = pallet_broker::Pallet<Runtime>;

#[runtime::pallet_index(74)]
pub type TasksExample = pallet_example_tasks;
pub type TasksExample = pallet_example_tasks::Pallet<Runtime>;

#[runtime::pallet_index(75)]
pub type Mixnet = pallet_mixnet;
pub type Mixnet = pallet_mixnet::Pallet<Runtime>;

#[runtime::pallet_index(76)]
pub type Parameters = pallet_parameters;
pub type Parameters = pallet_parameters::Pallet<Runtime>;

#[runtime::pallet_index(77)]
pub type SkipFeelessPayment = pallet_skip_feeless_payment;
pub type SkipFeelessPayment = pallet_skip_feeless_payment::Pallet<Runtime>;

#[runtime::pallet_index(78)]
pub type PalletExampleMbms = pallet_example_mbm;
pub type PalletExampleMbms = pallet_example_mbm::Pallet<Runtime>;

#[runtime::pallet_index(79)]
pub type AssetConversionMigration = pallet_asset_conversion_ops;
pub type AssetConversionMigration = pallet_asset_conversion_ops::Pallet<Runtime>;
}

/// The address format for describing accounts.
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/procedural/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cfg-expr = { workspace = true }
itertools = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn = { features = ["full", "visit-mut"], workspace = true }
syn = { features = ["full", "parsing", "visit-mut"], workspace = true }
frame-support-procedural-tools = { workspace = true, default-features = true }
macro_magic = { features = ["proc_support"], workspace = true }
proc-macro-warning = { workspace = true }
Expand Down
Loading

0 comments on commit 0bf8e0b

Please sign in to comment.