Skip to content

Commit

Permalink
pallet-xcm: Deprecate execute and send in favor of execute_blob
Browse files Browse the repository at this point in the history
… and `send_blob` (#3749)

`execute` and `send` try to decode the xcm in the parameters before
reaching the filter line.
The new extrinsics decode only after the filter line.
These should be used instead of the old ones.

## TODO
- [x] Tests
- [x] Generate weights
- [x] Deprecation issue ->
#3771
- [x] PRDoc
- [x] Handle error in pallet-contracts

This would make writing XCMs in PJS Apps more difficult, but here's the
fix for that: polkadot-js/apps#10350.
Already deployed! https://polkadot.js.org/apps/#/utilities/xcm

Supersedes #1798

---------

Co-authored-by: PG Herveou <pgherveou@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
  • Loading branch information
3 people authored Mar 27, 2024
1 parent 66051ad commit feee773
Show file tree
Hide file tree
Showing 36 changed files with 1,133 additions and 642 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ publish = false
workspace = true

[dependencies]

# Substrate
sp-core = { path = "../../../../../../../substrate/primitives/core", default-features = false }
sp-runtime = { path = "../../../../../../../substrate/primitives/runtime", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,18 @@ macro_rules! impl_send_transact_helpers_for_relay_chain {
recipient: $crate::impls::ParaId,
call: $crate::impls::DoubleEncoded<()>
) {
use $crate::impls::{bx, Chain, RelayChain};
use $crate::impls::{bx, Chain, RelayChain, Encode};

<Self as $crate::impls::TestExt>::execute_with(|| {
let root_origin = <Self as Chain>::RuntimeOrigin::root();
let destination: $crate::impls::Location = <Self as RelayChain>::child_location_of(recipient);
let xcm = $crate::impls::xcm_transact_unpaid_execution(call, $crate::impls::OriginKind::Superuser);

// Send XCM `Transact`
$crate::impls::assert_ok!(<Self as [<$chain RelayPallet>]>::XcmPallet::send(
$crate::impls::assert_ok!(<Self as [<$chain RelayPallet>]>::XcmPallet::send_blob(
root_origin,
bx!(destination.into()),
bx!(xcm),
xcm.encode().try_into().unwrap(),
));
Self::assert_xcm_pallet_sent();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() {
)]);

PenpalA::execute_with(|| {
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send_blob(
root_origin,
bx!(system_para_destination),
bx!(xcm),
xcm.encode().try_into().unwrap(),
));

PenpalA::assert_xcm_pallet_sent();
Expand Down Expand Up @@ -159,10 +159,10 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
)]);

PenpalA::execute_with(|| {
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send_blob(
root_origin,
bx!(system_para_destination),
bx!(xcm),
xcm.encode().try_into().unwrap(),
));

PenpalA::assert_xcm_pallet_sent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() {
penpal.clone(),
);

assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send_blob(
penpal_root,
bx!(asset_hub_location),
bx!(xcm),
xcm.encode().try_into().unwrap(),
));

PenpalA::assert_xcm_pallet_sent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() {
)]);

PenpalA::execute_with(|| {
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send_blob(
root_origin,
bx!(system_para_destination),
bx!(xcm),
xcm.encode().try_into().unwrap(),
));

PenpalA::assert_xcm_pallet_sent();
Expand Down Expand Up @@ -159,10 +159,10 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
)]);

PenpalA::execute_with(|| {
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send_blob(
root_origin,
bx!(system_para_destination),
bx!(xcm),
xcm.encode().try_into().unwrap(),
));

PenpalA::assert_xcm_pallet_sent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() {
penpal.clone(),
);

assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send_blob(
penpal_root,
bx!(asset_hub_location),
bx!(xcm),
xcm.encode().try_into().unwrap(),
));

PenpalA::assert_xcm_pallet_sent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.

use crate::tests::*;
use codec::Encode;

