-
Notifications
You must be signed in to change notification settings - Fork 666
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
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 79535cb
Update polkadot/xcm/xcm-executor/src/traits/controller.rs
pgherveou 0a02451
Update doc
pgherveou 18c6bb4
Use outcome in controller
pgherveou 198d692
add docstring
pgherveou e3ce2e0
Event consistency
pgherveou 6342962
Add more docs
pgherveou a2fde63
Update polkadot/xcm/xcm-executor/src/traits/controller.rs
pgherveou 0ae8763
fix doc
pgherveou 034150c
fix CI
pgherveou 7848e2f
move to xcm-builder
pgherveou b7155b6
move to pallet-xcm
pgherveou 34329e5
Update doc links
pgherveou 07439dd
Merge branch 'master' into pg/xcm_contracts_update
pgherveou b37d169
wip
pgherveou 8ac21da
Bench compile fix
pgherveou 7ee5d08
add missing use
pgherveou f3cbdc4
fix test
pgherveou f3bd197
fix lint
pgherveou de8500f
Add prdoc
pgherveou 9536755
Merge branch 'master' into pg/xcm_contracts_update
pgherveou abb196b
Move to xcm_builder
pgherveou df789aa
missing trait doc
pgherveou 2c01af3
Merge branch 'master' into pg/xcm_contracts_update
pgherveou 2fd1928
Merge branch 'master' into pg/xcm_contracts_update
pgherveou fd958af
Update polkadot/xcm/xcm-builder/src/controller.rs
pgherveou 2517c73
Merge branch 'master' into pg/xcm_contracts_update
pgherveou 65d3bf9
fix build
pgherveou 9a29e87
zepter fix
pgherveou 94055be
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
18aacb3
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
af5dd47
remove temp weightinfo impl
pgherveou 56a5449
Merge branch 'master' into pg/xcm_contracts_update
pgherveou 49e45d8
Revert "remove temp weightinfo impl"
pgherveou 7ee9145
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
02a3f4c
Add benchmark
pgherveou 9f48c00
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
de42120
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
eb4a904
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
fc09597
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
443aff6
update weights
pgherveou 0c308db
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
2029223
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
639c64f
westend weights
pgherveou 105d9f5
remove default weights
pgherveou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 inxcm-builder
, right?There was a problem hiding this comment.
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 thexcm
crate, but unsure if that's the best idea. I think as long as we don't version these types, it should be fine.There was a problem hiding this comment.
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