Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ismp crates.io #120

Merged
merged 8 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
109 changes: 74 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 }
Expand Down
21 changes: 10 additions & 11 deletions pallets/regions/src/ismp_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
// along with RegionX. If not, see <https://www.gnu.org/licenses/>.

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<T: crate::Config>(pub Arc<Host>, PhantomData<T>);
Expand Down Expand Up @@ -47,9 +48,8 @@ impl<T: crate::Config> IsmpDispatcher for MockDispatcher<T> {
fn dispatch_request(
&self,
request: DispatchRequest,
who: Self::Account,
_fee: Self::Balance,
) -> Result<(), Error> {
fee: FeeMetadata<Self::Account, Self::Balance>,
) -> Result<H256, Error> {
let request = match request {
DispatchRequest::Get(get) => Request::Get(IsmpGet {
source: T::CoretimeChain::get(),
Expand All @@ -65,19 +65,18 @@ impl<T: crate::Config> IsmpDispatcher for MockDispatcher<T> {

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<Self::Account, Self::Balance>,
) -> Result<H256, Error> {
Ok(Default::default())
}
}

Expand Down
18 changes: 10 additions & 8 deletions pallets/regions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<T>::IsmpDispatchError)?;

Self::deposit_event(Event::RegionRecordRequested { region_id, account: who });
Expand Down Expand Up @@ -297,7 +299,7 @@ impl<T: Config> IsmpModule for IsmpModuleCallback<T> {
.map_err(|_| IsmpCustomError::DecodeFailed)?;

crate::Pallet::<T>::set_record(region_id, record)
.map_err(|e| IsmpError::ImplementationSpecific(format!("{:?}", e)))?;
.map_err(|e| IsmpError::Custom(format!("{:?}", e)))?;

Ok(())
})?;
Expand Down
2 changes: 1 addition & 1 deletion pallets/regions/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ impl core::fmt::Display for IsmpCustomError {

impl From<IsmpCustomError> for IsmpError {
fn from(error: IsmpCustomError) -> Self {
IsmpError::ImplementationSpecific(format!("{}", error))
IsmpError::Custom(format!("{}", error))
}
}
Loading
Loading