[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
@@ -2928,7 +2928,7 @@ benchmarks! {
// configured `Schedule` during benchmark development.
// It can be outputed using the following command:
// 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
#[extra]
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.
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.
@@ -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) {
self.inner
.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.
@@ -408,8 +408,7 @@ impl<'a, 'b, E: Ext, S: BufOut> Environment<'a, 'b, E, S> {
buffer,
allow_skip,
|len| {
weight_per_byte
.map(|w| RuntimeCosts::ChainExtension(w.ref_time().saturating_mul(len.into())))
weight_per_byte.map(|w| RuntimeCosts::ChainExtension(w.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
/// 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
/// then the counter will be set to zero.
/// NOTE that amount isn't consumed if there is not enough gas. This is considered
/// safe because we always charge gas before performing any resource-spending action.
#[inline]
pub fn charge<Tok: Token<T>>(&mut self, token: Tok) -> Result<ChargedAmount, DispatchError> {
#[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`.
#[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)]
#[deprecated(note = "1D weight is used in this extrinsic, please migrate to `call`")]
pub fn call_old_weight(
@@ -396,7 +396,7 @@ pub mod pallet {
origin,
dest,
value,
<Pallet<T>>::compat_weight(gas_limit),
<Pallet<T>>::compat_weight_limit(gas_limit),
storage_deposit_limit,
data,
)
@@ -406,7 +406,7 @@ pub mod pallet {
#[pallet::call_index(1)]
#[pallet::weight(
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)]
#[deprecated(
@@ -424,7 +424,7 @@ pub mod pallet {
Self::instantiate_with_code(
origin,
value,
<Pallet<T>>::compat_weight(gas_limit),
<Pallet<T>>::compat_weight_limit(gas_limit),
storage_deposit_limit,
code,
data,
@@ -435,7 +435,7 @@ pub mod pallet {
/// Deprecated version if [`Self::instantiate`] for use in an in-storage `Call`.
#[pallet::call_index(2)]
#[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)]
#[deprecated(note = "1D weight is used in this extrinsic, please migrate to `instantiate`")]
@@ -451,7 +451,7 @@ pub mod pallet {
Self::instantiate(
origin,
value,
<Pallet<T>>::compat_weight(gas_limit),
<Pallet<T>>::compat_weight_limit(gas_limit),
storage_deposit_limit,
code_hash,
data,
@@ -1216,12 +1216,12 @@ impl<T: Config> Pallet<T> {
<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
/// or an old `Call` will just fail.
fn compat_weight(gas_limit: OldWeight) -> Weight {
Weight::from(gas_limit).set_proof_size(u64::from(T::MaxCodeLen::get()) * 2)
/// Used by backwards compatible extrinsics. We cannot just set the proof_size weight limit to
/// zero or an old `Call` will just fail with OutOfGas.
fn compat_weight_limit(gas_limit: OldWeight) -> Weight {
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 codec::{Decode, Encode};
use frame_support::DefaultNoBound;
use frame_support::{weights::Weight, DefaultNoBound};
use pallet_contracts_proc_macro::{ScheduleDebug, WeightDebug};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
@@ -169,7 +169,7 @@ impl Limits {
/// that use them as supporting instructions. Supporting means mainly pushing arguments
/// and dropping return values in order to maintain a valid module.
#[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))]
pub struct InstructionWeights<T: Config> {
/// Version of the instruction weights.
@@ -255,178 +255,178 @@ pub struct InstructionWeights<T: Config> {
#[scale_info(skip_type_params(T))]
pub struct HostFnWeights<T: Config> {
/// Weight of calling `seal_caller`.
pub caller: u64,
pub caller: Weight,
/// Weight of calling `seal_is_contract`.
pub is_contract: u64,
pub is_contract: Weight,
/// Weight of calling `seal_code_hash`.
pub code_hash: u64,
pub code_hash: Weight,
/// Weight of calling `seal_own_code_hash`.
pub own_code_hash: u64,
pub own_code_hash: Weight,
/// Weight of calling `seal_caller_is_origin`.
pub caller_is_origin: u64,
pub caller_is_origin: Weight,
/// Weight of calling `seal_address`.
pub address: u64,
pub address: Weight,
/// Weight of calling `seal_gas_left`.
pub gas_left: u64,
pub gas_left: Weight,
/// Weight of calling `seal_balance`.
pub balance: u64,
pub balance: Weight,
/// Weight of calling `seal_value_transferred`.
pub value_transferred: u64,
pub value_transferred: Weight,
/// Weight of calling `seal_minimum_balance`.
pub minimum_balance: u64,
pub minimum_balance: Weight,
/// Weight of calling `seal_block_number`.
pub block_number: u64,
pub block_number: Weight,
/// Weight of calling `seal_now`.
pub now: u64,
pub now: Weight,
/// Weight of calling `seal_weight_to_fee`.
pub weight_to_fee: u64,
pub weight_to_fee: Weight,
/// Weight of calling `gas`.
pub gas: u64,
pub gas: Weight,
/// Weight of calling `seal_input`.
pub input: u64,
pub input: Weight,
/// 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`.
pub r#return: u64,
pub r#return: Weight,
/// Weight per byte returned through `seal_return`.
pub return_per_byte: u64,
pub return_per_byte: Weight,
/// Weight of calling `seal_terminate`.
pub terminate: u64,
pub terminate: Weight,
/// Weight of calling `seal_random`.
pub random: u64,
pub random: Weight,
/// Weight of calling `seal_reposit_event`.
pub deposit_event: u64,
pub deposit_event: Weight,
/// 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`.
pub deposit_event_per_byte: u64,
pub deposit_event_per_byte: Weight,
/// Weight of calling `seal_debug_message`.
pub debug_message: u64,
pub debug_message: Weight,
/// 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`.
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`.
pub set_storage_per_old_byte: u64,
pub set_storage_per_old_byte: Weight,
/// Weight of calling `seal_set_code_hash`.
pub set_code_hash: u64,
pub set_code_hash: Weight,
/// 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.
pub clear_storage_per_byte: u64,
pub clear_storage_per_byte: Weight,
/// 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.
pub contains_storage_per_byte: u64,
pub contains_storage_per_byte: Weight,
/// 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`.
pub get_storage_per_byte: u64,
pub get_storage_per_byte: Weight,
/// 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`.
pub take_storage_per_byte: u64,
pub take_storage_per_byte: Weight,
/// Weight of calling `seal_transfer`.
pub transfer: u64,
pub transfer: Weight,
/// Weight of calling `seal_call`.
pub call: u64,
pub call: Weight,
/// 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.
pub call_transfer_surcharge: u64,
pub call_transfer_surcharge: Weight,
/// 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`.
pub instantiate: u64,
pub instantiate: Weight,
/// 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`.
pub instantiate_per_input_byte: u64,
pub instantiate_per_input_byte: Weight,
/// 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`.
pub hash_sha2_256: u64,
pub hash_sha2_256: Weight,
/// 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`.
pub hash_keccak_256: u64,
pub hash_keccak_256: Weight,
/// 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`.
pub hash_blake2_256: u64,
pub hash_blake2_256: Weight,
/// 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`.
pub hash_blake2_128: u64,
pub hash_blake2_128: Weight,
/// 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`.
pub ecdsa_recover: u64,
pub ecdsa_recover: Weight,
/// 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`.
pub reentrance_count: u64,
pub reentrance_count: Weight,
/// Weight of calling `account_reentrance_count`.
pub account_reentrance_count: u64,
pub account_reentrance_count: Weight,
/// Weight of calling `instantiation_nonce`.
pub instantiation_nonce: u64,
pub instantiation_nonce: Weight,
/// The type parameter is used in the default implementation.
#[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 {
fn default() -> Self {
Self {
@@ -596,85 +602,115 @@ impl<T: Config> Default for InstructionWeights<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 {
Self {
caller: cost_batched!(seal_caller),
is_contract: cost_batched!(seal_is_contract),
code_hash: cost_batched!(seal_code_hash),
own_code_hash: cost_batched!(seal_own_code_hash),
caller_is_origin: cost_batched!(seal_caller_is_origin),
address: cost_batched!(seal_address),
gas_left: cost_batched!(seal_gas_left),
balance: cost_batched!(seal_balance),
value_transferred: cost_batched!(seal_value_transferred),
minimum_balance: cost_batched!(seal_minimum_balance),
block_number: cost_batched!(seal_block_number),
now: cost_batched!(seal_now),
weight_to_fee: cost_batched!(seal_weight_to_fee),
gas: cost_batched!(seal_gas),
input: cost_batched!(seal_input),
input_per_byte: cost_byte_batched!(seal_input_per_kb),
r#return: cost!(seal_return),
return_per_byte: cost_byte!(seal_return_per_kb),
terminate: cost!(seal_terminate),
random: cost_batched!(seal_random),
deposit_event: cost_batched!(seal_deposit_event),
deposit_event_per_topic: cost_batched_args!(seal_deposit_event_per_topic_and_kb, 1, 0),
deposit_event_per_byte: cost_byte_batched_args!(
caller: to_weight!(cost_batched!(seal_caller)),
is_contract: to_weight!(cost_batched!(seal_is_contract)),
code_hash: to_weight!(cost_batched!(seal_code_hash)),
own_code_hash: to_weight!(cost_batched!(seal_own_code_hash)),
caller_is_origin: to_weight!(cost_batched!(seal_caller_is_origin)),
address: to_weight!(cost_batched!(seal_address)),
gas_left: to_weight!(cost_batched!(seal_gas_left)),
balance: to_weight!(cost_batched!(seal_balance)),
value_transferred: to_weight!(cost_batched!(seal_value_transferred)),
minimum_balance: to_weight!(cost_batched!(seal_minimum_balance)),
block_number: to_weight!(cost_batched!(seal_block_number)),
now: to_weight!(cost_batched!(seal_now)),
weight_to_fee: to_weight!(cost_batched!(seal_weight_to_fee)),
gas: to_weight!(cost_batched!(seal_gas)),
input: to_weight!(cost_batched!(seal_input)),
input_per_byte: to_weight!(cost_byte_batched!(seal_input_per_kb)),
r#return: to_weight!(cost!(seal_return)),
return_per_byte: to_weight!(cost_byte!(seal_return_per_kb)),
terminate: to_weight!(cost!(seal_terminate)),
random: to_weight!(cost_batched!(seal_random)),
deposit_event: to_weight!(cost_batched!(seal_deposit_event)),
deposit_event_per_topic: to_weight!(cost_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,
0,
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),
set_storage: cost_batched!(seal_set_storage),
set_code_hash: cost_batched!(seal_set_code_hash),
set_storage_per_new_byte: cost_byte_batched!(seal_set_storage_per_new_kb),
set_storage_per_old_byte: cost_byte_batched!(seal_set_storage_per_old_kb),
clear_storage: cost_batched!(seal_clear_storage),
clear_storage_per_byte: cost_byte_batched!(seal_clear_storage_per_kb),
contains_storage: cost_batched!(seal_contains_storage),
contains_storage_per_byte: cost_byte_batched!(seal_contains_storage_per_kb),
get_storage: cost_batched!(seal_get_storage),
get_storage_per_byte: cost_byte_batched!(seal_get_storage_per_kb),
take_storage: cost_batched!(seal_take_storage),
take_storage_per_byte: cost_byte_batched!(seal_take_storage_per_kb),
transfer: cost_batched!(seal_transfer),
call: cost_batched!(seal_call),
delegate_call: cost_batched!(seal_delegate_call),
call_transfer_surcharge: cost_batched_args!(seal_call_per_transfer_clone_kb, 1, 0),
call_per_cloned_byte: cost_batched_args!(seal_call_per_transfer_clone_kb, 0, 1),
instantiate: cost_batched!(seal_instantiate),
instantiate_transfer_surcharge: cost_byte_batched_args!(
clear_storage: to_weight!(cost_batched!(seal_clear_storage)),
clear_storage_per_byte: to_weight!(cost_byte_batched!(seal_clear_storage_per_kb), 1u64),
contains_storage: to_weight!(cost_batched!(seal_contains_storage)),
contains_storage_per_byte: to_weight!(
cost_byte_batched!(seal_contains_storage_per_kb),
1u64
),
get_storage: to_weight!(cost_batched!(seal_get_storage)),
get_storage_per_byte: to_weight!(cost_byte_batched!(seal_get_storage_per_kb), 1u64),
take_storage: to_weight!(cost_batched!(seal_take_storage)),
take_storage_per_byte: to_weight!(cost_byte_batched!(seal_take_storage_per_kb), 1u64),
transfer: to_weight!(cost_batched!(seal_transfer)),
call: to_weight!(cost_batched!(seal_call)),
delegate_call: to_weight!(cost_batched!(seal_delegate_call)),
call_transfer_surcharge: to_weight!(cost_batched_args!(
seal_call_per_transfer_clone_kb,
1,
0
)),
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,
1,
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,
0,
1,
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,
0,
0,
1
),
hash_sha2_256: cost_batched!(seal_hash_sha2_256),
hash_sha2_256_per_byte: cost_byte_batched!(seal_hash_sha2_256_per_kb),
hash_keccak_256: cost_batched!(seal_hash_keccak_256),
hash_keccak_256_per_byte: cost_byte_batched!(seal_hash_keccak_256_per_kb),
hash_blake2_256: cost_batched!(seal_hash_blake2_256),
hash_blake2_256_per_byte: cost_byte_batched!(seal_hash_blake2_256_per_kb),
hash_blake2_128: cost_batched!(seal_hash_blake2_128),
hash_blake2_128_per_byte: cost_byte_batched!(seal_hash_blake2_128_per_kb),
ecdsa_recover: cost_batched!(seal_ecdsa_recover),
ecdsa_to_eth_address: cost_batched!(seal_ecdsa_to_eth_address),
reentrance_count: cost_batched!(seal_reentrance_count),
account_reentrance_count: cost_batched!(seal_account_reentrance_count),
instantiation_nonce: cost_batched!(seal_instantiation_nonce),
)),
hash_sha2_256: to_weight!(cost_batched!(seal_hash_sha2_256)),
hash_sha2_256_per_byte: to_weight!(cost_byte_batched!(seal_hash_sha2_256_per_kb)),
hash_keccak_256: to_weight!(cost_batched!(seal_hash_keccak_256)),
hash_keccak_256_per_byte: to_weight!(cost_byte_batched!(seal_hash_keccak_256_per_kb)),
hash_blake2_256: to_weight!(cost_batched!(seal_hash_blake2_256)),
hash_blake2_256_per_byte: to_weight!(cost_byte_batched!(seal_hash_blake2_256_per_kb)),
hash_blake2_128: to_weight!(cost_batched!(seal_hash_blake2_128)),
hash_blake2_128_per_byte: to_weight!(cost_byte_batched!(seal_hash_blake2_128_per_kb)),
ecdsa_recover: to_weight!(cost_batched!(seal_ecdsa_recover)),
ecdsa_to_eth_address: to_weight!(cost_batched!(seal_ecdsa_to_eth_address)),
reentrance_count: to_weight!(cost_batched!(seal_reentrance_count)),
account_reentrance_count: to_weight!(cost_batched!(seal_account_reentrance_count)),
instantiation_nonce: to_weight!(cost_batched!(seal_instantiation_nonce)),
_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 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 {
existential_deposit: u64,
@@ -2837,7 +2837,7 @@ fn gas_estimation_call_runtime() {
let call = RuntimeCall::Contracts(crate::Call::call {
dest: addr_callee,
value: 0,
gas_limit: GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() / 3),
gas_limit: GAS_LIMIT / 3,
storage_deposit_limit: None,
data: vec![],
});
+1 -1
View File
@@ -430,7 +430,7 @@ mod tests {
events: Default::default(),
runtime_calls: 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(),
ecdsa_recover: Default::default(),
}
@@ -253,7 +253,7 @@ pub enum RuntimeCosts {
/// Weight of calling `seal_ecdsa_recover`.
EcdsaRecovery,
/// Weight charged by a chain extension through `seal_call_chain_extension`.
ChainExtension(u64),
ChainExtension(Weight),
/// Weight charged for calling into the runtime.
CallRuntime(Weight),
/// Weight of calling `seal_set_code_hash`
@@ -272,7 +272,7 @@ impl RuntimeCosts {
fn token<T: Config>(&self, s: &HostFnWeights<T>) -> RuntimeToken {
use self::RuntimeCosts::*;
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()),
CopyToContract(len) => s.input_per_byte.saturating_mul(len.into()),
Caller => s.caller,
@@ -335,8 +335,8 @@ impl RuntimeCosts {
.hash_blake2_128
.saturating_add(s.hash_blake2_128_per_byte.saturating_mul(len.into())),
EcdsaRecovery => s.ecdsa_recover,
ChainExtension(amount) => amount,
CallRuntime(weight) => weight.ref_time(),
ChainExtension(weight) => weight,
CallRuntime(weight) => weight,
SetCodeHash => s.set_code_hash,
EcdsaToEthAddress => s.ecdsa_to_eth_address,
ReentrantCount => s.reentrance_count,
@@ -346,7 +346,7 @@ impl RuntimeCosts {
RuntimeToken {
#[cfg(test)]
_created_from: *self,
weight: Weight::from_ref_time(weight),
weight,
}
}
}