1#![cfg_attr(not(feature = "std"), no_std)]
24#![recursion_limit = "512"]
26
27#[cfg(feature = "std")]
29include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
30
31extern crate alloc;
32extern crate core;
33
34use account::AccountId20;
35use alloc::borrow::Cow;
36use cumulus_pallet_parachain_system::{
37 RelayChainStateProof, RelayStateProof, RelaychainDataProvider, ValidationData,
38};
39use fp_rpc::TransactionStatus;
40
41use bp_moonbeam::bp_kusama;
42use cumulus_primitives_core::{relay_chain, AggregateMessageOrigin};
43#[cfg(feature = "std")]
44pub use fp_evm::GenesisAccount;
45pub use frame_support::traits::Get;
46use frame_support::{
47 construct_runtime,
48 dispatch::{DispatchClass, GetDispatchInfo, PostDispatchInfo},
49 ensure,
50 pallet_prelude::DispatchResult,
51 parameter_types,
52 traits::{
53 fungible::{Balanced, Credit, HoldConsideration, Inspect, NativeOrWithId},
54 ConstBool, ConstU128, ConstU16, ConstU32, ConstU64, ConstU8, Contains, EitherOf,
55 EitherOfDiverse, EqualPrivilegeOnly, InstanceFilter, LinearStoragePrice, OnFinalize,
56 OnUnbalanced, VariantCountOf,
57 },
58 weights::{
59 constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient,
60 WeightToFeeCoefficients, WeightToFeePolynomial,
61 },
62 PalletId,
63};
64use frame_system::{EnsureRoot, EnsureSigned};
65pub use moonbeam_core_primitives::{
66 AccountId, AccountIndex, Address, AssetId, Balance, BlockNumber, DigestItem, Hash, Header,
67 Index, Signature,
68};
69use moonbeam_rpc_primitives_txpool::TxPoolResponse;
70use moonbeam_runtime_common::{
71 deal_with_fees::{
72 DealWithEthereumBaseFees, DealWithEthereumPriorityFees, DealWithSubstrateFeesAndTip,
73 ProofSizeToFee, RefTimeToFee, WeightToFee,
74 },
75 impl_asset_conversion::AssetRateConverter,
76 impl_multiasset_paymaster::MultiAssetPaymaster,
77};
78pub use pallet_author_slot_filter::EligibilityValue;
79use pallet_ethereum::Call::transact;
80use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction};
81use pallet_evm::{
82 Account as EVMAccount, EVMFungibleAdapter, EnsureAddressNever, EnsureAddressRoot,
83 FeeCalculator, FrameSystemAccountProvider, GasWeightMapping, IdentityAddressMapping,
84 OnChargeEVMTransaction as OnChargeEVMTransactionT, Runner,
85};
86pub use pallet_parachain_staking::{weights::WeightInfo, InflationInfo, Range};
87use pallet_transaction_payment::{FungibleAdapter, Multiplier, TargetedFeeAdjustment};
88use parity_scale_codec as codec;
89use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
90use scale_info::TypeInfo;
91use serde::{Deserialize, Serialize};
92use smallvec::smallvec;
93use sp_api::impl_runtime_apis;
94use sp_consensus_slots::Slot;
95use sp_core::{OpaqueMetadata, H160, H256, U256};
96use sp_runtime::generic::Preamble;
97use sp_runtime::{
98 generic, impl_opaque_keys,
99 traits::{
100 BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, IdentityLookup,
101 PostDispatchInfoOf, UniqueSaturatedInto, Zero,
102 },
103 transaction_validity::{
104 InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError,
105 },
106 ApplyExtrinsicResult, DispatchErrorWithPostInfo, FixedPointNumber, Perbill, Permill,
107 Perquintill, SaturatedConversion,
108};
109use sp_std::{convert::TryFrom, prelude::*};
110use xcm::{
111 Version as XcmVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
112};
113use xcm_runtime_apis::{
114 dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
115 fees::Error as XcmPaymentApiError,
116};
117
118use runtime_params::*;
119
120#[cfg(feature = "std")]
121use sp_version::NativeVersion;
122use sp_version::RuntimeVersion;
123
124use nimbus_primitives::CanAuthor;
125
126mod migrations;
127mod precompiles;
128pub use precompiles::{
129 MoonbeamPrecompiles, PrecompileName, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX,
130};
131
132#[cfg(any(feature = "std", test))]
133pub use sp_runtime::BuildStorage;
134
135pub type Precompiles = MoonbeamPrecompiles<Runtime>;
136
137pub mod asset_config;
138pub mod bridge_config;
139#[cfg(not(feature = "disable-genesis-builder"))]
140pub mod genesis_config_preset;
141pub mod governance;
142pub mod runtime_params;
143mod weights;
144pub mod xcm_config;
145
146use governance::councils::*;
147pub(crate) use weights as moonbeam_weights;
148pub use weights::xcm as moonbeam_xcm_weights;
149
150pub mod currency {
152 use super::Balance;
153
154 pub const SUPPLY_FACTOR: Balance = 100;
156
157 pub const WEI: Balance = 1;
158 pub const KILOWEI: Balance = 1_000;
159 pub const MEGAWEI: Balance = 1_000_000;
160 pub const GIGAWEI: Balance = 1_000_000_000;
161 pub const MICROGLMR: Balance = 1_000_000_000_000;
162 pub const MILLIGLMR: Balance = 1_000_000_000_000_000;
163 pub const GLMR: Balance = 1_000_000_000_000_000_000;
164 pub const KILOGLMR: Balance = 1_000_000_000_000_000_000_000;
165
166 pub const TRANSACTION_BYTE_FEE: Balance = 1 * GIGAWEI * SUPPLY_FACTOR;
167 pub const STORAGE_BYTE_FEE: Balance = 100 * MICROGLMR * SUPPLY_FACTOR;
168 pub const WEIGHT_FEE: Balance = 50 * KILOWEI * SUPPLY_FACTOR / 4;
169
170 pub const fn deposit(items: u32, bytes: u32) -> Balance {
171 items as Balance * 100 * MILLIGLMR * SUPPLY_FACTOR + (bytes as Balance) * STORAGE_BYTE_FEE
172 }
173}
174
175pub const MAX_POV_SIZE: u32 = 10 * 1024 * 1024;
178
179pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
181 WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
182 MAX_POV_SIZE as u64,
183);
184
185pub const MILLISECS_PER_BLOCK: u64 = 6_000;
186pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
187pub const HOURS: BlockNumber = MINUTES * 60;
188pub const DAYS: BlockNumber = HOURS * 24;
189pub const WEEKS: BlockNumber = DAYS * 7;
190pub const MONTHS: BlockNumber = DAYS * 30;
191pub mod opaque {
196 use super::*;
197
198 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
199 pub type Block = generic::Block<Header, UncheckedExtrinsic>;
200
201 impl_opaque_keys! {
202 pub struct SessionKeys {
203 pub nimbus: AuthorInherent,
204 pub vrf: session_keys_primitives::VrfSessionKey,
205 }
206 }
207}
208
209#[sp_version::runtime_version]
214pub const VERSION: RuntimeVersion = RuntimeVersion {
215 spec_name: Cow::Borrowed("moonbeam"),
216 impl_name: Cow::Borrowed("moonbeam"),
217 authoring_version: 3,
218 spec_version: 4200,
219 impl_version: 0,
220 apis: RUNTIME_API_VERSIONS,
221 transaction_version: 3,
222 system_version: 1,
223};
224
225#[cfg(feature = "std")]
227pub fn native_version() -> NativeVersion {
228 NativeVersion {
229 runtime_version: VERSION,
230 can_author_with: Default::default(),
231 }
232}
233
234const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
235pub const NORMAL_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_mul(3).saturating_div(4);
236pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_GAS, 0);
241
242pub struct RuntimeBlockWeights;
243impl Get<frame_system::limits::BlockWeights> for RuntimeBlockWeights {
244 fn get() -> frame_system::limits::BlockWeights {
245 frame_system::limits::BlockWeights::builder()
246 .for_class(DispatchClass::Normal, |weights| {
247 weights.base_extrinsic = EXTRINSIC_BASE_WEIGHT;
248 weights.max_total = NORMAL_WEIGHT.into();
249 })
250 .for_class(DispatchClass::Operational, |weights| {
251 weights.max_total = MAXIMUM_BLOCK_WEIGHT.into();
252 weights.reserved = (MAXIMUM_BLOCK_WEIGHT - NORMAL_WEIGHT).into();
253 })
254 .avg_block_initialization(Perbill::from_percent(10))
255 .build()
256 .expect("Provided BlockWeight definitions are valid, qed")
257 }
258}
259
260parameter_types! {
261 pub const Version: RuntimeVersion = VERSION;
262 pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
264 ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
265}
266
267impl frame_system::Config for Runtime {
268 type AccountId = AccountId;
270 type RuntimeCall = RuntimeCall;
272 type Lookup = IdentityLookup<AccountId>;
274 type Nonce = Index;
276 type Block = Block;
278 type Hash = Hash;
280 type Hashing = BlakeTwo256;
282 type RuntimeEvent = RuntimeEvent;
284 type RuntimeOrigin = RuntimeOrigin;
286 type RuntimeTask = RuntimeTask;
288 type BlockHashCount = ConstU32<256>;
290 type BlockWeights = RuntimeBlockWeights;
292 type BlockLength = BlockLength;
294 type Version = Version;
296 type PalletInfo = PalletInfo;
297 type AccountData = pallet_balances::AccountData<Balance>;
298 type OnNewAccount = ();
299 type OnKilledAccount = ();
300 type DbWeight = moonbeam_weights::db::rocksdb::constants::RocksDbWeight;
301 type BaseCallFilter = MaintenanceMode;
302 type SystemWeightInfo = moonbeam_weights::frame_system::WeightInfo<Runtime>;
303 type SS58Prefix = ConstU16<1284>;
305 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
306 type MaxConsumers = frame_support::traits::ConstU32<16>;
307 type SingleBlockMigrations = migrations::SingleBlockMigrations<Runtime>;
308 type MultiBlockMigrator = MultiBlockMigrations;
309 type PreInherents = ();
310 type PostInherents = (
311 AsyncBacking,
313 );
314 type PostTransactions = ();
315 type ExtensionsWeightInfo = moonbeam_weights::frame_system_extensions::WeightInfo<Runtime>;
316}
317
318impl pallet_utility::Config for Runtime {
319 type RuntimeEvent = RuntimeEvent;
320 type RuntimeCall = RuntimeCall;
321 type PalletsOrigin = OriginCaller;
322 type WeightInfo = moonbeam_weights::pallet_utility::WeightInfo<Runtime>;
323}
324
325impl pallet_timestamp::Config for Runtime {
326 type Moment = u64;
328 type OnTimestampSet = ();
329 type MinimumPeriod = ConstU64<{ RELAY_CHAIN_SLOT_DURATION_MILLIS as u64 / 2 }>;
330 type WeightInfo = moonbeam_weights::pallet_timestamp::WeightInfo<Runtime>;
331}
332
333#[cfg(not(feature = "runtime-benchmarks"))]
334parameter_types! {
335 pub const ExistentialDeposit: Balance = 0;
336}
337
338#[cfg(feature = "runtime-benchmarks")]
339parameter_types! {
340 pub const ExistentialDeposit: Balance = 1;
341}
342
343impl pallet_balances::Config for Runtime {
344 type MaxReserves = ConstU32<50>;
345 type ReserveIdentifier = [u8; 4];
346 type MaxLocks = ConstU32<50>;
347 type Balance = Balance;
349 type RuntimeEvent = RuntimeEvent;
351 type DustRemoval = ();
352 type ExistentialDeposit = ExistentialDeposit;
353 type AccountStore = System;
354 type FreezeIdentifier = RuntimeFreezeReason;
355 type MaxFreezes = VariantCountOf<Self::RuntimeFreezeReason>;
356 type RuntimeHoldReason = RuntimeHoldReason;
357 type RuntimeFreezeReason = RuntimeFreezeReason;
358 type WeightInfo = moonbeam_weights::pallet_balances::WeightInfo<Runtime>;
359 type DoneSlashHandler = ();
360}
361
362pub struct LengthToFee;
363impl WeightToFeePolynomial for LengthToFee {
364 type Balance = Balance;
365
366 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
367 smallvec![
368 WeightToFeeCoefficient {
369 degree: 1,
370 coeff_frac: Perbill::zero(),
371 coeff_integer: currency::TRANSACTION_BYTE_FEE,
372 negative: false,
373 },
374 WeightToFeeCoefficient {
375 degree: 3,
376 coeff_frac: Perbill::zero(),
377 coeff_integer: 1 * currency::SUPPLY_FACTOR,
378 negative: false,
379 },
380 ]
381 }
382}
383
384impl pallet_transaction_payment::Config for Runtime {
385 type RuntimeEvent = RuntimeEvent;
386 type OnChargeTransaction = FungibleAdapter<
387 Balances,
388 DealWithSubstrateFeesAndTip<
389 Runtime,
390 dynamic_params::runtime_config::FeesTreasuryProportion,
391 >,
392 >;
393 type OperationalFeeMultiplier = ConstU8<5>;
394 type WeightToFee = WeightToFee<
395 RefTimeToFee<ConstU128<{ currency::WEIGHT_FEE }>>,
396 ProofSizeToFee<
397 ConstU128<
398 { currency::WEIGHT_FEE.saturating_mul(GasLimitPovSizeRatio::get() as Balance) },
399 >,
400 >,
401 >;
402 type LengthToFee = LengthToFee;
403 type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Runtime>;
404 type WeightInfo = weights::pallet_transaction_payment::WeightInfo<Runtime>;
405}
406
407impl pallet_evm_chain_id::Config for Runtime {}
408
409pub const GAS_PER_SECOND: u64 = 40_000_000;
414
415pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND;
418
419pub const BLOCK_STORAGE_LIMIT: u64 = 160 * 1024;
423
424parameter_types! {
425 pub BlockGasLimit: U256
426 = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
427 pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(35);
430 pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(4, 1_000);
433 pub MinimumMultiplier: Multiplier = Multiplier::from(1u128);
439 pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128);
442 pub PrecompilesValue: MoonbeamPrecompiles<Runtime> = MoonbeamPrecompiles::<_>::new();
443 pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
444 pub const GasLimitPovSizeRatio: u64 = 8;
451 pub GasLimitStorageGrowthRatio: u64 = 366;
454}
455
456pub struct TransactionPaymentAsGasPrice;
457impl FeeCalculator for TransactionPaymentAsGasPrice {
458 fn min_gas_price() -> (U256, Weight) {
459 let min_gas_price = TransactionPayment::next_fee_multiplier()
473 .saturating_mul_int((currency::WEIGHT_FEE).saturating_mul(WEIGHT_PER_GAS as u128));
474 (
475 min_gas_price.into(),
476 <Runtime as frame_system::Config>::DbWeight::get().reads(1),
477 )
478 }
479}
480
481pub type SlowAdjustingFeeUpdate<R> = TargetedFeeAdjustment<
493 R,
494 TargetBlockFullness,
495 AdjustmentVariable,
496 MinimumMultiplier,
497 MaximumMultiplier,
498>;
499
500use frame_support::traits::FindAuthor;
501pub struct FindAuthorAdapter<Inner>(sp_std::marker::PhantomData<Inner>);
507
508impl<Inner> FindAuthor<H160> for FindAuthorAdapter<Inner>
509where
510 Inner: FindAuthor<AccountId20>,
511{
512 fn find_author<'a, I>(digests: I) -> Option<H160>
513 where
514 I: 'a + IntoIterator<Item = (sp_runtime::ConsensusEngineId, &'a [u8])>,
515 {
516 Inner::find_author(digests).map(Into::into)
517 }
518}
519
520moonbeam_runtime_common::impl_on_charge_evm_transaction!();
521
522impl pallet_evm::Config for Runtime {
523 type FeeCalculator = TransactionPaymentAsGasPrice;
524 type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
525 type WeightPerGas = WeightPerGas;
526 type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;
527 type CallOrigin = EnsureAddressRoot<AccountId>;
528 type WithdrawOrigin = EnsureAddressNever<AccountId>;
529 type AddressMapping = IdentityAddressMapping;
530 type Currency = Balances;
531 type Runner = pallet_evm::runner::stack::Runner<Self>;
532 type PrecompilesType = MoonbeamPrecompiles<Self>;
533 type PrecompilesValue = PrecompilesValue;
534 type ChainId = EthereumChainId;
535 type OnChargeTransaction = OnChargeEVMTransaction<
536 DealWithEthereumBaseFees<Runtime, dynamic_params::runtime_config::FeesTreasuryProportion>,
537 DealWithEthereumPriorityFees<Runtime>,
538 >;
539 type BlockGasLimit = BlockGasLimit;
540 type FindAuthor = FindAuthorAdapter<AuthorInherent>;
541 type OnCreate = ();
542 type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
543 type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio;
544 type Timestamp = Timestamp;
545 type AccountProvider = FrameSystemAccountProvider<Runtime>;
546 type CreateOriginFilter = ();
547 type CreateInnerOriginFilter = ();
548 type WeightInfo = moonbeam_weights::pallet_evm::WeightInfo<Runtime>;
549}
550
551parameter_types! {
552 pub MaxServiceWeight: Weight = NORMAL_DISPATCH_RATIO * RuntimeBlockWeights::get().max_block;
553}
554
555impl pallet_scheduler::Config for Runtime {
556 type RuntimeEvent = RuntimeEvent;
557 type RuntimeOrigin = RuntimeOrigin;
558 type PalletsOrigin = OriginCaller;
559 type RuntimeCall = RuntimeCall;
560 type MaximumWeight = MaxServiceWeight;
561 type ScheduleOrigin = EnsureRoot<AccountId>;
562 type MaxScheduledPerBlock = ConstU32<50>;
563 type WeightInfo = moonbeam_weights::pallet_scheduler::WeightInfo<Runtime>;
564 type OriginPrivilegeCmp = EqualPrivilegeOnly;
565 type Preimages = Preimage;
566 type BlockNumberProvider = System;
567}
568
569parameter_types! {
570 pub const PreimageBaseDeposit: Balance = 5 * currency::GLMR * currency::SUPPLY_FACTOR ;
571 pub const PreimageByteDeposit: Balance = currency::STORAGE_BYTE_FEE;
572 pub const PreimageHoldReason: RuntimeHoldReason =
573 RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
574}
575
576impl pallet_preimage::Config for Runtime {
577 type WeightInfo = moonbeam_weights::pallet_preimage::WeightInfo<Runtime>;
578 type RuntimeEvent = RuntimeEvent;
579 type Currency = Balances;
580 type ManagerOrigin = EnsureRoot<AccountId>;
581 type Consideration = HoldConsideration<
582 AccountId,
583 Balances,
584 PreimageHoldReason,
585 LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
586 >;
587}
588
589parameter_types! {
590 pub const ProposalBond: Permill = Permill::from_percent(5);
591 pub const TreasuryId: PalletId = PalletId(*b"py/trsry");
592 pub TreasuryAccount: AccountId = Treasury::account_id();
593 pub const MaxSpendBalance: crate::Balance = crate::Balance::max_value();
594}
595
596type RootOrTreasuryCouncilOrigin = EitherOfDiverse<
597 EnsureRoot<AccountId>,
598 pallet_collective::EnsureProportionMoreThan<AccountId, TreasuryCouncilInstance, 1, 2>,
599>;
600
601impl pallet_treasury::Config for Runtime {
602 type PalletId = TreasuryId;
603 type Currency = Balances;
604 type RejectOrigin = RootOrTreasuryCouncilOrigin;
606 type RuntimeEvent = RuntimeEvent;
607 type SpendPeriod = ConstU32<{ 6 * DAYS }>;
608 type Burn = ();
609 type BurnDestination = ();
610 type MaxApprovals = ConstU32<100>;
611 type WeightInfo = moonbeam_weights::pallet_treasury::WeightInfo<Runtime>;
612 type SpendFunds = ();
613 type SpendOrigin =
614 frame_system::EnsureWithSuccess<RootOrTreasuryCouncilOrigin, AccountId, MaxSpendBalance>;
615 type AssetKind = NativeOrWithId<AssetId>;
616 type Beneficiary = AccountId;
617 type BeneficiaryLookup = IdentityLookup<AccountId>;
618 type Paymaster = MultiAssetPaymaster<Runtime, TreasuryAccount, Balances>;
619 type BalanceConverter = AssetRateConverter<Runtime, Balances>;
620 type PayoutPeriod = ConstU32<{ 30 * DAYS }>;
621 #[cfg(feature = "runtime-benchmarks")]
622 type BenchmarkHelper = BenchmarkHelper<Runtime>;
623 type BlockNumberProvider = System;
624}
625
626parameter_types! {
627 pub const MaxSubAccounts: u32 = 100;
628 pub const MaxAdditionalFields: u32 = 100;
629 pub const MaxRegistrars: u32 = 20;
630 pub const PendingUsernameExpiration: u32 = 7 * DAYS;
631 pub const MaxSuffixLength: u32 = 7;
632 pub const MaxUsernameLength: u32 = 32;
633}
634
635type IdentityForceOrigin =
636 EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
637type IdentityRegistrarOrigin =
638 EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
639
640impl pallet_identity::Config for Runtime {
641 type RuntimeEvent = RuntimeEvent;
642 type Currency = Balances;
643 type BasicDeposit = ConstU128<{ currency::deposit(1, 258) }>;
645 type ByteDeposit = ConstU128<{ currency::deposit(0, 1) }>;
647 type SubAccountDeposit = ConstU128<{ currency::deposit(1, 53) }>;
649 type MaxSubAccounts = MaxSubAccounts;
650 type IdentityInformation = pallet_identity::legacy::IdentityInfo<MaxAdditionalFields>;
651 type MaxRegistrars = MaxRegistrars;
652 type Slashed = Treasury;
653 type ForceOrigin = IdentityForceOrigin;
654 type RegistrarOrigin = IdentityRegistrarOrigin;
655 type OffchainSignature = Signature;
656 type SigningPublicKey = <Signature as sp_runtime::traits::Verify>::Signer;
657 type UsernameAuthorityOrigin = EnsureRoot<AccountId>;
658 type PendingUsernameExpiration = PendingUsernameExpiration;
659 type MaxSuffixLength = MaxSuffixLength;
660 type MaxUsernameLength = MaxUsernameLength;
661 type WeightInfo = moonbeam_weights::pallet_identity::WeightInfo<Runtime>;
662 type UsernameDeposit = ConstU128<{ currency::deposit(0, MaxUsernameLength::get()) }>;
663 type UsernameGracePeriod = ConstU32<{ 30 * DAYS }>;
664 #[cfg(feature = "runtime-benchmarks")]
665 type BenchmarkHelper = BenchmarkHelper<Runtime>;
666}
667
668pub struct TransactionConverter;
669
670impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {
671 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {
672 UncheckedExtrinsic::new_bare(
673 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),
674 )
675 }
676}
677
678impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {
679 fn convert_transaction(
680 &self,
681 transaction: pallet_ethereum::Transaction,
682 ) -> opaque::UncheckedExtrinsic {
683 let extrinsic = UncheckedExtrinsic::new_bare(
684 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),
685 );
686 let encoded = extrinsic.encode();
687 opaque::UncheckedExtrinsic::decode(&mut &encoded[..])
688 .expect("Encoded extrinsic is always valid")
689 }
690}
691
692parameter_types! {
693 pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;
694}
695
696impl pallet_ethereum::Config for Runtime {
697 type StateRoot = pallet_ethereum::IntermediateStateRoot<Self::Version>;
698 type PostLogContent = PostBlockAndTxnHashes;
699 type ExtraDataLength = ConstU32<30>;
700}
701
702const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
704const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
707const RELAY_PARENT_OFFSET: u32 = 1;
709const BLOCK_PROCESSING_VELOCITY: u32 = 1;
712
713type ConsensusHook = pallet_async_backing::consensus_hook::FixedVelocityConsensusHook<
714 Runtime,
715 RELAY_CHAIN_SLOT_DURATION_MILLIS,
716 BLOCK_PROCESSING_VELOCITY,
717 UNINCLUDED_SEGMENT_CAPACITY,
718>;
719
720impl cumulus_pallet_parachain_system::Config for Runtime {
721 type RuntimeEvent = RuntimeEvent;
722 type OnSystemEvent = ();
723 type SelfParaId = ParachainInfo;
724 type ReservedDmpWeight = ReservedDmpWeight;
725 type OutboundXcmpMessageSource = XcmpQueue;
726 type XcmpMessageHandler = XcmpQueue;
727 type ReservedXcmpWeight = ReservedXcmpWeight;
728 type CheckAssociatedRelayNumber = EmergencyParaXcm;
729 type ConsensusHook = ConsensusHook;
730 type DmpQueue = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
731 type WeightInfo = moonbeam_weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
732 type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector<Runtime>;
733 type RelayParentOffset = ConstU32<0>;
734}
735
736pub struct EthereumXcmEnsureProxy;
737impl xcm_primitives::EnsureProxy<AccountId> for EthereumXcmEnsureProxy {
738 fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> {
739 let def: pallet_proxy::ProxyDefinition<AccountId, ProxyType, BlockNumber> =
741 pallet_proxy::Pallet::<Runtime>::find_proxy(
742 &delegator,
743 &delegatee,
744 Some(ProxyType::Any),
745 )
746 .map_err(|_| "proxy error: expected `ProxyType::Any`")?;
747 ensure!(def.delay.is_zero(), "proxy delay is Non-zero`");
749 Ok(())
750 }
751}
752
753impl pallet_ethereum_xcm::Config for Runtime {
754 type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper;
755 type ValidatedTransaction = pallet_ethereum::ValidatedTransaction<Self>;
756 type XcmEthereumOrigin = pallet_ethereum_xcm::EnsureXcmEthereumTransaction;
757 type ReservedXcmpWeight = ReservedXcmpWeight;
758 type EnsureProxy = EthereumXcmEnsureProxy;
759 type ControllerOrigin = EnsureRoot<AccountId>;
760 type ForceOrigin = EnsureRoot<AccountId>;
761}
762
763parameter_types! {
764 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
766 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
767 pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;
768}
769
770impl parachain_info::Config for Runtime {}
771
772pub struct OnNewRound;
773impl pallet_parachain_staking::OnNewRound for OnNewRound {
774 fn on_new_round(round_index: pallet_parachain_staking::RoundIndex) -> Weight {
775 MoonbeamOrbiters::on_new_round(round_index)
776 }
777}
778pub struct PayoutCollatorOrOrbiterReward;
779impl pallet_parachain_staking::PayoutCollatorReward<Runtime> for PayoutCollatorOrOrbiterReward {
780 fn payout_collator_reward(
781 for_round: pallet_parachain_staking::RoundIndex,
782 collator_id: AccountId,
783 amount: Balance,
784 ) -> Weight {
785 let extra_weight =
786 if MoonbeamOrbiters::is_collator_pool_with_active_orbiter(for_round, collator_id) {
787 MoonbeamOrbiters::distribute_rewards(for_round, collator_id, amount)
788 } else {
789 ParachainStaking::mint_collator_reward(for_round, collator_id, amount)
790 };
791
792 <Runtime as frame_system::Config>::DbWeight::get()
793 .reads(1)
794 .saturating_add(extra_weight)
795 }
796}
797
798pub struct OnInactiveCollator;
799impl pallet_parachain_staking::OnInactiveCollator<Runtime> for OnInactiveCollator {
800 fn on_inactive_collator(
801 collator_id: AccountId,
802 round: pallet_parachain_staking::RoundIndex,
803 ) -> Result<Weight, DispatchErrorWithPostInfo<PostDispatchInfo>> {
804 let extra_weight = if !MoonbeamOrbiters::is_collator_pool_with_active_orbiter(
805 round,
806 collator_id.clone(),
807 ) {
808 ParachainStaking::go_offline_inner(collator_id)?;
809 <Runtime as pallet_parachain_staking::Config>::WeightInfo::go_offline(
810 pallet_parachain_staking::MAX_CANDIDATES,
811 )
812 } else {
813 Weight::zero()
814 };
815
816 Ok(<Runtime as frame_system::Config>::DbWeight::get()
817 .reads(1)
818 .saturating_add(extra_weight))
819 }
820}
821type MonetaryGovernanceOrigin =
822 EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
823
824pub struct RelayChainSlotProvider;
825impl Get<Slot> for RelayChainSlotProvider {
826 fn get() -> Slot {
827 let slot_info = pallet_async_backing::pallet::Pallet::<Runtime>::slot_info();
828 slot_info.unwrap_or_default().0
829 }
830}
831
832parameter_types! {
833 pub const LinearInflationThreshold: Option<Balance> = Some(1_200_000_000 * currency::GLMR);
835}
836
837impl pallet_parachain_staking::Config for Runtime {
838 type Currency = Balances;
839 type MonetaryGovernanceOrigin = MonetaryGovernanceOrigin;
840 type MinBlocksPerRound = ConstU32<10>;
842 type MaxOfflineRounds = ConstU32<1>;
844 type LeaveCandidatesDelay = ConstU32<{ 4 * 7 }>;
846 type CandidateBondLessDelay = ConstU32<{ 4 * 7 }>;
848 type LeaveDelegatorsDelay = ConstU32<{ 4 * 7 }>;
850 type RevokeDelegationDelay = ConstU32<{ 4 * 7 }>;
852 type DelegationBondLessDelay = ConstU32<{ 4 * 7 }>;
854 type RewardPaymentDelay = ConstU32<2>;
856 type MinSelectedCandidates = ConstU32<8>;
858 type MaxTopDelegationsPerCandidate = ConstU32<300>;
860 type MaxBottomDelegationsPerCandidate = ConstU32<50>;
862 type MaxDelegationsPerDelegator = ConstU32<100>;
864 type MaxScheduledRequestsPerDelegator = ConstU32<50>;
866 type MinCandidateStk = ConstU128<{ 100_000 * currency::GLMR }>;
868 type MinDelegation = ConstU128<{ 500 * currency::MILLIGLMR * currency::SUPPLY_FACTOR }>;
870 type BlockAuthor = AuthorInherent;
871 type OnCollatorPayout = ();
872 type PayoutCollatorReward = PayoutCollatorOrOrbiterReward;
873 type OnInactiveCollator = OnInactiveCollator;
874 type OnNewRound = OnNewRound;
875 type SlotProvider = RelayChainSlotProvider;
876 type WeightInfo = moonbeam_weights::pallet_parachain_staking::WeightInfo<Runtime>;
877 type MaxCandidates = ConstU32<200>;
878 type SlotDuration = ConstU64<MILLISECS_PER_BLOCK>;
879 type BlockTime = ConstU64<MILLISECS_PER_BLOCK>;
880 type RuntimeFreezeReason = RuntimeFreezeReason;
881 type LinearInflationThreshold = LinearInflationThreshold;
882}
883
884impl pallet_author_inherent::Config for Runtime {
885 type SlotBeacon = RelaychainDataProvider<Self>;
886 type AccountLookup = MoonbeamOrbiters;
887 type CanAuthor = AuthorFilter;
888 type AuthorId = AccountId;
889 type WeightInfo = moonbeam_weights::pallet_author_inherent::WeightInfo<Runtime>;
890}
891
892impl pallet_author_slot_filter::Config for Runtime {
893 type RandomnessSource = Randomness;
894 type PotentialAuthors = ParachainStaking;
895 type WeightInfo = moonbeam_weights::pallet_author_slot_filter::WeightInfo<Runtime>;
896}
897
898impl pallet_async_backing::Config for Runtime {
899 type AllowMultipleBlocksPerSlot = ConstBool<true>;
900 type GetAndVerifySlot = pallet_async_backing::RelaySlot;
901 type SlotDuration = ConstU64<MILLISECS_PER_BLOCK>;
902 type ExpectedBlockTime = ConstU64<MILLISECS_PER_BLOCK>;
903}
904
905parameter_types! {
906 pub const InitializationPayment: Perbill = Perbill::from_percent(30);
907 pub const RelaySignaturesThreshold: Perbill = Perbill::from_percent(100);
908 pub const SignatureNetworkIdentifier: &'static [u8] = b"moonbeam-";
909}
910
911impl pallet_crowdloan_rewards::Config for Runtime {
912 type Initialized = ConstBool<false>;
913 type InitializationPayment = InitializationPayment;
914 type MaxInitContributors = ConstU32<500>;
915 type MinimumReward = ConstU128<0>;
916 type RewardCurrency = Balances;
917 type RelayChainAccountId = [u8; 32];
918 type RewardAddressAssociateOrigin = EnsureSigned<Self::AccountId>;
919 type RewardAddressChangeOrigin = EnsureSigned<Self::AccountId>;
920 type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold;
921 type SignatureNetworkIdentifier = SignatureNetworkIdentifier;
922 type VestingBlockNumber = relay_chain::BlockNumber;
923 type VestingBlockProvider = RelaychainDataProvider<Self>;
924 type WeightInfo = moonbeam_weights::pallet_crowdloan_rewards::WeightInfo<Runtime>;
925}
926
927impl pallet_author_mapping::Config for Runtime {
930 type DepositCurrency = Balances;
931 type DepositAmount = ConstU128<{ 100 * currency::GLMR * currency::SUPPLY_FACTOR }>;
932 type Keys = session_keys_primitives::VrfId;
933 type WeightInfo = moonbeam_weights::pallet_author_mapping::WeightInfo<Runtime>;
934}
935
936#[derive(
938 Copy,
939 Clone,
940 Eq,
941 PartialEq,
942 Ord,
943 PartialOrd,
944 Encode,
945 Decode,
946 Debug,
947 MaxEncodedLen,
948 TypeInfo,
949 Serialize,
950 Deserialize,
951 DecodeWithMemTracking,
952)]
953pub enum ProxyType {
954 Any = 0,
956 NonTransfer = 1,
958 Governance = 2,
960 Staking = 3,
962 CancelProxy = 4,
964 Balances = 5,
966 AuthorMapping = 6,
968 IdentityJudgement = 7,
970}
971
972impl Default for ProxyType {
973 fn default() -> Self {
974 Self::Any
975 }
976}
977
978fn is_governance_precompile(precompile_name: &precompiles::PrecompileName) -> bool {
979 matches!(
980 precompile_name,
981 PrecompileName::ConvictionVotingPrecompile
982 | PrecompileName::PreimagePrecompile
983 | PrecompileName::ReferendaPrecompile
984 | PrecompileName::OpenTechCommitteeInstance
985 | PrecompileName::TreasuryCouncilInstance
986 )
987}
988
989impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType {
992 fn is_evm_proxy_call_allowed(
993 &self,
994 call: &pallet_evm_precompile_proxy::EvmSubCall,
995 recipient_has_code: bool,
996 gas: u64,
997 ) -> precompile_utils::EvmResult<bool> {
998 Ok(match self {
999 ProxyType::Any => {
1000 match PrecompileName::from_address(call.to.0) {
1001 Some(
1006 PrecompileName::AuthorMappingPrecompile
1007 | PrecompileName::ParachainStakingPrecompile,
1008 ) => true,
1009 Some(ref precompile) if is_governance_precompile(precompile) => true,
1010 Some(_) => false,
1012 None => {
1017 !recipient_has_code
1022 && !precompile_utils::precompile_set::is_precompile_or_fail::<Runtime>(
1023 call.to.0, gas,
1024 )?
1025 }
1026 }
1027 }
1028 ProxyType::NonTransfer => {
1029 call.value == U256::zero()
1030 && match PrecompileName::from_address(call.to.0) {
1031 Some(
1032 PrecompileName::AuthorMappingPrecompile
1033 | PrecompileName::ParachainStakingPrecompile,
1034 ) => true,
1035 Some(ref precompile) if is_governance_precompile(precompile) => true,
1036 _ => false,
1037 }
1038 }
1039 ProxyType::Governance => {
1040 call.value == U256::zero()
1041 && matches!(
1042 PrecompileName::from_address(call.to.0),
1043 Some(ref precompile) if is_governance_precompile(precompile)
1044 )
1045 }
1046 ProxyType::Staking => {
1047 call.value == U256::zero()
1048 && matches!(
1049 PrecompileName::from_address(call.to.0),
1050 Some(
1051 PrecompileName::AuthorMappingPrecompile
1052 | PrecompileName::ParachainStakingPrecompile
1053 )
1054 )
1055 }
1056 ProxyType::CancelProxy => false,
1058 ProxyType::Balances => {
1059 !recipient_has_code
1063 && !precompile_utils::precompile_set::is_precompile_or_fail::<Runtime>(
1064 call.to.0, gas,
1065 )?
1066 }
1067 ProxyType::AuthorMapping => {
1068 call.value == U256::zero()
1069 && matches!(
1070 PrecompileName::from_address(call.to.0),
1071 Some(PrecompileName::AuthorMappingPrecompile)
1072 )
1073 }
1074 ProxyType::IdentityJudgement => false,
1076 })
1077 }
1078}
1079
1080impl InstanceFilter<RuntimeCall> for ProxyType {
1082 fn filter(&self, c: &RuntimeCall) -> bool {
1083 match self {
1084 ProxyType::Any => true,
1085 ProxyType::NonTransfer => match c {
1086 RuntimeCall::Identity(
1087 pallet_identity::Call::add_sub { .. } | pallet_identity::Call::set_subs { .. },
1088 ) => false,
1089 call => {
1090 matches!(
1091 call,
1092 RuntimeCall::System(..)
1093 | RuntimeCall::ParachainSystem(..)
1094 | RuntimeCall::Timestamp(..)
1095 | RuntimeCall::ParachainStaking(..)
1096 | RuntimeCall::Referenda(..)
1097 | RuntimeCall::Preimage(..)
1098 | RuntimeCall::ConvictionVoting(..)
1099 | RuntimeCall::TreasuryCouncilCollective(..)
1100 | RuntimeCall::OpenTechCommitteeCollective(..)
1101 | RuntimeCall::Utility(..)
1102 | RuntimeCall::Proxy(..)
1103 | RuntimeCall::Identity(..)
1104 | RuntimeCall::AuthorMapping(..)
1105 | RuntimeCall::CrowdloanRewards(
1106 pallet_crowdloan_rewards::Call::claim { .. }
1107 )
1108 )
1109 }
1110 },
1111 ProxyType::Governance => matches!(
1112 c,
1113 RuntimeCall::Referenda(..)
1114 | RuntimeCall::Preimage(..)
1115 | RuntimeCall::ConvictionVoting(..)
1116 | RuntimeCall::TreasuryCouncilCollective(..)
1117 | RuntimeCall::OpenTechCommitteeCollective(..)
1118 | RuntimeCall::Utility(..)
1119 ),
1120 ProxyType::Staking => matches!(
1121 c,
1122 RuntimeCall::ParachainStaking(..)
1123 | RuntimeCall::Utility(..)
1124 | RuntimeCall::AuthorMapping(..)
1125 | RuntimeCall::MoonbeamOrbiters(..)
1126 ),
1127 ProxyType::CancelProxy => matches!(
1128 c,
1129 RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })
1130 ),
1131 ProxyType::Balances => {
1132 matches!(c, RuntimeCall::Balances(..) | RuntimeCall::Utility(..))
1133 }
1134 ProxyType::AuthorMapping => matches!(c, RuntimeCall::AuthorMapping(..)),
1135 ProxyType::IdentityJudgement => matches!(
1136 c,
1137 RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })
1138 | RuntimeCall::Utility(..)
1139 ),
1140 }
1141 }
1142
1143 fn is_superset(&self, o: &Self) -> bool {
1144 match (self, o) {
1145 (x, y) if x == y => true,
1146 (ProxyType::Any, _) => true,
1147 (_, ProxyType::Any) => false,
1148 _ => false,
1149 }
1150 }
1151}
1152
1153impl pallet_proxy::Config for Runtime {
1154 type RuntimeEvent = RuntimeEvent;
1155 type RuntimeCall = RuntimeCall;
1156 type Currency = Balances;
1157 type ProxyType = ProxyType;
1158 type ProxyDepositBase = ConstU128<{ currency::deposit(1, 8) }>;
1160 type ProxyDepositFactor = ConstU128<{ currency::deposit(0, 21) }>;
1162 type MaxProxies = ConstU32<32>;
1163 type WeightInfo = moonbeam_weights::pallet_proxy::WeightInfo<Runtime>;
1164 type MaxPending = ConstU32<32>;
1165 type CallHasher = BlakeTwo256;
1166 type AnnouncementDepositBase = ConstU128<{ currency::deposit(1, 8) }>;
1167 type AnnouncementDepositFactor = ConstU128<{ currency::deposit(0, 56) }>;
1172 type BlockNumberProvider = System;
1173}
1174
1175pub type ForeignAssetMigratorOrigin = EitherOfDiverse<
1176 EnsureRoot<AccountId>,
1177 EitherOfDiverse<
1178 pallet_collective::EnsureProportionMoreThan<AccountId, OpenTechCommitteeInstance, 5, 9>,
1179 EitherOf<
1180 governance::custom_origins::GeneralAdmin,
1181 governance::custom_origins::FastGeneralAdmin,
1182 >,
1183 >,
1184>;
1185
1186impl pallet_moonbeam_lazy_migrations::Config for Runtime {
1187 type WeightInfo = moonbeam_weights::pallet_moonbeam_lazy_migrations::WeightInfo<Runtime>;
1188}
1189
1190pub struct MaintenanceFilter;
1192impl Contains<RuntimeCall> for MaintenanceFilter {
1193 fn contains(c: &RuntimeCall) -> bool {
1194 match c {
1195 RuntimeCall::Balances(_) => false,
1196 RuntimeCall::CrowdloanRewards(_) => false,
1197 RuntimeCall::Ethereum(_) => false,
1198 RuntimeCall::EVM(_) => false,
1199 RuntimeCall::Identity(_) => false,
1200 RuntimeCall::ParachainStaking(_) => false,
1201 RuntimeCall::MoonbeamOrbiters(_) => false,
1202 RuntimeCall::PolkadotXcm(_) => false,
1203 RuntimeCall::Treasury(_) => false,
1204 RuntimeCall::XcmTransactor(_) => false,
1205 RuntimeCall::EthereumXcm(_) => false,
1206 _ => true,
1207 }
1208 }
1209}
1210
1211pub struct NormalFilter;
1213
1214impl Contains<RuntimeCall> for NormalFilter {
1215 fn contains(c: &RuntimeCall) -> bool {
1216 match c {
1217 RuntimeCall::PolkadotXcm(method) => match method {
1218 pallet_xcm::Call::send { .. }
1220 | pallet_xcm::Call::claim_assets { .. }
1221 | pallet_xcm::Call::transfer_assets { .. }
1222 | pallet_xcm::Call::transfer_assets_using_type_and_then { .. } => true,
1223 pallet_xcm::Call::force_xcm_version { .. }
1225 | pallet_xcm::Call::force_default_xcm_version { .. }
1226 | pallet_xcm::Call::force_subscribe_version_notify { .. }
1227 | pallet_xcm::Call::force_unsubscribe_version_notify { .. } => true,
1228 _ => false,
1230 },
1231 RuntimeCall::Proxy(method) => match method {
1232 pallet_proxy::Call::proxy { real, .. } => {
1233 !pallet_evm::AccountCodes::<Runtime>::contains_key(H160::from(*real))
1234 }
1235 _ => true,
1236 },
1237 RuntimeCall::EVM(_) => false,
1243 _ => true,
1244 }
1245 }
1246}
1247
1248pub struct XcmExecutionManager;
1249impl moonkit_xcm_primitives::PauseXcmExecution for XcmExecutionManager {
1250 fn suspend_xcm_execution() -> DispatchResult {
1251 XcmpQueue::suspend_xcm_execution(RuntimeOrigin::root())
1252 }
1253 fn resume_xcm_execution() -> DispatchResult {
1254 XcmpQueue::resume_xcm_execution(RuntimeOrigin::root())
1255 }
1256}
1257
1258impl pallet_maintenance_mode::Config for Runtime {
1259 type NormalCallFilter = NormalFilter;
1260 type MaintenanceCallFilter = MaintenanceFilter;
1261 type MaintenanceOrigin =
1262 pallet_collective::EnsureProportionAtLeast<AccountId, OpenTechCommitteeInstance, 5, 9>;
1263 type XcmExecutionManager = XcmExecutionManager;
1264}
1265
1266impl pallet_proxy_genesis_companion::Config for Runtime {
1267 type ProxyType = ProxyType;
1268 type BlockNumberProvider = System;
1269}
1270
1271parameter_types! {
1272 pub OrbiterReserveIdentifier: [u8; 4] = [b'o', b'r', b'b', b'i'];
1273}
1274
1275type AddCollatorOrigin =
1276 EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
1277type DelCollatorOrigin =
1278 EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
1279
1280impl pallet_moonbeam_orbiters::Config for Runtime {
1281 type AccountLookup = AuthorMapping;
1282 type AddCollatorOrigin = AddCollatorOrigin;
1283 type Currency = Balances;
1284 type DelCollatorOrigin = DelCollatorOrigin;
1285 type MaxPoolSize = ConstU32<8>;
1287 type MaxRoundArchive = ConstU32<4>;
1289 type OrbiterReserveIdentifier = OrbiterReserveIdentifier;
1290 type RotatePeriod = ConstU32<1>;
1291 type RoundIndex = pallet_parachain_staking::RoundIndex;
1293 type WeightInfo = moonbeam_weights::pallet_moonbeam_orbiters::WeightInfo<Runtime>;
1294}
1295
1296fn relay_chain_state_proof<Runtime>() -> RelayChainStateProof
1298where
1299 Runtime: cumulus_pallet_parachain_system::Config,
1300{
1301 let relay_storage_root = ValidationData::<Runtime>::get()
1302 .expect("set in `set_validation_data`")
1303 .relay_parent_storage_root;
1304 let relay_chain_state =
1305 RelayStateProof::<Runtime>::get().expect("set in `set_validation_data`");
1306 RelayChainStateProof::new(ParachainInfo::get(), relay_storage_root, relay_chain_state)
1307 .expect("Invalid relay chain state proof, already constructed in `set_validation_data`")
1308}
1309
1310pub struct BabeDataGetter<Runtime>(sp_std::marker::PhantomData<Runtime>);
1311impl<Runtime> pallet_randomness::GetBabeData<u64, Option<Hash>> for BabeDataGetter<Runtime>
1312where
1313 Runtime: cumulus_pallet_parachain_system::Config,
1314{
1315 fn get_epoch_index() -> u64 {
1317 if cfg!(feature = "runtime-benchmarks") {
1318 let _relay_storage_root = ValidationData::<Runtime>::get();
1320 let _relay_chain_state = RelayStateProof::<Runtime>::get();
1321 const BENCHMARKING_NEW_EPOCH: u64 = 10u64;
1322 return BENCHMARKING_NEW_EPOCH;
1323 }
1324 relay_chain_state_proof::<Runtime>()
1325 .read_optional_entry(relay_chain::well_known_keys::EPOCH_INDEX)
1326 .ok()
1327 .flatten()
1328 .expect("expected to be able to read epoch index from relay chain state proof")
1329 }
1330 fn get_epoch_randomness() -> Option<Hash> {
1331 if cfg!(feature = "runtime-benchmarks") {
1332 let _relay_storage_root = ValidationData::<Runtime>::get();
1334 let _relay_chain_state = RelayStateProof::<Runtime>::get();
1335 let benchmarking_babe_output = Hash::default();
1336 return Some(benchmarking_babe_output);
1337 }
1338 relay_chain_state_proof::<Runtime>()
1339 .read_optional_entry(relay_chain::well_known_keys::ONE_EPOCH_AGO_RANDOMNESS)
1340 .ok()
1341 .flatten()
1342 }
1343}
1344
1345impl pallet_randomness::Config for Runtime {
1346 type AddressMapping = sp_runtime::traits::ConvertInto;
1347 type Currency = Balances;
1348 type BabeDataGetter = BabeDataGetter<Runtime>;
1349 type VrfKeyLookup = AuthorMapping;
1350 type Deposit = runtime_params::PalletRandomnessDepositU128;
1351 type MaxRandomWords = ConstU8<100>;
1352 type MinBlockDelay = ConstU32<2>;
1353 type MaxBlockDelay = ConstU32<2_000>;
1354 type BlockExpirationDelay = ConstU32<10_000>;
1355 type EpochExpirationDelay = ConstU64<10_000>;
1356 type WeightInfo = moonbeam_weights::pallet_randomness::WeightInfo<Runtime>;
1357}
1358
1359impl pallet_root_testing::Config for Runtime {
1360 type RuntimeEvent = RuntimeEvent;
1361}
1362
1363parameter_types! {
1364 pub const DepositBase: Balance = currency::deposit(1, 96);
1366 pub const DepositFactor: Balance = currency::deposit(0, 20);
1368 pub const MaxSignatories: u32 = 100;
1369}
1370
1371impl pallet_multisig::Config for Runtime {
1372 type RuntimeEvent = RuntimeEvent;
1373 type RuntimeCall = RuntimeCall;
1374 type Currency = Balances;
1375 type DepositBase = DepositBase;
1376 type DepositFactor = DepositFactor;
1377 type MaxSignatories = MaxSignatories;
1378 type WeightInfo = moonbeam_weights::pallet_multisig::WeightInfo<Runtime>;
1379 type BlockNumberProvider = System;
1380}
1381
1382impl pallet_relay_storage_roots::Config for Runtime {
1383 type MaxStorageRoots = ConstU32<30>;
1384 type RelaychainStateProvider = cumulus_pallet_parachain_system::RelaychainDataProvider<Self>;
1385 type WeightInfo = moonbeam_weights::pallet_relay_storage_roots::WeightInfo<Runtime>;
1386}
1387
1388#[cfg(feature = "runtime-benchmarks")]
1389impl pallet_precompile_benchmarks::Config for Runtime {
1390 type WeightInfo = moonbeam_weights::pallet_precompile_benchmarks::WeightInfo<Runtime>;
1391}
1392
1393impl pallet_parameters::Config for Runtime {
1394 type AdminOrigin = EnsureRoot<AccountId>;
1395 type RuntimeEvent = RuntimeEvent;
1396 type RuntimeParameters = RuntimeParameters;
1397 type WeightInfo = moonbeam_weights::pallet_parameters::WeightInfo<Runtime>;
1398}
1399
1400impl cumulus_pallet_weight_reclaim::Config for Runtime {
1401 type WeightInfo = moonbeam_weights::cumulus_pallet_weight_reclaim::WeightInfo<Runtime>;
1402}
1403
1404impl pallet_migrations::Config for Runtime {
1405 type RuntimeEvent = RuntimeEvent;
1406 #[cfg(not(feature = "runtime-benchmarks"))]
1407 type Migrations = migrations::MultiBlockMigrationList<Runtime>;
1408 #[cfg(feature = "runtime-benchmarks")]
1409 type Migrations = pallet_migrations::mock_helpers::MockedMigrations;
1410 type CursorMaxLen = ConstU32<65_536>;
1411 type IdentifierMaxLen = ConstU32<256>;
1412 type MigrationStatusHandler = ();
1413 type FailedMigrationHandler = MaintenanceMode;
1414 type MaxServiceWeight = MaxServiceWeight;
1415 type WeightInfo = weights::pallet_migrations::WeightInfo<Runtime>;
1416}
1417
1418construct_runtime! {
1419 pub enum Runtime
1420 {
1421 System: frame_system::{Pallet, Call, Storage, Config<T>, Event<T>} = 0,
1423 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>} = 1,
1424 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 3,
1426 ParachainInfo: parachain_info::{Pallet, Storage, Config<T>} = 4,
1427 RootTesting: pallet_root_testing::{Pallet, Call, Storage, Event<T>} = 5,
1428
1429 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 10,
1431 TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Config<T>, Event<T>} = 11,
1432
1433 ParachainStaking: pallet_parachain_staking::{Pallet, Call, Storage, Event<T>, Config<T>, FreezeReason} = 20,
1435 AuthorInherent: pallet_author_inherent::{Pallet, Call, Storage, Inherent} = 21,
1436 AuthorFilter: pallet_author_slot_filter::{Pallet, Call, Storage, Event, Config<T>} = 22,
1437 AuthorMapping: pallet_author_mapping::{Pallet, Call, Config<T>, Storage, Event<T>} = 23,
1438 MoonbeamOrbiters: pallet_moonbeam_orbiters::{Pallet, Call, Storage, Event<T>} = 24,
1439 AsyncBacking: pallet_async_backing::{Pallet, Storage} = 25,
1440
1441 Utility: pallet_utility::{Pallet, Call, Event} = 30,
1443 Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 31,
1444 MaintenanceMode: pallet_maintenance_mode::{Pallet, Call, Config<T>, Storage, Event} = 32,
1445 Identity: pallet_identity::{Pallet, Call, Storage, Event<T>} = 33,
1446 ProxyGenesisCompanion: pallet_proxy_genesis_companion::{Pallet, Config<T>} = 35,
1448 Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 36,
1449 MoonbeamLazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call, Storage} = 37,
1450 Parameters: pallet_parameters = 38,
1451
1452 EthereumChainId: pallet_evm_chain_id::{Pallet, Storage, Config<T>} = 50,
1457 EVM: pallet_evm::{Pallet, Config<T>, Call, Storage, Event<T>} = 51,
1458 Ethereum: pallet_ethereum::{Pallet, Call, Storage, Event, Origin, Config<T>} = 52,
1459
1460 Scheduler: pallet_scheduler::{Pallet, Storage, Event<T>, Call} = 60,
1462 Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>, HoldReason} = 62,
1464 ConvictionVoting: pallet_conviction_voting::{Pallet, Call, Storage, Event<T>} = 63,
1465 Referenda: pallet_referenda::{Pallet, Call, Storage, Event<T>} = 64,
1466 Origins: governance::custom_origins::{Origin} = 65,
1467 Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event<T>} = 66,
1468
1469 TreasuryCouncilCollective:
1473 pallet_collective::<Instance3>::{Pallet, Call, Storage, Event<T>, Origin<T>, Config<T>} = 72,
1474 OpenTechCommitteeCollective:
1475 pallet_collective::<Instance4>::{Pallet, Call, Storage, Event<T>, Origin<T>, Config<T>} = 73,
1476
1477 Treasury: pallet_treasury::{Pallet, Storage, Config<T>, Event<T>, Call} = 80,
1479
1480 CrowdloanRewards: pallet_crowdloan_rewards::{Pallet, Call, Storage, Event<T>} = 90,
1482
1483 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Storage, Event<T>} = 100,
1485 CumulusXcm: cumulus_pallet_xcm::{Pallet, Event<T>, Origin} = 101,
1486 PolkadotXcm: pallet_xcm::{Pallet, Storage, Call, Event<T>, Origin, Config<T>} = 103,
1488 XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event<T>} = 107,
1492 EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin, Event<T>} = 109,
1494 Erc20XcmBridge: pallet_erc20_xcm_bridge::{Pallet} = 110,
1495 MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event<T>} = 111,
1496 EvmForeignAssets: pallet_moonbeam_foreign_assets::{Pallet, Call, Storage, Event<T>, Config<T>} = 114,
1497 XcmWeightTrader: pallet_xcm_weight_trader::{Pallet, Call, Storage, Event<T>, Config<T>} = 115,
1498 EmergencyParaXcm: pallet_emergency_para_xcm::{Pallet, Call, Storage, Event} = 116,
1499 MultiBlockMigrations: pallet_migrations = 117,
1500 WeightReclaim: cumulus_pallet_weight_reclaim = 118,
1501
1502 RelayStorageRoots: pallet_relay_storage_roots::{Pallet, Storage} = 112,
1504
1505 #[cfg(feature = "runtime-benchmarks")]
1506 PrecompileBenchmarks: pallet_precompile_benchmarks::{Pallet} = 113,
1507
1508 Randomness: pallet_randomness::{Pallet, Call, Storage, Event<T>, Inherent} = 120,
1510
1511 BridgeKusamaGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>} = 130,
1513 BridgeKusamaParachains: pallet_bridge_parachains::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>} = 131,
1514 BridgeKusamaMessages: pallet_bridge_messages::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>} = 132,
1515 BridgeXcmOverMoonriver: pallet_xcm_bridge::<Instance1>::{Pallet, Call, Storage, Event<T>, HoldReason, Config<T>} = 133,
1516 }
1517}
1518
1519bridge_runtime_common::generate_bridge_reject_obsolete_headers_and_messages! {
1520 RuntimeCall, AccountId,
1521 BridgeKusamaGrandpa,
1523 BridgeKusamaParachains,
1525 BridgeKusamaMessages
1527}
1528
1529#[cfg(feature = "runtime-benchmarks")]
1530use moonbeam_runtime_common::benchmarking::BenchmarkHelper;
1531#[cfg(feature = "runtime-benchmarks")]
1532mod benches {
1533 frame_support::parameter_types! {
1534 pub const MaxBalance: crate::Balance = crate::Balance::max_value();
1535 }
1536
1537 frame_benchmarking::define_benchmarks!(
1538 [frame_system, SystemBench::<Runtime>]
1539 [frame_system_extensions, frame_system_benchmarking::extensions::Pallet::<Runtime>]
1540 [pallet_utility, Utility]
1541 [pallet_timestamp, Timestamp]
1542 [pallet_balances, Balances]
1543 [pallet_evm, EVM]
1544 [pallet_parachain_staking, ParachainStaking]
1545 [pallet_scheduler, Scheduler]
1546 [pallet_treasury, Treasury]
1547 [pallet_author_inherent, AuthorInherent]
1548 [pallet_author_slot_filter, AuthorFilter]
1549 [pallet_crowdloan_rewards, CrowdloanRewards]
1550 [pallet_author_mapping, AuthorMapping]
1551 [pallet_proxy, Proxy]
1552 [pallet_transaction_payment, TransactionPaymentBenchmark::<Runtime>]
1553 [pallet_identity, Identity]
1554 [cumulus_pallet_parachain_system, ParachainSystem]
1555 [cumulus_pallet_xcmp_queue, XcmpQueue]
1556 [pallet_message_queue, MessageQueue]
1557 [pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
1558 [pallet_xcm_transactor, XcmTransactor]
1559 [pallet_moonbeam_foreign_assets, EvmForeignAssets]
1560 [pallet_moonbeam_orbiters, MoonbeamOrbiters]
1561 [pallet_randomness, Randomness]
1562 [pallet_conviction_voting, ConvictionVoting]
1563 [pallet_referenda, Referenda]
1564 [pallet_preimage, Preimage]
1565 [pallet_whitelist, Whitelist]
1566 [pallet_multisig, Multisig]
1567 [pallet_migrations, MultiBlockMigrations]
1568 [pallet_relay_storage_roots, RelayStorageRoots]
1571 [pallet_precompile_benchmarks, PrecompileBenchmarks]
1572 [pallet_parameters, Parameters]
1573 [pallet_xcm_weight_trader, XcmWeightTrader]
1574 [pallet_collective, TreasuryCouncilCollective]
1575 [pallet_collective, OpenTechCommitteeCollective]
1576 [pallet_bridge_grandpa, BridgeKusamaGrandpa]
1577 [pallet_bridge_parachains, pallet_bridge_parachains::benchmarking::Pallet::<Runtime, bridge_config::BridgeMoonriverInstance>]
1578 [pallet_bridge_messages, pallet_bridge_messages::benchmarking::Pallet::<Runtime, bridge_config::WithKusamaMessagesInstance>]
1579 [cumulus_pallet_weight_reclaim, WeightReclaim]
1580 );
1581}
1582
1583pub type Block = generic::Block<Header, UncheckedExtrinsic>;
1585pub type SignedBlock = generic::SignedBlock<Block>;
1587pub type BlockId = generic::BlockId<Block>;
1589
1590pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim<
1592 Runtime,
1593 (
1594 frame_system::CheckNonZeroSender<Runtime>,
1595 frame_system::CheckSpecVersion<Runtime>,
1596 frame_system::CheckTxVersion<Runtime>,
1597 frame_system::CheckGenesis<Runtime>,
1598 frame_system::CheckEra<Runtime>,
1599 frame_system::CheckNonce<Runtime>,
1600 frame_system::CheckWeight<Runtime>,
1601 pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
1602 BridgeRejectObsoleteHeadersAndMessages,
1603 frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
1604 ),
1605>;
1606pub type UncheckedExtrinsic =
1608 fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
1609pub type CheckedExtrinsic =
1611 fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, TxExtension, H160>;
1612pub type Executive = frame_executive::Executive<
1614 Runtime,
1615 Block,
1616 frame_system::ChainContext<Runtime>,
1617 Runtime,
1618 AllPalletsWithSystem,
1619>;
1620
1621moonbeam_runtime_common::impl_runtime_apis_plus_common!(
1632 {
1633 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
1634 fn validate_transaction(
1635 source: TransactionSource,
1636 xt: <Block as BlockT>::Extrinsic,
1637 block_hash: <Block as BlockT>::Hash,
1638 ) -> TransactionValidity {
1639 if !<Runtime as frame_system::Config>::BaseCallFilter::contains(&xt.0.function) {
1642 return InvalidTransaction::Call.into();
1643 }
1644
1645 let mut intermediate_valid = Executive::validate_transaction(source, xt.clone(), block_hash)?;
1660
1661 let dispatch_info = xt.get_dispatch_info();
1662
1663 Ok(match &xt.0.function {
1667 RuntimeCall::Ethereum(transact { .. }) => intermediate_valid,
1668 _ if dispatch_info.class != DispatchClass::Normal => intermediate_valid,
1669 _ => {
1670 let tip = match &xt.0.preamble {
1671 Preamble::Bare(_) => 0,
1672 Preamble::Signed(_, _, signed_extra) => {
1673 let charge_transaction_payment = &signed_extra.0.7;
1676 charge_transaction_payment.tip()
1677 },
1678 Preamble::General(_, _) => 0,
1679 };
1680
1681 let fee: u64 = TransactionPayment::compute_fee(
1683 xt.encode().len() as u32,
1684 &dispatch_info,
1685 tip,
1686 ).saturated_into();
1687
1688 let effective_gas =
1690 <Runtime as pallet_evm::Config>::GasWeightMapping::weight_to_gas(
1691 dispatch_info.total_weight()
1692 );
1693
1694 let effective_gas_price = if effective_gas > 0 {
1698 fee / effective_gas
1699 } else {
1700 fee
1702 };
1703
1704 intermediate_valid.priority = effective_gas_price;
1706 intermediate_valid
1707 }
1708 })
1709 }
1710 }
1711
1712 impl async_backing_primitives::UnincludedSegmentApi<Block> for Runtime {
1713 fn can_build_upon(
1714 included_hash: <Block as BlockT>::Hash,
1715 slot: async_backing_primitives::Slot,
1716 ) -> bool {
1717 ConsensusHook::can_build_upon(included_hash, slot)
1718 }
1719 }
1720
1721 impl bp_kusama::KusamaFinalityApi<Block> for Runtime {
1722 fn best_finalized() -> Option<bp_runtime::HeaderId<bp_kusama::Hash, bp_kusama::BlockNumber>> {
1723 BridgeKusamaGrandpa::best_finalized()
1724 }
1725 fn free_headers_interval() -> Option<bp_kusama::BlockNumber> {
1726 <Runtime as pallet_bridge_grandpa::Config<
1727 bridge_config::BridgeGrandpaKusamaInstance
1728 >>::FreeHeadersInterval::get()
1729 }
1730 fn synced_headers_grandpa_info(
1731 ) -> Vec<bp_header_chain::StoredHeaderGrandpaInfo<bp_kusama::Header>> {
1732 BridgeKusamaGrandpa::synced_headers_grandpa_info()
1733 }
1734 }
1735
1736 impl bp_moonriver::MoonriverKusamaFinalityApi<Block> for Runtime {
1737 fn best_finalized() -> Option<bp_runtime::HeaderId<bp_moonriver::Hash, bp_moonriver::BlockNumber>> {
1738 BridgeKusamaParachains::best_parachain_head_id::<
1739 bp_moonriver::Moonriver
1740 >().unwrap_or(None)
1741 }
1742 fn free_headers_interval() -> Option<bp_moonriver::BlockNumber> {
1743 None
1745 }
1746 }
1747
1748 impl bp_moonriver::ToMoonriverKusamaOutboundLaneApi<Block> for Runtime {
1749 fn message_details(
1750 lane: bp_moonriver::LaneId,
1751 begin: bp_messages::MessageNonce,
1752 end: bp_messages::MessageNonce,
1753 ) -> Vec<bp_messages::OutboundMessageDetails> {
1754 bridge_runtime_common::messages_api::outbound_message_details::<
1755 Runtime,
1756 bridge_config::WithKusamaMessagesInstance,
1757 >(lane, begin, end)
1758 }
1759 }
1760
1761 impl bp_moonriver::FromMoonriverKusamaInboundLaneApi<Block> for Runtime {
1762 fn message_details(
1763 lane: bp_moonriver::LaneId,
1764 messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails)>,
1765 ) -> Vec<bp_messages::InboundMessageDetails> {
1766 bridge_runtime_common::messages_api::inbound_message_details::<
1767 Runtime,
1768 bridge_config::WithKusamaMessagesInstance,
1769 >(lane, messages)
1770 }
1771 }
1772 }
1773
1774 {
1776 impl pallet_bridge_parachains::benchmarking::Config<bridge_config::BridgeMoonriverInstance> for Runtime {
1777 fn parachains() -> Vec<bp_polkadot_core::parachains::ParaId> {
1778 use bp_runtime::Parachain;
1779 vec![bp_polkadot_core::parachains::ParaId(bp_moonriver::Moonriver::PARACHAIN_ID)]
1780 }
1781
1782 fn prepare_parachain_heads_proof(
1783 parachains: &[bp_polkadot_core::parachains::ParaId],
1784 parachain_head_size: u32,
1785 proof_params: bp_runtime::UnverifiedStorageProofParams,
1786 ) -> (
1787 bp_parachains::RelayBlockNumber,
1788 bp_parachains::RelayBlockHash,
1789 bp_polkadot_core::parachains::ParaHeadsProof,
1790 Vec<(bp_polkadot_core::parachains::ParaId, bp_polkadot_core::parachains::ParaHash)>,
1791 ) {
1792 bridge_runtime_common::parachains_benchmarking::prepare_parachain_heads_proof::<Runtime, bridge_config::BridgeMoonriverInstance>(
1793 parachains,
1794 parachain_head_size,
1795 proof_params,
1796 )
1797 }
1798 }
1799
1800 use bridge_runtime_common::messages_benchmarking::{
1801 generate_xcm_builder_bridge_message_sample, prepare_message_delivery_proof_from_parachain,
1802 prepare_message_proof_from_parachain,
1803 };
1804 use pallet_bridge_messages::benchmarking::{
1805 Config as BridgeMessagesConfig, MessageDeliveryProofParams, MessageProofParams,
1806 };
1807
1808 impl BridgeMessagesConfig<bridge_config::WithKusamaMessagesInstance> for Runtime {
1809 fn is_relayer_rewarded(_relayer: &Self::AccountId) -> bool {
1810 true
1812 }
1813
1814 fn prepare_message_proof(
1815 params: MessageProofParams<
1816 pallet_bridge_messages::LaneIdOf<Runtime, bridge_config::WithKusamaMessagesInstance>,
1817 >,
1818 ) -> (
1819 bridge_config::benchmarking::FromMoonriverMessagesProof<
1820 bridge_config::WithKusamaMessagesInstance,
1821 >,
1822 Weight,
1823 ) {
1824 use cumulus_primitives_core::XcmpMessageSource;
1825 assert!(XcmpQueue::take_outbound_messages(usize::MAX).is_empty());
1826 ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(42.into());
1827 PolkadotXcm::force_xcm_version(
1828 RuntimeOrigin::root(),
1829 Box::new(Location::new(1, Parachain(42))),
1830 cumulus_primitives_core::XCM_VERSION,
1831 )
1832 .map_err(|e| {
1833 log::error!(
1834 "Failed to dispatch `force_xcm_version({:?}, {:?}, {:?})`, error: {:?}",
1835 RuntimeOrigin::root(),
1836 Location::new(1, Parachain(42)),
1837 cumulus_primitives_core::XCM_VERSION,
1838 e
1839 );
1840 })
1841 .expect("XcmVersion stored!");
1842 let universal_source = bridge_config::benchmarking::open_bridge_for_benchmarks::<
1843 Runtime,
1844 bridge_config::XcmOverKusamaInstance,
1845 xcm_config::LocationToAccountId,
1846 >(params.lane, 42);
1847 prepare_message_proof_from_parachain::<
1848 Runtime,
1849 bridge_config::BridgeGrandpaKusamaInstance,
1850 bridge_config::WithKusamaMessagesInstance,
1851 >(params, generate_xcm_builder_bridge_message_sample(universal_source))
1852 }
1853
1854 fn prepare_message_delivery_proof(
1855 params: MessageDeliveryProofParams<
1856 AccountId,
1857 pallet_bridge_messages::LaneIdOf<Runtime, bridge_config::WithKusamaMessagesInstance>,
1858 >,
1859 ) -> bridge_config::benchmarking::ToMoonriverMessagesDeliveryProof<
1860 bridge_config::WithKusamaMessagesInstance,
1861 > {
1862 let _ = bridge_config::benchmarking::open_bridge_for_benchmarks::<
1863 Runtime,
1864 bridge_config::XcmOverKusamaInstance,
1865 xcm_config::LocationToAccountId,
1866 >(params.lane, 42);
1867 prepare_message_delivery_proof_from_parachain::<
1868 Runtime,
1869 bridge_config::BridgeGrandpaKusamaInstance,
1870 bridge_config::WithKusamaMessagesInstance,
1871 >(params)
1872 }
1873
1874 fn is_message_successfully_dispatched(_nonce: bp_messages::MessageNonce) -> bool {
1875 true
1877 }
1878 }
1879 }
1880);
1881
1882cumulus_pallet_parachain_system::register_validate_block!(
1884 Runtime = Runtime,
1885 BlockExecutor = pallet_author_inherent::BlockExecutor::<Runtime, Executive>,
1886);
1887
1888moonbeam_runtime_common::impl_self_contained_call!();
1889
1890#[macro_export]
1892macro_rules! get {
1893 ($pallet:ident, $name:ident, $type:ty) => {
1894 <<$crate::Runtime as $pallet::Config>::$name as $crate::Get<$type>>::get()
1895 };
1896}
1897
1898#[cfg(test)]
1899mod tests {
1900 use super::{currency::*, *};
1901
1902 #[test]
1903 fn call_max_size() {
1907 const CALL_ALIGN: u32 = 1024;
1908 assert!(std::mem::size_of::<pallet_evm_chain_id::Call<Runtime>>() <= CALL_ALIGN as usize);
1909 assert!(std::mem::size_of::<pallet_evm::Call<Runtime>>() <= CALL_ALIGN as usize);
1910 assert!(std::mem::size_of::<pallet_ethereum::Call<Runtime>>() <= CALL_ALIGN as usize);
1911 assert!(
1912 std::mem::size_of::<pallet_parachain_staking::Call<Runtime>>() <= CALL_ALIGN as usize
1913 );
1914 assert!(
1915 std::mem::size_of::<pallet_author_inherent::Call<Runtime>>() <= CALL_ALIGN as usize
1916 );
1917 assert!(
1918 std::mem::size_of::<pallet_author_slot_filter::Call<Runtime>>() <= CALL_ALIGN as usize
1919 );
1920 assert!(
1921 std::mem::size_of::<pallet_crowdloan_rewards::Call<Runtime>>() <= CALL_ALIGN as usize
1922 );
1923 assert!(std::mem::size_of::<pallet_author_mapping::Call<Runtime>>() <= CALL_ALIGN as usize);
1924 assert!(
1925 std::mem::size_of::<pallet_maintenance_mode::Call<Runtime>>() <= CALL_ALIGN as usize
1926 );
1927 assert!(std::mem::size_of::<pallet_migrations::Call<Runtime>>() <= CALL_ALIGN as usize);
1928 assert!(
1929 std::mem::size_of::<pallet_moonbeam_lazy_migrations::Call<Runtime>>()
1930 <= CALL_ALIGN as usize
1931 );
1932 assert!(
1933 std::mem::size_of::<pallet_proxy_genesis_companion::Call<Runtime>>()
1934 <= CALL_ALIGN as usize
1935 );
1936 }
1937
1938 #[test]
1939 fn currency_constants_are_correct() {
1940 assert_eq!(SUPPLY_FACTOR, 100);
1941
1942 assert_eq!(TRANSACTION_BYTE_FEE, Balance::from(100 * GIGAWEI));
1944 assert_eq!(
1945 get!(pallet_transaction_payment, OperationalFeeMultiplier, u8),
1946 5_u8
1947 );
1948 assert_eq!(STORAGE_BYTE_FEE, Balance::from(10 * MILLIGLMR));
1949
1950 assert_eq!(
1952 get!(pallet_identity, BasicDeposit, u128),
1953 Balance::from(10 * GLMR + 2580 * MILLIGLMR)
1954 );
1955 assert_eq!(
1956 get!(pallet_identity, ByteDeposit, u128),
1957 Balance::from(10 * MILLIGLMR)
1958 );
1959 assert_eq!(
1960 get!(pallet_identity, SubAccountDeposit, u128),
1961 Balance::from(10 * GLMR + 530 * MILLIGLMR)
1962 );
1963
1964 assert_eq!(
1966 get!(pallet_parachain_staking, MinCandidateStk, u128),
1967 Balance::from(100_000 * GLMR)
1968 );
1969 assert_eq!(
1970 get!(pallet_parachain_staking, MinDelegation, u128),
1971 Balance::from(50 * GLMR)
1972 );
1973
1974 assert_eq!(
1976 get!(pallet_crowdloan_rewards, MinimumReward, u128),
1977 Balance::from(0u128)
1978 );
1979
1980 assert_eq!(
1982 get!(pallet_author_mapping, DepositAmount, u128),
1983 Balance::from(10 * KILOGLMR)
1984 );
1985
1986 assert_eq!(
1988 get!(pallet_proxy, ProxyDepositBase, u128),
1989 Balance::from(10 * GLMR + 80 * MILLIGLMR)
1990 );
1991 assert_eq!(
1992 get!(pallet_proxy, ProxyDepositFactor, u128),
1993 Balance::from(210 * MILLIGLMR)
1994 );
1995 assert_eq!(
1996 get!(pallet_proxy, AnnouncementDepositBase, u128),
1997 Balance::from(10 * GLMR + 80 * MILLIGLMR)
1998 );
1999 assert_eq!(
2000 get!(pallet_proxy, AnnouncementDepositFactor, u128),
2001 Balance::from(560 * MILLIGLMR)
2002 );
2003 }
2004
2005 #[test]
2006 fn max_offline_rounds_lower_or_eq_than_reward_payment_delay() {
2007 assert!(
2008 get!(pallet_parachain_staking, MaxOfflineRounds, u32)
2009 <= get!(pallet_parachain_staking, RewardPaymentDelay, u32)
2010 );
2011 }
2012
2013 #[test]
2014 fn updating_maximum_delegators_per_candidate_requires_configuring_required_migration() {
2018 assert_eq!(
2019 get!(pallet_parachain_staking, MaxTopDelegationsPerCandidate, u32),
2020 300
2021 );
2022 assert_eq!(
2023 get!(
2024 pallet_parachain_staking,
2025 MaxBottomDelegationsPerCandidate,
2026 u32
2027 ),
2028 50
2029 );
2030 }
2031
2032 #[test]
2033 fn configured_base_extrinsic_weight_is_evm_compatible() {
2034 let min_ethereum_transaction_weight = WeightPerGas::get() * 21_000;
2035 let base_extrinsic = <Runtime as frame_system::Config>::BlockWeights::get()
2036 .get(frame_support::dispatch::DispatchClass::Normal)
2037 .base_extrinsic;
2038 assert!(base_extrinsic.ref_time() <= min_ethereum_transaction_weight.ref_time());
2039 }
2040
2041 #[test]
2042 fn test_storage_growth_ratio_is_correct() {
2043 let block_storage_limit = 160 * 1024;
2045 let expected_storage_growth_ratio = BlockGasLimit::get()
2046 .low_u64()
2047 .saturating_div(block_storage_limit);
2048 let actual_storage_growth_ratio =
2049 <Runtime as pallet_evm::Config>::GasLimitStorageGrowthRatio::get();
2050 assert_eq!(
2051 expected_storage_growth_ratio, actual_storage_growth_ratio,
2052 "Storage growth ratio is not correct"
2053 );
2054 }
2055}