Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(node): Benchmark tasks and reduce GasAllowance accordingly #2797

Merged
merged 40 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
af794cb
update TaskHandler
gshep Jun 16, 2023
fc63588
func get_maximum_task_gas
gshep Jun 16, 2023
718b174
tasks_remove_gas_reservation benchmark
gshep Jun 16, 2023
05479ec
tasks_send_user_message* benchmarks
gshep Jun 17, 2023
d71c136
make fmt
gshep Jun 17, 2023
4ed5a9f
adjust scheduler tests to the new gas charging
gshep Jun 18, 2023
d8ce91d
make clippy
gshep Jun 18, 2023
476c2ce
Merge remote-tracking branch 'origin/master'
gshep Jun 19, 2023
00f7bcc
tasks_send_dispatch
gshep Jun 19, 2023
41df241
make fmt
gshep Jun 19, 2023
23890dd
fix deps for gclient
gshep Jun 19, 2023
61be2d7
tasks_wake_message
gshep Jun 20, 2023
9532284
fix gsdk deps
gshep Jun 20, 2023
82abcc8
tasks_remove_from_waitlist
gshep Jun 20, 2023
4f51408
tasks_remove_from_mailbox
gshep Jun 20, 2023
c4821bc
tasks_pause_program
gshep Jun 22, 2023
f6b1c7e
make pre-commit
gshep Jun 26, 2023
4012547
Merge remote-tracking branch 'origin/master'
gshep Jun 26, 2023
cb57cd2
add upper bound on block weight in execution_over_blocks test case
gshep Jun 26, 2023
34f675f
feature gate gstd part of demo-constructor
gshep Jun 27, 2023
23314d4
use gcore in demo-constructor, adjust test case
gshep Jun 27, 2023
0542d32
adjust test overblocks
gshep Jun 27, 2023
1f9ba49
Merge remote-tracking branch 'origin/master'
gshep Jul 11, 2023
14196ec
make fmt
gshep Jul 11, 2023
2cd29d3
set features for constructor dependency
gshep Jul 11, 2023
64e5587
Merge remote-tracking branch 'origin/master'
gshep Aug 8, 2023
4c36795
Merge remote-tracking branch 'origin/master'
gshep Sep 7, 2023
8867de2
use drain iterator
gshep Sep 8, 2023
ba40b8b
fix review remarks
gshep Sep 8, 2023
45336f7
rename funcs
gshep Sep 8, 2023
541c240
Merge remote-tracking branch 'origin/master'
gshep Sep 11, 2023
a8f4abd
fix build
gshep Sep 11, 2023
397c6e8
remove copy-paste
gshep Sep 11, 2023
2d8f0d9
fix review remarks
gshep Sep 11, 2023
6ce3d10
fix review remarks
gshep Sep 11, 2023
2ec5438
move all tasks benchmarks in the module
gshep Sep 11, 2023
831218e
Merge remote-tracking branch 'origin/master'
gshep Sep 13, 2023
e8da3a7
add logging for returned gas value
gshep Sep 13, 2023
db1ac81
update weights
gshep Sep 14, 2023
28d0ac1
Merge remote-tracking branch 'origin/master'
gshep Sep 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,15 @@ demo-calc-hash-in-one-block = { path = "examples/binaries/calc-hash/in-one-block
demo-calc-hash-over-blocks = { path = "examples/binaries/calc-hash/over-blocks" }
demo-capacitor = { path = "examples/binaries/capacitor" }
demo-compose = { path = "examples/binaries/compose" }
demo-constructor = { path = "examples/binaries/constructor" }
demo-delayed-sender = { path = "examples/binaries/delayed-sender" }
demo-constructor = { path = "examples/binaries/constructor", default-features = false }
demo-delayed-sender = { path = "examples/binaries/delayed-sender", default-features = false }
demo-distributor = { path = "examples/binaries/distributor" }
demo-futures-unordered = { path = "examples/binaries/futures-unordered", features = ["debug"] }
demo-gas-burned = { path = "examples/binaries/gas-burned" }
demo-fungible-token = { path = "examples/binaries/fungible-token" }
demo-incomplete-async-payloads = { path = "examples/binaries/incomplete-async-payloads" }
demo-init-fail-sender = { path = "examples/binaries/init-fail-sender" }
demo-init-wait = { path = "examples/binaries/init-wait" }
demo-init-wait = { path = "examples/binaries/init-wait", default-features = false }
demo-init-wait-reply-exit = { path = "examples/binaries/init-wait-reply-exit" }
demo-messager = { path = "examples/binaries/messager" }
demo-meta-io = { path = "examples/binaries/new-meta/io" }
Expand All @@ -390,15 +390,15 @@ demo-proxy = { path = "examples/binaries/proxy", default-features = false }
demo-proxy-relay = { path = "examples/binaries/proxy-relay" }
demo-proxy-reservation-with-gas = { path = "examples/binaries/proxy-reservation-with-gas" }
demo-reservation-manager = { path = "examples/binaries/reservation-manager" }
demo-reserve-gas = { path = "examples/binaries/reserve-gas" }
demo-reserve-gas = { path = "examples/binaries/reserve-gas", default-features = false }
demo-rwlock = { path = "examples/binaries/rwlock" }
demo-send-from-reservation = { path = "examples/binaries/send-from-reservation" }
demo-signal-entry = { path = "examples/binaries/signal-entry" }
demo-state-rollback = { path = "examples/binaries/state-rollback" }
demo-sync-duplicate = { path = "examples/binaries/sync-duplicate" }
demo-vec = { path = "examples/binaries/vec" }
demo-wait = { path = "examples/binaries/wait" }
demo-waiter = { path = "examples/binaries/waiter" }
demo-waiter = { path = "examples/binaries/waiter", default-features = false }
demo-wait-timeout = { path = "examples/binaries/wait-timeout" }
demo-wait-wake = { path = "examples/binaries/wait_wake" }
demo-waiting-proxy = { path = "examples/binaries/waiting-proxy" }
Expand Down
30 changes: 18 additions & 12 deletions common/src/scheduler/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use frame_support::{
};
use gear_core::ids::{CodeId, MessageId, ProgramId, ReservationId};

pub type Gas = u64;
ark0f marked this conversation as resolved.
Show resolved Hide resolved

/// Scheduled task sense and required data for processing action.
///
/// CAUTION: NEVER ALLOW `ScheduledTask<AccountId>` BE A BIG DATA.
Expand Down Expand Up @@ -85,7 +87,7 @@ pub enum ScheduledTask<AccountId> {
}

impl<AccountId> ScheduledTask<AccountId> {
pub fn process_with(self, handler: &mut impl TaskHandler<AccountId>) {
pub fn process_with(self, handler: &mut impl TaskHandler<AccountId>) -> Gas {
use ScheduledTask::*;

match self {
Expand Down Expand Up @@ -117,32 +119,36 @@ pub trait TaskHandler<AccountId> {
// Rent charging section.
// -----
/// Pause program action.
fn pause_program(&mut self, program_id: ProgramId);
/// Remove code action.
fn remove_code(&mut self, code_id: CodeId);
fn pause_program(&mut self, program_id: ProgramId) -> Gas;
/// Remove code action
ark0f marked this conversation as resolved.
Show resolved Hide resolved
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]
Expand Down
4 changes: 3 additions & 1 deletion examples/binaries/constructor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,5 +17,6 @@ gear-wasm-builder.workspace = true

[features]
debug = ["gstd/debug"]
std = []
wasm-wrapper = []
std = ["wasm-wrapper"]
default = ["std"]
6 changes: 5 additions & 1 deletion examples/binaries/constructor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use gear_wasm_builder::WasmBuilder;

fn main() {
gear_wasm_builder::build();
WasmBuilder::new()
.exclude_features(vec!["std", "wasm-wrapper"])
.build();
}
2 changes: 1 addition & 1 deletion examples/binaries/constructor/src/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl From<&'static str> for Arg<bool> {
}
}

#[cfg(not(feature = "std"))]
#[cfg(not(feature = "wasm-wrapper"))]
gshep marked this conversation as resolved.
Show resolved Hide resolved
mod wasm {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion examples/binaries/constructor/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub enum Call {
Loop,
}

#[cfg(not(feature = "std"))]
#[cfg(not(feature = "wasm-wrapper"))]
mod wasm {
use super::*;
use crate::DATA;
Expand Down
10 changes: 5 additions & 5 deletions examples/binaries/constructor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Arg, Call, Calls, Scheme};
use gstd::errors::{ReplyCode, SuccessReplyReason};
ark0f marked this conversation as resolved.
Show resolved Hide resolved
use gcore::errors::{ReplyCode, SuccessReplyReason};
use parity_scale_codec::Encode;

pub const PROXIED_MESSAGE: &[u8] = b"proxied message";
Expand Down
3 changes: 2 additions & 1 deletion examples/binaries/delayed-sender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ gear-wasm-builder.workspace = true

[features]
debug = ["gstd/debug"]
std = [ ]
wasm-wrapper = []
std = ["wasm-wrapper"]
default = ["std"]
6 changes: 5 additions & 1 deletion examples/binaries/delayed-sender/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use gear_wasm_builder::WasmBuilder;

fn main() {
gear_wasm_builder::build();
WasmBuilder::new()
.exclude_features(vec!["std", "wasm-wrapper"])
.build();
}
18 changes: 18 additions & 0 deletions examples/binaries/delayed-sender/src/code.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
// This file is part of Gear.

// Copyright (C) Gear Technologies Inc.
ark0f marked this conversation as resolved.
Show resolved Hide resolved
// 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 <https://www.gnu.org/licenses/>.

use gstd::{msg, MessageId, exec};

static mut MID: Option<MessageId> = None;
Expand Down
7 changes: 4 additions & 3 deletions examples/binaries/delayed-sender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![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"}
}
9 changes: 4 additions & 5 deletions examples/binaries/init-wait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"]
6 changes: 5 additions & 1 deletion examples/binaries/init-wait/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use gear_wasm_builder::WasmBuilder;

fn main() {
gear_wasm_builder::build();
WasmBuilder::new()
.exclude_features(vec!["std", "wasm-wrapper"])
.build();
}
18 changes: 18 additions & 0 deletions examples/binaries/init-wait/src/code.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

use gstd::{exec, msg, BTreeMap, MessageId};

#[derive(PartialEq, Debug)]
Expand Down
24 changes: 21 additions & 3 deletions examples/binaries/init-wait/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

#![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"}
}
3 changes: 2 additions & 1 deletion examples/binaries/reserve-gas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ gtest.workspace = true

[features]
debug = ["gstd/debug"]
std = []
wasm-wrapper = []
std = ["wasm-wrapper", "parity-scale-codec/std"]
default = ["std"]
6 changes: 5 additions & 1 deletion examples/binaries/reserve-gas/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use gear_wasm_builder::WasmBuilder;

fn main() {
gear_wasm_builder::build();
WasmBuilder::new()
.exclude_features(vec!["std", "wasm-wrapper"])
.build();
}
6 changes: 3 additions & 3 deletions examples/binaries/reserve-gas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::{
Expand Down
Loading