Skip to content

chore(messaging): pop-api and integration tests #566

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

Open
wants to merge 16 commits into
base: messaging-base
Choose a base branch
from
1,727 changes: 1,230 additions & 497 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ repository = "https://github.com/r0gue-io/pop-node/"
[workspace]
exclude = [
"extension/contract",
"integration-tests",
"pop-api",
"tests/contracts",
"integration-tests",
]
members = [
"node",
"pallets/*",
#"pop-api/integration-tests",
"pop-api/integration-tests",
"primitives",
"runtime/devnet",
"runtime/mainnet",
Expand Down Expand Up @@ -148,8 +148,8 @@ sp-session = { git = "https://github.com/paritytech/polkadot-sdk", branch = "sta
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412" }
sp-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
sp-weights = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
sp-weights = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412" }

# Polkadot
Expand Down
4 changes: 2 additions & 2 deletions pallets/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ frame-support.workspace = true
frame-system.workspace = true
pallet-assets.workspace = true
pallet-balances.workspace = true
pallet-timestamp.workspace = true
pallet-nfts.workspace = true
pallet-timestamp.workspace = true
sp-core.workspace = true
sp-io.workspace = true
sp-runtime.workspace = true
Expand Down Expand Up @@ -75,7 +75,7 @@ std = [
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"xcm-builder/std"
"xcm-builder/std",
]
try-runtime = [
"frame-support/try-runtime",
Expand Down
20 changes: 17 additions & 3 deletions pallets/api/src/messaging/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Benchmarking setup for pallet_api::messaging
#![cfg(feature = "runtime-benchmarks")]

Check warning on line 2 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

duplicated attribute

warning: duplicated attribute --> pallets/api/src/messaging/benchmarking.rs:2:8 | 2 | #![cfg(feature = "runtime-benchmarks")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first defined here --> pallets/api/src/messaging/mod.rs:38:7 | 38 | #[cfg(feature = "runtime-benchmarks")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute --> pallets/api/src/messaging/benchmarking.rs:2:8 | 2 | #![cfg(feature = "runtime-benchmarks")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes = note: `#[warn(clippy::duplicated_attributes)]` on by default

use ::ismp::{
messaging::hash_request,
Expand Down Expand Up @@ -29,10 +29,10 @@
frame_system::Pallet::<T>::assert_has_event(generic_event.into());
}

#[benchmarks(
where
T: pallet_balances::Config + pallet_timestamp::Config,
)]

Check warning on line 35 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

bound is defined in more than one place

warning: bound is defined in more than one place --> pallets/api/src/messaging/benchmarking.rs:32:1 | 32 | / #[benchmarks( 33 | | where 34 | | T: pallet_balances::Config + pallet_timestamp::Config, | | ^ 35 | | )] | |__^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations = note: `#[warn(clippy::multiple_bound_locations)]` on by default = note: this warning originates in the attribute macro `benchmarks` (in Nightly builds, run with -Z macro-backtrace for more info)
mod messaging_benchmarks {
use super::*;

Expand All @@ -57,13 +57,13 @@

// Timeout messages release callback deposit hence, are most expensive case for now.
let good_message = Message::IsmpTimeout {
commitment: commitment.clone(),

Check warning on line 60 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `H256` which implements the `Copy` trait

warning: using `clone` on type `H256` which implements the `Copy` trait --> pallets/api/src/messaging/benchmarking.rs:60:17 | 60 | commitment: commitment.clone(), | ^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `commitment` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy = note: `#[warn(clippy::clone_on_copy)]` on by default
message_deposit,
callback_deposit: Some(callback_deposit),
};

Messages::<T>::insert(&owner, &message_id.0, &good_message);

Check warning on line 65 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/api/src/messaging/benchmarking.rs:65:34 | 65 | Messages::<T>::insert(&owner, &message_id.0, &good_message); | ^^^^^^^^^^^^^ help: change this to: `message_id.0` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
IsmpRequests::<T>::insert(&commitment, (&owner, &message_id.0));

Check warning on line 66 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/api/src/messaging/benchmarking.rs:66:30 | 66 | IsmpRequests::<T>::insert(&commitment, (&owner, &message_id.0)); | ^^^^^^^^^^^ help: change this to: `commitment` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
message_ids.try_push(message_id.0).unwrap();
}
#[extrinsic_call]
Expand Down Expand Up @@ -102,10 +102,10 @@
#[extrinsic_call]
Pallet::<T>::xcm_new_query(
RawOrigin::Signed(owner.clone()),
message_id.clone(),

Check warning on line 105 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `[u8; 32]` which implements the `Copy` trait

warning: using `clone` on type `[u8; 32]` which implements the `Copy` trait --> pallets/api/src/messaging/benchmarking.rs:105:4 | 105 | message_id.clone(), | ^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `message_id` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
responder.clone(),
timeout,
callback.clone(),

Check warning on line 108 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `Option<Callback>` which implements the `Copy` trait

warning: using `clone` on type `Option<Callback>` which implements the `Copy` trait --> pallets/api/src/messaging/benchmarking.rs:108:4 | 108 | callback.clone(), | ^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `callback` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
);

assert_has_event::<T>(
Expand Down Expand Up @@ -146,7 +146,7 @@
message_id,
responder.clone(),
timeout,
callback.clone(),

Check warning on line 149 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `Option<Callback>` which implements the `Copy` trait

warning: using `clone` on type `Option<Callback>` which implements the `Copy` trait --> pallets/api/src/messaging/benchmarking.rs:149:4 | 149 | callback.clone(), | ^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `callback` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
)
.unwrap();

Expand Down Expand Up @@ -240,8 +240,8 @@

let message = Message::Ismp { commitment, callback, message_deposit };

IsmpRequests::<T>::insert(&commitment, (&origin, &message_id));

Check warning on line 243 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/api/src/messaging/benchmarking.rs:243:29 | 243 | IsmpRequests::<T>::insert(&commitment, (&origin, &message_id)); | ^^^^^^^^^^^ help: change this to: `commitment` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
Messages::<T>::insert(&origin, &message_id, &message);

Check warning on line 244 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/api/src/messaging/benchmarking.rs:244:34 | 244 | Messages::<T>::insert(&origin, &message_id, &message); | ^^^^^^^^^^^ help: change this to: `message_id` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

let handler = crate::messaging::ismp::Handler::<T>::new();

Expand Down Expand Up @@ -299,8 +299,8 @@

let input_message = Message::Ismp { commitment, callback, message_deposit: One::one() };

IsmpRequests::<T>::insert(&commitment, (&origin, &message_id));

Check warning on line 302 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/api/src/messaging/benchmarking.rs:302:29 | 302 | IsmpRequests::<T>::insert(&commitment, (&origin, &message_id)); | ^^^^^^^^^^^ help: change this to: `commitment` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
Messages::<T>::insert(&origin, &message_id, &input_message);

Check warning on line 303 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> pallets/api/src/messaging/benchmarking.rs:303:34 | 303 | Messages::<T>::insert(&origin, &message_id, &input_message); | ^^^^^^^^^^^ help: change this to: `message_id` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

let handler = crate::messaging::ismp::Handler::<T>::new();
#[block]
Expand Down Expand Up @@ -329,9 +329,10 @@
let id_data = (x, y, a, "ismp_get");
let encoded = id_data.encode();
let message_id = H256::from(blake2_256(&encoded));
let ismp_relayer_fee: BalanceOf<T> = u32::MAX.into();

let inner_keys: BoundedVec<u8, T::MaxKeyLen> =
vec![1u8].repeat(T::MaxKeyLen::get() as usize).try_into().unwrap();

Check warning on line 335 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

useless use of `vec!`

warning: useless use of `vec!` --> pallets/api/src/messaging/benchmarking.rs:335:4 | 335 | vec![1u8].repeat(T::MaxKeyLen::get() as usize).try_into().unwrap(); | ^^^^^^^^^ help: you can use an array directly: `[1u8]` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec = note: `#[warn(clippy::useless_vec)]` on by default

let mut outer_keys = vec![];
for _ in 0..y {
Expand All @@ -352,7 +353,7 @@
dest: 2000,
height: 100_000,
timeout: 100_000,
context: vec![1u8].repeat(x as usize).try_into().unwrap(),

Check warning on line 356 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

useless use of `vec!`

warning: useless use of `vec!` --> pallets/api/src/messaging/benchmarking.rs:356:13 | 356 | context: vec![1u8].repeat(x as usize).try_into().unwrap(), | ^^^^^^^^^ help: you can use an array directly: `[1u8]` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec
keys: outer_keys.try_into().unwrap(),
};

Expand All @@ -362,7 +363,13 @@
);

