From 6617fc86d4c9ff21d5b749f1e6f23f9c86a40c10 Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Sat, 11 May 2024 08:52:40 +0200 Subject: [PATCH] Ismp crates.io (#120) * Ismp crates.io * working * clippy * fix tests * fix benchmarks * unrelated fixes * clippy * fmt --- .github/workflows/basic.yml | 2 +- Cargo.lock | 109 +++++++++++++++++++++---------- Cargo.toml | 15 ++--- pallets/regions/src/ismp_mock.rs | 21 +++--- pallets/regions/src/lib.rs | 18 ++--- pallets/regions/src/types.rs | 2 +- runtime/regionx/Cargo.toml | 19 +++--- runtime/regionx/src/ismp.rs | 88 ++++++------------------- runtime/regionx/src/lib.rs | 90 +++++++++---------------- 9 files changed, 167 insertions(+), 197 deletions(-) diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index f19c2460..93b8ed94 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -54,7 +54,7 @@ jobs: run: echo "CARGO_NET_GIT_FETCH_WITH_CLI=true" >> $GITHUB_ENV - name: Cargo clippy - run: cargo clippy -- -D warnings + run: cargo clippy --release -- -D warnings - name: Check Code run: cargo check diff --git a/Cargo.lock b/Cargo.lock index af84d3a3..a83ff03a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4172,8 +4172,23 @@ dependencies = [ [[package]] name = "ismp" -version = "0.1.0" -source = "git+https://github.com/Szegoo/hyperbridge.git?branch=fix-to-string#ff5e3878bdda2ed61a28c24811e6bb0ecf0ec5ed" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fccd6e0fc7610973a861881baefa0a9ebdb3ec500d9cd0a5c7a7374a410b046b" +dependencies = [ + "derive_more", + "hex", + "parity-scale-codec", + "primitive-types", + "scale-info", + "serde", + "serde_json", +] + +[[package]] +name = "ismp" +version = "0.1.2" +source = "git+https://github.com/polytope-labs/hyperbridge.git?branch=main#711fd0cd9676de88afa6d7c571a950494b90eaf1" dependencies = [ "derive_more", "hex", @@ -4186,15 +4201,17 @@ dependencies = [ [[package]] name = "ismp-parachain" -version = "0.1.0" -source = "git+https://github.com/Szegoo/hyperbridge.git?branch=fix-to-string#ff5e3878bdda2ed61a28c24811e6bb0ecf0ec5ed" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61338c0e24f1414bb90641ca18226ab59ec2479b3924dbb863a004f02f13594" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", "frame-support", "frame-system", "hex-literal", - "ismp", + "ismp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log", "pallet-ismp", "parity-scale-codec", "primitive-types", @@ -4210,16 +4227,19 @@ dependencies = [ [[package]] name = "ismp-parachain-inherent" -version = "0.1.0" -source = "git+https://github.com/Szegoo/hyperbridge.git?branch=fix-to-string#ff5e3878bdda2ed61a28c24811e6bb0ecf0ec5ed" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01640c48d57c367289df9d4e60ff838569ff7fd7efa7807f28fa0ec01eb6bf42" dependencies = [ "anyhow", "async-trait", "cumulus-primitives-core", "cumulus-relay-chain-interface", - "ismp", + "ismp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "ismp-parachain", "ismp-parachain-runtime-api", + "log", + "pallet-ismp-runtime-api", "parity-scale-codec", "sp-api", "sp-blockchain", @@ -4229,18 +4249,20 @@ dependencies = [ [[package]] name = "ismp-parachain-runtime-api" -version = "0.1.0" -source = "git+https://github.com/Szegoo/hyperbridge.git?branch=fix-to-string#ff5e3878bdda2ed61a28c24811e6bb0ecf0ec5ed" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a3a1e8c1c0e3b9a94577d192ffd16114e6db85762e5118a25f41f0e00aa3838" dependencies = [ + "cumulus-pallet-parachain-system", "sp-api", ] [[package]] name = "ismp-testsuite" -version = "0.1.0" -source = "git+https://github.com/Szegoo/hyperbridge.git?branch=fix-to-string#ff5e3878bdda2ed61a28c24811e6bb0ecf0ec5ed" +version = "0.1.1" +source = "git+https://github.com/polytope-labs/hyperbridge.git?branch=main#711fd0cd9676de88afa6d7c571a950494b90eaf1" dependencies = [ - "ismp", + "ismp 0.1.2 (git+https://github.com/polytope-labs/hyperbridge.git?branch=main)", "once_cell", "parity-scale-codec", "primitive-types", @@ -5369,6 +5391,25 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "mmr-primitives" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e06bd5ddfd3c7b75b99046e9d80d9b4f36a6ec84941c08a69a0b061dff37eea5" +dependencies = [ + "ckb-merkle-mountain-range", + "frame-system", + "ismp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-mmr-primitives", + "sp-runtime", + "sp-std", +] + [[package]] name = "mmr-rpc" version = "28.0.0" @@ -6535,42 +6576,41 @@ dependencies = [ [[package]] name = "pallet-ismp" -version = "0.1.0" -source = "git+https://github.com/Szegoo/hyperbridge.git?branch=fix-to-string#ff5e3878bdda2ed61a28c24811e6bb0ecf0ec5ed" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9946f35078ea0056dbe8e03f8bc8526668962b57f30fa5a5c2a7044370586c0a" dependencies = [ - "ckb-merkle-mountain-range", - "derive_more", - "enum-as-inner", "fortuples", "frame-benchmarking", "frame-support", "frame-system", - "ismp", + "ismp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log", - "pallet-balances", + "mmr-primitives", "parity-scale-codec", "scale-info", "serde", "sp-api", - "sp-consensus-aura", "sp-core", "sp-io", + "sp-mmr-primitives", "sp-runtime", "sp-std", ] [[package]] name = "pallet-ismp-runtime-api" -version = "0.1.0" -source = "git+https://github.com/Szegoo/hyperbridge.git?branch=fix-to-string#ff5e3878bdda2ed61a28c24811e6bb0ecf0ec5ed" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "810e0d1e115fdd0fe3fa35b0099006f03ce59dd2e0d4d7c765b5316bb01db4a0" dependencies = [ - "ismp", + "ismp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-ismp", "parity-scale-codec", + "primitive-types", "serde", "sp-api", - "sp-core", - "sp-std", + "sp-mmr-primitives", ] [[package]] @@ -6858,7 +6898,7 @@ dependencies = [ "frame-support", "frame-system", "hex", - "ismp", + "ismp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "ismp-parachain", "ismp-testsuite", "log", @@ -9435,8 +9475,7 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", - "hex-literal", - "ismp", + "ismp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "ismp-parachain", "ismp-parachain-runtime-api", "log", @@ -9486,6 +9525,7 @@ dependencies = [ "sp-core", "sp-genesis-builder", "sp-inherents", + "sp-mmr-primitives", "sp-offchain", "sp-runtime", "sp-session", @@ -12754,20 +12794,19 @@ dependencies = [ [[package]] name = "substrate-state-machine" -version = "0.1.0" -source = "git+https://github.com/Szegoo/hyperbridge.git?branch=fix-to-string#ff5e3878bdda2ed61a28c24811e6bb0ecf0ec5ed" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b4419938bb41e334beafd07ef3d9498e6da5ee18a4de478a5207b53433465db" dependencies = [ - "ckb-merkle-mountain-range", "frame-support", - "frame-system", "hash-db", - "ismp", + "ismp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "pallet-ismp", "parity-scale-codec", "primitive-types", "scale-info", "serde", - "sp-core", + "sp-consensus-aura", "sp-runtime", "sp-trie", ] diff --git a/Cargo.toml b/Cargo.toml index 62828d6b..3444d367 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,7 +101,6 @@ sp-keystore = { version = "0.34.0", default-features = false } sp-mmr-primitives = { version = "26.0.0", default-features = false } sp-storage = { version = "19.0.0", default-features = false } pallet-beefy-mmr = { version = "28.0.0", default-features = false } -pallet-mmr = { version = "27.0.0", default-features = false } # client frame-benchmarking-cli = "32.0.0" @@ -151,13 +150,13 @@ orml-unknown-tokens = { version = "0.7.0", default-features = false } orml-xcm-support = { version = "0.7.0", default-features = false } # Polytope Labs -ismp = { git="https://github.com/Szegoo/hyperbridge.git", branch="fix-to-string", default-features = false } -pallet-ismp = { git="https://github.com/Szegoo/hyperbridge.git", branch="fix-to-string", default-features = false } -ismp-parachain = { git="https://github.com/Szegoo/hyperbridge.git", branch="fix-to-string", default-features = false } -ismp-parachain-inherent = { git="https://github.com/Szegoo/hyperbridge.git", branch="fix-to-string", default-features = false } -pallet-ismp-runtime-api = { git="https://github.com/Szegoo/hyperbridge.git", branch="fix-to-string", default-features = false } -ismp-parachain-runtime-api = { git="https://github.com/Szegoo/hyperbridge.git", branch="fix-to-string", default-features = false } -ismp-testsuite = { git="https://github.com/Szegoo/hyperbridge.git", branch="fix-to-string", default-features = false } +ismp = { version = "0.1.2", default-features = false } +pallet-ismp = { version = "1.6.2", default-features = false } +ismp-parachain = { version = "1.6.2", default-features = false } +ismp-parachain-inherent = { version = "1.6.2", default-features = false } +pallet-ismp-runtime-api = { version = "1.6.2", default-features = false } +ismp-parachain-runtime-api = { version = "1.6.2", default-features = false } +ismp-testsuite = { git="https://github.com/polytope-labs/hyperbridge.git", branch="main", default-features = false } # Local regionx-primitives = { path = "./runtime/primitives", default-features = false } diff --git a/pallets/regions/src/ismp_mock.rs b/pallets/regions/src/ismp_mock.rs index 5160a0f7..ea282e42 100644 --- a/pallets/regions/src/ismp_mock.rs +++ b/pallets/regions/src/ismp_mock.rs @@ -14,11 +14,12 @@ // along with RegionX. If not, see . use ismp::{ + dispatcher::{DispatchRequest, FeeMetadata, IsmpDispatcher}, error::Error, - router::{DispatchRequest, Get as IsmpGet, IsmpDispatcher, PostResponse, Request}, + router::{Get as IsmpGet, PostResponse, Request}, }; use ismp_testsuite::mocks::Host; -use sp_core::Get; +use sp_core::{Get, H256}; use std::{cell::RefCell, marker::PhantomData, sync::Arc}; pub struct MockDispatcher(pub Arc, PhantomData); @@ -47,9 +48,8 @@ impl IsmpDispatcher for MockDispatcher { fn dispatch_request( &self, request: DispatchRequest, - who: Self::Account, - _fee: Self::Balance, - ) -> Result<(), Error> { + fee: FeeMetadata, + ) -> Result { let request = match request { DispatchRequest::Get(get) => Request::Get(IsmpGet { source: T::CoretimeChain::get(), @@ -65,19 +65,18 @@ impl IsmpDispatcher for MockDispatcher { REQUESTS.with(|requests| { let mut requests = requests.borrow_mut(); - requests.push(MockRequest { request, who }); + requests.push(MockRequest { request, who: fee.payer }); }); - Ok(()) + Ok(Default::default()) } fn dispatch_response( &self, _response: PostResponse, - _who: Self::Account, - _fee: Self::Balance, - ) -> Result<(), Error> { - Ok(()) + _fee: FeeMetadata, + ) -> Result { + Ok(Default::default()) } } diff --git a/pallets/regions/src/lib.rs b/pallets/regions/src/lib.rs index 15f0ff76..56c6deb6 100644 --- a/pallets/regions/src/lib.rs +++ b/pallets/regions/src/lib.rs @@ -17,18 +17,17 @@ use codec::{alloc::collections::BTreeMap, Decode}; use core::cmp::max; -use frame_support::PalletId; use ismp::{ consensus::StateMachineId, + dispatcher::{DispatchGet, DispatchRequest, FeeMetadata, IsmpDispatcher}, error::Error as IsmpError, host::StateMachine, module::IsmpModule, - router::{DispatchGet, DispatchRequest, IsmpDispatcher, Post, Request, Response, Timeout}, + router::{Post, Request, Response, Timeout}, }; use ismp_parachain::PARACHAIN_CONSENSUS_ID; pub use pallet::*; use pallet_broker::RegionId; -use pallet_ismp::primitives::ModuleId; use scale_info::prelude::{format, vec, vec::Vec}; use sp_runtime::traits::Zero; @@ -58,7 +57,7 @@ pub use weights::WeightInfo; const LOG_TARGET: &str = "runtime::regions"; /// Constant Pallet ID -pub const PALLET_ID: ModuleId = ModuleId::Pallet(PalletId(*b"region-p")); +pub const PALLET_ID: &[u8] = b"region-pallet"; #[frame_support::pallet] pub mod pallet { @@ -247,16 +246,19 @@ pub mod pallet { // TODO: should requests be coupled in the future? let get = DispatchGet { dest: T::CoretimeChain::get(), - from: PALLET_ID.to_bytes(), + from: PALLET_ID.into(), keys: vec![key], height: coretime_chain_height, - timeout_timestamp: T::Timeout::get(), + timeout: T::Timeout::get(), }; let dispatcher = T::IsmpDispatcher::default(); dispatcher - .dispatch_request(DispatchRequest::Get(get), who.clone(), Zero::zero()) + .dispatch_request( + DispatchRequest::Get(get), + FeeMetadata { payer: who.clone(), fee: Zero::zero() }, + ) .map_err(|_| Error::::IsmpDispatchError)?; Self::deposit_event(Event::RegionRecordRequested { region_id, account: who }); @@ -297,7 +299,7 @@ impl IsmpModule for IsmpModuleCallback { .map_err(|_| IsmpCustomError::DecodeFailed)?; crate::Pallet::::set_record(region_id, record) - .map_err(|e| IsmpError::ImplementationSpecific(format!("{:?}", e)))?; + .map_err(|e| IsmpError::Custom(format!("{:?}", e)))?; Ok(()) })?; diff --git a/pallets/regions/src/types.rs b/pallets/regions/src/types.rs index f1849fc6..21f1d47e 100644 --- a/pallets/regions/src/types.rs +++ b/pallets/regions/src/types.rs @@ -100,6 +100,6 @@ impl core::fmt::Display for IsmpCustomError { impl From for IsmpError { fn from(error: IsmpCustomError) -> Self { - IsmpError::ImplementationSpecific(format!("{}", error)) + IsmpError::Custom(format!("{}", error)) } } diff --git a/runtime/regionx/Cargo.toml b/runtime/regionx/Cargo.toml index 79951439..d267580e 100644 --- a/runtime/regionx/Cargo.toml +++ b/runtime/regionx/Cargo.toml @@ -14,7 +14,6 @@ substrate-wasm-builder = { workspace = true } [dependencies] codec = { workspace = true } -hex-literal = { workspace = true, optional = true } log = { workspace = true } scale-info = { workspace = true } smallvec = { workspace = true } @@ -24,11 +23,11 @@ regionx-primitives = { workspace = true, default-features = false } pallet-regions = { workspace = true, default-features = false } # Polytope Labs -ismp = { workspace = true, default-features = false } -pallet-ismp = { workspace = true, default-features = false } -ismp-parachain = { workspace = true, default-features = false } -pallet-ismp-runtime-api = { workspace = true, default-features = false } -ismp-parachain-runtime-api = { workspace = true, default-features = false } +ismp = { workspace = true } +pallet-ismp = { workspace = true, features = ["unsigned"] } +ismp-parachain = { workspace = true } +pallet-ismp-runtime-api = { workspace = true } +ismp-parachain-runtime-api = { workspace = true } # Orml orml-asset-registry = { workspace = true } @@ -80,6 +79,7 @@ sp-session = { workspace = true } sp-std = { workspace = true } sp-transaction-pool = { workspace = true } sp-version = { workspace = true } +sp-mmr-primitives = { workspace = true } # Polkadot pallet-xcm = { workspace = true } @@ -179,6 +179,7 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", + "sp-mmr-primitives/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", @@ -195,7 +196,6 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", - "hex-literal", "orml-asset-registry/runtime-benchmarks", "orml-tokens/runtime-benchmarks", "pallet-asset-rate/runtime-benchmarks", @@ -210,6 +210,7 @@ runtime-benchmarks = [ "pallet-proxy/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-regions/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", @@ -238,6 +239,7 @@ try-runtime = [ "orml-asset-registry/try-runtime", "orml-currencies/try-runtime", "orml-tokens/try-runtime", + "orml-unknown-tokens/try-runtime", "pallet-ismp/try-runtime", "ismp-parachain/try-runtime", "pallet-aura/try-runtime", @@ -248,12 +250,13 @@ try-runtime = [ "pallet-collective/try-runtime", "pallet-conviction-voting/try-runtime", "pallet-collator-selection/try-runtime", - "pallet-membership/std", + "pallet-membership/try-runtime", "pallet-message-queue/try-runtime", "pallet-multisig/try-runtime", "pallet-proxy/try-runtime", "pallet-preimage/try-runtime", "pallet-regions/try-runtime", + "pallet-referenda/try-runtime", "pallet-session/try-runtime", "pallet-sudo/try-runtime", "pallet-scheduler/try-runtime", diff --git a/runtime/regionx/src/ismp.rs b/runtime/regionx/src/ismp.rs index 914651d7..3d922687 100644 --- a/runtime/regionx/src/ismp.rs +++ b/runtime/regionx/src/ismp.rs @@ -15,17 +15,15 @@ #[cfg(not(feature = "std"))] use crate::alloc::string::ToString; -use crate::{AccountId, Ismp, IsmpParachain, ParachainInfo, Runtime, RuntimeEvent, Timestamp}; +use crate::{ + AccountId, Balance, Balances, Ismp, IsmpParachain, ParachainInfo, Runtime, RuntimeEvent, + Timestamp, +}; use frame_support::pallet_prelude::Get; use frame_system::EnsureRoot; -use ismp::{ - error::Error, - host::StateMachine, - module::IsmpModule, - router::{IsmpRouter, Post, Request, Response, Timeout}, -}; +use ismp::{error::Error, host::StateMachine, module::IsmpModule, router::IsmpRouter}; use ismp_parachain::ParachainConsensusClient; -use pallet_ismp::{dispatcher::FeeMetadata, primitives::ModuleId}; +use pallet_ismp::NoOpMmrTree; use sp_std::prelude::*; pub struct HostStateMachine; @@ -39,83 +37,39 @@ pub struct Coprocessor; impl Get> for Coprocessor { fn get() -> Option { - Some(HostStateMachine::get()) + None } } impl ismp_parachain::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type IsmpHost = Ismp; } impl pallet_ismp::Config for Runtime { type RuntimeEvent = RuntimeEvent; - const INDEXING_PREFIX: &'static [u8] = b"ISMP"; type AdminOrigin = EnsureRoot; type HostStateMachine = HostStateMachine; - type Coprocessor = Coprocessor; - type TimeProvider = Timestamp; + type TimestampProvider = Timestamp; type Router = Router; + type Balance = Balance; + type Currency = Balances; + type Coprocessor = Coprocessor; type ConsensusClients = (ParachainConsensusClient,); - type WeightProvider = (); -} - -#[derive(Default)] -pub struct ProxyModule; - -impl IsmpModule for ProxyModule { - fn on_accept(&self, _request: Post) -> Result<(), Error> { - // we don't support any incoming post requests. - Err(Error::CannotHandleMessage) - } - - fn on_response(&self, response: Response) -> Result<(), Error> { - if response.dest_chain() != HostStateMachine::get() { - let meta = FeeMetadata { origin: [0u8; 32].into(), fee: Default::default() }; - return Ismp::dispatch_response(response, meta); - } - - let request = &response.request(); - let from = match &request { - Request::Post(post) => &post.from, - Request::Get(get) => &get.from, - }; - let pallet_id = ModuleId::from_bytes(from) - .map_err(|err| Error::ImplementationSpecific(err.to_string()))?; - - #[allow(clippy::match_single_binding)] - match pallet_id { - pallet_regions::PALLET_ID => - pallet_regions::IsmpModuleCallback::::default().on_response(response), - _ => Err(Error::ImplementationSpecific("Destination module not found".to_string())), - } - } - - fn on_timeout(&self, timeout: Timeout) -> Result<(), Error> { - let from = match &timeout { - Timeout::Request(Request::Post(post)) => &post.from, - Timeout::Request(Request::Get(get)) => &get.from, - Timeout::Response(res) => &res.post.to, - }; - - let pallet_id = ModuleId::from_bytes(from) - .map_err(|err| Error::ImplementationSpecific(err.to_string()))?; - - #[allow(clippy::match_single_binding)] - match pallet_id { - pallet_regions::PALLET_ID => - pallet_regions::IsmpModuleCallback::::default().on_timeout(timeout), - // instead of returning an error, do nothing. The timeout is for a connected chain. - _ => Ok(()), - } - } + type Mmr = NoOpMmrTree; + type WeightProvider = (); } #[derive(Default)] pub struct Router; - impl IsmpRouter for Router { - fn module_for_id(&self, _bytes: Vec) -> Result, Error> { - Ok(Box::new(ProxyModule)) + fn module_for_id(&self, id: Vec) -> Result, Error> { + let module = match id.as_slice() { + pallet_regions::PALLET_ID => + Box::>::default(), + _ => Err(Error::ModuleNotFound(id))?, + }; + Ok(module) } } diff --git a/runtime/regionx/src/lib.rs b/runtime/regionx/src/lib.rs index 24173b47..5a8c40a6 100644 --- a/runtime/regionx/src/lib.rs +++ b/runtime/regionx/src/lib.rs @@ -38,7 +38,7 @@ mod ismp; use impls::*; -use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_pallet_parachain_system::{RelayChainState, RelayNumberStrictlyIncreases}; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::traits::{ fungible::HoldConsideration, @@ -50,7 +50,7 @@ use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use smallvec::smallvec; use sp_api::impl_runtime_apis; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; +use sp_core::{crypto::KeyTypeId, Get, OpaqueMetadata}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, IdentityLookup}, @@ -82,17 +82,12 @@ use frame_support::{ }; use frame_system::{ limits::{BlockLength, BlockWeights}, - EnsureRoot, Phase, + EnsureRoot, }; use orml_currencies::BasicCurrencyAdapter; use orml_tokens::CurrencyAdapter; use pallet_asset_tx_payment::FungiblesAdapter; -use pallet_ismp::{ - dispatcher::Dispatcher, - mmr::primitives::{Leaf, LeafIndex}, - primitives::Proof, - ProofKeys, -}; +use pallet_ismp::mmr::{Leaf, Proof, ProofKeys}; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::H256; @@ -602,7 +597,7 @@ impl pallet_collator_selection::Config for Runtime { pub struct StateMachineHeightProvider; impl StateMachineHeightProviderT for StateMachineHeightProvider { fn get_latest_state_machine_height(id: StateMachineId) -> u64 { - Ismp::latest_state_height(id) + Ismp::latest_state_machine_height(id).unwrap_or(0) // TODO } } @@ -615,7 +610,7 @@ impl pallet_regions::Config for Runtime { type Balance = Balance; type NativeCurrency = Balances; type CoretimeChain = CoretimeChain; - type IsmpDispatcher = Dispatcher; + type IsmpDispatcher = Ismp; type StateMachineHeightProvider = StateMachineHeightProvider; type Timeout = ConstU64<1000>; // TODO: FIXME type WeightInfo = (); @@ -830,6 +825,13 @@ mod benches { [pallet_collator_selection, CollatorSelection] [cumulus_pallet_xcmp_queue, XcmpQueue] [pallet_regions, Regions] + [pallet_referenda, NativeReferenda] + [pallet_referenda, DelegatedReferenda] + [pallet_conviction_voting, NativeConvictionVoting] + [pallet_conviction_voting, DelegatedConvictionVoting] + [pallet_collective, GeneralCouncil] + [pallet_collective, TechnicalCommittee] + [pallet_whitelist, Whitelist] ); } @@ -978,61 +980,29 @@ impl_runtime_apis! { } impl pallet_ismp_runtime_api::IsmpRuntimeApi::Hash> for Runtime { - /// Return the number of MMR leaves. - fn mmr_leaf_count() -> Result { - Ok(Ismp::mmr_leaf_count()) - } - - /// Return the on-chain MMR root hash. - fn mmr_root() -> Result<::Hash, pallet_ismp::primitives::Error> { - Ok(Ismp::mmr_root()) + fn host_state_machine() -> StateMachine { + ::HostStateMachine::get() } fn challenge_period(consensus_state_id: [u8; 4]) -> Option { - Ismp::get_challenge_period(consensus_state_id) + Ismp::challenge_period(consensus_state_id) } /// Generate a proof for the provided leaf indices fn generate_proof( keys: ProofKeys - ) -> Result<(Vec, Proof<::Hash>), pallet_ismp::primitives::Error> { + ) -> Result<(Vec, Proof<::Hash>), sp_mmr_primitives::Error> { Ismp::generate_proof(keys) } - /// Fetch all ISMP events - fn block_events() -> Vec { - let raw_events = frame_system::Pallet::::read_events_no_consensus(); - raw_events.filter_map(|e| { - let frame_system::EventRecord{ event, ..} = *e; - - match event { - RuntimeEvent::Ismp(event) => { - pallet_ismp::events::to_core_protocol_event(event) - }, - _ => None - } - }).collect() + /// Fetch all ISMP events and their extrinsic metadata + fn block_events_with_metadata() -> Vec<(::ismp::events::Event, u32)> { + Ismp::block_events_with_metadata() } - /// Fetch all ISMP events and their extrinsic metadata - fn block_events_with_metadata() -> Vec<(pallet_ismp::events::Event, u32)> { - let raw_events = frame_system::Pallet::::read_events_no_consensus(); - raw_events.filter_map(|e| { - let frame_system::EventRecord { event, phase, ..} = *e; - let Phase::ApplyExtrinsic(index) = phase else { - unreachable!("ISMP events are always dispatched by extrinsics"); - }; - - match event { - RuntimeEvent::Ismp(event) => { - pallet_ismp::events::to_core_protocol_event(event) - .map(|event| { - (event, index) - }) - }, - _ => None - } - }).collect() + /// Fetch all ISMP events + fn block_events() -> Vec<::ismp::events::Event> { + Ismp::block_events() } /// Return the scale encoded consensus state @@ -1047,17 +1017,17 @@ impl_runtime_apis! { /// Return the latest height of the state machine fn latest_state_machine_height(id: StateMachineId) -> Option { - Ismp::get_latest_state_machine_height(id) + Ismp::latest_state_machine_height(id) } /// Get actual requests - fn get_requests(commitments: Vec) -> Vec { - Ismp::get_requests(commitments) + fn requests(commitments: Vec) -> Vec { + Ismp::requests(commitments) } /// Get actual requests - fn get_responses(commitments: Vec) -> Vec { - Ismp::get_responses(commitments) + fn responses(commitments: Vec) -> Vec { + Ismp::responses(commitments) } } @@ -1065,6 +1035,10 @@ impl_runtime_apis! { fn para_ids() -> Vec { IsmpParachain::para_ids() } + + fn current_relay_chain_state() -> RelayChainState { + IsmpParachain::current_relay_chain_state() + } } #[cfg(feature = "try-runtime")]