From 231acca72cb80f42f8cb510c9e3ab43e21205238 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Fri, 23 Feb 2024 10:34:23 +0100 Subject: [PATCH 1/4] Fixes --- substrate/bin/node/runtime/src/lib.rs | 1 + substrate/frame/contracts/src/lib.rs | 19 +++++++++++++++++++ substrate/frame/contracts/src/tests.rs | 1 + 3 files changed, 21 insertions(+) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 24c8f6f48e96..b34d8c89e568 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1367,6 +1367,7 @@ impl pallet_contracts::Config for Runtime { type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent; type Debug = (); type Environment = (); + type ApiVersion = (); type Xcm = (); } diff --git a/substrate/frame/contracts/src/lib.rs b/substrate/frame/contracts/src/lib.rs index 533085f2b874..e16877d6880e 100644 --- a/substrate/frame/contracts/src/lib.rs +++ b/substrate/frame/contracts/src/lib.rs @@ -214,6 +214,19 @@ pub struct Environment { block_number: EnvironmentType>, } +/// Defines the current version of the HostFn APIs. +/// This is used to communicate the available APIs in pallet-contracts. +/// +/// The version is bumped any time a new HostFn is added or stabilized. +#[derive(Encode, Decode, TypeInfo)] +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +pub struct ApiVersion(u16); +impl Default for ApiVersion { + fn default() -> Self { + Self(1) + } +} + #[frame_support::pallet] pub mod pallet { use super::*; @@ -402,6 +415,12 @@ pub mod pallet { #[pallet::constant] type Environment: Get>; + /// The version of the HostFn APIs that are available in the runtime. + /// + /// Only valid value is `()`. + #[pallet::constant] + type ApiVersion: Get; + /// A type that exposes XCM APIs, allowing contracts to interact with other parachains, and /// execute XCM programs. type Xcm: xcm_builder::Controller< diff --git a/substrate/frame/contracts/src/tests.rs b/substrate/frame/contracts/src/tests.rs index a06b65b86b5a..0dce84bf9728 100644 --- a/substrate/frame/contracts/src/tests.rs +++ b/substrate/frame/contracts/src/tests.rs @@ -465,6 +465,7 @@ impl Config for Test { type MaxDelegateDependencies = MaxDelegateDependencies; type Debug = TestDebug; type Environment = (); + type ApiVersion = (); type Xcm = (); } From 905c5cf1f0b5047b6b72488b9a8a99ccb77a9b8e Mon Sep 17 00:00:00 2001 From: pgherveou Date: Fri, 23 Feb 2024 10:39:38 +0100 Subject: [PATCH 2/4] fix --- substrate/frame/contracts/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/frame/contracts/src/lib.rs b/substrate/frame/contracts/src/lib.rs index e16877d6880e..314a7044778b 100644 --- a/substrate/frame/contracts/src/lib.rs +++ b/substrate/frame/contracts/src/lib.rs @@ -219,7 +219,6 @@ pub struct Environment { /// /// The version is bumped any time a new HostFn is added or stabilized. #[derive(Encode, Decode, TypeInfo)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub struct ApiVersion(u16); impl Default for ApiVersion { fn default() -> Self { From 510b9cdba9b4ec787d89fcfda87f21ff526bdfb4 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Fri, 23 Feb 2024 10:45:52 +0100 Subject: [PATCH 3/4] Add prdoc --- prdoc/pr_3415.prdoc | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 prdoc/pr_3415.prdoc diff --git a/prdoc/pr_3415.prdoc b/prdoc/pr_3415.prdoc new file mode 100644 index 000000000000..c56a5d3ffaa1 --- /dev/null +++ b/prdoc/pr_3415.prdoc @@ -0,0 +1,9 @@ +title: "[pallet-contracts] Add APIVersion to the config." + +doc: + - audience: Runtime Dev + description: | + Add `APIVersion` to the config to communicate the state of the Host functions exposed by the pallet. + +crates: + - name: pallet-contracts From 3e4a7fde411a14ceb6e9fc619c567eaa3c665a61 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Fri, 23 Feb 2024 10:47:44 +0100 Subject: [PATCH 4/4] Fix missing --- .../runtimes/contracts/contracts-rococo/src/contracts.rs | 1 + .../contracts/mock-network/src/parachain/contracts_config.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/contracts.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/contracts.rs index 7b89f2df8077..681b95ce6a53 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/contracts.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/contracts.rs @@ -72,5 +72,6 @@ impl Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type Debug = (); type Environment = (); + type ApiVersion = (); type Xcm = pallet_xcm::Pallet; } diff --git a/substrate/frame/contracts/mock-network/src/parachain/contracts_config.rs b/substrate/frame/contracts/mock-network/src/parachain/contracts_config.rs index dadba394e264..3f26c6f372ef 100644 --- a/substrate/frame/contracts/mock-network/src/parachain/contracts_config.rs +++ b/substrate/frame/contracts/mock-network/src/parachain/contracts_config.rs @@ -94,5 +94,6 @@ impl pallet_contracts::Config for Runtime { type WeightPrice = Self; type Debug = (); type Environment = (); + type ApiVersion = (); type Xcm = pallet_xcm::Pallet; }