1
// Copyright 2019-2025 PureStake Inc.
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Moonbeam is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
#[macro_export]
18
macro_rules! impl_runtime_apis_plus_common {
19
    ({$($custom:tt)*} {$($bench_custom:tt)*}) => {
20
    	use ethereum::AuthorizationList;
21

            
22
		#[cfg(feature = "evm-tracing")]
23
		// Helper function to replay the "on_idle" hook for all pallets, we need this for
24
		// evm-tracing because some ethereum-xcm transactions might be executed at on_idle.
25
		//
26
		// We need to make sure that we replay on_idle exactly the same way as the
27
		// original block execution, but unfortunatly frame executive diosn't provide a function
28
		// to replay only on_idle, so we need to copy here some code inside frame executive.
29
22
		fn replay_on_idle() {
30
			use frame_system::pallet_prelude::BlockNumberFor;
31
			use frame_support::traits::OnIdle;
32

            
33
22
			let weight = <frame_system::Pallet<Runtime>>::block_weight();
34
22
			let max_weight = <
35
22
					<Runtime as frame_system::Config>::BlockWeights as
36
22
					frame_support::traits::Get<_>
37
22
				>::get().max_block;
38
22
			let remaining_weight = max_weight.saturating_sub(weight.total());
39
22
			if remaining_weight.all_gt(Weight::zero()) {
40
22
				let _ = <AllPalletsWithSystem as OnIdle<BlockNumberFor<Runtime>>>::on_idle(
41
22
					<frame_system::Pallet<Runtime>>::block_number(),
42
22
					remaining_weight,
43
22
				);
44
22
			}
45
22
		}
46

            
47
		/// AccountId Converter used for benchmarks.
48
		///
49
		/// * AccountId32 Junction is being used in pallet_xcm_benchmarks
50
		/// * Parent is used as valid destination location for benchmarking.
51
		#[cfg(feature = "runtime-benchmarks")]
52
		pub struct BenchAccountIdConverter<AccountId>(sp_std::marker::PhantomData<AccountId>);
53

            
54
		#[cfg(feature = "runtime-benchmarks")]
55
		impl<AccountId: From<[u8; 20]> + Into<[u8; 20]> + Clone> xcm_executor::traits::ConvertLocation<AccountId>
56
			for BenchAccountIdConverter<AccountId>
57
		{
58
			fn convert_location(location: &xcm::latest::prelude::Location) -> Option<AccountId> {
59
				match location.unpack() {
60
					(0, [xcm::latest::prelude::AccountId32 { id, network: None }]) => {
61
						// take the first 20 bytes of the id and convert to fixed-size array
62
						let mut id20: [u8; 20] = [0u8; 20];
63
						id20.copy_from_slice(&id[..20]);
64
						Some(id20.into())
65
					},
66
					(1, []) => {
67
						Some([1u8; 20].into())
68
					},
69
					_ => return None,
70
				}
71
			}
72
		}
73

            
74
		impl_runtime_apis! {
75
			$($custom)*
76

            
77
			impl sp_api::Core<Block> for Runtime {
78
				fn version() -> RuntimeVersion {
79
					VERSION
80
				}
81

            
82
				fn execute_block(block: Block) {
83
					Executive::execute_block(block)
84
				}
85

            
86
				fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
87
					Executive::initialize_block(header)
88
				}
89
			}
90

            
91
			impl cumulus_primitives_core::RelayParentOffsetApi<Block> for Runtime {
92
				fn relay_parent_offset() -> u32 {
93
					crate::RELAY_PARENT_OFFSET
94
				}
95
			}
96

            
97
			impl cumulus_primitives_core::GetCoreSelectorApi<Block> for Runtime {
98
				fn core_selector() -> (cumulus_primitives_core::CoreSelector, cumulus_primitives_core::ClaimQueueOffset) {
99
					ParachainSystem::core_selector()
100
				}
101
			}
102

            
103
			impl sp_api::Metadata<Block> for Runtime {
104
				fn metadata() -> OpaqueMetadata {
105
					OpaqueMetadata::new(Runtime::metadata().into())
106
				}
107

            
108
				fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
109
					Runtime::metadata_at_version(version)
110
				}
111

            
112
				fn metadata_versions() -> Vec<u32> {
113
					Runtime::metadata_versions()
114
				}
115
			}
116

            
117
			impl sp_block_builder::BlockBuilder<Block> for Runtime {
118
				fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
119
					Executive::apply_extrinsic(extrinsic)
120
				}
121

            
122
				fn finalize_block() -> <Block as BlockT>::Header {
123
					Executive::finalize_block()
124
				}
125

            
126
				fn inherent_extrinsics(
127
					data: sp_inherents::InherentData,
128
				) -> Vec<<Block as BlockT>::Extrinsic> {
129
					data.create_extrinsics()
130
				}
131

            
132
				fn check_inherents(
133
					block: Block,
134
					data: sp_inherents::InherentData,
135
				) -> sp_inherents::CheckInherentsResult {
136
					data.check_extrinsics(&block)
137
				}
138
			}
139

            
140
			impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
141
				fn offchain_worker(header: &<Block as BlockT>::Header) {
142
					Executive::offchain_worker(header)
143
				}
144
			}
145

            
146
			impl sp_session::SessionKeys<Block> for Runtime {
147
				fn decode_session_keys(
148
					encoded: Vec<u8>,
149
				) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
150
					opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
151
				}
152

            
153
				fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
154
					opaque::SessionKeys::generate(seed)
155
				}
156
			}
157

            
158
			impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
159
				fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
160
					frame_support::genesis_builder_helper::build_state::<RuntimeGenesisConfig>(config)
161
				}
162

            
163
				#[cfg(not(feature = "disable-genesis-builder"))]
164
				fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
165
					frame_support::genesis_builder_helper::get_preset::<RuntimeGenesisConfig>(id, genesis_config_preset::get_preset)
166
				}
167
				#[cfg(feature = "disable-genesis-builder")]
168
				fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
169
					None
170
				}
171

            
172
				#[cfg(not(feature = "disable-genesis-builder"))]
