[contracts] Adapt storage reading host functions to Weights V2 (#12976)

* update RuntimeCosts to Weights V2, update tests

* improve docs

* clearer naming and docs to compat_weight helper

* Apply suggestions from code review

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

* save before master merge

* HostFnWeights to Weight

* added to_weight! macro

* Apply suggestions from code review

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

* RuntimeCosts::ChainExtension to weight_v2

* chain extension to weight v2

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
Sasha Gryaznov
2023-01-18 12:36:09 +02:00
committed by GitHub
parent 338d75d0a3
commit 05b846d63b
9 changed files with 189 additions and 154 deletions
@@ -122,23 +122,23 @@ fn iterate_fields(data: &syn::DataStruct, fmt: impl Fn(&Ident) -> TokenStream2)
fn format_weight(field: &Ident) -> TokenStream2 { fn format_weight(field: &Ident) -> TokenStream2 {
quote_spanned! { field.span() => quote_spanned! { field.span() =>
&if self.#field > 1_000_000_000 { &if self.#field.ref_time() > 1_000_000_000 {
format!( format!(
"{:.1?} ms", "{:.1?} ms",
Fixed::saturating_from_rational(self.#field, 1_000_000_000).to_float() Fixed::saturating_from_rational(self.#field.ref_time(), 1_000_000_000).to_float()
) )
} else if self.#field > 1_000_000 { } else if self.#field.ref_time() > 1_000_000 {
format!( format!(
"{:.1?} µs", "{:.1?} µs",
Fixed::saturating_from_rational(self.#field, 1_000_000).to_float() Fixed::saturating_from_rational(self.#field.ref_time(), 1_000_000).to_float()
) )
} else if self.#field > 1_000 { } else if self.#field.ref_time() > 1_000 {
format!( format!(
"{:.1?} ns", "{:.1?} ns",
Fixed::saturating_from_rational(self.#field, 1_000).to_float() Fixed::saturating_from_rational(self.#field.ref_time(), 1_000).to_float()
) )
} else { } else {
format!("{} ps", self.#field) format!("{} ps", self.#field.ref_time())
} }
} }
} }
@@ -2928,7 +2928,7 @@ benchmarks! {
// configured `Schedule` during benchmark development. // configured `Schedule` during benchmark development.
// It can be outputed using the following command: // It can be outputed using the following command:
// cargo run --manifest-path=bin/node/cli/Cargo.toml --release \ // cargo run --manifest-path=bin/node/cli/Cargo.toml --release \
// --features runtime-benchmarks -- benchmark --extra --dev --execution=native \ // --features runtime-benchmarks -- benchmark pallet --extra --dev --execution=native \
// -p pallet_contracts -e print_schedule --no-median-slopes --no-min-squares // -p pallet_contracts -e print_schedule --no-median-slopes --no-min-squares
#[extra] #[extra]
print_schedule { print_schedule {
@@ -227,7 +227,7 @@ impl<'a, 'b, E: Ext, S: State> Environment<'a, 'b, E, S> {
/// ///
/// Weight is synonymous with gas in substrate. /// Weight is synonymous with gas in substrate.
pub fn charge_weight(&mut self, amount: Weight) -> Result<ChargedAmount> { pub fn charge_weight(&mut self, amount: Weight) -> Result<ChargedAmount> {
self.inner.runtime.charge_gas(RuntimeCosts::ChainExtension(amount.ref_time())) self.inner.runtime.charge_gas(RuntimeCosts::ChainExtension(amount))
} }
/// Adjust a previously charged amount down to its actual amount. /// Adjust a previously charged amount down to its actual amount.
@@ -237,7 +237,7 @@ impl<'a, 'b, E: Ext, S: State> Environment<'a, 'b, E, S> {
pub fn adjust_weight(&mut self, charged: ChargedAmount, actual_weight: Weight) { pub fn adjust_weight(&mut self, charged: ChargedAmount, actual_weight: Weight) {
self.inner self.inner
.runtime .runtime
.adjust_gas(charged, RuntimeCosts::ChainExtension(actual_weight.ref_time())) .adjust_gas(charged, RuntimeCosts::ChainExtension(actual_weight))
} }
/// Grants access to the execution environment of the current contract call. /// Grants access to the execution environment of the current contract call.
@@ -408,8 +408,7 @@ impl<'a, 'b, E: Ext, S: BufOut> Environment<'a, 'b, E, S> {
buffer, buffer,
allow_skip, allow_skip,
|len| { |len| {
weight_per_byte weight_per_byte.map(|w| RuntimeCosts::ChainExtension(w.saturating_mul(len.into())))
.map(|w| RuntimeCosts::ChainExtension(w.ref_time().saturating_mul(len.into())))
}, },
) )
} }
+2 -2
View File
@@ -153,8 +153,8 @@ impl<T: Config> GasMeter<T> {
/// Returns `OutOfGas` if there is not enough gas or addition of the specified /// Returns `OutOfGas` if there is not enough gas or addition of the specified
/// amount of gas has lead to overflow. On success returns `Proceed`. /// amount of gas has lead to overflow. On success returns `Proceed`.
/// ///
/// NOTE that amount is always consumed, i.e. if there is not enough gas /// NOTE that amount isn't consumed if there is not enough gas. This is considered
/// then the counter will be set to zero. /// safe because we always charge gas before performing any resource-spending action.
#[inline] #[inline]
pub fn charge<Tok: Token<T>>(&mut self, token: Tok) -> Result<ChargedAmount, DispatchError> { pub fn charge<Tok: Token<T>>(&mut self, token: Tok) -> Result<ChargedAmount, DispatchError> {
#[cfg(test)] #[cfg(test)]
+11 -11
View File
@@ -381,7 +381,7 @@ pub mod pallet {
{ {
/// Deprecated version if [`Self::call`] for use in an in-storage `Call`. /// Deprecated version if [`Self::call`] for use in an in-storage `Call`.
#[pallet::call_index(0)] #[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::call().saturating_add(<Pallet<T>>::compat_weight(*gas_limit)))] #[pallet::weight(T::WeightInfo::call().saturating_add(<Pallet<T>>::compat_weight_limit(*gas_limit)))]
#[allow(deprecated)] #[allow(deprecated)]
#[deprecated(note = "1D weight is used in this extrinsic, please migrate to `call`")] #[deprecated(note = "1D weight is used in this extrinsic, please migrate to `call`")]
pub fn call_old_weight( pub fn call_old_weight(
@@ -396,7 +396,7 @@ pub mod pallet {
origin, origin,
dest, dest,
value, value,
<Pallet<T>>::compat_weight(gas_limit), <Pallet<T>>::compat_weight_limit(gas_limit),
storage_deposit_limit, storage_deposit_limit,
data, data,
) )
@@ -406,7 +406,7 @@ pub mod pallet {
#[pallet::call_index(1)] #[pallet::call_index(1)]
#[pallet::weight( #[pallet::weight(
T::WeightInfo::instantiate_with_code(code.len() as u32, data.len() as u32, salt.len() as u32) T::WeightInfo::instantiate_with_code(code.len() as u32, data.len() as u32, salt.len() as u32)
.saturating_add(<Pallet<T>>::compat_weight(*gas_limit)) .saturating_add(<Pallet<T>>::compat_weight_limit(*gas_limit))
)] )]
#[allow(deprecated)] #[allow(deprecated)]
#[deprecated( #[deprecated(
@@ -424,7 +424,7 @@ pub mod pallet {
Self::instantiate_with_code( Self::instantiate_with_code(
origin, origin,
value, value,
<Pallet<T>>::compat_weight(gas_limit), <Pallet<T>>::compat_weight_limit(gas_limit),
storage_deposit_limit, storage_deposit_limit,
code, code,
data, data,
@@ -435,7 +435,7 @@ pub mod pallet {
/// Deprecated version if [`Self::instantiate`] for use in an in-storage `Call`. /// Deprecated version if [`Self::instantiate`] for use in an in-storage `Call`.
#[pallet::call_index(2)] #[pallet::call_index(2)]
#[pallet::weight( #[pallet::weight(
T::WeightInfo::instantiate(data.len() as u32, salt.len() as u32).saturating_add(<Pallet<T>>::compat_weight(*gas_limit)) T::WeightInfo::instantiate(data.len() as u32, salt.len() as u32).saturating_add(<Pallet<T>>::compat_weight_limit(*gas_limit))
)] )]
#[allow(deprecated)] #[allow(deprecated)]
#[deprecated(note = "1D weight is used in this extrinsic, please migrate to `instantiate`")] #[deprecated(note = "1D weight is used in this extrinsic, please migrate to `instantiate`")]
@@ -451,7 +451,7 @@ pub mod pallet {
Self::instantiate( Self::instantiate(
origin, origin,
value, value,
<Pallet<T>>::compat_weight(gas_limit), <Pallet<T>>::compat_weight_limit(gas_limit),
storage_deposit_limit, storage_deposit_limit,
code_hash, code_hash,
data, data,
@@ -1216,12 +1216,12 @@ impl<T: Config> Pallet<T> {
<T::Currency as Inspect<AccountIdOf<T>>>::minimum_balance() <T::Currency as Inspect<AccountIdOf<T>>>::minimum_balance()
} }
/// Convert a 1D Weight to a 2D weight. /// Convert gas_limit from 1D Weight to a 2D Weight.
/// ///
/// Used by backwards compatible extrinsics. We cannot just set the proof to zero /// Used by backwards compatible extrinsics. We cannot just set the proof_size weight limit to
/// or an old `Call` will just fail. /// zero or an old `Call` will just fail with OutOfGas.
fn compat_weight(gas_limit: OldWeight) -> Weight { fn compat_weight_limit(gas_limit: OldWeight) -> Weight {
Weight::from(gas_limit).set_proof_size(u64::from(T::MaxCodeLen::get()) * 2) Weight::from_parts(gas_limit.0, u64::from(T::MaxCodeLen::get()) * 2)
} }
} }
+157 -121
View File
@@ -21,7 +21,7 @@
use crate::{wasm::Determinism, weights::WeightInfo, Config}; use crate::{wasm::Determinism, weights::WeightInfo, Config};
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use frame_support::DefaultNoBound; use frame_support::{weights::Weight, DefaultNoBound};
use pallet_contracts_proc_macro::{ScheduleDebug, WeightDebug}; use pallet_contracts_proc_macro::{ScheduleDebug, WeightDebug};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")] #[cfg(feature = "std")]
@@ -169,7 +169,7 @@ impl Limits {
/// that use them as supporting instructions. Supporting means mainly pushing arguments /// that use them as supporting instructions. Supporting means mainly pushing arguments
/// and dropping return values in order to maintain a valid module. /// and dropping return values in order to maintain a valid module.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, WeightDebug, TypeInfo)] #[derive(Clone, Encode, Decode, PartialEq, Eq, ScheduleDebug, TypeInfo)]
#[scale_info(skip_type_params(T))] #[scale_info(skip_type_params(T))]
pub struct InstructionWeights<T: Config> { pub struct InstructionWeights<T: Config> {
/// Version of the instruction weights. /// Version of the instruction weights.
@@ -255,178 +255,178 @@ pub struct InstructionWeights<T: Config> {
#[scale_info(skip_type_params(T))] #[scale_info(skip_type_params(T))]
pub struct HostFnWeights<T: Config> { pub struct HostFnWeights<T: Config> {
/// Weight of calling `seal_caller`. /// Weight of calling `seal_caller`.
pub caller: u64, pub caller: Weight,
/// Weight of calling `seal_is_contract`. /// Weight of calling `seal_is_contract`.
pub is_contract: u64, pub is_contract: Weight,
/// Weight of calling `seal_code_hash`. /// Weight of calling `seal_code_hash`.
pub code_hash: u64, pub code_hash: Weight,
/// Weight of calling `seal_own_code_hash`. /// Weight of calling `seal_own_code_hash`.
pub own_code_hash: u64, pub own_code_hash: Weight,
/// Weight of calling `seal_caller_is_origin`. /// Weight of calling `seal_caller_is_origin`.
pub caller_is_origin: u64, pub caller_is_origin: Weight,
/// Weight of calling `seal_address`. /// Weight of calling `seal_address`.
pub address: u64, pub address: Weight,
/// Weight of calling `seal_gas_left`. /// Weight of calling `seal_gas_left`.
pub gas_left: u64, pub gas_left: Weight,
/// Weight of calling `seal_balance`. /// Weight of calling `seal_balance`.
pub balance: u64, pub balance: Weight,
/// Weight of calling `seal_value_transferred`. /// Weight of calling `seal_value_transferred`.
pub value_transferred: u64, pub value_transferred: Weight,
/// Weight of calling `seal_minimum_balance`. /// Weight of calling `seal_minimum_balance`.
pub minimum_balance: u64, pub minimum_balance: Weight,
/// Weight of calling `seal_block_number`. /// Weight of calling `seal_block_number`.
pub block_number: u64, pub block_number: Weight,
/// Weight of calling `seal_now`. /// Weight of calling `seal_now`.
pub now: u64, pub now: Weight,
/// Weight of calling `seal_weight_to_fee`. /// Weight of calling `seal_weight_to_fee`.
pub weight_to_fee: u64, pub weight_to_fee: Weight,
/// Weight of calling `gas`. /// Weight of calling `gas`.
pub gas: u64, pub gas: Weight,
/// Weight of calling `seal_input`. /// Weight of calling `seal_input`.
pub input: u64, pub input: Weight,
/// Weight per input byte copied to contract memory by `seal_input`. /// Weight per input byte copied to contract memory by `seal_input`.
pub input_per_byte: u64, pub input_per_byte: Weight,
/// Weight of calling `seal_return`. /// Weight of calling `seal_return`.
pub r#return: u64, pub r#return: Weight,
/// Weight per byte returned through `seal_return`. /// Weight per byte returned through `seal_return`.
pub return_per_byte: u64, pub return_per_byte: Weight,
/// Weight of calling `seal_terminate`. /// Weight of calling `seal_terminate`.
pub terminate: u64, pub terminate: Weight,
/// Weight of calling `seal_random`. /// Weight of calling `seal_random`.
pub random: u64, pub random: Weight,
/// Weight of calling `seal_reposit_event`. /// Weight of calling `seal_reposit_event`.
pub deposit_event: u64, pub deposit_event: Weight,
/// Weight per topic supplied to `seal_deposit_event`. /// Weight per topic supplied to `seal_deposit_event`.
pub deposit_event_per_topic: u64, pub deposit_event_per_topic: Weight,
/// Weight per byte of an event deposited through `seal_deposit_event`. /// Weight per byte of an event deposited through `seal_deposit_event`.
pub deposit_event_per_byte: u64, pub deposit_event_per_byte: Weight,
/// Weight of calling `seal_debug_message`. /// Weight of calling `seal_debug_message`.
pub debug_message: u64, pub debug_message: Weight,
/// Weight of calling `seal_set_storage`. /// Weight of calling `seal_set_storage`.
pub set_storage: u64, pub set_storage: Weight,
/// Weight per written byten of an item stored with `seal_set_storage`. /// Weight per written byten of an item stored with `seal_set_storage`.
pub set_storage_per_new_byte: u64, pub set_storage_per_new_byte: Weight,
/// Weight per overwritten byte of an item stored with `seal_set_storage`. /// Weight per overwritten byte of an item stored with `seal_set_storage`.
pub set_storage_per_old_byte: u64, pub set_storage_per_old_byte: Weight,
/// Weight of calling `seal_set_code_hash`. /// Weight of calling `seal_set_code_hash`.
pub set_code_hash: u64, pub set_code_hash: Weight,
/// Weight of calling `seal_clear_storage`. /// Weight of calling `seal_clear_storage`.
pub clear_storage: u64, pub clear_storage: Weight,
/// Weight of calling `seal_clear_storage` per byte of the stored item. /// Weight of calling `seal_clear_storage` per byte of the stored item.
pub clear_storage_per_byte: u64, pub clear_storage_per_byte: Weight,
/// Weight of calling `seal_contains_storage`. /// Weight of calling `seal_contains_storage`.
pub contains_storage: u64, pub contains_storage: Weight,
/// Weight of calling `seal_contains_storage` per byte of the stored item. /// Weight of calling `seal_contains_storage` per byte of the stored item.
pub contains_storage_per_byte: u64, pub contains_storage_per_byte: Weight,
/// Weight of calling `seal_get_storage`. /// Weight of calling `seal_get_storage`.
pub get_storage: u64, pub get_storage: Weight,
/// Weight per byte of an item received via `seal_get_storage`. /// Weight per byte of an item received via `seal_get_storage`.
pub get_storage_per_byte: u64, pub get_storage_per_byte: Weight,
/// Weight of calling `seal_take_storage`. /// Weight of calling `seal_take_storage`.
pub take_storage: u64, pub take_storage: Weight,
/// Weight per byte of an item received via `seal_take_storage`. /// Weight per byte of an item received via `seal_take_storage`.
pub take_storage_per_byte: u64, pub take_storage_per_byte: Weight,
/// Weight of calling `seal_transfer`. /// Weight of calling `seal_transfer`.
pub transfer: u64, pub transfer: Weight,
/// Weight of calling `seal_call`. /// Weight of calling `seal_call`.
pub call: u64, pub call: Weight,
/// Weight of calling `seal_delegate_call`. /// Weight of calling `seal_delegate_call`.
pub delegate_call: u64, pub delegate_call: Weight,
/// Weight surcharge that is claimed if `seal_call` does a balance transfer. /// Weight surcharge that is claimed if `seal_call` does a balance transfer.
pub call_transfer_surcharge: u64, pub call_transfer_surcharge: Weight,
/// Weight per byte that is cloned by supplying the `CLONE_INPUT` flag. /// Weight per byte that is cloned by supplying the `CLONE_INPUT` flag.
pub call_per_cloned_byte: u64, pub call_per_cloned_byte: Weight,
/// Weight of calling `seal_instantiate`. /// Weight of calling `seal_instantiate`.
pub instantiate: u64, pub instantiate: Weight,
/// Weight surcharge that is claimed if `seal_instantiate` does a balance transfer. /// Weight surcharge that is claimed if `seal_instantiate` does a balance transfer.
pub instantiate_transfer_surcharge: u64, pub instantiate_transfer_surcharge: Weight,
/// Weight per input byte supplied to `seal_instantiate`. /// Weight per input byte supplied to `seal_instantiate`.
pub instantiate_per_input_byte: u64, pub instantiate_per_input_byte: Weight,
/// Weight per salt byte supplied to `seal_instantiate`. /// Weight per salt byte supplied to `seal_instantiate`.
pub instantiate_per_salt_byte: u64, pub instantiate_per_salt_byte: Weight,
/// Weight of calling `seal_hash_sha_256`. /// Weight of calling `seal_hash_sha_256`.
pub hash_sha2_256: u64, pub hash_sha2_256: Weight,
/// Weight per byte hashed by `seal_hash_sha_256`. /// Weight per byte hashed by `seal_hash_sha_256`.
pub hash_sha2_256_per_byte: u64, pub hash_sha2_256_per_byte: Weight,
/// Weight of calling `seal_hash_keccak_256`. /// Weight of calling `seal_hash_keccak_256`.
pub hash_keccak_256: u64, pub hash_keccak_256: Weight,
/// Weight per byte hashed by `seal_hash_keccak_256`. /// Weight per byte hashed by `seal_hash_keccak_256`.
pub hash_keccak_256_per_byte: u64, pub hash_keccak_256_per_byte: Weight,
/// Weight of calling `seal_hash_blake2_256`. /// Weight of calling `seal_hash_blake2_256`.
pub hash_blake2_256: u64, pub hash_blake2_256: Weight,
/// Weight per byte hashed by `seal_hash_blake2_256`. /// Weight per byte hashed by `seal_hash_blake2_256`.
pub hash_blake2_256_per_byte: u64, pub hash_blake2_256_per_byte: Weight,
/// Weight of calling `seal_hash_blake2_128`. /// Weight of calling `seal_hash_blake2_128`.
pub hash_blake2_128: u64, pub hash_blake2_128: Weight,
/// Weight per byte hashed by `seal_hash_blake2_128`. /// Weight per byte hashed by `seal_hash_blake2_128`.
pub hash_blake2_128_per_byte: u64, pub hash_blake2_128_per_byte: Weight,
/// Weight of calling `seal_ecdsa_recover`. /// Weight of calling `seal_ecdsa_recover`.
pub ecdsa_recover: u64, pub ecdsa_recover: Weight,
/// Weight of calling `seal_ecdsa_to_eth_address`. /// Weight of calling `seal_ecdsa_to_eth_address`.
pub ecdsa_to_eth_address: u64, pub ecdsa_to_eth_address: Weight,
/// Weight of calling `reentrance_count`. /// Weight of calling `reentrance_count`.
pub reentrance_count: u64, pub reentrance_count: Weight,
/// Weight of calling `account_reentrance_count`. /// Weight of calling `account_reentrance_count`.
pub account_reentrance_count: u64, pub account_reentrance_count: Weight,
/// Weight of calling `instantiation_nonce`. /// Weight of calling `instantiation_nonce`.
pub instantiation_nonce: u64, pub instantiation_nonce: Weight,
/// The type parameter is used in the default implementation. /// The type parameter is used in the default implementation.
#[codec(skip)] #[codec(skip)]
@@ -514,6 +514,12 @@ macro_rules! cost_byte_batched {
}; };
} }
macro_rules! to_weight {
($ref_time:expr $(, $proof_size:expr )?) => {
Weight::from_ref_time($ref_time)$(.set_proof_size($proof_size))?
};
}
impl Default for Limits { impl Default for Limits {
fn default() -> Self { fn default() -> Self {
Self { Self {
@@ -596,85 +602,115 @@ impl<T: Config> Default for InstructionWeights<T> {
} }
impl<T: Config> Default for HostFnWeights<T> { impl<T: Config> Default for HostFnWeights<T> {
/// PoV should contain all trie nodes that are read during state transition (i.e. block
/// production). Hence we need to charge the `proof_size` weight for every host function which
/// reads storage, namely:
/// - get_storage,
/// - take_storage,
/// - contains_storage,
/// - clear_storage,
/// - set_storage.
///
/// The last two functions write to storage, but they also do read storage in order to return
/// the size of the pre-existed value. Till we have PoV benchmarks implemented, we approximate
/// `proof_size` as being equal to the size of storage read.
fn default() -> Self { fn default() -> Self {
Self { Self {
caller: cost_batched!(seal_caller), caller: to_weight!(cost_batched!(seal_caller)),
is_contract: cost_batched!(seal_is_contract), is_contract: to_weight!(cost_batched!(seal_is_contract)),
code_hash: cost_batched!(seal_code_hash), code_hash: to_weight!(cost_batched!(seal_code_hash)),
own_code_hash: cost_batched!(seal_own_code_hash), own_code_hash: to_weight!(cost_batched!(seal_own_code_hash)),
caller_is_origin: cost_batched!(seal_caller_is_origin), caller_is_origin: to_weight!(cost_batched!(seal_caller_is_origin)),
address: cost_batched!(seal_address), address: to_weight!(cost_batched!(seal_address)),
gas_left: cost_batched!(seal_gas_left), gas_left: to_weight!(cost_batched!(seal_gas_left)),
balance: cost_batched!(seal_balance), balance: to_weight!(cost_batched!(seal_balance)),
value_transferred: cost_batched!(seal_value_transferred), value_transferred: to_weight!(cost_batched!(seal_value_transferred)),
minimum_balance: cost_batched!(seal_minimum_balance), minimum_balance: to_weight!(cost_batched!(seal_minimum_balance)),
block_number: cost_batched!(seal_block_number), block_number: to_weight!(cost_batched!(seal_block_number)),
now: cost_batched!(seal_now), now: to_weight!(cost_batched!(seal_now)),
weight_to_fee: cost_batched!(seal_weight_to_fee), weight_to_fee: to_weight!(cost_batched!(seal_weight_to_fee)),
gas: cost_batched!(seal_gas), gas: to_weight!(cost_batched!(seal_gas)),
input: cost_batched!(seal_input), input: to_weight!(cost_batched!(seal_input)),
input_per_byte: cost_byte_batched!(seal_input_per_kb), input_per_byte: to_weight!(cost_byte_batched!(seal_input_per_kb)),
r#return: cost!(seal_return), r#return: to_weight!(cost!(seal_return)),
return_per_byte: cost_byte!(seal_return_per_kb), return_per_byte: to_weight!(cost_byte!(seal_return_per_kb)),
terminate: cost!(seal_terminate), terminate: to_weight!(cost!(seal_terminate)),
random: cost_batched!(seal_random), random: to_weight!(cost_batched!(seal_random)),
deposit_event: cost_batched!(seal_deposit_event), deposit_event: to_weight!(cost_batched!(seal_deposit_event)),
deposit_event_per_topic: cost_batched_args!(seal_deposit_event_per_topic_and_kb, 1, 0), deposit_event_per_topic: to_weight!(cost_batched_args!(
deposit_event_per_byte: cost_byte_batched_args!( seal_deposit_event_per_topic_and_kb,
1,
0
)),
deposit_event_per_byte: to_weight!(cost_byte_batched_args!(
seal_deposit_event_per_topic_and_kb, seal_deposit_event_per_topic_and_kb,
0, 0,
1 1
)),
debug_message: to_weight!(cost_batched!(seal_debug_message)),
set_storage: to_weight!(cost_batched!(seal_set_storage)),
set_code_hash: to_weight!(cost_batched!(seal_set_code_hash)),
set_storage_per_new_byte: to_weight!(cost_byte_batched!(seal_set_storage_per_new_kb)),
set_storage_per_old_byte: to_weight!(
cost_byte_batched!(seal_set_storage_per_old_kb),
1u64
), ),
debug_message: cost_batched!(seal_debug_message), clear_storage: to_weight!(cost_batched!(seal_clear_storage)),
set_storage: cost_batched!(seal_set_storage), clear_storage_per_byte: to_weight!(cost_byte_batched!(seal_clear_storage_per_kb), 1u64),
set_code_hash: cost_batched!(seal_set_code_hash), contains_storage: to_weight!(cost_batched!(seal_contains_storage)),
set_storage_per_new_byte: cost_byte_batched!(seal_set_storage_per_new_kb), contains_storage_per_byte: to_weight!(
set_storage_per_old_byte: cost_byte_batched!(seal_set_storage_per_old_kb), cost_byte_batched!(seal_contains_storage_per_kb),
clear_storage: cost_batched!(seal_clear_storage), 1u64
clear_storage_per_byte: cost_byte_batched!(seal_clear_storage_per_kb), ),
contains_storage: cost_batched!(seal_contains_storage), get_storage: to_weight!(cost_batched!(seal_get_storage)),
contains_storage_per_byte: cost_byte_batched!(seal_contains_storage_per_kb), get_storage_per_byte: to_weight!(cost_byte_batched!(seal_get_storage_per_kb), 1u64),
get_storage: cost_batched!(seal_get_storage), take_storage: to_weight!(cost_batched!(seal_take_storage)),
get_storage_per_byte: cost_byte_batched!(seal_get_storage_per_kb), take_storage_per_byte: to_weight!(cost_byte_batched!(seal_take_storage_per_kb), 1u64),
take_storage: cost_batched!(seal_take_storage), transfer: to_weight!(cost_batched!(seal_transfer)),
take_storage_per_byte: cost_byte_batched!(seal_take_storage_per_kb), call: to_weight!(cost_batched!(seal_call)),
transfer: cost_batched!(seal_transfer), delegate_call: to_weight!(cost_batched!(seal_delegate_call)),
call: cost_batched!(seal_call), call_transfer_surcharge: to_weight!(cost_batched_args!(
delegate_call: cost_batched!(seal_delegate_call), seal_call_per_transfer_clone_kb,
call_transfer_surcharge: cost_batched_args!(seal_call_per_transfer_clone_kb, 1, 0), 1,
call_per_cloned_byte: cost_batched_args!(seal_call_per_transfer_clone_kb, 0, 1), 0
instantiate: cost_batched!(seal_instantiate), )),
instantiate_transfer_surcharge: cost_byte_batched_args!( call_per_cloned_byte: to_weight!(cost_batched_args!(
seal_call_per_transfer_clone_kb,
0,
1
)),
instantiate: to_weight!(cost_batched!(seal_instantiate)),
instantiate_transfer_surcharge: to_weight!(cost_byte_batched_args!(
seal_instantiate_per_transfer_input_salt_kb, seal_instantiate_per_transfer_input_salt_kb,
1, 1,
0, 0,
0 0
), )),
instantiate_per_input_byte: cost_byte_batched_args!( instantiate_per_input_byte: to_weight!(cost_byte_batched_args!(
seal_instantiate_per_transfer_input_salt_kb, seal_instantiate_per_transfer_input_salt_kb,
0, 0,
1, 1,
0 0
), )),
instantiate_per_salt_byte: cost_byte_batched_args!( instantiate_per_salt_byte: to_weight!(cost_byte_batched_args!(
seal_instantiate_per_transfer_input_salt_kb, seal_instantiate_per_transfer_input_salt_kb,
0, 0,
0, 0,
1 1
), )),
hash_sha2_256: cost_batched!(seal_hash_sha2_256), hash_sha2_256: to_weight!(cost_batched!(seal_hash_sha2_256)),
hash_sha2_256_per_byte: cost_byte_batched!(seal_hash_sha2_256_per_kb), hash_sha2_256_per_byte: to_weight!(cost_byte_batched!(seal_hash_sha2_256_per_kb)),
hash_keccak_256: cost_batched!(seal_hash_keccak_256), hash_keccak_256: to_weight!(cost_batched!(seal_hash_keccak_256)),
hash_keccak_256_per_byte: cost_byte_batched!(seal_hash_keccak_256_per_kb), hash_keccak_256_per_byte: to_weight!(cost_byte_batched!(seal_hash_keccak_256_per_kb)),
hash_blake2_256: cost_batched!(seal_hash_blake2_256), hash_blake2_256: to_weight!(cost_batched!(seal_hash_blake2_256)),
hash_blake2_256_per_byte: cost_byte_batched!(seal_hash_blake2_256_per_kb), hash_blake2_256_per_byte: to_weight!(cost_byte_batched!(seal_hash_blake2_256_per_kb)),
hash_blake2_128: cost_batched!(seal_hash_blake2_128), hash_blake2_128: to_weight!(cost_batched!(seal_hash_blake2_128)),
hash_blake2_128_per_byte: cost_byte_batched!(seal_hash_blake2_128_per_kb), hash_blake2_128_per_byte: to_weight!(cost_byte_batched!(seal_hash_blake2_128_per_kb)),
ecdsa_recover: cost_batched!(seal_ecdsa_recover), ecdsa_recover: to_weight!(cost_batched!(seal_ecdsa_recover)),
ecdsa_to_eth_address: cost_batched!(seal_ecdsa_to_eth_address), ecdsa_to_eth_address: to_weight!(cost_batched!(seal_ecdsa_to_eth_address)),
reentrance_count: cost_batched!(seal_reentrance_count), reentrance_count: to_weight!(cost_batched!(seal_reentrance_count)),
account_reentrance_count: cost_batched!(seal_account_reentrance_count), account_reentrance_count: to_weight!(cost_batched!(seal_account_reentrance_count)),
instantiation_nonce: cost_batched!(seal_instantiation_nonce), instantiation_nonce: to_weight!(cost_batched!(seal_instantiation_nonce)),
_phantom: PhantomData, _phantom: PhantomData,
} }
} }
+2 -2
View File
@@ -416,7 +416,7 @@ pub const BOB: AccountId32 = AccountId32::new([2u8; 32]);
pub const CHARLIE: AccountId32 = AccountId32::new([3u8; 32]); pub const CHARLIE: AccountId32 = AccountId32::new([3u8; 32]);
pub const DJANGO: AccountId32 = AccountId32::new([4u8; 32]); pub const DJANGO: AccountId32 = AccountId32::new([4u8; 32]);
pub const GAS_LIMIT: Weight = Weight::from_ref_time(100_000_000_000).set_proof_size(256 * 1024); pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 512 * 1024);
pub struct ExtBuilder { pub struct ExtBuilder {
existential_deposit: u64, existential_deposit: u64,
@@ -2837,7 +2837,7 @@ fn gas_estimation_call_runtime() {
let call = RuntimeCall::Contracts(crate::Call::call { let call = RuntimeCall::Contracts(crate::Call::call {
dest: addr_callee, dest: addr_callee,
value: 0, value: 0,
gas_limit: GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() / 3), gas_limit: GAS_LIMIT / 3,
storage_deposit_limit: None, storage_deposit_limit: None,
data: vec![], data: vec![],
}); });
+1 -1
View File
@@ -430,7 +430,7 @@ mod tests {
events: Default::default(), events: Default::default(),
runtime_calls: Default::default(), runtime_calls: Default::default(),
schedule: Default::default(), schedule: Default::default(),
gas_meter: GasMeter::new(Weight::from_ref_time(10_000_000_000)), gas_meter: GasMeter::new(Weight::from_parts(10_000_000_000, 10 * 1024 * 1024)),
debug_buffer: Default::default(), debug_buffer: Default::default(),
ecdsa_recover: Default::default(), ecdsa_recover: Default::default(),
} }
@@ -253,7 +253,7 @@ pub enum RuntimeCosts {
/// Weight of calling `seal_ecdsa_recover`. /// Weight of calling `seal_ecdsa_recover`.
EcdsaRecovery, EcdsaRecovery,
/// Weight charged by a chain extension through `seal_call_chain_extension`. /// Weight charged by a chain extension through `seal_call_chain_extension`.
ChainExtension(u64), ChainExtension(Weight),
/// Weight charged for calling into the runtime. /// Weight charged for calling into the runtime.
CallRuntime(Weight), CallRuntime(Weight),
/// Weight of calling `seal_set_code_hash` /// Weight of calling `seal_set_code_hash`
@@ -272,7 +272,7 @@ impl RuntimeCosts {
fn token<T: Config>(&self, s: &HostFnWeights<T>) -> RuntimeToken { fn token<T: Config>(&self, s: &HostFnWeights<T>) -> RuntimeToken {
use self::RuntimeCosts::*; use self::RuntimeCosts::*;
let weight = match *self { let weight = match *self {
MeteringBlock(amount) => s.gas.saturating_add(amount), MeteringBlock(amount) => s.gas.saturating_add(Weight::from_ref_time(amount)),
CopyFromContract(len) => s.return_per_byte.saturating_mul(len.into()), CopyFromContract(len) => s.return_per_byte.saturating_mul(len.into()),
CopyToContract(len) => s.input_per_byte.saturating_mul(len.into()), CopyToContract(len) => s.input_per_byte.saturating_mul(len.into()),
Caller => s.caller, Caller => s.caller,
@@ -335,8 +335,8 @@ impl RuntimeCosts {
.hash_blake2_128 .hash_blake2_128
.saturating_add(s.hash_blake2_128_per_byte.saturating_mul(len.into())), .saturating_add(s.hash_blake2_128_per_byte.saturating_mul(len.into())),
EcdsaRecovery => s.ecdsa_recover, EcdsaRecovery => s.ecdsa_recover,
ChainExtension(amount) => amount, ChainExtension(weight) => weight,
CallRuntime(weight) => weight.ref_time(), CallRuntime(weight) => weight,
SetCodeHash => s.set_code_hash, SetCodeHash => s.set_code_hash,
EcdsaToEthAddress => s.ecdsa_to_eth_address, EcdsaToEthAddress => s.ecdsa_to_eth_address,
ReentrantCount => s.reentrance_count, ReentrantCount => s.reentrance_count,
@@ -346,7 +346,7 @@ impl RuntimeCosts {
RuntimeToken { RuntimeToken {
#[cfg(test)] #[cfg(test)]
_created_from: *self, _created_from: *self,
weight: Weight::from_ref_time(weight), weight,
} }
} }
} }