Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[WIP]: Construct Runtime v2 #14788

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft

[WIP]: Construct Runtime v2 #14788

wants to merge 22 commits into from

Conversation

gupnik
Copy link
Contributor

@gupnik gupnik commented Aug 18, 2023

Fixes paritytech/polkadot-sdk#232

This PR introduces outer-macro approach for construct_runtime as discussed in the linked issue. It looks like the following:

#[frame_support::construct_runtime_v2]
mod runtime {
	#[frame::runtime]
	pub struct Runtime;

	#[frame::pallets]
	#[frame::derive(
		RuntimeCall,
		RuntimeEvent,
		RuntimeError,
		RuntimeOrigin,
		RuntimeFreezeReason,
		RuntimeHoldReason,
		RuntimeSlashReason,
		RuntimeLockId
	)]
	pub struct Pallets {
		System: frame_system,
		Timestamp: pallet_timestamp,
		Aura: pallet_aura,
		Grandpa: pallet_grandpa,
		Balances: pallet_balances,
		TransactionPayment: pallet_transaction_payment,
		Sudo: pallet_sudo,
		// Include the custom logic from the pallet-template in the runtime.
		#[frame::pallet_index(8)]
		#[frame::disable_call]
		TemplateModule: pallet_template,
	}
}

Features

  • #[frame::runtime] attached to a struct defines the main runtime
  • #[frame::pallets] attached to a struct defines the pallets in the runtime
  • #[frame::derive] attached to this struct defines the types generated by construct_runtime
  • #[frame::pallet_index] can be optionally attached to a pallet to override its index
  • #[frame::disable_call] can be optionally attached to a pallet to disable its calls
  • A pallet instance can be defined as TemplateModule: pallet_template<Instance>

Todo

  • #[frame::disable_unsigned] to disable unsigned calls
  • Errors and Edge-cases
  • UI tests
  • Docs

Extension

@gupnik gupnik added A3-in_progress Pull request is in progress. No review needed at this stage. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit B1-note_worthy Changes should be noted in the release notes T1-runtime This PR/Issue is related to the topic “runtime”. labels Aug 18, 2023
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable-int
Logs: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/3413012

@bkchr
Copy link
Member

bkchr commented Aug 18, 2023

  • #[frame::pallet_index] can be optionally attached to a pallet to override its index

The index should be required and not be optional.

@gupnik
Copy link
Contributor Author

gupnik commented Aug 19, 2023

  • #[frame::pallet_index] can be optionally attached to a pallet to override its index

The index should be required and not be optional.

@bkchr By default, the index is derived from the order in which the pallets appear in the struct. If this attribute is specified, this default index is overridden. This is consistent with the current behaviour of construct_runtime. Do we want to get rid of this altogether?

@bkchr
Copy link
Member

bkchr commented Aug 21, 2023

The indexes should be obligatory.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A3-in_progress Pull request is in progress. No review needed at this stage. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make construct_runtime macro more flexible
3 participants