Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct Runtime v2 #1378

Merged
merged 64 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
496bbac
Moves from older repo
gupnik Sep 4, 2023
cec8668
Adds disable_unsigned
gupnik Sep 5, 2023
73327a1
Fixes kitchensink build
gupnik Sep 5, 2023
40919d7
Merge branch 'master' into gupnik/crv2
gupnik Sep 5, 2023
99a43cf
Makes pallet_index mandatory
gupnik Sep 6, 2023
1467f0a
Adds UI Test
gupnik Sep 6, 2023
140e05f
Merge branch 'master' into gupnik/crv2
gupnik Sep 7, 2023
6568852
Adds UI Tests
gupnik Sep 11, 2023
2a70549
Minor CI fixes
gupnik Sep 11, 2023
6a59057
Merge branch 'master' into gupnik/crv2
gupnik Sep 11, 2023
9beb3ba
Adds more UI tests
gupnik Sep 12, 2023
88fa35a
Adds some docs
gupnik Sep 12, 2023
8ab5c66
Updates tests for construct_runtime_v2
gupnik Sep 13, 2023
977a553
Adds docs
gupnik Sep 13, 2023
c232d49
Merge branch 'master' into gupnik/crv2
gupnik Sep 13, 2023
df4fc3d
Minor update in doc
gupnik Sep 13, 2023
88fa662
Minor updates
gupnik Sep 13, 2023
a3d9319
Removes Todo
gupnik Sep 15, 2023
d5dd8ec
Merge branch 'master' into gupnik/crv2
gupnik Sep 15, 2023
e2ab4f6
Addresses review comments
gupnik Sep 18, 2023
ed2d9e9
Merge branch 'master' into gupnik/crv2
gupnik Sep 18, 2023
d1cd1a9
Update substrate/frame/support/procedural/src/construct_runtime_v2/mo…
gupnik Sep 19, 2023
2df5888
Update substrate/frame/support/procedural/src/construct_runtime_v2/ex…
gupnik Sep 19, 2023
51f1a70
Addresses review comment
gupnik Sep 19, 2023
996fefe
Uses type alias for pallets
gupnik Sep 25, 2023
fc3b765
Merge branch 'master' of github.com:paritytech/polkadot-sdk into gupn…
Oct 12, 2023
0498dc4
Updates as per latest syntax
Oct 12, 2023
502fda4
Renames construct_runtime_v2 to runtime
Oct 12, 2023
e8b5371
Fixes kitchensink build
Oct 12, 2023
dcc0b60
Updates tests and docs
Oct 12, 2023
8a4b13c
fmt
Oct 12, 2023
1e44e9b
Minor fix
Oct 12, 2023
6660575
Minor fixes
Oct 12, 2023
9aa6aaf
Merge branch 'master' of github.com:paritytech/polkadot-sdk into gupn…
gupnik Feb 3, 2024
985faef
Adds missing pallets in v2
gupnik Feb 3, 2024
5be682d
Fixes build and adds RuntimeTask support
gupnik Feb 8, 2024
aba35c6
Fixes test
gupnik Feb 8, 2024
7733d61
Adds task to tt_default_parts_v2
gupnik Feb 8, 2024
143ba02
Merge branch 'master' into gupnik/crv2
codekitz Feb 8, 2024
0774bca
Adds TaskExample in v2
gupnik Feb 8, 2024
2c17eda
Fixes UI Tests
gupnik Feb 9, 2024
61fb110
Merge branch 'master' of github.com:paritytech/polkadot-sdk into gupn…
gupnik Feb 9, 2024
19db6d7
Updates docs
gupnik Feb 12, 2024
69a49a4
Adds legacy_ordering
gupnik Feb 12, 2024
dd1df58
Adds UI Test for legacy_ordering
gupnik Feb 13, 2024
c3c0be3
Fixes UT
gupnik Feb 13, 2024
a8fd228
Updates docs
gupnik Feb 13, 2024
044d106
Merge branch 'master' into gupnik/crv2
codekitz Feb 13, 2024
2f8b62c
".git/.scripts/commands/fmt/fmt.sh"
Feb 13, 2024
c779b74
Adds PrDoc
gupnik Feb 13, 2024
d1c976b
Merge branch 'gupnik/crv2' of github.com:paritytech/polkadot-sdk into…
gupnik Feb 13, 2024
1aac057
Minor fix
gupnik Feb 13, 2024
d150a5b
Updates docs
gupnik Feb 14, 2024
7ad4fc7
Update prdoc/pr_1378.prdoc
codekitz Feb 14, 2024
d22e45b
Addresses review comments
gupnik Feb 19, 2024
017bd41
Merge branch 'master' into gupnik/crv2
codekitz Feb 19, 2024
0aeb0f3
Fmt
gupnik Feb 19, 2024
a5401ed
Merge branch 'gupnik/crv2' of github.com:paritytech/polkadot-sdk into…
gupnik Feb 19, 2024
fcdb613
Merge branch 'master' into gupnik/crv2
codekitz Feb 27, 2024
761cedb
Incorporates changes for improved error reporting
gupnik Feb 27, 2024
e5c7f79
Merge branch 'master' of github.com:paritytech/polkadot-sdk into gupn…
gupnik Mar 11, 2024
97a4425
Minor fix
gupnik Mar 11, 2024
29c2259
Feature gates under experimental
gupnik Mar 13, 2024
d71dbbc
Minor fix
gupnik Mar 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions prdoc/pr_1378.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
title: Construct Runtime V2 - An outer macro approach to define the runtime

