From 9ea95ff78dc3f22dea08f0d78e9e4c0a6f0e6b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Wed, 24 Nov 2021 15:55:36 +0100 Subject: [PATCH] Remove the state rent API (#1036) * Remove the state rent API * Apply `cargo fmt`, make clippy happy * Make clippy happy * Remove unused `sp-arithmetic` dep * Remove `RentFraction` and related deps * Update test fixtures --- RELEASES.md | 3 + crates/engine/src/ext.rs | 45 +--- crates/engine/src/lib.rs | 1 - crates/engine/src/types.rs | 1 + crates/env/Cargo.toml | 1 - crates/env/src/api.rs | 146 +----------- crates/env/src/backend.rs | 58 ----- .../engine/experimental_off_chain/impls.rs | 64 ------ .../engine/experimental_off_chain/test_api.rs | 35 --- .../env/src/engine/off_chain/db/accounts.rs | 32 +-- .../env/src/engine/off_chain/db/chain_spec.rs | 37 +-- crates/env/src/engine/off_chain/impls.rs | 95 -------- crates/env/src/engine/off_chain/mod.rs | 1 - crates/env/src/engine/off_chain/test_api.rs | 49 ---- crates/env/src/engine/off_chain/types.rs | 4 - crates/env/src/engine/on_chain/ext.rs | 99 +------- crates/env/src/engine/on_chain/impls.rs | 60 ----- crates/env/src/error.rs | 2 +- crates/env/src/lib.rs | 3 - crates/env/src/types.rs | 112 --------- crates/lang/macro/src/lib.rs | 4 - crates/lang/src/env_access.rs | 214 +----------------- crates/lang/src/reflect/contract.rs | 1 - .../tests/ui/chain_extension/E-01-simple.rs | 1 - .../fail/event-too-many-topics-anonymous.rs | 1 - .../event-too-many-topics-anonymous.stderr | 18 +- .../ui/contract/fail/event-too-many-topics.rs | 1 - .../fail/event-too-many-topics.stderr | 18 +- .../ui/contract/pass/config-custom-env.rs | 3 - .../contract/pass/event-config-more-topics.rs | 1 - examples/contract-transfer/lib.rs | 6 +- examples/rand-extension/lib.rs | 1 - 32 files changed, 36 insertions(+), 1081 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 5a712a603e..f75f59b775 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -2,6 +2,9 @@ This is the 7th release candidate for ink! 3.0. +## Removed +- Removed the state rent API ‒ [#1036](https://github.com/paritytech/ink/pull/1036). + ## Added - The ink! codegen now heavily relies on static type information based on traits defined in `ink_lang`. - Some of those traits and their carried information can be used for static reflection of ink! diff --git a/crates/engine/src/ext.rs b/crates/engine/src/ext.rs index a28957954c..47a4c97005 100644 --- a/crates/engine/src/ext.rs +++ b/crates/engine/src/ext.rs @@ -24,10 +24,7 @@ use crate::{ DebugInfo, EmittedEvent, }, - types::{ - AccountId, - Key, - }, + types::AccountId, }; use std::panic::panic_any; @@ -89,7 +86,7 @@ define_error_codes! { NewContractNotFunded = 6, /// No code could be found at the supplied code hash. CodeNotFound = 7, - /// The account that was called is either no contract (e.g. user account) or is a tombstone. + /// The account that was called is no contract, but a plain account. NotCallable = 8, /// The call to `seal_debug_message` had no effect because debug message /// recording was disabled. @@ -244,9 +241,6 @@ impl Engine { self.transfer(beneficiary, value) .expect("transfer did not work"); - // What is currently missing is to set a tombstone with a code hash here - // and remove the contract storage subsequently. - // Encode the result of the termination and panic with it. // This enables testing for the proper result and makes sure this // method returns `Never`. @@ -299,29 +293,6 @@ impl Engine { set_output(output, callee) } - /// Restores a tombstone to the original smart contract. - /// - /// # Params - /// - /// - `account_id`: Encoded bytes of the `AccountId` of the to-be-restored contract. - /// - `code_hash`: Encoded code hash of the to-be-restored contract. - /// - `rent_allowance`: The encoded rent allowance of the restored contract - /// upon successful restoration. - /// - `filtered_keys`: Storage keys that will be ignored for the tombstone hash - /// match calculation that decide whether the original contract - /// storage and the storage of the restorer contract is equal. - pub fn restore_to( - &mut self, - _account_id: &[u8], - _code_hash: &[u8], - _rent_allowance: &[u8], - filtered_keys: &[&[u8]], - ) { - let _filtered_keys: Vec = - filtered_keys.iter().map(|k| Key::from_bytes(k)).collect(); - unimplemented!("off-chain environment does not yet support `restore_to`"); - } - /// Records the given debug message and appends to stdout. pub fn debug_message(&mut self, message: &str) { self.debug_info.record_debug_message(String::from(message)); @@ -360,18 +331,10 @@ impl Engine { unimplemented!("off-chain environment does not yet support `gas_left`"); } - pub fn rent_allowance(&self, _output: &mut &mut [u8]) { - unimplemented!("off-chain environment does not yet support `rent_allowance`"); - } - pub fn minimum_balance(&self, _output: &mut &mut [u8]) { unimplemented!("off-chain environment does not yet support `minimum_balance`"); } - pub fn tombstone_deposit(&self, _output: &mut &mut [u8]) { - unimplemented!("off-chain environment does not yet support `tombstone_deposit`"); - } - #[allow(clippy::too_many_arguments)] pub fn instantiate( &mut self, @@ -401,10 +364,6 @@ impl Engine { unimplemented!("off-chain environment does not yet support `weight_to_fee`"); } - pub fn set_rent_allowance(&mut self, _value: &[u8]) { - unimplemented!("off-chain environment does not yet support `set_rent_allowance`"); - } - pub fn random(&self, _subject: &[u8], _output: &mut &mut [u8]) { unimplemented!("off-chain environment does not yet support `random`"); } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index a6deba086e..ca1c306750 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -24,7 +24,6 @@ mod types; mod tests; pub use types::AccountError; -use types::Key; use derive_more::From; diff --git a/crates/engine/src/types.rs b/crates/engine/src/types.rs index 5237f7a594..0f94cf9908 100644 --- a/crates/engine/src/types.rs +++ b/crates/engine/src/types.rs @@ -49,6 +49,7 @@ pub struct Key(Vec); impl Key { /// Creates a new `Key` from the given raw bytes. + #[allow(dead_code)] pub fn from_bytes(bytes: &[u8]) -> Self { Self(bytes.to_vec()) } diff --git a/crates/env/Cargo.toml b/crates/env/Cargo.toml index abafb26179..2a901d1c5e 100644 --- a/crates/env/Cargo.toml +++ b/crates/env/Cargo.toml @@ -27,7 +27,6 @@ cfg-if = "1.0" paste = "1.0" arrayref = "0.3" static_assertions = "1.1" -sp-arithmetic = { version = "3.0", default-features = false } [target.'cfg(target_arch = "wasm32")'.dependencies] libsecp256k1 = { version = "0.7.0", default-features = false } diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index d9a4bcc28d..3f4891984f 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -34,10 +34,6 @@ use crate::{ HashOutput, }, topics::Topics, - types::{ - RentParams, - RentStatus, - }, Environment, Result, }; @@ -145,56 +141,6 @@ where }) } -/// Returns the current rent allowance for the executed contract. -/// -/// # Errors -/// -/// If the returned value cannot be properly decoded. -pub fn rent_allowance() -> T::Balance -where - T: Environment, -{ - ::on_instance(|instance| { - TypedEnvBackend::rent_allowance::(instance) - }) -} - -/// Returns information needed for rent calculations. -/// -/// # Errors -/// -/// If the returned value cannot be properly decoded. -pub fn rent_params() -> Result> -where - T: Environment, -{ - ::on_instance(|instance| { - TypedEnvBackend::rent_params::(instance) - }) -} - -/// Returns information about the required deposit and resulting rent. -/// -/// # Parameters -/// -/// - `at_refcount`: The `refcount` assumed for the returned `custom_refcount_*` fields. -/// If `None` is supplied the `custom_refcount_*` fields will also be `None`. -/// -/// The `current_*` fields of `RentStatus` do **not** consider changes to the code's -/// `refcount` made during the currently running call. -/// -/// # Errors -/// -/// If the returned value cannot be properly decoded. -pub fn rent_status(at_refcount: Option) -> Result> -where - T: Environment, -{ - ::on_instance(|instance| { - TypedEnvBackend::rent_status::(instance, at_refcount) - }) -} - /// Returns the current block number. /// /// # Errors @@ -223,20 +169,6 @@ where }) } -/// Returns the tombstone deposit for the contracts chain. -/// -/// # Errors -/// -/// If the returned value cannot be properly decoded. -pub fn tombstone_deposit() -> T::Balance -where - T: Environment, -{ - ::on_instance(|instance| { - TypedEnvBackend::tombstone_deposit::(instance) - }) -} - /// Emits an event with the given event data. pub fn emit_event(event: Event) where @@ -248,16 +180,6 @@ where }) } -/// Sets the rent allowance of the executed contract to the new value. -pub fn set_rent_allowance(new_value: T::Balance) -where - T: Environment, -{ - ::on_instance(|instance| { - TypedEnvBackend::set_rent_allowance::(instance, new_value) - }) -} - /// Writes the value to the contract storage under the given key. /// /// # Panics @@ -306,7 +228,6 @@ pub fn clear_contract_storage(key: &Key) { /// /// - If the called account does not exist. /// - If the called account is not a contract. -/// - If the called contract is a tombstone. /// - If arguments passed to the called contract message are invalid. /// - If the called contract execution has trapped. /// - If the called contract ran out of gas upon execution. @@ -331,7 +252,6 @@ where /// /// - If the called account does not exist. /// - If the called account is not a contract. -/// - If the called contract is a tombstone. /// - If arguments passed to the called contract message are invalid. /// - If the called contract execution has trapped. /// - If the called contract ran out of gas upon execution. @@ -375,75 +295,11 @@ where }) } -/// Restores a smart contract in tombstone state. -/// -/// # Params -/// -/// - `account_id`: Account ID of the to-be-restored contract. -/// - `code_hash`: Code hash of the to-be-restored contract. -/// - `rent_allowance`: Rent allowance of the restored contract -/// upon successful restoration. -/// - `filtered_keys`: Storage keys to be excluded when calculating the tombstone hash, -/// which is used to decide whether the original contract and the -/// to-be-restored contract have matching storage. -/// -/// # Usage -/// -/// A smart contract that has too few funds to pay for its storage fees -/// can eventually be evicted. An evicted smart contract `C` leaves behind -/// a tombstone associated with a hash that has been computed partially -/// by its storage contents. -/// -/// To restore contract `C` back to a fully working contract the normal -/// process is to write another contract `C2` with the only purpose to -/// eventually have the absolutely same contract storage as `C` did when -/// it was evicted. -/// For that purpose `C2` can use other storage keys that have not been in -/// use by contract `C`. -/// Once `C2` contract storage matches the storage of `C` when it was evicted -/// `C2` can invoke this method in order to initiate restoration of `C`. -/// A tombstone hash is calculated for `C2` and if it matches the tombstone -/// hash of `C` the restoration is going to be successful. -/// The `filtered_keys` argument can be used to ignore the extraneous keys -/// used by `C2` but not used by `C`. -/// -/// The process of such a smart contract restoration can generally be very expensive. -/// -/// # Note -/// -/// - `filtered_keys` can be used to ignore certain storage regions -/// in the restorer contract to not influence the hash calculations. -/// - Does *not* perform restoration right away but defers it to the end of -/// the contract execution. -/// - Restoration is canceled if there is no tombstone in the destination -/// address or if the hashes don't match. No changes are made in this case. -pub fn restore_contract( - account_id: T::AccountId, - code_hash: T::Hash, - rent_allowance: T::Balance, - filtered_keys: &[Key], -) where - T: Environment, -{ - ::on_instance(|instance| { - TypedEnvBackend::restore_contract::( - instance, - account_id, - code_hash, - rent_allowance, - filtered_keys, - ) - }) -} - -/// Terminates the existence of the currently executed smart contract -/// without creating a tombstone. +/// Terminates the existence of the currently executed smart contract. /// /// This removes the calling account and transfers all remaining balance /// to the given beneficiary. /// -/// No tombstone will be created, this function kills a contract completely! -/// /// # Note /// /// This function never returns. Either the termination was successful and the diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index 743ecdfc35..84c6df038c 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -23,10 +23,6 @@ use crate::{ HashOutput, }, topics::Topics, - types::{ - RentParams, - RentStatus, - }, Environment, Result, }; @@ -336,30 +332,6 @@ pub trait TypedEnvBackend: EnvBackend { /// For more details visit: [`balance`][`crate::balance`] fn balance(&mut self) -> T::Balance; - /// Returns the current rent allowance for the executed contract. - /// - /// # Note - /// - /// For more details visit: [`rent_allowance`][`crate::rent_allowance`] - fn rent_allowance(&mut self) -> T::Balance; - - /// Returns information needed for rent calculations. - /// - /// # Note - /// - /// For more details visit: [`RentParams`][`crate::RentParams`] - fn rent_params(&mut self) -> Result>; - - /// Returns information about the required deposit and resulting rent. - /// - /// # Note - /// - /// For more details visit: [`RentStatus`][`crate::RentStatus`] - fn rent_status( - &mut self, - at_refcount: Option, - ) -> Result>; - /// Returns the current block number. /// /// # Note @@ -374,13 +346,6 @@ pub trait TypedEnvBackend: EnvBackend { /// For more details visit: [`minimum_balance`][`crate::minimum_balance`] fn minimum_balance(&mut self) -> T::Balance; - /// Returns the tombstone deposit of the contract chain. - /// - /// # Note - /// - /// For more details visit: [`tombstone_deposit`][`crate::tombstone_deposit`] - fn tombstone_deposit(&mut self) -> T::Balance; - /// Emits an event with the given event data. /// /// # Note @@ -391,15 +356,6 @@ pub trait TypedEnvBackend: EnvBackend { T: Environment, Event: Topics + scale::Encode; - /// Sets the rent allowance of the executed contract to the new value. - /// - /// # Note - /// - /// For more details visit: [`set_rent_allowance`][`crate::set_rent_allowance`] - fn set_rent_allowance(&mut self, new_value: T::Balance) - where - T: Environment; - /// Invokes a contract message. /// /// # Note @@ -441,20 +397,6 @@ pub trait TypedEnvBackend: EnvBackend { Args: scale::Encode, Salt: AsRef<[u8]>; - /// Restores a smart contract tombstone. - /// - /// # Note - /// - /// For more details visit: [`restore_contract`][`crate::restore_contract`] - fn restore_contract( - &mut self, - account_id: T::AccountId, - code_hash: T::Hash, - rent_allowance: T::Balance, - filtered_keys: &[Key], - ) where - T: Environment; - /// Terminates a smart contract. /// /// # Note diff --git a/crates/env/src/engine/experimental_off_chain/impls.rs b/crates/env/src/engine/experimental_off_chain/impls.rs index 98f754a352..29fcff4d26 100644 --- a/crates/env/src/engine/experimental_off_chain/impls.rs +++ b/crates/env/src/engine/experimental_off_chain/impls.rs @@ -35,8 +35,6 @@ use crate::{ EnvBackend, Environment, Error, - RentParams, - RentStatus, Result, ReturnFlags, TypedEnvBackend, @@ -354,30 +352,6 @@ impl TypedEnvBackend for EnvInstance { }) } - fn rent_allowance(&mut self) -> T::Balance { - self.get_property::(Engine::rent_allowance) - .unwrap_or_else(|error| { - panic!("could not read `rent_allowance` property: {:?}", error) - }) - } - - fn rent_params(&mut self) -> Result> - where - T: Environment, - { - unimplemented!("off-chain environment does not support rent params") - } - - fn rent_status( - &mut self, - _at_refcount: Option, - ) -> Result> - where - T: Environment, - { - unimplemented!("off-chain environment does not support rent status") - } - fn block_number(&mut self) -> T::BlockNumber { self.get_property::(Engine::block_number) .unwrap_or_else(|error| { @@ -392,13 +366,6 @@ impl TypedEnvBackend for EnvInstance { }) } - fn tombstone_deposit(&mut self) -> T::Balance { - self.get_property::(Engine::tombstone_deposit) - .unwrap_or_else(|error| { - panic!("could not read `tombstone_deposit` property: {:?}", error) - }) - } - fn emit_event(&mut self, event: Event) where T: Environment, @@ -410,14 +377,6 @@ impl TypedEnvBackend for EnvInstance { self.engine.deposit_event(&enc_topics[..], enc_data); } - fn set_rent_allowance(&mut self, new_value: T::Balance) - where - T: Environment, - { - let buffer = &scale::Encode::encode(&new_value)[..]; - self.engine.set_rent_allowance(buffer) - } - fn invoke_contract(&mut self, params: &CallParams) -> Result<()> where T: Environment, @@ -460,29 +419,6 @@ impl TypedEnvBackend for EnvInstance { unimplemented!("off-chain environment does not support contract instantiation") } - fn restore_contract( - &mut self, - account_id: T::AccountId, - code_hash: T::Hash, - rent_allowance: T::Balance, - filtered_keys: &[Key], - ) where - T: Environment, - { - let enc_account_id = &scale::Encode::encode(&account_id)[..]; - let enc_code_hash = &scale::Encode::encode(&code_hash)[..]; - let enc_rent_allowance = &scale::Encode::encode(&rent_allowance)[..]; - - let filtered: Vec<&[u8]> = - filtered_keys.iter().map(|k| &k.as_ref()[..]).collect(); - self.engine.restore_to( - enc_account_id, - enc_code_hash, - enc_rent_allowance, - &filtered[..], - ); - } - fn terminate_contract(&mut self, beneficiary: T::AccountId) -> ! where T: Environment, diff --git a/crates/env/src/engine/experimental_off_chain/test_api.rs b/crates/env/src/engine/experimental_off_chain/test_api.rs index aebdb46c7b..7bedddf04e 100644 --- a/crates/env/src/engine/experimental_off_chain/test_api.rs +++ b/crates/env/src/engine/experimental_off_chain/test_api.rs @@ -82,41 +82,6 @@ where }) } -/// Sets the rent allowance of the contract account to the given rent allowance. -/// -/// # Errors -/// -/// - If `account` does not exist. -/// - If the underlying `account` type does not match. -/// - If the underlying `new_rent_allowance` type does not match. -pub fn set_contract_rent_allowance( - _account_id: T::AccountId, - _new_rent_allowance: T::Balance, -) -> Result<()> -where - T: Environment, -{ - unimplemented!( - "off-chain environment does not yet support `set_contract_rent_allowance`" - ); -} - -/// Returns the rent allowance of the contract account. -/// -/// # Errors -/// -/// - If `account` does not exist. -/// - If the underlying `account` type does not match. -/// - If the returned rent allowance cannot be properly decoded. -pub fn get_contract_rent_allowance(_account_id: T::AccountId) -> Result -where - T: Environment, -{ - unimplemented!( - "off-chain environment does not yet support `get_contract_rent_allowance`" - ); -} - /// Set the entropy hash of the current block. /// /// # Note diff --git a/crates/env/src/engine/off_chain/db/accounts.rs b/crates/env/src/engine/off_chain/db/accounts.rs index e23f9ce474..2b36d13f09 100644 --- a/crates/env/src/engine/off_chain/db/accounts.rs +++ b/crates/env/src/engine/off_chain/db/accounts.rs @@ -150,7 +150,6 @@ impl AccountsDb { &mut self, account_id: T::AccountId, initial_balance: T::Balance, - rent_allowance: T::Balance, ) where T: Environment, { @@ -158,7 +157,7 @@ impl AccountsDb { OffAccountId::new(&account_id), Account { balance: OffBalance::new(&initial_balance), - kind: AccountKind::Contract(ContractAccount::new::(rent_allowance)), + kind: AccountKind::Contract(ContractAccount::new::()), }, ); } @@ -217,28 +216,6 @@ impl Account { } } - /// Returns the rent allowance of the contract account or an error. - pub fn rent_allowance(&self) -> Result - where - T: Environment, - { - self.contract_or_err() - .and_then(|contract| contract.rent_allowance.decode().map_err(Into::into)) - } - - /// Sets the rent allowance for the contract account or returns an error. - pub fn set_rent_allowance(&mut self, new_rent_allowance: T::Balance) -> Result<()> - where - T: Environment, - { - self.contract_or_err_mut().and_then(|contract| { - contract - .rent_allowance - .assign(&new_rent_allowance) - .map_err(Into::into) - }) - } - /// Sets the contract storage of key to the new value. pub fn set_storage(&mut self, at: Key, new_value: &T) -> Result<()> where @@ -285,20 +262,17 @@ pub enum AccountKind { /// Extraneous fields for contract accounts. pub struct ContractAccount { - /// The contract's rent allowance. - rent_allowance: OffBalance, /// The contract storage. pub storage: ContractStorage, } impl ContractAccount { - /// Creates a new contract account with the given initial rent allowance. - pub fn new(rent_allowance: T::Balance) -> Self + /// Creates a new contract account. + pub fn new() -> Self where T: Environment, { Self { - rent_allowance: OffBalance::new(&rent_allowance), storage: ContractStorage::new(), } } diff --git a/crates/env/src/engine/off_chain/db/chain_spec.rs b/crates/env/src/engine/off_chain/db/chain_spec.rs index 444accff60..5edd6b1846 100644 --- a/crates/env/src/engine/off_chain/db/chain_spec.rs +++ b/crates/env/src/engine/off_chain/db/chain_spec.rs @@ -17,20 +17,14 @@ use super::{ OffBalance, OffTimestamp, }; -use crate::{ - engine::off_chain::types::OffRentFraction, - Environment, -}; -use sp_arithmetic::PerThing; +use crate::Environment; /// The chain specification. pub struct ChainSpec { /// The current gas price. gas_price: OffBalance, - /// The minimum value an account of the chain may have. + /// The minimum value an account of the chain must have. minimum_balance: OffBalance, - /// The tombstone deposit. - tombstone_deposit: OffBalance, /// The targeted block time. block_time: OffTimestamp, /// The balance a contract needs to deposit per storage byte to stay alive indefinitely. @@ -39,8 +33,6 @@ pub struct ChainSpec { deposit_per_contract: OffBalance, /// The balance a contract needs to deposit per storage item to stay alive indefinitely. deposit_per_storage_item: OffBalance, - /// The fraction of the deposit costs that should be used as rent per block. - rent_fraction: OffRentFraction, } impl ChainSpec { @@ -49,12 +41,10 @@ impl ChainSpec { Self { gas_price: OffBalance::uninitialized(), minimum_balance: OffBalance::uninitialized(), - tombstone_deposit: OffBalance::uninitialized(), block_time: OffTimestamp::uninitialized(), deposit_per_storage_byte: OffBalance::uninitialized(), deposit_per_contract: OffBalance::uninitialized(), deposit_per_storage_item: OffBalance::uninitialized(), - rent_fraction: OffRentFraction::uninitialized(), } } @@ -62,12 +52,10 @@ impl ChainSpec { pub fn reset(&mut self) { self.gas_price = OffBalance::uninitialized(); self.minimum_balance = OffBalance::uninitialized(); - self.tombstone_deposit = OffBalance::uninitialized(); self.block_time = OffTimestamp::uninitialized(); self.deposit_per_storage_byte = OffBalance::uninitialized(); self.deposit_per_contract = OffBalance::uninitialized(); self.deposit_per_storage_item = OffBalance::uninitialized(); - self.rent_fraction = OffRentFraction::uninitialized(); } /// Default initialization for the off-chain specification. @@ -80,8 +68,6 @@ impl ChainSpec { .try_initialize::(&T::Balance::from(100u32))?; self.minimum_balance .try_initialize::(&T::Balance::from(42u32))?; - self.tombstone_deposit - .try_initialize::(&T::Balance::from(16u32))?; self.block_time .try_initialize::(&T::Timestamp::from(5u32))?; @@ -94,9 +80,6 @@ impl ChainSpec { ))?; self.deposit_per_storage_item .try_initialize::(&T::Balance::from(10_000u32))?; - self.rent_fraction.try_initialize::( - &T::RentFraction::from_rational_approximation(4, 10_000), - )?; Ok(()) } @@ -125,14 +108,6 @@ impl ChainSpec { self.minimum_balance.decode().map_err(Into::into) } - /// Returns the tombstone deposit for the chain. - pub fn tombstone_deposit(&self) -> Result - where - T: Environment, - { - self.tombstone_deposit.decode().map_err(Into::into) - } - /// Returns the targeted block time for the chain. pub fn block_time(&self) -> Result where @@ -164,12 +139,4 @@ impl ChainSpec { { self.deposit_per_storage_item.decode().map_err(Into::into) } - - /// The fraction of the deposit costs that should be used as rent per block. - pub fn rent_fraction(&self) -> Result - where - T: Environment, - { - self.rent_fraction.decode().map_err(Into::into) - } } diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index 2b25b45ddf..2c82f9ce9f 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -32,10 +32,6 @@ use crate::{ Sha2x256, }, topics::Topics, - types::{ - RentParams, - RentStatus, - }, EnvBackend, Environment, Error, @@ -308,10 +304,6 @@ impl EnvInstance { let contract_id = self.account_id::(); self.accounts.remove_account::(contract_id); - // The on-chain implementation would set a tombstone with a code hash here - // and remove the contract storage subsequently. Both is not easily achievable - // with our current off-chain env, hence we left it out here for the moment. - // Encode the result of the termination and panic with it. // This enables testing for the proper result and makes sure this // method returns `Never`. @@ -384,64 +376,6 @@ impl TypedEnvBackend for EnvInstance { }) } - fn rent_allowance(&mut self) -> T::Balance { - self.callee_account() - .rent_allowance::() - .unwrap_or_else(|error| { - panic!("could not read `rent_allowance` property: {:?}", error) - }) - } - - fn rent_params(&mut self) -> Result> - where - T: Environment, - { - use crate::arithmetic::Saturating as _; - - let total_balance = self.balance::(); - - // the off-chain environment does currently not support reserved balance, - // hence we just use the total balance here. - let free_balance = self.balance::(); - - let deposit_per_contract = self.chain_spec.deposit_per_contract::()?; - let deposit_per_storage_byte = self.chain_spec.deposit_per_storage_byte::()?; - let deposit_per_storage_item = self.chain_spec.deposit_per_storage_item::()?; - let rent_fraction = self.chain_spec.rent_fraction::()?; - let minimum_balance: T::Balance = self.minimum_balance::(); - let tombstone_deposit = self.tombstone_deposit::(); - let subsistence_threshold = minimum_balance.saturating_add(tombstone_deposit); - let rent_allowance = self.rent_allowance::(); - - Ok(RentParams { - deposit_per_contract, - deposit_per_storage_byte, - deposit_per_storage_item, - rent_fraction, - subsistence_threshold, - - rent_allowance, - total_balance, - free_balance, - - storage_size: 0, - code_size: 0, - code_refcount: 0, - - _reserved: None, - }) - } - - fn rent_status( - &mut self, - _at_refcount: Option, - ) -> Result> - where - T: Environment, - { - unimplemented!("off-chain environment does not support rent status") - } - fn block_number(&mut self) -> T::BlockNumber { self.current_block() .expect(UNINITIALIZED_EXEC_CONTEXT) @@ -459,14 +393,6 @@ impl TypedEnvBackend for EnvInstance { }) } - fn tombstone_deposit(&mut self) -> T::Balance { - self.chain_spec - .tombstone_deposit::() - .unwrap_or_else(|error| { - panic!("could not read `tombstone_deposit` property: {:?}", error) - }) - } - fn emit_event(&mut self, new_event: Event) where T: Environment, @@ -475,15 +401,6 @@ impl TypedEnvBackend for EnvInstance { self.emitted_events.record::(new_event) } - fn set_rent_allowance(&mut self, new_rent_allowance: T::Balance) - where - T: Environment, - { - self.callee_account_mut() - .set_rent_allowance::(new_rent_allowance) - .expect("could not encode rent allowance") - } - fn invoke_contract(&mut self, params: &CallParams) -> Result<()> where T: Environment, @@ -533,18 +450,6 @@ impl TypedEnvBackend for EnvInstance { self.terminate_contract_impl::(beneficiary) } - fn restore_contract( - &mut self, - _account_id: T::AccountId, - _code_hash: T::Hash, - _rent_allowance: T::Balance, - _filtered_keys: &[Key], - ) where - T: Environment, - { - unimplemented!("off-chain environment does not support contract restoration") - } - fn transfer(&mut self, destination: T::AccountId, value: T::Balance) -> Result<()> where T: Environment, diff --git a/crates/env/src/engine/off_chain/mod.rs b/crates/env/src/engine/off_chain/mod.rs index 6ff31e65d8..df1e0767d1 100644 --- a/crates/env/src/engine/off_chain/mod.rs +++ b/crates/env/src/engine/off_chain/mod.rs @@ -194,7 +194,6 @@ impl EnvInstance { self.accounts.add_contract_account::( contract_account_id.clone(), T::Balance::from(0u32), - T::Balance::from(20u32), ); // Initialize the execution context for the first contract execution. use crate::call::Selector; diff --git a/crates/env/src/engine/off_chain/test_api.rs b/crates/env/src/engine/off_chain/test_api.rs index ff3e9c8236..e7048f80f2 100644 --- a/crates/env/src/engine/off_chain/test_api.rs +++ b/crates/env/src/engine/off_chain/test_api.rs @@ -130,55 +130,6 @@ where }) } -/// Sets the rent allowance of the contract account to the given rent allowance. -/// -/// # Errors -/// -/// - If `account` does not exist. -/// - If the underlying `account` type does not match. -/// - If the underlying `new_rent_allowance` type does not match. -pub fn set_contract_rent_allowance( - account_id: T::AccountId, - new_rent_allowance: T::Balance, -) -> Result<()> -where - T: Environment, -{ - ::on_instance(|instance| { - instance - .accounts - .get_account_mut::(&account_id) - .ok_or_else(|| AccountError::no_account_for_id::(&account_id)) - .map_err(Into::into) - .and_then(|account| { - account - .set_rent_allowance::(new_rent_allowance) - .map_err(Into::into) - }) - }) -} - -/// Returns the rent allowance of the contract account. -/// -/// # Errors -/// -/// - If `account` does not exist. -/// - If the underlying `account` type does not match. -/// - If the returned rent allowance cannot be properly decoded. -pub fn get_contract_rent_allowance(account_id: T::AccountId) -> Result -where - T: Environment, -{ - ::on_instance(|instance| { - instance - .accounts - .get_account::(&account_id) - .ok_or_else(|| AccountError::no_account_for_id::(&account_id)) - .map_err(Into::into) - .and_then(|account| account.rent_allowance::().map_err(Into::into)) - }) -} - /// Registers a new chain extension. pub fn register_chain_extension(extension: E) where diff --git a/crates/env/src/engine/off_chain/types.rs b/crates/env/src/engine/off_chain/types.rs index 4e86a4a6c5..55d4c1fd14 100644 --- a/crates/env/src/engine/off_chain/types.rs +++ b/crates/env/src/engine/off_chain/types.rs @@ -40,8 +40,6 @@ mod type_marker { #[derive(Debug, Clone)] pub enum OffTimestamp {} /// Type marker representing an environmental `BlockNumber`. #[derive(Debug, Clone)] pub enum BlockNumber {} - /// Type marker representing an environmental `RentFraction`. - #[derive(Debug, Clone)] pub enum RentFraction {} } /// Off-chain environment account ID type. @@ -54,5 +52,3 @@ pub type OffHash = TypedEncoded; pub type OffTimestamp = TypedEncoded; /// Off-chain environment block number type. pub type OffBlockNumber = TypedEncoded; -/// Off-chain environment rent fraction type. -pub type OffRentFraction = TypedEncoded; diff --git a/crates/env/src/engine/on_chain/ext.rs b/crates/env/src/engine/on_chain/ext.rs index badbb39be8..a2051dd344 100644 --- a/crates/env/src/engine/on_chain/ext.rs +++ b/crates/env/src/engine/on_chain/ext.rs @@ -18,7 +18,6 @@ use crate::ReturnFlags; use core::marker::PhantomData; -use ink_primitives::Key; macro_rules! define_error_codes { ( @@ -74,7 +73,7 @@ define_error_codes! { NewContractNotFunded = 6, /// No code could be found at the supplied code hash. CodeNotFound = 7, - /// The account that was called is either no contract (e.g. user account) or is a tombstone. + /// The account that was called is no contract. NotCallable = 8, /// The call to `seal_debug_message` had no effect because debug message /// recording was disabled. @@ -195,7 +194,6 @@ type Result = core::result::Result<(), Error>; mod sys { use super::{ - Key, Ptr32, Ptr32Mut, ReturnCode, @@ -245,16 +243,6 @@ mod sys { ) -> ReturnCode; pub fn seal_clear_storage(key_ptr: Ptr32<[u8]>); - pub fn seal_restore_to( - dest_ptr: Ptr32<[u8]>, - dest_len: u32, - code_hash_ptr: Ptr32<[u8]>, - code_hash_len: u32, - rent_allowance_ptr: Ptr32<[u8]>, - rent_allowance_len: u32, - delta_ptr: Ptr32<[Key]>, - delta_count: u32, - ); pub fn seal_terminate(beneficiary_ptr: Ptr32<[u8]>, beneficiary_len: u32) -> !; pub fn seal_call_chain_extension( @@ -286,20 +274,10 @@ mod sys { output_len_ptr: Ptr32Mut, ); pub fn seal_now(output_ptr: Ptr32Mut<[u8]>, output_len_ptr: Ptr32Mut); - pub fn seal_rent_allowance( - output_ptr: Ptr32Mut<[u8]>, - output_len_ptr: Ptr32Mut, - ); pub fn seal_minimum_balance( output_ptr: Ptr32Mut<[u8]>, output_len_ptr: Ptr32Mut, ); - pub fn seal_tombstone_deposit( - output_ptr: Ptr32Mut<[u8]>, - output_len_ptr: Ptr32Mut, - ); - - pub fn seal_set_rent_allowance(value_ptr: Ptr32<[u8]>, value_len: u32); pub fn seal_hash_keccak_256( input_ptr: Ptr32<[u8]>, @@ -349,17 +327,6 @@ mod sys { output_len_ptr: Ptr32Mut, ) -> ReturnCode; - pub fn seal_rent_params( - output_ptr: Ptr32Mut<[u8]>, - output_len_ptr: Ptr32Mut, - ); - - pub fn seal_rent_status( - at_refcount: u32, - output_ptr: Ptr32Mut<[u8]>, - output_len_ptr: Ptr32Mut, - ); - pub fn seal_ecdsa_recover( // 65 bytes of ecdsa signature signature_ptr: Ptr32<[u8]>, @@ -490,37 +457,6 @@ pub fn get_storage(key: &[u8], output: &mut &mut [u8]) -> Result { ret_code.into() } -/// Restores a tombstone to the original smart contract. -/// -/// # Params -/// -/// - `account_id`: Encoded bytes of the `AccountId` of the to-be-restored contract. -/// - `code_hash`: Encoded code hash of the to-be-restored contract. -/// - `rent_allowance`: The encoded rent allowance of the restored contract -/// upon successful restoration. -/// - `filtered_keys`: Storage keys that will be ignored for the tombstone hash -/// match calculation that decide whether the original contract -/// storage and the storage of the restorer contract is equal. -pub fn restore_to( - account_id: &[u8], - code_hash: &[u8], - rent_allowance: &[u8], - filtered_keys: &[Key], -) { - unsafe { - sys::seal_restore_to( - Ptr32::from_slice(account_id), - account_id.len() as u32, - Ptr32::from_slice(code_hash), - code_hash.len() as u32, - Ptr32::from_slice(rent_allowance), - rent_allowance.len() as u32, - Ptr32::from_slice(filtered_keys), - filtered_keys.len() as u32, - ) - } -} - pub fn terminate(beneficiary: &[u8]) -> ! { unsafe { sys::seal_terminate(Ptr32::from_slice(beneficiary), beneficiary.len() as u32) @@ -593,9 +529,7 @@ impl_seal_wrapper_for! { (gas_left => seal_gas_left), (value_transferred => seal_value_transferred), (now => seal_now), - (rent_allowance => seal_rent_allowance), (minimum_balance => seal_minimum_balance), - (tombstone_deposit => seal_tombstone_deposit), } pub fn weight_to_fee(gas: u64, output: &mut &mut [u8]) { @@ -612,37 +546,6 @@ pub fn weight_to_fee(gas: u64, output: &mut &mut [u8]) { extract_from_slice(output, output_len as usize); } -pub fn set_rent_allowance(value: &[u8]) { - unsafe { sys::seal_set_rent_allowance(Ptr32::from_slice(value), value.len() as u32) } -} - -pub fn rent_params(output: &mut &mut [u8]) { - let mut output_len = output.len() as u32; - { - unsafe { - sys::seal_rent_params( - Ptr32Mut::from_slice(output), - Ptr32Mut::from_ref(&mut output_len), - ) - }; - } - extract_from_slice(output, output_len as usize); -} - -pub fn rent_status(at_refcount: Option, output: &mut &mut [u8]) { - let mut output_len = output.len() as u32; - { - unsafe { - sys::seal_rent_status( - at_refcount.map_or(0, |rc| rc.get()), - Ptr32Mut::from_slice(output), - Ptr32Mut::from_ref(&mut output_len), - ) - }; - } - extract_from_slice(output, output_len as usize); -} - pub fn random(subject: &[u8], output: &mut &mut [u8]) { let mut output_len = output.len() as u32; { diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index 990cabceb6..2be6718333 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -36,10 +36,6 @@ use crate::{ Topics, TopicsBuilderBackend, }, - types::{ - RentParams, - RentStatus, - }, Clear, EnvBackend, Environment, @@ -381,10 +377,6 @@ impl TypedEnvBackend for EnvInstance { self.get_property_little_endian::(ext::balance) } - fn rent_allowance(&mut self) -> T::Balance { - self.get_property_little_endian::(ext::rent_allowance) - } - fn block_number(&mut self) -> T::BlockNumber { self.get_property_little_endian::(ext::block_number) } @@ -393,10 +385,6 @@ impl TypedEnvBackend for EnvInstance { self.get_property_little_endian::(ext::minimum_balance) } - fn tombstone_deposit(&mut self) -> T::Balance { - self.get_property_little_endian::(ext::tombstone_deposit) - } - fn emit_event(&mut self, event: Event) where T: Environment, @@ -408,33 +396,6 @@ impl TypedEnvBackend for EnvInstance { ext::deposit_event(enc_topics, enc_data); } - fn set_rent_allowance(&mut self, new_value: T::Balance) - where - T: Environment, - { - let buffer = self.scoped_buffer().take_encoded(&new_value); - ext::set_rent_allowance(&buffer[..]) - } - - fn rent_params(&mut self) -> Result> - where - T: Environment, - { - self.get_property::>(ext::rent_params) - } - - fn rent_status( - &mut self, - at_refcount: Option, - ) -> Result> - where - T: Environment, - { - let output = &mut self.scoped_buffer().take_rest(); - ext::rent_status(at_refcount, output); - scale::Decode::decode(&mut &output[..]).map_err(Into::into) - } - fn invoke_contract( &mut self, call_params: &CallParams, @@ -495,27 +456,6 @@ impl TypedEnvBackend for EnvInstance { Ok(account_id) } - fn restore_contract( - &mut self, - account_id: T::AccountId, - code_hash: T::Hash, - rent_allowance: T::Balance, - filtered_keys: &[Key], - ) where - T: Environment, - { - let mut scope = self.scoped_buffer(); - let enc_account_id = scope.take_encoded(&account_id); - let enc_code_hash = scope.take_encoded(&code_hash); - let enc_rent_allowance = scope.take_encoded(&rent_allowance); - ext::restore_to( - enc_account_id, - enc_code_hash, - enc_rent_allowance, - filtered_keys, - ); - } - fn terminate_contract(&mut self, beneficiary: T::AccountId) -> ! where T: Environment, diff --git a/crates/env/src/error.rs b/crates/env/src/error.rs index a6b9be65de..f66079f2d2 100644 --- a/crates/env/src/error.rs +++ b/crates/env/src/error.rs @@ -42,7 +42,7 @@ pub enum Error { NewContractNotFunded, /// No code could be found at the supplied code hash. CodeNotFound, - /// The account that was called is either no contract (e.g. user account) or is a tombstone. + /// The account that was called is no contract, but a plain account. NotCallable, /// An unknown error has occurred. Unknown, diff --git a/crates/env/src/lib.rs b/crates/env/src/lib.rs index 609cd35c62..7f6c45c1e1 100644 --- a/crates/env/src/lib.rs +++ b/crates/env/src/lib.rs @@ -103,9 +103,6 @@ pub use self::{ FromLittleEndian, Hash, NoChainExtension, - Perbill, - RentParams, - RentStatus, }, }; diff --git a/crates/env/src/types.rs b/crates/env/src/types.rs index fff2d3a886..a2d07be1c7 100644 --- a/crates/env/src/types.rs +++ b/crates/env/src/types.rs @@ -43,8 +43,6 @@ use scale::{ }; #[cfg(feature = "std")] use scale_info::TypeInfo; -use sp_arithmetic::PerThing; -pub use sp_arithmetic::Perbill; /// Allows to instantiate a type from its little-endian bytes representation. pub trait FromLittleEndian { @@ -167,9 +165,6 @@ pub trait Environment { /// /// [chain_extension]: https://paritytech.github.io/ink/ink_lang/attr.chain_extension.html type ChainExtension; - - /// The fraction of the deposit costs that should be used as rent per block. - type RentFraction: 'static + scale::Codec + Clone + PartialEq + Eq + Ord + PerThing; } /// Placeholder for chains that have no defined chain extension. @@ -189,7 +184,6 @@ impl Environment for DefaultEnvironment { type Timestamp = Timestamp; type BlockNumber = BlockNumber; type ChainExtension = NoChainExtension; - type RentFraction = RentFraction; } /// The default balance type. @@ -201,9 +195,6 @@ pub type Timestamp = u64; /// The default block number type. pub type BlockNumber = u32; -/// The default rent fraction type. -pub type RentFraction = Perbill; - /// The default environment `AccountId` type. /// /// # Note @@ -338,106 +329,3 @@ impl Clear for Hash { Self(<[u8; 32] as Clear>::clear()) } } - -/// Information needed for rent calculations that can be requested by a contract. -#[derive(scale::Decode)] -#[cfg_attr(test, derive(Debug, PartialEq))] -pub struct RentParams { - /// The total balance of the contract. Includes the balance transferred from the caller. - pub total_balance: T::Balance, - - /// The free balance of the contract, i.e. the portion of the contract's balance - /// that is not reserved. Includes the balance transferred from the caller. - pub free_balance: T::Balance, - - /// Subsistence threshold is the extension of the minimum balance (aka existential deposit) - /// by the tombstone deposit, required for leaving a tombstone. - /// - /// Rent or any contract initiated balance transfer mechanism cannot make the balance lower - /// than the subsistence threshold in order to guarantee that a tombstone is created. - /// - /// The only way to completely kill a contract without a tombstone is calling `seal_terminate`. - pub subsistence_threshold: T::Balance, - - /// The balance every contract needs to deposit to stay alive indefinitely. - /// - /// This is different from the tombstone deposit because this only needs to be - /// deposited while the contract is alive. Costs for additional storage are added to - /// this base cost. - /// - /// This is a simple way to ensure that contracts with empty storage eventually get deleted by - /// making them pay rent. This creates an incentive to remove them early in order to save rent. - pub deposit_per_contract: T::Balance, - - /// The balance a contract needs to deposit per storage byte to stay alive indefinitely. - /// - /// Let's suppose the deposit is 1,000 BU (balance units)/byte and the rent is 1 BU/byte/day, - /// then a contract with 1,000,000 BU that uses 1,000 bytes of storage would pay no rent. - /// But if the balance reduced to 500,000 BU and the storage stayed the same at 1,000, - /// then it would pay 500 BU/day. - pub deposit_per_storage_byte: T::Balance, - - /// The balance a contract needs to deposit per storage item to stay alive indefinitely. - /// - /// It works as [`Self::deposit_per_storage_byte`] but for storage items. - pub deposit_per_storage_item: T::Balance, - - /// The contract's rent allowance, the rent mechanism cannot consume more than this. - pub rent_allowance: T::Balance, - - /// The fraction of the deposit costs that should be used as rent per block. - /// - /// When a contract does not have enough balance deposited to stay alive indefinitely - /// it needs to pay per block for the storage it consumes that is not covered by the - /// deposit. This determines how high this rent payment is per block as a fraction - /// of the deposit costs. - pub rent_fraction: T::RentFraction, - - /// The total number of bytes used by this contract. - /// - /// It is a sum of each key-value pair stored by this contract. - pub storage_size: u32, - - /// Sum of instrumented and pristine code length. - pub code_size: u32, - - /// The number of contracts using this executable. - pub code_refcount: u32, - - /// Reserved for backwards compatible changes to this data structure. - pub _reserved: Option<()>, -} - -/// Information about the required deposit and resulting rent. -/// -/// The easiest way to guarantee that a contract stays alive is to assert that -/// `max_rent == 0` at the **end** of a contract's execution. -/// -/// # Note -/// -/// The `current_*` fields do **not** consider changes to the code's `refcount` -/// made during the currently running call. -#[derive(scale::Decode)] -#[cfg_attr(test, derive(Debug, PartialEq))] -pub struct RentStatus { - /// Required deposit assuming that this contract is the only user of its code. - pub max_deposit: T::Balance, - - /// Required deposit assuming the code's current `refcount`. - pub current_deposit: T::Balance, - - /// Required deposit assuming the specified `refcount` (`None` if `0` is supplied). - pub custom_refcount_deposit: Option, - - /// Rent that is paid assuming that the contract is the only user of its code. - pub max_rent: T::Balance, - - /// Rent that is paid given the code's current refcount. - pub current_rent: T::Balance, - - /// Rent that is paid assuming the specified refcount (`None` if `0` is supplied). - pub custom_refcount_rent: Option, - - /// Reserved for backwards compatible changes to this data structure. - pub _reserved: Option<()>, -} diff --git a/crates/lang/macro/src/lib.rs b/crates/lang/macro/src/lib.rs index 203d8ff141..21487eb179 100644 --- a/crates/lang/macro/src/lib.rs +++ b/crates/lang/macro/src/lib.rs @@ -220,7 +220,6 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream { /// type Hash = [u8; 32]; /// type Timestamp = u64; /// type BlockNumber = u32; -/// type RentFraction = ::ink_env::Perbill; /// type ChainExtension = ::ink_env::NoChainExtension; /// } /// ``` @@ -240,7 +239,6 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream { /// # type Timestamp = u64; /// # type BlockNumber = u32; /// # type ChainExtension = ::ink_env::NoChainExtension; -/// # type RentFraction = ::ink_env::Perbill; /// # } /// # /// # #[ink(storage)] @@ -982,7 +980,6 @@ pub fn test(attr: TokenStream, item: TokenStream) -> TokenStream { /// type Hash = ::Hash; /// type BlockNumber = ::BlockNumber; /// type Timestamp = ::Timestamp; -/// type RentFraction = ::RentFraction; /// /// type ChainExtension = RuntimeReadWrite; /// } @@ -1126,7 +1123,6 @@ pub fn test(attr: TokenStream, item: TokenStream) -> TokenStream { /// # type Hash = ::Hash; /// # type BlockNumber = ::BlockNumber; /// # type Timestamp = ::Timestamp; -/// # type RentFraction = ::RentFraction; /// # /// # type ChainExtension = RuntimeReadWrite; /// # } diff --git a/crates/lang/src/env_access.rs b/crates/lang/src/env_access.rs index d3e79a345d..1fdc6af27b 100644 --- a/crates/lang/src/env_access.rs +++ b/crates/lang/src/env_access.rs @@ -26,12 +26,9 @@ use ink_env::{ }, Environment, Error, - RentParams, - RentStatus, Result, }; use ink_eth_compatibility::ECDSAPublicKey; -use ink_primitives::Key; /// The API behind the `self.env()` and `Self::env()` syntax in ink!. /// @@ -351,132 +348,6 @@ where ink_env::balance::() } - /// Returns the current rent allowance for the executed contract. - /// - /// # Example - /// - /// ``` - /// # use ink_lang as ink; - /// # #[ink::contract] - /// # pub mod my_contract { - /// # #[ink(storage)] - /// # pub struct MyContract { } - /// # - /// # impl MyContract { - /// # #[ink(constructor)] - /// # pub fn new() -> Self { - /// # Self {} - /// # } - /// # - /// /// Returns the amount of the contract's balance which - /// /// can be used for paying rent. - /// #[ink(message)] - /// pub fn rent_allowance(&self) -> Balance { - /// self.env().rent_allowance() - /// } - /// # - /// # } - /// # } - /// ``` - /// - /// # Note - /// - /// For more details visit: [`ink_env::rent_allowance`] - pub fn rent_allowance(self) -> T::Balance { - ink_env::rent_allowance::() - } - - /// Sets the rent allowance of the executed contract to the new value. - /// - /// # Example - /// - /// ``` - /// # use ink_lang as ink; - /// # #[ink::contract] - /// # pub mod my_contract { - /// # #[ink(storage)] - /// # pub struct MyContract { } - /// # - /// # impl MyContract { - /// # #[ink(constructor)] - /// # pub fn new() -> Self { - /// # Self {} - /// # } - /// # - /// /// Limits the amount of contract balance which can be used for paying rent - /// /// to half of the contract's total balance. - /// #[ink(message)] - /// pub fn limit_rent_allowance(&self) { - /// self.env().set_rent_allowance(self.env().balance() / 2); - /// } - /// # - /// # } - /// # } - /// ``` - /// - /// # Note - /// - /// For more details visit: [`ink_env::set_rent_allowance`] - pub fn set_rent_allowance(self, new_value: T::Balance) { - ink_env::set_rent_allowance::(new_value) - } - - /// Returns information needed for rent calculations. - /// - /// # Example - /// - /// ``` - /// # use ink_lang as ink; - /// # #[ink::contract] - /// # pub mod my_contract { - /// # #[ink(storage)] - /// # pub struct MyContract { } - /// # - /// # impl MyContract { - /// # #[ink(constructor)] - /// # pub fn new() -> Self { - /// # Self {} - /// # } - /// # - /// /// Returns the balance every contract needs to deposit on this chain - /// /// to stay alive indefinitely. - /// #[ink(message)] - /// pub fn deposit_per_contract(&self) -> Balance { - /// self.env().rent_params().deposit_per_contract - /// } - /// # - /// # } - /// # } - /// ``` - /// - /// # Note - /// - /// For more details visit: [`ink_env::RentParams`] - pub fn rent_params(self) -> RentParams { - ink_env::rent_params::().expect("couldn't decode contract rent params") - } - - /// Returns information about the required deposit and resulting rent. - /// - /// # Parameters - /// - /// - `at_refcount`: The `refcount` assumed for the returned `custom_refcount_*` fields. - /// If `None` is supplied the `custom_refcount_*` fields will also be `None`. - /// - /// The `current_*` fields of `RentStatus` do **not** consider changes to the code's - /// `refcount` made during the currently running call. - /// - /// # Note - /// - /// For more details visit: [`ink_env::RentStatus`] - pub fn rent_status( - self, - at_refcount: Option, - ) -> RentStatus { - ink_env::rent_status::(at_refcount) - .expect("couldn't decode contract rent params") - } - /// Returns the current block number. /// /// # Example @@ -550,39 +421,6 @@ where ink_env::minimum_balance::() } - /// Returns the tombstone deposit for the contracts chain. - /// - /// # Example - /// - /// ``` - /// # use ink_lang as ink; - /// # #[ink::contract] - /// # pub mod my_contract { - /// # #[ink(storage)] - /// # pub struct MyContract { } - /// # - /// # impl MyContract { - /// # #[ink(constructor)] - /// # pub fn new() -> Self { - /// # Self {} - /// # } - /// # - /// #[ink(message)] - /// pub fn tombstone_deposit(&self) -> Balance { - /// self.env().tombstone_deposit() - /// } - /// # - /// # } - /// # } - /// ``` - /// - /// # Note - /// - /// For more details visit: [`ink_env::tombstone_deposit`] - pub fn tombstone_deposit(self) -> T::Balance { - ink_env::tombstone_deposit::() - } - /// Instantiates another contract. /// /// # Example @@ -779,57 +617,7 @@ where ink_env::eval_contract::(params) } - /// Restores a smart contract from its tombstone state. - /// - /// # Example - /// - /// ``` - /// # use ink_lang as ink; - /// # #[ink::contract] - /// # pub mod my_contract { - /// # #[ink(storage)] - /// # pub struct MyContract { } - /// # - /// # impl MyContract { - /// # #[ink(constructor)] - /// # pub fn new() -> Self { - /// # Self {} - /// # } - /// # - /// /// Simple resurrection of a contract. - /// #[ink(message)] - /// pub fn resurrect(&self, contract: AccountId) { - /// self.env().restore_contract( - /// contract, - /// Hash::from([0x42; 32]), - /// 1000, - /// &[] - /// ) - /// } - /// # - /// # } - /// # } - /// ``` - /// - /// # Note - /// - /// For more details visit: [`ink_env::restore_contract`] - pub fn restore_contract( - self, - account_id: T::AccountId, - code_hash: T::Hash, - rent_allowance: T::Balance, - filtered_keys: &[Key], - ) { - ink_env::restore_contract::( - account_id, - code_hash, - rent_allowance, - filtered_keys, - ) - } - - /// Terminates the existence of a contract without creating a tombstone. + /// Terminates the existence of a contract. /// /// # Example /// diff --git a/crates/lang/src/reflect/contract.rs b/crates/lang/src/reflect/contract.rs index 7083f56f8b..965b27c878 100644 --- a/crates/lang/src/reflect/contract.rs +++ b/crates/lang/src/reflect/contract.rs @@ -110,7 +110,6 @@ pub trait ContractName { /// type Hash = ::Hash; /// type BlockNumber = u32; /// type Timestamp = u64; -/// type RentFraction = ::RentFraction; /// type ChainExtension = ::ChainExtension; /// } /// diff --git a/crates/lang/tests/ui/chain_extension/E-01-simple.rs b/crates/lang/tests/ui/chain_extension/E-01-simple.rs index 6ef333f61f..96bbfef087 100644 --- a/crates/lang/tests/ui/chain_extension/E-01-simple.rs +++ b/crates/lang/tests/ui/chain_extension/E-01-simple.rs @@ -117,7 +117,6 @@ impl Environment for CustomEnvironment { type Hash = ::Hash; type BlockNumber = ::BlockNumber; type Timestamp = ::Timestamp; - type RentFraction = ::RentFraction; type ChainExtension = RuntimeReadWrite; } diff --git a/crates/lang/tests/ui/contract/fail/event-too-many-topics-anonymous.rs b/crates/lang/tests/ui/contract/fail/event-too-many-topics-anonymous.rs index 7ef6b7499e..64fa8d5e04 100644 --- a/crates/lang/tests/ui/contract/fail/event-too-many-topics-anonymous.rs +++ b/crates/lang/tests/ui/contract/fail/event-too-many-topics-anonymous.rs @@ -15,7 +15,6 @@ impl ink_env::Environment for EnvironmentMoreTopics { type Timestamp = ::Timestamp; type BlockNumber = ::BlockNumber; type ChainExtension = (); - type RentFraction = ::RentFraction; } #[ink::contract(env = super::EnvironmentMoreTopics)] diff --git a/crates/lang/tests/ui/contract/fail/event-too-many-topics-anonymous.stderr b/crates/lang/tests/ui/contract/fail/event-too-many-topics-anonymous.stderr index 026ef1c4dd..57c4886dc1 100644 --- a/crates/lang/tests/ui/contract/fail/event-too-many-topics-anonymous.stderr +++ b/crates/lang/tests/ui/contract/fail/event-too-many-topics-anonymous.stderr @@ -1,13 +1,13 @@ error[E0277]: the trait bound `EventTopics<4_usize>: RespectTopicLimit<2_usize>` is not satisfied - --> tests/ui/contract/fail/event-too-many-topics-anonymous.rs:27:5 + --> tests/ui/contract/fail/event-too-many-topics-anonymous.rs:26:5 | -27 | / pub struct Event { -28 | | #[ink(topic)] -29 | | arg_1: i8, -30 | | #[ink(topic)] +26 | / pub struct Event { +27 | | #[ink(topic)] +28 | | arg_1: i8, +29 | | #[ink(topic)] ... | -35 | | arg_4: i32, -36 | | } +34 | | arg_4: i32, +35 | | } | |_____^ the trait `RespectTopicLimit<2_usize>` is not implemented for `EventTopics<4_usize>` | = help: the following implementations were found: @@ -17,7 +17,7 @@ error[E0277]: the trait bound `EventTopics<4_usize>: RespectTopicLimit<2_usize>` as RespectTopicLimit<12_usize>> and 87 others note: required by a bound in `EventRespectsTopicLimit` - --> src/codegen/event/topics.rs:48:43 + --> src/codegen/event/topics.rs | -48 | ::LenTopics: RespectTopicLimit, + | ::LenTopics: RespectTopicLimit, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `EventRespectsTopicLimit` diff --git a/crates/lang/tests/ui/contract/fail/event-too-many-topics.rs b/crates/lang/tests/ui/contract/fail/event-too-many-topics.rs index c3834db8d9..659b047c44 100644 --- a/crates/lang/tests/ui/contract/fail/event-too-many-topics.rs +++ b/crates/lang/tests/ui/contract/fail/event-too-many-topics.rs @@ -15,7 +15,6 @@ impl ink_env::Environment for EnvironmentMoreTopics { type Timestamp = ::Timestamp; type BlockNumber = ::BlockNumber; type ChainExtension = (); - type RentFraction = ::RentFraction; } #[ink::contract(env = super::EnvironmentMoreTopics)] diff --git a/crates/lang/tests/ui/contract/fail/event-too-many-topics.stderr b/crates/lang/tests/ui/contract/fail/event-too-many-topics.stderr index 4ae2bbb32c..ad6aff4311 100644 --- a/crates/lang/tests/ui/contract/fail/event-too-many-topics.stderr +++ b/crates/lang/tests/ui/contract/fail/event-too-many-topics.stderr @@ -1,13 +1,13 @@ error[E0277]: the trait bound `EventTopics<3_usize>: RespectTopicLimit<2_usize>` is not satisfied - --> tests/ui/contract/fail/event-too-many-topics.rs:27:5 + --> tests/ui/contract/fail/event-too-many-topics.rs:26:5 | -27 | / pub struct Event { -28 | | #[ink(topic)] -29 | | arg_1: i8, -30 | | #[ink(topic)] +26 | / pub struct Event { +27 | | #[ink(topic)] +28 | | arg_1: i8, +29 | | #[ink(topic)] ... | -33 | | arg_3: i32, -34 | | } +32 | | arg_3: i32, +33 | | } | |_____^ the trait `RespectTopicLimit<2_usize>` is not implemented for `EventTopics<3_usize>` | = help: the following implementations were found: @@ -17,7 +17,7 @@ error[E0277]: the trait bound `EventTopics<3_usize>: RespectTopicLimit<2_usize>` as RespectTopicLimit<12_usize>> and 87 others note: required by a bound in `EventRespectsTopicLimit` - --> src/codegen/event/topics.rs:48:43 + --> src/codegen/event/topics.rs | -48 | ::LenTopics: RespectTopicLimit, + | ::LenTopics: RespectTopicLimit, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `EventRespectsTopicLimit` diff --git a/crates/lang/tests/ui/contract/pass/config-custom-env.rs b/crates/lang/tests/ui/contract/pass/config-custom-env.rs index 613205f007..90958764ac 100644 --- a/crates/lang/tests/ui/contract/pass/config-custom-env.rs +++ b/crates/lang/tests/ui/contract/pass/config-custom-env.rs @@ -10,9 +10,6 @@ impl ink_env::Environment for CustomEnv { type Timestamp = u64; type BlockNumber = u64; type ChainExtension = (); - // Too lazy to define a test type that fits the required trait bounds. - type RentFraction = - ::RentFraction; } #[ink::contract(env = super::CustomEnv)] diff --git a/crates/lang/tests/ui/contract/pass/event-config-more-topics.rs b/crates/lang/tests/ui/contract/pass/event-config-more-topics.rs index e7b73525a8..7e357a7614 100644 --- a/crates/lang/tests/ui/contract/pass/event-config-more-topics.rs +++ b/crates/lang/tests/ui/contract/pass/event-config-more-topics.rs @@ -15,7 +15,6 @@ impl ink_env::Environment for EnvironmentMoreTopics { type Timestamp = ::Timestamp; type BlockNumber = ::BlockNumber; type ChainExtension = (); - type RentFraction = ::RentFraction; } #[ink::contract(env = super::EnvironmentMoreTopics)] diff --git a/examples/contract-transfer/lib.rs b/examples/contract-transfer/lib.rs index f5ebf58891..b72cd6a2bd 100644 --- a/examples/contract-transfer/lib.rs +++ b/examples/contract-transfer/lib.rs @@ -21,9 +21,9 @@ pub mod give_me { /// Insufficient funds to execute transfer. InsufficientFunds, /// Transfer failed because it would have brought the contract's - /// balance below the subsistence threshold. - /// This is necessary to keep enough funds in the contract to - /// allow for a tombstone to be created. + /// balance below the subsistence threshold. No transfer is + /// allowed to do this. Use `self.env().terminate()` to recover + /// the deposit. BelowSubsistenceThreshold, } diff --git a/examples/rand-extension/lib.rs b/examples/rand-extension/lib.rs index 21cd84e309..bf6740937a 100755 --- a/examples/rand-extension/lib.rs +++ b/examples/rand-extension/lib.rs @@ -47,7 +47,6 @@ impl Environment for CustomEnvironment { type Hash = ::Hash; type BlockNumber = ::BlockNumber; type Timestamp = ::Timestamp; - type RentFraction = ::RentFraction; type ChainExtension = FetchRandom; }