173
				fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
174
					genesis_config_preset::preset_names()
175
				}
176
				#[cfg(feature = "disable-genesis-builder")]
177
				fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
178
					Default::default()
179
				}
180
			}
181

            
182
			impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
183
				fn account_nonce(account: AccountId) -> Index {
184
					System::account_nonce(account)
185
				}
186
			}
187

            
188
			impl moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block> for Runtime {
189
22
				fn trace_transaction(
190
22
					extrinsics: Vec<<Block as BlockT>::Extrinsic>,
191
22
					traced_transaction: &EthereumTransaction,
192
22
					header: &<Block as BlockT>::Header,
193
22
				) -> Result<
194
22
					(),
195
22
					sp_runtime::DispatchError,
196
22
				> {
197
					#[cfg(feature = "evm-tracing")]
198
					{
199
						use moonbeam_evm_tracer::tracer::{
200
							EthereumTracingStatus,
201
							EvmTracer,
202
							EthereumTracer
203
						};
204
						use frame_support::storage::unhashed;
205
						use frame_system::pallet_prelude::BlockNumberFor;
206

            
207
						// Tell the CallDispatcher we are tracing a specific Transaction.
208
22
						EthereumTracer::transaction(traced_transaction.hash(), || {
209
							// Initialize block: calls the "on_initialize" hook on every pallet
210
							// in AllPalletsWithSystem.
211
							// After pallet message queue was introduced, this must be done only after
212
							// enabling XCM tracing by calling ETHEREUM_TRACING_STATUS::using
213
							// in the storage
214
22
							Executive::initialize_block(header);
215

            
216
							// Apply a subset of extrinsics: all the substrate-specific or ethereum
217
							// transactions that preceded the requested transaction.
218
44
							for ext in extrinsics.into_iter() {
219
44
								let _ = match &ext.0.function {
220
22
									RuntimeCall::Ethereum(transact { transaction }) => {
221
										// Reset the previously consumed weight when tracing ethereum transactions.
222
										// This is necessary because EVM tracing introduces additional
223
										// (ref_time) overhead, which differs from the production runtime behavior.
224
										// Without resetting the block weight, the extra tracing overhead could
225
										// leading to some transactions to incorrectly fail during tracing.
226
22
										frame_system::BlockWeight::<Runtime>::kill();
227

            
228
22
										if transaction == traced_transaction {
229
22
											EvmTracer::new().trace(|| Executive::apply_extrinsic(ext));
230
22
											return Ok(());
231
										} else {
232
											Executive::apply_extrinsic(ext)
233
										}
234
									}
235
22
									_ => Executive::apply_extrinsic(ext),
236
								};
237

            
238
22
								if let Some(EthereumTracingStatus::TransactionExited) = EthereumTracer::status() {
239
									return Ok(());
240
22
								}
241
							}
242

            
243
							if let Some(EthereumTracingStatus::Transaction(_)) = EthereumTracer::status() {
244
								// If the transaction was not found, it might be
245
								// an eth-xcm transaction that was executed at on_idle
246
								replay_on_idle();
247
							}
248

            
249
							if let Some(EthereumTracingStatus::TransactionExited) = EthereumTracer::status() {
250
								// The transaction was found
251
								Ok(())
252
							} else {
253
								// The transaction was not-found
254
								Err(sp_runtime::DispatchError::Other(
255
									"Failed to find Ethereum transaction among the extrinsics.",
256
								))
257
							}
258
22
						})
259
					}
260
					#[cfg(not(feature = "evm-tracing"))]
261
					Err(sp_runtime::DispatchError::Other(
262
						"Missing `evm-tracing` compile time feature flag.",
263
					))
264
22
				}
265

            
266
22
				fn trace_block(
267
22
					extrinsics: Vec<<Block as BlockT>::Extrinsic>,
268
22
					known_transactions: Vec<H256>,
269
22
					header: &<Block as BlockT>::Header,
270
22
				) -> Result<
271
22
					(),
272
22
					sp_runtime::DispatchError,
273
22
				> {
274
					#[cfg(feature = "evm-tracing")]
275
					{
276
						use moonbeam_evm_tracer::tracer::{
277
							EthereumTracingStatus,
278
							EvmTracer,
279
							EthereumTracer
280
						};
281
						use frame_system::pallet_prelude::BlockNumberFor;
282

            
283
						// Tell the CallDispatcher we are tracing a full Block.
284
22
						EthereumTracer::block(|| {
285
22
							let mut config = <Runtime as pallet_evm::Config>::config().clone();
286
22
							config.estimate = true;
287

            
288
							// Initialize block: calls the "on_initialize" hook on every pallet
289
							// in AllPalletsWithSystem.
290
							// After pallet message queue was introduced, this must be done only after
291
							// enabling XCM tracing by calling ETHEREUM_TRACING_STATUS::using
292
							// in the storage
293
22
							Executive::initialize_block(header);
294

            
295
							// Apply all extrinsics. Ethereum extrinsics are traced.
296
88
							for ext in extrinsics.into_iter() {
297
88
								match &ext.0.function {
298
44
									RuntimeCall::Ethereum(transact { transaction }) => {
299

            
300
										// Reset the previously consumed weight when tracing multiple transactions.
301
										// This is necessary because EVM tracing introduces additional
302
										// (ref_time) overhead, which differs from the production runtime behavior.
303
										// Without resetting the block weight, the extra tracing overhead could
304
										// leading to some transactions to incorrectly fail during tracing.
305
44
										frame_system::BlockWeight::<Runtime>::kill();
306

            
307
44
										let tx_hash = &transaction.hash();
308
44
										if known_transactions.contains(&tx_hash) {
309
											// Each known extrinsic is a new call stack.
310
44
											EvmTracer::emit_new();
311
44
											EvmTracer::new().trace(|| {
312
44
												if let Err(err) = Executive::apply_extrinsic(ext) {
313
44
													log::debug!(
314
														target: "tracing",
315
														"Could not trace eth transaction (hash: {}): {:?}",
316
														&tx_hash,
317
														err
318
													);
319
												}
320
44
											});
321
										} else {
322
											if let Err(err) = Executive::apply_extrinsic(ext) {
323
												log::debug!(
324
													target: "tracing",
325
													"Failed to apply eth extrinsic (hash: {}): {:?}",
326
													&tx_hash,
327
													err
328
												);
329
											}
330
										}
331
									}
332
									_ => {
333
44
										if let Err(err) = Executive::apply_extrinsic(ext) {
334
											log::debug!(
335
												target: "tracing",
336
												"Failed to apply non-eth extrinsic: {:?}",
337
												err
338
											);
339
44
										}
340
									}
341
								};
342
							}
343

            
344
							// Replay on_idle
345
							// Some XCM messages with eth-xcm transaction might be executed at on_idle
346
22
							replay_on_idle();
347

            
348
22
							Ok(())
349
22
						})
350
					}
351
					#[cfg(not(feature = "evm-tracing"))]
352
					Err(sp_runtime::DispatchError::Other(
353
						"Missing `evm-tracing` compile time feature flag.",
354
					))
355
22
				}
356

            
357
22
				fn trace_call(
358
22
					header: &<Block as BlockT>::Header,
359
22
					from: H160,
360
22
					to: H160,
361
22
					data: Vec<u8>,
362
22
					value: U256,
363
22
					gas_limit: U256,
364
22
					max_fee_per_gas: Option<U256>,
365
22
					max_priority_fee_per_gas: Option<U256>,
366
22
					nonce: Option<U256>,
367
22
					access_list: Option<Vec<(H160, Vec<H256>)>>,
368
22
					authorization_list: Option<AuthorizationList>,
369
22
				) -> Result<(), sp_runtime::DispatchError> {
370
					#[cfg(feature = "evm-tracing")]
371
					{
372
						use moonbeam_evm_tracer::tracer::EvmTracer;
373

            
374
						// Initialize block: calls the "on_initialize" hook on every pallet
375
						// in AllPalletsWithSystem.
376
22
						Executive::initialize_block(header);
377

            
378
22
						EvmTracer::new().trace(|| {
379
22
							let is_transactional = false;
380
22
							let validate = true;
381

            
382
22
							let transaction_data = pallet_ethereum::TransactionData::new(
383
22
								pallet_ethereum::TransactionAction::Call(to),
384
22
								data.clone(),
385
22
								nonce.unwrap_or_default(),
386
22
								gas_limit,
387
22
								None,
388
22
								max_fee_per_gas.or(Some(U256::default())),
389
22
								max_priority_fee_per_gas.or(Some(U256::default())),
390
22
								value,
391
22
								Some(<Runtime as pallet_evm::Config>::ChainId::get()),
392
22
								access_list.clone().unwrap_or_default(),
393
22
								authorization_list.clone().unwrap_or_default(),
394
							);
395

            
396
22
							let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
397

            
398
22
							let (weight_limit, proof_size_base_cost) = pallet_ethereum::Pallet::<Runtime>::transaction_weight(&transaction_data);
399

            
400
22
							let _ = <Runtime as pallet_evm::Config>::Runner::call(
401
22
								from,
402
22
								to,
403
22
								data,
404
22
								value,
405
22
								gas_limit,
406
22
								max_fee_per_gas,
407
22
								max_priority_fee_per_gas,
408
22
								nonce,
409
22
								access_list.unwrap_or_default(),
410
22
								authorization_list.unwrap_or_default(),
411
22
								is_transactional,
412
22
								validate,
413
22
								weight_limit,
414
22
								proof_size_base_cost,
415
22
								<Runtime as pallet_evm::Config>::config(),
416
22
							);
417
22
						});
418
22
						Ok(())
419
					}
420
					#[cfg(not(feature = "evm-tracing"))]
421
					Err(sp_runtime::DispatchError::Other(
422
						"Missing `evm-tracing` compile time feature flag.",
423
					))
424
22
				}
425
			}
