Skip to content

Commit

Permalink
Merge branch 'master' into cl/issue-2832
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Nov 17, 2023
2 parents d9d776b + 84cd09d commit 9c05fa3
Show file tree
Hide file tree
Showing 42 changed files with 952 additions and 529 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ jobs:
- name: "Build: Node"
run: ./scripts/gear.sh build node --release --locked

- name: "Check: Stack height limit"
run: cargo run -p calc-stack-height --release --locked

- name: "Test: gsdk tests"
run: ./scripts/gear.sh test gsdk --release

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ jobs:

- name: "Build: Node"
run: cargo build -p gear-cli

- name: "Check: Stack height limit"
run: cargo run -p calc-stack-height --release --locked

- name: "Test: Lazy pages"
run: >-
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ jobs:
- name: "Check: Vara runtime imports"
run: ./target/release/wasm-proc --check-runtime-imports target/release/wbuild/vara-runtime/vara_runtime.compact.wasm

- name: "Check: Stack height limit"
run: cargo run -p calc-stack-height --release --locked

- name: "Test: Gear workspace"
run: ./scripts/gear.sh test gear --exclude gclient --exclude gcli --exclude gsdk --release --locked

Expand Down Expand Up @@ -110,7 +113,7 @@ jobs:
- name: "Test: Try runtime migrations"
run: |
cargo build -p gear-cli --features try-runtime --release --locked
./target/release/gear try-runtime --runtime ./target/release/wbuild/vara-runtime/vara_runtime.wasm on-runtime-upgrade --checks live --uri ws://52.32.138.151:9944
./target/release/gear try-runtime --runtime ./target/release/wbuild/vara-runtime/vara_runtime.wasm on-runtime-upgrade --checks live --uri ws://rpc-private.vara-network.io:9944
env:
RUST_LOG: info

Expand Down Expand Up @@ -228,6 +231,11 @@ jobs:
env:
CARGO_BUILD_TARGET: x86_64-pc-windows-msvc

- name: "Check: Stack height limit"
run: cargo xwin run -p calc-stack-height --release --locked
env:
CARGO_BUILD_TARGET: x86_64-pc-windows-msvc

# These tests randomly stops responding

#- name: "Test: Client tests"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
context: .
file: ./docker/Dockerfile
push: true
tags: ghcr.io/gear-tech/node:latest, ${{ needs.tag-image.outputs.image_tag }}
tags: ${{ needs.tag-image.outputs.image_tag }}

- name: SSH into VM
uses: appleboy/[email protected]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules/
target/
target-no-lazy/
target-xwin/
log/
.binpath
.vscode
Expand Down
22 changes: 17 additions & 5 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ gear-wasm-gen = { path = "utils/wasm-gen" }
gear-wasm-instrument = { path = "utils/wasm-instrument", default-features = false }
junit-common = { path = "utils/junit-common" }
actor-system-error = { path = "utils/actor-system-error" }
calc-stack-height = { path = "utils/calc-stack-height" }
pallet-gear = { path = "pallets/gear", default-features = false }
pallet-gear-debug = { path = "pallets/gear-debug", default-features = false }
pallet-gear-gas = { path = "pallets/gas", default-features = false }
Expand All @@ -249,6 +250,10 @@ testing = { package = "gear-node-testing", path = "node/testing" }
vara-runtime = { path = "runtime/vara", default-features = false }
wasm-smith = { version = "0.12.21", git = "https://github.com/gear-tech/wasm-tools.git", branch = "gear-stable" }

# Common executors between `sandbox-host` and `calc-stack-height`
sandbox-wasmer = { package = "wasmer", version = "2.2", features = ["singlepass"] }
sandbox-wasmer-types = { package = "wasmer-types", version = "2.2" }

