Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Prev Previous commit
Next Next commit
Adapt to the new WeightInfo
The new benchmarks add a new parameter for salt "s" to the instantiate weights
that needs to be applied.
  • Loading branch information
athei committed Nov 10, 2020
commit 320bd3dc3d17481fab051466962a67c6c80aaf80
7 changes: 6 additions & 1 deletion frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,12 @@ decl_module! {
/// after the execution is saved as the `code` of the account. That code will be invoked
/// upon any call received by this account.
/// - The contract is initialized.
#[weight = T::WeightInfo::instantiate(data.len() as u32 / 1024).saturating_add(*gas_limit)]
#[weight =
T::WeightInfo::instantiate(
data.len() as u32 / 1024,
salt.len() as u32 / 1024,
).saturating_add(*gas_limit)
]
pub fn instantiate(
origin,
#[compact] endowment: BalanceOf<T>,
Expand Down
8 changes: 6 additions & 2 deletions frame/contracts/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ pub struct HostFnWeights<T: Trait> {
/// Weight per output byte received through `seal_instantiate`.
pub instantiate_per_output_byte: Weight,

/// Weight per salt byte supplied to `seal_instantiate`.
pub instantiate_per_salt_byte: Weight,

/// Weight of calling `seal_hash_sha_256`.
pub hash_sha2_256: Weight,

Expand Down Expand Up @@ -535,8 +538,9 @@ impl<T: Trait> Default for HostFnWeights<T> {
call_per_input_byte: cost_byte_batched_args!(seal_call_per_transfer_input_output_kb, 0, 1, 0),
call_per_output_byte: cost_byte_batched_args!(seal_call_per_transfer_input_output_kb, 0, 0, 1),
instantiate: cost_batched!(seal_instantiate),
instantiate_per_input_byte: cost_byte_batched_args!(seal_instantiate_per_input_output_kb, 1, 0),
instantiate_per_output_byte: cost_byte_batched_args!(seal_instantiate_per_input_output_kb, 0, 1),
instantiate_per_input_byte: cost_byte_batched_args!(seal_instantiate_per_input_output_salt_kb, 1, 0, 0),
instantiate_per_output_byte: cost_byte_batched_args!(seal_instantiate_per_input_output_salt_kb, 0, 1, 0),
instantiate_per_salt_byte: cost_byte_batched_args!(seal_instantiate_per_input_output_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),
Expand Down
11 changes: 6 additions & 5 deletions frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ pub enum RuntimeToken {
CallSurchargeTransfer,
/// Weight of output received through `seal_call` for the given size.
CallCopyOut(u32),
/// Weight of calling `seal_instantiate` for the given input size without output weight.
/// Weight of calling `seal_instantiate` for the given input and salt without output weight.
/// This includes the transfer as an instantiate without a value will always be below
/// the existential deposit and is disregarded as corner case.
InstantiateBase(u32),
InstantiateBase{input_data_len: u32, salt_len: u32},
/// Weight of output received through `seal_instantiate` for the given size.
InstantiateCopyOut(u32),
/// Weight of calling `seal_hash_sha_256` for the given input size.
Expand Down Expand Up @@ -236,8 +236,9 @@ where
.saturating_add(s.call_per_input_byte.saturating_mul(len.into())),
CallSurchargeTransfer => s.call_transfer_surcharge,
CallCopyOut(len) => s.call_per_output_byte.saturating_mul(len.into()),
InstantiateBase(len) => s.instantiate
.saturating_add(s.instantiate_per_input_byte.saturating_mul(len.into())),
InstantiateBase{input_data_len, salt_len} => s.instantiate
.saturating_add(s.instantiate_per_input_byte.saturating_mul(input_data_len.into()))
.saturating_add(s.instantiate_per_salt_byte.saturating_mul(salt_len.into())),
InstantiateCopyOut(len) => s.instantiate_per_output_byte
.saturating_mul(len.into()),
HashSha256(len) => s.hash_sha2_256
Expand Down Expand Up @@ -860,7 +861,7 @@ define_env!(Env, <E: Ext>,
salt_ptr: u32,
salt_len: u32
) -> ReturnCode => {
ctx.charge_gas(RuntimeToken::InstantiateBase(input_data_len))?;
ctx.charge_gas(RuntimeToken::InstantiateBase {input_data_len, salt_len})?;
let code_hash: CodeHash<<E as Ext>::T> =
ctx.read_sandbox_memory_as(code_hash_ptr, code_hash_len)?;
let value: BalanceOf<<E as Ext>::T> = ctx.read_sandbox_memory_as(value_ptr, value_len)?;
Expand Down