426

            
427
			impl moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi<Block> for Runtime {
428
22
				fn extrinsic_filter(
429
22
					xts_ready: Vec<<Block as BlockT>::Extrinsic>,
430
22
					xts_future: Vec<<Block as BlockT>::Extrinsic>,
431
22
				) -> TxPoolResponse {
432
					TxPoolResponse {
433
22
						ready: xts_ready
434
22
							.into_iter()
435
44
							.filter_map(|xt| match xt.0.function {
436
22
								RuntimeCall::Ethereum(transact { transaction }) => Some(transaction),
437
22
								_ => None,
438
44
							})
439
22
							.collect(),
440
22
						future: xts_future
441
22
							.into_iter()
442
44
							.filter_map(|xt| match xt.0.function {
443
22
								RuntimeCall::Ethereum(transact { transaction }) => Some(transaction),
444
22
								_ => None,
445
44
							})
446
22
							.collect(),
447
					}
448
22
				}
449
			}
450

            
451
			impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
452
22
				fn chain_id() -> u64 {
453
22
					<Runtime as pallet_evm::Config>::ChainId::get()
454
22
				}
455

            
456
22
				fn account_basic(address: H160) -> EVMAccount {
457
22
					let (account, _) = EVM::account_basic(&address);
458
22
					account
459
22
				}
460

            
461
22
				fn gas_price() -> U256 {
462
22
					let (gas_price, _) = <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price();
463
22
					gas_price
464
22
				}
465

            
466
22
				fn account_code_at(address: H160) -> Vec<u8> {
467
22
					pallet_evm::AccountCodes::<Runtime>::get(address)
468
22
				}
469

            
470
22
				fn author() -> H160 {
471
22
					<pallet_evm::Pallet<Runtime>>::find_author()
472
22
				}
473

            
474
22
				fn storage_at(address: H160, index: U256) -> H256 {
475
22
					let tmp: [u8; 32] = index.to_big_endian();
476
22
					pallet_evm::AccountStorages::<Runtime>::get(address, H256::from_slice(&tmp[..]))
477
22
				}