# Substrate deps
frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/gear-tech/substrate.git", branch = "gear-polkadot-v0.9.41-canary-no-sandbox-revert-oom-changes", default-features = false }
frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/gear-tech/substrate.git", branch = "gear-polkadot-v0.9.41-canary-no-sandbox-revert-oom-changes" }
Expand Down Expand Up @@ -425,14 +430,14 @@ demo-wat = { path = "examples/wat" }
# TODO: remove these dependencies (from this file?) or add more docs.
cfg-if = "1.0.0" # gear-lazy-pages
errno = "0.3" # gear-lazy-pages
nix = "0.26.4" # gear-lazy-pages
impl-trait-for-tuples = "0.2.2" # pallets/staking-rewards
indexmap = "2.1.0" # utils/weight-diff
indicatif = "*" # utils/wasm-gen
keyring = "1.2.1" # gcli
libp2p = "=0.50.1" # gcli (same version as sc-consensus)
mimalloc = { version = "0.1.39", default-features = false } # node/cli
nacl = "0.5.3" # gcli
nix = "0.26.4" # gear-lazy-pages
nonempty = "0.8.1" # utils/utils
libfuzzer-sys = "0.4" # utils/runtime-fuzzer/fuzz
pwasm-utils = "0.19.0" # utils/wasm-builder
Expand Down
30 changes: 30 additions & 0 deletions core/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use alloc::{collections::BTreeSet, vec, vec::Vec};
use gear_wasm_instrument::{
parity_wasm::{
self,
builder::ModuleBuilder,
elements::{ExportEntry, GlobalEntry, GlobalType, InitExpr, Instruction, Internal, Module},
},
wasm_instrument::{
Expand Down Expand Up @@ -295,13 +296,31 @@ fn check_start_section(module: &Module) -> Result<(), CodeError> {
}
}

fn export_stack_height(module: Module) -> Module {
let globals = module
.global_section()
.expect("Global section must be create by `inject_stack_limiter` before")
.entries()
.len();
ModuleBuilder::new()
.with_module(module)
.export()
.field("__gear_stack_height")
.internal()
.global(globals as u32 - 1)
.build()
.build()
}

/// Configuration for `Code::try_new_mock_`.
/// By default all checks enabled.
pub struct TryNewCodeConfig {
/// Instrumentation version
pub version: u32,
/// Stack height limit
pub stack_height: Option<u32>,
/// Export `__gear_stack_height` global
pub export_stack_height: bool,
/// Check exports (wasm contains init or handle exports)
pub check_exports: bool,
/// Check and canonize stack end
Expand All @@ -319,6 +338,7 @@ impl Default for TryNewCodeConfig {
Self {
version: 1,
stack_height: None,
export_stack_height: false,
check_exports: true,
check_and_canonize_stack_end: true,
check_mut_global_exports: true,
Expand Down Expand Up @@ -398,10 +418,20 @@ impl Code {
}

if let Some(stack_limit) = config.stack_height {
let globals = config.export_stack_height.then(|| module.globals_space());

module = wasm_instrument::inject_stack_limiter(module, stack_limit).map_err(|err| {
log::trace!("Failed to inject stack height limits: {err}");
CodeError::StackLimitInjection
})?;

if let Some(globals_before) = globals {
// ensure stack limiter injector has created global
let globals_after = module.globals_space();
assert_eq!(globals_after, globals_before + 1);

module = export_stack_height(module);
}
}

if let Some(mut get_gas_rules) = get_gas_rules {
Expand Down
1 change: 1 addition & 0 deletions gcli/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub use self::{
result::{Error, Result},
traits::{Convert, NodeExec},
};
use gear_core::ids::{CodeId, ProgramId};
use gsdk::{
ext::{sp_core::crypto::Ss58Codec, sp_runtime::AccountId32},
testing::Node,
Expand Down
2 changes: 1 addition & 1 deletion gstd/src/async_runtime/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl WakeSignals {
self.signals.contains_key(&reply_to)
}

pub fn poll(&mut self, reply_to: MessageId, cx: &mut Context<'_>) -> ReplyPoll {
pub fn poll(&mut self, reply_to: MessageId, cx: &Context<'_>) -> ReplyPoll {
match self.signals.remove(&reply_to) {
None => ReplyPoll::None,
Some(mut signal @ WakeSignal { payload: None, .. }) => {
Expand Down
2 changes: 1 addition & 1 deletion gstd/src/msg/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use core::{
use futures::future::FusedFuture;
use scale_info::scale::Decode;

fn poll<F, R>(waiting_reply_to: MessageId, cx: &mut Context<'_>, f: F) -> Poll<Result<R>>
fn poll<F, R>(waiting_reply_to: MessageId, cx: &Context<'_>, f: F) -> Poll<Result<R>>
where
F: Fn(Vec<u8>) -> Result<R>,
{
Expand Down
7 changes: 3 additions & 4 deletions gtest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ license.workspace = true
gear-core.workspace = true
gear-core-errors.workspace = true
core-processor = { workspace = true, features = ["std"] }
gear-lazy-pages-interface = { workspace = true, features = ["std"] }
gear-lazy-pages.workspace = true
gear-lazy-pages-common.workspace = true
gear-utils.workspace = true
gear-wasm-instrument.workspace = true
gsys.workspace = true

sp-io = { workspace = true, features = ["std"] }

codec = { workspace = true, features = ["derive"] }
hex.workspace = true
colored.workspace = true
derive_more = { workspace = true, features = ["add", "add_assign", "display", "mul", "mul_assign"] }
env_logger.workspace = true
path-clean.workspace = true
rand = { workspace = true, features = ["std", "std_rng"] }
gear-wasm-instrument.workspace = true
log.workspace = true

[dev-dependencies]
Expand Down
Loading

0 comments on commit 9c05fa3

Please sign in to comment.