From d56a14e012951f86fae8a427b33b75dcbcc0c89b Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Thu, 14 Mar 2024 13:09:25 +0100 Subject: [PATCH 01/14] add_xcm_hrmp --- .../assets/asset-hub-rococo/src/xcm_config.rs | 1 + .../asset-hub-westend/src/xcm_config.rs | 1 + .../bridge-hub-rococo/src/xcm_config.rs | 1 + .../bridge-hub-westend/src/xcm_config.rs | 1 + .../collectives-westend/src/xcm_config.rs | 1 + .../contracts-rococo/src/xcm_config.rs | 1 + .../coretime-rococo/src/xcm_config.rs | 1 + .../coretime-westend/src/xcm_config.rs | 1 + .../glutton/glutton-westend/src/xcm_config.rs | 1 + .../people/people-rococo/src/xcm_config.rs | 1 + .../people/people-westend/src/xcm_config.rs | 1 + .../runtimes/starters/shell/src/xcm_config.rs | 1 + .../runtimes/testing/penpal/src/xcm_config.rs | 1 + .../testing/rococo-parachain/src/lib.rs | 1 + polkadot/runtime/rococo/src/xcm_config.rs | 1 + .../runtime/test-runtime/src/xcm_config.rs | 1 + polkadot/runtime/westend/src/xcm_config.rs | 1 + polkadot/xcm/xcm-executor/src/config.rs | 9 ++++---- polkadot/xcm/xcm-executor/src/lib.rs | 8 +++---- polkadot/xcm/xcm-executor/src/traits/hrmp.rs | 23 +++++++++++++++++++ polkadot/xcm/xcm-executor/src/traits/mod.rs | 2 ++ .../xcm-simulator/example/src/parachain.rs | 1 + .../xcm-simulator/example/src/relay_chain.rs | 1 + .../xcm/xcm-simulator/fuzzer/src/parachain.rs | 1 + .../xcm-simulator/fuzzer/src/relay_chain.rs | 1 + .../contracts/mock-network/src/parachain.rs | 1 + .../contracts/mock-network/src/relay_chain.rs | 1 + templates/parachain/runtime/src/xcm_config.rs | 1 + 28 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 polkadot/xcm/xcm-executor/src/traits/hrmp.rs diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 2584dbdf3106..e5c1cb6f39b3 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -628,6 +628,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Converts a local signed origin into an XCM location. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 50865c000611..4c0fc8a15722 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -649,6 +649,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Local origins on this chain are allowed to dispatch XCM sends/executions. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 55c78477b568..184e03ea7e78 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -336,6 +336,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } pub type PriceForParentDelivery = diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs index e18df6feda82..2865b6ec70bb 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs @@ -264,6 +264,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } pub type PriceForParentDelivery = diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs index 87f637d5b59a..93c21b42f33e 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs @@ -288,6 +288,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Converts a local signed origin into an XCM location. diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs index e8f3209eb67f..6701fb6356e2 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs @@ -197,6 +197,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Converts a local signed origin into an XCM location. diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs index 1722e1fcb319..9367639b8ffb 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs @@ -257,6 +257,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs index b03c7748fe09..eb3864715d62 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs @@ -269,6 +269,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs index ad61987c0e70..5cd9b9bc9c8b 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs @@ -88,6 +88,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } impl cumulus_pallet_xcm::Config for Runtime { diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs index 534d65190862..428b79300be4 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs @@ -269,6 +269,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs index 6353a5813525..5bb66d19b69d 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs @@ -277,6 +277,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs b/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs index f6af50f76d85..a1d5b1fa4ee0 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs @@ -88,6 +88,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = (); + type HrmpHandler = (); } impl cumulus_pallet_xcm::Config for Runtime { diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index bc1aa05a6177..03a596a56df4 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -338,6 +338,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 2b21a12c3ca4..a94431814ef7 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -487,6 +487,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// Local origins on this chain are allowed to dispatch XCM sends/executions. diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index 67f34916fe78..b9fc5fb7885a 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -221,6 +221,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } parameter_types! { diff --git a/polkadot/runtime/test-runtime/src/xcm_config.rs b/polkadot/runtime/test-runtime/src/xcm_config.rs index a48bca17e9ff..9d2326d09bce 100644 --- a/polkadot/runtime/test-runtime/src/xcm_config.rs +++ b/polkadot/runtime/test-runtime/src/xcm_config.rs @@ -153,6 +153,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } impl pallet_xcm::Config for crate::Runtime { diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index 7281007f0060..cafccfdfeeeb 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -219,6 +219,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } parameter_types! { diff --git a/polkadot/xcm/xcm-executor/src/config.rs b/polkadot/xcm/xcm-executor/src/config.rs index ebe532a42fd3..95a6c86b5063 100644 --- a/polkadot/xcm/xcm-executor/src/config.rs +++ b/polkadot/xcm/xcm-executor/src/config.rs @@ -14,11 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use crate::traits::{ - AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm, - FeeManager, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset, - VersionChangeNotifier, WeightBounds, WeightTrader, -}; +use crate::traits::{AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm, FeeManager, HandleHrmp, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader}; use frame_support::{ dispatch::{GetDispatchInfo, Parameter, PostDispatchInfo}, traits::{Contains, ContainsPair, Get, PalletsInfoAccess}, @@ -114,4 +110,7 @@ pub trait Config { /// Transactional processor for XCM instructions. type TransactionalProcessor: ProcessTransaction; + + /// Handler for HRMP notification messages sent by the relay chain. + type HrmpHandler: HandleHrmp; } diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index c61e1e1d15bc..0e6c9ade20d3 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -33,7 +33,7 @@ use traits::{ validate_export, AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, Enact, ExportXcm, FeeManager, FeeReason, OnResponse, ProcessTransaction, Properties, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader, - XcmAssetTransfers, + XcmAssetTransfers, HandleHrmp }; mod assets; @@ -1212,9 +1212,9 @@ impl XcmExecutor { ); Ok(()) }, - HrmpNewChannelOpenRequest { .. } => Err(XcmError::Unimplemented), - HrmpChannelAccepted { .. } => Err(XcmError::Unimplemented), - HrmpChannelClosing { .. } => Err(XcmError::Unimplemented), + HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } => Config::HrmpHandler::handle_new_channel_open_request(sender, max_message_size, max_capacity), + HrmpChannelAccepted { recipient } => Config::HrmpHandler::handle_channel_accepted(recipient), + HrmpChannelClosing { initiator, sender, recipient } => Config::HrmpHandler::handle_channel_closing(initiator, sender, recipient), } } } diff --git a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs new file mode 100644 index 000000000000..85199e8b5a97 --- /dev/null +++ b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs @@ -0,0 +1,23 @@ +use xcm::v3::{ + prelude::{XcmError, XcmResult}, +}; + +pub trait HandleHrmp { + fn handle_new_channel_open_request(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult; + fn handle_channel_accepted(recipient: u32) -> XcmResult; + fn handle_channel_closing(initiator: u32, sender: u32, recipient: u32) -> XcmResult; +} + +impl HandleHrmp for () { + fn handle_new_channel_open_request(_sender: u32, _max_message_size: u32, _max_capacity: u32) -> XcmResult { + Err(XcmError::Unimplemented) + } + + fn handle_channel_accepted(_recipient: u32) -> XcmResult { + Err(XcmError::Unimplemented) + } + + fn handle_channel_closing(_initiator: u32, _sender: u32, _recipient: u32) -> XcmResult { + Err(XcmError::Unimplemented) + } +} diff --git a/polkadot/xcm/xcm-executor/src/traits/mod.rs b/polkadot/xcm/xcm-executor/src/traits/mod.rs index b445e84d3912..56ce3606c992 100644 --- a/polkadot/xcm/xcm-executor/src/traits/mod.rs +++ b/polkadot/xcm/xcm-executor/src/traits/mod.rs @@ -45,6 +45,8 @@ mod should_execute; pub use should_execute::{CheckSuspension, Properties, ShouldExecute}; mod transact_asset; pub use transact_asset::TransactAsset; +mod hrmp; +pub use hrmp::HandleHrmp; mod weight; #[deprecated = "Use `sp_runtime::traits::` instead"] pub use sp_runtime::traits::{Identity, TryConvertInto as JustTry}; diff --git a/polkadot/xcm/xcm-simulator/example/src/parachain.rs b/polkadot/xcm/xcm-simulator/example/src/parachain.rs index 64333b4d5815..50110e0d9c4f 100644 --- a/polkadot/xcm/xcm-simulator/example/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/parachain.rs @@ -251,6 +251,7 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } #[frame_support::pallet] diff --git a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs index 54c5657c00d7..b4f17711cbb7 100644 --- a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs @@ -198,6 +198,7 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs index a20390b64f94..8ac66a4a356b 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -156,6 +156,7 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } #[frame_support::pallet] diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index 5bf65fa9f9ac..e163a3971e12 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -157,6 +157,7 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/substrate/frame/contracts/mock-network/src/parachain.rs b/substrate/frame/contracts/mock-network/src/parachain.rs index 7a60a66b3145..294e49cf2695 100644 --- a/substrate/frame/contracts/mock-network/src/parachain.rs +++ b/substrate/frame/contracts/mock-network/src/parachain.rs @@ -282,6 +282,7 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } impl mock_msg_queue::Config for Runtime { diff --git a/substrate/frame/contracts/mock-network/src/relay_chain.rs b/substrate/frame/contracts/mock-network/src/relay_chain.rs index 6eb9b4e53855..71af6849ab7e 100644 --- a/substrate/frame/contracts/mock-network/src/relay_chain.rs +++ b/substrate/frame/contracts/mock-network/src/relay_chain.rs @@ -182,6 +182,7 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/templates/parachain/runtime/src/xcm_config.rs b/templates/parachain/runtime/src/xcm_config.rs index b1230ba1e5d4..3fb61096e7fb 100644 --- a/templates/parachain/runtime/src/xcm_config.rs +++ b/templates/parachain/runtime/src/xcm_config.rs @@ -137,6 +137,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpHandler = (); } /// No local origins on this chain are allowed to dispatch XCM sends/executions. From 3830c7aaf95af4d4655b23e2ffd57c195b9ae3d4 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Thu, 14 Mar 2024 17:22:26 +0100 Subject: [PATCH 02/14] separate traits and add blanket tuple impl --- .../assets/asset-hub-rococo/src/xcm_config.rs | 4 +- .../asset-hub-westend/src/xcm_config.rs | 4 +- .../bridge-hub-rococo/src/xcm_config.rs | 4 +- .../bridge-hub-westend/src/xcm_config.rs | 4 +- .../collectives-westend/src/xcm_config.rs | 4 +- .../contracts-rococo/src/xcm_config.rs | 4 +- .../coretime-rococo/src/xcm_config.rs | 4 +- .../coretime-westend/src/xcm_config.rs | 4 +- .../glutton/glutton-westend/src/xcm_config.rs | 4 +- .../people/people-rococo/src/xcm_config.rs | 4 +- .../people/people-westend/src/xcm_config.rs | 4 +- .../runtimes/starters/shell/src/xcm_config.rs | 4 +- .../runtimes/testing/penpal/src/xcm_config.rs | 4 +- .../testing/rococo-parachain/src/lib.rs | 4 +- polkadot/runtime/rococo/src/xcm_config.rs | 4 +- .../runtime/test-runtime/src/xcm_config.rs | 4 +- polkadot/runtime/westend/src/xcm_config.rs | 4 +- polkadot/xcm/xcm-executor/src/config.rs | 7 ++-- polkadot/xcm/xcm-executor/src/lib.rs | 8 ++-- polkadot/xcm/xcm-executor/src/traits/hrmp.rs | 40 ++++++++++++------- polkadot/xcm/xcm-executor/src/traits/mod.rs | 2 +- .../xcm-simulator/example/src/parachain.rs | 4 +- .../xcm-simulator/example/src/relay_chain.rs | 4 +- .../xcm/xcm-simulator/fuzzer/src/parachain.rs | 4 +- .../xcm-simulator/fuzzer/src/relay_chain.rs | 4 +- .../contracts/mock-network/src/parachain.rs | 4 +- .../contracts/mock-network/src/relay_chain.rs | 4 +- templates/parachain/runtime/src/xcm_config.rs | 4 +- 28 files changed, 107 insertions(+), 46 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index e5c1cb6f39b3..c438361cc177 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -628,7 +628,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 4c0fc8a15722..c993d61545a6 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -649,7 +649,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Local origins on this chain are allowed to dispatch XCM sends/executions. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 184e03ea7e78..8934ff9b2272 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -336,7 +336,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type PriceForParentDelivery = diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs index 2865b6ec70bb..840d0c9af0e5 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/xcm_config.rs @@ -264,7 +264,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type PriceForParentDelivery = diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs index 93c21b42f33e..b83106a58284 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/xcm_config.rs @@ -288,7 +288,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs index 6701fb6356e2..ac6fe634662f 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/xcm_config.rs @@ -197,7 +197,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs index 9367639b8ffb..955f2eeba339 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/xcm_config.rs @@ -257,7 +257,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs index eb3864715d62..fc7d36a8ba18 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/xcm_config.rs @@ -269,7 +269,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs index 5cd9b9bc9c8b..15bb519e115c 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/xcm_config.rs @@ -88,7 +88,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl cumulus_pallet_xcm::Config for Runtime { diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs index 428b79300be4..a10333fdb626 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/xcm_config.rs @@ -269,7 +269,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs index 5bb66d19b69d..fee2f5684ac3 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/xcm_config.rs @@ -277,7 +277,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = SafeCallFilter; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Converts a local signed origin into an XCM location. Forms the basis for local origins diff --git a/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs b/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs index a1d5b1fa4ee0..df89158729cd 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs @@ -88,7 +88,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = (); - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl cumulus_pallet_xcm::Config for Runtime { diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index 03a596a56df4..d83a877c2f89 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -338,7 +338,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index a94431814ef7..b96f28c98158 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -487,7 +487,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// Local origins on this chain are allowed to dispatch XCM sends/executions. diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index b9fc5fb7885a..328879715de3 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -221,7 +221,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } parameter_types! { diff --git a/polkadot/runtime/test-runtime/src/xcm_config.rs b/polkadot/runtime/test-runtime/src/xcm_config.rs index 9d2326d09bce..8411b79f2529 100644 --- a/polkadot/runtime/test-runtime/src/xcm_config.rs +++ b/polkadot/runtime/test-runtime/src/xcm_config.rs @@ -153,7 +153,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl pallet_xcm::Config for crate::Runtime { diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index cafccfdfeeeb..73127cb1efd6 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -219,7 +219,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } parameter_types! { diff --git a/polkadot/xcm/xcm-executor/src/config.rs b/polkadot/xcm/xcm-executor/src/config.rs index 95a6c86b5063..ee65a5bce783 100644 --- a/polkadot/xcm/xcm-executor/src/config.rs +++ b/polkadot/xcm/xcm-executor/src/config.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use crate::traits::{AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm, FeeManager, HandleHrmp, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader}; +use crate::traits::{AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm, FeeManager, HandleHrmpChannelAccepted, HandleHrmpChannelClosing, HandleHrmpNewChannelOpenRequest, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader}; use frame_support::{ dispatch::{GetDispatchInfo, Parameter, PostDispatchInfo}, traits::{Contains, ContainsPair, Get, PalletsInfoAccess}, @@ -111,6 +111,7 @@ pub trait Config { /// Transactional processor for XCM instructions. type TransactionalProcessor: ProcessTransaction; - /// Handler for HRMP notification messages sent by the relay chain. - type HrmpHandler: HandleHrmp; + type HrmpNewChannelOpenRequestHandler: HandleHrmpNewChannelOpenRequest; + type HrmpChannelAcceptedHandler: HandleHrmpChannelAccepted; + type HrmpChannelClosingHandler: HandleHrmpChannelClosing; } diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index 0e6c9ade20d3..c73e02f0a8d9 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -33,7 +33,7 @@ use traits::{ validate_export, AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, Enact, ExportXcm, FeeManager, FeeReason, OnResponse, ProcessTransaction, Properties, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader, - XcmAssetTransfers, HandleHrmp + XcmAssetTransfers, HandleHrmpNewChannelOpenRequest, HandleHrmpChannelAccepted, HandleHrmpChannelClosing, }; mod assets; @@ -1212,9 +1212,9 @@ impl XcmExecutor { ); Ok(()) }, - HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } => Config::HrmpHandler::handle_new_channel_open_request(sender, max_message_size, max_capacity), - HrmpChannelAccepted { recipient } => Config::HrmpHandler::handle_channel_accepted(recipient), - HrmpChannelClosing { initiator, sender, recipient } => Config::HrmpHandler::handle_channel_closing(initiator, sender, recipient), + HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } => Config::HrmpNewChannelOpenRequestHandler::handle(sender, max_message_size, max_capacity), + HrmpChannelAccepted { recipient } => Config::HrmpChannelAcceptedHandler::handle(recipient), + HrmpChannelClosing { initiator, sender, recipient } => Config::HrmpChannelClosingHandler::handle(initiator, sender, recipient), } } } diff --git a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs index 85199e8b5a97..c2b8c5604708 100644 --- a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs +++ b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs @@ -1,23 +1,35 @@ -use xcm::v3::{ - prelude::{XcmError, XcmResult}, -}; +use xcm::v3::prelude::XcmResult; -pub trait HandleHrmp { - fn handle_new_channel_open_request(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult; - fn handle_channel_accepted(recipient: u32) -> XcmResult; - fn handle_channel_closing(initiator: u32, sender: u32, recipient: u32) -> XcmResult; +pub trait HandleHrmpNewChannelOpenRequest { + fn handle(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult; +} +pub trait HandleHrmpChannelAccepted { + fn handle(recipient: u32) -> XcmResult; +} +pub trait HandleHrmpChannelClosing { + fn handle(initiator: u32, sender: u32, recipient: u32) -> XcmResult; } -impl HandleHrmp for () { - fn handle_new_channel_open_request(_sender: u32, _max_message_size: u32, _max_capacity: u32) -> XcmResult { - Err(XcmError::Unimplemented) +#[impl_trait_for_tuples::impl_for_tuples(30)] +impl HandleHrmpNewChannelOpenRequest for Tuple { + fn handle(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult { + for_tuples!( #( Tuple::handle(sender, max_message_size, max_capacity)?; )* ); + Ok(()) } +} - fn handle_channel_accepted(_recipient: u32) -> XcmResult { - Err(XcmError::Unimplemented) +#[impl_trait_for_tuples::impl_for_tuples(30)] +impl HandleHrmpChannelAccepted for Tuple { + fn handle(recipient: u32) -> XcmResult { + for_tuples!( #( Tuple::handle(recipient)?; )* ); + Ok(()) } +} - fn handle_channel_closing(_initiator: u32, _sender: u32, _recipient: u32) -> XcmResult { - Err(XcmError::Unimplemented) +#[impl_trait_for_tuples::impl_for_tuples(30)] +impl HandleHrmpChannelClosing for Tuple { + fn handle(initiator: u32, sender: u32, recipient: u32) -> XcmResult { + for_tuples!( #( Tuple::handle(initiator, sender, recipient)?; )* ); + Ok(()) } } diff --git a/polkadot/xcm/xcm-executor/src/traits/mod.rs b/polkadot/xcm/xcm-executor/src/traits/mod.rs index 56ce3606c992..95d985d8c4be 100644 --- a/polkadot/xcm/xcm-executor/src/traits/mod.rs +++ b/polkadot/xcm/xcm-executor/src/traits/mod.rs @@ -46,7 +46,7 @@ pub use should_execute::{CheckSuspension, Properties, ShouldExecute}; mod transact_asset; pub use transact_asset::TransactAsset; mod hrmp; -pub use hrmp::HandleHrmp; +pub use hrmp::{HandleHrmpNewChannelOpenRequest, HandleHrmpChannelAccepted, HandleHrmpChannelClosing}; mod weight; #[deprecated = "Use `sp_runtime::traits::` instead"] pub use sp_runtime::traits::{Identity, TryConvertInto as JustTry}; diff --git a/polkadot/xcm/xcm-simulator/example/src/parachain.rs b/polkadot/xcm/xcm-simulator/example/src/parachain.rs index 50110e0d9c4f..5cba63a6f9ef 100644 --- a/polkadot/xcm/xcm-simulator/example/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/parachain.rs @@ -251,7 +251,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } #[frame_support::pallet] diff --git a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs index b4f17711cbb7..4ebc4220c7e6 100644 --- a/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/example/src/relay_chain.rs @@ -198,7 +198,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs index 8ac66a4a356b..22eb1a62d23f 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -156,7 +156,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } #[frame_support::pallet] diff --git a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index e163a3971e12..bfed871161b0 100644 --- a/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -157,7 +157,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/substrate/frame/contracts/mock-network/src/parachain.rs b/substrate/frame/contracts/mock-network/src/parachain.rs index 294e49cf2695..03817da0c05f 100644 --- a/substrate/frame/contracts/mock-network/src/parachain.rs +++ b/substrate/frame/contracts/mock-network/src/parachain.rs @@ -282,7 +282,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl mock_msg_queue::Config for Runtime { diff --git a/substrate/frame/contracts/mock-network/src/relay_chain.rs b/substrate/frame/contracts/mock-network/src/relay_chain.rs index 71af6849ab7e..5ab6c0200315 100644 --- a/substrate/frame/contracts/mock-network/src/relay_chain.rs +++ b/substrate/frame/contracts/mock-network/src/relay_chain.rs @@ -182,7 +182,9 @@ impl Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/templates/parachain/runtime/src/xcm_config.rs b/templates/parachain/runtime/src/xcm_config.rs index 3fb61096e7fb..7dce71648886 100644 --- a/templates/parachain/runtime/src/xcm_config.rs +++ b/templates/parachain/runtime/src/xcm_config.rs @@ -137,7 +137,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpHandler = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// No local origins on this chain are allowed to dispatch XCM sends/executions. From f9f7d516fdd9f6795dd7df3d7ece3ee5dc7e5c96 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 15 Mar 2024 09:01:05 +0100 Subject: [PATCH 03/14] Update polkadot/xcm/xcm-executor/src/traits/hrmp.rs --- polkadot/xcm/xcm-executor/src/traits/hrmp.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs index c2b8c5604708..878f35c04096 100644 --- a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs +++ b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs @@ -1,4 +1,20 @@ -use xcm::v3::prelude::XcmResult; +// 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 . + +use xcm::latest::Result as XcmResult; pub trait HandleHrmpNewChannelOpenRequest { fn handle(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult; From 350bd9e96a2d592140925433236a9003d8b8fe12 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 15 Mar 2024 08:27:15 +0000 Subject: [PATCH 04/14] ".git/.scripts/commands/fmt/fmt.sh" --- polkadot/xcm/xcm-executor/src/config.rs | 7 ++++++- polkadot/xcm/xcm-executor/src/lib.rs | 18 +++++++++++++----- polkadot/xcm/xcm-executor/src/traits/mod.rs | 4 +++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/config.rs b/polkadot/xcm/xcm-executor/src/config.rs index ee65a5bce783..601d692714cd 100644 --- a/polkadot/xcm/xcm-executor/src/config.rs +++ b/polkadot/xcm/xcm-executor/src/config.rs @@ -14,7 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use crate::traits::{AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm, FeeManager, HandleHrmpChannelAccepted, HandleHrmpChannelClosing, HandleHrmpNewChannelOpenRequest, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader}; +use crate::traits::{ + AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm, + FeeManager, HandleHrmpChannelAccepted, HandleHrmpChannelClosing, + HandleHrmpNewChannelOpenRequest, OnResponse, ProcessTransaction, ShouldExecute, TransactAsset, + VersionChangeNotifier, WeightBounds, WeightTrader, +}; use frame_support::{ dispatch::{GetDispatchInfo, Parameter, PostDispatchInfo}, traits::{Contains, ContainsPair, Get, PalletsInfoAccess}, diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index c73e02f0a8d9..6b0332058d25 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -31,9 +31,10 @@ use xcm::latest::prelude::*; pub mod traits; use traits::{ validate_export, AssetExchange, AssetLock, CallDispatcher, ClaimAssets, ConvertOrigin, - DropAssets, Enact, ExportXcm, FeeManager, FeeReason, OnResponse, ProcessTransaction, + DropAssets, Enact, ExportXcm, FeeManager, FeeReason, HandleHrmpChannelAccepted, + HandleHrmpChannelClosing, HandleHrmpNewChannelOpenRequest, OnResponse, ProcessTransaction, Properties, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader, - XcmAssetTransfers, HandleHrmpNewChannelOpenRequest, HandleHrmpChannelAccepted, HandleHrmpChannelClosing, + XcmAssetTransfers, }; mod assets; @@ -1212,9 +1213,16 @@ impl XcmExecutor { ); Ok(()) }, - HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } => Config::HrmpNewChannelOpenRequestHandler::handle(sender, max_message_size, max_capacity), - HrmpChannelAccepted { recipient } => Config::HrmpChannelAcceptedHandler::handle(recipient), - HrmpChannelClosing { initiator, sender, recipient } => Config::HrmpChannelClosingHandler::handle(initiator, sender, recipient), + HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } => + Config::HrmpNewChannelOpenRequestHandler::handle( + sender, + max_message_size, + max_capacity, + ), + HrmpChannelAccepted { recipient } => + Config::HrmpChannelAcceptedHandler::handle(recipient), + HrmpChannelClosing { initiator, sender, recipient } => + Config::HrmpChannelClosingHandler::handle(initiator, sender, recipient), } } } diff --git a/polkadot/xcm/xcm-executor/src/traits/mod.rs b/polkadot/xcm/xcm-executor/src/traits/mod.rs index 95d985d8c4be..aa3f0d26e302 100644 --- a/polkadot/xcm/xcm-executor/src/traits/mod.rs +++ b/polkadot/xcm/xcm-executor/src/traits/mod.rs @@ -46,7 +46,9 @@ pub use should_execute::{CheckSuspension, Properties, ShouldExecute}; mod transact_asset; pub use transact_asset::TransactAsset; mod hrmp; -pub use hrmp::{HandleHrmpNewChannelOpenRequest, HandleHrmpChannelAccepted, HandleHrmpChannelClosing}; +pub use hrmp::{ + HandleHrmpChannelAccepted, HandleHrmpChannelClosing, HandleHrmpNewChannelOpenRequest, +}; mod weight; #[deprecated = "Use `sp_runtime::traits::` instead"] pub use sp_runtime::traits::{Identity, TryConvertInto as JustTry}; From 094f6f41857adee59d41c13e0fdcfb3db173d9f1 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Fri, 15 Mar 2024 11:12:42 +0100 Subject: [PATCH 05/14] add doc strings --- polkadot/xcm/xcm-executor/src/config.rs | 3 +++ polkadot/xcm/xcm-executor/src/traits/hrmp.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/polkadot/xcm/xcm-executor/src/config.rs b/polkadot/xcm/xcm-executor/src/config.rs index ee65a5bce783..6d050d6e023f 100644 --- a/polkadot/xcm/xcm-executor/src/config.rs +++ b/polkadot/xcm/xcm-executor/src/config.rs @@ -111,7 +111,10 @@ pub trait Config { /// Transactional processor for XCM instructions. type TransactionalProcessor: ProcessTransaction; + /// Allows optional logic execution for the `HrmpNewChannelOpenRequest` XCM notification sent by the relay chain. type HrmpNewChannelOpenRequestHandler: HandleHrmpNewChannelOpenRequest; + /// Allows optional logic execution for the `HrmpChannelAccepted` XCM notification sent by the relay chain. type HrmpChannelAcceptedHandler: HandleHrmpChannelAccepted; + /// Allows optional logic execution for the `HrmpChannelClosing` XCM notification sent by the relay chain. type HrmpChannelClosingHandler: HandleHrmpChannelClosing; } diff --git a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs index c2b8c5604708..d021ed14c0c4 100644 --- a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs +++ b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs @@ -1,11 +1,24 @@ use xcm::v3::prelude::XcmResult; +/// Executes optional logic when a `HrmpNewChannelOpenRequest` XCM notification is received from the relay chain. +/// A chain could, for example, decide to accept it or reject the request based on its own business logic, +/// and send a response back to the relay chain to open/close the channel. pub trait HandleHrmpNewChannelOpenRequest { fn handle(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult; } + +/// Executes optional logic when a `HrmpChannelAccepted` XCM notification is received from the relay chain. +/// If chain `sender` receives this notification, it means that chain `recipient` +/// has accepted the channel `sender` -> `recipient`. +/// The sender chain could, for example, decide to accept the other channel `recipient` -> `sender`, +/// once their request was accepted, by automatically sending a `Transact` message to the relay. pub trait HandleHrmpChannelAccepted { fn handle(recipient: u32) -> XcmResult; } + +/// Executes optional logic when a `HrmpChannelClosing` XCM notification is received from the relay chain. +/// Both `sender` and `recipient` can close the channel, and the opposite party will be notified. +/// The chain could, for example, decide to close the other direction channel once this notification is received. pub trait HandleHrmpChannelClosing { fn handle(initiator: u32, sender: u32, recipient: u32) -> XcmResult; } From c926daa55923c43f5271a79ff7a69bd4372763cd Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Fri, 15 Mar 2024 11:33:42 +0100 Subject: [PATCH 06/14] fix compilation --- cumulus/pallets/xcmp-queue/src/mock.rs | 3 +++ polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs | 3 +++ polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs | 3 +++ polkadot/xcm/pallet-xcm/src/mock.rs | 3 +++ polkadot/xcm/xcm-builder/src/tests/mock.rs | 3 +++ polkadot/xcm/xcm-builder/src/tests/pay/mock.rs | 3 +++ polkadot/xcm/xcm-builder/tests/mock/mod.rs | 3 +++ 7 files changed, 21 insertions(+) diff --git a/cumulus/pallets/xcmp-queue/src/mock.rs b/cumulus/pallets/xcmp-queue/src/mock.rs index 1fb88cafd93c..6d80d33b2187 100644 --- a/cumulus/pallets/xcmp-queue/src/mock.rs +++ b/cumulus/pallets/xcmp-queue/src/mock.rs @@ -175,6 +175,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type XcmRouter = ( diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index 637446832fdc..f5b65c8f10a8 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -145,6 +145,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } impl crate::Config for Test { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index c84f062a8d16..502c020de368 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -135,6 +135,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Aliasers; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } parameter_types! { diff --git a/polkadot/xcm/pallet-xcm/src/mock.rs b/polkadot/xcm/pallet-xcm/src/mock.rs index d5ba7312a3a5..215900526822 100644 --- a/polkadot/xcm/pallet-xcm/src/mock.rs +++ b/polkadot/xcm/pallet-xcm/src/mock.rs @@ -513,6 +513,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; diff --git a/polkadot/xcm/xcm-builder/src/tests/mock.rs b/polkadot/xcm/xcm-builder/src/tests/mock.rs index 4521d5e92a42..4bf347ea7713 100644 --- a/polkadot/xcm/xcm-builder/src/tests/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/mock.rs @@ -743,6 +743,9 @@ impl Config for TestConfig { type SafeCallFilter = Everything; type Aliasers = AliasForeignAccountId32; type TransactionalProcessor = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub fn fungible_multi_asset(location: Location, amount: u128) -> Asset { diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs index 9892c500f2ee..5e215deabf00 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs @@ -218,6 +218,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } parameter_types! { diff --git a/polkadot/xcm/xcm-builder/tests/mock/mod.rs b/polkadot/xcm/xcm-builder/tests/mock/mod.rs index 06cedb9c3577..aaa20401da82 100644 --- a/polkadot/xcm/xcm-builder/tests/mock/mod.rs +++ b/polkadot/xcm/xcm-builder/tests/mock/mod.rs @@ -204,6 +204,9 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type Aliasers = Nothing; type TransactionalProcessor = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } pub type LocalOriginToLocation = SignedToAccountId32; From 258d0dbcd5d75c689374cc3f4a3ea9f9a8ffb542 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Fri, 15 Mar 2024 11:36:31 +0100 Subject: [PATCH 07/14] wrap in transactional processor --- polkadot/xcm/xcm-executor/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index 6b0332058d25..ec2d37f8d381 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -1214,15 +1214,15 @@ impl XcmExecutor { Ok(()) }, HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } => - Config::HrmpNewChannelOpenRequestHandler::handle( + Config::TransactionalProcessor::process(|| Config::HrmpNewChannelOpenRequestHandler::handle( sender, max_message_size, max_capacity, - ), + )), HrmpChannelAccepted { recipient } => - Config::HrmpChannelAcceptedHandler::handle(recipient), + Config::TransactionalProcessor::process(|| Config::HrmpChannelAcceptedHandler::handle(recipient)), HrmpChannelClosing { initiator, sender, recipient } => - Config::HrmpChannelClosingHandler::handle(initiator, sender, recipient), + Config::TransactionalProcessor::process(|| Config::HrmpChannelClosingHandler::handle(initiator, sender, recipient)), } } } From 27ffc19be5d5fc0cfbf252072d3f2790904973a7 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Fri, 15 Mar 2024 14:20:06 +0100 Subject: [PATCH 08/14] fmt --- polkadot/xcm/xcm-executor/src/config.rs | 9 ++++++--- polkadot/xcm/xcm-executor/src/lib.rs | 21 ++++++++++++-------- polkadot/xcm/xcm-executor/src/traits/hrmp.rs | 17 ++++++++-------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/config.rs b/polkadot/xcm/xcm-executor/src/config.rs index 855273b7a60c..dff79f7a8202 100644 --- a/polkadot/xcm/xcm-executor/src/config.rs +++ b/polkadot/xcm/xcm-executor/src/config.rs @@ -116,10 +116,13 @@ pub trait Config { /// Transactional processor for XCM instructions. type TransactionalProcessor: ProcessTransaction; - /// Allows optional logic execution for the `HrmpNewChannelOpenRequest` XCM notification sent by the relay chain. + /// Allows optional logic execution for the `HrmpNewChannelOpenRequest` XCM notification sent by + /// the relay chain. type HrmpNewChannelOpenRequestHandler: HandleHrmpNewChannelOpenRequest; - /// Allows optional logic execution for the `HrmpChannelAccepted` XCM notification sent by the relay chain. + /// Allows optional logic execution for the `HrmpChannelAccepted` XCM notification sent by the + /// relay chain. type HrmpChannelAcceptedHandler: HandleHrmpChannelAccepted; - /// Allows optional logic execution for the `HrmpChannelClosing` XCM notification sent by the relay chain. + /// Allows optional logic execution for the `HrmpChannelClosing` XCM notification sent by the + /// relay chain. type HrmpChannelClosingHandler: HandleHrmpChannelClosing; } diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index ec2d37f8d381..81b81fe6a171 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -1214,15 +1214,20 @@ impl XcmExecutor { Ok(()) }, HrmpNewChannelOpenRequest { sender, max_message_size, max_capacity } => - Config::TransactionalProcessor::process(|| Config::HrmpNewChannelOpenRequestHandler::handle( - sender, - max_message_size, - max_capacity, - )), - HrmpChannelAccepted { recipient } => - Config::TransactionalProcessor::process(|| Config::HrmpChannelAcceptedHandler::handle(recipient)), + Config::TransactionalProcessor::process(|| { + Config::HrmpNewChannelOpenRequestHandler::handle( + sender, + max_message_size, + max_capacity, + ) + }), + HrmpChannelAccepted { recipient } => Config::TransactionalProcessor::process(|| { + Config::HrmpChannelAcceptedHandler::handle(recipient) + }), HrmpChannelClosing { initiator, sender, recipient } => - Config::TransactionalProcessor::process(|| Config::HrmpChannelClosingHandler::handle(initiator, sender, recipient)), + Config::TransactionalProcessor::process(|| { + Config::HrmpChannelClosingHandler::handle(initiator, sender, recipient) + }), } } } diff --git a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs index 9c6dd3df41d8..1eaec2e14360 100644 --- a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs +++ b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs @@ -16,15 +16,15 @@ use xcm::latest::Result as XcmResult; -/// Executes optional logic when a `HrmpNewChannelOpenRequest` XCM notification is received from the relay chain. -/// A chain could, for example, decide to accept it or reject the request based on its own business logic, -/// and send a response back to the relay chain to open/close the channel. +/// Executes optional logic when a `HrmpNewChannelOpenRequest` XCM notification is received from the +/// relay chain. A chain could, for example, decide to accept it or reject the request based on its +/// own business logic, and send a response back to the relay chain to open/close the channel. pub trait HandleHrmpNewChannelOpenRequest { fn handle(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult; } -/// Executes optional logic when a `HrmpChannelAccepted` XCM notification is received from the relay chain. -/// If chain `sender` receives this notification, it means that chain `recipient` +/// Executes optional logic when a `HrmpChannelAccepted` XCM notification is received from the relay +/// chain. If chain `sender` receives this notification, it means that chain `recipient` /// has accepted the channel `sender` -> `recipient`. /// The sender chain could, for example, decide to accept the other channel `recipient` -> `sender`, /// once their request was accepted, by automatically sending a `Transact` message to the relay. @@ -32,9 +32,10 @@ pub trait HandleHrmpChannelAccepted { fn handle(recipient: u32) -> XcmResult; } -/// Executes optional logic when a `HrmpChannelClosing` XCM notification is received from the relay chain. -/// Both `sender` and `recipient` can close the channel, and the opposite party will be notified. -/// The chain could, for example, decide to close the other direction channel once this notification is received. +/// Executes optional logic when a `HrmpChannelClosing` XCM notification is received from the relay +/// chain. Both `sender` and `recipient` can close the channel, and the opposite party will be +/// notified. The chain could, for example, decide to close the other direction channel once this +/// notification is received. pub trait HandleHrmpChannelClosing { fn handle(initiator: u32, sender: u32, recipient: u32) -> XcmResult; } From 9c6b7788882d5fd456b9ad9124b680d7605659e7 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Sat, 16 Mar 2024 06:16:30 +0100 Subject: [PATCH 09/14] Update polkadot/xcm/xcm-executor/src/traits/hrmp.rs --- polkadot/xcm/xcm-executor/src/traits/hrmp.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs index 1eaec2e14360..e169b3e121ae 100644 --- a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs +++ b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs @@ -32,10 +32,7 @@ pub trait HandleHrmpChannelAccepted { fn handle(recipient: u32) -> XcmResult; } -/// Executes optional logic when a `HrmpChannelClosing` XCM notification is received from the relay -/// chain. Both `sender` and `recipient` can close the channel, and the opposite party will be -/// notified. The chain could, for example, decide to close the other direction channel once this -/// notification is received. +/// Executes optional logic when a `HrmpChannelClosing` XCM notification is received. pub trait HandleHrmpChannelClosing { fn handle(initiator: u32, sender: u32, recipient: u32) -> XcmResult; } From ffc98984713f33894c2e95fb1345d7596109d342 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Sat, 16 Mar 2024 06:16:48 +0100 Subject: [PATCH 10/14] Update polkadot/xcm/xcm-executor/src/traits/hrmp.rs --- polkadot/xcm/xcm-executor/src/traits/hrmp.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs index e169b3e121ae..b4e30164adc3 100644 --- a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs +++ b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs @@ -23,11 +23,7 @@ pub trait HandleHrmpNewChannelOpenRequest { fn handle(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult; } -/// Executes optional logic when a `HrmpChannelAccepted` XCM notification is received from the relay -/// chain. If chain `sender` receives this notification, it means that chain `recipient` -/// has accepted the channel `sender` -> `recipient`. -/// The sender chain could, for example, decide to accept the other channel `recipient` -> `sender`, -/// once their request was accepted, by automatically sending a `Transact` message to the relay. +/// Executes optional logic when a `HrmpChannelAccepted` XCM notification is received. pub trait HandleHrmpChannelAccepted { fn handle(recipient: u32) -> XcmResult; } From ea679fdbadae013e6b2c50df874f9bc8da249f85 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Sat, 16 Mar 2024 06:16:59 +0100 Subject: [PATCH 11/14] Update polkadot/xcm/xcm-executor/src/traits/hrmp.rs --- polkadot/xcm/xcm-executor/src/traits/hrmp.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs index b4e30164adc3..b6bbb9316d75 100644 --- a/polkadot/xcm/xcm-executor/src/traits/hrmp.rs +++ b/polkadot/xcm/xcm-executor/src/traits/hrmp.rs @@ -16,9 +16,7 @@ use xcm::latest::Result as XcmResult; -/// Executes optional logic when a `HrmpNewChannelOpenRequest` XCM notification is received from the -/// relay chain. A chain could, for example, decide to accept it or reject the request based on its -/// own business logic, and send a response back to the relay chain to open/close the channel. +/// Executes logic when a `HrmpNewChannelOpenRequest` XCM notification is received. pub trait HandleHrmpNewChannelOpenRequest { fn handle(sender: u32, max_message_size: u32, max_capacity: u32) -> XcmResult; } From 9861959350f286df74e231d9b14cf5b2a43d24ee Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Sat, 16 Mar 2024 06:55:33 +0100 Subject: [PATCH 12/14] Update polkadot/xcm/xcm-executor/src/config.rs --- polkadot/xcm/xcm-executor/src/config.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/polkadot/xcm/xcm-executor/src/config.rs b/polkadot/xcm/xcm-executor/src/config.rs index dff79f7a8202..b296d32ca2ad 100644 --- a/polkadot/xcm/xcm-executor/src/config.rs +++ b/polkadot/xcm/xcm-executor/src/config.rs @@ -116,13 +116,10 @@ pub trait Config { /// Transactional processor for XCM instructions. type TransactionalProcessor: ProcessTransaction; - /// Allows optional logic execution for the `HrmpNewChannelOpenRequest` XCM notification sent by - /// the relay chain. + /// Allows optional logic execution for the `HrmpNewChannelOpenRequest` XCM notification. type HrmpNewChannelOpenRequestHandler: HandleHrmpNewChannelOpenRequest; - /// Allows optional logic execution for the `HrmpChannelAccepted` XCM notification sent by the - /// relay chain. + /// Allows optional logic execution for the `HrmpChannelAccepted` XCM notification. type HrmpChannelAcceptedHandler: HandleHrmpChannelAccepted; - /// Allows optional logic execution for the `HrmpChannelClosing` XCM notification sent by the - /// relay chain. + /// Allows optional logic execution for the `HrmpChannelClosing` XCM notification. type HrmpChannelClosingHandler: HandleHrmpChannelClosing; } From b182c8b1673fa961bc3b7596b17eec9dda971d01 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Mon, 18 Mar 2024 13:06:48 +0100 Subject: [PATCH 13/14] prdoc 3696 --- prdoc/pr_3696.prdoc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 prdoc/pr_3696.prdoc diff --git a/prdoc/pr_3696.prdoc b/prdoc/pr_3696.prdoc new file mode 100644 index 000000000000..463da9c73032 --- /dev/null +++ b/prdoc/pr_3696.prdoc @@ -0,0 +1,17 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Add HRMP notification handlers to the xcm-executor + +doc: + - audience: Runtime Dev + description: | + Adds optional HRMP notification handlers to the xcm-executor. These handlers are 3 new config types on the xcm-executor `Config` trait: + - `HrmpNewChannelOpenRequestHandler` + - `HrmpChannelAcceptedHandler` + - `HrmpChannelClosingHandler` + + The traits of these config types are implemented on tuples, and on `()` for the default case. + +crates: + - name: xcm-executor From c596857226353efe4b0874e427e151eb7afd4d72 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Mon, 18 Mar 2024 14:48:45 +0100 Subject: [PATCH 14/14] rename xcm-executor on prdoc to staging-xcm-executor --- prdoc/pr_3696.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_3696.prdoc b/prdoc/pr_3696.prdoc index 463da9c73032..f3371d1734ad 100644 --- a/prdoc/pr_3696.prdoc +++ b/prdoc/pr_3696.prdoc @@ -14,4 +14,4 @@ doc: The traits of these config types are implemented on tuples, and on `()` for the default case. crates: - - name: xcm-executor + - name: staging-xcm-executor