478

            
479
22
				fn call(
480
22
					from: H160,
481
22
					to: H160,
482
22
					data: Vec<u8>,
483
22
					value: U256,
484
22
					gas_limit: U256,
485
22
					max_fee_per_gas: Option<U256>,
486
22
					max_priority_fee_per_gas: Option<U256>,
487
22
					nonce: Option<U256>,
488
22
					estimate: bool,
489
22
					access_list: Option<Vec<(H160, Vec<H256>)>>,
490
22
					authorization_list: Option<AuthorizationList>,
491
22
				) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {
492
22
					let config = if estimate {
493
						let mut config = <Runtime as pallet_evm::Config>::config().clone();
494
						config.estimate = true;
495
						Some(config)
496
					} else {
497
22
						None
498
					};
499
22
					let is_transactional = false;
500
22
					let validate = true;
501

            
502
22
					let transaction_data = pallet_ethereum::TransactionData::new(
503
22
						pallet_ethereum::TransactionAction::Call(to),
504
22
						data.clone(),
505
22
						nonce.unwrap_or_default(),
506
22
						gas_limit,
507
22
						None,
508
22
						max_fee_per_gas.or(Some(U256::default())),
509
22
						max_priority_fee_per_gas.or(Some(U256::default())),
510
22
						value,
511
22
						Some(<Runtime as pallet_evm::Config>::ChainId::get()),
512
22
						access_list.clone().unwrap_or_default(),
513
22
						authorization_list.clone().unwrap_or_default(),
514
					);
515

            
516
22
					let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
517

            
518
22
					let (weight_limit, proof_size_base_cost) = pallet_ethereum::Pallet::<Runtime>::transaction_weight(&transaction_data);
519

            
520
22
					<Runtime as pallet_evm::Config>::Runner::call(
521
22
						from,
522
22
						to,
523
22
						data,
524
22
						value,
525
22
						gas_limit,
526
22
						max_fee_per_gas,
527
22
						max_priority_fee_per_gas,
528
22
						nonce,
529
22
						access_list.unwrap_or_default(),
530
22
						authorization_list.unwrap_or_default(),
531
22
						is_transactional,
532
22
						validate,
533
22
						weight_limit,
534
22
						proof_size_base_cost,
535
22
						config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),
536
22
					).map_err(|err| err.error.into())
537
22
				}
538

            
539
22
				fn create(
540
22
					from: H160,
541
22
					data: Vec<u8>,
542
22
					value: U256,
543
22
					gas_limit: U256,
544
22
					max_fee_per_gas: Option<U256>,
545
22
					max_priority_fee_per_gas: Option<U256>,
546
22
					nonce: Option<U256>,
547
22
					estimate: bool,
548
22
					access_list: Option<Vec<(H160, Vec<H256>)>>,
549
22
					authorization_list: Option<AuthorizationList>,
550
22
				) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {
551
22
					let config = if estimate {
552
						let mut config = <Runtime as pallet_evm::Config>::config().clone();
553
						config.estimate = true;
554
						Some(config)
555
					} else {
556
22
						None
557
					};
558
22
					let is_transactional = false;
559
22
					let validate = true;
560

            
561
22
					let transaction_data = pallet_ethereum::TransactionData::new(
562
22
						pallet_ethereum::TransactionAction::Create,
563
22
						data.clone(),
564
22
						nonce.unwrap_or_default(),
565
22
						gas_limit,
566
22
						None,
567
22
						max_fee_per_gas.or(Some(U256::default())),
568
22
						max_priority_fee_per_gas.or(Some(U256::default())),
569
22
						value,
570
22
						Some(<Runtime as pallet_evm::Config>::ChainId::get()),
571
22
						access_list.clone().unwrap_or_default(),
572
22
						authorization_list.clone().unwrap_or_default(),
573
					);
574

            
575
22
					let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
576

            
577
22
					let (weight_limit, proof_size_base_cost) = pallet_ethereum::Pallet::<Runtime>::transaction_weight(&transaction_data);
578

            
579
					#[allow(clippy::or_fun_call)] // suggestion not helpful here
580
22
					<Runtime as pallet_evm::Config>::Runner::create(
581
22
						from,
582
22
						data,
583
22
						value,
584
22
						gas_limit,
585
22
						max_fee_per_gas,
586
22
						max_priority_fee_per_gas,
587
22
						nonce,
588
22
						access_list.unwrap_or_default(),
589
22
						authorization_list.unwrap_or_default(),
590
22
						is_transactional,
591
22
						validate,
592
22
						weight_limit,
593
22
						proof_size_base_cost,
594
22
						config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),
595
22
					).map_err(|err| err.error.into())
596
22
				}
597

            
598
22
				fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {
599
22
					pallet_ethereum::CurrentTransactionStatuses::<Runtime>::get()
600
22
				}
601

            
602
22
				fn current_block() -> Option<pallet_ethereum::Block> {
603
22
					pallet_ethereum::CurrentBlock::<Runtime>::get()
604
22
				}
605

            
606
22
				fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {
607
22
					pallet_ethereum::CurrentReceipts::<Runtime>::get()
608
22
				}
609

            
610
				fn current_all() -> (
611
					Option<pallet_ethereum::Block>,
612
					Option<Vec<pallet_ethereum::Receipt>>,
613
					Option<Vec<TransactionStatus>>,
614
				) {
615
					(
616
						pallet_ethereum::CurrentBlock::<Runtime>::get(),
617
						pallet_ethereum::CurrentReceipts::<Runtime>::get(),
618
						pallet_ethereum::CurrentTransactionStatuses::<Runtime>::get(),
619
					)
620
				}
621

            
622
				fn extrinsic_filter(
623
					xts: Vec<<Block as BlockT>::Extrinsic>,
624
				) -> Vec<EthereumTransaction> {
625
					xts.into_iter().filter_map(|xt| match xt.0.function {
626
						RuntimeCall::Ethereum(transact { transaction }) => Some(transaction),
627
						_ => None
628
					}).collect::<Vec<EthereumTransaction>>()
629
				}
630

            
631
				fn elasticity() -> Option<Permill> {
632
					None
633
				}
