From 52589808ecdfd0b102640d36646dde4aaa6ad7ab Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Thu, 13 Apr 2023 16:54:14 +0300 Subject: [PATCH 1/3] stabilize call_runtime --- crates/env/Cargo.toml | 3 -- crates/env/src/api.rs | 6 --- crates/env/src/backend.rs | 1 - crates/env/src/engine/off_chain/impls.rs | 1 - crates/env/src/engine/on_chain/ext/riscv32.rs | 1 - crates/env/src/engine/on_chain/ext/wasm32.rs | 2 - crates/env/src/engine/on_chain/impls.rs | 1 - crates/ink/Cargo.toml | 5 --- crates/ink/src/env_access.rs | 1 - integration-tests/call-runtime/Cargo.toml | 6 +-- integration-tests/call-runtime/lib.rs | 41 ------------------- .../custom-environment/Cargo.toml | 3 -- integration-tests/custom-environment/lib.rs | 37 ----------------- 13 files changed, 1 insertion(+), 107 deletions(-) diff --git a/crates/env/Cargo.toml b/crates/env/Cargo.toml index 7157be4b9e6..5ec0d9e56c8 100644 --- a/crates/env/Cargo.toml +++ b/crates/env/Cargo.toml @@ -72,9 +72,6 @@ std = [ "blake2", ] -# Enable direct call to a pallet dispatchable via `call_runtime()`. -call-runtime = [] - # Enable contract debug messages via `debug_print!` and `debug_println!`. ink-debug = [] diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index c1a9a660ff5..f62d2955cad 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -750,15 +750,9 @@ where /// - If the runtime doesn't allow for the contract unstable feature. /// - If the runtime doesn't allow for dispatching this call from a contract. /// -/// # Note -/// -/// The `call_runtime` host function is still part of `pallet-contracts`' unstable -/// interface and thus can be changed at anytime. -/// /// # Panics /// /// Panics in the off-chain environment. -#[cfg(feature = "call-runtime")] pub fn call_runtime(call: &Call) -> Result<()> where E: Environment, diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index fb6b00350c1..05b8f890aa3 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -515,7 +515,6 @@ pub trait TypedEnvBackend: EnvBackend { where E: Environment; - #[cfg(feature = "call-runtime")] fn call_runtime(&mut self, call: &Call) -> Result<()> where E: Environment, diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index 5dbdf6a7733..5475acd2230 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -543,7 +543,6 @@ impl TypedEnvBackend for EnvInstance { unimplemented!("off-chain environment does not support `own_code_hash`") } - #[cfg(feature = "call-runtime")] fn call_runtime(&mut self, _call: &Call) -> Result<()> where E: Environment, diff --git a/crates/env/src/engine/on_chain/ext/riscv32.rs b/crates/env/src/engine/on_chain/ext/riscv32.rs index ba030eb3d98..69dbdd36385 100644 --- a/crates/env/src/engine/on_chain/ext/riscv32.rs +++ b/crates/env/src/engine/on_chain/ext/riscv32.rs @@ -250,7 +250,6 @@ pub fn return_value(flags: ReturnFlags, return_value: &[u8]) -> ! { } } -#[cfg(feature = "call-runtime")] pub fn call_runtime(call: &[u8]) -> Result { let ret_code = (Ptr32::from_slice(call), call.len() as u32) .using_encoded(|in_data| sys::call(FUNC_ID, Ptr32::from_slice(in_data))); diff --git a/crates/env/src/engine/on_chain/ext/wasm32.rs b/crates/env/src/engine/on_chain/ext/wasm32.rs index 790eabc0d39..523b9ad5c4a 100644 --- a/crates/env/src/engine/on_chain/ext/wasm32.rs +++ b/crates/env/src/engine/on_chain/ext/wasm32.rs @@ -153,7 +153,6 @@ mod sys { out_len_ptr: Ptr32Mut, ) -> ReturnCode; - #[cfg(feature = "call-runtime")] pub fn call_runtime(call_ptr: Ptr32<[u8]>, call_len: u32) -> ReturnCode; } @@ -465,7 +464,6 @@ pub fn return_value(flags: ReturnFlags, return_value: &[u8]) -> ! { } } -#[cfg(feature = "call-runtime")] pub fn call_runtime(call: &[u8]) -> Result { let ret_code = unsafe { sys::call_runtime(Ptr32::from_slice(call), call.len() as u32) }; diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index 69747bba5cd..429dba7f4a8 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -578,7 +578,6 @@ impl TypedEnvBackend for EnvInstance { Ok(hash) } - #[cfg(feature = "call-runtime")] fn call_runtime(&mut self, call: &Call) -> Result<()> where E: Environment, diff --git a/crates/ink/Cargo.toml b/crates/ink/Cargo.toml index 1dd74ad93c3..ea209266a20 100644 --- a/crates/ink/Cargo.toml +++ b/crates/ink/Cargo.toml @@ -50,11 +50,6 @@ ink-debug = [ "ink_env/ink-debug", ] -# Enable direct call to a pallet dispatchable via `call_runtime()`. -call-runtime = [ - "ink_env/call-runtime", -] - show-codegen-docs = [] # Disable the ink! provided global memory allocator. diff --git a/crates/ink/src/env_access.rs b/crates/ink/src/env_access.rs index 63c42d01f85..6bab424c629 100644 --- a/crates/ink/src/env_access.rs +++ b/crates/ink/src/env_access.rs @@ -1040,7 +1040,6 @@ where ink_env::set_code_hash2::(code_hash) } - #[cfg(feature = "call-runtime")] pub fn call_runtime(self, call: &Call) -> Result<()> { ink_env::call_runtime::(call) } diff --git a/integration-tests/call-runtime/Cargo.toml b/integration-tests/call-runtime/Cargo.toml index 84538775554..84d5c9a6ab9 100644 --- a/integration-tests/call-runtime/Cargo.toml +++ b/integration-tests/call-runtime/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" publish = false [dependencies] -ink = { path = "../../crates/ink", default-features = false, features = ["call-runtime"] } +ink = { path = "../../crates/ink", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.5", default-features = false, features = ["derive"], optional = true } @@ -37,7 +37,3 @@ std = [ ] ink-as-dependency = [] e2e-tests = [] - -# Assumes that the node used in E2E testing allows using the `call-runtime` API, including triggering -# `Balances::transfer` extrinsic. -permissive-node = [] diff --git a/integration-tests/call-runtime/lib.rs b/integration-tests/call-runtime/lib.rs index 7bf35e12507..a95991544d7 100644 --- a/integration-tests/call-runtime/lib.rs +++ b/integration-tests/call-runtime/lib.rs @@ -82,8 +82,6 @@ mod runtime_call { /// /// Fails if: /// - called in the off-chain environment - /// - the chain doesn't allow `call-runtime` API (`UnsafeUnstableInterface` is - /// turned off) /// - the chain forbids contracts to call `Balances::transfer` (`CallFilter` is /// too restrictive) /// - after the transfer, `receiver` doesn't have at least existential deposit @@ -133,7 +131,6 @@ mod runtime_call { const UNIT: Balance = 1_000_000_000_000; /// The contract will be given 1000 tokens during instantiation. - #[cfg(feature = "permissive-node")] const CONTRACT_BALANCE: Balance = 1_000 * UNIT; /// The receiver will get enough funds to have the required existential deposit. @@ -145,14 +142,11 @@ mod runtime_call { /// empty account fails. /// /// Must not be zero, because such an operation would be a successful no-op. - #[cfg(feature = "permissive-node")] const INSUFFICIENT_TRANSFER_VALUE: Balance = 1; /// Positive case scenario: - /// - `call_runtime` is enabled /// - the call is valid /// - the call execution succeeds - #[cfg(feature = "permissive-node")] #[ink_e2e::test] async fn transfer_with_call_runtime_works( mut client: Client, @@ -216,10 +210,8 @@ mod runtime_call { } /// Negative case scenario: - /// - `call_runtime` is enabled /// - the call is valid /// - the call execution fails - #[cfg(feature = "permissive-node")] #[ink_e2e::test] async fn transfer_with_call_runtime_fails_when_execution_fails( mut client: Client, @@ -258,9 +250,7 @@ mod runtime_call { } /// Negative case scenario: - /// - `call_runtime` is enabled /// - the call is invalid - #[cfg(feature = "permissive-node")] #[ink_e2e::test] async fn transfer_with_call_runtime_fails_when_call_is_invalid( mut client: Client, @@ -292,36 +282,5 @@ mod runtime_call { Ok(()) } - - /// Negative case scenario: - /// - `call_runtime` is disabled - #[cfg(not(feature = "permissive-node"))] - #[ink_e2e::test] - async fn call_runtime_fails_when_forbidden( - mut client: Client, - ) -> E2EResult<()> { - // given - let constructor = RuntimeCallerRef::new(); - let contract_acc_id = client - .instantiate("call-runtime", &ink_e2e::alice(), constructor, 0, None) - .await - .expect("instantiate failed") - .account_id; - - let receiver: AccountId = default_accounts::().bob; - - let transfer_message = build_message::(contract_acc_id) - .call(|caller| caller.transfer_through_runtime(receiver, TRANSFER_VALUE)); - - // when - let call_res = client - .call(&ink_e2e::alice(), transfer_message, 0, None) - .await; - - // then - assert!(matches!(call_res, Err(ink_e2e::Error::CallExtrinsic(_)))); - - Ok(()) - } } } diff --git a/integration-tests/custom-environment/Cargo.toml b/integration-tests/custom-environment/Cargo.toml index f05547dfe9b..396632fc9a5 100644 --- a/integration-tests/custom-environment/Cargo.toml +++ b/integration-tests/custom-environment/Cargo.toml @@ -26,6 +26,3 @@ std = [ ] ink-as-dependency = [] e2e-tests = [] - -# Assumes that the node used in E2E testing allows for at least 6 event topics. -permissive-node = [] diff --git a/integration-tests/custom-environment/lib.rs b/integration-tests/custom-environment/lib.rs index b83fcfd70a8..7e6d1fd4a1e 100644 --- a/integration-tests/custom-environment/lib.rs +++ b/integration-tests/custom-environment/lib.rs @@ -96,7 +96,6 @@ mod runtime_call { type E2EResult = Result>; - #[cfg(feature = "permissive-node")] #[ink_e2e::test(environment = crate::EnvironmentWithManyTopics)] async fn calling_custom_environment_works( mut client: Client, @@ -132,41 +131,5 @@ mod runtime_call { Ok(()) } - - #[cfg(not(feature = "permissive-node"))] - #[ink_e2e::test(environment = crate::EnvironmentWithManyTopics)] - async fn calling_custom_environment_fails_if_incompatible_with_node( - mut client: Client, - ) -> E2EResult<()> { - // given - let constructor = TopicsRef::new(); - let contract_acc_id = client - .instantiate( - "custom-environment", - &ink_e2e::alice(), - constructor, - 0, - None, - ) - .await - .expect("instantiate failed") - .account_id; - - let message = - MessageBuilder::::from_account_id( - contract_acc_id, - ) - .call(|caller| caller.trigger()); - - // when - let call_res = client - .call_dry_run(&ink_e2e::alice(), &message, 0, None) - .await; - - // then - assert!(call_res.is_err()); - - Ok(()) - } } } From fc2a4311b13d4369c6b4209d681c1e2ddd43b67f Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Thu, 13 Apr 2023 16:58:46 +0300 Subject: [PATCH 2/3] changelog update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d0e6dc0f45..cb1464f73ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Stabilize `call_runtime` ‒ [#1749](https://github.com/paritytech/ink/pull/1749) ### Changed - Upgraded `syn` to version `2` - [#1731](https://github.com/paritytech/ink/pull/1731) From e267dd15730c3d19d5030fa440292f849acf9960 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Fri, 26 May 2023 17:57:00 +0300 Subject: [PATCH 3/3] fix test --- integration-tests/call-runtime/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/call-runtime/lib.rs b/integration-tests/call-runtime/lib.rs index 321fca06551..919a06f525b 100644 --- a/integration-tests/call-runtime/lib.rs +++ b/integration-tests/call-runtime/lib.rs @@ -167,7 +167,7 @@ mod runtime_call { let receiver: AccountId = default_accounts::().bob; let contract_balance_before = client - .balance(contract_acc_id) + .balance(contract.account_id) .await .expect("Failed to get account balance"); let receiver_balance_before = client @@ -188,7 +188,7 @@ mod runtime_call { // then let contract_balance_after = client - .balance(contract_acc_id) + .balance(contract.account_id) .await .expect("Failed to get account balance"); let receiver_balance_after = client