Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
charge debug_message per byte of the message
Browse files Browse the repository at this point in the history
  • Loading branch information
agryaznov committed Jan 20, 2023
1 parent f260505 commit fd7323c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
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

0 comments on commit fd7323c

Please sign in to comment.