#[extrinsic_call]
Pallet::<T>::ismp_get(RawOrigin::Signed(origin.clone()), message_id.into(), get, callback);
Pallet::<T>::ismp_get(
RawOrigin::Signed(origin.clone()),
message_id.into(),
get,
ismp_relayer_fee,
callback,
);
}

/// Sends a `Post` request using ISMP with a variable-sized data payload.
Expand All @@ -380,8 +387,9 @@
let id_data = (x, y, b"ismp_post");
let encoded = id_data.encode();
let message_id = H256::from(blake2_256(&encoded));
let ismp_relayer_fee: BalanceOf<T> = u32::MAX.into();

let data = vec![1u8].repeat(x as usize).try_into().unwrap();

Check warning on line 392 in pallets/api/src/messaging/benchmarking.rs

View workflow job for this annotation

GitHub Actions / clippy

useless use of `vec!`

warning: useless use of `vec!` --> pallets/api/src/messaging/benchmarking.rs:392:14 | 392 | let data = vec![1u8].repeat(x as usize).try_into().unwrap(); | ^^^^^^^^^ help: you can use an array directly: `[1u8]` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec

let get = crate::messaging::ismp::Post::<T> { dest: 2000, timeout: 100_000, data };

Expand All @@ -402,7 +410,13 @@
);

