Skip to content

Commit

Permalink
refactor(node): Benchmark tasks and reduce GasAllowance accordingly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gshep authored Sep 17, 2023
1 parent 604d713 commit 50a4ec1
Show file tree
Hide file tree
Showing 40 changed files with 1,595 additions and 153 deletions.
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

0 comments on commit 50a4ec1

Please sign in to comment.