penpal_runtime/
lib.rs

1// This file is part of Cumulus.
2// SPDX-License-Identifier: Unlicense
3
4// This is free and unencumbered software released into the public domain.
5
6// Anyone is free to copy, modify, publish, use, compile, sell, or
7// distribute this software, either in source code form or as a compiled
8// binary, for any purpose, commercial or non-commercial, and by any
9// means.
10
11// In jurisdictions that recognize copyright laws, the author or authors
12// of this software dedicate any and all copyright interest in the
13// software to the public domain. We make this dedication for the benefit
14// of the public at large and to the detriment of our heirs and
15// successors. We intend this dedication to be an overt act of
16// relinquishment in perpetuity of all present and future rights to this
17// software under copyright law.
18
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25// OTHER DEALINGS IN THE SOFTWARE.
26
27// For more information, please refer to <http://unlicense.org/>
28
29//! The PenPal runtime is designed as a test runtime that can be created with an arbitrary `ParaId`,
30//! such that multiple instances of the parachain can be on the same parent relay. Ensure that you
31//! have enough nodes running to support this or you will get scheduling errors.
32//!
33//! The PenPal runtime's primary use is for testing interactions between System parachains and
34//! other chains that are not trusted teleporters.
35
36#![cfg_attr(not(feature = "std"), no_std)]
37// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
38#![recursion_limit = "256"]
39
40// Make the WASM binary available.
41#[cfg(feature = "std")]
42include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
43
44mod genesis_config_presets;
45mod weights;
46pub mod xcm_config;
47
48extern crate alloc;
49
50use alloc::{vec, vec::Vec};
51use assets_common::{
52	foreign_creators::ForeignCreators,
53	local_and_foreign_assets::{LocalFromLeft, TargetFromLeft},
54	AssetIdForTrustBackedAssetsConvert,
55};
56use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
57use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
58use frame_support::{
59	construct_runtime, derive_impl,
60	dispatch::DispatchClass,
61	genesis_builder_helper::{build_state, get_preset},
62	ord_parameter_types,
63	pallet_prelude::Weight,
64	parameter_types,
65	traits::{
66		tokens::{fungible, fungibles, imbalance::ResolveAssetTo},
67		AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Everything,
68		TransformOrigin,
69	},
70	weights::{
71		constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, FeePolynomial,
72		WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
73	},
74	PalletId,
75};
76use frame_system::{
77	limits::{BlockLength, BlockWeights},
78	EnsureRoot, EnsureSigned, EnsureSignedBy,
79};
80use pallet_revive::evm::runtime::EthExtra;
81use parachains_common::{
82	impls::{AssetsToBlockAuthor, NonZeroIssuance},
83	message_queue::{NarrowOriginToSibling, ParaIdToSibling},
84};
85use smallvec::smallvec;
86use sp_api::impl_runtime_apis;
87pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
88use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
89use sp_runtime::{
90	generic, impl_opaque_keys,
91	traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT},
92	transaction_validity::{TransactionSource, TransactionValidity},
93	ApplyExtrinsicResult, FixedU128,
94};
95pub use sp_runtime::{traits::ConvertInto, MultiAddress, Perbill, Permill};
96#[cfg(feature = "std")]
97use sp_version::NativeVersion;
98use sp_version::RuntimeVersion;
99use xcm_config::{ForeignAssetsAssetId, LocationToAccountId, XcmOriginToTransactDispatchOrigin};
100
101#[cfg(any(feature = "std", test))]
102pub use sp_runtime::BuildStorage;
103
104use parachains_common::{AccountId, Signature};
105use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
106use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
107use xcm::{
108	latest::prelude::{AssetId as AssetLocationId, BodyId},
109	Version as XcmVersion, VersionedAsset, VersionedAssetId, VersionedAssets, VersionedLocation,
110	VersionedXcm,
111};
112use xcm_runtime_apis::{
113	dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
114	fees::Error as XcmPaymentApiError,
115};
116
117/// Balance of an account.
118pub type Balance = u128;
119
120/// Index of a transaction in the chain.
121pub type Nonce = u32;
122
123/// A hash of some data used by the chain.
124pub type Hash = sp_core::H256;
125
126/// An index to a block.
127pub type BlockNumber = u32;
128
129/// The address format for describing accounts.
130pub type Address = MultiAddress<AccountId, ()>;
131
132/// Block header type as expected by this runtime.
133pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
134
135/// Block type as expected by this runtime.
136pub type Block = generic::Block<Header, UncheckedExtrinsic>;
137
138/// A Block signed with a Justification
139pub type SignedBlock = generic::SignedBlock<Block>;
140
141/// BlockId type as expected by this runtime.
142pub type BlockId = generic::BlockId<Block>;
143
144// Id used for identifying assets.
145pub type AssetId = u32;
146
147/// The extension to the basic transaction logic.
148pub type TxExtension = (
149	frame_system::AuthorizeCall<Runtime>,
150	frame_system::CheckNonZeroSender<Runtime>,
151	frame_system::CheckSpecVersion<Runtime>,
152	frame_system::CheckTxVersion<Runtime>,
153	frame_system::CheckGenesis<Runtime>,
154	frame_system::CheckEra<Runtime>,
155	frame_system::CheckNonce<Runtime>,
156	frame_system::CheckWeight<Runtime>,
157	pallet_asset_tx_payment::ChargeAssetTxPayment<Runtime>,
158	frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
159	pallet_revive::evm::tx_extension::SetOrigin<Runtime>,
160	frame_system::WeightReclaim<Runtime>,
161);
162
163/// Default extensions applied to Ethereum transactions.
164#[derive(Clone, PartialEq, Eq, Debug)]
165pub struct EthExtraImpl;
166
167impl EthExtra for EthExtraImpl {
168	type Config = Runtime;
169	type Extension = TxExtension;
170
171	fn get_eth_extension(nonce: u32, tip: Balance) -> Self::Extension {
172		(
173			frame_system::AuthorizeCall::<Runtime>::new(),
174			frame_system::CheckNonZeroSender::<Runtime>::new(),
175			frame_system::CheckSpecVersion::<Runtime>::new(),
176			frame_system::CheckTxVersion::<Runtime>::new(),
177			frame_system::CheckGenesis::<Runtime>::new(),
178			frame_system::CheckEra::<Runtime>::from(generic::Era::Immortal),
179			frame_system::CheckNonce::<Runtime>::from(nonce),
180			frame_system::CheckWeight::<Runtime>::new(),
181			pallet_asset_tx_payment::ChargeAssetTxPayment::<Runtime>::from(tip, None),
182			frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(false),
183			pallet_revive::evm::tx_extension::SetOrigin::<Runtime>::new_from_eth_transaction(),
184			frame_system::WeightReclaim::<Runtime>::new(),
185		)
186			.into()
187	}
188}
189
190/// Unchecked extrinsic type as expected by this runtime.
191pub type UncheckedExtrinsic =
192	pallet_revive::evm::runtime::UncheckedExtrinsic<Address, Signature, EthExtraImpl>;
193
194pub type Migrations = (
195	pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckingAccount>,
196	pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
197	pallet_session::migrations::v1::MigrateV0ToV1<
198		Runtime,
199		pallet_session::migrations::v1::InitOffenceSeverity<Runtime>,
200	>,
201);
202
203/// Executive: handles dispatch to the various modules.
204pub type Executive = frame_executive::Executive<
205	Runtime,
206	Block,
207	frame_system::ChainContext<Runtime>,
208	Runtime,
209	AllPalletsWithSystem,
210	Migrations,
211>;
212
213/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
214/// node's balance type.
215///
216/// This should typically create a mapping between the following ranges:
217///   - `[0, MAXIMUM_BLOCK_WEIGHT]`
218///   - `[Balance::min, Balance::max]`
219///
220/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
221///   - Setting it to `0` will essentially disable the weight fee.
222///   - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
223pub struct WeightToFee;
224impl frame_support::weights::WeightToFee for WeightToFee {
225	type Balance = Balance;
226
227	fn weight_to_fee(weight: &Weight) -> Self::Balance {
228		let time_poly: FeePolynomial<Balance> = RefTimeToFee::polynomial().into();
229		let proof_poly: FeePolynomial<Balance> = ProofSizeToFee::polynomial().into();
230
231		// Take the maximum instead of the sum to charge by the more scarce resource.
232		time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size()))
233	}
234}
235
236/// Maps the reference time component of `Weight` to a fee.
237pub struct RefTimeToFee;
238impl WeightToFeePolynomial for RefTimeToFee {
239	type Balance = Balance;
240	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
241		let p = MILLIUNIT / 10;
242		let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
243
244		smallvec![WeightToFeeCoefficient {
245			degree: 1,
246			negative: false,
247			coeff_frac: Perbill::from_rational(p % q, q),
248			coeff_integer: p / q,
249		}]
250	}
251}
252
253/// Maps the proof size component of `Weight` to a fee.
254pub struct ProofSizeToFee;
255impl WeightToFeePolynomial for ProofSizeToFee {
256	type Balance = Balance;
257	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
258		// Map 10kb proof to 1 CENT.
259		let p = MILLIUNIT / 10;
260		let q = 10_000;
261
262		smallvec![WeightToFeeCoefficient {
263			degree: 1,
264			negative: false,
265			coeff_frac: Perbill::from_rational(p % q, q),
266			coeff_integer: p / q,
267		}]
268	}
269}
270/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
271/// the specifics of the runtime. They can then be made to be agnostic over specific formats
272/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
273/// to even the core data structures.
274pub mod opaque {
275	use super::*;
276	use sp_runtime::{generic, traits::BlakeTwo256};
277
278	pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
279	/// Opaque block header type.
280	pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
281	/// Opaque block type.
282	pub type Block = generic::Block<Header, UncheckedExtrinsic>;
283	/// Opaque block identifier type.
284	pub type BlockId = generic::BlockId<Block>;
285}
286
287impl_opaque_keys! {
288	pub struct SessionKeys {
289		pub aura: Aura,
290	}
291}
292
293#[sp_version::runtime_version]
294pub const VERSION: RuntimeVersion = RuntimeVersion {
295	spec_name: alloc::borrow::Cow::Borrowed("penpal-parachain"),
296	impl_name: alloc::borrow::Cow::Borrowed("penpal-parachain"),
297	authoring_version: 1,
298	spec_version: 1,
299	impl_version: 0,
300	apis: RUNTIME_API_VERSIONS,
301	transaction_version: 1,
302	system_version: 1,
303};
304
305/// This determines the average expected block time that we are targeting.
306/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
307/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
308/// up by `pallet_aura` to implement `fn slot_duration()`.
309///
310/// Change this to adjust the block time.
311pub const MILLISECS_PER_BLOCK: u64 = 12000;
312
313// NOTE: Currently it is not possible to change the slot duration after the chain has started.
314//       Attempting to do so will brick block production.
315pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
316
317// Time is measured by number of blocks.
318pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
319pub const HOURS: BlockNumber = MINUTES * 60;
320pub const DAYS: BlockNumber = HOURS * 24;
321
322// Unit = the base number of indivisible units for balances
323pub const UNIT: Balance = 1_000_000_000_000;
324pub const MILLIUNIT: Balance = 1_000_000_000;
325pub const MICROUNIT: Balance = 1_000_000;
326
327/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
328pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
329
330/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
331/// used to limit the maximal weight of a single extrinsic.
332const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
333
334/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by
335/// `Operational` extrinsics.
336const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
337
338/// We allow for 0.5 of a second of compute with a 12 second average block time.
339const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
340	WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
341	cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
342);
343
344/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
345/// into the relay chain.
346const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
347/// How many parachain blocks are processed by the relay chain per parent. Limits the
348/// number of blocks authored per slot.
349const BLOCK_PROCESSING_VELOCITY: u32 = 1;
350/// Relay chain slot duration, in milliseconds.
351const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
352
353/// The version information used to identify this runtime when compiled natively.
354#[cfg(feature = "std")]
355pub fn native_version() -> NativeVersion {
356	NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
357}
358
359parameter_types! {
360	pub const Version: RuntimeVersion = VERSION;
361
362	// This part is copied from Substrate's `bin/node/runtime/src/lib.rs`.
363	//  The `RuntimeBlockLength` and `RuntimeBlockWeights` exist here because the
364	// `DeletionWeightLimit` and `DeletionQueueDepth` depend on those to parameterize
365	// the lazy contract deletion.
366	pub RuntimeBlockLength: BlockLength =
367		BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
368	pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
369		.base_block(BlockExecutionWeight::get())
370		.for_class(DispatchClass::all(), |weights| {
371			weights.base_extrinsic = ExtrinsicBaseWeight::get();
372		})
373		.for_class(DispatchClass::Normal, |weights| {
374			weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
375		})
376		.for_class(DispatchClass::Operational, |weights| {
377			weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
378			// Operational transactions have some extra reserved space, so that they
379			// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
380			weights.reserved = Some(
381				MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
382			);
383		})
384		.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
385		.build_or_panic();
386	pub const SS58Prefix: u16 = 42;
387}
388
389// Configure FRAME pallets to include in runtime.
390
391#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
392impl frame_system::Config for Runtime {
393	/// The identifier used to distinguish between accounts.
394	type AccountId = AccountId;
395	/// The aggregated dispatch type that is available for extrinsics.
396	type RuntimeCall = RuntimeCall;
397	/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
398	type Lookup = AccountIdLookup<AccountId, ()>;
399	/// The index type for storing how many extrinsics an account has signed.
400	type Nonce = Nonce;
401	/// The type for hashing blocks and tries.
402	type Hash = Hash;
403	/// The hashing algorithm used.
404	type Hashing = BlakeTwo256;
405	/// The block type.
406	type Block = Block;
407	/// The ubiquitous event type.
408	type RuntimeEvent = RuntimeEvent;
409	/// The ubiquitous origin type.
410	type RuntimeOrigin = RuntimeOrigin;
411	/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
412	type BlockHashCount = BlockHashCount;
413	/// Runtime version.
414	type Version = Version;
415	/// Converts a module to an index of this module in the runtime.
416	type PalletInfo = PalletInfo;
417	/// The data to be stored in an account.
418	type AccountData = pallet_balances::AccountData<Balance>;
419	/// What to do if a new account is created.
420	type OnNewAccount = ();
421	/// What to do if an account is fully reaped from the system.
422	type OnKilledAccount = ();
423	/// The weight of database operations that the runtime can invoke.
424	type DbWeight = RocksDbWeight;
425	/// The basic call filter to use in dispatchable.
426	type BaseCallFilter = Everything;
427	/// Weight information for the extrinsics of this pallet.
428	type SystemWeightInfo = ();
429	/// Block & extrinsics weights: base values and limits.
430	type BlockWeights = RuntimeBlockWeights;
431	/// The maximum length of a block (in bytes).
432	type BlockLength = RuntimeBlockLength;
433	/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
434	type SS58Prefix = SS58Prefix;
435	/// The action to take on a Runtime Upgrade
436	type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
437	type MaxConsumers = frame_support::traits::ConstU32<16>;
438}
439
440impl pallet_timestamp::Config for Runtime {
441	/// A timestamp: milliseconds since the unix epoch.
442	type Moment = u64;
443	type OnTimestampSet = Aura;
444	type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
445	type WeightInfo = ();
446}
447
448impl pallet_authorship::Config for Runtime {
449	type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
450	type EventHandler = (CollatorSelection,);
451}
452
453parameter_types! {
454	pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
455}
456
457impl pallet_balances::Config for Runtime {
458	type MaxLocks = ConstU32<50>;
459	/// The type for recording an account's balance.
460	type Balance = Balance;
461	/// The ubiquitous event type.
462	type RuntimeEvent = RuntimeEvent;
463	type DustRemoval = ();
464	type ExistentialDeposit = ExistentialDeposit;
465	type AccountStore = System;
466	type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
467	type MaxReserves = ConstU32<50>;
468	type ReserveIdentifier = [u8; 8];
469	type RuntimeHoldReason = RuntimeHoldReason;
470	type RuntimeFreezeReason = RuntimeFreezeReason;
471	type FreezeIdentifier = ();
472	type MaxFreezes = ConstU32<0>;
473	type DoneSlashHandler = ();
474}
475
476parameter_types! {
477	/// Relay Chain `TransactionByteFee` / 10
478	pub const TransactionByteFee: Balance = 10 * MICROUNIT;
479}
480
481impl pallet_transaction_payment::Config for Runtime {
482	type RuntimeEvent = RuntimeEvent;
483	type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
484	type WeightToFee = pallet_revive::evm::fees::BlockRatioFee<1, 1, Self>;
485	type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
486	type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
487	type OperationalFeeMultiplier = ConstU8<5>;
488	type WeightInfo = ();
489}
490
491parameter_types! {
492	pub const AssetDeposit: Balance = 0;
493	pub const AssetAccountDeposit: Balance = 0;
494	pub const ApprovalDeposit: Balance = 0;
495	pub const AssetsStringLimit: u32 = 50;
496	pub const MetadataDepositBase: Balance = 0;
497	pub const MetadataDepositPerByte: Balance = 0;
498}
499
500// /// We allow root and the Relay Chain council to execute privileged asset operations.
501// pub type AssetsForceOrigin =
502// 	EnsureOneOf<EnsureRoot<AccountId>, EnsureXcm<IsMajorityOfBody<KsmLocation, ExecutiveBody>>>;
503
504pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
505
506impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
507	type RuntimeEvent = RuntimeEvent;
508	type Balance = Balance;
509	type AssetId = AssetId;
510	type AssetIdParameter = codec::Compact<AssetId>;
511	type Currency = Balances;
512	type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
513	type ForceOrigin = EnsureRoot<AccountId>;
514	type AssetDeposit = AssetDeposit;
515	type MetadataDepositBase = MetadataDepositBase;
516	type MetadataDepositPerByte = MetadataDepositPerByte;
517	type ApprovalDeposit = ApprovalDeposit;
518	type StringLimit = AssetsStringLimit;
519	type Holder = ();
520	type Freezer = ();
521	type Extra = ();
522	type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
523	type CallbackHandle = ();
524	type AssetAccountDeposit = AssetAccountDeposit;
525	type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
526	#[cfg(feature = "runtime-benchmarks")]
527	type BenchmarkHelper = ();
528}
529
530parameter_types! {
531	// we just reuse the same deposits
532	pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get();
533	pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get();
534	pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get();
535	pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get();
536	pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get();
537	pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get();
538}
539
540/// Another pallet assets instance to store foreign assets from bridgehub.
541pub type ForeignAssetsInstance = pallet_assets::Instance2;
542impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
543	type RuntimeEvent = RuntimeEvent;
544	type Balance = Balance;
545	type AssetId = ForeignAssetsAssetId;
546	type AssetIdParameter = ForeignAssetsAssetId;
547	type Currency = Balances;
548	// This is to allow any other remote location to create foreign assets. Used in tests, not
549	// recommended on real chains.
550	type CreateOrigin =
551		ForeignCreators<Everything, LocationToAccountId, AccountId, xcm::latest::Location>;
552	type ForceOrigin = EnsureRoot<AccountId>;
553	type AssetDeposit = ForeignAssetsAssetDeposit;
554	type MetadataDepositBase = ForeignAssetsMetadataDepositBase;
555	type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
556	type ApprovalDeposit = ForeignAssetsApprovalDeposit;
557	type StringLimit = ForeignAssetsAssetsStringLimit;
558	type Holder = ();
559	type Freezer = ();
560	type Extra = ();
561	type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
562	type CallbackHandle = ();
563	type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit;
564	type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
565	#[cfg(feature = "runtime-benchmarks")]
566	type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
567}
568
569parameter_types! {
570	pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
571	pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
572}
573
574ord_parameter_types! {
575	pub const AssetConversionOrigin: sp_runtime::AccountId32 =
576		AccountIdConversion::<sp_runtime::AccountId32>::into_account_truncating(&AssetConversionPalletId::get());
577}
578
579pub type AssetsForceOrigin = EnsureRoot<AccountId>;
580
581pub type PoolAssetsInstance = pallet_assets::Instance3;
582impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
583	type RuntimeEvent = RuntimeEvent;
584	type Balance = Balance;
585	type RemoveItemsLimit = ConstU32<1000>;
586	type AssetId = u32;
587	type AssetIdParameter = u32;
588	type Currency = Balances;
589	type CreateOrigin =
590		AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, sp_runtime::AccountId32>>;
591	type ForceOrigin = AssetsForceOrigin;
592	type AssetDeposit = ConstU128<0>;
593	type AssetAccountDeposit = ConstU128<0>;
594	type MetadataDepositBase = ConstU128<0>;
595	type MetadataDepositPerByte = ConstU128<0>;
596	type ApprovalDeposit = ConstU128<0>;
597	type StringLimit = ConstU32<50>;
598	type Holder = ();
599	type Freezer = ();
600	type Extra = ();
601	type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
602	type CallbackHandle = ();
603	#[cfg(feature = "runtime-benchmarks")]
604	type BenchmarkHelper = ();
605}
606
607/// Union fungibles implementation for `Assets` and `ForeignAssets`.
608pub type LocalAndForeignAssets = fungibles::UnionOf<
609	Assets,
610	ForeignAssets,
611	LocalFromLeft<
612		AssetIdForTrustBackedAssetsConvert<
613			xcm_config::TrustBackedAssetsPalletLocation,
614			xcm::latest::Location,
615		>,
616		parachains_common::AssetIdForTrustBackedAssets,
617		xcm::latest::Location,
618	>,
619	xcm::latest::Location,
620	AccountId,
621>;
622
623/// Union fungibles implementation for [`LocalAndForeignAssets`] and `Balances`.
624pub type NativeAndAssets = fungible::UnionOf<
625	Balances,
626	LocalAndForeignAssets,
627	TargetFromLeft<xcm_config::RelayLocation, xcm::latest::Location>,
628	xcm::latest::Location,
629	AccountId,
630>;
631
632pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter<
633	AssetConversionPalletId,
634	(xcm::latest::Location, xcm::latest::Location),
635>;
636
637impl pallet_asset_conversion::Config for Runtime {
638	type RuntimeEvent = RuntimeEvent;
639	type Balance = Balance;
640	type HigherPrecisionBalance = sp_core::U256;
641	type AssetKind = xcm::latest::Location;
642	type Assets = NativeAndAssets;
643	type PoolId = (Self::AssetKind, Self::AssetKind);
644	type PoolLocator = pallet_asset_conversion::WithFirstAsset<
645		xcm_config::RelayLocation,
646		AccountId,
647		Self::AssetKind,
648		PoolIdToAccountId,
649	>;
650	type PoolAssetId = u32;
651	type PoolAssets = PoolAssets;
652	type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam
653	type PoolSetupFeeAsset = xcm_config::RelayLocation;
654	type PoolSetupFeeTarget = ResolveAssetTo<AssetConversionOrigin, Self::Assets>;
655	type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
656	type LPFee = ConstU32<3>;
657	type PalletId = AssetConversionPalletId;
658	type MaxSwapPathLength = ConstU32<3>;
659	type MintMinLiquidity = ConstU128<100>;
660	type WeightInfo = ();
661	#[cfg(feature = "runtime-benchmarks")]
662	type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory<
663		xcm_config::RelayLocation,
664		parachain_info::Pallet<Runtime>,
665		xcm_config::TrustBackedAssetsPalletIndex,
666		xcm::latest::Location,
667	>;
668}
669
670parameter_types! {
671	pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
672	pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
673	pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
674}
675
676impl cumulus_pallet_parachain_system::Config for Runtime {
677	type WeightInfo = ();
678	type RuntimeEvent = RuntimeEvent;
679	type OnSystemEvent = ();
680	type SelfParaId = parachain_info::Pallet<Runtime>;
681	type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
682	type ReservedDmpWeight = ReservedDmpWeight;
683	type OutboundXcmpMessageSource = XcmpQueue;
684	type XcmpMessageHandler = XcmpQueue;
685	type ReservedXcmpWeight = ReservedXcmpWeight;
686	type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
687	type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
688		Runtime,
689		RELAY_CHAIN_SLOT_DURATION_MILLIS,
690		BLOCK_PROCESSING_VELOCITY,
691		UNINCLUDED_SEGMENT_CAPACITY,
692	>;
693	type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
694	type RelayParentOffset = ConstU32<0>;
695}
696
697impl parachain_info::Config for Runtime {}
698
699parameter_types! {
700	pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block;
701}
702
703impl pallet_message_queue::Config for Runtime {
704	type RuntimeEvent = RuntimeEvent;
705	type WeightInfo = ();
706	type MessageProcessor = xcm_builder::ProcessXcmMessage<
707		AggregateMessageOrigin,
708		xcm_executor::XcmExecutor<xcm_config::XcmConfig>,
709		RuntimeCall,
710	>;
711	type Size = u32;
712	// The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin:
713	type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;
714	type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;
715	type HeapSize = sp_core::ConstU32<{ 103 * 1024 }>;
716	type MaxStale = sp_core::ConstU32<8>;
717	type ServiceWeight = MessageQueueServiceWeight;
718	type IdleMaxServiceWeight = MessageQueueServiceWeight;
719}
720
721impl cumulus_pallet_aura_ext::Config for Runtime {}
722
723parameter_types! {
724	/// The asset ID for the asset that we use to pay for message delivery fees.
725	pub FeeAssetId: AssetLocationId = AssetLocationId(xcm_config::RelayLocation::get());
726	/// The base fee for the message delivery fees (3 CENTS).
727	pub const BaseDeliveryFee: u128 = (1_000_000_000_000u128 / 100).saturating_mul(3);
728}
729
730pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
731	FeeAssetId,
732	BaseDeliveryFee,
733	TransactionByteFee,
734	XcmpQueue,
735>;
736
737impl cumulus_pallet_xcmp_queue::Config for Runtime {
738	type RuntimeEvent = RuntimeEvent;
739	type ChannelInfo = ParachainSystem;
740	type VersionWrapper = PolkadotXcm;
741	// Enqueue XCMP messages from siblings for later processing.
742	type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
743	type MaxInboundSuspended = ConstU32<1_000>;
744	type MaxActiveOutboundChannels = ConstU32<128>;
745	// Most on-chain HRMP channels are configured to use 102400 bytes of max message size, so we
746	// need to set the page size larger than that until we reduce the channel size on-chain.
747	type MaxPageSize = ConstU32<{ 103 * 1024 }>;
748	type ControllerOrigin = EnsureRoot<AccountId>;
749	type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
750	type WeightInfo = ();
751	type PriceForSiblingDelivery = PriceForSiblingParachainDelivery;
752}
753
754parameter_types! {
755	pub const Period: u32 = 6 * HOURS;
756	pub const Offset: u32 = 0;
757}
758impl pallet_session::Config for Runtime {
759	type RuntimeEvent = RuntimeEvent;
760	type ValidatorId = <Self as frame_system::Config>::AccountId;
761	// we don't have stash and controller, thus we don't need the convert as well.
762	type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
763	type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
764	type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
765	type SessionManager = CollatorSelection;
766	// Essentially just Aura, but let's be pedantic.
767	type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
768	type Keys = SessionKeys;
769	type DisablingStrategy = ();
770	type WeightInfo = ();
771	type Currency = Balances;
772	type KeyDeposit = ();
773}
774
775impl pallet_aura::Config for Runtime {
776	type AuthorityId = AuraId;
777	type DisabledValidators = ();
778	type MaxAuthorities = ConstU32<100_000>;
779	type AllowMultipleBlocksPerSlot = ConstBool<false>;
780	type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Self>;
781}
782
783parameter_types! {
784	pub const PotId: PalletId = PalletId(*b"PotStake");
785	pub const SessionLength: BlockNumber = 6 * HOURS;
786	pub const ExecutiveBody: BodyId = BodyId::Executive;
787}
788
789// We allow root only to execute privileged collator selection operations.
790pub type CollatorSelectionUpdateOrigin = EnsureRoot<AccountId>;
791
792impl pallet_collator_selection::Config for Runtime {
793	type RuntimeEvent = RuntimeEvent;
794	type Currency = Balances;
795	type UpdateOrigin = CollatorSelectionUpdateOrigin;
796	type PotId = PotId;
797	type MaxCandidates = ConstU32<100>;
798	type MinEligibleCollators = ConstU32<4>;
799	type MaxInvulnerables = ConstU32<20>;
800	// should be a multiple of session or things will get inconsistent
801	type KickThreshold = Period;
802	type ValidatorId = <Self as frame_system::Config>::AccountId;
803	type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
804	type ValidatorRegistration = Session;
805	type WeightInfo = ();
806}
807
808#[cfg(feature = "runtime-benchmarks")]
809pub struct AssetTxHelper;
810
811#[cfg(feature = "runtime-benchmarks")]
812impl pallet_asset_tx_payment::BenchmarkHelperTrait<AccountId, u32, u32> for AssetTxHelper {
813	fn create_asset_id_parameter(_id: u32) -> (u32, u32) {
814		unimplemented!("Penpal uses default weights");
815	}
816	fn setup_balances_and_pool(_asset_id: u32, _account: AccountId) {
817		unimplemented!("Penpal uses default weights");
818	}
819}
820
821impl pallet_asset_tx_payment::Config for Runtime {
822	type RuntimeEvent = RuntimeEvent;
823	type Fungibles = Assets;
824	type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
825		pallet_assets::BalanceToAssetBalance<
826			Balances,
827			Runtime,
828			ConvertInto,
829			TrustBackedAssetsInstance,
830		>,
831		AssetsToBlockAuthor<Runtime, TrustBackedAssetsInstance>,
832	>;
833	type WeightInfo = ();
834	#[cfg(feature = "runtime-benchmarks")]
835	type BenchmarkHelper = AssetTxHelper;
836}
837
838parameter_types! {
839	pub const DepositPerItem: Balance = 0;
840	pub const DepositPerChildTrieItem: Balance = 0;
841	pub const DepositPerByte: Balance = 0;
842	pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
843	pub const MaxEthExtrinsicWeight: FixedU128 = FixedU128::from_rational(9, 10);
844}
845
846impl pallet_revive::Config for Runtime {
847	type Time = Timestamp;
848	type Balance = Balance;
849	type Currency = Balances;
850	type RuntimeEvent = RuntimeEvent;
851	type RuntimeCall = RuntimeCall;
852	type RuntimeOrigin = RuntimeOrigin;
853	type DepositPerItem = DepositPerItem;
854	type DepositPerChildTrieItem = DepositPerChildTrieItem;
855	type DepositPerByte = DepositPerByte;
856	type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
857	type Precompiles = ();
858	type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
859	type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
860	type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
861	type UnsafeUnstableInterface = ConstBool<true>;
862	type AllowEVMBytecode = ConstBool<true>;
863	type UploadOrigin = EnsureSigned<Self::AccountId>;
864	type InstantiateOrigin = EnsureSigned<Self::AccountId>;
865	type RuntimeHoldReason = RuntimeHoldReason;
866	type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
867	type ChainId = ConstU64<420_420_999>;
868	type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
869	type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
870	type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
871	type MaxEthExtrinsicWeight = MaxEthExtrinsicWeight;
872	type DebugEnabled = ConstBool<false>;
873	type GasScale = ConstU32<1000>;
874}
875
876impl pallet_sudo::Config for Runtime {
877	type RuntimeEvent = RuntimeEvent;
878	type RuntimeCall = RuntimeCall;
879	type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
880}
881
882impl pallet_utility::Config for Runtime {
883	type RuntimeEvent = RuntimeEvent;
884	type RuntimeCall = RuntimeCall;
885	type PalletsOrigin = OriginCaller;
886	type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
887}
888
889// Create the runtime by composing the FRAME pallets that were previously configured.
890construct_runtime!(
891	pub enum Runtime
892	{
893		// System support stuff.
894		System: frame_system = 0,
895		ParachainSystem: cumulus_pallet_parachain_system = 1,
896		Timestamp: pallet_timestamp = 2,
897		ParachainInfo: parachain_info = 3,
898
899		// Monetary stuff.
900		Balances: pallet_balances = 10,
901		TransactionPayment: pallet_transaction_payment = 11,
902		AssetTxPayment: pallet_asset_tx_payment = 12,
903
904		// Collator support. The order of these 4 are important and shall not change.
905		Authorship: pallet_authorship = 20,
906		CollatorSelection: pallet_collator_selection = 21,
907		Session: pallet_session = 22,
908		Aura: pallet_aura = 23,
909		AuraExt: cumulus_pallet_aura_ext = 24,
910
911		// XCM helpers.
912		XcmpQueue: cumulus_pallet_xcmp_queue = 30,
913		PolkadotXcm: pallet_xcm = 31,
914		CumulusXcm: cumulus_pallet_xcm = 32,
915		MessageQueue: pallet_message_queue = 34,
916
917		// Handy utilities.
918		Utility: pallet_utility = 40,
919
920		// The main stage.
921		Assets: pallet_assets::<Instance1> = 50,
922		ForeignAssets: pallet_assets::<Instance2> = 51,
923		PoolAssets: pallet_assets::<Instance3> = 52,
924		AssetConversion: pallet_asset_conversion = 53,
925
926		Revive: pallet_revive = 60,
927
928		Sudo: pallet_sudo = 255,
929	}
930);
931
932#[cfg(feature = "runtime-benchmarks")]
933mod benches {
934	frame_benchmarking::define_benchmarks!(
935		[frame_system, SystemBench::<Runtime>]
936		[frame_system_extensions, SystemExtensionsBench::<Runtime>]
937		[pallet_balances, Balances]
938		[pallet_message_queue, MessageQueue]
939		[pallet_session, SessionBench::<Runtime>]
940		[pallet_sudo, Sudo]
941		[pallet_timestamp, Timestamp]
942		[pallet_collator_selection, CollatorSelection]
943		[cumulus_pallet_parachain_system, ParachainSystem]
944		[cumulus_pallet_xcmp_queue, XcmpQueue]
945		[pallet_utility, Utility]
946	);
947}
948
949pallet_revive::impl_runtime_apis_plus_revive_traits!(
950	Runtime,
951	Revive,
952	Executive,
953	EthExtraImpl,
954
955	impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
956		fn slot_duration() -> sp_consensus_aura::SlotDuration {
957			sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
958		}
959
960		fn authorities() -> Vec<AuraId> {
961			pallet_aura::Authorities::<Runtime>::get().into_inner()
962		}
963	}
964
965	impl sp_api::Core<Block> for Runtime {
966		fn version() -> RuntimeVersion {
967			VERSION
968		}
969
970		fn execute_block(block: Block) {
971			Executive::execute_block(block)
972		}
973
974		fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
975			Executive::initialize_block(header)
976		}
977	}
978
979	impl sp_api::Metadata<Block> for Runtime {
980		fn metadata() -> OpaqueMetadata {
981			OpaqueMetadata::new(Runtime::metadata().into())
982		}
983
984		fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
985			Runtime::metadata_at_version(version)
986		}
987
988		fn metadata_versions() -> alloc::vec::Vec<u32> {
989			Runtime::metadata_versions()
990		}
991	}
992
993	impl sp_block_builder::BlockBuilder<Block> for Runtime {
994		fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
995			Executive::apply_extrinsic(extrinsic)
996		}
997
998		fn finalize_block() -> <Block as BlockT>::Header {
999			Executive::finalize_block()
1000		}
1001
1002		fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
1003			data.create_extrinsics()
1004		}
1005
1006		fn check_inherents(
1007			block: Block,
1008			data: sp_inherents::InherentData,
1009		) -> sp_inherents::CheckInherentsResult {
1010			data.check_extrinsics(&block)
1011		}
1012	}
1013
1014	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
1015		fn validate_transaction(
1016			source: TransactionSource,
1017			tx: <Block as BlockT>::Extrinsic,
1018			block_hash: <Block as BlockT>::Hash,
1019		) -> TransactionValidity {
1020			Executive::validate_transaction(source, tx, block_hash)
1021		}
1022	}
1023
1024	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
1025		fn offchain_worker(header: &<Block as BlockT>::Header) {
1026			Executive::offchain_worker(header)
1027		}
1028	}
1029
1030	impl sp_session::SessionKeys<Block> for Runtime {
1031		fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
1032			SessionKeys::generate(seed)
1033		}
1034
1035		fn decode_session_keys(
1036			encoded: Vec<u8>,
1037		) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
1038			SessionKeys::decode_into_raw_public_keys(&encoded)
1039		}
1040	}
1041
1042	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
1043		fn account_nonce(account: AccountId) -> Nonce {
1044			System::account_nonce(account)
1045		}
1046	}
1047
1048	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
1049		fn query_info(
1050			uxt: <Block as BlockT>::Extrinsic,
1051			len: u32,
1052		) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
1053			TransactionPayment::query_info(uxt, len)
1054		}
1055		fn query_fee_details(
1056			uxt: <Block as BlockT>::Extrinsic,
1057			len: u32,
1058		) -> pallet_transaction_payment::FeeDetails<Balance> {
1059			TransactionPayment::query_fee_details(uxt, len)
1060		}
1061		fn query_weight_to_fee(weight: Weight) -> Balance {
1062			TransactionPayment::weight_to_fee(weight)
1063		}
1064		fn query_length_to_fee(length: u32) -> Balance {
1065			TransactionPayment::length_to_fee(length)
1066		}
1067	}
1068
1069	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
1070		for Runtime
1071	{
1072		fn query_call_info(
1073			call: RuntimeCall,
1074			len: u32,
1075		) -> pallet_transaction_payment::RuntimeDispatchInfo<Balance> {
1076			TransactionPayment::query_call_info(call, len)
1077		}
1078		fn query_call_fee_details(
1079			call: RuntimeCall,
1080			len: u32,
1081		) -> pallet_transaction_payment::FeeDetails<Balance> {
1082			TransactionPayment::query_call_fee_details(call, len)
1083		}
1084		fn query_weight_to_fee(weight: Weight) -> Balance {
1085			TransactionPayment::weight_to_fee(weight)
1086		}
1087		fn query_length_to_fee(length: u32) -> Balance {
1088			TransactionPayment::length_to_fee(length)
1089		}
1090	}
1091
1092	impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
1093		fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
1094			ParachainSystem::collect_collation_info(header)
1095		}
1096	}
1097
1098	impl cumulus_primitives_core::GetCoreSelectorApi<Block> for Runtime {
1099		fn core_selector() -> (CoreSelector, ClaimQueueOffset) {
1100			ParachainSystem::core_selector()
1101		}
1102	}
1103
1104	impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
1105		fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
1106			let acceptable_assets = vec![AssetLocationId(xcm_config::RelayLocation::get())];
1107			PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
1108		}
1109
1110		fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
1111			use crate::xcm_config::XcmConfig;
1112
1113			type Trader = <XcmConfig as xcm_executor::Config>::Trader;
1114
1115			PolkadotXcm::query_weight_to_asset_fee::<Trader>(weight, asset)
1116		}
1117
1118		fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
1119			PolkadotXcm::query_xcm_weight(message)
1120		}
1121
1122		fn query_delivery_fees(destination: VersionedLocation, message: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
1123			PolkadotXcm::query_delivery_fees(destination, message)
1124		}
1125	}
1126
1127	impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
1128		fn dry_run_call(origin: OriginCaller, call: RuntimeCall, result_xcms_version: XcmVersion) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
1129			PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call, result_xcms_version)
1130		}
1131
1132		fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
1133			PolkadotXcm::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
1134		}
1135	}
1136
1137	impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
1138		fn convert_location(location: VersionedLocation) -> Result<
1139			AccountId,
1140			xcm_runtime_apis::conversions::Error
1141		> {
1142			xcm_runtime_apis::conversions::LocationToAccountHelper::<
1143				AccountId,
1144				xcm_config::LocationToAccountId,
1145			>::convert_location(location)
1146		}
1147	}
1148
1149	impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
1150		fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1151			PolkadotXcm::is_trusted_reserve(asset, location)
1152		}
1153		fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
1154			PolkadotXcm::is_trusted_teleporter(asset, location)
1155		}
1156	}
1157
1158	impl xcm_runtime_apis::authorized_aliases::AuthorizedAliasersApi<Block> for Runtime {
1159		fn authorized_aliasers(target: VersionedLocation) -> Result<
1160			Vec<xcm_runtime_apis::authorized_aliases::OriginAliaser>,
1161			xcm_runtime_apis::authorized_aliases::Error
1162		> {
1163			PolkadotXcm::authorized_aliasers(target)
1164		}
1165		fn is_authorized_alias(origin: VersionedLocation, target: VersionedLocation) -> Result<
1166			bool,
1167			xcm_runtime_apis::authorized_aliases::Error
1168		> {
1169			PolkadotXcm::is_authorized_alias(origin, target)
1170		}
1171	}
1172
1173	#[cfg(feature = "try-runtime")]
1174	impl frame_try_runtime::TryRuntime<Block> for Runtime {
1175		fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
1176			let weight = Executive::try_runtime_upgrade(checks).unwrap();
1177			(weight, RuntimeBlockWeights::get().max_block)
1178		}
1179
1180		fn execute_block(
1181			block: Block,
1182			state_root_check: bool,
1183			signature_check: bool,
1184			select: frame_try_runtime::TryStateSelect,
1185		) -> Weight {
1186			// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
1187			// have a backtrace here.
1188			Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
1189		}
1190	}
1191
1192	#[cfg(feature = "runtime-benchmarks")]
1193	impl frame_benchmarking::Benchmark<Block> for Runtime {
1194		fn benchmark_metadata(extra: bool) -> (
1195			Vec<frame_benchmarking::BenchmarkList>,
1196			Vec<frame_support::traits::StorageInfo>,
1197		) {
1198			use frame_benchmarking::BenchmarkList;
1199			use frame_support::traits::StorageInfoTrait;
1200			use frame_system_benchmarking::Pallet as SystemBench;
1201			use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
1202			use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1203
1204			let mut list = Vec::<BenchmarkList>::new();
1205			list_benchmarks!(list, extra);
1206
1207			let storage_info = AllPalletsWithSystem::storage_info();
1208			(list, storage_info)
1209		}
1210
1211		#[allow(non_local_definitions)]
1212		fn dispatch_benchmark(
1213			config: frame_benchmarking::BenchmarkConfig
1214		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
1215			use frame_benchmarking::BenchmarkBatch;
1216			use sp_storage::TrackedStorageKey;
1217
1218			use frame_system_benchmarking::Pallet as SystemBench;
1219			use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
1220			impl frame_system_benchmarking::Config for Runtime {}
1221
1222			use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
1223			impl cumulus_pallet_session_benchmarking::Config for Runtime {}
1224
1225			use frame_support::traits::WhitelistedStorageKeys;
1226			let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
1227
1228			let mut batches = Vec::<BenchmarkBatch>::new();
1229			let params = (&config, &whitelist);
1230			add_benchmarks!(params, batches);
1231
1232			if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
1233			Ok(batches)
1234		}
1235	}
1236
1237	impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
1238		fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
1239			build_state::<RuntimeGenesisConfig>(config)
1240		}
1241
1242		fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
1243			get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
1244		}
1245
1246		fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
1247			genesis_config_presets::preset_names()
1248		}
1249	}
1250
1251	impl cumulus_primitives_core::GetParachainInfo<Block> for Runtime {
1252		fn parachain_id() -> ParaId {
1253			ParachainInfo::parachain_id()
1254		}
1255	}
1256);
1257
1258cumulus_pallet_parachain_system::register_validate_block! {
1259	Runtime = Runtime,
1260	BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
1261}