#[extrinsic_call]
Pallet::<T>::ismp_post(RawOrigin::Signed(origin.clone()), message_id.into(), get, callback);
Pallet::<T>::ismp_post(
RawOrigin::Signed(origin.clone()),
message_id.into(),
get,
ismp_relayer_fee,
callback,
);
}

/// Tops up callback weight for callback execution of pending messages.
Expand All @@ -416,7 +430,7 @@

let message: Message<T> = Message::Ismp {
commitment: [10u8; 32].into(),
deposit: 100_000u32.into(),
message_deposit: 100_000u32.into(),
callback: Some(callback),
};

Expand Down
9 changes: 4 additions & 5 deletions pallets/api/src/messaging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
type BalanceOf<T> = <<T as Config>::Fungibles as Inspect<AccountIdOf<T>>>::Balance;
type DbWeightOf<T> = <T as frame_system::Config>::DbWeight;

pub type MessageId = [u8; 32];

Check warning on line 62 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a type alias

warning: missing documentation for a type alias --> pallets/api/src/messaging/mod.rs:62:1 | 62 | pub type MessageId = [u8; 32]; | ^^^^^^^^^^^^^^^^^^

#[frame_support::pallet]
pub mod pallet {
Expand All @@ -72,7 +72,7 @@
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

type OriginConverter: TryConvert<Self::RuntimeOrigin, Location>;

Check warning on line 75 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an associated type

warning: missing documentation for an associated type --> pallets/api/src/messaging/mod.rs:75:3 | 75 | type OriginConverter: TryConvert<Self::RuntimeOrigin, Location>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/// The base byte fee for data stored onchain.
#[pallet::constant]
Expand Down Expand Up @@ -139,9 +139,6 @@
/// payment.
type WeightToFee: WeightToFee<Balance = BalanceOf<Self>>;

/// The fee paid to the relayers account for relaying a message.
type IsmpRelayerFee: Get<BalanceOf<Self>>;

/// The implementation of Keccak used for commitment hashes.
type Keccak256: ::ismp::messaging::Keccak256;

Expand Down Expand Up @@ -274,13 +271,13 @@
messages: Vec<MessageId>,
},
/// An ISMP message has timed out.
IsmpTimedOut { commitment: H256 },