634

            
635
				fn gas_limit_multiplier_support() {}
636

            
637
				fn pending_block(
638
					xts: Vec<<Block as sp_runtime::traits::Block>::Extrinsic>
639
				) -> (
640
					Option<pallet_ethereum::Block>, Option<sp_std::prelude::Vec<TransactionStatus>>
641
				) {
642
					for ext in xts.into_iter() {
643
						let _ = Executive::apply_extrinsic(ext);
644
					}
645

            
646
					Ethereum::on_finalize(System::block_number() + 1);
647

            
648
					(
649
						pallet_ethereum::CurrentBlock::<Runtime>::get(),
650
						pallet_ethereum::CurrentTransactionStatuses::<Runtime>::get()
651
					)
652
				 }
653

            
654
				fn initialize_pending_block(header: &<Block as BlockT>::Header) {
655
					pallet_randomness::vrf::using_fake_vrf(|| {
656
						pallet_author_slot_filter::using_fake_author(|| {
657
							let _ = Executive::initialize_block(header);
658
						})
659
					})
660
				}
661
			}
662

            
663
			impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {
664
				fn convert_transaction(
665
					transaction: pallet_ethereum::Transaction
666
				) -> <Block as BlockT>::Extrinsic {
667
					UncheckedExtrinsic::new_bare(
668
						pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),
669
					)
670
				}
671
			}
672

            
673
			impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
674
			for Runtime {
675
				fn query_info(
676
					uxt: <Block as BlockT>::Extrinsic,
677
					len: u32,
678
				) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
679
					TransactionPayment::query_info(uxt, len)
680
				}
681

            
682
				fn query_fee_details(
683
					uxt: <Block as BlockT>::Extrinsic,
684
					len: u32,
685
				) -> pallet_transaction_payment::FeeDetails<Balance> {
686
					TransactionPayment::query_fee_details(uxt, len)
687
				}
688

            
689
				fn query_weight_to_fee(weight: Weight) -> Balance {
690
					TransactionPayment::weight_to_fee(weight)
691
				}
692

            
693
				fn query_length_to_fee(length: u32) -> Balance {
694
					TransactionPayment::length_to_fee(length)
695
				}
696
			}
697

            
698
			impl nimbus_primitives::NimbusApi<Block> for Runtime {
699
66
				fn can_author(
700
66
					author: nimbus_primitives::NimbusId,
701
66
					slot: u32,
702
66
					parent_header: &<Block as BlockT>::Header
703
66
				) -> bool {
704
					use pallet_parachain_staking::Config as PalletParachainStakingConfig;
705

            
706
66
					let block_number = parent_header.number + 1;
707

            
708
					// The Moonbeam runtimes use an entropy source that needs to do some accounting
709
					// work during block initialization. Therefore we initialize it here to match
710
					// the state it will be in when the next block is being executed.
711
					use frame_support::traits::OnInitialize;
712
66
					System::initialize(
713
66
						&block_number,
714
66
						&parent_header.hash(),
715
66
						&parent_header.digest,
716
					);
717

            
718
					// Because the staking solution calculates the next staking set at the beginning
719
					// of the first block in the new round, the only way to accurately predict the
720
					// authors is to compute the selection during prediction.
721
66
					if pallet_parachain_staking::Pallet::<Self>::round()
722
66
						.should_update(block_number) {
723
						// get author account id
724
						use nimbus_primitives::AccountLookup;
725
						let author_account_id = if let Some(account) =
726
							pallet_author_mapping::Pallet::<Self>::lookup_account(&author) {
727
							account
728
						} else {
729
							// return false if author mapping not registered like in can_author impl
730
							return false
731
						};
732
						let candidates = pallet_parachain_staking::Pallet::<Self>::compute_top_candidates();
733
						if candidates.is_empty() {
734
							// If there are zero selected candidates, we use the same eligibility
735
							// as the previous round
736
							return AuthorInherent::can_author(&author, &slot);
737
						}
738

            
739
						// predict eligibility post-selection by computing selection results now
740
						let (eligible, _) =
741
							pallet_author_slot_filter::compute_pseudo_random_subset::<Self>(
742
								candidates,
743
								&slot
744
							);
745
						eligible.contains(&author_account_id)
746
					} else {
747
66
						AuthorInherent::can_author(&author, &slot)
748
					}
749
66
				}
750
			}
751

            
752
			impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
753
				fn collect_collation_info(
754
					header: &<Block as BlockT>::Header
755
				) -> cumulus_primitives_core::CollationInfo {
756
					ParachainSystem::collect_collation_info(header)
757
				}
758
			}
759

            
760
			impl session_keys_primitives::VrfApi<Block> for Runtime {
761
				fn get_last_vrf_output() -> Option<<Block as BlockT>::Hash> {
762
					// TODO: remove in future runtime upgrade along with storage item
763
					if pallet_randomness::Pallet::<Self>::not_first_block().is_none() {
764
						return None;
765
					}
766
					pallet_randomness::Pallet::<Self>::local_vrf_output()
767
				}
768
				fn vrf_key_lookup(
769
					nimbus_id: nimbus_primitives::NimbusId
770
				) -> Option<session_keys_primitives::VrfId> {
771
					use session_keys_primitives::KeysLookup;
772
					AuthorMapping::lookup_keys(&nimbus_id)
773
				}
774
			}
775

            
776
			impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
777
				fn query_acceptable_payment_assets(
778
					xcm_version: xcm::Version
779
				) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
780
					XcmWeightTrader::query_acceptable_payment_assets(xcm_version)
781
				}
782

            
783
				fn query_weight_to_asset_fee(
784
					weight: Weight, asset: VersionedAssetId
785
				) -> Result<u128, XcmPaymentApiError> {
786
					XcmWeightTrader::query_weight_to_asset_fee(weight, asset)
787
				}
788

            
789
				fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
790
					PolkadotXcm::query_xcm_weight(message)
791
				}
