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

Contracts: Add XCM traits to interface with contracts #2086

Merged
merged 45 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
582467d
Contracts: Add XCM traits to interface with contracts
pgherveou Oct 30, 2023
79535cb
Update polkadot/xcm/xcm-executor/src/traits/controller.rs
pgherveou Oct 30, 2023
0a02451
Update doc
pgherveou Oct 30, 2023
18c6bb4
Use outcome in controller
pgherveou Oct 31, 2023
198d692
add docstring
pgherveou Oct 31, 2023
e3ce2e0
Event consistency
pgherveou Oct 31, 2023
6342962
Add more docs
pgherveou Oct 31, 2023
a2fde63
Update polkadot/xcm/xcm-executor/src/traits/controller.rs
pgherveou Oct 31, 2023
0ae8763
fix doc
pgherveou Oct 31, 2023
034150c
fix CI
pgherveou Oct 31, 2023
7848e2f
move to xcm-builder
pgherveou Nov 1, 2023
b7155b6
move to pallet-xcm
pgherveou Nov 1, 2023
34329e5
Update doc links
pgherveou Nov 1, 2023
07439dd
Merge branch 'master' into pg/xcm_contracts_update
pgherveou Nov 1, 2023
b37d169
wip
pgherveou Nov 1, 2023
8ac21da
Bench compile fix
pgherveou Nov 1, 2023
7ee5d08
add missing use
pgherveou Nov 2, 2023
f3cbdc4
fix test
pgherveou Nov 2, 2023
f3bd197
fix lint
pgherveou Nov 2, 2023
de8500f
Add prdoc
pgherveou Nov 2, 2023
9536755
Merge branch 'master' into pg/xcm_contracts_update
pgherveou Nov 2, 2023
abb196b
Move to xcm_builder
pgherveou Nov 6, 2023
df789aa
missing trait doc
pgherveou Nov 6, 2023
2c01af3
Merge branch 'master' into pg/xcm_contracts_update
pgherveou Nov 6, 2023
2fd1928
Merge branch 'master' into pg/xcm_contracts_update
pgherveou Nov 6, 2023
fd958af
Update polkadot/xcm/xcm-builder/src/controller.rs
pgherveou Nov 7, 2023
2517c73
Merge branch 'master' into pg/xcm_contracts_update
pgherveou Nov 7, 2023
65d3bf9
fix build
pgherveou Nov 7, 2023
9a29e87
zepter fix
pgherveou Nov 7, 2023
94055be
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Nov 7, 2023
18aacb3
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
Nov 7, 2023
af5dd47
remove temp weightinfo impl
pgherveou Nov 7, 2023
56a5449
Merge branch 'master' into pg/xcm_contracts_update
pgherveou Nov 7, 2023
49e45d8
Revert "remove temp weightinfo impl"
pgherveou Nov 7, 2023
7ee9145
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Nov 7, 2023
02a3f4c
Add benchmark
pgherveou Nov 8, 2023
9f48c00
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Nov 9, 2023
de42120
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 9, 2023
eb4a904
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Nov 10, 2023
fc09597
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 10, 2023
443aff6
update weights
pgherveou Nov 10, 2023
0c308db
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Nov 10, 2023
2029223
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 10, 2023
639c64f
westend weights
pgherveou Nov 10, 2023
105d9f5
remove default weights
pgherveou Nov 10, 2023
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
27 changes: 27 additions & 0 deletions polkadot/xcm/pallet-xcm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@ benchmarks! {
Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateAndNotifyOldTargets, Weight::zero());
}

new_query {
let responder = MultiLocation::from(Parent);
let timeout = 1u32.into();
let match_querier = MultiLocation::from(Here);
}: {
Pallet::<T>::new_query(responder, timeout, match_querier);
}

take_response {
let responder = MultiLocation::from(Parent);
let timeout = 1u32.into();
let match_querier = MultiLocation::from(Here);
let query_id = Pallet::<T>::new_query(responder, timeout, match_querier);
let infos = (0 .. xcm::v3::MaxPalletsInfo::get()).map(|_| PalletInfo::new(
u32::MAX,
(0..xcm::v3::MaxPalletNameLen::get()).map(|_| 97u8).collect::<Vec<_>>().try_into().unwrap(),
(0..xcm::v3::MaxPalletNameLen::get()).map(|_| 97u8).collect::<Vec<_>>().try_into().unwrap(),
u32::MAX,
u32::MAX,
u32::MAX,
).unwrap()).collect::<Vec<_>>();
Pallet::<T>::expect_response(query_id, Response::PalletsInfo(infos.try_into().unwrap()));

}: {
<Pallet::<T> as QueryHandler>::take_response(query_id);
}

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext_with_balances(Vec::new()),
Expand Down
186 changes: 186 additions & 0 deletions polkadot/xcm/pallet-xcm/src/controller.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By putting those crates into the pallet we still have to add the dependency in pallet-contracts. Can't they exist in xcm-executor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was discussed above #2086 (comment)
Does it matter for us that we depend on one crate rather than the other ? Ultimately you will need to import pallet-xcm if you want to do something useful with Config::Xcm.

I am ooo today, but would be great if we could come to a consensus quickly so we can merge this and #1248 quickly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we do this whole stunt in order to remove the direct non-dev dependency on that crate as we don't want tight coupling between those pallets. Sure, we don't call the pallet directly anymore but it feels we only went half the way with still keeping the dependency.

