Skip to main content

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