diff --git a/frame/contracts/src/benchmarking/mod.rs b/frame/contracts/src/benchmarking/mod.rs index 8bc1ae35d1bb7..96dafb0c53f0a 100644 --- a/frame/contracts/src/benchmarking/mod.rs +++ b/frame/contracts/src/benchmarking/mod.rs @@ -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::::from(ModuleDefinition { memory: Some(ImportedMemory { min_pages: T::Schedule::get().limits.memory_pages, @@ -1054,8 +1054,7 @@ benchmarks! { ])), .. Default::default() }); - println!("n= {}, seal_set_storage_per_kb code size: {}", n, code.code.len()); - let instance = Contract::::new(code, vec![])?; + let instance = Contract::::new(code, vec![])?; let info = instance.info()?; for key in keys { Storage::::write( diff --git a/frame/contracts/src/schedule.rs b/frame/contracts/src/schedule.rs index eabd18c818952..178c8f95cbbcf 100644 --- a/frame/contracts/src/schedule.rs +++ b/frame/contracts/src/schedule.rs @@ -323,6 +323,9 @@ pub struct HostFnWeights { /// 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, @@ -644,6 +647,7 @@ impl Default for HostFnWeights { 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)), diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index 957eb59f4d012..9733236526105 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -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. @@ -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())) @@ -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(()) } @@ -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(()) } @@ -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(()) } @@ -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(()) } @@ -2364,7 +2366,7 @@ pub mod env { str_ptr: u32, str_len: u32, ) -> Result { - 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() { diff --git a/frame/contracts/src/weights.rs b/frame/contracts/src/weights.rs index 7ae1a9c594671..a64e0db1ec4a0 100644 --- a/frame/contracts/src/weights.rs +++ b/frame/contracts/src/weights.rs @@ -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; @@ -642,6 +643,17 @@ impl WeightInfo for SubstrateWeight { .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 { @@ -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 {