792

            
793
				fn query_delivery_fees(
794
					destination: VersionedLocation, message: VersionedXcm<()>
795
				) -> Result<VersionedAssets, XcmPaymentApiError> {
796
					PolkadotXcm::query_delivery_fees(destination, message)
797
				}
798
			}
799

            
800
			impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller>
801
				for Runtime {
802
					fn dry_run_call(
803
						origin: OriginCaller,
804
						call: RuntimeCall,
805
						result_xcms_version: XcmVersion
806
					) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
807
						PolkadotXcm::dry_run_call::<
808
							Runtime,
809
							xcm_config::XcmRouter,
810
							OriginCaller,
811
							RuntimeCall>(origin, call, result_xcms_version)
812
					}
813

            
814
					fn dry_run_xcm(
815
						origin_location: VersionedLocation,
816
						xcm: VersionedXcm<RuntimeCall>
817
					) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
818
						PolkadotXcm::dry_run_xcm::<xcm_config::XcmRouter>(origin_location, xcm)
819
					}
820
				}
821

            
822
			impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
823
				fn convert_location(location: VersionedLocation) -> Result<
824
					AccountId,
825
					xcm_runtime_apis::conversions::Error
826
				> {
827
					xcm_runtime_apis::conversions::LocationToAccountHelper::<
828
						AccountId,
829
						xcm_config::LocationToAccountId,
830
					>::convert_location(location)
831
				}
832
			}
833

            
834
			#[cfg(feature = "runtime-benchmarks")]
835
			impl frame_benchmarking::Benchmark<Block> for Runtime {
836

            
837
				fn benchmark_metadata(extra: bool) -> (
838
					Vec<frame_benchmarking::BenchmarkList>,
839
					Vec<frame_support::traits::StorageInfo>,
840
				) {
841
					use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
842
					use frame_system_benchmarking::Pallet as SystemBench;
843
					use frame_support::traits::StorageInfoTrait;
844

            
845
					use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
846
					use pallet_transaction_payment::benchmarking::Pallet as TransactionPaymentBenchmark;
847

            
848
					let mut list = Vec::<BenchmarkList>::new();
849
					list_benchmarks!(list, extra);
850

            
851
					let storage_info = AllPalletsWithSystem::storage_info();
852

            
853
					return (list, storage_info)
854
				}
855

            
856
				#[allow(non_local_definitions)]
857
				fn dispatch_benchmark(
858
					config: frame_benchmarking::BenchmarkConfig,
859
				) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
860
					use frame_benchmarking::{add_benchmark, BenchmarkBatch, Benchmarking};
861
					use frame_support::traits::TrackedStorageKey;
862
					use cumulus_primitives_core::ParaId;
863

            
864
					use xcm::latest::prelude::{
865
						GeneralIndex, Junction, Junctions, Location, Response, NetworkId, AssetId, Here,
866
						Assets as XcmAssets, Fungible, Asset, ParentThen, Parachain, Parent, WeightLimit,
867
						AccountId32,
868
					};
869
					use xcm_config::{SelfReserve, MaxAssetsIntoHolding, AssetHubLocation, RelayLocation};
870
					use frame_benchmarking::BenchmarkError;
871
					use xcm_executor::traits::ConvertLocation;
872

            
873
					use frame_system_benchmarking::Pallet as SystemBench;
874
					// Needed to run `set_code` and `apply_authorized_upgrade` frame_system benchmarks
875
					// https://github.com/paritytech/cumulus/pull/2766
876
					impl frame_system_benchmarking::Config for Runtime {
877
						fn setup_set_code_requirements(code: &Vec<u8>) -> Result<(), BenchmarkError> {
878
							ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
879
							Ok(())
880
						}
881

            
882
						fn verify_set_code() {
883
							System::assert_last_event(cumulus_pallet_parachain_system::Event::<Runtime>::ValidationFunctionStored.into());
884
						}
885
					}
886

            
887
					// Needed to run `charge_transaction_payment` benchmark which distributes
888
					// fees to block author. Moonbeam requires an author to be set for fee distribution.
889
					use pallet_transaction_payment::benchmarking::Pallet as TransactionPaymentBenchmark;
890
					impl pallet_transaction_payment::benchmarking::Config for Runtime {
891
						fn setup_benchmark_environment() {
892
							// Set a dummy author for the block so fee distribution doesn't panic
893
							let author: AccountId = frame_benchmarking::whitelisted_caller();
894
							pallet_author_inherent::Author::<Runtime>::put(author);
895
						}
896
					}
897

            
898
					use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
899
					parameter_types! {
900
						pub const RandomParaId: ParaId = ParaId::new(43211234);
901
					}
902

            
903
					/// Custom delivery helper for Moonbeam that works with H160 accounts.
904
					/// This is needed because Moonbeam uses AccountKey20 (H160) accounts
905
					/// instead of AccountId32, and the standard ToParentDeliveryHelper
906
					/// fails when trying to deposit assets to an origin location.
907
					pub struct TestDeliveryHelper;
908
					impl xcm_builder::EnsureDelivery for TestDeliveryHelper {
909
						fn ensure_successful_delivery(
910
							origin_ref: &Location,
911
							dest: &Location,
912
							_fee_reason: xcm_executor::traits::FeeReason,
913
						) -> (Option<xcm_executor::FeesMode>, Option<XcmAssets>) {
914
							use xcm_executor::traits::ConvertLocation;
915

            
916
							// Ensure the XCM sender is properly configured for benchmarks
917
							// This sets up the HostConfiguration for sending messages
918
							<xcm_config::XcmRouter as xcm::latest::SendXcm>::ensure_successful_delivery(Some(dest.clone()));
919

            
920
							// Open HRMP channel for sibling parachain destinations
921
							if let Some(Parachain(para_id)) = dest.interior().first() {
922
								ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
923
									(*para_id).into()
924
								);
925
							}
926

            
927
							// Deposit existential deposit to the origin account if we can convert it
928
							if let Some(account) = xcm_config::LocationToH160::convert_location(origin_ref) {
929
								let balance = ExistentialDeposit::get() * 1000u128;
930
								let _ = <Balances as frame_support::traits::Currency<_>>::
931
									make_free_balance_be(&account.into(), balance);
932
							}
933

            
934
							(None, None)
935
						}
936
					}
