From 0d5745354fbd76c0af9208bd14e2788b6a13a615 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Thu, 7 Sep 2023 18:32:55 +0100 Subject: [PATCH] move ismp config to file --- parachain/runtime/src/{router.rs => ismp.rs} | 68 +++++++++++++++- parachain/runtime/src/lib.rs | 81 +++---------------- .../runtime/src/{xcm_config.rs => xcm.rs} | 0 3 files changed, 75 insertions(+), 74 deletions(-) rename parachain/runtime/src/{router.rs => ismp.rs} (52%) rename parachain/runtime/src/{xcm_config.rs => xcm.rs} (100%) diff --git a/parachain/runtime/src/router.rs b/parachain/runtime/src/ismp.rs similarity index 52% rename from parachain/runtime/src/router.rs rename to parachain/runtime/src/ismp.rs index 349bbfabf..40340e48c 100644 --- a/parachain/runtime/src/router.rs +++ b/parachain/runtime/src/ismp.rs @@ -1,23 +1,83 @@ use crate::{ alloc::{boxed::Box, string::ToString}, - Runtime, StateMachineProvider, + AccountId, Balance, Balances, Ismp, IsmpParachain, ParachainInfo, Runtime, RuntimeEvent, + Timestamp, }; +use alloc::format; use frame_support::pallet_prelude::Get; +use frame_system::EnsureRoot; use ismp::{ + consensus::{ConsensusClient, ConsensusClientId}, error::Error, + host::StateMachine, module::IsmpModule, router::{IsmpRouter, Post, Request, Response}, }; -use pallet_ismp::primitives::ModuleId; + +use pallet_ismp::{ + host::Host, + primitives::{ConsensusClientProvider, ModuleId}, +}; use sp_std::prelude::*; #[derive(Default)] pub struct ProxyModule; +pub struct StateMachineProvider; + +impl Get for StateMachineProvider { + fn get() -> StateMachine { + StateMachine::Kusama(ParachainInfo::get().into()) + } +} + +pub struct ConsensusProvider; + +impl ConsensusClientProvider for ConsensusProvider { + fn consensus_client(id: ConsensusClientId) -> Result, Error> { + match id { + ismp_parachain::PARACHAIN_CONSENSUS_ID => { + let parachain = + ismp_parachain::ParachainConsensusClient::::default(); + Ok(Box::new(parachain)) + }, + ismp_sync_committee::BEACON_CONSENSUS_ID => { + let sync_committee = + ismp_sync_committee::SyncCommitteeConsensusClient::>::default(); + Ok(Box::new(sync_committee)) + }, + id => Err(Error::ImplementationSpecific(format!("Unknown consensus client: {id:?}")))?, + } + } +} + +impl ismp_parachain::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +impl pallet_ismp::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + const INDEXING_PREFIX: &'static [u8] = b"ISMP"; + type AdminOrigin = EnsureRoot; + type StateMachine = StateMachineProvider; + type TimeProvider = Timestamp; + type IsmpRouter = Router; + type ConsensusClientProvider = ConsensusProvider; + type WeightInfo = (); + type WeightProvider = (); +} + +impl ismp_demo::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type NativeCurrency = Balances; + type IsmpDispatcher = pallet_ismp::dispatcher::Dispatcher; +} + impl IsmpModule for ProxyModule { fn on_accept(&self, request: Post) -> Result<(), Error> { if request.dest != StateMachineProvider::get() { - return pallet_ismp::Pallet::::dispatch_request(Request::Post(request)) + return Ismp::dispatch_request(Request::Post(request)) } let pallet_id = ModuleId::from_bytes(&request.to) @@ -31,7 +91,7 @@ impl IsmpModule for ProxyModule { fn on_response(&self, response: Response) -> Result<(), Error> { if response.dest_chain() != StateMachineProvider::get() { - return pallet_ismp::Pallet::::dispatch_response(response) + return Ismp::dispatch_response(response) } let request = &response.request(); diff --git a/parachain/runtime/src/lib.rs b/parachain/runtime/src/lib.rs index bb6581401..07cf1f872 100644 --- a/parachain/runtime/src/lib.rs +++ b/parachain/runtime/src/lib.rs @@ -8,12 +8,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); extern crate alloc; - -mod router; +mod ismp; mod weights; -pub mod xcm_config; +pub mod xcm; -use alloc::format; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use scale_info::TypeInfo; @@ -32,11 +30,15 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; +use ::ismp::{ + consensus::{ConsensusClientId, StateMachineId}, + router::{Request, Response}, +}; use frame_support::{ construct_runtime, dispatch::DispatchClass, parameter_types, - traits::{ConstU32, ConstU64, ConstU8, Everything, Get}, + traits::{ConstU32, ConstU64, ConstU8, Everything}, weights::{ constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, @@ -47,23 +49,14 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, }; -use ismp::{ - consensus::{ConsensusClient, ConsensusClientId, StateMachineId}, - error::Error, - host::StateMachine, - router::{Request, Response}, -}; use ismp_primitives::{ mmr::{Leaf, LeafIndex}, LeafIndexQuery, }; -use pallet_ismp::{ - host::Host, - primitives::{ConsensusClientProvider, Proof}, -}; +use pallet_ismp::primitives::Proof; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; -use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; +use xcm::{XcmConfig, XcmOriginToTransactDispatchOrigin}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -74,8 +67,7 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; // XCM Imports -use crate::router::Router; -use xcm::latest::prelude::BodyId; +use ::xcm::latest::prelude::BodyId; use xcm_executor::XcmExecutor; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. @@ -484,57 +476,6 @@ impl pallet_sudo::Config for Runtime { type RuntimeCall = RuntimeCall; } -pub struct StateMachineProvider; - -impl Get for StateMachineProvider { - fn get() -> StateMachine { - StateMachine::Kusama(ParachainInfo::get().into()) - } -} - -pub struct ConsensusProvider; - -impl ConsensusClientProvider for ConsensusProvider { - fn consensus_client(id: ConsensusClientId) -> Result, Error> { - match id { - ismp_parachain::PARACHAIN_CONSENSUS_ID => { - let parachain = - ismp_parachain::ParachainConsensusClient::::default(); - Ok(Box::new(parachain)) - }, - ismp_sync_committee::BEACON_CONSENSUS_ID => { - let sync_committee = - ismp_sync_committee::SyncCommitteeConsensusClient::>::default(); - Ok(Box::new(sync_committee)) - }, - id => Err(Error::ImplementationSpecific(format!("Unknown consensus client: {id:?}")))?, - } - } -} - -impl ismp_parachain::Config for Runtime { - type RuntimeEvent = RuntimeEvent; -} - -impl pallet_ismp::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - const INDEXING_PREFIX: &'static [u8] = b"ISMP"; - type AdminOrigin = EnsureRoot; - type StateMachine = StateMachineProvider; - type TimeProvider = Timestamp; - type IsmpRouter = Router; - type ConsensusClientProvider = ConsensusProvider; - type WeightInfo = (); - type WeightProvider = (); -} - -impl ismp_demo::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type NativeCurrency = Balances; - type IsmpDispatcher = pallet_ismp::dispatcher::Dispatcher; -} - // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -805,7 +746,7 @@ impl_runtime_apis! { Ismp::get_responses(leaf_indices) } - fn pending_get_requests() -> Vec { + fn pending_get_requests() -> Vec<::ismp::router::Get> { Ismp::pending_get_requests() } } diff --git a/parachain/runtime/src/xcm_config.rs b/parachain/runtime/src/xcm.rs similarity index 100% rename from parachain/runtime/src/xcm_config.rs rename to parachain/runtime/src/xcm.rs