Check warning on line 274 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> pallets/api/src/messaging/mod.rs:274:18 | 274 | IsmpTimedOut { commitment: H256 }, | ^^^^^^^^^^^^^^^^
/// A collection of xcm queries have timed out.
XcmQueriesTimedOut { query_ids: Vec<QueryId> },

Check warning on line 276 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> pallets/api/src/messaging/mod.rs:276:24 | 276 | XcmQueriesTimedOut { query_ids: Vec<QueryId> }, | ^^^^^^^^^^^^^^^^^^^^^^^
/// An error has occured while attempting to refund weight.
WeightRefundErrored { message_id: MessageId, error: DispatchError },

Check warning on line 278 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> pallets/api/src/messaging/mod.rs:278:48 | 278 | WeightRefundErrored { message_id: MessageId, error: DispatchError }, | ^^^^^^^^^^^^^^^^^^^^

Check warning on line 278 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> pallets/api/src/messaging/mod.rs:278:25 | 278 | WeightRefundErrored { message_id: MessageId, error: DispatchError }, | ^^^^^^^^^^^^^^^^^^^^^
/// Callback gas has been topped up.
CallbackGasIncreased { message_id: MessageId, total_weight: Weight },

Check warning on line 280 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> pallets/api/src/messaging/mod.rs:280:49 | 280 | CallbackGasIncreased { message_id: MessageId, total_weight: Weight }, | ^^^^^^^^^^^^^^^^^^^^

Check warning on line 280 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> pallets/api/src/messaging/mod.rs:280:26 | 280 | CallbackGasIncreased { message_id: MessageId, total_weight: Weight }, | ^^^^^^^^^^^^^^^^^^^^^
}

#[pallet::error]
Expand Down Expand Up @@ -322,7 +319,7 @@
#[codec(index = 0)]
Messaging,
#[codec(index = 1)]
CallbackGas,

Check warning on line 322 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:322:3 | 322 | CallbackGas, | ^^^^^^^^^^^
}

