Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,6 @@ impl pallet_revive::Config for Runtime {
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
type UnsafeUnstableInterface = ConstBool<false>;
type AllowEVMBytecode = ConstBool<true>;
type UploadOrigin = EnsureSigned<Self::AccountId>;
type InstantiateOrigin = EnsureSigned<Self::AccountId>;
Expand Down
1 change: 0 additions & 1 deletion cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,6 @@ impl pallet_revive::Config for Runtime {
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
type UnsafeUnstableInterface = ConstBool<true>;
type AllowEVMBytecode = ConstBool<true>;
type UploadOrigin = EnsureSigned<Self::AccountId>;
type InstantiateOrigin = EnsureSigned<Self::AccountId>;
Expand Down
20 changes: 20 additions & 0 deletions prdoc/pr_10712.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
title: '[pallet-revive] remove code related to stable and unstable_hostfn'
doc:
- audience: Runtime Dev
description: |-
Part of https://github.com/paritytech/polkadot-sdk/issues/8572

Removes the proc macro `unstable_hostfn` and attribute `#[stable]` because they are not used anywhere.
crates:
- name: pallet-revive-proc-macro
bump: patch
- name: pallet-revive
bump: major
- name: pallet-revive-fixtures
bump: patch
- name: pallet-revive-uapi
bump: major
- name: asset-hub-westend-runtime
bump: patch
- name: penpal-runtime
bump: patch
1 change: 0 additions & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,6 @@ impl pallet_revive::Config for Runtime {
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
type UnsafeUnstableInterface = ConstBool<false>;
type UploadOrigin = EnsureSigned<Self::AccountId>;
type InstantiateOrigin = EnsureSigned<Self::AccountId>;
type RuntimeHoldReason = RuntimeHoldReason;
Expand Down
15 changes: 0 additions & 15 deletions substrate/frame/revive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,4 @@ Example:
cargo run --release -- --dev -lerror,runtime::revive::strace=trace,runtime::revive=debug
```

## Unstable Interfaces

Driven by the desire to have an iterative approach in developing new contract interfaces this pallet contains the
concept of an unstable interface. Akin to the rust nightly compiler it allows us to add new interfaces but mark them as
unstable so that contract languages can experiment with them and give feedback before we stabilize those.

In order to access interfaces which don't have a stable `#[stable]` in [`runtime.rs`](src/vm/runtime.rs)
one need to set `pallet_revive::Config::UnsafeUnstableInterface` to `ConstU32<true>`.
**It should be obvious that any production runtime should never be compiled with this feature: In addition to be
subject to change or removal those interfaces might not have proper weights associated with them and are therefore
considered unsafe**.

New interfaces are generally added as unstable and might go through several iterations before they are promoted to a
stable interface.

License: Apache-2.0
2 changes: 1 addition & 1 deletion substrate/frame/revive/fixtures/build/_Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2021"

# All paths are injected dynamically by the build script.
[dependencies]
uapi = { package = 'pallet-revive-uapi', features = ["unstable-hostfn"], default-features = false }
uapi = { package = 'pallet-revive-uapi', default-features = false }
hex-literal = { version = "0.4.1", default-features = false }
polkavm-derive = { version = "0.30.0" }

Expand Down
47 changes: 7 additions & 40 deletions substrate/frame/revive/proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ use proc_macro2::{Literal, Span, TokenStream as TokenStream2};
use quote::{quote, ToTokens};
use syn::{parse_quote, punctuated::Punctuated, spanned::Spanned, token::Comma, FnArg, Ident};

#[proc_macro_attribute]
pub fn unstable_hostfn(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::Item);
let expanded = quote! {
#[cfg(feature = "unstable-hostfn")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-hostfn")))]
#input
};
expanded.into()
}

/// Defines a host functions set that can be imported by contract polkavm code.
///
/// **CAUTION**: Be advised that all functions defined by this macro
Expand Down Expand Up @@ -71,7 +60,6 @@ struct EnvDef {
/// Parsed host function definition.
struct HostFn {
item: syn::ItemFn,
is_stable: bool,
name: String,
returns: HostFnReturn,
cfg: Option<syn::Attribute>,
Expand Down Expand Up @@ -135,22 +123,15 @@ impl HostFn {
};

// process attributes
let msg = "Only #[stable], #[cfg] and #[mutating] attributes are allowed.";
let msg = "Only #[cfg] and #[mutating] attributes are allowed.";
let span = item.span();
let mut attrs = item.attrs.clone();
attrs.retain(|a| !a.path().is_ident("doc"));
let mut is_stable = false;
let mut mutating = false;
let mut cfg = None;
while let Some(attr) = attrs.pop() {
let ident = attr.path().get_ident().ok_or(err(span, msg))?.to_string();
match ident.as_str() {
"stable" => {
if is_stable {
return Err(err(span, "#[stable] can only be specified once"))
}
is_stable = true;
},
"mutating" => {
if mutating {
return Err(err(span, "#[mutating] can only be specified once"))
Expand Down Expand Up @@ -264,7 +245,7 @@ impl HostFn {
_ => Err(err(arg1.span(), &msg)),
}?;

Ok(Self { item, is_stable, name, returns, cfg })
Ok(Self { item, name, returns, cfg })
},
_ => Err(err(span, &msg)),
}
Expand Down Expand Up @@ -335,16 +316,11 @@ fn expand_env(def: &EnvDef) -> TokenStream2 {
let impls = expand_functions(def);
let bench_impls = expand_bench_functions(def);
let docs = expand_func_doc(def);
let stable_syscalls = expand_func_list(def, false);
let all_syscalls = expand_func_list(def, true);
let all_syscalls = expand_func_list(def);

quote! {
pub fn list_syscalls(include_unstable: bool) -> &'static [&'static [u8]] {
if include_unstable {
#all_syscalls
} else {
#stable_syscalls
}
pub fn list_syscalls() -> &'static [&'static [u8]] {
#all_syscalls
}

impl<'a, E: Ext, M: PolkaVmInstance<E::T>> Runtime<'a, E, M> {
Expand Down Expand Up @@ -512,17 +488,8 @@ fn expand_func_doc(def: &EnvDef) -> TokenStream2 {
});
quote! { #( #docs )* }
};
let availability = if func.is_stable {
let info = "\n# Stable API\nThis API is stable and will never change.";
quote! { #[doc = #info] }
} else {
let info =
"\n# Unstable API\nThis API is not standardized and only available for testing.";
quote! { #[doc = #info] }
};
quote! {
#func_docs
#availability
}
};
quote! {
Expand All @@ -536,8 +503,8 @@ fn expand_func_doc(def: &EnvDef) -> TokenStream2 {
}
}

fn expand_func_list(def: &EnvDef, include_unstable: bool) -> TokenStream2 {
let docs = def.host_funcs.iter().filter(|f| include_unstable || f.is_stable).map(|f| {
fn expand_func_list(def: &EnvDef) -> TokenStream2 {
let docs = def.host_funcs.iter().map(|f| {
let name = Literal::byte_string(f.name.as_bytes());
quote! {
#name.as_slice()
Expand Down
13 changes: 0 additions & 13 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,6 @@ pub mod pallet {
#[pallet::no_default]
type AddressMapper: AddressMapper<Self>;

/// Make contract callable functions marked as `#[unstable]` available.
///
/// Contracts that use `#[unstable]` functions won't be able to be uploaded unless
/// this is set to `true`. This is only meant for testnets and dev nodes in order to
/// experiment with new features.
///
/// # Warning
///
/// Do **not** set to `true` on productions chains.
#[pallet::constant]
type UnsafeUnstableInterface: Get<bool>;

/// Allow EVM bytecode to be uploaded and instantiated.
#[pallet::constant]
type AllowEVMBytecode: Get<bool>;
Expand Down Expand Up @@ -438,7 +426,6 @@ pub mod pallet {
type DepositPerItem = DepositPerItem;
type DepositPerChildTrieItem = DepositPerChildTrieItem;
type Time = Self;
type UnsafeUnstableInterface = ConstBool<true>;
type AllowEVMBytecode = ConstBool<true>;
type UploadOrigin = EnsureSigned<Self::AccountId>;
type InstantiateOrigin = EnsureSigned<Self::AccountId>;
Expand Down
6 changes: 0 additions & 6 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ pub(crate) mod builder {
}

impl Test {
pub fn set_unstable_interface(unstable_interface: bool) {
UNSTABLE_INTERFACE.with(|v| *v.borrow_mut() = unstable_interface);
}

pub fn set_allow_evm_bytecode(allow_evm_bytecode: bool) {
ALLOW_EVM_BYTECODE.with(|v| *v.borrow_mut() = allow_evm_bytecode);
}
Expand Down Expand Up @@ -372,7 +368,6 @@ where
}
}
parameter_types! {
pub static UnstableInterface: bool = true;
pub static AllowEvmBytecode: bool = true;
pub CheckingAccount: AccountId32 = BOB.clone();
pub static DebugFlag: bool = false;
Expand All @@ -396,7 +391,6 @@ impl Config for Test {
type DepositPerByte = DepositPerByte;
type DepositPerItem = DepositPerItem;
type DepositPerChildTrieItem = DepositPerItem;
type UnsafeUnstableInterface = UnstableInterface;
type AllowEVMBytecode = AllowEvmBytecode;
type UploadOrigin = EnsureAccount<Self, UploadAccount>;
type InstantiateOrigin = EnsureAccount<Self, InstantiateAccount>;
Expand Down
Loading
Loading