doc:
- audience: Runtime Dev
description: |
Introduces `#[frame_support::runtime]` that can be attached to a mod to define a runtime. The items
in this mod can be attached to the following attributes to define the key components of the runtime.
1. `#[runtime::runtime]` attached to a struct defines the main runtime
2. `#[runtime::derive]` attached to the runtime struct defines the types generated by the runtime
3. `#[runtime::pallet_index]` must be attached to a pallet to define its index
4. `#[runtime::disable_call]` can be optionally attached to a pallet to disable its calls
5. `#[runtime::disable_unsigned]` can be optionally attached to a pallet to disable unsigned calls
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
6. 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkchr do you have an opinion on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Not sure this is such a great idea (ordering based on the index). But also wasn't the idea that this would be changed with the new Poll logic? Aka that the runtime implementor needs to explicitly state this order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Not sure this is such a great idea (ordering based on the index).

I thought this was causing a lot of issues as the user expectation would be to have everything as per the pallet_index. I would also imagine this to be better but please let me know your concerns.

But also wasn't the idea that this would be changed with the new Poll logic? Aka that the runtime implementor needs to explicitly state this order?

I am not aware of this. Could you please link the issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the poll hook it can explicitly be set, yes. But my question was about the on_initialize etc that have fixed order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was causing a lot of issues as the user expectation would be to have everything as per the pallet_index

Yeah that is a good point 👍

For the poll hook it can explicitly be set, yes. But my question was about the on_initialize etc that have fixed order.

If we have poll explicit and have everything fixed up with on_initialize, the order of on_initialize shouldn't be that important anymore. By "fixed up" on_initialize I mean that pallets should not call into other pallets in this stage if possible, to not run into race conditions that stuff is not yet setup. They should setup their own state and then in poll they can do whatever they need.


migrations:
db: []

runtime: []

crates:
- name: frame-support
- name: frame-support-procedural

