Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

contracts: Remove state rent #9669

Merged
14 commits merged into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,16 +821,10 @@ impl pallet_tips::Config for Runtime {
}

parameter_types! {
pub TombstoneDeposit: Balance = deposit(
pub ContractDeposit: Balance = deposit(
1,
<pallet_contracts::Pallet<Runtime>>::contract_info_size(),
);
pub DepositPerContract: Balance = TombstoneDeposit::get();
pub const DepositPerStorageByte: Balance = deposit(0, 1);
pub const DepositPerStorageItem: Balance = deposit(1, 0);
pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS);
pub const SurchargeReward: Balance = 150 * MILLICENTS;
pub const SignedClaimHandicap: u32 = 2;
pub const MaxValueSize: u32 = 16 * 1024;
// The lazy deletion runs inside on_initialize.
pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *
Expand All @@ -857,14 +851,7 @@ impl pallet_contracts::Config for Runtime {
/// change because that would break already deployed contracts. The `Call` structure itself
/// is not allowed to change the indices of existing pallets, too.
type CallFilter = Nothing;
type RentPayment = ();
type SignedClaimHandicap = SignedClaimHandicap;
type TombstoneDeposit = TombstoneDeposit;
type DepositPerContract = DepositPerContract;
type DepositPerStorageByte = DepositPerStorageByte;
type DepositPerStorageItem = DepositPerStorageItem;
type RentFraction = RentFraction;
type SurchargeReward = SurchargeReward;
type ContractDeposit = ContractDeposit;
type CallStack = [pallet_contracts::Frame<Self>; 31];
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
Expand Down Expand Up @@ -1460,9 +1447,9 @@ impl_runtime_apis! {
code: pallet_contracts_primitives::Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId>
{
Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, true)
Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true)
}

fn get_storage(
Expand All @@ -1471,12 +1458,6 @@ impl_runtime_apis! {
) -> pallet_contracts_primitives::GetStorageResult {
Contracts::get_storage(address, key)
}

fn rent_projection(
address: AccountId,
) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {
Contracts::rent_projection(address)
}
}

impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
Expand Down
32 changes: 3 additions & 29 deletions frame/contracts/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,17 @@ pub struct ContractResult<T> {
pub type ContractExecResult = ContractResult<Result<ExecReturnValue, DispatchError>>;

/// Result type of a `bare_instantiate` call.
pub type ContractInstantiateResult<AccountId, BlockNumber> =
ContractResult<Result<InstantiateReturnValue<AccountId, BlockNumber>, DispatchError>>;
pub type ContractInstantiateResult<AccountId> =
ContractResult<Result<InstantiateReturnValue<AccountId>, DispatchError>>;

/// Result type of a `get_storage` call.
pub type GetStorageResult = Result<Option<Vec<u8>>, ContractAccessError>;

/// Result type of a `rent_projection` call.
pub type RentProjectionResult<BlockNumber> =
Result<RentProjection<BlockNumber>, ContractAccessError>;

/// The possible errors that can happen querying the storage of a contract.
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug)]
pub enum ContractAccessError {
/// The given address doesn't point to a contract.
DoesntExist,
/// The specified contract is a tombstone and thus cannot have any storage.
IsTombstone,
}

#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
pub enum RentProjection<BlockNumber> {
/// Eviction is projected to happen at the specified block number.
EvictionAt(BlockNumber),
/// No eviction is scheduled.
///
/// E.g. Contract accumulated enough funds to offset the rent storage costs.
NoEviction,
}

bitflags! {
Expand Down Expand Up @@ -134,19 +116,11 @@ impl ExecReturnValue {
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
pub struct InstantiateReturnValue<AccountId, BlockNumber> {
pub struct InstantiateReturnValue<AccountId> {
/// The output of the called constructor.
pub result: ExecReturnValue,
/// The account id of the new contract.
pub account_id: AccountId,
/// Information about when and if the new project will be evicted.
///
/// # Note
///
/// `None` if `bare_instantiate` was called with
/// `compute_projection` set to false. From the perspective of an RPC this means that
/// the runtime API did not request this value and this feature is therefore unsupported.
pub rent_projection: Option<RentProjection<BlockNumber>>,
}

/// Reference to an existing code hash or a new wasm module.
Expand Down
43 changes: 0 additions & 43 deletions frame/contracts/fixtures/check_default_rent_allowance.wat

This file was deleted.

2 changes: 1 addition & 1 deletion frame/contracts/fixtures/destroy_and_transfer.wat
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@

;; Calling the destination address with non-empty input data should now work since the
;; contract has been removed. Also transfer a balance to the address so we can ensure this
;; does not keep the contract alive.
;; does not hinder the contract from being removed.
(call $assert
(i32.eq
(call $seal_transfer
Expand Down
72 changes: 0 additions & 72 deletions frame/contracts/fixtures/restoration.wat

This file was deleted.

105 changes: 0 additions & 105 deletions frame/contracts/fixtures/set_rent.wat

This file was deleted.

15 changes: 3 additions & 12 deletions frame/contracts/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

use codec::Codec;
use pallet_contracts_primitives::{
Code, ContractExecResult, ContractInstantiateResult, GetStorageResult, RentProjectionResult,
Code, ContractExecResult, ContractInstantiateResult, GetStorageResult,
};
use sp_std::vec::Vec;

Expand Down Expand Up @@ -58,25 +58,16 @@ sp_api::decl_runtime_apis! {
code: Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> ContractInstantiateResult<AccountId, BlockNumber>;
) -> ContractInstantiateResult<AccountId>;

/// Query a given storage key in a given contract.
///
/// Returns `Ok(Some(Vec<u8>))` if the storage value exists under the given key in the
/// specified account and `Ok(None)` if it doesn't. If the account specified by the address
/// doesn't exist, or doesn't have a contract or if the contract is a tombstone, then `Err`
/// is returned.
/// doesn't exist, or doesn't have a contract then `Err` is returned.
fn get_storage(
address: AccountId,
key: [u8; 32],
) -> GetStorageResult;

/// Returns the projected time a given contract will be able to sustain paying its rent.
///
/// The returned projection is relevant for the current block, i.e. it is as if the contract
/// was accessed at the current block.
///
/// Returns `Err` if the contract is in a tombstone state or doesn't exist.
fn rent_projection(address: AccountId) -> RentProjectionResult<BlockNumber>;
}
}
Loading