contracts: Remove weight pre charging (#8976)

* Remove pre-charging for code size

* Remove pre charging when reading values of fixed size

* Add new versions of API functions that leave out parameters

* Update CHANGELOG.md

* Apply suggestions from code review

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Add v1 for seal_set_rent_allowance

* Remove unneeded trait bound

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Alexander Theißen
2021-06-25 18:27:01 +02:00
committed by GitHub
parent bc0520913d
commit 0cccd282a1
18 changed files with 1238 additions and 1132 deletions
+9 -13
View File
@@ -20,7 +20,7 @@
use crate::{
AliveContractInfo, BalanceOf, ContractInfo, ContractInfoOf, Pallet, Event,
TombstoneContractInfo, Config, CodeHash, Error,
storage::Storage, wasm::PrefabWasmModule, exec::Executable,
storage::Storage, wasm::PrefabWasmModule, exec::Executable, gas::GasMeter,
};
use sp_std::prelude::*;
use sp_io::hashing::blake2_256;
@@ -232,10 +232,6 @@ where
/// Upon succesful restoration, `origin` will be destroyed, all its funds are transferred to
/// the restored account. The restored account will inherit the last write block and its last
/// deduct block will be set to the current block.
///
/// # Return Value
///
/// Result<(CallerCodeSize, DestCodeSize), (DispatchError, CallerCodeSize, DestCodesize)>
pub fn restore_to(
origin: &T::AccountId,
mut origin_contract: AliveContractInfo<T>,
@@ -243,18 +239,19 @@ where
code_hash: CodeHash<T>,
rent_allowance: BalanceOf<T>,
delta: Vec<crate::exec::StorageKey>,
) -> Result<(u32, u32), (DispatchError, u32, u32)> {
gas_meter: &mut GasMeter<T>,
) -> Result<(), DispatchError> {
let child_trie_info = origin_contract.child_trie_info();
let current_block = <frame_system::Pallet<T>>::block_number();
if origin_contract.last_write == Some(current_block) {
return Err((Error::<T>::InvalidContractOrigin.into(), 0, 0));
return Err(Error::<T>::InvalidContractOrigin.into());
}
let dest_tombstone = <ContractInfoOf<T>>::get(&dest)
.and_then(|c| c.get_tombstone())
.ok_or((Error::<T>::InvalidDestinationContract.into(), 0, 0))?;
.ok_or(Error::<T>::InvalidDestinationContract)?;
let last_write = if !delta.is_empty() {
Some(current_block)
@@ -263,7 +260,7 @@ where
};
// Fails if the code hash does not exist on chain
let caller_code_len = E::add_user(code_hash).map_err(|e| (e, 0, 0))?;
E::add_user(code_hash, gas_meter)?;
// We are allowed to eagerly modify storage even though the function can
// fail later due to tombstones not matching. This is because the restoration
@@ -287,13 +284,13 @@ where
);
if tombstone != dest_tombstone {
return Err((Error::<T>::InvalidTombstone.into(), caller_code_len, 0));
return Err(Error::<T>::InvalidTombstone.into());
}
origin_contract.storage_size -= bytes_taken;
<ContractInfoOf<T>>::remove(&origin);
let tombstone_code_len = E::remove_user(origin_contract.code_hash);
E::remove_user(origin_contract.code_hash, gas_meter)?;
<ContractInfoOf<T>>::insert(&dest, ContractInfo::Alive(AliveContractInfo::<T> {
code_hash,
rent_allowance,
@@ -306,8 +303,7 @@ where
let origin_free_balance = T::Currency::free_balance(&origin);
T::Currency::make_free_balance_be(&origin, <BalanceOf<T>>::zero());
T::Currency::deposit_creating(&dest, origin_free_balance);
Ok((caller_code_len, tombstone_code_len))
Ok(())
}
/// Create a new `RentStatus` struct for pass through to a requesting contract.