diff --git a/Cargo.lock b/Cargo.lock index 1675162eae9b..a127d7be786f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8706,6 +8706,14 @@ dependencies = [ "winapi", ] +[[package]] +name = "hrmp-primitives" +version = "0.1.0" +dependencies = [ + "parity-scale-codec", + "scale-info", +] + [[package]] name = "http" version = "0.2.9" @@ -13500,6 +13508,26 @@ dependencies = [ "sp-tracing 16.0.0", ] +[[package]] +name = "pallet-hrmp-para" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "pallet-hrmp-relay" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "pallet-identity" version = "29.0.0" @@ -14156,6 +14184,26 @@ dependencies = [ "sp-runtime 31.0.1", ] +[[package]] +name = "pallet-registrar-para" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "pallet-registrar-relay" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", +] + [[package]] name = "pallet-remark" version = "28.0.0" @@ -19725,6 +19773,14 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "registrar-primitives" +version = "0.1.0" +dependencies = [ + "parity-scale-codec", + "scale-info", +] + [[package]] name = "relative-path" version = "1.9.2" diff --git a/Cargo.toml b/Cargo.toml index 4f7d1fcbb4b6..9fb11bd0d77e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -389,6 +389,9 @@ members = [ "substrate/frame/grandpa", "substrate/frame/honzon/oracle", "substrate/frame/honzon/oracle/runtime-api", + "substrate/frame/hrmp/para", + "substrate/frame/hrmp/primitives", + "substrate/frame/hrmp/relay", "substrate/frame/identity", "substrate/frame/im-online", "substrate/frame/indices", @@ -428,6 +431,9 @@ members = [ "substrate/frame/ranked-collective", "substrate/frame/recovery", "substrate/frame/referenda", + "substrate/frame/registrar/para", + "substrate/frame/registrar/primitives", + "substrate/frame/registrar/relay", "substrate/frame/remark", "substrate/frame/revive", "substrate/frame/revive/dev-node/node", diff --git a/substrate/frame/hrmp/README.md b/substrate/frame/hrmp/README.md new file mode 100644 index 000000000000..79d039f01264 --- /dev/null +++ b/substrate/frame/hrmp/README.md @@ -0,0 +1,5 @@ +# HRMP channels + +- `para/` — `pallet-hrmp-para`: user facing control-plane, runs on a parachain. +- `relay/` — `pallet-hrmp-relay`: receives messages from the parachain, runs on the relay chain. +- `primitives/` — `hrmp-primitives`: shared parachain<->relay XCM message types. diff --git a/substrate/frame/hrmp/para/Cargo.toml b/substrate/frame/hrmp/para/Cargo.toml new file mode 100644 index 000000000000..1b17f2bf9199 --- /dev/null +++ b/substrate/frame/hrmp/para/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "pallet-hrmp-para" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +homepage.workspace = true +repository.workspace = true +description = "User facing control plane for managing HRMP channels that are stored on the relay chain." + +[package.metadata.polkadot-sdk] +exclude-from-umbrella = true + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { workspace = true, features = ["derive"] } +frame-support = { workspace = true } +frame-system = { workspace = true } +scale-info = { workspace = true, features = ["derive"] } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", +] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] diff --git a/substrate/frame/hrmp/para/src/lib.rs b/substrate/frame/hrmp/para/src/lib.rs new file mode 100644 index 000000000000..54b54912ae2c --- /dev/null +++ b/substrate/frame/hrmp/para/src/lib.rs @@ -0,0 +1,58 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! # Parachain HRMP pallet +//! +//! User-facing half of HRMP channel management. Runs on a parachain, holding channel deposits and +//! driving open / accept / close on the relay-chain counterpart ([`pallet-hrmp-relay`]) over XCM. + +#![cfg_attr(not(feature = "std"), no_std)] + +pub use pallet::*; + +/// Used to send an XCM `Transact` to the HRMP pallet on the remote relay chain. +pub trait SendToRelay {} + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + /// Sends messages to the relay chain. + type SendToRelay: SendToRelay; + } + + #[pallet::pallet] + pub struct Pallet(_); + + // - TODO: hrmp_init_open_channel — request to open a channel; holds the sender deposit, XCM to + // the relay. + + // - TODO: hrmp_accept_open_channel — accept a pending open request; holds the recipient + // deposit. + + // - TODO: hrmp_close_channel — close a channel; releases both deposits. + + // - TODO: hrmp_cancel_open_request — cancel a pending open request; releases the sender + // deposit. + + // - TODO: establish_channel_with_system — open a bidirectional channel with a system chain (no + // deposit). + + // - TODO: poke_channel_deposits — re-sync a channel's deposits to the current config. +} diff --git a/substrate/frame/hrmp/primitives/Cargo.toml b/substrate/frame/hrmp/primitives/Cargo.toml new file mode 100644 index 000000000000..47e83cf2da09 --- /dev/null +++ b/substrate/frame/hrmp/primitives/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "hrmp-primitives" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +homepage.workspace = true +repository.workspace = true +description = "Shared Para<->Relay message types." + +[package.metadata.polkadot-sdk] +exclude-from-umbrella = true + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { workspace = true, features = ["derive"] } +scale-info = { workspace = true, features = ["derive"] } + +[features] +default = ["std"] +std = [ + "codec/std", + "scale-info/std", +] diff --git a/substrate/frame/hrmp/primitives/src/lib.rs b/substrate/frame/hrmp/primitives/src/lib.rs new file mode 100644 index 000000000000..ff12d858b1d8 --- /dev/null +++ b/substrate/frame/hrmp/primitives/src/lib.rs @@ -0,0 +1,62 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! # HRMP-channel shared primitives +//! +//! Types shared by the parachain pallet ([`pallet-hrmp-para`]) and relay-chain pallet +//! ([`pallet-hrmp-relay`]). This crate is deliberately free of any FRAME, XCM, or network-specific +//! dependency, so a single version of the wire types serves Westend, Kusama and Polkadot, and so +//! both pallets can depend on it without forming a dependency cycle. + +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::{Decode, Encode}; +use scale_info::TypeInfo; + +/// HRMP control-plane messages sent to the relay chain. +/// +/// The variant's `#[codec(index)]` is the on-wire version tag. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo)] +pub enum MessageToRelay { + /// Version 1 of the HRMP control-plane messages to the relay chain. + #[codec(index = 0)] + V1(MessageToRelayV1), +} + +/// Version 1 payloads for [`MessageToRelay`]. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo)] +pub enum MessageToRelayV1 { + #[codec(index = 0)] + TODO, +} + +/// HRMP report messages sent back to the parachain. +/// +/// The variant's `#[codec(index)]` is the on-wire version tag. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo)] +pub enum MessageToPara { + /// Version 1 of the HRMP report messages to the parachain. + #[codec(index = 0)] + V1(MessageToParaV1), +} + +/// Version 1 payloads for [`MessageToPara`]. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo)] +pub enum MessageToParaV1 { + #[codec(index = 0)] + TODO, +} diff --git a/substrate/frame/hrmp/relay/Cargo.toml b/substrate/frame/hrmp/relay/Cargo.toml new file mode 100644 index 000000000000..cdc0f09f8245 --- /dev/null +++ b/substrate/frame/hrmp/relay/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "pallet-hrmp-relay" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +homepage.workspace = true +repository.workspace = true +description = "Relay pallet as counter-part for the pallet-hrmp-para" + +[package.metadata.polkadot-sdk] +exclude-from-umbrella = true + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { workspace = true, features = ["derive"] } +frame-support = { workspace = true } +frame-system = { workspace = true } +scale-info = { workspace = true, features = ["derive"] } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", +] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] diff --git a/substrate/frame/hrmp/relay/src/lib.rs b/substrate/frame/hrmp/relay/src/lib.rs new file mode 100644 index 000000000000..7449110cb70b --- /dev/null +++ b/substrate/frame/hrmp/relay/src/lib.rs @@ -0,0 +1,45 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! # Relay-chain HRMP pallet +//! +//! Relay half of HRMP channel management. Runs on the relay chain, applying channel operations +//! received from a parachain ([`pallet-hrmp-para`]) to the relay's legacy `hrmp` routing table and +//! reporting back. + +#![cfg_attr(not(feature = "std"), no_std)] + +pub use pallet::*; + +/// Used to send an XCM `Transact` to the HRMP pallet on the remote parachain. +pub trait SendToPara {} + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + /// Sends messages to the parachain. + type SendToPara: SendToPara; + } + + #[pallet::pallet] + pub struct Pallet(_); + + // - TODO: Extrinsic to accept the messages from the para. +} diff --git a/substrate/frame/registrar/README.md b/substrate/frame/registrar/README.md new file mode 100644 index 000000000000..f102e5395ad6 --- /dev/null +++ b/substrate/frame/registrar/README.md @@ -0,0 +1,5 @@ +# Parachain registrar + +- `para/` — `pallet-registrar-para`: user facing control-plane, runs on a parachain. +- `relay/` — `pallet-registrar-relay`: receives messages from the parachain, runs on the relay chain. +- `primitives/` — `registrar-primitives`: shared parachain<->relay XCM message types. diff --git a/substrate/frame/registrar/para/Cargo.toml b/substrate/frame/registrar/para/Cargo.toml new file mode 100644 index 000000000000..a4be56e781a7 --- /dev/null +++ b/substrate/frame/registrar/para/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "pallet-registrar-para" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +homepage.workspace = true +repository.workspace = true +description = "User facing control plane for managing parachain registrations that are stored on the relay chain." + +[package.metadata.polkadot-sdk] +exclude-from-umbrella = true + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { workspace = true, features = ["derive"] } +frame-support = { workspace = true } +frame-system = { workspace = true } +scale-info = { workspace = true, features = ["derive"] } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", +] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] diff --git a/substrate/frame/registrar/para/src/lib.rs b/substrate/frame/registrar/para/src/lib.rs new file mode 100644 index 000000000000..e62a6d509c61 --- /dev/null +++ b/substrate/frame/registrar/para/src/lib.rs @@ -0,0 +1,59 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! # User Interface Pallet For Parachain Registrations +//! +//! This pallet exposes the extrinsics that can be used to manage parachain registrations. It +//! communicates over XCM with the `pallet-registrar-relay` + +#![cfg_attr(not(feature = "std"), no_std)] + +pub use pallet::*; + +/// Used to send an XCM `Transact` to the registrar pallet on the remote relay chain. +pub trait SendToRelay {} + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + /// Sends messages to the relay chain. + type SendToRelay: SendToRelay; + } + + #[pallet::pallet] + pub struct Pallet(_); + + // - TODO: reserve — reserve a ParaId; holds the ParaId deposit. + + // - TODO: register — register code+head for a reserved ParaId; holds the code deposit, + // XCM-authorizes on the relay. + + // - TODO: deregister — free the ParaId; releases both deposits. + + // - TODO: swap — swap the slots of two paras. (Do we still need this? leases are deprecated) + + // - TODO: add_lock — add the manager lock. + + // - TODO: remove_lock — remove the manager lock. + + // - TODO: schedule_code_upgrade — schedule a validation-code upgrade (XCM to the relay). + + // - TODO: set_current_head — set the current head data (XCM to the relay). +} diff --git a/substrate/frame/registrar/primitives/Cargo.toml b/substrate/frame/registrar/primitives/Cargo.toml new file mode 100644 index 000000000000..9d835da3cd18 --- /dev/null +++ b/substrate/frame/registrar/primitives/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "registrar-primitives" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +homepage.workspace = true +repository.workspace = true +description = "Shared Para<->Relay message types." + +[package.metadata.polkadot-sdk] +exclude-from-umbrella = true + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { workspace = true, features = ["derive"] } +scale-info = { workspace = true, features = ["derive"] } + +[features] +default = ["std"] +std = [ + "codec/std", + "scale-info/std", +] diff --git a/substrate/frame/registrar/primitives/src/lib.rs b/substrate/frame/registrar/primitives/src/lib.rs new file mode 100644 index 000000000000..7bb1d60189c3 --- /dev/null +++ b/substrate/frame/registrar/primitives/src/lib.rs @@ -0,0 +1,62 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! # Parachain-registrar shared primitives +//! +//! Types shared by the parachain registrar pallet ([`pallet-registrar-para`]) and relay-chain +//! registrar pallet ([`pallet-registrar-relay`]). This crate is deliberately free of any FRAME, +//! XCM, or network-specific dependency, so a single version of the wire types serves Westend, +//! Kusama and Polkadot, and so both pallets can depend on it without forming a dependency cycle. + +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::{Decode, Encode}; +use scale_info::TypeInfo; + +/// Registrar control-plane messages sent to the relay chain. +/// +/// The variant's `#[codec(index)]` is the on-wire version tag. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo)] +pub enum MessageToRelay { + /// Version 1 of the registrar control-plane messages to the relay chain. + #[codec(index = 0)] + V1(MessageToRelayV1), +} + +/// Version 1 payloads for [`MessageToRelay`]. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo)] +pub enum MessageToRelayV1 { + #[codec(index = 0)] + TODO, +} + +/// Registrar report messages sent back to the parachain. +/// +/// The variant's `#[codec(index)]` is the on-wire version tag. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo)] +pub enum MessageToPara { + /// Version 1 of the registrar report messages to the parachain. + #[codec(index = 0)] + V1(MessageToParaV1), +} + +/// Version 1 payloads for [`MessageToPara`]. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo)] +pub enum MessageToParaV1 { + #[codec(index = 0)] + TODO, +} diff --git a/substrate/frame/registrar/relay/Cargo.toml b/substrate/frame/registrar/relay/Cargo.toml new file mode 100644 index 000000000000..6acfaf00e7e4 --- /dev/null +++ b/substrate/frame/registrar/relay/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "pallet-registrar-relay" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +homepage.workspace = true +repository.workspace = true +description = "Relay pallet as counter-part for the pallet-registrar-para" + +[package.metadata.polkadot-sdk] +exclude-from-umbrella = true + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { workspace = true, features = ["derive"] } +frame-support = { workspace = true } +frame-system = { workspace = true } +scale-info = { workspace = true, features = ["derive"] } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", +] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] diff --git a/substrate/frame/registrar/relay/src/lib.rs b/substrate/frame/registrar/relay/src/lib.rs new file mode 100644 index 000000000000..6bf51522c11e --- /dev/null +++ b/substrate/frame/registrar/relay/src/lib.rs @@ -0,0 +1,47 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! # Relay-chain registrar pallet +//! +//! Relay half of the parachain registrar. Runs on the relay chain, applying registrations +//! authorized on a parachain ([`pallet-registrar-para`]) and driving the relay's legacy `paras` +//! state. + +#![cfg_attr(not(feature = "std"), no_std)] + +pub use pallet::*; + +/// Used to send an XCM `Transact` to the registrar pallet on the remote parachain. +pub trait SendToPara {} + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + /// Sends messages to the parachain. + type SendToPara: SendToPara; + } + + #[pallet::pallet] + pub struct Pallet(_); + + // - TODO: Extrinsic to accept the messages from the para. + + // - TODO: Accept unsigned TX for PVF upload +}