From 9ed88f73dc6c79d11b3fe7bd95cbc58f46cf48e2 Mon Sep 17 00:00:00 2001 From: Alejandro Martinez Andres <11448715+al3mart@users.noreply.github.com> Date: Wed, 5 Mar 2025 03:35:38 +0100 Subject: [PATCH] refactor(devnet): move apis to its own modules typo fmt fix unsed --- runtime/devnet/src/apis.rs | 438 +++++++++++++++++++++++++++++++++++++ runtime/devnet/src/lib.rs | 426 +----------------------------------- 2 files changed, 444 insertions(+), 420 deletions(-) create mode 100644 runtime/devnet/src/apis.rs diff --git a/runtime/devnet/src/apis.rs b/runtime/devnet/src/apis.rs new file mode 100644 index 000000000..9e5803078 --- /dev/null +++ b/runtime/devnet/src/apis.rs @@ -0,0 +1,438 @@ +use alloc::vec::Vec; + +use frame_support::{ + genesis_builder_helper::{build_state, get_preset}, + traits::nonfungibles_v2::Inspect, + weights::Weight, +}; +use ismp::host::StateMachine; +use sp_api::impl_runtime_apis; +use sp_consensus_aura::sr25519::AuthorityId as AuraId; +use sp_core::{crypto::KeyTypeId, Get, OpaqueMetadata, H256}; +use sp_runtime::{ + traits::Block as BlockT, + transaction_validity::{TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, +}; +use sp_version::RuntimeVersion; + +// Local module imports +use super::{ + genesis, AccountId, AllPalletsWithSystem, Balance, Block, BlockNumber, ConsensusClientId, + Contracts, EventRecord, Executive, ExtrinsicInclusionMode, Hash, InherentDataExt, Ismp, + IsmpParachain, Leaf, Nfts, Nonce, ParachainSystem, Proof, ProofKeys, RelayChainState, Request, + Response, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeGenesisConfig, SessionKeys, + StateMachineHeight, StateMachineId, System, TransactionPayment, CONTRACTS_DEBUG_OUTPUT, + CONTRACTS_EVENTS, VERSION, *, +}; + +impl_runtime_apis! { + + impl sp_consensus_aura::AuraApi for Runtime { + fn slot_duration() -> sp_consensus_aura::SlotDuration { + Runtime::impl_slot_duration() + } + + fn authorities() -> Vec { + pallet_aura::Authorities::::get().into_inner() + } + } + + impl sp_api::Core for Runtime { + fn version() -> RuntimeVersion { + VERSION + } + + fn execute_block(block: Block) { + Executive::execute_block(block) + } + + fn initialize_block(header: &::Header) -> ExtrinsicInclusionMode { + Executive::initialize_block(header) + } + } + + impl sp_api::Metadata for Runtime { + fn metadata() -> OpaqueMetadata { + OpaqueMetadata::new(Runtime::metadata().into()) + } + + fn metadata_at_version(version: u32) -> Option { + Runtime::metadata_at_version(version) + } + + fn metadata_versions() -> Vec { + Runtime::metadata_versions() + } + } + + impl sp_block_builder::BlockBuilder for Runtime { + fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { + Executive::apply_extrinsic(extrinsic) + } + + fn finalize_block() -> ::Header { + Executive::finalize_block() + } + + fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<::Extrinsic> { + data.create_extrinsics() + } + + fn check_inherents( + block: Block, + data: sp_inherents::InherentData, + ) -> sp_inherents::CheckInherentsResult { + data.check_extrinsics(&block) + } + } + + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + fn validate_transaction( + source: TransactionSource, + tx: ::Extrinsic, + block_hash: ::Hash, + ) -> TransactionValidity { + Executive::validate_transaction(source, tx, block_hash) + } + } + + impl sp_offchain::OffchainWorkerApi for Runtime { + fn offchain_worker(header: &::Header) { + Executive::offchain_worker(header) + } + } + + impl sp_session::SessionKeys for Runtime { + fn generate_session_keys(seed: Option>) -> Vec { + SessionKeys::generate(seed) + } + + fn decode_session_keys( + encoded: Vec, + ) -> Option, KeyTypeId)>> { + SessionKeys::decode_into_raw_public_keys(&encoded) + } + } + + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Nonce { + System::account_nonce(account) + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { + fn query_info( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo { + TransactionPayment::query_info(uxt, len) + } + fn query_fee_details( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment::FeeDetails { + TransactionPayment::query_fee_details(uxt, len) + } + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi + for Runtime + { + fn query_call_info( + call: RuntimeCall, + len: u32, + ) -> pallet_transaction_payment::RuntimeDispatchInfo { + TransactionPayment::query_call_info(call, len) + } + fn query_call_fee_details( + call: RuntimeCall, + len: u32, + ) -> pallet_transaction_payment::FeeDetails { + TransactionPayment::query_call_fee_details(call, len) + } + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } + } + + impl pallet_contracts::ContractsApi + for Runtime + { + fn call( + origin: AccountId, + dest: AccountId, + value: Balance, + gas_limit: Option, + storage_deposit_limit: Option, + input_data: Vec, + ) -> pallet_contracts::ContractExecResult { + let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); + Contracts::bare_call( + origin, + dest, + value, + gas_limit, + storage_deposit_limit, + input_data, + CONTRACTS_DEBUG_OUTPUT, + CONTRACTS_EVENTS, + pallet_contracts::Determinism::Enforced, + ) + } + + fn instantiate( + origin: AccountId, + value: Balance, + gas_limit: Option, + storage_deposit_limit: Option, + code: pallet_contracts::Code, + data: Vec, + salt: Vec, + ) -> pallet_contracts::ContractInstantiateResult + { + let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); + Contracts::bare_instantiate( + origin, + value, + gas_limit, + storage_deposit_limit, + code, + data, + salt, + CONTRACTS_DEBUG_OUTPUT, + CONTRACTS_EVENTS, + ) + } + + fn upload_code( + origin: AccountId, + code: Vec, + storage_deposit_limit: Option, + determinism: pallet_contracts::Determinism, + ) -> pallet_contracts::CodeUploadResult + { + Contracts::bare_upload_code(origin, code, storage_deposit_limit, determinism) + } + + fn get_storage( + address: AccountId, + key: Vec, + ) -> pallet_contracts::GetStorageResult { + Contracts::get_storage(address, key) + } + } + + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot, + ) -> bool { + Runtime::impl_can_build_upon(included_hash, slot) + } + } + + impl cumulus_primitives_core::CollectCollationInfo for Runtime { + fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { + ParachainSystem::collect_collation_info(header) + } + } + + impl pallet_nfts_runtime_api::NftsApi for Runtime { + fn owner(collection: u32, item: u32) -> Option { + >::owner(&collection, &item) + } + + fn collection_owner(collection: u32) -> Option { + >::collection_owner(&collection) + } + + fn attribute( + collection: u32, + item: u32, + key: Vec, + ) -> Option> { + >::attribute(&collection, &item, &key) + } + + fn custom_attribute( + account: AccountId, + collection: u32, + item: u32, + key: Vec, + ) -> Option> { + >::custom_attribute( + &account, + &collection, + &item, + &key, + ) + } + + fn system_attribute( + collection: u32, + item: Option, + key: Vec, + ) -> Option> { + >::system_attribute(&collection, item.as_ref(), &key) + } + + fn collection_attribute(collection: u32, key: Vec) -> Option> { + >::collection_attribute(&collection, &key) + } + } + + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { + let weight = Executive::try_runtime_upgrade(checks).unwrap(); + (weight, RuntimeBlockWeights::get().max_block) + } + + fn execute_block( + block: Block, + state_root_check: bool, + signature_check: bool, + select: frame_try_runtime::TryStateSelect, + ) -> Weight { + // 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).unwrap() + } + } + + #[cfg(feature = "runtime-benchmarks")] + impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec, + ) { + use frame_benchmarking::{Benchmarking, BenchmarkList}; + use frame_support::traits::StorageInfoTrait; + use frame_system_benchmarking::Pallet as SystemBench; + use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + + let mut list = Vec::::new(); + list_benchmarks!(list, extra); + + let storage_info = AllPalletsWithSystem::storage_info(); + (list, storage_info) + } + + fn dispatch_benchmark( + config: frame_benchmarking::BenchmarkConfig + ) -> Result, alloc::string::String> { + use frame_benchmarking::{Benchmarking, BenchmarkError, BenchmarkBatch}; + + use frame_system_benchmarking::Pallet as SystemBench; + impl frame_system_benchmarking::Config for Runtime { + fn setup_set_code_requirements(code: &Vec) -> Result<(), BenchmarkError> { + ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32); + Ok(()) + } + + fn verify_set_code() { + System::assert_last_event(cumulus_pallet_parachain_system::Event::::ValidationFunctionStored.into()); + } + } + + use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + impl cumulus_pallet_session_benchmarking::Config for Runtime {} + + use frame_support::traits::WhitelistedStorageKeys; + let whitelist = AllPalletsWithSystem::whitelisted_storage_keys(); + + let mut batches = Vec::::new(); + let params = (&config, &whitelist); + add_benchmarks!(params, batches); + + if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } + Ok(batches) + } + } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + get_preset::(id, genesis::get_preset) + } + + fn preset_names() -> Vec { + genesis::presets() + } + } + + impl pallet_ismp_runtime_api::IsmpRuntimeApi::Hash> for Runtime { + fn host_state_machine() -> StateMachine { + ::HostStateMachine::get() + } + + fn challenge_period(id: StateMachineId) -> Option { + Ismp::challenge_period(id) + } + + /// Generate a proof for the provided leaf indices + fn generate_proof( + keys: ProofKeys + ) -> Result<(Vec, Proof<::Hash>), sp_mmr_primitives::Error> { + Ismp::generate_proof(keys) + } + + /// Fetch all ISMP events + fn block_events() -> Vec<::ismp::events::Event> { + Ismp::block_events() + } + + /// Fetch all ISMP events and their extrinsic metadata + fn block_events_with_metadata() -> Vec<(::ismp::events::Event, Option)> { + Ismp::block_events_with_metadata() + } + + /// Return the scale encoded consensus state + fn consensus_state(id: ConsensusClientId) -> Option> { + Ismp::consensus_states(id) + } + + /// Return the timestamp this client was last updated in seconds + fn state_machine_update_time(height: StateMachineHeight) -> Option { + Ismp::state_machine_update_time(height) + } + + /// Return the latest height of the state machine + fn latest_state_machine_height(id: StateMachineId) -> Option { + Ismp::latest_state_machine_height(id) + } + + /// Get actual requests + fn requests(commitments: Vec) -> Vec { + Ismp::requests(commitments) + } + + /// Get actual requests + fn responses(commitments: Vec) -> Vec { + Ismp::responses(commitments) + } + } + + impl ismp_parachain_runtime_api::IsmpParachainApi for Runtime { + fn para_ids() -> Vec { + IsmpParachain::para_ids() + } + + fn current_relay_chain_state() -> RelayChainState { + IsmpParachain::current_relay_chain_state() + } + } +} diff --git a/runtime/devnet/src/lib.rs b/runtime/devnet/src/lib.rs index 9dbf0ace1..70067b837 100644 --- a/runtime/devnet/src/lib.rs +++ b/runtime/devnet/src/lib.rs @@ -6,6 +6,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +mod apis; // Public due to integration tests crate. pub mod config; /// The genesis state presets available. @@ -19,7 +20,6 @@ use alloc::{borrow::Cow, vec::Vec}; // ISMP imports use ::ismp::{ consensus::{ConsensusClientId, StateMachineHeight, StateMachineId}, - host::StateMachine, router::{Request, Response}, }; use config::xcm::{RelayLocation, XcmOriginToTransactDispatchOrigin}; @@ -28,12 +28,11 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ derive_impl, dispatch::DispatchClass, - genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - fungible::HoldConsideration, tokens::nonfungibles_v2::Inspect, ConstBool, ConstU32, - ConstU64, ConstU8, Contains, EitherOfDiverse, EqualPrivilegeOnly, EverythingBut, - LinearStoragePrice, TransformOrigin, VariantCountOf, + fungible::HoldConsideration, ConstBool, ConstU32, ConstU64, ConstU8, Contains, + EitherOfDiverse, EqualPrivilegeOnly, EverythingBut, LinearStoragePrice, TransformOrigin, + VariantCountOf, }, weights::{ ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, @@ -60,15 +59,11 @@ pub use pop_runtime_common::{ UNINCLUDED_SEGMENT_CAPACITY, UNIT, }; use smallvec::smallvec; -use sp_api::impl_runtime_apis; -use sp_core::{crypto::KeyTypeId, Get, OpaqueMetadata, H256}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; use sp_runtime::{ generic, impl_opaque_keys, traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, Verify}, - transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, }; pub use sp_runtime::{ExtrinsicInclusionMode, MultiAddress, Perbill, Permill}; #[cfg(feature = "std")] @@ -78,6 +73,8 @@ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; // XCM Imports use xcm::latest::prelude::BodyId; +pub use crate::apis::{RuntimeApi, RUNTIME_API_VERSIONS}; + /// Some way of identifying an account on the chain. We intentionally make it equivalent /// to the public key of our transaction signing scheme. pub type AccountId = <::Signer as IdentifyAccount>::AccountId; @@ -692,417 +689,6 @@ impl Runtime { } } -impl_runtime_apis! { - - impl sp_consensus_aura::AuraApi for Runtime { - fn slot_duration() -> sp_consensus_aura::SlotDuration { - Runtime::impl_slot_duration() - } - - fn authorities() -> Vec { - pallet_aura::Authorities::::get().into_inner() - } - } - - impl sp_api::Core for Runtime { - fn version() -> RuntimeVersion { - VERSION - } - - fn execute_block(block: Block) { - Executive::execute_block(block) - } - - fn initialize_block(header: &::Header) -> ExtrinsicInclusionMode { - Executive::initialize_block(header) - } - } - - impl sp_api::Metadata for Runtime { - fn metadata() -> OpaqueMetadata { - OpaqueMetadata::new(Runtime::metadata().into()) - } - - fn metadata_at_version(version: u32) -> Option { - Runtime::metadata_at_version(version) - } - - fn metadata_versions() -> Vec { - Runtime::metadata_versions() - } - } - - impl sp_block_builder::BlockBuilder for Runtime { - fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { - Executive::apply_extrinsic(extrinsic) - } - - fn finalize_block() -> ::Header { - Executive::finalize_block() - } - - fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<::Extrinsic> { - data.create_extrinsics() - } - - fn check_inherents( - block: Block, - data: sp_inherents::InherentData, - ) -> sp_inherents::CheckInherentsResult { - data.check_extrinsics(&block) - } - } - - impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { - fn validate_transaction( - source: TransactionSource, - tx: ::Extrinsic, - block_hash: ::Hash, - ) -> TransactionValidity { - Executive::validate_transaction(source, tx, block_hash) - } - } - - impl sp_offchain::OffchainWorkerApi for Runtime { - fn offchain_worker(header: &::Header) { - Executive::offchain_worker(header) - } - } - - impl sp_session::SessionKeys for Runtime { - fn generate_session_keys(seed: Option>) -> Vec { - SessionKeys::generate(seed) - } - - fn decode_session_keys( - encoded: Vec, - ) -> Option, KeyTypeId)>> { - SessionKeys::decode_into_raw_public_keys(&encoded) - } - } - - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { - fn account_nonce(account: AccountId) -> Nonce { - System::account_nonce(account) - } - } - - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { - fn query_info( - uxt: ::Extrinsic, - len: u32, - ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo { - TransactionPayment::query_info(uxt, len) - } - fn query_fee_details( - uxt: ::Extrinsic, - len: u32, - ) -> pallet_transaction_payment::FeeDetails { - TransactionPayment::query_fee_details(uxt, len) - } - fn query_weight_to_fee(weight: Weight) -> Balance { - TransactionPayment::weight_to_fee(weight) - } - fn query_length_to_fee(length: u32) -> Balance { - TransactionPayment::length_to_fee(length) - } - } - - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi - for Runtime - { - fn query_call_info( - call: RuntimeCall, - len: u32, - ) -> pallet_transaction_payment::RuntimeDispatchInfo { - TransactionPayment::query_call_info(call, len) - } - fn query_call_fee_details( - call: RuntimeCall, - len: u32, - ) -> pallet_transaction_payment::FeeDetails { - TransactionPayment::query_call_fee_details(call, len) - } - fn query_weight_to_fee(weight: Weight) -> Balance { - TransactionPayment::weight_to_fee(weight) - } - fn query_length_to_fee(length: u32) -> Balance { - TransactionPayment::length_to_fee(length) - } - } - - impl pallet_contracts::ContractsApi - for Runtime - { - fn call( - origin: AccountId, - dest: AccountId, - value: Balance, - gas_limit: Option, - storage_deposit_limit: Option, - input_data: Vec, - ) -> pallet_contracts::ContractExecResult { - let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_call( - origin, - dest, - value, - gas_limit, - storage_deposit_limit, - input_data, - CONTRACTS_DEBUG_OUTPUT, - CONTRACTS_EVENTS, - pallet_contracts::Determinism::Enforced, - ) - } - - fn instantiate( - origin: AccountId, - value: Balance, - gas_limit: Option, - storage_deposit_limit: Option, - code: pallet_contracts::Code, - data: Vec, - salt: Vec, - ) -> pallet_contracts::ContractInstantiateResult - { - let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block); - Contracts::bare_instantiate( - origin, - value, - gas_limit, - storage_deposit_limit, - code, - data, - salt, - CONTRACTS_DEBUG_OUTPUT, - CONTRACTS_EVENTS, - ) - } - - fn upload_code( - origin: AccountId, - code: Vec, - storage_deposit_limit: Option, - determinism: pallet_contracts::Determinism, - ) -> pallet_contracts::CodeUploadResult - { - Contracts::bare_upload_code(origin, code, storage_deposit_limit, determinism) - } - - fn get_storage( - address: AccountId, - key: Vec, - ) -> pallet_contracts::GetStorageResult { - Contracts::get_storage(address, key) - } - } - - impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { - fn can_build_upon( - included_hash: ::Hash, - slot: cumulus_primitives_aura::Slot, - ) -> bool { - Runtime::impl_can_build_upon(included_hash, slot) - } - } - - impl cumulus_primitives_core::CollectCollationInfo for Runtime { - fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { - ParachainSystem::collect_collation_info(header) - } - } - - impl pallet_nfts_runtime_api::NftsApi for Runtime { - fn owner(collection: u32, item: u32) -> Option { - >::owner(&collection, &item) - } - - fn collection_owner(collection: u32) -> Option { - >::collection_owner(&collection) - } - - fn attribute( - collection: u32, - item: u32, - key: Vec, - ) -> Option> { - >::attribute(&collection, &item, &key) - } - - fn custom_attribute( - account: AccountId, - collection: u32, - item: u32, - key: Vec, - ) -> Option> { - >::custom_attribute( - &account, - &collection, - &item, - &key, - ) - } - - fn system_attribute( - collection: u32, - item: Option, - key: Vec, - ) -> Option> { - >::system_attribute(&collection, item.as_ref(), &key) - } - - fn collection_attribute(collection: u32, key: Vec) -> Option> { - >::collection_attribute(&collection, &key) - } - } - - #[cfg(feature = "try-runtime")] - impl frame_try_runtime::TryRuntime for Runtime { - fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { - let weight = Executive::try_runtime_upgrade(checks).unwrap(); - (weight, RuntimeBlockWeights::get().max_block) - } - - fn execute_block( - block: Block, - state_root_check: bool, - signature_check: bool, - select: frame_try_runtime::TryStateSelect, - ) -> Weight { - // 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).unwrap() - } - } - - #[cfg(feature = "runtime-benchmarks")] - impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; - use frame_support::traits::StorageInfoTrait; - use frame_system_benchmarking::Pallet as SystemBench; - use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - - let mut list = Vec::::new(); - list_benchmarks!(list, extra); - - let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) - } - - fn dispatch_benchmark( - config: frame_benchmarking::BenchmarkConfig - ) -> Result, alloc::string::String> { - use frame_benchmarking::{BenchmarkError, Benchmarking, BenchmarkBatch}; - - use frame_system_benchmarking::Pallet as SystemBench; - impl frame_system_benchmarking::Config for Runtime { - fn setup_set_code_requirements(code: &Vec) -> Result<(), BenchmarkError> { - ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32); - Ok(()) - } - - fn verify_set_code() { - System::assert_last_event(cumulus_pallet_parachain_system::Event::::ValidationFunctionStored.into()); - } - } - - use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - impl cumulus_pallet_session_benchmarking::Config for Runtime {} - - use frame_support::traits::WhitelistedStorageKeys; - let whitelist = AllPalletsWithSystem::whitelisted_storage_keys(); - - let mut batches = Vec::::new(); - let params = (&config, &whitelist); - add_benchmarks!(params, batches); - - if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } - Ok(batches) - } - } - - impl sp_genesis_builder::GenesisBuilder for Runtime { - fn build_state(config: Vec) -> sp_genesis_builder::Result { - build_state::(config) - } - - fn get_preset(id: &Option) -> Option> { - get_preset::(id, genesis::get_preset) - } - - fn preset_names() -> Vec { - genesis::presets() - } - } - - impl pallet_ismp_runtime_api::IsmpRuntimeApi::Hash> for Runtime { - fn host_state_machine() -> StateMachine { - ::HostStateMachine::get() - } - - fn challenge_period(id: StateMachineId) -> Option { - Ismp::challenge_period(id) - } - - /// Generate a proof for the provided leaf indices - fn generate_proof( - keys: ProofKeys - ) -> Result<(Vec, Proof<::Hash>), sp_mmr_primitives::Error> { - Ismp::generate_proof(keys) - } - - /// Fetch all ISMP events - fn block_events() -> Vec<::ismp::events::Event> { - Ismp::block_events() - } - - /// Fetch all ISMP events and their extrinsic metadata - fn block_events_with_metadata() -> Vec<(::ismp::events::Event, Option)> { - Ismp::block_events_with_metadata() - } - - /// Return the scale encoded consensus state - fn consensus_state(id: ConsensusClientId) -> Option> { - Ismp::consensus_states(id) - } - - /// Return the timestamp this client was last updated in seconds - fn state_machine_update_time(height: StateMachineHeight) -> Option { - Ismp::state_machine_update_time(height) - } - - /// Return the latest height of the state machine - fn latest_state_machine_height(id: StateMachineId) -> Option { - Ismp::latest_state_machine_height(id) - } - - /// Get actual requests - fn requests(commitments: Vec) -> Vec { - Ismp::requests(commitments) - } - - /// Get actual requests - fn responses(commitments: Vec) -> Vec { - Ismp::responses(commitments) - } - } - - impl ismp_parachain_runtime_api::IsmpParachainApi for Runtime { - fn para_ids() -> Vec { - IsmpParachain::para_ids() - } - - fn current_relay_chain_state() -> RelayChainState { - IsmpParachain::current_relay_chain_state() - } - } -} - #[docify::export(register_validate_block)] cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime,