From 50a4ec10b145d793ba112d29092e64287f8400c4 Mon Sep 17 00:00:00 2001 From: Georgy Shepelev Date: Sun, 17 Sep 2023 20:30:16 +0400 Subject: [PATCH] refactor(node): Benchmark tasks and reduce GasAllowance accordingly (#2797) --- Cargo.lock | 2 + Cargo.toml | 8 +- common/src/lib.rs | 15 +- common/src/scheduler/task.rs | 28 +- examples/constructor/Cargo.toml | 4 +- examples/constructor/build.rs | 6 +- examples/constructor/src/arg.rs | 2 +- examples/constructor/src/call.rs | 2 +- examples/constructor/src/lib.rs | 10 +- .../src/scheme/demo_proxy_with_gas.rs | 2 +- examples/delayed-sender/Cargo.toml | 3 +- examples/delayed-sender/build.rs | 6 +- examples/delayed-sender/src/code.rs | 18 + examples/delayed-sender/src/lib.rs | 7 +- examples/init-wait/Cargo.toml | 9 +- examples/init-wait/build.rs | 6 +- examples/init-wait/src/code.rs | 18 + examples/init-wait/src/lib.rs | 24 +- examples/reserve-gas/Cargo.toml | 3 +- examples/reserve-gas/build.rs | 6 +- examples/reserve-gas/src/lib.rs | 6 +- examples/wait_wake/build.rs | 6 +- examples/waiter/Cargo.toml | 8 +- examples/waiter/build.rs | 6 +- examples/waiter/src/code.rs | 28 +- examples/waiter/src/lib.rs | 30 +- gclient/Cargo.toml | 4 +- gsdk/Cargo.toml | 2 +- gsdk/tests/rpc.rs | 2 +- pallets/gear-scheduler/src/tests.rs | 15 +- pallets/gear/Cargo.toml | 15 + pallets/gear/src/benchmarking/mod.rs | 122 +++++- pallets/gear/src/benchmarking/tasks.rs | 371 ++++++++++++++++++ pallets/gear/src/lib.rs | 58 ++- pallets/gear/src/manager/task.rs | 164 ++++++-- pallets/gear/src/mock.rs | 2 +- pallets/gear/src/tests.rs | 37 +- pallets/gear/src/weights.rs | 231 +++++++++++ runtime/gear/src/weights/pallet_gear.rs | 231 +++++++++++ runtime/vara/src/weights/pallet_gear.rs | 231 +++++++++++ 40 files changed, 1595 insertions(+), 153 deletions(-) create mode 100644 pallets/gear/src/benchmarking/tasks.rs diff --git a/Cargo.lock b/Cargo.lock index 108999619f0..76d3ff7a82e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1903,6 +1903,7 @@ dependencies = [ name = "demo-constructor" version = "0.1.0" dependencies = [ + "gcore", "gear-wasm-builder", "gstd", "hex", @@ -2314,6 +2315,7 @@ version = "0.1.0" dependencies = [ "demo-waiter", "futures", + "gcore", "gear-core", "gear-wasm-builder", "gstd", diff --git a/Cargo.toml b/Cargo.toml index 108d5011b92..1b581dac2b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -371,7 +371,7 @@ demo-calc-hash-in-one-block = { path = "examples/calc-hash/in-one-block" } demo-calc-hash-over-blocks = { path = "examples/calc-hash/over-blocks" } demo-custom = { path = "examples/custom" } demo-compose = { path = "examples/compose" } -demo-constructor = { path = "examples/constructor" } +demo-constructor = { path = "examples/constructor", default-features = false } demo-delayed-sender = { path = "examples/delayed-sender" } demo-distributor = { path = "examples/distributor" } demo-futures-unordered = { path = "examples/futures-unordered", features = ["debug"] } @@ -379,7 +379,7 @@ demo-gas-burned = { path = "examples/gas-burned" } demo-fungible-token = { path = "examples/fungible-token" } demo-incomplete-async-payloads = { path = "examples/incomplete-async-payloads" } demo-init-fail-sender = { path = "examples/init-fail-sender" } -demo-init-wait = { path = "examples/init-wait" } +demo-init-wait = { path = "examples/init-wait", default-features = false } demo-init-wait-reply-exit = { path = "examples/init-wait-reply-exit" } demo-messager = { path = "examples/messager" } demo-meta-io = { path = "examples/new-meta/io" } @@ -396,7 +396,7 @@ demo-proxy-relay = { path = "examples/proxy-relay" } demo-proxy-reservation-with-gas = { path = "examples/proxy-reservation-with-gas" } demo-read-big-state = { path = "examples/read-big-state", default-features = false } demo-reservation-manager = { path = "examples/reservation-manager" } -demo-reserve-gas = { path = "examples/reserve-gas" } +demo-reserve-gas = { path = "examples/reserve-gas", default-features = false } demo-rwlock = { path = "examples/rwlock" } demo-send-from-reservation = { path = "examples/send-from-reservation" } demo-signal-entry = { path = "examples/signal-entry" } @@ -404,7 +404,7 @@ demo-state-rollback = { path = "examples/state-rollback" } demo-sync-duplicate = { path = "examples/sync-duplicate" } demo-vec = { path = "examples/vec" } demo-wait = { path = "examples/wait" } -demo-waiter = { path = "examples/waiter" } +demo-waiter = { path = "examples/waiter", default-features = false } demo-wait-timeout = { path = "examples/wait-timeout" } demo-wait-wake = { path = "examples/wait_wake" } demo-waiting-proxy = { path = "examples/waiting-proxy" } diff --git a/common/src/lib.rs b/common/src/lib.rs index 3d4873bb6a2..64f47fd4aa4 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -73,6 +73,9 @@ pub use gas_provider::{ LockId, LockableTree, Provider as GasProvider, ReservableTree, Tree as GasTree, }; +/// Type alias for gas entity. +pub type Gas = u64; + pub trait Origin: Sized { fn into_origin(self) -> H256; fn from_origin(val: H256) -> Self; @@ -228,18 +231,6 @@ impl Program { }) ) } - - pub fn is_uninitialized(&self) -> Option { - if let Program::Active(ActiveProgram { - state: ProgramState::Uninitialized { message_id }, - .. - }) = self - { - Some(*message_id) - } else { - None - } - } } #[derive(Clone, Debug, derive_more::Display)] diff --git a/common/src/scheduler/task.rs b/common/src/scheduler/task.rs index ebeb0ff7e78..cbfd0575943 100644 --- a/common/src/scheduler/task.rs +++ b/common/src/scheduler/task.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::paused_program_storage::SessionId; +use crate::{paused_program_storage::SessionId, Gas}; use frame_support::{ codec::{self, Decode, Encode, MaxEncodedLen}, scale_info::{self, TypeInfo}, @@ -85,7 +85,7 @@ pub enum ScheduledTask { } impl ScheduledTask { - pub fn process_with(self, handler: &mut impl TaskHandler) { + pub fn process_with(self, handler: &mut impl TaskHandler) -> Gas { use ScheduledTask::*; match self { @@ -117,32 +117,36 @@ pub trait TaskHandler { // Rent charging section. // ----- /// Pause program action. - fn pause_program(&mut self, program_id: ProgramId); + fn pause_program(&mut self, program_id: ProgramId) -> Gas; /// Remove code action. - fn remove_code(&mut self, code_id: CodeId); + fn remove_code(&mut self, code_id: CodeId) -> Gas; /// Remove from mailbox action. - fn remove_from_mailbox(&mut self, user_id: AccountId, message_id: MessageId); + fn remove_from_mailbox(&mut self, user_id: AccountId, message_id: MessageId) -> Gas; /// Remove from waitlist action. - fn remove_from_waitlist(&mut self, program_id: ProgramId, message_id: MessageId); + fn remove_from_waitlist(&mut self, program_id: ProgramId, message_id: MessageId) -> Gas; /// Remove paused program action. - fn remove_paused_program(&mut self, program_id: ProgramId); + fn remove_paused_program(&mut self, program_id: ProgramId) -> Gas; // Time chained section. // ----- /// Wake message action. - fn wake_message(&mut self, program_id: ProgramId, message_id: MessageId); + fn wake_message(&mut self, program_id: ProgramId, message_id: MessageId) -> Gas; // Send delayed message to program action. - fn send_dispatch(&mut self, stashed_message_id: MessageId); + fn send_dispatch(&mut self, stashed_message_id: MessageId) -> Gas; // Send delayed message to user action. - fn send_user_message(&mut self, stashed_message_id: MessageId, to_mailbox: bool); + fn send_user_message(&mut self, stashed_message_id: MessageId, to_mailbox: bool) -> Gas; /// Remove gas reservation action. - fn remove_gas_reservation(&mut self, program_id: ProgramId, reservation_id: ReservationId); + fn remove_gas_reservation( + &mut self, + program_id: ProgramId, + reservation_id: ReservationId, + ) -> Gas; /// Remove data created by resume program session. - fn remove_resume_session(&mut self, session_id: SessionId); + fn remove_resume_session(&mut self, session_id: SessionId) -> Gas; } #[test] diff --git a/examples/constructor/Cargo.toml b/examples/constructor/Cargo.toml index 10782f0558e..383ed6e29f7 100644 --- a/examples/constructor/Cargo.toml +++ b/examples/constructor/Cargo.toml @@ -7,6 +7,7 @@ license.workspace = true workspace = "../../" [dependencies] +gcore.workspace = true gstd.workspace = true parity-scale-codec = { workspace = true, features = ["derive"] } hex.workspace = true @@ -16,5 +17,6 @@ gear-wasm-builder.workspace = true [features] debug = ["gstd/debug"] -std = [] +wasm-wrapper = [] +std = ["wasm-wrapper"] default = ["std"] diff --git a/examples/constructor/build.rs b/examples/constructor/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/constructor/build.rs +++ b/examples/constructor/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/constructor/src/arg.rs b/examples/constructor/src/arg.rs index 2d78edf7576..b749bbc03b7 100644 --- a/examples/constructor/src/arg.rs +++ b/examples/constructor/src/arg.rs @@ -90,7 +90,7 @@ impl From<&'static str> for Arg { } } -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm { use super::*; diff --git a/examples/constructor/src/call.rs b/examples/constructor/src/call.rs index 0287abd0db5..06c0fde0edb 100644 --- a/examples/constructor/src/call.rs +++ b/examples/constructor/src/call.rs @@ -44,7 +44,7 @@ pub enum Call { Loop, } -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm { use super::*; use crate::DATA; diff --git a/examples/constructor/src/lib.rs b/examples/constructor/src/lib.rs index d112fb3d26b..0ebc224368d 100644 --- a/examples/constructor/src/lib.rs +++ b/examples/constructor/src/lib.rs @@ -16,22 +16,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] extern crate alloc; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] pub(crate) use wasm::DATA; -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] mod code { include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); } -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] pub use code::WASM_BINARY_OPT as WASM_BINARY; mod arg; diff --git a/examples/constructor/src/scheme/demo_proxy_with_gas.rs b/examples/constructor/src/scheme/demo_proxy_with_gas.rs index 35c33e3b6c1..70b7e2a1ba5 100644 --- a/examples/constructor/src/scheme/demo_proxy_with_gas.rs +++ b/examples/constructor/src/scheme/demo_proxy_with_gas.rs @@ -1,5 +1,5 @@ use crate::{Arg, Call, Calls, Scheme}; -use gstd::errors::{ReplyCode, SuccessReplyReason}; +use gcore::errors::{ReplyCode, SuccessReplyReason}; use parity_scale_codec::Encode; pub const PROXIED_MESSAGE: &[u8] = b"proxied message"; diff --git a/examples/delayed-sender/Cargo.toml b/examples/delayed-sender/Cargo.toml index e23c5e2f310..7c386c1b22a 100644 --- a/examples/delayed-sender/Cargo.toml +++ b/examples/delayed-sender/Cargo.toml @@ -14,5 +14,6 @@ gear-wasm-builder.workspace = true [features] debug = ["gstd/debug"] -std = [ ] +wasm-wrapper = [] +std = ["wasm-wrapper"] default = ["std"] diff --git a/examples/delayed-sender/build.rs b/examples/delayed-sender/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/delayed-sender/build.rs +++ b/examples/delayed-sender/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/delayed-sender/src/code.rs b/examples/delayed-sender/src/code.rs index 3107b539988..c1c1c2d61f8 100644 --- a/examples/delayed-sender/src/code.rs +++ b/examples/delayed-sender/src/code.rs @@ -1,3 +1,21 @@ +// This file is part of Gear. + +// Copyright (C) Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + use gstd::{msg, MessageId, exec}; static mut MID: Option = None; diff --git a/examples/delayed-sender/src/lib.rs b/examples/delayed-sender/src/lib.rs index 9348dfb7a52..1175ebd0d91 100644 --- a/examples/delayed-sender/src/lib.rs +++ b/examples/delayed-sender/src/lib.rs @@ -15,17 +15,18 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . + #![no_std] -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] mod code { include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); } -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] pub use code::WASM_BINARY_OPT as WASM_BINARY; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm { include! {"./code.rs"} } diff --git a/examples/init-wait/Cargo.toml b/examples/init-wait/Cargo.toml index 8b0d9b0b238..5a7c643798f 100644 --- a/examples/init-wait/Cargo.toml +++ b/examples/init-wait/Cargo.toml @@ -2,8 +2,8 @@ name = "demo-init-wait" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" +edition.workspace = true +license.workspace = true workspace = "../../" [dependencies] @@ -12,9 +12,8 @@ gstd.workspace = true [build-dependencies] gear-wasm-builder.workspace = true -[lib] - [features] debug = ["gstd/debug"] -std = [] +wasm-wrapper = [] +std = ["wasm-wrapper"] default = ["std"] diff --git a/examples/init-wait/build.rs b/examples/init-wait/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/init-wait/build.rs +++ b/examples/init-wait/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/init-wait/src/code.rs b/examples/init-wait/src/code.rs index 432a5fe94f1..c6ef0bc9edc 100644 --- a/examples/init-wait/src/code.rs +++ b/examples/init-wait/src/code.rs @@ -1,3 +1,21 @@ +// This file is part of Gear. + +// Copyright (C) 2021-2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + use gstd::{exec, msg, collections::BTreeMap, MessageId}; #[derive(PartialEq, Debug)] diff --git a/examples/init-wait/src/lib.rs b/examples/init-wait/src/lib.rs index e5e4ef17484..a4fc7ea8b42 100644 --- a/examples/init-wait/src/lib.rs +++ b/examples/init-wait/src/lib.rs @@ -1,14 +1,32 @@ +// This file is part of Gear. + +// Copyright (C) 2021-2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] mod code { include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); } -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] pub use code::WASM_BINARY_OPT as WASM_BINARY; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm { include! {"./code.rs"} } diff --git a/examples/reserve-gas/Cargo.toml b/examples/reserve-gas/Cargo.toml index aef27afb79c..132b43911fa 100644 --- a/examples/reserve-gas/Cargo.toml +++ b/examples/reserve-gas/Cargo.toml @@ -18,5 +18,6 @@ gtest.workspace = true [features] debug = ["gstd/debug"] -std = [] +wasm-wrapper = [] +std = ["wasm-wrapper", "parity-scale-codec/std"] default = ["std"] diff --git a/examples/reserve-gas/build.rs b/examples/reserve-gas/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/reserve-gas/build.rs +++ b/examples/reserve-gas/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/reserve-gas/src/lib.rs b/examples/reserve-gas/src/lib.rs index da47e95a438..7644c983bb7 100644 --- a/examples/reserve-gas/src/lib.rs +++ b/examples/reserve-gas/src/lib.rs @@ -23,12 +23,12 @@ extern crate alloc; use alloc::vec::Vec; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] mod code { include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); } -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] pub use code::WASM_BINARY_OPT as WASM_BINARY; pub const RESERVATION_AMOUNT: u64 = 50_000_000; @@ -62,7 +62,7 @@ pub enum ReplyAction { pub type GasAmount = u64; pub type BlockCount = u32; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm { use super::*; use gstd::{ diff --git a/examples/wait_wake/build.rs b/examples/wait_wake/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/wait_wake/build.rs +++ b/examples/wait_wake/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/waiter/Cargo.toml b/examples/waiter/Cargo.toml index a72ef94b3a5..3090fc3f7a0 100644 --- a/examples/waiter/Cargo.toml +++ b/examples/waiter/Cargo.toml @@ -2,14 +2,15 @@ name = "demo-waiter" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" +edition.workspace = true +license.workspace = true workspace = "../../" [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } futures.workspace = true gstd.workspace = true +gcore.workspace = true [build-dependencies] gear-wasm-builder.workspace = true @@ -23,5 +24,6 @@ demo-waiter = { path = ".", features = ["debug"] } [features] debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] +wasm-wrapper = [] +std = ["parity-scale-codec/std", "wasm-wrapper"] default = ["std"] diff --git a/examples/waiter/build.rs b/examples/waiter/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/waiter/build.rs +++ b/examples/waiter/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/waiter/src/code.rs b/examples/waiter/src/code.rs index 9bc91cb726d..7a68dd08957 100644 --- a/examples/waiter/src/code.rs +++ b/examples/waiter/src/code.rs @@ -1,3 +1,21 @@ +// This file is part of Gear. + +// Copyright (C) 2021-2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + use crate::{ Command, LockContinuation, LockStaticAccessSubcommand, MxLockContinuation, RwLockContinuation, RwLockType, SleepForWaitType, WaitSubcommand, @@ -22,33 +40,33 @@ async fn main() { match cmd { Command::Wait(subcommand) => process_wait_subcommand(subcommand), Command::SendFor(to, duration) => { - msg::send_bytes_for_reply(to, [], 0, 0) + msg::send_bytes_for_reply(to.into(), [], 0, 0) .expect("send message failed") .exactly(Some(duration)) .expect("Invalid wait duration.") .await; } Command::SendUpTo(to, duration) => { - msg::send_bytes_for_reply(to, [], 0, 0) + msg::send_bytes_for_reply(to.into(), [], 0, 0) .expect("send message failed") .up_to(Some(duration)) .expect("Invalid wait duration.") .await; } Command::SendUpToWait(to, duration) => { - msg::send_bytes_for_reply(to, [], 0, 0) + msg::send_bytes_for_reply(to.into(), [], 0, 0) .expect("send message failed") .up_to(Some(duration)) .expect("Invalid wait duration.") .await; // after waking, wait again. - msg::send_bytes_for_reply(to, [], 0, 0) + msg::send_bytes_for_reply(to.into(), [], 0, 0) .expect("send message failed") .await; } Command::SendAndWaitFor(duration, to) => { - msg::send(to, b"ping", 0); + msg::send(to.into(), b"ping", 0); exec::wait_for(duration); } Command::ReplyAndWait(subcommand) => { diff --git a/examples/waiter/src/lib.rs b/examples/waiter/src/lib.rs index 1e744113065..b7d4619f789 100644 --- a/examples/waiter/src/lib.rs +++ b/examples/waiter/src/lib.rs @@ -15,29 +15,37 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] -use gstd::{ActorId, Vec}; +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +use alloc::vec::Vec; +use gcore::BlockCount; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] +type ActorId = [u8; 32]; + +#[cfg(feature = "wasm-wrapper")] mod code { include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); } -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] pub use code::WASM_BINARY_OPT as WASM_BINARY; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm { include! {"./code.rs"} } +#[cfg(feature = "std")] pub fn system_reserve() -> u64 { gstd::Config::system_reserve() } // Re-exports for testing +#[cfg(feature = "std")] pub fn default_wait_up_to_duration() -> u32 { gstd::Config::wait_up_to() } @@ -94,14 +102,14 @@ pub enum RwLockContinuation { #[derive(Debug, Encode, Decode)] pub enum Command { Wait(WaitSubcommand), - SendFor(ActorId, gstd::BlockCount), - SendUpTo(ActorId, gstd::BlockCount), - SendUpToWait(ActorId, gstd::BlockCount), - SendAndWaitFor(gstd::BlockCount, ActorId), + SendFor(ActorId, BlockCount), + SendUpTo(ActorId, BlockCount), + SendUpToWait(ActorId, BlockCount), + SendAndWaitFor(BlockCount, ActorId), ReplyAndWait(WaitSubcommand), - SleepFor(Vec, SleepForWaitType), + SleepFor(Vec, SleepForWaitType), WakeUp([u8; 32]), - MxLock(gstd::BlockCount, MxLockContinuation), + MxLock(BlockCount, MxLockContinuation), MxLockStaticAccess(LockStaticAccessSubcommand), RwLock(RwLockType, RwLockContinuation), RwLockStaticAccess(RwLockType, LockStaticAccessSubcommand), diff --git a/gclient/Cargo.toml b/gclient/Cargo.toml index 3ee7de0f6ec..26f9d8b973a 100644 --- a/gclient/Cargo.toml +++ b/gclient/Cargo.toml @@ -38,7 +38,7 @@ demo-async-tester.workspace = true demo-calc-hash.workspace = true demo-calc-hash-in-one-block.workspace = true demo-custom.workspace = true -demo-constructor.workspace = true +demo-constructor = { workspace = true, features = ["std"] } demo-distributor.workspace = true demo-meta-io.workspace = true demo-new-meta.workspace = true @@ -47,7 +47,7 @@ demo-node.workspace = true demo-program-factory.workspace = true demo-proxy = { workspace = true, features = ["std"] } demo-proxy-relay.workspace = true -demo-reserve-gas.workspace = true +demo-reserve-gas = { workspace = true, features = ["std"] } gmeta = { workspace = true } gstd = { workspace = true, features = ["debug"] } demo-wat.workspace = true diff --git a/gsdk/Cargo.toml b/gsdk/Cargo.toml index d823fcd42d9..3985dbc5494 100644 --- a/gsdk/Cargo.toml +++ b/gsdk/Cargo.toml @@ -42,7 +42,7 @@ gsdk = { path = ".", features = ["testing"] } tokio = { workspace = true, features = [ "full" ] } demo-messager.workspace = true demo-new-meta.workspace = true -demo-waiter.workspace = true +demo-waiter = { workspace = true, features = ["std"] } [features] testing = [ "rand" ] diff --git a/gsdk/tests/rpc.rs b/gsdk/tests/rpc.rs index c458cee94e8..376af7741de 100644 --- a/gsdk/tests/rpc.rs +++ b/gsdk/tests/rpc.rs @@ -151,7 +151,7 @@ async fn test_calculate_reply_gas() -> Result<()> { let salt = vec![]; let pid = ProgramId::generate(CodeId::generate(demo_waiter::WASM_BINARY), &salt); - let payload = demo_waiter::Command::SendUpTo(alice.into(), 10); + let payload = demo_waiter::Command::SendUpTo(alice, 10); // 1. upload program. let signer = Api::new(Some(&node_uri(&node))) diff --git a/pallets/gear-scheduler/src/tests.rs b/pallets/gear-scheduler/src/tests.rs index d2ba06af84f..58a0285d026 100644 --- a/pallets/gear-scheduler/src/tests.rs +++ b/pallets/gear-scheduler/src/tests.rs @@ -89,6 +89,7 @@ fn populate_wl_from( (mid, pid) } +#[track_caller] fn task_and_wl_message_exist( mid: impl Into, pid: impl Into, @@ -100,9 +101,7 @@ fn task_and_wl_message_exist( let ts = TaskPoolOf::::contains(&bn, &ScheduledTask::RemoveFromWaitlist(pid, mid)); let wl = WaitlistOf::::contains(&pid, &mid); - if ts != wl { - panic!("Logic invalidated"); - } + assert_eq!(ts, wl, "Logic invalidated"); ts } @@ -196,12 +195,14 @@ fn gear_handles_tasks() { ); assert_eq!(GearBank::account_total(&USER_1), gas_price(DEFAULT_GAS)); + let task = ScheduledTask::RemoveFromWaitlist(Default::default(), Default::default()); + let task_gas = pallet_gear::manager::get_maximum_task_gas::(&task); // Check if task and message got processed in block `bn`. run_to_block(bn, Some(u64::MAX)); // Read of the first block of incomplete tasks and write for removal of task. assert_eq!( GasAllowanceOf::::get(), - u64::MAX - db_r_w(1, 1).ref_time() + u64::MAX - db_r_w(1, 1).ref_time() - task_gas ); // Storages checking. @@ -298,7 +299,9 @@ fn gear_handles_outdated_tasks() { // Check if task and message got processed before start of block `bn`. // But due to the low gas allowance, we may process the only first task. - run_to_block(bn, Some(db_r_w(1, 2).ref_time() + 1)); + let task = ScheduledTask::RemoveFromWaitlist(Default::default(), Default::default()); + let task_gas = pallet_gear::manager::get_maximum_task_gas::(&task); + run_to_block(bn, Some(db_r_w(2, 2).ref_time() + task_gas + 1)); // Read of the first block of incomplete tasks, write to it afterwards + single task processing. assert_eq!(GasAllowanceOf::::get(), 1); @@ -329,7 +332,7 @@ fn gear_handles_outdated_tasks() { // Delete of the first block of incomplete tasks + single task processing. assert_eq!( GasAllowanceOf::::get(), - u64::MAX - db_r_w(0, 2).ref_time() + u64::MAX - db_r_w(0, 2).ref_time() - task_gas ); let cost2 = wl_cost_for(bn + 1 - initial_block); diff --git a/pallets/gear/Cargo.toml b/pallets/gear/Cargo.toml index 8dc26661bee..ac6f96b0a64 100644 --- a/pallets/gear/Cargo.toml +++ b/pallets/gear/Cargo.toml @@ -60,6 +60,11 @@ sp-consensus-slots = { workspace = true, optional = true } test-syscalls = { workspace = true, optional = true } demo-read-big-state = { workspace = true, optional = true } demo-proxy = { workspace = true, optional = true } +demo-reserve-gas = { workspace = true, optional = true } +demo-delayed-sender = { workspace = true, optional = true } +demo-constructor = { workspace = true, optional = true } +demo-waiter = { workspace = true, optional = true } +demo-init-wait = { workspace = true, optional = true } [dev-dependencies] wabt.workspace = true @@ -154,6 +159,11 @@ std = [ "test-syscalls?/std", "demo-read-big-state?/std", "demo-proxy?/std", + "demo-reserve-gas?/std", + "demo-delayed-sender?/std", + "demo-constructor?/std", + "demo-waiter?/std", + "demo-init-wait?/std", "gear-runtime-interface/std", ] runtime-benchmarks = [ @@ -172,6 +182,11 @@ runtime-benchmarks = [ "demo-read-big-state/wasm-wrapper", "demo-proxy/wasm-wrapper", "gsys", + "demo-reserve-gas/wasm-wrapper", + "demo-delayed-sender/wasm-wrapper", + "demo-constructor/wasm-wrapper", + "demo-waiter/wasm-wrapper", + "demo-init-wait/wasm-wrapper", ] runtime-benchmarks-checkers = [] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/gear/src/benchmarking/mod.rs b/pallets/gear/src/benchmarking/mod.rs index 089b6ba2799..354379bfe16 100644 --- a/pallets/gear/src/benchmarking/mod.rs +++ b/pallets/gear/src/benchmarking/mod.rs @@ -39,6 +39,7 @@ mod code; mod sandbox; mod syscalls; +mod tasks; mod utils; use syscalls::Benches; @@ -59,7 +60,7 @@ use crate::{ schedule::{API_BENCHMARK_BATCH_SIZE, INSTR_BENCHMARK_BATCH_SIZE}, BalanceOf, BenchmarkStorage, Call, Config, CurrencyOf, Event, ExecutionEnvironment, Ext as Externalities, GasHandlerOf, GearBank, MailboxOf, Pallet as Gear, Pallet, - ProgramStorageOf, QueueOf, RentFreePeriodOf, ResumeMinimalPeriodOf, Schedule, + ProgramStorageOf, QueueOf, RentFreePeriodOf, ResumeMinimalPeriodOf, Schedule, TaskPoolOf, }; use ::alloc::{ collections::{BTreeMap, BTreeSet}, @@ -68,6 +69,7 @@ use ::alloc::{ use common::{ self, benchmarking, paused_program_storage::SessionId, + scheduler::{ScheduledTask, TaskHandler}, storage::{Counter, *}, ActiveProgram, CodeMetadata, CodeStorage, GasTree, Origin, PausedProgramStorage, ProgramStorage, ReservableTree, @@ -241,6 +243,31 @@ where .unwrap_or_else(|e| unreachable!("core-processor logic invalidated: {}", e)) } +fn get_last_session_id() -> Option { + find_latest_event::(|event| match event { + Event::ProgramResumeSessionStarted { session_id, .. } => Some(session_id), + _ => None, + }) +} + +pub fn find_latest_event(mapping_filter: F) -> Option +where + T: Config, + F: Fn(Event) -> Option, +{ + SystemPallet::::events() + .into_iter() + .rev() + .filter_map(|event_record| { + let event = <::RuntimeEvent as From<_>>::from(event_record.event); + let event: Result, _> = event.try_into(); + + event.ok() + }) + .find_map(mapping_filter) +} + +#[track_caller] fn resume_session_prepare( c: u32, program_id: ProgramId, @@ -261,14 +288,6 @@ where ) .expect("failed to start resume session"); - let event_record = SystemPallet::::events().pop().unwrap(); - let event = <::RuntimeEvent as From<_>>::from(event_record.event); - let event: Result, _> = event.try_into(); - let session_id = match event { - Ok(Event::ProgramResumeSessionStarted { session_id, .. }) => session_id, - _ => unreachable!(), - }; - let memory_pages = { let mut pages = Vec::with_capacity(c as usize); for i in 0..c { @@ -278,7 +297,7 @@ where pages }; - (session_id, memory_pages) + (get_last_session_id::().unwrap(), memory_pages) } /// An instantiated and deployed program. @@ -2741,6 +2760,89 @@ benchmarks! { sbox.invoke(); } + tasks_remove_resume_session { + let session_id = tasks::remove_resume_session::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.remove_resume_session(session_id); + } + + tasks_remove_gas_reservation { + let (program_id, reservation_id) = tasks::remove_gas_reservation::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.remove_gas_reservation(program_id, reservation_id); + } + + tasks_send_user_message_to_mailbox { + let message_id = tasks::send_user_message::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.send_user_message(message_id, true); + } + + tasks_send_user_message { + let message_id = tasks::send_user_message::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.send_user_message(message_id, false); + } + + tasks_send_dispatch { + let message_id = tasks::send_dispatch::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.send_dispatch(message_id); + } + + tasks_wake_message { + let (program_id, message_id) = tasks::wake_message::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.wake_message(program_id, message_id); + } + + tasks_wake_message_no_wake { + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.wake_message(Default::default(), Default::default()); + } + + tasks_remove_from_waitlist { + let (program_id, message_id) = tasks::remove_from_waitlist::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.remove_from_waitlist(program_id, message_id); + } + + tasks_remove_from_mailbox { + let (user, message_id) = tasks::remove_from_mailbox::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.remove_from_mailbox(T::AccountId::from_origin(user.into_origin()), message_id); + } + + tasks_pause_program { + let c in 0 .. (MAX_PAGES - 1) * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u32; + + let code = benchmarking::generate_wasm2(0.into()).unwrap(); + let program_id = tasks::pause_program_prepare::(c, code); + + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.pause_program(program_id); + } + + tasks_pause_program_uninited { + let c in 0 .. (MAX_PAGES - 1) * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u32; + + let program_id = tasks::pause_program_prepare::(c, demo_init_wait::WASM_BINARY.to_vec()); + + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.pause_program(program_id); + } + // This is no benchmark. It merely exist to have an easy way to pretty print the currently // configured `Schedule` during benchmark development. // It can be outputted using the following command: diff --git a/pallets/gear/src/benchmarking/tasks.rs b/pallets/gear/src/benchmarking/tasks.rs new file mode 100644 index 00000000000..6447b509f01 --- /dev/null +++ b/pallets/gear/src/benchmarking/tasks.rs @@ -0,0 +1,371 @@ +// This file is part of Gear. + +// Copyright (C) Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +use super::*; +use gear_core::ids::ReservationId; + +#[track_caller] +fn send_user_message_prepare(delay: u32) +where + T: Config, + T::AccountId: Origin, +{ + use demo_delayed_sender::WASM_BINARY; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + Gear::::upload_program( + RawOrigin::Signed(caller).into(), + WASM_BINARY.to_vec(), + salt, + delay.encode(), + 100_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + Gear::::process_queue(Default::default()); +} + +#[track_caller] +pub(super) fn pause_program_prepare(c: u32, code: Vec) -> ProgramId +where + T: Config, + T::AccountId: Origin, +{ + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 400_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(&code), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller).into(), + code, + salt, + b"init_payload".to_vec(), + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + Gear::::process_queue(Default::default()); + + let memory_page = { + let mut page = PageBuf::new_zeroed(); + page[0] = 1; + + page + }; + + for i in 0..c { + ProgramStorageOf::::set_program_page_data( + program_id, + GearPage::from(i as u16), + memory_page.clone(), + ); + } + + ProgramStorageOf::::update_active_program(program_id, |program| { + program.pages_with_data = BTreeSet::from_iter((0..c).map(|i| GearPage::from(i as u16))); + + let wasm_pages = (c as usize * GEAR_PAGE_SIZE) / WASM_PAGE_SIZE; + program.allocations = + BTreeSet::from_iter((0..wasm_pages).map(|i| WasmPage::from(i as u16))); + }) + .expect("program should exist"); + + program_id +} + +#[track_caller] +pub(super) fn remove_resume_session() -> SessionId +where + T: Config, + T::AccountId: Origin, +{ + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let code = benchmarking::generate_wasm2(16.into()).unwrap(); + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(&code), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller.clone()).into(), + code, + salt, + b"init_payload".to_vec(), + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + init_block::(None); + + ProgramStorageOf::::pause_program(program_id, 100u32.into()).unwrap(); + + Gear::::resume_session_init( + RawOrigin::Signed(caller).into(), + program_id, + Default::default(), + CodeId::default(), + ) + .expect("failed to start resume session"); + + get_last_session_id::().unwrap() +} + +#[track_caller] +pub(super) fn remove_gas_reservation() -> (ProgramId, ReservationId) +where + T: Config, + T::AccountId: Origin, +{ + use demo_reserve_gas::{InitAction, WASM_BINARY}; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(WASM_BINARY), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller).into(), + WASM_BINARY.to_vec(), + salt, + InitAction::Normal(vec![(50_000, 100)]).encode(), + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + Gear::::process_queue(Default::default()); + + let program: ActiveProgram<_> = ProgramStorageOf::::get_program(program_id) + .expect("program should exist") + .try_into() + .expect("program should be active"); + + ( + program_id, + program + .gas_reservation_map + .first_key_value() + .map(|(k, _v)| *k) + .unwrap(), + ) +} + +#[track_caller] +pub(super) fn send_user_message() -> MessageId +where + T: Config, + T::AccountId: Origin, +{ + let delay = 1u32; + send_user_message_prepare::(delay); + + let task = TaskPoolOf::::iter_prefix_keys(Gear::::block_number() + delay.into()) + .next() + .expect("task should be scheduled"); + let (message_id, to_mailbox) = match task { + ScheduledTask::SendUserMessage { + message_id, + to_mailbox, + } => (message_id, to_mailbox), + _ => unreachable!("task should be SendUserMessage"), + }; + assert!(to_mailbox); + + message_id +} + +#[track_caller] +pub(super) fn send_dispatch() -> MessageId +where + T: Config, + T::AccountId: Origin, +{ + use demo_constructor::{Call, Calls, Scheme, WASM_BINARY}; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(WASM_BINARY), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller.clone()).into(), + WASM_BINARY.to_vec(), + salt, + Scheme::empty().encode(), + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + let delay = 1u32; + let calls = Calls::builder().add_call(Call::Send( + <[u8; 32]>::from(program_id.into_origin()).into(), + [].into(), + Some(0u64.into()), + 0u128.into(), + delay.into(), + )); + Gear::::send_message( + RawOrigin::Signed(caller).into(), + program_id, + calls.encode(), + 10_000_000_000, + 0u32.into(), + false, + ) + .expect("failed to send message"); + + Gear::::process_queue(Default::default()); + + let task = TaskPoolOf::::iter_prefix_keys(Gear::::block_number() + delay.into()) + .next() + .unwrap(); + + match task { + ScheduledTask::SendDispatch(message_id) => message_id, + _ => unreachable!(), + } +} + +#[track_caller] +pub(super) fn wake_message() -> (ProgramId, MessageId) +where + T: Config, + T::AccountId: Origin, +{ + use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(WASM_BINARY), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller.clone()).into(), + WASM_BINARY.to_vec(), + salt, + vec![], + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + let delay = 10u32; + Gear::::send_message( + RawOrigin::Signed(caller).into(), + program_id, + Command::Wait(WaitSubcommand::WaitFor(delay)).encode(), + 10_000_000_000, + 0u32.into(), + false, + ) + .expect("failed to send message"); + + Gear::::process_queue(Default::default()); + + let task = TaskPoolOf::::iter_prefix_keys(Gear::::block_number() + delay.into()) + .next() + .unwrap(); + let (_program_id, message_id) = match task { + ScheduledTask::WakeMessage(program_id, message_id) => (program_id, message_id), + _ => unreachable!(), + }; + + (program_id, message_id) +} + +#[track_caller] +pub(super) fn remove_from_waitlist() -> (ProgramId, MessageId) +where + T: Config, + T::AccountId: Origin, +{ + use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(WASM_BINARY), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller.clone()).into(), + WASM_BINARY.to_vec(), + salt, + vec![], + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + Gear::::send_message( + RawOrigin::Signed(caller).into(), + program_id, + Command::Wait(WaitSubcommand::Wait).encode(), + 10_000_000_000, + 0u32.into(), + false, + ) + .expect("failed to send message"); + + Gear::::process_queue(Default::default()); + + let expiration = find_latest_event::(|event| match event { + Event::MessageWaited { expiration, .. } => Some(expiration), + _ => None, + }) + .expect("message should be waited"); + + let task = TaskPoolOf::::iter_prefix_keys(expiration) + .next() + .unwrap(); + let (_program_id, message_id) = match task { + ScheduledTask::RemoveFromWaitlist(program_id, message_id) => (program_id, message_id), + _ => unreachable!(), + }; + + (program_id, message_id) +} + +#[track_caller] +pub(super) fn remove_from_mailbox() -> (ProgramId, MessageId) +where + T: Config, + T::AccountId: Origin, +{ + send_user_message_prepare::(0u32); + + find_latest_event::(|event| match event { + Event::UserMessageSent { message, .. } => Some((message.destination(), message.id())), + _ => None, + }) + .expect("message should be sent") +} diff --git a/pallets/gear/src/lib.rs b/pallets/gear/src/lib.rs index e236c02de33..0db25c86d60 100644 --- a/pallets/gear/src/lib.rs +++ b/pallets/gear/src/lib.rs @@ -934,7 +934,6 @@ pub mod pallet { ..=current_bn.saturated_into()) .map(|block| block.saturated_into::>()); for bn in missing_blocks { - // Tasks drain iterator. let tasks = TaskPoolOf::::drain_prefix_keys(bn); // Checking gas allowance. @@ -948,30 +947,63 @@ pub mod pallet { } // Iterating over tasks, scheduled on `bn`. + let mut last_task = None; for task in tasks { - log::debug!("Processing task: {:?}", task); - // Decreasing gas allowance due to DB deletion. GasAllowanceOf::::decrease(DbWeightOf::::get().writes(1).ref_time()); - // Processing task. - // - // NOTE: Gas allowance decrease should be implemented - // inside `TaskHandler` trait and/or inside other - // generic types, which interact with storage. - task.process_with(ext_manager); + // gas required to process task. + let max_task_gas = manager::get_maximum_task_gas::(&task); + log::debug!("Processing task: {task:?}, max gas = {max_task_gas}"); // Checking gas allowance. // - // Making sure we have gas to remove next task - // or update the first block of incomplete tasks. - if GasAllowanceOf::::get() <= DbWeightOf::::get().writes(2).ref_time() { + // Making sure we have gas to process the current task + // and update the first block of incomplete tasks. + if GasAllowanceOf::::get().saturating_sub(max_task_gas) + <= DbWeightOf::::get().writes(1).ref_time() + { + // Since the task is not processed write DB cost should be refunded. + // In the same time gas allowance should be charged for read DB cost. + GasAllowanceOf::::put( + GasAllowanceOf::::get() + .saturating_add(DbWeightOf::::get().writes(1).ref_time()) + .saturating_sub(DbWeightOf::::get().reads(1).ref_time()), + ); + + last_task = Some(task); + log::debug!("Not enough gas to process task at: {bn:?}"); + + break; + } + + // Processing task and update allowance of gas. + let task_gas = task.process_with(ext_manager); + GasAllowanceOf::::decrease(task_gas); + + // Check that there is enough gas allowance to query next task and update the first block of incomplete tasks. + if GasAllowanceOf::::get() + <= DbWeightOf::::get().reads_writes(1, 1).ref_time() + { stopped_at = Some(bn); - log::debug!("Stopping processing tasks at: {stopped_at:?}"); + log::debug!("Stopping processing tasks at (read next): {stopped_at:?}"); break; } } + if let Some(task) = last_task { + stopped_at = Some(bn); + + // since there is the overlay mechanism we don't need to subtract write cost + // from gas allowance on task insertion. + GasAllowanceOf::::put( + GasAllowanceOf::::get() + .saturating_add(DbWeightOf::::get().writes(1).ref_time()), + ); + TaskPoolOf::::add(bn, task) + .unwrap_or_else(|e| unreachable!("Scheduling logic invalidated! {:?}", e)); + } + // Stopping iteration over blocks if no resources left. if stopped_at.is_some() { break; diff --git a/pallets/gear/src/manager/task.rs b/pallets/gear/src/manager/task.rs index 41a399265f2..54f6eb85f2b 100644 --- a/pallets/gear/src/manager/task.rs +++ b/pallets/gear/src/manager/task.rs @@ -17,8 +17,8 @@ // along with this program. If not, see . use crate::{ - manager::ExtManager, Config, DispatchStashOf, Event, Pallet, ProgramStorageOf, QueueOf, - TaskPoolOf, WaitlistOf, + manager::ExtManager, weights::WeightInfo, Config, DbWeightOf, DispatchStashOf, Event, Pallet, + ProgramStorageOf, QueueOf, TaskPoolOf, WaitlistOf, }; use alloc::string::ToString; use common::{ @@ -29,21 +29,71 @@ use common::{ paused_program_storage::SessionId, scheduler::*, storage::*, - Origin, PausedProgramStorage, Program, ProgramStorage, + ActiveProgram, Gas, Origin, PausedProgramStorage, Program, ProgramState, ProgramStorage, }; +use core::cmp; use gear_core::{ + code::MAX_WASM_PAGE_COUNT, ids::{CodeId, MessageId, ProgramId, ReservationId}, message::{DispatchKind, ReplyMessage}, + pages::{GEAR_PAGE_SIZE, WASM_PAGE_SIZE}, }; use gear_core_errors::{ErrorReplyReason, SignalCode}; use sp_core::Get; use sp_runtime::Saturating; +pub fn get_maximum_task_gas(task: &ScheduledTask) -> Gas { + use ScheduledTask::*; + + match task { + PauseProgram(_) => { + // TODO: #3079 + if ::ProgramRentEnabled::get() { + let count = + u32::from(MAX_WASM_PAGE_COUNT * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u16 / 2); + cmp::max( + ::WeightInfo::tasks_pause_program(count).ref_time(), + ::WeightInfo::tasks_pause_program_uninited(count).ref_time(), + ) + } else { + DbWeightOf::::get().writes(2).ref_time() + } + } + RemoveCode(_) => todo!("#646"), + RemoveFromMailbox(_, _) => { + ::WeightInfo::tasks_remove_from_mailbox().ref_time() + } + RemoveFromWaitlist(_, _) => { + ::WeightInfo::tasks_remove_from_waitlist().ref_time() + } + RemovePausedProgram(_) => todo!("#646"), + WakeMessage(_, _) => cmp::max( + ::WeightInfo::tasks_wake_message().ref_time(), + ::WeightInfo::tasks_wake_message_no_wake().ref_time(), + ), + SendDispatch(_) => ::WeightInfo::tasks_send_dispatch().ref_time(), + SendUserMessage { .. } => cmp::max( + ::WeightInfo::tasks_send_user_message_to_mailbox().ref_time(), + ::WeightInfo::tasks_send_user_message().ref_time(), + ), + RemoveGasReservation(_, _) => { + ::WeightInfo::tasks_remove_gas_reservation().ref_time() + } + RemoveResumeSession(_) => { + ::WeightInfo::tasks_remove_resume_session().ref_time() + } + } +} + impl TaskHandler for ExtManager where T::AccountId: Origin, { - fn pause_program(&mut self, program_id: ProgramId) { + fn pause_program(&mut self, program_id: ProgramId) -> Gas { + // + // TODO: #3079 + // + if !::ProgramRentEnabled::get() { log::debug!("Program rent logic is disabled."); @@ -63,13 +113,17 @@ where TaskPoolOf::::add(expiration_block, task) .unwrap_or_else(|e| unreachable!("Scheduling logic invalidated! {:?}", e)); - return; + return DbWeightOf::::get().writes(1).ref_time(); } - let program = ProgramStorageOf::::get_program(program_id) - .unwrap_or_else(|| unreachable!("Program to pause not found.")); + let program: ActiveProgram<_> = ProgramStorageOf::::get_program(program_id) + .unwrap_or_else(|| unreachable!("Program to pause not found.")) + .try_into() + .unwrap_or_else(|e| unreachable!("Pause program task logic corrupted: {e:?}")); - let Some(init_message_id) = program.is_uninitialized() else { + let pages_with_data = program.pages_with_data.len() as u32; + + let ProgramState::Uninitialized{ message_id: init_message_id } = program.state else { // pause initialized program let gas_reservation_map = ProgramStorageOf::::pause_program(program_id, Pallet::::block_number()) @@ -90,7 +144,10 @@ where change: ProgramChangeKind::Paused, }); - return; + let gas = ::WeightInfo::tasks_pause_program(pages_with_data).ref_time(); + log::trace!("Task gas: tasks_pause_program = {gas}"); + + return gas; }; // terminate uninitialized program @@ -141,13 +198,19 @@ where id: program_id, change: ProgramChangeKind::Terminated, }); + + let gas = + ::WeightInfo::tasks_pause_program_uninited(pages_with_data).ref_time(); + log::trace!("Task gas: tasks_pause_program_uninited = {gas}"); + + gas } - fn remove_code(&mut self, _code_id: CodeId) { - todo!("#646"); + fn remove_code(&mut self, _code_id: CodeId) -> Gas { + todo!("#646") } - fn remove_from_mailbox(&mut self, user_id: T::AccountId, message_id: MessageId) { + fn remove_from_mailbox(&mut self, user_id: T::AccountId, message_id: MessageId) -> Gas { // Read reason. let reason = UserMessageReadSystemReason::OutOfRent.into_reason(); @@ -169,9 +232,14 @@ where // Queueing dispatch. QueueOf::::queue(dispatch) .unwrap_or_else(|e| unreachable!("Message queue corrupted! {:?}", e)); + + let gas = ::WeightInfo::tasks_remove_from_mailbox().ref_time(); + log::trace!("Task gas: tasks_remove_from_mailbox = {gas}"); + + gas } - fn remove_from_waitlist(&mut self, program_id: ProgramId, message_id: MessageId) { + fn remove_from_waitlist(&mut self, program_id: ProgramId, message_id: MessageId) -> Gas { // Wake reason. let reason = MessageWokenSystemReason::OutOfRent.into_reason(); @@ -240,24 +308,42 @@ where let origin = waitlisted.source(); Self::process_failed_init(program_id, origin, true); } + + let gas = ::WeightInfo::tasks_remove_from_waitlist().ref_time(); + log::trace!("Task gas: tasks_remove_from_waitlist = {gas}"); + + gas } - fn remove_paused_program(&mut self, _program_id: ProgramId) { - todo!("#646"); + fn remove_paused_program(&mut self, _program_id: ProgramId) -> Gas { + todo!("#646") } - fn wake_message(&mut self, program_id: ProgramId, message_id: MessageId) { - if let Some(dispatch) = Pallet::::wake_dispatch( + fn wake_message(&mut self, program_id: ProgramId, message_id: MessageId) -> Gas { + match Pallet::::wake_dispatch( program_id, message_id, MessageWokenRuntimeReason::WakeCalled.into_reason(), ) { - QueueOf::::queue(dispatch) - .unwrap_or_else(|e| unreachable!("Message queue corrupted! {:?}", e)); + Some(dispatch) => { + QueueOf::::queue(dispatch) + .unwrap_or_else(|e| unreachable!("Message queue corrupted! {:?}", e)); + + let gas = ::WeightInfo::tasks_wake_message().ref_time(); + log::trace!("Task gas: tasks_wake_message = {gas}"); + + gas + } + None => { + let gas = ::WeightInfo::tasks_wake_message_no_wake().ref_time(); + log::trace!("Task gas: tasks_wake_message_no_wake = {gas}"); + + gas + } } } - fn send_dispatch(&mut self, stashed_message_id: MessageId) { + fn send_dispatch(&mut self, stashed_message_id: MessageId) -> Gas { // No validation required. If program doesn't exist, then NotExecuted appears. let (dispatch, hold_interval) = DispatchStashOf::::take(stashed_message_id) @@ -268,9 +354,14 @@ where QueueOf::::queue(dispatch) .unwrap_or_else(|e| unreachable!("Message queue corrupted! {:?}", e)); + + let gas = ::WeightInfo::tasks_send_dispatch().ref_time(); + log::trace!("Task gas: tasks_send_dispatch = {gas}"); + + gas } - fn send_user_message(&mut self, stashed_message_id: MessageId, to_mailbox: bool) { + fn send_user_message(&mut self, stashed_message_id: MessageId, to_mailbox: bool) -> Gas { // TODO: validate here destination and send error reply, if required. // Atm despite the fact that program may exist, message goes into mailbox / event. let (message, hold_interval) = DispatchStashOf::::take(stashed_message_id) @@ -285,15 +376,40 @@ where .try_into() .unwrap_or_else(|_| unreachable!("Signal message sent to user")); Pallet::::send_user_message_after_delay(message, to_mailbox); + + if to_mailbox { + let gas = ::WeightInfo::tasks_send_user_message_to_mailbox().ref_time(); + log::trace!("Task gas: tasks_send_user_message_to_mailbox = {gas}"); + + gas + } else { + let gas = ::WeightInfo::tasks_send_user_message().ref_time(); + log::trace!("Task gas: tasks_send_user_message = {gas}"); + + gas + } } - fn remove_gas_reservation(&mut self, program_id: ProgramId, reservation_id: ReservationId) { + fn remove_gas_reservation( + &mut self, + program_id: ProgramId, + reservation_id: ReservationId, + ) -> Gas { let _slot = Self::remove_gas_reservation_impl(program_id, reservation_id); + + let gas = ::WeightInfo::tasks_remove_gas_reservation().ref_time(); + log::trace!("Task gas: tasks_remove_gas_reservation = {gas}"); + + gas } - fn remove_resume_session(&mut self, session_id: SessionId) { - log::debug!("Execute task to remove resume session with session_id = {session_id}"); + fn remove_resume_session(&mut self, session_id: SessionId) -> Gas { ProgramStorageOf::::remove_resume_session(session_id) .unwrap_or_else(|e| unreachable!("ProgramStorage corrupted! {:?}", e)); + + let gas = ::WeightInfo::tasks_remove_resume_session().ref_time(); + log::trace!("Task gas: tasks_remove_resume_session = {gas}"); + + gas } } diff --git a/pallets/gear/src/mock.rs b/pallets/gear/src/mock.rs index e4f29b149e2..6ddddaa70ca 100644 --- a/pallets/gear/src/mock.rs +++ b/pallets/gear/src/mock.rs @@ -302,7 +302,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { pallet_balances::GenesisConfig:: { balances: vec![ (USER_1, 5_000_000_000_000_000_u128), - (USER_2, 200_000_000_000_000_u128), + (USER_2, 350_000_000_000_000_u128), (USER_3, 500_000_000_000_000_u128), (LOW_BALANCE_USER, 1_000_000_u128), (BLOCK_AUTHOR, 500_000_u128), diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index ae861d0d365..019d2ac293b 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -5118,7 +5118,7 @@ fn test_requeue_after_wait_for_timeout() { run_to_next_block(None); let duration = 10; - let payload = Command::SendAndWaitFor(duration, USER_1.into()).encode(); + let payload = Command::SendAndWaitFor(duration, USER_1.into_origin().into()).encode(); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), program_id, @@ -5189,7 +5189,7 @@ fn test_sending_waits() { // // Send message and then wait_for. let duration = 5; - let payload = Command::SendFor(USER_1.into(), duration).encode(); + let payload = Command::SendFor(USER_1.into_origin().into(), duration).encode(); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), @@ -5209,7 +5209,7 @@ fn test_sending_waits() { // // Send message and then wait_up_to. let duration = 10; - let payload = Command::SendUpTo(USER_1.into(), duration).encode(); + let payload = Command::SendUpTo(USER_1.into_origin().into(), duration).encode(); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), program_id, @@ -5228,7 +5228,7 @@ fn test_sending_waits() { // // Send message and then wait no_more, wake, wait no_more again. let duration = 10; - let payload = Command::SendUpToWait(USER_2.into(), duration).encode(); + let payload = Command::SendUpToWait(USER_2.into_origin().into(), duration).encode(); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), program_id, @@ -8809,6 +8809,8 @@ fn free_storage_hold_on_scheduler_overwhelm() { #[test] fn execution_over_blocks() { + const MAX_BLOCK: u64 = 10_000_000_000; + init_logger(); let assert_last_message = |src: [u8; 32], count: u128| { @@ -8849,7 +8851,7 @@ fn execution_over_blocks() { )); let in_one_block = get_last_program_id(); - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); // estimate start cost let pkg = Package::new(times, src); @@ -8870,7 +8872,7 @@ fn execution_over_blocks() { use demo_calc_hash_in_one_block::{Package, WASM_BINARY}; // We suppose that gas limit is less than gas allowance - let block_gas_limit = BlockGasLimitOf::::get() - 10000; + let block_gas_limit = MAX_BLOCK - 10_000; // Deploy demo-calc-hash-in-one-block. assert_ok!(Gear::upload_program( @@ -8887,30 +8889,31 @@ fn execution_over_blocks() { let src = [0; 32]; + let expected = 64; assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), in_one_block, - Package::new(128, src).encode(), + Package::new(expected, src).encode(), block_gas_limit, 0, false, )); - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); - assert_last_message([0; 32], 128); + assert_last_message([0; 32], expected); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), in_one_block, - Package::new(17_384, src).encode(), + Package::new(1_024, src).encode(), block_gas_limit, 0, false, )); let message_id = get_last_message_id(); - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); assert_failed( message_id, @@ -8921,7 +8924,7 @@ fn execution_over_blocks() { new_test_ext().execute_with(|| { use demo_calc_hash::sha2_512_256; use demo_calc_hash_over_blocks::{Method, WASM_BINARY}; - let block_gas_limit = BlockGasLimitOf::::get(); + let block_gas_limit = MAX_BLOCK; let (_, calc_threshold) = estimate_gas_per_calc(); @@ -8931,26 +8934,26 @@ fn execution_over_blocks() { WASM_BINARY.to_vec(), DEFAULT_SALT.to_vec(), calc_threshold.encode(), - 10_000_000_000, + 9_000_000_000, 0, )); let over_blocks = get_last_program_id(); assert!(ProgramStorageOf::::program_exists(over_blocks)); - let (src, id, expected) = ([0; 32], sha2_512_256(b"42"), 16_384); + let (src, id, expected) = ([0; 32], sha2_512_256(b"42"), 512); // trigger calculation assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), over_blocks, Method::Start { src, id, expected }.encode(), - 10_000_000_000, + 9_000_000_000, 0, false, )); - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); let mut count = 0; loop { @@ -8970,7 +8973,7 @@ fn execution_over_blocks() { )); count += 1; - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); } assert!(count > 1); diff --git a/pallets/gear/src/weights.rs b/pallets/gear/src/weights.rs index c52d1f58fac..3ad8efedec0 100644 --- a/pallets/gear/src/weights.rs +++ b/pallets/gear/src/weights.rs @@ -215,6 +215,17 @@ pub trait WeightInfo { fn instr_i32rotl(r: u32, ) -> Weight; fn instr_i64rotr(r: u32, ) -> Weight; fn instr_i32rotr(r: u32, ) -> Weight; + fn tasks_remove_resume_session() -> Weight; + fn tasks_remove_gas_reservation() -> Weight; + fn tasks_send_user_message_to_mailbox() -> Weight; + fn tasks_send_user_message() -> Weight; + fn tasks_send_dispatch() -> Weight; + fn tasks_wake_message() -> Weight; + fn tasks_wake_message_no_wake() -> Weight; + fn tasks_remove_from_waitlist() -> Weight; + fn tasks_remove_from_mailbox() -> Weight; + fn tasks_pause_program(c: u32, ) -> Weight; + fn tasks_pause_program_uninited(c: u32, ) -> Weight; fn allocation_cost() -> Weight; fn grow_cost() -> Weight; fn initial_cost() -> Weight; @@ -2062,6 +2073,116 @@ impl WeightInfo for SubstrateWeight { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 5_698_000 picoseconds. + Weight::from_parts(5_953_000, 4169) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1003` + // Estimated: `23637` + // Minimum execution time: 61_615_000 picoseconds. + Weight::from_parts(64_309_000, 23637) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `784` + // Estimated: `21534` + // Minimum execution time: 43_449_000 picoseconds. + Weight::from_parts(44_990_000, 21534) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `906` + // Estimated: `33891` + // Minimum execution time: 75_764_000 picoseconds. + Weight::from_parts(77_875_000, 33891) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `591` + // Estimated: `19885` + // Minimum execution time: 31_362_000 picoseconds. + Weight::from_parts(32_425_000, 19885) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `872` + // Estimated: `25908` + // Minimum execution time: 45_023_000 picoseconds. + Weight::from_parts(46_479_000, 25908) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_365_000 picoseconds. + Weight::from_parts(3_639_000, 3545) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1522` + // Estimated: `57192` + // Minimum execution time: 114_023_000 picoseconds. + Weight::from_parts(117_157_000, 57192) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1228` + // Estimated: `46026` + // Minimum execution time: 90_320_000 picoseconds. + Weight::from_parts(93_096_000, 46026) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2200 + c * (16400 ±0)` + // Estimated: `19363 + c * (84480 ±0)` + // Minimum execution time: 28_326_000 picoseconds. + Weight::from_parts(28_612_000, 19363) + // Standard Error: 73_191 + .saturating_add(Weight::from_parts(39_403_570, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3025 + c * (42 ±0)` + // Estimated: `59431 + c * (2947 ±0)` + // Minimum execution time: 86_517_000 picoseconds. + Weight::from_parts(78_047_954, 59431) + // Standard Error: 2_660 + .saturating_add(Weight::from_parts(1_060_607, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(13_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(9_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } // For backwards compatibility and tests @@ -3903,4 +4024,114 @@ impl WeightInfo for () { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 5_698_000 picoseconds. + Weight::from_parts(5_953_000, 4169) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1003` + // Estimated: `23637` + // Minimum execution time: 61_615_000 picoseconds. + Weight::from_parts(64_309_000, 23637) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `784` + // Estimated: `21534` + // Minimum execution time: 43_449_000 picoseconds. + Weight::from_parts(44_990_000, 21534) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `906` + // Estimated: `33891` + // Minimum execution time: 75_764_000 picoseconds. + Weight::from_parts(77_875_000, 33891) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `591` + // Estimated: `19885` + // Minimum execution time: 31_362_000 picoseconds. + Weight::from_parts(32_425_000, 19885) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `872` + // Estimated: `25908` + // Minimum execution time: 45_023_000 picoseconds. + Weight::from_parts(46_479_000, 25908) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_365_000 picoseconds. + Weight::from_parts(3_639_000, 3545) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1522` + // Estimated: `57192` + // Minimum execution time: 114_023_000 picoseconds. + Weight::from_parts(117_157_000, 57192) + .saturating_add(RocksDbWeight::get().reads(16_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1228` + // Estimated: `46026` + // Minimum execution time: 90_320_000 picoseconds. + Weight::from_parts(93_096_000, 46026) + .saturating_add(RocksDbWeight::get().reads(14_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2200 + c * (16400 ±0)` + // Estimated: `19363 + c * (84480 ±0)` + // Minimum execution time: 28_326_000 picoseconds. + Weight::from_parts(28_612_000, 19363) + // Standard Error: 73_191 + .saturating_add(Weight::from_parts(39_403_570, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3025 + c * (42 ±0)` + // Estimated: `59431 + c * (2947 ±0)` + // Minimum execution time: 86_517_000 picoseconds. + Weight::from_parts(78_047_954, 59431) + // Standard Error: 2_660 + .saturating_add(Weight::from_parts(1_060_607, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(13_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(9_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } diff --git a/runtime/gear/src/weights/pallet_gear.rs b/runtime/gear/src/weights/pallet_gear.rs index 707b287d5c5..8b14d71ab58 100644 --- a/runtime/gear/src/weights/pallet_gear.rs +++ b/runtime/gear/src/weights/pallet_gear.rs @@ -215,6 +215,17 @@ pub trait WeightInfo { fn instr_i32rotl(r: u32, ) -> Weight; fn instr_i64rotr(r: u32, ) -> Weight; fn instr_i32rotr(r: u32, ) -> Weight; + fn tasks_remove_resume_session() -> Weight; + fn tasks_remove_gas_reservation() -> Weight; + fn tasks_send_user_message_to_mailbox() -> Weight; + fn tasks_send_user_message() -> Weight; + fn tasks_send_dispatch() -> Weight; + fn tasks_wake_message() -> Weight; + fn tasks_wake_message_no_wake() -> Weight; + fn tasks_remove_from_waitlist() -> Weight; + fn tasks_remove_from_mailbox() -> Weight; + fn tasks_pause_program(c: u32, ) -> Weight; + fn tasks_pause_program_uninited(c: u32, ) -> Weight; fn allocation_cost() -> Weight; fn grow_cost() -> Weight; fn initial_cost() -> Weight; @@ -2062,6 +2073,116 @@ impl pallet_gear::WeightInfo for SubstrateWeight { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 5_698_000 picoseconds. + Weight::from_parts(5_953_000, 4169) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1003` + // Estimated: `23637` + // Minimum execution time: 61_615_000 picoseconds. + Weight::from_parts(64_309_000, 23637) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `784` + // Estimated: `21534` + // Minimum execution time: 43_449_000 picoseconds. + Weight::from_parts(44_990_000, 21534) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `906` + // Estimated: `33891` + // Minimum execution time: 75_764_000 picoseconds. + Weight::from_parts(77_875_000, 33891) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `591` + // Estimated: `19885` + // Minimum execution time: 31_362_000 picoseconds. + Weight::from_parts(32_425_000, 19885) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `872` + // Estimated: `25908` + // Minimum execution time: 45_023_000 picoseconds. + Weight::from_parts(46_479_000, 25908) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_365_000 picoseconds. + Weight::from_parts(3_639_000, 3545) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1522` + // Estimated: `57192` + // Minimum execution time: 114_023_000 picoseconds. + Weight::from_parts(117_157_000, 57192) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1228` + // Estimated: `46026` + // Minimum execution time: 90_320_000 picoseconds. + Weight::from_parts(93_096_000, 46026) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2200 + c * (16400 ±0)` + // Estimated: `19363 + c * (84480 ±0)` + // Minimum execution time: 28_326_000 picoseconds. + Weight::from_parts(28_612_000, 19363) + // Standard Error: 73_191 + .saturating_add(Weight::from_parts(39_403_570, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3025 + c * (42 ±0)` + // Estimated: `59431 + c * (2947 ±0)` + // Minimum execution time: 86_517_000 picoseconds. + Weight::from_parts(78_047_954, 59431) + // Standard Error: 2_660 + .saturating_add(Weight::from_parts(1_060_607, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(13_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(9_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } // For backwards compatibility and tests @@ -3903,4 +4024,114 @@ impl WeightInfo for () { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 5_698_000 picoseconds. + Weight::from_parts(5_953_000, 4169) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1003` + // Estimated: `23637` + // Minimum execution time: 61_615_000 picoseconds. + Weight::from_parts(64_309_000, 23637) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `784` + // Estimated: `21534` + // Minimum execution time: 43_449_000 picoseconds. + Weight::from_parts(44_990_000, 21534) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `906` + // Estimated: `33891` + // Minimum execution time: 75_764_000 picoseconds. + Weight::from_parts(77_875_000, 33891) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `591` + // Estimated: `19885` + // Minimum execution time: 31_362_000 picoseconds. + Weight::from_parts(32_425_000, 19885) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `872` + // Estimated: `25908` + // Minimum execution time: 45_023_000 picoseconds. + Weight::from_parts(46_479_000, 25908) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_365_000 picoseconds. + Weight::from_parts(3_639_000, 3545) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1522` + // Estimated: `57192` + // Minimum execution time: 114_023_000 picoseconds. + Weight::from_parts(117_157_000, 57192) + .saturating_add(RocksDbWeight::get().reads(16_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1228` + // Estimated: `46026` + // Minimum execution time: 90_320_000 picoseconds. + Weight::from_parts(93_096_000, 46026) + .saturating_add(RocksDbWeight::get().reads(14_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2200 + c * (16400 ±0)` + // Estimated: `19363 + c * (84480 ±0)` + // Minimum execution time: 28_326_000 picoseconds. + Weight::from_parts(28_612_000, 19363) + // Standard Error: 73_191 + .saturating_add(Weight::from_parts(39_403_570, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3025 + c * (42 ±0)` + // Estimated: `59431 + c * (2947 ±0)` + // Minimum execution time: 86_517_000 picoseconds. + Weight::from_parts(78_047_954, 59431) + // Standard Error: 2_660 + .saturating_add(Weight::from_parts(1_060_607, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(13_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(9_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } diff --git a/runtime/vara/src/weights/pallet_gear.rs b/runtime/vara/src/weights/pallet_gear.rs index 707b287d5c5..c5702325ce6 100644 --- a/runtime/vara/src/weights/pallet_gear.rs +++ b/runtime/vara/src/weights/pallet_gear.rs @@ -215,6 +215,17 @@ pub trait WeightInfo { fn instr_i32rotl(r: u32, ) -> Weight; fn instr_i64rotr(r: u32, ) -> Weight; fn instr_i32rotr(r: u32, ) -> Weight; + fn tasks_remove_resume_session() -> Weight; + fn tasks_remove_gas_reservation() -> Weight; + fn tasks_send_user_message_to_mailbox() -> Weight; + fn tasks_send_user_message() -> Weight; + fn tasks_send_dispatch() -> Weight; + fn tasks_wake_message() -> Weight; + fn tasks_wake_message_no_wake() -> Weight; + fn tasks_remove_from_waitlist() -> Weight; + fn tasks_remove_from_mailbox() -> Weight; + fn tasks_pause_program(c: u32, ) -> Weight; + fn tasks_pause_program_uninited(c: u32, ) -> Weight; fn allocation_cost() -> Weight; fn grow_cost() -> Weight; fn initial_cost() -> Weight; @@ -2062,6 +2073,116 @@ impl pallet_gear::WeightInfo for SubstrateWeight { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 6_081_000 picoseconds. + Weight::from_parts(6_314_000, 4169) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1107` + // Estimated: `24053` + // Minimum execution time: 61_245_000 picoseconds. + Weight::from_parts(64_310_000, 24053) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `888` + // Estimated: `22158` + // Minimum execution time: 47_184_000 picoseconds. + Weight::from_parts(48_335_000, 22158) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `1010` + // Estimated: `34619` + // Minimum execution time: 75_767_000 picoseconds. + Weight::from_parts(77_229_000, 34619) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `695` + // Estimated: `20509` + // Minimum execution time: 31_513_000 picoseconds. + Weight::from_parts(33_232_000, 20509) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `976` + // Estimated: `26636` + // Minimum execution time: 48_739_000 picoseconds. + Weight::from_parts(49_963_000, 26636) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_513_000 picoseconds. + Weight::from_parts(3_670_000, 3545) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1626` + // Estimated: `58232` + // Minimum execution time: 109_582_000 picoseconds. + Weight::from_parts(112_343_000, 58232) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1332` + // Estimated: `46962` + // Minimum execution time: 90_789_000 picoseconds. + Weight::from_parts(93_329_000, 46962) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2303 + c * (16400 ±0)` + // Estimated: `19878 + c * (84480 ±0)` + // Minimum execution time: 31_262_000 picoseconds. + Weight::from_parts(31_610_000, 19878) + // Standard Error: 69_131 + .saturating_add(Weight::from_parts(39_928_419, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3129 + c * (42 ±0)` + // Estimated: `60575 + c * (2947 ±0)` + // Minimum execution time: 91_223_000 picoseconds. + Weight::from_parts(98_002_861, 60575) + // Standard Error: 2_086 + .saturating_add(Weight::from_parts(1_092_801, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(13_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(9_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } // For backwards compatibility and tests @@ -3903,4 +4024,114 @@ impl WeightInfo for () { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 6_081_000 picoseconds. + Weight::from_parts(6_314_000, 4169) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1107` + // Estimated: `24053` + // Minimum execution time: 61_245_000 picoseconds. + Weight::from_parts(64_310_000, 24053) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `888` + // Estimated: `22158` + // Minimum execution time: 47_184_000 picoseconds. + Weight::from_parts(48_335_000, 22158) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `1010` + // Estimated: `34619` + // Minimum execution time: 75_767_000 picoseconds. + Weight::from_parts(77_229_000, 34619) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `695` + // Estimated: `20509` + // Minimum execution time: 31_513_000 picoseconds. + Weight::from_parts(33_232_000, 20509) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `976` + // Estimated: `26636` + // Minimum execution time: 48_739_000 picoseconds. + Weight::from_parts(49_963_000, 26636) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_513_000 picoseconds. + Weight::from_parts(3_670_000, 3545) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1626` + // Estimated: `58232` + // Minimum execution time: 109_582_000 picoseconds. + Weight::from_parts(112_343_000, 58232) + .saturating_add(RocksDbWeight::get().reads(16_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1332` + // Estimated: `46962` + // Minimum execution time: 90_789_000 picoseconds. + Weight::from_parts(93_329_000, 46962) + .saturating_add(RocksDbWeight::get().reads(14_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2303 + c * (16400 ±0)` + // Estimated: `19878 + c * (84480 ±0)` + // Minimum execution time: 31_262_000 picoseconds. + Weight::from_parts(31_610_000, 19878) + // Standard Error: 69_131 + .saturating_add(Weight::from_parts(39_928_419, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3129 + c * (42 ±0)` + // Estimated: `60575 + c * (2947 ±0)` + // Minimum execution time: 91_223_000 picoseconds. + Weight::from_parts(98_002_861, 60575) + // Standard Error: 2_086 + .saturating_add(Weight::from_parts(1_092_801, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(13_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(9_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } }