Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
charge debug_message per byte of the message
  • Loading branch information
agryaznov committed Jan 20, 2023
commit 47c2d8f95373620bb45db13f0f044eaf1cbbfb3f
7 changes: 3 additions & 4 deletions frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,8 @@ benchmarks! {
// limited by T::MaxCodeLen::get(), being far less than 1Mb.
//
// So we import maximum allowed memory to the module, in which only the beginning will be initialized by
// some data which represents following use cases: ASCII printable and control codes, as well an invalid utf-8 byte.
// All unitialized memory will get 0-bytes which is decoded to utf-8 NUL control code.
// some data which represents following use cases: ASCII printable and control codes, and an invalid utf-8 byte.
// All unitialized memory bytes will get 0 value which is decoded to utf-8 NUL control code.
let code = WasmModule::<T>::from(ModuleDefinition {
memory: Some(ImportedMemory {
min_pages: T::Schedule::get().limits.memory_pages,
Expand Down Expand Up @@ -1054,8 +1054,7 @@ benchmarks! {
])),
.. Default::default()
});
println!("n= {}, seal_set_storage_per_kb code size: {}", n, code.code.len());
let instance = Contract::<T>::new(code, vec![])?;
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
for key in keys {
Storage::<T>::write(
Expand Down
4 changes: 4 additions & 0 deletions frame/contracts/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ pub struct HostFnWeights<T: Config> {
/// Weight of calling `seal_debug_message`.
pub debug_message: Weight,

/// Weight of calling `seal_debug_message` per byte of the message.
pub debug_message_per_byte: Weight,

/// Weight of calling `seal_set_storage`.
pub set_storage: Weight,

Expand Down Expand Up @@ -644,6 +647,7 @@ impl<T: Config> Default for HostFnWeights<T> {
1
)),
debug_message: to_weight!(cost_batched!(seal_debug_message)),
debug_message_per_byte: to_weight!(cost_byte_batched!(seal_debug_message_per_kb)),
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)),
Expand Down
18 changes: 10 additions & 8 deletions frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ pub enum RuntimeCosts {
Random,
/// Weight of calling `seal_deposit_event` with the given number of topics and event size.
DepositEvent { num_topic: u32, len: u32 },
/// Weight of calling `seal_debug_message`.
DebugMessage,
/// Weight of calling `seal_debug_message` per byte of passed message.
DebugMessage(u32),
/// Weight of calling `seal_set_storage` for the given storage item sizes.
SetStorage { old_bytes: u32, new_bytes: u32 },
/// Weight of calling `seal_clear_storage` per cleared byte.
Expand Down Expand Up @@ -293,7 +293,9 @@ impl RuntimeCosts {
.deposit_event
.saturating_add(s.deposit_event_per_topic.saturating_mul(num_topic.into()))
.saturating_add(s.deposit_event_per_byte.saturating_mul(len.into())),
DebugMessage => s.debug_message,
DebugMessage(len) => s
.debug_message
.saturating_add(s.deposit_event_per_byte.saturating_mul(len.into())),
SetStorage { new_bytes, old_bytes } => s
.set_storage
.saturating_add(s.set_storage_per_new_byte.saturating_mul(new_bytes.into()))
Expand Down Expand Up @@ -2039,7 +2041,7 @@ pub mod env {
_delta_ptr: u32,
_delta_count: u32,
) -> Result<(), TrapReason> {
ctx.charge_gas(RuntimeCosts::DebugMessage)?;
ctx.charge_gas(RuntimeCosts::DebugMessage(0))?;
Ok(())
}

Expand All @@ -2060,7 +2062,7 @@ pub mod env {
_delta_ptr: u32,
_delta_count: u32,
) -> Result<(), TrapReason> {
ctx.charge_gas(RuntimeCosts::DebugMessage)?;
ctx.charge_gas(RuntimeCosts::DebugMessage(0))?;
Ok(())
}

Expand Down Expand Up @@ -2120,7 +2122,7 @@ pub mod env {
_value_ptr: u32,
_value_len: u32,
) -> Result<(), TrapReason> {
ctx.charge_gas(RuntimeCosts::DebugMessage)?;
ctx.charge_gas(RuntimeCosts::DebugMessage(0))?;
Ok(())
}

Expand All @@ -2133,7 +2135,7 @@ pub mod env {
#[version(1)]
#[prefixed_alias]
fn set_rent_allowance(ctx: _, _memory: _, _value_ptr: u32) -> Result<(), TrapReason> {
ctx.charge_gas(RuntimeCosts::DebugMessage)?;
ctx.charge_gas(RuntimeCosts::DebugMessage(0))?;
Ok(())
}

Expand Down Expand Up @@ -2364,7 +2366,7 @@ pub mod env {
str_ptr: u32,
str_len: u32,
) -> Result<ReturnCode, TrapReason> {
ctx.charge_gas(RuntimeCosts::DebugMessage)?;
ctx.charge_gas(RuntimeCosts::DebugMessage(str_len))?;
if ctx.ext.append_debug_buffer("") {
let data = ctx.read_sandbox_memory(memory, str_ptr, str_len)?;
if let Some(msg) = core::str::from_utf8(&data).ok() {
Expand Down
22 changes: 22 additions & 0 deletions frame/contracts/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub trait WeightInfo {
fn seal_deposit_event(r: u32, ) -> Weight;
fn seal_deposit_event_per_topic_and_kb(t: u32, n: u32, ) -> Weight;
fn seal_debug_message(r: u32, ) -> Weight;
fn seal_debug_message_per_kb(n: u32, ) -> Weight;
fn seal_set_storage(r: u32, ) -> Weight;
fn seal_set_storage_per_new_kb(n: u32, ) -> Weight;
fn seal_set_storage_per_old_kb(n: u32, ) -> Weight;
Expand Down Expand Up @@ -642,6 +643,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(3))
}

// brand new (stubbed until automated bencmark run)
fn seal_debug_message_per_kb(n: u32, ) -> Weight {
// Minimum execution time: 157_706 nanoseconds.
Weight::from_ref_time(161_895_583)
// Standard Error: 14_952
.saturating_add(Weight::from_ref_time(12_990_237).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(3))
}

// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `r` is `[0, 10]`.
fn seal_set_storage(r: u32, ) -> Weight {
Expand Down Expand Up @@ -1919,6 +1931,16 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(3))
}
// brand new (stubbed until automated bencmark run)
fn seal_debug_message_per_kb(n: u32, ) -> Weight {
// Minimum execution time: 157_706 nanoseconds.
// Minimum execution time: 157_706 nanoseconds.
Weight::from_ref_time(161_895_583)
// Standard Error: 14_952
.saturating_add(Weight::from_ref_time(12_990_237).saturating_mul(n.into()))
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(3))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `r` is `[0, 10]`.
fn seal_set_storage(r: u32, ) -> Weight {
Expand Down