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