paritytech / substrate

Substrate: The platform for blockchain innovators
Apache License 2.0
8.39k stars 2.65k forks source link

[WIP]: Construct Runtime v2 #14788

Open gupnik opened 1 year ago

gupnik commented 1 year ago

Fixes https://github.com/paritytech/polkadot-sdk/issues/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

Todo

Extension

paritytech-cicd-pr commented 1 year ago

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 commented 1 year ago
  • #[frame::pallet_index] can be optionally attached to a pallet to override its index

The index should be required and not be optional.

gupnik commented 1 year ago
  • #[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 commented 1 year ago

The indexes should be obligatory.