Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,7 @@ impl pallet_xcm_bridge_hub_router::Config<ToRococoXcmRouterInstance> for Runtime

parameter_types! {
pub const DepositPerItem: Balance = deposit(1, 0);
pub const DepositPerChildTrieItem: Balance = deposit(1, 0) / 100;
Comment thread
xermicus marked this conversation as resolved.
pub const DepositPerByte: Balance = deposit(0, 1);
pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
pub const MaxEthExtrinsicWeight: FixedU128 = FixedU128::from_rational(1,2);
Expand All @@ -1185,6 +1186,7 @@ impl pallet_revive::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeOrigin = RuntimeOrigin;
type DepositPerItem = DepositPerItem;
type DepositPerChildTrieItem = DepositPerChildTrieItem;
type DepositPerByte = DepositPerByte;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type Precompiles = (
Expand Down
2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ impl pallet_asset_tx_payment::Config for Runtime {

parameter_types! {
pub const DepositPerItem: Balance = 0;
pub const DepositPerChildTrieItem: Balance = 0;
pub const DepositPerByte: Balance = 0;
pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
pub const MaxEthExtrinsicWeight: FixedU128 = FixedU128::from_rational(1,2);
Expand All @@ -819,6 +820,7 @@ impl pallet_revive::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeOrigin = RuntimeOrigin;
type DepositPerItem = DepositPerItem;
type DepositPerChildTrieItem = DepositPerChildTrieItem;
type DepositPerByte = DepositPerByte;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type Precompiles = ();
Expand Down
11 changes: 11 additions & 0 deletions prdoc/pr_10027.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: 'pallet_revive: Lower the deposit costs for child trie items'
doc:
- audience: Runtime User
description: Fixes https://github.com/paritytech/polkadot-sdk/issues/9246
crates:
- name: asset-hub-westend-runtime
bump: major
- name: penpal-runtime
bump: major
- name: pallet-revive
bump: major
2 changes: 2 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ impl pallet_tips::Config for Runtime {

parameter_types! {
pub const DepositPerItem: Balance = deposit(1, 0);
pub const DepositPerChildTrieItem: Balance = deposit(1, 0) / 100;
pub const DepositPerByte: Balance = deposit(0, 1);
pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024);
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
Expand Down Expand Up @@ -1454,6 +1455,7 @@ impl pallet_revive::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeOrigin = RuntimeOrigin;
type DepositPerItem = DepositPerItem;
type DepositPerChildTrieItem = DepositPerChildTrieItem;
type DepositPerByte = DepositPerByte;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type Precompiles =
Expand Down
15 changes: 15 additions & 0 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ pub mod pallet {
#[pallet::no_default_bounds]
type DepositPerItem: Get<BalanceOf<Self>>;

/// The amount of balance a caller has to pay for each child trie storage item.
///
/// Those are the items created by a contract. In Solidity each value is a single
/// storage item. This is why we need to set a lower value here than for the main
/// trie items. Otherwise the storage deposit is too high.
///
/// # Note
///
/// It is safe to change this value on a live chain as all refunds are pro rata.
#[pallet::constant]
#[pallet::no_default_bounds]
type DepositPerChildTrieItem: Get<BalanceOf<Self>>;

/// The percentage of the storage deposit that should be held for using a code hash.
/// Instantiating a contract, protects the code from being removed. In order to prevent
/// abuse these actions are protected with a percentage of the code deposit.
Expand Down Expand Up @@ -339,6 +352,7 @@ pub mod pallet {

parameter_types! {
pub const DepositPerItem: Balance = deposit(1, 0);
pub const DepositPerChildTrieItem: Balance = deposit(1, 0) / 100;
pub const DepositPerByte: Balance = deposit(0, 1);
pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(0);
pub const MaxEthExtrinsicWeight: FixedU128 = FixedU128::from_rational(1, 2);
Expand Down Expand Up @@ -381,6 +395,7 @@ pub mod pallet {
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type DepositPerByte = DepositPerByte;
type DepositPerItem = DepositPerItem;
type DepositPerChildTrieItem = DepositPerChildTrieItem;
type Time = Self;
type UnsafeUnstableInterface = ConstBool<true>;
type AllowEVMBytecode = ConstBool<true>;
Expand Down
17 changes: 9 additions & 8 deletions substrate/frame/revive/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod meter;
use crate::{
address::AddressMapper,
exec::{AccountIdOf, Key},
storage::meter::Diff,
tracing::if_tracing,
weights::WeightInfo,
AccountInfoOf, BalanceOf, BalanceWithDust, Config, DeletionQueue, DeletionQueueCounter, Error,
Expand Down Expand Up @@ -357,13 +356,15 @@ impl<T: Config> ContractInfo<T> {
/// the deposit paid to upload the contract's code. It also depends on the size of immutable
/// storage which is also changed when the code hash of a contract is changed.
pub fn update_base_deposit(&mut self, code_deposit: BalanceOf<T>) -> BalanceOf<T> {
let contract_deposit = Diff {
bytes_added: (self.encoded_size() as u32).saturating_add(self.immutable_data_len),
items_added: if self.immutable_data_len == 0 { 1 } else { 2 },
..Default::default()
}
.update_contract::<T>(None)
.charge_or_zero();
let contract_deposit = {
let bytes_added: u32 =
(self.encoded_size() as u32).saturating_add(self.immutable_data_len);
let items_added: u32 = if self.immutable_data_len == 0 { 1 } else { 2 };

T::DepositPerByte::get()
.saturating_mul(bytes_added.into())
.saturating_add(T::DepositPerItem::get().saturating_mul(items_added.into()))
};

// Instantiating the contract prevents its code to be deleted, therefore the base deposit
// includes a fraction (`T::CodeHashLockupDepositPercent`) of the original storage deposit
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/storage/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Diff {
/// this information from the passed `info`.
pub fn update_contract<T: Config>(&self, info: Option<&mut ContractInfo<T>>) -> DepositOf<T> {
let per_byte = T::DepositPerByte::get();
let per_item = T::DepositPerItem::get();
let per_item = T::DepositPerChildTrieItem::get();
let bytes_added = self.bytes_added.saturating_sub(self.bytes_removed);
let items_added = self.items_added.saturating_sub(self.items_removed);
let mut bytes_deposit = Deposit::Charge(per_byte.saturating_mul((bytes_added).into()));
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ impl Config for Test {
type Currency = Balances;
type DepositPerByte = DepositPerByte;
type DepositPerItem = DepositPerItem;
type DepositPerChildTrieItem = DepositPerItem;
type UnsafeUnstableInterface = UnstableInterface;
type AllowEVMBytecode = AllowEvmBytecode;
type UploadOrigin = EnsureAccount<Self, UploadAccount>;
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/revive/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
exec::{ExecResult, Executable, ExportedFunction, Ext},
frame_support::{ensure, error::BadOrigin, traits::tokens::Restriction},
gas::{GasMeter, Token},
storage::meter::{Diff, NestedMeter},
storage::meter::NestedMeter,
weights::WeightInfo,
AccountIdOf, BalanceOf, CodeInfoOf, CodeRemoved, Config, Error, ExecConfig, ExecError,
HoldReason, Pallet, PristineCode, StorageDeposit, Weight, LOG_TARGET,
Expand All @@ -44,7 +44,7 @@ use frame_support::{
};
use pallet_revive_uapi::ReturnErrorCode;
use sp_core::{Get, H256};
use sp_runtime::DispatchError;
use sp_runtime::{DispatchError, Saturating};

/// Validated Vm module ready for execution.
/// This data structure is immutable once created and stored.
Expand Down Expand Up @@ -109,9 +109,9 @@ pub struct CodeInfo<T: Config> {
/// Calculate the deposit required for storing code and its metadata.
pub fn calculate_code_deposit<T: Config>(code_len: u32) -> BalanceOf<T> {
let bytes_added = code_len.saturating_add(<CodeInfo<T>>::max_encoded_len() as u32);
Diff { bytes_added, items_added: 2, ..Default::default() }
.update_contract::<T>(None)
.charge_or_zero()
T::DepositPerByte::get()
.saturating_mul(bytes_added.into())
.saturating_add(T::DepositPerItem::get().saturating_mul(2u32.into()))
}

impl ExportedFunction {
Expand Down
Loading