Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracts Add new version for marking new stable API #3415

Merged
merged 4 commits into from Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -72,5 +72,6 @@ impl Config for Runtime {
type RuntimeHoldReason = RuntimeHoldReason;
type Debug = ();
type Environment = ();
type ApiVersion = ();
type Xcm = pallet_xcm::Pallet<Self>;
}
9 changes: 9 additions & 0 deletions 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
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Expand Up @@ -1367,6 +1367,7 @@ impl pallet_contracts::Config for Runtime {
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type Debug = ();
type Environment = ();
type ApiVersion = ();
type Xcm = ();
}

Expand Down
Expand Up @@ -94,5 +94,6 @@ impl pallet_contracts::Config for Runtime {
type WeightPrice = Self;
type Debug = ();
type Environment = ();
type ApiVersion = ();
type Xcm = pallet_xcm::Pallet<Self>;
}
18 changes: 18 additions & 0 deletions substrate/frame/contracts/src/lib.rs
Expand Up @@ -214,6 +214,18 @@ pub struct Environment<T: Config> {
block_number: EnvironmentType<BlockNumberFor<T>>,
}

/// 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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking about if we're better off using more general semantics here. Something like impl_version that we generally increment every time a host fn is added/stabilized, but also every time we want to communicate some other change, like an important bug fix.

Copy link
Member

@athei athei Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be difficult to do with a linear numbers. Bugfixes will get backported and then this system will fall apart.

#[derive(Encode, Decode, TypeInfo)]
pub struct ApiVersion(u16);
impl Default for ApiVersion {
fn default() -> Self {
Self(1)
}
}

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -402,6 +414,12 @@ pub mod pallet {
#[pallet::constant]
type Environment: Get<Environment<Self>>;

/// The version of the HostFn APIs that are available in the runtime.
///
/// Only valid value is `()`.
#[pallet::constant]
type ApiVersion: Get<ApiVersion>;

/// A type that exposes XCM APIs, allowing contracts to interact with other parachains, and
/// execute XCM programs.
type Xcm: xcm_builder::Controller<
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/contracts/src/tests.rs
Expand Up @@ -465,6 +465,7 @@ impl Config for Test {
type MaxDelegateDependencies = MaxDelegateDependencies;
type Debug = TestDebug;
type Environment = ();
type ApiVersion = ();
type Xcm = ();
}

Expand Down