This is why I would prefer to have them in xcm-builder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KiChjang @franciscoaguirre fine for you if I move that back to xcm-builder and make it a non-dev dependency of pallet-xcm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before it was in xcm-executor not in xcm-builder, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it was originally in xcm-executor, which didn't make much sense as the types exposed here are used by pallets. Another option is to put it in the xcm crate, but unsure if that's the best idea. I think as long as we don't version these types, it should be fine.

Copy link
Contributor

@franciscoaguirre franciscoaguirre Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xcm-builder makes sense to me

Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! A set of traits that define how a pallet interface with XCM.
//! Controller traits defined in this module are high-level traits that will rely on other traits
//! from `xcm-executor` to perform their tasks.

use frame_support::pallet_prelude::DispatchError;
use sp_std::boxed::Box;
use xcm::prelude::*;
use xcm_executor::traits::QueryHandler;

pub trait Controller<Origin, RuntimeCall, Timeout>:
ExecuteController<Origin, RuntimeCall> + SendController<Origin> + QueryController<Origin, Timeout>
{
}

impl<T, Origin, RuntimeCall, Timeout> Controller<Origin, RuntimeCall, Timeout> for T where
T: ExecuteController<Origin, RuntimeCall>
+ SendController<Origin>
+ QueryController<Origin, Timeout>
{
}

/// Weight functions needed for [`ExecuteController`].
pub trait ExecuteControllerWeightInfo {
/// Weight for [`ExecuteController::execute`]
fn execute() -> Weight;
}

/// Execute an XCM locally, for a given origin.
///
/// An implementation of that trait will handle the low-level details of the execution, such as:
/// - Validating and Converting the origin to a MultiLocation.
/// - Handling versioning.
/// - Calling the internal executor, which implements [`ExecuteXcm`].
pub trait ExecuteController<Origin, RuntimeCall> {
/// Weight information for ExecuteController functions.
type WeightInfo: ExecuteControllerWeightInfo;

/// Attempt to execute an XCM locally, and return the outcome.
///
/// # Parameters
///
/// - `origin`: the origin of the call.
/// - `message`: the XCM program to be executed.
/// - `max_weight`: the maximum weight that can be consumed by the execution.
fn execute(
origin: Origin,
message: Box<VersionedXcm<RuntimeCall>>,
max_weight: Weight,
) -> Result<Outcome, DispatchError>;
}

/// Weight functions needed for [`SendController`].
pub trait SendControllerWeightInfo {
/// Weight for [`SendController::send`]
fn send() -> Weight;
}

/// Send an XCM from a given origin.
///
/// An implementation of that trait will handle the low-level details of dispatching an XCM, such
/// as:
/// - Validating and Converting the origin to an interior location.
/// - Handling versioning.
/// - Calling the internal router, which implements [`SendXcm`].
pub trait SendController<Origin> {
/// Weight information for SendController functions.
type WeightInfo: SendControllerWeightInfo;

/// Send an XCM to be executed by a remote location.
///
/// # Parameters
///
/// - `origin`: the origin of the call.
/// - `dest`: the destination of the message.
/// - `msg`: the XCM to be sent.
fn send(
origin: Origin,
dest: Box<VersionedMultiLocation>,
message: Box<VersionedXcm<()>>,
) -> Result<XcmHash, DispatchError>;
}

/// Weight functions needed for [`QueryController`].
pub trait QueryControllerWeightInfo {
/// Weight for [`QueryController::query`]
fn query() -> Weight;

/// Weight for [`QueryHandler::take_response`]
fn take_response() -> Weight;
}

/// Query a remote location, from a given origin.
///
/// An implementation of that trait will handle the low-level details of querying a remote location,
/// such as:
/// - Validating and Converting the origin to an interior location.
/// - Handling versioning.
/// - Calling the [`QueryHandler`] to register the query.
pub trait QueryController<Origin, Timeout>: QueryHandler {
/// Weight information for QueryController functions.
type WeightInfo: QueryControllerWeightInfo;

/// Query a remote location.
///
/// # Parameters
///
/// - `origin`: the origin of the call, used to determine the responder.
/// - `timeout`: the maximum block number that the query should be responded to.
/// - `match_querier`: the querier that the query should be responded to.
fn query(
origin: Origin,
timeout: Timeout,
match_querier: VersionedMultiLocation,
) -> Result<Self::QueryId, DispatchError>;
}

impl<Origin, RuntimeCall> ExecuteController<Origin, RuntimeCall> for () {
type WeightInfo = ();
fn execute(
_origin: Origin,
_message: Box<VersionedXcm<RuntimeCall>>,
_max_weight: Weight,
) -> Result<Outcome, DispatchError> {
Ok(Outcome::Error(XcmError::Unimplemented))
}
}

impl ExecuteControllerWeightInfo for () {
fn execute() -> Weight {
Weight::zero()
}
}

impl<Origin> SendController<Origin> for () {
type WeightInfo = ();
fn send(
_origin: Origin,
_dest: Box<VersionedMultiLocation>,
_message: Box<VersionedXcm<()>>,
) -> Result<XcmHash, DispatchError> {
Ok(Default::default())
}
}

impl SendControllerWeightInfo for () {
fn send() -> Weight {
Weight::zero()
}
}

impl QueryControllerWeightInfo for () {
fn query() -> Weight {
Weight::zero()
}
fn take_response() -> Weight {
Weight::zero()
}
}

impl<Origin, Timeout> QueryController<Origin, Timeout> for () {
type WeightInfo = ();

fn query(
_origin: Origin,
_timeout: Timeout,
_match_querier: VersionedMultiLocation,
) -> Result<Self::QueryId, DispatchError> {
Ok(Default::default())
}
}
Loading
Loading