#[pallet::hooks]
Expand Down Expand Up @@ -383,6 +380,7 @@
origin: OriginFor<T>,
id: MessageId,
message: ismp::Get<T>,
ismp_relayer_fee: BalanceOf<T>,
callback: Option<Callback>,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
Expand All @@ -408,7 +406,7 @@
// Process message by dispatching request via ISMP.
let commitment = match T::IsmpDispatcher::default().dispatch_request(
message.into(),
FeeMetadata { payer: origin.clone(), fee: T::IsmpRelayerFee::get() },
FeeMetadata { payer: origin.clone(), fee: ismp_relayer_fee },
) {
Ok(commitment) => Ok::<H256, DispatchError>(commitment),
Err(e) => {
Expand Down Expand Up @@ -454,6 +452,7 @@
origin: OriginFor<T>,
id: MessageId,
message: ismp::Post<T>,
ismp_relayer_fee: BalanceOf<T>,
callback: Option<Callback>,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
Expand All @@ -480,7 +479,7 @@
let commitment = T::IsmpDispatcher::default()
.dispatch_request(
message.into(),
FeeMetadata { payer: origin.clone(), fee: T::IsmpRelayerFee::get() },
FeeMetadata { payer: origin.clone(), fee: ismp_relayer_fee },
)
.map_err(|_| Error::<T>::IsmpDispatchFailed)?;

Expand Down Expand Up @@ -683,7 +682,7 @@

/// Remove a batch of completed or timed-out messages.
///
/// Allows users to clean up storage and reclaim deposits for messages that have concluded.

Check warning on line 685 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `()`

warning: useless conversion to the same type: `()` --> pallets/api/src/messaging/mod.rs:685:7 | 685 | Ok(().into()) | ^^^^^^^^^ help: consider removing `.into()`: `()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
///
/// # Parameters
/// - `origin`: The account removing the messages.
Expand Down Expand Up @@ -1029,25 +1028,25 @@
Fortitude::Polite,
)?;

// Handle assets.

Check warning on line 1031 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an enum

warning: missing documentation for an enum --> pallets/api/src/messaging/mod.rs:1031:1 | 1031 | pub enum Read<T: Config> { | ^^^^^^^^^^^^^^^^^^^^^^^^
T::FeeHandler::on_unbalanced(credit);
Ok(())

Check warning on line 1033 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1033:2 | 1033 | PollStatus((T::AccountId, MessageId)), | ^^^^^^^^^^
}
}

Check warning on line 1035 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1035:2 | 1035 | GetResponse((T::AccountId, MessageId)), | ^^^^^^^^^^^
}
#[derive(Encode, Decode, Debug, MaxEncodedLen)]

Check warning on line 1037 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1037:2 | 1037 | QueryId((T::AccountId, MessageId)), | ^^^^^^^
#[cfg_attr(feature = "std", derive(PartialEq, Clone))]
#[repr(u8)]
#[allow(clippy::unnecessary_cast)]
pub enum Read<T: Config> {
#[codec(index = 0)]

Check warning on line 1042 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an enum

warning: missing documentation for an enum --> pallets/api/src/messaging/mod.rs:1042:1 | 1042 | pub enum ReadResult { | ^^^^^^^^^^^^^^^^^^^
PollStatus((T::AccountId, MessageId)),

Check warning on line 1043 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1043:2 | 1043 | Poll(Option<MessageStatus>), | ^^^^
#[codec(index = 1)]

Check warning on line 1044 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1044:2 | 1044 | Get(Option<Vec<u8>>), | ^^^
GetResponse((T::AccountId, MessageId)),

Check warning on line 1045 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1045:2 | 1045 | QueryId(Option<QueryId>), | ^^^^^^^
#[codec(index = 2)]
QueryId((T::AccountId, MessageId)),
}

Check warning on line 1049 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a method

warning: missing documentation for a method --> pallets/api/src/messaging/mod.rs:1049:2 | 1049 | pub fn encode(&self) -> Vec<u8> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#[derive(Debug)]
#[cfg_attr(feature = "std", derive(PartialEq, Clone))]
pub enum ReadResult {
Expand Down Expand Up @@ -1176,18 +1175,18 @@
Message::Ismp { .. } => MessageStatus::Pending,
Message::XcmQuery { .. } => MessageStatus::Pending,
Message::IsmpResponse { .. } => MessageStatus::Complete,
Message::XcmResponse { .. } => MessageStatus::Complete,

Check warning on line 1178 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1178:2 | 1178 | Pending, | ^^^^^^^
Message::IsmpTimeout { .. } => MessageStatus::Timeout,

Check warning on line 1179 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1179:2 | 1179 | Complete, | ^^^^^^^^
Message::XcmTimeout { .. } => MessageStatus::Timeout,

Check warning on line 1180 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1180:2 | 1180 | Timeout, | ^^^^^^^
}
}
}

/// The related message status of a Message.
#[derive(Clone, Debug, Encode, Eq, Decode, MaxEncodedLen, PartialEq, TypeInfo)]
pub enum MessageStatus {

Check warning on line 1187 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> pallets/api/src/messaging/mod.rs:1187:2 | 1187 | pub abi: Abi, | ^^^^^^^^^^^^
Pending,

Check warning on line 1188 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> pallets/api/src/messaging/mod.rs:1188:2 | 1188 | pub selector: [u8; 4], | ^^^^^^^^^^^^^^^^^^^^^
Complete,

Check warning on line 1189 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> pallets/api/src/messaging/mod.rs:1189:2 | 1189 | pub weight: Weight, | ^^^^^^^^^^^^^^^^^^
Timeout,
}

Expand All @@ -1201,7 +1200,7 @@
}

impl Callback {
pub(crate) fn increase_callback_weight(&mut self, additional_weight: Weight) -> Weight {

Check warning on line 1203 in pallets/api/src/messaging/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> pallets/api/src/messaging/mod.rs:1203:2 | 1203 | Scale, | ^^^^^
let new_callback_weight = self.weight.saturating_add(additional_weight);
self.weight = new_callback_weight;
new_callback_weight
Expand Down
78 changes: 69 additions & 9 deletions pallets/api/src/messaging/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,8 @@ mod xcm_hooks {
fn xcm_queries_expire_on_expiry_block() {
new_test_ext().execute_with(|| {
let message_id = [0; 32];
let timeout = System::block_number() + 10;
// timeout in 100 blocks time.
let timeout = 100;
assert_ok!(Messaging::xcm_new_query(
signed(ALICE),
message_id,
Expand All @@ -912,7 +913,22 @@ mod xcm_hooks {
None,
));

run_to(timeout + 1);
// assert that the block before is not timed out.

run_to(timeout + System::block_number() - 1);
let Some(Message::XcmQuery { .. }): Option<Message<Test>> =
Messages::get(ALICE, message_id)
else {
panic!("Message should be a query!")
};

let Some(Message::XcmQuery { .. }): Option<Message<Test>> =
Messages::get(ALICE, message_id_2)
else {
panic!("Message should be query!")
};

run_to(System::block_number() + 1);

let Some(Message::XcmTimeout { .. }): Option<Message<Test>> =
Messages::get(ALICE, message_id)
Expand Down Expand Up @@ -1178,10 +1194,17 @@ mod ismp_get {
keys: bounded_vec!(),
};
let callback = None;
let ismp_relayer_fee: Balance = u32::MAX.into();

assert_ok!(Messaging::ismp_get(signed(ALICE), message_id, message.clone(), callback));
assert_ok!(Messaging::ismp_get(
signed(ALICE),
message_id,
message.clone(),
ismp_relayer_fee,
callback
));
assert_noop!(
Messaging::ismp_get(signed(ALICE), message_id, message, callback),
Messaging::ismp_get(signed(ALICE), message_id, message, ismp_relayer_fee, callback),
Error::<Test>::MessageExists
);
})
Expand All @@ -1202,6 +1225,7 @@ mod ismp_get {
let callback = Callback { selector: [1; 4], weight, abi: Abi::Scale };

let callback_deposit = <Test as Config>::WeightToFee::weight_to_fee(&weight);
let ismp_relayer_fee: Balance = u32::MAX.into();

let expected_deposit = calculate_protocol_deposit::<
Test,
Expand All @@ -1215,7 +1239,13 @@ mod ismp_get {
assert_eq!(alice_hold_balance_pre_hold, 0);
assert!(expected_deposit != 0);

assert_ok!(Messaging::ismp_get(signed(ALICE), message_id, message, Some(callback)));
assert_ok!(Messaging::ismp_get(
signed(ALICE),
message_id,
message,
ismp_relayer_fee,
Some(callback)
));

let alice_hold_balance_post_hold = Balances::total_balance_on_hold(&ALICE);

Expand All @@ -1235,7 +1265,15 @@ mod ismp_get {
keys: bounded_vec!(),
};
let callback = None;
assert_ok!(Messaging::ismp_get(signed(ALICE), message_id, message, callback));
let ismp_relayer_fee: Balance = u32::MAX.into();

assert_ok!(Messaging::ismp_get(
signed(ALICE),
message_id,
message,
ismp_relayer_fee,
callback
));
let events = events();
let Some(Event::<Test>::IsmpGetDispatched { origin, id, commitment, callback }) =
events.first()
Expand All @@ -1262,10 +1300,23 @@ mod ismp_post {
let message_id = [0u8; 32];
let message = ismp::Post { dest: 2000, timeout: 100, data: bounded_vec![] };
let callback = None;
let ismp_relayer_fee: Balance = u32::MAX.into();

assert_ok!(Messaging::ismp_post(signed(ALICE), message_id, message.clone(), callback));
assert_ok!(Messaging::ismp_post(
signed(ALICE),
message_id,
message.clone(),
ismp_relayer_fee,
callback
));
assert_noop!(
Messaging::ismp_post(signed(ALICE), message_id, message, callback),
Messaging::ismp_post(
signed(ALICE),
message_id,
message,
ismp_relayer_fee,
callback
),
Error::<Test>::MessageExists
);
})
Expand All @@ -1277,6 +1328,7 @@ mod ismp_post {
let message_id = [0u8; 32];
let message = ismp::Post { dest: 2000, timeout: 100, data: bounded_vec![] };
let weight = Weight::from_parts(100_000_000, 100_000_000);
let ismp_relayer_fee: Balance = u32::MAX.into();
let callback = Callback { selector: [1; 4], weight, abi: Abi::Scale };
let callback_deposit = <Test as Config>::WeightToFee::weight_to_fee(&weight);
let expected_deposit = calculate_protocol_deposit::<
Expand All @@ -1297,6 +1349,7 @@ mod ismp_post {
signed(ALICE),
message_id,
message.clone(),
ismp_relayer_fee,
Some(callback)
));

Expand All @@ -1312,8 +1365,15 @@ mod ismp_post {
let message_id = [0u8; 32];
let message = ismp::Post { dest: 2000, timeout: 100, data: bounded_vec![] };
let callback = None;
let ismp_relayer_fee: Balance = u32::MAX.into();

assert_ok!(Messaging::ismp_post(signed(ALICE), message_id, message.clone(), callback));
assert_ok!(Messaging::ismp_post(
signed(ALICE),
message_id,
message.clone(),
ismp_relayer_fee,
callback
));

let events = events();
let Some(Event::<Test>::IsmpPostDispatched { origin, id, commitment, callback }) =
Expand Down
2 changes: 0 additions & 2 deletions pallets/api/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ parameter_types! {
pub const OffChainByteFee: Balance = 5;
pub const MaxXcmQueryTimeoutsPerBlock: u32 = 10;
pub const FeeAccount: AccountId = FEE_ACCOUNT;
pub const IsmpRelayerFee: Balance = 100_000;
}

pub struct MockNotifyQuery<T>(T);
Expand Down Expand Up @@ -270,7 +269,6 @@ impl crate::messaging::Config for Test {
type FeeHandler = ResolveTo<FeeAccount, Balances>;
type Fungibles = Balances;
type IsmpDispatcher = pallet_ismp::Pallet<Test>;
type IsmpRelayerFee = IsmpRelayerFee;
type Keccak256 = Keccak;
type MaxContextLen = ConstU32<64>;
type MaxDataLen = ConstU32<1024>;
Expand Down
2 changes: 1 addition & 1 deletion pop-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ path = "src/lib.rs"
[features]
default = [ "std" ]
fungibles = [ ]
messaging = [ ]
nonfungibles = [ ]
std = [
"ink/std",
"pop-primitives/std",
"sp-io/std",
]
messaging = [ ]
4 changes: 2 additions & 2 deletions pop-api/examples/messaging/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod messaging {
self.id,
Get::new(self.para, height, 0, Vec::default(), Vec::from([key.clone()])),
0,
Some(Callback::to(0x57ad942b, Weight::from_parts(800_000_000, 500_000))),
Some(Callback::new(0x57ad942b, Weight::from_parts(800_000_000, 500_000))),
)?;
self.env().emit_event(IsmpRequested { id: self.id, key, height });
Ok(())
Expand Down Expand Up @@ -95,7 +95,7 @@ mod messaging {
self.id,
dest.clone(),
self.env().block_number().saturating_add(100),
Some(Callback::to(0x641b0b03, Weight::from_parts(800_000_000, 500_000))),
Some(Callback::new(0x641b0b03, Weight::from_parts(800_000_000, 500_000), Abi::Scale)),
)?
.unwrap(); // TODO: handle error

Expand Down
4 changes: 4 additions & 0 deletions pop-api/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pallet-balances = { workspace = true, default-features = false }
pallet-contracts = { workspace = true, default-features = false }
pallet-ismp = { workspace = true, default-features = false }
pallet-nfts = { workspace = true, default-features = false }
pallet-revive = { workspace = true, default-features = false }
pallet-timestamp = { workspace = true, default-features = false }
pallet-xcm = { workspace = true, default-features = false }
pop-api = { path = "../../pop-api", default-features = false, features = [
"fungibles",
Expand All @@ -37,6 +39,7 @@ xcm-executor.workspace = true
[features]
default = [ "std" ]
devnet = [ "pop-runtime-devnet/default" ]

std = [
"codec/std",
"frame-support/std",
Expand All @@ -46,6 +49,7 @@ std = [
"pallet-balances/std",
"pallet-contracts/std",
"pallet-nfts/std",
"pallet-timestamp/std",
"pop-api/std",
"pop-primitives/std",
"pop-runtime-devnet/std",
Expand Down
Loading
Loading