Skip to content

Commit

Permalink
chore: use construct runtime v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Jun 15, 2024
1 parent bc1b5a6 commit 768af06
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 44 deletions.
9 changes: 9 additions & 0 deletions prdoc/pr_4684.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: "Refactor of the parachain template"

doc:
- audience: Runtime Dev
description: |
Introduce the construct runtime V2 to the parachain template runtime. In addition, url links in the parachain pallet
template now direct to the polkadot sdk docs.

crates: [ ]
2 changes: 1 addition & 1 deletion templates/parachain/pallets/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ scale-info = { version = "2.11.1", default-features = false, features = [

# frame deps
frame-benchmarking = { path = "../../../../substrate/frame/benchmarking", default-features = false, optional = true }
frame-support = { path = "../../../../substrate/frame/support", default-features = false }
frame-support = { path = "../../../../substrate/frame/support", default-features = false, features = ["experimental"] }
frame-system = { path = "../../../../substrate/frame/system", default-features = false }

[dev-dependencies]
Expand Down
27 changes: 21 additions & 6 deletions templates/parachain/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@ use frame_system::{mocking::MockBlock, GenesisConfig};
use sp_runtime::{traits::ConstU64, BuildStorage};

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub struct Test {
System: frame_system,
TemplateModule: crate,
}
);
#[frame_support::runtime]
mod test_runtime {
#[runtime::runtime]
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeFreezeReason,
RuntimeHoldReason,
RuntimeSlashReason,
RuntimeLockId,
RuntimeTask
)]
pub struct Test;

#[runtime::pallet_index(0)]
pub type System = frame_system;
#[runtime::pallet_index(1)]
pub type TemplateModule = crate;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
Expand Down
2 changes: 1 addition & 1 deletion templates/parachain/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pallet-parachain-template = { path = "../pallets/template", default-features = f
frame-benchmarking = { path = "../../../substrate/frame/benchmarking", default-features = false, optional = true }
frame-executive = { path = "../../../substrate/frame/executive", default-features = false }
frame-metadata-hash-extension = { path = "../../../substrate/frame/metadata-hash-extension", default-features = false }
frame-support = { path = "../../../substrate/frame/support", default-features = false }
frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["experimental"] }
frame-system = { path = "../../../substrate/frame/system", default-features = false }
frame-system-benchmarking = { path = "../../../substrate/frame/system/benchmarking", default-features = false, optional = true }
frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false }
Expand Down
99 changes: 63 additions & 36 deletions templates/parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

pub mod apis;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarks;
mod configs;
mod weights;

Expand All @@ -23,7 +25,6 @@ use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use frame_support::{
construct_runtime,
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient,
WeightToFeeCoefficients, WeightToFeePolynomial,
Expand Down Expand Up @@ -232,43 +233,69 @@ pub fn native_version() -> NativeVersion {
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime {
// System support stuff.
System: frame_system = 0,
ParachainSystem: cumulus_pallet_parachain_system = 1,
Timestamp: pallet_timestamp = 2,
ParachainInfo: parachain_info = 3,

// Monetary stuff.
Balances: pallet_balances = 10,
TransactionPayment: pallet_transaction_payment = 11,

// Governance
Sudo: pallet_sudo = 15,

// Collator support. The order of these 4 are important and shall not change.
Authorship: pallet_authorship = 20,
CollatorSelection: pallet_collator_selection = 21,
Session: pallet_session = 22,
Aura: pallet_aura = 23,
AuraExt: cumulus_pallet_aura_ext = 24,

// XCM helpers.
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
PolkadotXcm: pallet_xcm = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
MessageQueue: pallet_message_queue = 33,

// Template
TemplatePallet: pallet_parachain_template = 50,
}
);
#[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 ParachainSystem = cumulus_pallet_parachain_system ;
#[runtime::pallet_index(2)]
pub type Timestamp = pallet_timestamp;
#[runtime::pallet_index(3)]
pub type ParachainInfo = parachain_info;

// Monetary stuff.
#[runtime::pallet_index(10)]
pub type Balances = pallet_balances;
#[runtime::pallet_index(11)]
pub type TransactionPayment = pallet_transaction_payment;

// Governance
#[runtime::pallet_index(15)]
pub type Sudo = pallet_sudo;

// Collator support. The order of these 4 are important and shall not change.
#[runtime::pallet_index(20)]
pub type Authorship = pallet_authorship;
#[runtime::pallet_index(21)]
pub type CollatorSelection = pallet_collator_selection;
#[runtime::pallet_index(22)]
pub type Session = pallet_session;
#[runtime::pallet_index(23)]
pub type Aura = pallet_aura;
#[runtime::pallet_index(24)]
pub type AuraExt = cumulus_pallet_aura_ext;

// XCM helpers.
#[runtime::pallet_index(30)]
pub type XcmpQueue = cumulus_pallet_xcmp_queue;
#[runtime::pallet_index(31)]
pub type PolkadotXcm = pallet_xcm;
#[runtime::pallet_index(32)]
pub type CumulusXcm = cumulus_pallet_xcm;
#[runtime::pallet_index(33)]
pub type MessageQueue = pallet_message_queue;
#[runtime::pallet_index(50)]

// Include the custom logic from the pallet-template in the runtime.
pub type TemplatePallet = pallet_parachain_template;
}

cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}

#[cfg(feature = "runtime-benchmarks")]
mod benchmarks;

0 comments on commit 768af06

Please sign in to comment.