937

            
938
					impl pallet_xcm::benchmarking::Config for Runtime {
939
				        type DeliveryHelper = TestDeliveryHelper;
940

            
941
						fn get_asset() -> Asset {
942
							Asset {
943
								id: AssetId(SelfReserve::get()),
944
								fun: Fungible(ExistentialDeposit::get()),
945
							}
946
						}
947

            
948
						fn reachable_dest() -> Option<Location> {
949
							Some(Parent.into())
950
						}
951

            
952
						fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
953
							None
954
						}
955

            
956
						fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
957
							use xcm_config::SelfReserve;
958

            
959
							ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
960
								RandomParaId::get().into()
961
							);
962

            
963
							Some((
964
								Asset {
965
									fun: Fungible(ExistentialDeposit::get()),
966
									id: AssetId(SelfReserve::get().into())
967
								},
968
								// Moonbeam can reserve transfer native token to
969
								// some random parachain.
970
								ParentThen(Parachain(RandomParaId::get().into()).into()).into(),
971
							))
972
						}
973

            
974
						fn set_up_complex_asset_transfer(
975
						) -> Option<(XcmAssets, u32, Location, Box<dyn FnOnce()>)> {
976
							use xcm_config::SelfReserve;
977

            
978
							let destination: xcm::v5::Location = Parent.into();
979

            
980
							let fee_amount: u128 = <Runtime as pallet_balances::Config>::ExistentialDeposit::get();
981
							let fee_asset: Asset = (SelfReserve::get(), fee_amount).into();
982

            
983
							// Give some multiple of transferred amount
984
							let balance = fee_amount * 1000;
985
							let who = frame_benchmarking::whitelisted_caller();
986
							let _ =
987
								<Balances as frame_support::traits::Currency<_>>::make_free_balance_be(&who, balance);
988

            
989
							// verify initial balance
990
							assert_eq!(Balances::free_balance(&who), balance);
991

            
992
							// set up foreign asset
993
							let asset_amount: u128 = 10u128;
994
							let initial_asset_amount: u128 = asset_amount * 10;
995

            
996
							let asset_id = pallet_moonbeam_foreign_assets::default_asset_id::<Runtime>() + 1;
997
							let (_, location, _) = pallet_moonbeam_foreign_assets::create_default_minted_foreign_asset::<Runtime>(
998
								asset_id,
999
								initial_asset_amount,
							);
							let transfer_asset: Asset = (AssetId(location), asset_amount).into();
							let assets: XcmAssets = vec![fee_asset.clone(), transfer_asset].into();
							let fee_index: u32 = 0;
							let verify: Box<dyn FnOnce()> = Box::new(move || {
								// verify balance after transfer, decreased by
								// transferred amount (and delivery fees)
								assert!(Balances::free_balance(&who) <= balance - fee_amount);
							});
							Some((assets, fee_index, destination, verify))
						}
					}
					impl pallet_xcm_benchmarks::Config for Runtime {
						type XcmConfig = xcm_config::XcmExecutorConfig;
						type AccountIdConverter = BenchAccountIdConverter<AccountId>;
						type DeliveryHelper = TestDeliveryHelper;
						fn valid_destination() -> Result<Location, BenchmarkError> {
							Ok(Location::parent())
						}
						fn worst_case_holding(_depositable_count: u32) -> XcmAssets {
							const HOLDING_FUNGIBLES: u32 = MaxAssetsIntoHolding::get();
							let fungibles_amount: u128 = 1_000 * ExistentialDeposit::get();
							let assets = (1..=HOLDING_FUNGIBLES).map(|i| {
								let location: Location = GeneralIndex(i as u128).into();
								Asset {
									id: AssetId(location),
									fun: Fungible(fungibles_amount * i as u128),
								}
								.into()
							})
							.chain(
								core::iter::once(
									Asset {
										id: AssetId(Location::parent()),
										fun: Fungible(u128::MAX)
									}
								)
							)
							.collect::<Vec<_>>();
							for (i, asset) in assets.iter().enumerate() {
								if let Asset {
									id: AssetId(location),
									fun: Fungible(_)
								} = asset {
									EvmForeignAssets::set_asset(
										location.clone(),
										i as u128
									);
									XcmWeightTrader::set_asset_price(
										location.clone(),
										10u128.pow(18)
									);
								}
							}
							assets.into()
						}
					}
					parameter_types! {
						// Native token location
						pub const TokenLocation: Location = Here.into_location();
						pub TrustedTeleporter: Option<(Location, Asset)> = None;
						pub CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;
						// Reserve location and asset used by the `reserve_asset_deposited` benchmark.
						// We use DOT (asset id = `RelayLocation`) whose reserve is Asset Hub.
						pub TrustedReserve: Option<(Location, Asset)> = Some((
							AssetHubLocation::get(),
							Asset {
								id: AssetId(RelayLocation::get()),
								fun: Fungible(100 * ExistentialDeposit::get()),
							}
						));
					}
					impl pallet_xcm_benchmarks::fungible::Config for Runtime {
						type TransactAsset = Balances;
						type CheckedAccount = CheckedAccount;
						type TrustedTeleporter = TrustedTeleporter;
						type TrustedReserve = TrustedReserve;
						fn get_asset() -> Asset {
							// We put more than ED here for being able to keep accounts alive when transferring
							// and paying the delivery fees.
							let location: Location = GeneralIndex(1).into();
							let asset_id = 1u128;
							let decimals = 18u8;
							let asset = Asset {
								id: AssetId(location.clone()),
								fun: Fungible(100 * ExistentialDeposit::get()),
							};
							EvmForeignAssets::set_asset(
								location.clone(),
								asset_id,
							);
							XcmWeightTrader::set_asset_price(
								location.clone(),
								10u128.pow(decimals as u32)
							);
							EvmForeignAssets::create_asset_contract(
								asset_id,
								decimals,
								"TKN",
								"Token",
							).unwrap();
							asset
						}
					}
					impl pallet_xcm_benchmarks::generic::Config for Runtime {
						type RuntimeCall = RuntimeCall;
						type TransactAsset = Balances;
						fn worst_case_response() -> (u64, Response) {
							(0u64, Response::Version(Default::default()))
						}
						fn worst_case_asset_exchange()
							-> Result<(XcmAssets, XcmAssets), BenchmarkError> {
							Err(BenchmarkError::Skip)
						}
						fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
							Err(BenchmarkError::Skip)
						}
						fn export_message_origin_and_destination()
							-> Result<(Location, NetworkId, Junctions), BenchmarkError> {
							Err(BenchmarkError::Skip)
						}
						fn transact_origin_and_runtime_call()
							-> Result<(Location, RuntimeCall), BenchmarkError> {
							Ok((Location::parent(), frame_system::Call::remark_with_event {
								remark: vec![]
							}.into()))
						}
						fn subscribe_origin() -> Result<Location, BenchmarkError> {
							Ok(Location::parent())
						}
						fn claimable_asset()
							-> Result<(Location, Location, XcmAssets), BenchmarkError> {
							let origin = Location::parent();
							let assets: XcmAssets = (AssetId(Location::parent()), 1_000u128)
								.into();
							let ticket = Location { parents: 0, interior: [].into() /* Here */ };
							Ok((origin, ticket, assets))
						}
						fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
							let location: Location = GeneralIndex(1).into();
							Ok((
								Asset {
									id: AssetId(Location::parent()),
									fun: Fungible(1_000_000_000_000_000 as u128)
								},
								WeightLimit::Limited(Weight::from_parts(5000, 5000)),
							))
						}
						fn unlockable_asset()
							-> Result<(Location, Location, Asset), BenchmarkError> {
							Err(BenchmarkError::Skip)
						}
						fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
							Err(BenchmarkError::Skip)
						}
					}
					$($bench_custom)*
					let whitelist: Vec<TrackedStorageKey> = vec![
						// Block Number
						hex_literal::hex!(  "26aa394eea5630e07c48ae0c9558cef7"
											"02a5c1b19ab7a04f536c519aca4983ac")
							.to_vec().into(),
						// Total Issuance
						hex_literal::hex!(  "c2261276cc9d1f8598ea4b6a74b15c2f"
											"57c875e4cff74148e4628f264b974c80")
							.to_vec().into(),
						// Execution Phase
						hex_literal::hex!(  "26aa394eea5630e07c48ae0c9558cef7"
											"ff553b5a9862a516939d82b3d3d8661a")
							.to_vec().into(),
						// Event Count
						hex_literal::hex!(  "26aa394eea5630e07c48ae0c9558cef7"
											"0a98fdbe9ce6c55837576c60c7af3850")
							.to_vec().into(),
						// System Events
						hex_literal::hex!(  "26aa394eea5630e07c48ae0c9558cef7"
											"80d41e5e16056765bc8461851072c9d7")
							.to_vec().into(),
						// System BlockWeight
						hex_literal::hex!(  "26aa394eea5630e07c48ae0c9558cef7"
											"34abf5cb34d6244378cddbf18e849d96")
							.to_vec().into(),
						// ParachainStaking Round
						hex_literal::hex!(  "a686a3043d0adcf2fa655e57bc595a78"
											"13792e785168f725b60e2969c7fc2552")
							.to_vec().into(),
						// Treasury Account (py/trsry)
						hex_literal::hex!(  "26aa394eea5630e07c48ae0c9558cef7"
											"b99d880ec681799c0cf30e8886371da9"
											"7be2919ac397ba499ea5e57132180ec6"
											"6d6f646c70792f747273727900000000"
											"00000000"
						).to_vec().into(),
						// Treasury Account (pc/trsry)
						hex_literal::hex!(  "26aa394eea5630e07c48ae0c9558cef7"
											"b99d880ec681799c0cf30e8886371da9"
											"7be2919ac397ba499ea5e57132180ec6"
											"6d6f646c70632f747273727900000000"
											"00000000"
						).to_vec().into(),
						// ParachainInfo ParachainId
						hex_literal::hex!(  "0d715f2646c8f85767b5d2764bb27826"
											"04a74d81251e398fd8a0a4d55023bb3f")
							.to_vec().into(),
						// Parameters Parameters
						hex_literal::hex!(  "c63bdd4a39095ccf55623a6f2872bf8a" // Pallet: "Parameters"
											"c63bdd4a39095ccf55623a6f2872bf8a" // Storage Prefix: "Parameters"
											// MoonbaseRuntimeRuntimeParamsRuntimeParametersKey(FeesTreasuryProportion)
											"71d0aacb690b61280d0c97c6b6a666640000"
										)
							.to_vec().into(),
					];
					let mut batches = Vec::<BenchmarkBatch>::new();
					let params = (&config, &whitelist);
					add_benchmarks!(params, batches);
					Ok(batches)
				}
			}
			#[cfg(feature = "try-runtime")]
			impl frame_try_runtime::TryRuntime<Block> for Runtime {
				fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
					log::info!("try-runtime::on_runtime_upgrade()");
					// NOTE: intentional expect: we don't want to propagate the error backwards,
					// and want to have a backtrace here. If any of the pre/post migration checks
					// fail, we shall stop right here and right now.
					let weight = Executive::try_runtime_upgrade(checks)
						.expect("runtime upgrade logic *must* be infallible");
					(weight, RuntimeBlockWeights::get().max_block)
				}
				fn execute_block(
					block: Block,
					state_root_check: bool,
					signature_check: bool,
					select: frame_try_runtime::TryStateSelect
				) -> Weight {
					log::info!(
						"try-runtime: executing block {:?} / root checks: {:?} / try-state-select: {:?}",
						block.header.hash(),
						state_root_check,
						select,
					);
					// NOTE: intentional unwrap: we don't want to propagate the error backwards,
					// and want to have a backtrace here.
					Executive::try_execute_block(
						block,
						state_root_check,
						signature_check,
						select,
					).expect("execute-block failed")
				}
			}
967866
		}
	};
}