#[test]
fn send_xcm_from_rococo_relay_to_westend_asset_hub_should_fail_on_not_applicable() {
Expand All @@ -26,7 +27,7 @@ fn send_xcm_from_rococo_relay_to_westend_asset_hub_should_fail_on_not_applicable

let remote_xcm = Xcm(vec![ClearOrigin]);

let xcm = VersionedXcm::from(Xcm(vec![
let xcm = VersionedXcm::from(Xcm::<()>(vec![
UnpaidExecution { weight_limit, check_origin },
ExportMessage {
network: WestendId.into(),
Expand All @@ -38,10 +39,10 @@ fn send_xcm_from_rococo_relay_to_westend_asset_hub_should_fail_on_not_applicable
// Rococo Global Consensus
// Send XCM message from Relay Chain to Bridge Hub source Parachain
Rococo::execute_with(|| {
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send(
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send_blob(
sudo_origin,
bx!(destination),
bx!(xcm),
xcm.encode().try_into().unwrap(),
));

type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn create_agent() {

let create_agent_call = SnowbridgeControl::Control(ControlCall::CreateAgent {});
// Construct XCM to create an agent for para 1001
let remote_xcm = VersionedXcm::from(Xcm(vec![
let remote_xcm = VersionedXcm::from(Xcm::<()>(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
DescendOrigin(Parachain(origin_para).into()),
Transact {
Expand All @@ -96,10 +96,10 @@ fn create_agent() {
// Rococo Global Consensus
// Send XCM message from Relay Chain to Bridge Hub source Parachain
Rococo::execute_with(|| {
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send(
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send_blob(
sudo_origin,
bx!(destination),
bx!(remote_xcm),
remote_xcm.encode().try_into().unwrap(),
));

type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;
Expand Down Expand Up @@ -141,7 +141,7 @@ fn create_channel() {

let create_agent_call = SnowbridgeControl::Control(ControlCall::CreateAgent {});
// Construct XCM to create an agent for para 1001
let create_agent_xcm = VersionedXcm::from(Xcm(vec![
let create_agent_xcm = VersionedXcm::from(Xcm::<()>(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
DescendOrigin(Parachain(origin_para).into()),
Transact {
Expand All @@ -154,7 +154,7 @@ fn create_channel() {
let create_channel_call =
SnowbridgeControl::Control(ControlCall::CreateChannel { mode: OperatingMode::Normal });
// Construct XCM to create a channel for para 1001
let create_channel_xcm = VersionedXcm::from(Xcm(vec![
let create_channel_xcm = VersionedXcm::from(Xcm::<()>(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
DescendOrigin(Parachain(origin_para).into()),
Transact {
Expand All @@ -167,16 +167,16 @@ fn create_channel() {
// Rococo Global Consensus
// Send XCM message from Relay Chain to Bridge Hub source Parachain
Rococo::execute_with(|| {
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send(
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send_blob(
sudo_origin.clone(),
bx!(destination.clone()),
bx!(create_agent_xcm),
create_agent_xcm.encode().try_into().unwrap(),
));

assert_ok!(<Rococo as RococoPallet>::XcmPallet::send(
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send_blob(
sudo_origin,
bx!(destination),
bx!(create_channel_xcm),
create_channel_xcm.encode().try_into().unwrap(),
));

type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ publish = false
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.0" }

# Substrate
frame-support = { path = "../../../../../../../substrate/frame/support", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.

use crate::tests::*;
use codec::Encode;

#[test]
fn send_xcm_from_westend_relay_to_rococo_asset_hub_should_fail_on_not_applicable() {
Expand All @@ -26,7 +27,7 @@ fn send_xcm_from_westend_relay_to_rococo_asset_hub_should_fail_on_not_applicable

let remote_xcm = Xcm(vec![ClearOrigin]);

let xcm = VersionedXcm::from(Xcm(vec![
let xcm = VersionedXcm::from(Xcm::<()>(vec![
UnpaidExecution { weight_limit, check_origin },
ExportMessage {
network: RococoId,
Expand All @@ -38,10 +39,10 @@ fn send_xcm_from_westend_relay_to_rococo_asset_hub_should_fail_on_not_applicable
// Westend Global Consensus
// Send XCM message from Relay Chain to Bridge Hub source Parachain
Westend::execute_with(|| {
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
assert_ok!(<Westend as WestendPallet>::XcmPallet::send_blob(
sudo_origin,
bx!(destination),
bx!(xcm),
xcm.encode().try_into().unwrap(),
));

type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
Expand Down
Loading

0 comments on commit feee773

Please sign in to comment.