host_functions: []
2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sp-io = { path = "../../../primitives/io", default-features = false }
frame-executive = { path = "../../../frame/executive", default-features = false }
frame-benchmarking = { path = "../../../frame/benchmarking", default-features = false }
frame-benchmarking-pallet-pov = { path = "../../../frame/benchmarking/pov", default-features = false }
frame-support = { path = "../../../frame/support", default-features = false, features = ["tuples-96"] }
frame-support = { path = "../../../frame/support", default-features = false, features = ["experimental", "tuples-96"] }
frame-system = { path = "../../../frame/system", default-features = false }
frame-system-benchmarking = { path = "../../../frame/system/benchmarking", default-features = false, optional = true }
frame-election-provider-support = { path = "../../../frame/election-provider-support", default-features = false }
Expand Down
342 changes: 255 additions & 87 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use frame_election_provider_support::{
onchain, BalancingConfig, ElectionDataProvider, SequentialPhragmen, VoteWeight,
};
use frame_support::{
construct_runtime, derive_impl,
derive_impl,
dispatch::DispatchClass,
dynamic_params::{dynamic_pallet_params, dynamic_params},
genesis_builder_helper::{build_config, create_default_config},
Expand Down Expand Up @@ -2196,92 +2196,260 @@ impl pallet_parameters::Config for Runtime {
type WeightInfo = ();
}

construct_runtime!(
pub enum Runtime {
System: frame_system,
Utility: pallet_utility,
Babe: pallet_babe,
Timestamp: pallet_timestamp,
// Authorship must be before session in order to note author in the correct session and era
// for im-online and staking.
Authorship: pallet_authorship,
Indices: pallet_indices,
Balances: pallet_balances,
TransactionPayment: pallet_transaction_payment,
AssetTxPayment: pallet_asset_tx_payment,
AssetConversionTxPayment: pallet_asset_conversion_tx_payment,
ElectionProviderMultiPhase: pallet_election_provider_multi_phase,
Staking: pallet_staking,
Session: pallet_session,
Democracy: pallet_democracy,
Council: pallet_collective::<Instance1>,
TechnicalCommittee: pallet_collective::<Instance2>,
Elections: pallet_elections_phragmen,
TechnicalMembership: pallet_membership::<Instance1>,
Grandpa: pallet_grandpa,
Treasury: pallet_treasury,
AssetRate: pallet_asset_rate,
Contracts: pallet_contracts,
Sudo: pallet_sudo,
ImOnline: pallet_im_online,
AuthorityDiscovery: pallet_authority_discovery,
Offences: pallet_offences,
Historical: pallet_session_historical,
RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip,
Identity: pallet_identity,
Society: pallet_society,
Recovery: pallet_recovery,
Vesting: pallet_vesting,
Scheduler: pallet_scheduler,
Glutton: pallet_glutton,
Preimage: pallet_preimage,
Proxy: pallet_proxy,
Multisig: pallet_multisig,
Bounties: pallet_bounties,
Tips: pallet_tips,
Assets: pallet_assets::<Instance1>,
PoolAssets: pallet_assets::<Instance2>,
Beefy: pallet_beefy,
// 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.
Mmr: pallet_mmr,
MmrLeaf: pallet_beefy_mmr,
Lottery: pallet_lottery,
Nis: pallet_nis,
Uniques: pallet_uniques,
Nfts: pallet_nfts,
NftFractionalization: pallet_nft_fractionalization,
Salary: pallet_salary,
CoreFellowship: pallet_core_fellowship,
TransactionStorage: pallet_transaction_storage,
VoterList: pallet_bags_list::<Instance1>,
StateTrieMigration: pallet_state_trie_migration,
ChildBounties: pallet_child_bounties,
Referenda: pallet_referenda,
Remark: pallet_remark,
RootTesting: pallet_root_testing,
ConvictionVoting: pallet_conviction_voting,
Whitelist: pallet_whitelist,
AllianceMotion: pallet_collective::<Instance3>,
Alliance: pallet_alliance,
NominationPools: pallet_nomination_pools,
RankedPolls: pallet_referenda::<Instance2>,
RankedCollective: pallet_ranked_collective,
AssetConversion: pallet_asset_conversion,
FastUnstake: pallet_fast_unstake,
MessageQueue: pallet_message_queue,
Pov: frame_benchmarking_pallet_pov,
TxPause: pallet_tx_pause,
SafeMode: pallet_safe_mode,
Statement: pallet_statement,
MultiBlockMigrations: pallet_migrations,
Broker: pallet_broker,
TasksExample: pallet_example_tasks,
Mixnet: pallet_mixnet,
Parameters: pallet_parameters,
SkipFeelessPayment: pallet_skip_feeless_payment,
}
);
#[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 Utility = pallet_utility;

#[runtime::pallet_index(2)]
pub type Babe = pallet_babe;

#[runtime::pallet_index(3)]
pub type Timestamp = pallet_timestamp;

// 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;

#[runtime::pallet_index(5)]
pub type Indices = pallet_indices;

#[runtime::pallet_index(6)]
pub type Balances = pallet_balances;

#[runtime::pallet_index(7)]
pub type TransactionPayment = pallet_transaction_payment;

#[runtime::pallet_index(8)]
pub type AssetTxPayment = pallet_asset_tx_payment;

#[runtime::pallet_index(9)]
pub type AssetConversionTxPayment = pallet_asset_conversion_tx_payment;

#[runtime::pallet_index(10)]
pub type ElectionProviderMultiPhase = pallet_election_provider_multi_phase;

#[runtime::pallet_index(11)]
pub type Staking = pallet_staking;

#[runtime::pallet_index(12)]
pub type Session = pallet_session;

#[runtime::pallet_index(13)]
pub type Democracy = pallet_democracy;

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

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

#[runtime::pallet_index(16)]
pub type Elections = pallet_elections_phragmen;

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

#[runtime::pallet_index(18)]
pub type Grandpa = pallet_grandpa;

#[runtime::pallet_index(19)]
pub type Treasury = pallet_treasury;

#[runtime::pallet_index(20)]
pub type AssetRate = pallet_asset_rate;

#[runtime::pallet_index(21)]
pub type Contracts = pallet_contracts;

#[runtime::pallet_index(22)]
pub type Sudo = pallet_sudo;

#[runtime::pallet_index(23)]
pub type ImOnline = pallet_im_online;

#[runtime::pallet_index(24)]
pub type AuthorityDiscovery = pallet_authority_discovery;

#[runtime::pallet_index(25)]
pub type Offences = pallet_offences;

#[runtime::pallet_index(26)]
pub type Historical = pallet_session_historical;

#[runtime::pallet_index(27)]
pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip;

#[runtime::pallet_index(28)]
pub type Identity = pallet_identity;

#[runtime::pallet_index(29)]
pub type Society = pallet_society;

#[runtime::pallet_index(30)]
pub type Recovery = pallet_recovery;

#[runtime::pallet_index(31)]
pub type Vesting = pallet_vesting;

#[runtime::pallet_index(32)]
pub type Scheduler = pallet_scheduler;

#[runtime::pallet_index(33)]
pub type Glutton = pallet_glutton;

#[runtime::pallet_index(34)]
pub type Preimage = pallet_preimage;

#[runtime::pallet_index(35)]
pub type Proxy = pallet_proxy;

#[runtime::pallet_index(36)]
pub type Multisig = pallet_multisig;

#[runtime::pallet_index(37)]
pub type Bounties = pallet_bounties;

#[runtime::pallet_index(38)]
pub type Tips = pallet_tips;

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

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

#[runtime::pallet_index(41)]
pub type Beefy = pallet_beefy;

// 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;

#[runtime::pallet_index(43)]
pub type MmrLeaf = pallet_beefy_mmr;

#[runtime::pallet_index(44)]
pub type Lottery = pallet_lottery;

#[runtime::pallet_index(45)]
pub type Nis = pallet_nis;

#[runtime::pallet_index(46)]
pub type Uniques = pallet_uniques;

#[runtime::pallet_index(47)]
pub type Nfts = pallet_nfts;

#[runtime::pallet_index(48)]
pub type NftFractionalization = pallet_nft_fractionalization;

#[runtime::pallet_index(49)]
pub type Salary = pallet_salary;

#[runtime::pallet_index(50)]
pub type CoreFellowship = pallet_core_fellowship;

#[runtime::pallet_index(51)]
pub type TransactionStorage = pallet_transaction_storage;

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

#[runtime::pallet_index(53)]
pub type StateTrieMigration = pallet_state_trie_migration;

#[runtime::pallet_index(54)]
pub type ChildBounties = pallet_child_bounties;

#[runtime::pallet_index(55)]
pub type Referenda = pallet_referenda;

#[runtime::pallet_index(56)]
pub type Remark = pallet_remark;

#[runtime::pallet_index(57)]
pub type RootTesting = pallet_root_testing;

#[runtime::pallet_index(58)]
pub type ConvictionVoting = pallet_conviction_voting;

#[runtime::pallet_index(59)]
pub type Whitelist = pallet_whitelist;

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

#[runtime::pallet_index(61)]
pub type Alliance = pallet_alliance;

#[runtime::pallet_index(62)]
pub type NominationPools = pallet_nomination_pools;

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

#[runtime::pallet_index(64)]
pub type RankedCollective = pallet_ranked_collective;

#[runtime::pallet_index(65)]
pub type AssetConversion = pallet_asset_conversion;

#[runtime::pallet_index(66)]
pub type FastUnstake = pallet_fast_unstake;

#[runtime::pallet_index(67)]
pub type MessageQueue = pallet_message_queue;

#[runtime::pallet_index(68)]
pub type Pov = frame_benchmarking_pallet_pov;

#[runtime::pallet_index(69)]
pub type TxPause = pallet_tx_pause;

#[runtime::pallet_index(70)]
pub type SafeMode = pallet_safe_mode;

#[runtime::pallet_index(71)]
pub type Statement = pallet_statement;

#[runtime::pallet_index(72)]
pub type MultiBlockMigrations = pallet_migrations;

#[runtime::pallet_index(73)]
pub type Broker = pallet_broker;

#[runtime::pallet_index(74)]
pub type TasksExample = pallet_example_tasks;

#[runtime::pallet_index(75)]
pub type Mixnet = pallet_mixnet;

#[runtime::pallet_index(76)]
pub type Parameters = pallet_parameters;

#[runtime::pallet_index(77)]
pub type SkipFeelessPayment = pallet_skip_feeless_payment;
}

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