Skip to content

Commit 768af06

Browse files
committed
chore: use construct runtime v2
1 parent bc1b5a6 commit 768af06

5 files changed

Lines changed: 95 additions & 44 deletions

File tree

prdoc/pr_4684.prdoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: "Refactor of the parachain template"
2+
3+
doc:
4+
- audience: Runtime Dev
5+
description: |
6+
Introduce the construct runtime V2 to the parachain template runtime. In addition, url links in the parachain pallet
7+
template now direct to the polkadot sdk docs.
8+
9+
crates: [ ]

templates/parachain/pallets/template/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ scale-info = { version = "2.11.1", default-features = false, features = [
2222

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

2828
[dev-dependencies]

templates/parachain/pallets/template/src/mock.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@ use frame_system::{mocking::MockBlock, GenesisConfig};
33
use sp_runtime::{traits::ConstU64, BuildStorage};
44

55
// Configure a mock runtime to test the pallet.
6-
frame_support::construct_runtime!(
7-
pub struct Test {
8-
System: frame_system,
9-
TemplateModule: crate,
10-
}
11-
);
6+
#[frame_support::runtime]
7+
mod test_runtime {
8+
#[runtime::runtime]
9+
#[runtime::derive(
10+
RuntimeCall,
11+
RuntimeEvent,
12+
RuntimeError,
13+
RuntimeOrigin,
14+
RuntimeFreezeReason,
15+
RuntimeHoldReason,
16+
RuntimeSlashReason,
17+
RuntimeLockId,
18+
RuntimeTask
19+
)]
20+
pub struct Test;
21+
22+
#[runtime::pallet_index(0)]
23+
pub type System = frame_system;
24+
#[runtime::pallet_index(1)]
25+
pub type TemplateModule = crate;
26+
}
1227

1328
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
1429
impl frame_system::Config for Test {

templates/parachain/runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pallet-parachain-template = { path = "../pallets/template", default-features = f
3535
frame-benchmarking = { path = "../../../substrate/frame/benchmarking", default-features = false, optional = true }
3636
frame-executive = { path = "../../../substrate/frame/executive", default-features = false }
3737
frame-metadata-hash-extension = { path = "../../../substrate/frame/metadata-hash-extension", default-features = false }
38-
frame-support = { path = "../../../substrate/frame/support", default-features = false }
38+
frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["experimental"] }
3939
frame-system = { path = "../../../substrate/frame/system", default-features = false }
4040
frame-system-benchmarking = { path = "../../../substrate/frame/system/benchmarking", default-features = false, optional = true }
4141
frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false }

templates/parachain/runtime/src/lib.rs

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
88

99
pub mod apis;
10+
#[cfg(feature = "runtime-benchmarks")]
11+
mod benchmarks;
1012
mod configs;
1113
mod weights;
1214

@@ -23,7 +25,6 @@ use sp_version::NativeVersion;
2325
use sp_version::RuntimeVersion;
2426

2527
use frame_support::{
26-
construct_runtime,
2728
weights::{
2829
constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient,
2930
WeightToFeeCoefficients, WeightToFeePolynomial,
@@ -232,43 +233,69 @@ pub fn native_version() -> NativeVersion {
232233
}
233234

234235
// Create the runtime by composing the FRAME pallets that were previously configured.
235-
construct_runtime!(
236-
pub enum Runtime {
237-
// System support stuff.
238-
System: frame_system = 0,
239-
ParachainSystem: cumulus_pallet_parachain_system = 1,
240-
Timestamp: pallet_timestamp = 2,
241-
ParachainInfo: parachain_info = 3,
242-
243-
// Monetary stuff.
244-
Balances: pallet_balances = 10,
245-
TransactionPayment: pallet_transaction_payment = 11,
246-
247-
// Governance
248-
Sudo: pallet_sudo = 15,
249-
250-
// Collator support. The order of these 4 are important and shall not change.
251-
Authorship: pallet_authorship = 20,
252-
CollatorSelection: pallet_collator_selection = 21,
253-
Session: pallet_session = 22,
254-
Aura: pallet_aura = 23,
255-
AuraExt: cumulus_pallet_aura_ext = 24,
256-
257-
// XCM helpers.
258-
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
259-
PolkadotXcm: pallet_xcm = 31,
260-
CumulusXcm: cumulus_pallet_xcm = 32,
261-
MessageQueue: pallet_message_queue = 33,
262-
263-
// Template
264-
TemplatePallet: pallet_parachain_template = 50,
265-
}
266-
);
236+
#[frame_support::runtime]
237+
mod runtime {
238+
#[runtime::runtime]
239+
#[runtime::derive(
240+
RuntimeCall,
241+
RuntimeEvent,
242+
RuntimeError,
243+
RuntimeOrigin,
244+
RuntimeFreezeReason,
245+
RuntimeHoldReason,
246+
RuntimeSlashReason,
247+
RuntimeLockId,
248+
RuntimeTask
249+
)]
250+
pub struct Runtime;
251+
252+
#[runtime::pallet_index(0)]
253+
pub type System = frame_system;
254+
#[runtime::pallet_index(1)]
255+
pub type ParachainSystem = cumulus_pallet_parachain_system ;
256+
#[runtime::pallet_index(2)]
257+
pub type Timestamp = pallet_timestamp;
258+
#[runtime::pallet_index(3)]
259+
pub type ParachainInfo = parachain_info;
260+
261+
// Monetary stuff.
262+
#[runtime::pallet_index(10)]
263+
pub type Balances = pallet_balances;
264+
#[runtime::pallet_index(11)]
265+
pub type TransactionPayment = pallet_transaction_payment;
266+
267+
// Governance
268+
#[runtime::pallet_index(15)]
269+
pub type Sudo = pallet_sudo;
270+
271+
// Collator support. The order of these 4 are important and shall not change.
272+
#[runtime::pallet_index(20)]
273+
pub type Authorship = pallet_authorship;
274+
#[runtime::pallet_index(21)]
275+
pub type CollatorSelection = pallet_collator_selection;
276+
#[runtime::pallet_index(22)]
277+
pub type Session = pallet_session;
278+
#[runtime::pallet_index(23)]
279+
pub type Aura = pallet_aura;
280+
#[runtime::pallet_index(24)]
281+
pub type AuraExt = cumulus_pallet_aura_ext;
282+
283+
// XCM helpers.
284+
#[runtime::pallet_index(30)]
285+
pub type XcmpQueue = cumulus_pallet_xcmp_queue;
286+
#[runtime::pallet_index(31)]
287+
pub type PolkadotXcm = pallet_xcm;
288+
#[runtime::pallet_index(32)]
289+
pub type CumulusXcm = cumulus_pallet_xcm;
290+
#[runtime::pallet_index(33)]
291+
pub type MessageQueue = pallet_message_queue;
292+
#[runtime::pallet_index(50)]
293+
294+
// Include the custom logic from the pallet-template in the runtime.
295+
pub type TemplatePallet = pallet_parachain_template;
296+
}
267297

268298
cumulus_pallet_parachain_system::register_validate_block! {
269299
Runtime = Runtime,
270300
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
271301
}
272-
273-
#[cfg(feature = "runtime-benchmarks")]
274-
mod benchmarks;

0 commit comments

Comments
 (0)