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 all 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
2 changes: 2 additions & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,15 @@ 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"] }
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" }
Expand All @@ -396,15 +396,15 @@ 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" }
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" }
Expand Down
15 changes: 3 additions & 12 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -228,18 +231,6 @@ impl<BlockNumber: Copy + Saturating> Program<BlockNumber> {
})
)
}

pub fn is_uninitialized(&self) -> Option<MessageId> {
if let Program::Active(ActiveProgram {
state: ProgramState::Uninitialized { message_id },
..
}) = self
{
Some(*message_id)
} else {
None
}
}
}

#[derive(Clone, Debug, derive_more::Display)]
Expand Down
28 changes: 16 additions & 12 deletions common/src/scheduler/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// 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 crate::paused_program_storage::SessionId;
use crate::{paused_program_storage::SessionId, Gas};
use frame_support::{
codec::{self, Decode, Encode, MaxEncodedLen},
scale_info::{self, TypeInfo},
Expand Down Expand Up @@ -85,7 +85,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 +117,36 @@ pub trait TaskHandler<AccountId> {
// 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]
Expand Down
4 changes: 3 additions & 1 deletion examples/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/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/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"))]
mod wasm {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion examples/constructor/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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/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
2 changes: 1 addition & 1 deletion examples/constructor/src/scheme/demo_proxy_with_gas.rs
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};
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/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/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/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.
// 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/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/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/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/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, collections::BTreeMap, MessageId};

#[derive(PartialEq, Debug)]
Expand Down
24 changes: 21 additions & 3 deletions examples/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/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"]
Loading