diff --git a/.github/workflows/CI-docker-gear.yml b/.github/workflows/CI-docker-gear.yml
new file mode 100644
index 00000000000..69ec358f421
--- /dev/null
+++ b/.github/workflows/CI-docker-gear.yml
@@ -0,0 +1,49 @@
+name: CI | docker-gear release version
+
+on:
+ workflow_dispatch:
+ inputs:
+ release_version:
+ description: 'Release version from https://get.gear.rs Example: v1.0.0. *Null = latest'
+ required: false
+ default: ''
+
+env:
+ RELEASE_VERSION: ${{ github.event.inputs.release_version }}
+
+jobs:
+ build:
+ runs-on: [kuberunner]
+ steps:
+ - uses: actions/checkout@v4
+ - uses: docker/setup-buildx-action@v2
+
+ - uses: actions/cache@v3
+ with:
+ path: /tmp/.buildx-cache
+ key: ${{ runner.os }}-buildx-gear-${{ github.sha }}
+ restore-keys: |
+ ${{ runner.os }}-buildx-gear
+
+ - uses: docker/login-action@v2
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - run: |
+ if [ -z "${{ env.RELEASE_VERSION }}" ]; then
+ echo "DOCKER_TAGS=ghcr.io/gear-tech/node:latest" >> $GITHUB_ENV
+ else
+ echo "DOCKER_TAGS=ghcr.io/gear-tech/node:latest,ghcr.io/gear-tech/node:${{ env.RELEASE_VERSION }}" >> $GITHUB_ENV
+ fi
+
+ - uses: docker/build-push-action@v4
+ with:
+ file: ./docker/Dockerfile-release
+ push: true
+ tags: ${{ env.DOCKER_TAGS }}
+ build-args: |
+ RELEASE_VERSION=${{ env.RELEASE_VERSION }}
+ cache-from: type=local,src=/tmp/.buildx-cache
+ cache-to: type=local,dest=/tmp/.buildx-cache
diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml
index cdb98420dac..8ec90626b45 100644
--- a/.github/workflows/benchmarks.yml
+++ b/.github/workflows/benchmarks.yml
@@ -3,10 +3,15 @@ name: Benchmarks
on:
workflow_dispatch:
inputs:
- create_pr:
- description: Whether to create a pull request after the benchmarks are completed
- required: false
- type: boolean
+ change-type:
+ description: How should changes be made after the benchmarks are completed?
+ required: true
+ default: ignore
+ type: choice
+ options:
+ - ignore
+ - commit
+ - pull_request
env:
CARGO_TERM_COLOR: always
@@ -15,6 +20,9 @@ env:
jobs:
benchmarks:
runs-on: bench
+ permissions:
+ contents: write
+ pull-requests: write
env:
RUSTUP_HOME: /tmp/rustup_home
steps:
@@ -65,11 +73,18 @@ jobs:
run: |
echo "::notice::You can download the artifacts and use script \`./scripts/unpack-weights.sh\` to apply the changes to your branch"
- - name: Create Pull Request
- if: ${{ inputs.create_pr }}
+ - name: Create commit
+ if: ${{ inputs.change-type == 'commit' }}
+ uses: stefanzweifel/git-auto-commit-action@v4
+ with:
+ commit_message: >-
+ chore(runtime): update weights
+ file_pattern: "pallets/gear/src/ runtime/gear/src/weights/ runtime/vara/src/weights/"
+
+ - name: Create pull Request
+ if: ${{ inputs.change-type == 'pull_request' }}
uses: peter-evans/create-pull-request@v5
with:
- token: ${{ secrets.GH_TOKEN_FOR_PR }}
add-paths: |
pallets/gear/src/
runtime/gear/src/weights/
@@ -78,7 +93,7 @@ jobs:
branch: weights/patch
branch-suffix: short-commit-hash
title: >-
- chore: update weights
+ chore(runtime): update weights
body: |
`run_all_benchmarks.sh` script is applied to update weights (branch: `${{ github.ref_name }}`, commit ${{ github.sha }})
**Note:** If CI fails, try manually updating the heuristic tests: `runtime/{gear, vara}/src/tests.rs`
diff --git a/.github/workflows/comparison-table.yml b/.github/workflows/comparison-table.yml
new file mode 100644
index 00000000000..17f39581145
--- /dev/null
+++ b/.github/workflows/comparison-table.yml
@@ -0,0 +1,46 @@
+name: Comparison table
+
+on:
+ workflow_dispatch:
+ inputs:
+ runtime:
+ description: For which runtime generate comparison table?
+ required: true
+ type: choice
+ options:
+ - gear
+ - vara
+
+env:
+ CARGO_TERM_COLOR: always
+ TERM: xterm-256color
+
+jobs:
+ comparison-table:
+ runs-on: [kuberunner]
+ env:
+ RUSTUP_HOME: /tmp/rustup_home
+ steps:
+ - name: "ACTIONS: Checkout & fetch all history"
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: "Install: Set cargo path"
+ run: echo "/tmp/cargo/bin" >> $GITHUB_PATH
+
+ - name: "Install: Rust toolchain"
+ uses: dsherret/rust-toolchain-file@v1
+
+ - name: "Build: Init"
+ run: ./scripts/gear.sh init cargo
+
+ - name: "Generate comparison tables (${{ inputs.runtime }})"
+ run: |
+ ./scripts/weight-diff.sh master $(git branch --show-current) ${{ inputs.runtime }} --display-units > ${{ inputs.runtime }}-tables.txt
+
+ - name: "ACTIONS: Upload artifact with comparison tables (${{ inputs.runtime }})"
+ uses: actions/upload-artifact@v3
+ with:
+ name: ${{ inputs.runtime }}-tables
+ path: ${{ inputs.runtime }}-tables.txt
diff --git a/.github/workflows/time-consuming-tests.yml b/.github/workflows/time-consuming-tests.yml
index 126744ebcfa..9c75a58480c 100644
--- a/.github/workflows/time-consuming-tests.yml
+++ b/.github/workflows/time-consuming-tests.yml
@@ -24,7 +24,7 @@ jobs:
- name: "Install: Rust toolchain"
uses: dsherret/rust-toolchain-file@v1
- - name: "Buid: Init"
+ - name: "Build: Init"
run: ./scripts/gear.sh init cargo
- name: "Build: Node"
diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml
new file mode 100644
index 00000000000..09ca0e73dc1
--- /dev/null
+++ b/.github/workflows/validation.yml
@@ -0,0 +1,69 @@
+name: Live check on Vara Network Validator machine
+
+on:
+ pull_request:
+ types: [synchronize, labeled, opened, reopened, ready_for_review]
+ branches: [master]
+ workflow_dispatch:
+
+env:
+ CARGO_TERM_COLOR: always
+
+jobs:
+ tag-image:
+ runs-on: ubuntu-latest
+ if: contains(github.event.pull_request.labels.*.name, 'check-validator')
+ outputs:
+ image_tag: ${{ steps.image-tag.outputs.tag }}
+ steps:
+ - name: Checkout repo
+ uses: actions/checkout@v4
+
+ - name: Create image tag
+ id: image-tag
+ run: echo "tag=ghcr.io/gear-tech/node:0.1.0-`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_OUTPUT
+
+ build-update-validator:
+ runs-on: [kuberunner]
+ if: contains(github.event.pull_request.labels.*.name, 'check-validator')
+ needs: tag-image
+ steps:
+
+ - name: Checkout repo
+ uses: actions/checkout@v4
+
+ - name: Echo tag
+ run: echo ${{ needs.tag-image.outputs.image_tag }}
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v2
+
+ - name: Login to DockerHub
+ uses: docker/login-action@v2
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Build and push
+ id: docker_build
+ uses: docker/build-push-action@v4
+ with:
+ context: .
+ file: ./docker/Dockerfile
+ push: true
+ tags: ghcr.io/gear-tech/node:latest, ${{ needs.tag-image.outputs.image_tag }}
+
+ - name: SSH into VM
+ uses: appleboy/ssh-action@v1.0.0
+ env:
+ NEW_IMAGE: ${{ needs.tag-image.outputs.image_tag }}
+ with:
+ host: ${{ secrets.VARA_VALIDATOR_8 }}
+ username: ${{ secrets.SSH_VARA_USERNAME }}
+ key: ${{ secrets.VARA_SSH_PRIVATE_KEY }}
+ envs: NEW_IMAGE
+ script: |
+ sudo docker-compose -f /home/gear/docker-compose.yaml down
+ awk -v new_image="$NEW_IMAGE" '{gsub(/image: ghcr.io\/gear-tech\/node:.*/, "image: " new_image)}1' /home/gear/docker-compose.yaml > tmp && mv tmp /home/gear/docker-compose.yaml
+ sudo docker-compose -f /home/gear/docker-compose.yaml up -d
diff --git a/Cargo.lock b/Cargo.lock
index 3041ea8580e..bda8e9987c2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2227,7 +2227,6 @@ dependencies = [
"gear-core",
"gear-wasm-builder",
"gstd",
- "gsys",
"gtest",
"parity-scale-codec",
]
@@ -2582,11 +2581,11 @@ checksum = "86e3bdc80eee6e16b2b6b0f87fbc98c04bee3455e35174c0de1a125d0688c632"
[[package]]
name = "dlmalloc"
version = "0.1.4"
-source = "git+https://github.com/gear-tech/dlmalloc-rust.git?rev=9135baa#9135baa728ef9a9a04a887998e019733c4b093af"
+source = "git+https://github.com/gear-tech/dlmalloc-rust.git#15352f969112faa463302f2490bbb7f6e1cb904d"
dependencies = [
"libc",
- "libc_print",
- "page_size 0.4.2",
+ "libc-print",
+ "page_size 0.6.0",
"static_assertions",
"str-buf",
]
@@ -3633,14 +3632,14 @@ dependencies = [
[[package]]
name = "galloc"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"dlmalloc",
]
[[package]]
name = "gcli"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"anyhow",
"base64 0.21.3",
@@ -3681,7 +3680,7 @@ dependencies = [
[[package]]
name = "gclient"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"anyhow",
"async-trait",
@@ -3725,7 +3724,7 @@ dependencies = [
[[package]]
name = "gcore"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"galloc",
"gear-core-errors",
@@ -3738,7 +3737,7 @@ dependencies = [
[[package]]
name = "gear-authorship"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"demo-mul-by-const",
"env_logger",
@@ -3754,6 +3753,7 @@ dependencies = [
"pallet-balances",
"pallet-gear",
"pallet-gear-messenger",
+ "pallet-gear-program",
"pallet-gear-rpc-runtime-api",
"pallet-sudo",
"pallet-timestamp",
@@ -3781,7 +3781,7 @@ dependencies = [
[[package]]
name = "gear-backend-codegen"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"proc-macro2",
"quote",
@@ -3790,7 +3790,7 @@ dependencies = [
[[package]]
name = "gear-backend-common"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"actor-system-error",
"blake2-rfc",
@@ -3849,7 +3849,7 @@ dependencies = [
[[package]]
name = "gear-cli"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"clap 4.4.2",
"frame-benchmarking",
@@ -3883,7 +3883,7 @@ dependencies = [
[[package]]
name = "gear-common"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"derive_more",
"enum-iterator 1.4.1",
@@ -3911,7 +3911,7 @@ dependencies = [
[[package]]
name = "gear-common-codegen"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"quote",
"syn 2.0.31",
@@ -3919,7 +3919,7 @@ dependencies = [
[[package]]
name = "gear-core"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"blake2-rfc",
"byteorder",
@@ -3935,6 +3935,7 @@ dependencies = [
"paste",
"proptest",
"scale-info",
+ "serde",
"static_assertions",
"wabt",
"wasmparser-nostd 0.100.1",
@@ -3942,7 +3943,7 @@ dependencies = [
[[package]]
name = "gear-core-errors"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"derive_more",
"enum-iterator 1.4.1",
@@ -3951,7 +3952,7 @@ dependencies = [
[[package]]
name = "gear-core-processor"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"actor-system-error",
"derive_more",
@@ -3969,7 +3970,7 @@ dependencies = [
[[package]]
name = "gear-lazy-pages"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"cfg-if",
"derive_more",
@@ -4009,7 +4010,7 @@ dependencies = [
[[package]]
name = "gear-node-loader"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"anyhow",
"arbitrary",
@@ -4041,7 +4042,7 @@ dependencies = [
[[package]]
name = "gear-node-testing"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"frame-benchmarking",
"frame-support",
@@ -4110,7 +4111,7 @@ dependencies = [
[[package]]
name = "gear-runtime"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"const-str",
"frame-benchmarking",
@@ -4172,7 +4173,7 @@ dependencies = [
[[package]]
name = "gear-runtime-common"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"frame-benchmarking",
"frame-support",
@@ -4198,7 +4199,7 @@ dependencies = [
[[package]]
name = "gear-runtime-interface"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"byteorder",
"derive_more",
@@ -4220,7 +4221,7 @@ dependencies = [
[[package]]
name = "gear-runtime-primitives"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"sp-core 7.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)",
"sp-runtime 7.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)",
@@ -4273,7 +4274,7 @@ dependencies = [
[[package]]
name = "gear-service"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"frame-benchmarking",
"frame-benchmarking-cli",
@@ -4354,7 +4355,7 @@ dependencies = [
[[package]]
name = "gear-stack-buffer"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"cc",
]
@@ -4448,7 +4449,7 @@ dependencies = [
[[package]]
name = "gear-wasm-instrument"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"enum-iterator 1.4.1",
"gear-backend-common",
@@ -4618,7 +4619,7 @@ dependencies = [
[[package]]
name = "gmeta"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"blake2-rfc",
"derive_more",
@@ -4632,7 +4633,7 @@ dependencies = [
[[package]]
name = "gmeta-codegen"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"gmeta",
"gstd",
@@ -4656,7 +4657,7 @@ dependencies = [
[[package]]
name = "gsdk"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"anyhow",
"base64 0.21.3",
@@ -4670,9 +4671,11 @@ dependencies = [
"gsdk",
"gsdk-codegen",
"hex",
+ "indexmap 2.0.0",
"jsonrpsee",
"log",
"parity-scale-codec",
+ "parking_lot 0.12.1",
"rand 0.8.5",
"scale-decode",
"scale-value",
@@ -4707,7 +4710,7 @@ dependencies = [
[[package]]
name = "gsdk-codegen"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"proc-macro2",
"quote",
@@ -4716,7 +4719,7 @@ dependencies = [
[[package]]
name = "gstd"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"bs58",
"futures",
@@ -4745,7 +4748,7 @@ dependencies = [
[[package]]
name = "gsys"
-version = "1.0.0"
+version = "1.0.1"
[[package]]
name = "gtest"
@@ -5605,9 +5608,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
[[package]]
-name = "libc_print"
-version = "0.1.16"
-source = "git+https://github.com/grishasobol/rust-libc-print.git#b300804809e7a5f1c8fab4d2d11bcea29217bc70"
+name = "libc-print"
+version = "0.1.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06cea5d58bd9ba4717bbf5c6c5bb11bb6e9e76685b7fff34039b80f50ce86c11"
dependencies = [
"libc",
]
@@ -7114,9 +7118,9 @@ dependencies = [
[[package]]
name = "page_size"
-version = "0.4.2"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd"
+checksum = "1b7663cbd190cfd818d08efa8497f6cd383076688c49a391ef7c0d03cd12b561"
dependencies = [
"libc",
"winapi",
@@ -7124,9 +7128,9 @@ dependencies = [
[[package]]
name = "page_size"
-version = "0.5.0"
+version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1b7663cbd190cfd818d08efa8497f6cd383076688c49a391ef7c0d03cd12b561"
+checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da"
dependencies = [
"libc",
"winapi",
@@ -7313,7 +7317,7 @@ dependencies = [
[[package]]
name = "pallet-gear"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"blake2-rfc",
"demo-async",
@@ -7411,7 +7415,7 @@ dependencies = [
[[package]]
name = "pallet-gear-bank"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"frame-benchmarking",
"frame-support",
@@ -7429,7 +7433,7 @@ dependencies = [
[[package]]
name = "pallet-gear-debug"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"demo-vec",
"env_logger",
@@ -7466,7 +7470,7 @@ dependencies = [
[[package]]
name = "pallet-gear-gas"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"env_logger",
"frame-benchmarking",
@@ -7495,7 +7499,7 @@ dependencies = [
[[package]]
name = "pallet-gear-messenger"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"env_logger",
"frame-benchmarking",
@@ -7519,7 +7523,7 @@ dependencies = [
[[package]]
name = "pallet-gear-payment"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"env_logger",
"frame-benchmarking",
@@ -7553,7 +7557,7 @@ dependencies = [
[[package]]
name = "pallet-gear-proc-macro"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"proc-macro2",
"quote",
@@ -7562,7 +7566,7 @@ dependencies = [
[[package]]
name = "pallet-gear-program"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"frame-support",
"frame-system",
@@ -7587,7 +7591,7 @@ dependencies = [
[[package]]
name = "pallet-gear-rpc"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"gear-common",
"gear-core",
@@ -7603,7 +7607,7 @@ dependencies = [
[[package]]
name = "pallet-gear-rpc-runtime-api"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"pallet-gear",
"sp-api",
@@ -7614,7 +7618,7 @@ dependencies = [
[[package]]
name = "pallet-gear-scheduler"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"env_logger",
"frame-benchmarking",
@@ -7645,7 +7649,7 @@ dependencies = [
[[package]]
name = "pallet-gear-staking-rewards"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"env_logger",
"frame-benchmarking",
@@ -7697,7 +7701,7 @@ dependencies = [
[[package]]
name = "pallet-gear-voucher"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"env_logger",
"frame-benchmarking",
@@ -12343,9 +12347,9 @@ dependencies = [
[[package]]
name = "str-buf"
-version = "2.0.5"
+version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0873cb29201126440dcc78d0b1f5a13d917e78831778429a7920ca9c7f3dae1e"
+checksum = "e75b72ee54e2f93c3ea1354066162be893ee5e25773ab743de3e088cecbb4f31"
[[package]]
name = "strsim"
@@ -13494,7 +13498,7 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vara-runtime"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"const-str",
"env_logger",
@@ -13750,7 +13754,7 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "wasm-encoder"
version = "0.16.0"
-source = "git+https://github.com/gear-tech/wasm-tools.git?branch=gear-stable#2db6004e21aa014f411f8b575a99969284cff702"
+source = "git+https://github.com/gear-tech/wasm-tools.git?branch=gear-stable#9942645b3891607e13f11f6444ca320ba36a6a1f"
dependencies = [
"leb128",
]
@@ -13837,7 +13841,7 @@ dependencies = [
[[package]]
name = "wasm-smith"
version = "0.11.4"
-source = "git+https://github.com/gear-tech/wasm-tools.git?branch=gear-stable#2db6004e21aa014f411f8b575a99969284cff702"
+source = "git+https://github.com/gear-tech/wasm-tools.git?branch=gear-stable#9942645b3891607e13f11f6444ca320ba36a6a1f"
dependencies = [
"arbitrary",
"flagset",
@@ -14219,7 +14223,7 @@ checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a"
[[package]]
name = "wasmparser"
version = "0.90.0"
-source = "git+https://github.com/gear-tech/wasm-tools.git?branch=gear-stable#2db6004e21aa014f411f8b575a99969284cff702"
+source = "git+https://github.com/gear-tech/wasm-tools.git?branch=gear-stable#9942645b3891607e13f11f6444ca320ba36a6a1f"
dependencies = [
"indexmap 1.9.3",
]
diff --git a/Cargo.toml b/Cargo.toml
index eecdbf0432f..95f1b55982d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,5 @@
[workspace.package]
-version = "1.0.0"
+version = "1.0.1"
authors = ["Gear Technologies"]
edition = "2021"
license = "GPL-3.0"
@@ -105,7 +105,7 @@ colored = "2.0.0"
const-str = "0.5"
derive_more = "0.99.17"
dirs = "4.0.0"
-dlmalloc = { git = "https://github.com/gear-tech/dlmalloc-rust.git", rev = "9135baa", default-features = false }
+dlmalloc = { git = "https://github.com/gear-tech/dlmalloc-rust.git" }
dyn-clonable = "0.9.0"
enum-iterator = "1.4.0"
env_logger = "0.10"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 666e400433f..6fb6635d08e 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -26,10 +26,15 @@ paste = { workspace = true }
enum-iterator.workspace = true
byteorder.workspace = true
+# Optional dependencies
+serde = { workspace = true, features = [ "derive" ], optional = true }
+
[dev-dependencies]
wabt.workspace = true
env_logger.workspace = true
proptest.workspace = true
[features]
+default = []
strict = []
+std = ["serde/std"]
diff --git a/core/src/gas.rs b/core/src/gas.rs
index 8cfe903e66b..022d10116d3 100644
--- a/core/src/gas.rs
+++ b/core/src/gas.rs
@@ -20,7 +20,10 @@
use crate::costs::RuntimeCosts;
use enum_iterator::Sequence;
-use scale_info::scale::{Decode, Encode};
+use scale_info::{
+ scale::{Decode, Encode},
+ TypeInfo,
+};
/// The id of the gas lock.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Sequence)]
@@ -329,6 +332,27 @@ impl From<(i64, i64)> for GasLeft {
}
}
+/// The struct contains results of gas calculation required to process
+/// a message.
+#[derive(Clone, Debug, Decode, Encode, PartialEq, Eq, TypeInfo)]
+#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
+pub struct GasInfo {
+ /// Represents minimum gas limit required for execution.
+ pub min_limit: u64,
+ /// Gas amount that we reserve for some other on-chain interactions.
+ pub reserved: u64,
+ /// Contains number of gas burned during message processing.
+ pub burned: u64,
+ /// The value may be returned if a program happens to be executed
+ /// the second or next time in a block.
+ pub may_be_returned: u64,
+ /// Was the message placed into waitlist at the end of calculating.
+ ///
+ /// This flag shows, that `min_limit` makes sense and have some guarantees
+ /// only before insertion into waitlist.
+ pub waited: bool,
+}
+
#[cfg(test)]
mod tests {
use super::{ChargeResult, GasCounter};
diff --git a/docker/Dockerfile b/docker/Dockerfile
index a36437d090c..c15e2bd8d13 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -37,7 +37,7 @@ RUN cargo build -p gear-cli --profile $PROFILE
# ===== SECOND STAGE ======
-FROM ubuntu:22.10
+FROM ubuntu:22.04
MAINTAINER GEAR
LABEL description="This is the 2nd stage: a very small image where we copy the Gear binary."
ARG PROFILE=production
diff --git a/docker/Dockerfile-release b/docker/Dockerfile-release
new file mode 100644
index 00000000000..d5181c2092c
--- /dev/null
+++ b/docker/Dockerfile-release
@@ -0,0 +1,17 @@
+FROM debian:12-slim
+
+ARG RELEASE_VERSION
+
+RUN apt-get update && \
+ apt-get install -y curl sudo xz-utils && \
+ rm -rf /var/lib/apt/lists/*
+
+RUN if [ -z "$RELEASE_VERSION" ]; then \
+ curl --proto '=https' --tlsv1.2 -sSf https://get.gear.rs/install.sh | bash -s -- --to /usr/local/bin/ ; \
+ else \
+ curl --proto '=https' --tlsv1.2 -sSf https://get.gear.rs/install.sh | bash -s -- --tag ${RELEASE_VERSION} --to /usr/local/bin/ ; \
+ fi
+
+RUN gear --version
+
+CMD ["gear"]
diff --git a/examples/async-custom-entry/Cargo.toml b/examples/async-custom-entry/Cargo.toml
index 7a059c0d776..ce820c11930 100644
--- a/examples/async-custom-entry/Cargo.toml
+++ b/examples/async-custom-entry/Cargo.toml
@@ -2,13 +2,14 @@
name = "demo-async-custom-entry"
version = "0.1.0"
authors.workspace = true
-edition = "2021"
-license = "GPL-3.0"
-workspace = "../../"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+repository.workspace = true
[dependencies]
-parity-scale-codec = { workspace = true, features = ["derive"] }
gstd.workspace = true
+parity-scale-codec.workspace = true
[build-dependencies]
gear-wasm-builder.workspace = true
@@ -16,8 +17,6 @@ gear-wasm-builder.workspace = true
[dev-dependencies]
gtest.workspace = true
-[lib]
-
[features]
debug = ["gstd/debug"]
std = ["parity-scale-codec/std"]
diff --git a/examples/async-custom-entry/src/lib.rs b/examples/async-custom-entry/src/lib.rs
index 6a7b7d54ea0..b20b99554f5 100644
--- a/examples/async-custom-entry/src/lib.rs
+++ b/examples/async-custom-entry/src/lib.rs
@@ -27,33 +27,4 @@ mod code {
pub use code::WASM_BINARY_OPT as WASM_BINARY;
#[cfg(not(feature = "std"))]
-mod wasm {
- use gstd::{msg, ActorId};
-
- static mut USER: ActorId = ActorId::zero();
-
- #[gstd::async_init(handle_reply = my_handle_reply, handle_signal = my_handle_signal)]
- async fn init() {
- gstd::Config::set_system_reserve(10_000_000_000).expect("Failed to set system reserve");
-
- unsafe { USER = msg::source() }
- }
-
- #[gstd::async_main]
- async fn main() {
- #[allow(clippy::empty_loop)]
- loop {}
- }
-
- fn my_handle_reply() {
- unsafe {
- msg::send_bytes(USER, b"my_handle_reply", 0).unwrap();
- }
- }
-
- fn my_handle_signal() {
- unsafe {
- msg::send_bytes(USER, b"my_handle_signal", 0).unwrap();
- }
- }
-}
+mod wasm;
diff --git a/examples/async-custom-entry/src/wasm.rs b/examples/async-custom-entry/src/wasm.rs
new file mode 100644
index 00000000000..a8f110f5bb2
--- /dev/null
+++ b/examples/async-custom-entry/src/wasm.rs
@@ -0,0 +1,46 @@
+// This file is part of Gear.
+
+// Copyright (C) 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::{msg, ActorId};
+
+static mut USER: ActorId = ActorId::zero();
+
+#[gstd::async_init(handle_reply = my_handle_reply, handle_signal = my_handle_signal)]
+async fn init() {
+ gstd::Config::set_system_reserve(10_000_000_000).expect("Failed to set system reserve");
+
+ unsafe { USER = msg::source() }
+}
+
+#[gstd::async_main]
+async fn main() {
+ #[allow(clippy::empty_loop)]
+ loop {}
+}
+
+fn my_handle_reply() {
+ unsafe {
+ msg::send_bytes(USER, b"my_handle_reply", 0).unwrap();
+ }
+}
+
+fn my_handle_signal() {
+ unsafe {
+ msg::send_bytes(USER, b"my_handle_signal", 0).unwrap();
+ }
+}
diff --git a/examples/async-init/Cargo.toml b/examples/async-init/Cargo.toml
index 950e247e59d..eb2eb78d4b6 100644
--- a/examples/async-init/Cargo.toml
+++ b/examples/async-init/Cargo.toml
@@ -4,12 +4,13 @@ version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
-workspace = "../../"
+homepage.workspace = true
+repository.workspace = true
[dependencies]
gstd.workspace = true
-parity-scale-codec = { workspace = true, features = ["derive"] }
-futures = { workspace = true, features = ["alloc"] }
+parity-scale-codec.workspace = true
+futures.workspace = true
[build-dependencies]
gear-wasm-builder.workspace = true
diff --git a/examples/async-init/src/lib.rs b/examples/async-init/src/lib.rs
index d5111c026cd..f58aab75c33 100644
--- a/examples/async-init/src/lib.rs
+++ b/examples/async-init/src/lib.rs
@@ -57,74 +57,4 @@ impl InputArgs {
}
#[cfg(not(feature = "std"))]
-mod wasm {
- /* The program demonstrates asynchronous execution and
- * how to use macros `gstd::async_init`/`gstd::async_main`.
- *
- * `Init` method gets three addresses, sends "PING" messages
- * to them and waits for at least two replies with any payload ("approvals").
- *
- * `Handle` processes only "PING" messages. When `handle` gets such message
- * it sends empty requests to the three addresses and waits for just one approval.
- * If an approval is obtained the method replies with "PONG".
- */
-
- use crate::InputArgs;
- use futures::future;
- use gstd::{msg, prelude::*, ActorId};
-
- // One of the addresses supposed to be non-program.
- static mut ARGUMENTS: InputArgs = InputArgs {
- approver_first: ActorId::zero(),
- approver_second: ActorId::zero(),
- approver_third: ActorId::zero(),
- };
-
- static mut RESPONSES: u8 = 0;
-
- #[gstd::async_init]
- async fn init() {
- let arguments: InputArgs = msg::load().expect("Failed to load arguments");
-
- let mut requests = arguments
- .iter()
- .map(|&addr| {
- msg::send_bytes_for_reply(addr, "PING", 0, 0).expect("Failed to send message")
- })
- .collect::>();
-
- unsafe {
- ARGUMENTS = arguments;
- }
-
- while !requests.is_empty() {
- let (.., remaining) = future::select_all(requests).await;
- unsafe {
- RESPONSES += 1;
- }
-
- if unsafe { RESPONSES } >= 2 {
- break;
- }
-
- requests = remaining;
- }
- }
-
- #[gstd::async_main]
- async fn main() {
- let message = msg::load_bytes().expect("Failed to load bytes");
-
- assert_eq!(message, b"PING");
-
- let requests = unsafe { ARGUMENTS.iter() }
- .map(|&addr| {
- msg::send_bytes_for_reply(addr, "PING", 0, 0).expect("Failed to send message")
- })
- .collect::>();
-
- let _ = future::select_all(requests).await;
-
- msg::reply(unsafe { RESPONSES }, 0).expect("Failed to send reply");
- }
-}
+mod wasm;
diff --git a/examples/async-init/src/wasm.rs b/examples/async-init/src/wasm.rs
new file mode 100644
index 00000000000..0b12705ca91
--- /dev/null
+++ b/examples/async-init/src/wasm.rs
@@ -0,0 +1,82 @@
+// This file is part of Gear.
+
+// Copyright (C) 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 .
+
+//! The program demonstrates asynchronous execution and
+//! how to use macros `gstd::async_init`/`gstd::async_main`.
+//!
+//! `Init` method gets three addresses, sends "PING" messages
+//! to them and waits for at least two replies with any payload ("approvals").
+//!
+//! `Handle` processes only "PING" messages. When `handle` gets such message
+//! it sends empty requests to the three addresses and waits for just one approval.
+//! If an approval is obtained the method replies with "PONG".
+
+use crate::InputArgs;
+use futures::future;
+use gstd::{msg, prelude::*, ActorId};
+
+// One of the addresses supposed to be non-program.
+static mut ARGUMENTS: InputArgs = InputArgs {
+ approver_first: ActorId::zero(),
+ approver_second: ActorId::zero(),
+ approver_third: ActorId::zero(),
+};
+
+static mut RESPONSES: u8 = 0;
+
+#[gstd::async_init]
+async fn init() {
+ let arguments: InputArgs = msg::load().expect("Failed to load arguments");
+
+ let mut requests = arguments
+ .iter()
+ .map(|&addr| msg::send_bytes_for_reply(addr, "PING", 0, 0).expect("Failed to send message"))
+ .collect::>();
+
+ unsafe {
+ ARGUMENTS = arguments;
+ }
+
+ while !requests.is_empty() {
+ let (.., remaining) = future::select_all(requests).await;
+ unsafe {
+ RESPONSES += 1;
+ }
+
+ if unsafe { RESPONSES } >= 2 {
+ break;
+ }
+
+ requests = remaining;
+ }
+}
+
+#[gstd::async_main]
+async fn main() {
+ let message = msg::load_bytes().expect("Failed to load bytes");
+
+ assert_eq!(message, b"PING");
+
+ let requests = unsafe { ARGUMENTS.iter() }
+ .map(|&addr| msg::send_bytes_for_reply(addr, "PING", 0, 0).expect("Failed to send message"))
+ .collect::>();
+
+ let _ = future::select_all(requests).await;
+
+ msg::reply(unsafe { RESPONSES }, 0).expect("Failed to send reply");
+}
diff --git a/examples/async-recursion/Cargo.toml b/examples/async-recursion/Cargo.toml
index 8bdf01eb582..99fc3c4f579 100644
--- a/examples/async-recursion/Cargo.toml
+++ b/examples/async-recursion/Cargo.toml
@@ -4,7 +4,8 @@ version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
-workspace = "../../"
+homepage.workspace = true
+repository.workspace = true
[dependencies]
gstd.workspace = true
diff --git a/examples/async-recursion/src/lib.rs b/examples/async-recursion/src/lib.rs
index 7d32db1717b..fbc08d47a0b 100644
--- a/examples/async-recursion/src/lib.rs
+++ b/examples/async-recursion/src/lib.rs
@@ -27,39 +27,4 @@ mod code {
pub use code::WASM_BINARY_OPT as WASM_BINARY;
#[cfg(not(feature = "std"))]
-mod wasm {
- use async_recursion::async_recursion;
- use gstd::{msg, prelude::*, ActorId};
-
- static mut DESTINATION: ActorId = ActorId::zero();
-
- #[no_mangle]
- extern "C" fn init() {
- let destination = msg::load().expect("Failed to load destination");
- unsafe { DESTINATION = destination };
- }
-
- /// Send message "PING" and wait for a reply, then recursively
- /// repeat with `val` decreased by reply len while `val` > reply len.
- #[async_recursion]
- async fn rec_func(val: i32) {
- let reply = msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0)
- .expect("Failed to send message")
- .await
- .expect("Received error reply");
-
- msg::send(msg::source(), val, 0).expect("Failed to send message");
-
- let reply_len = reply.len() as i32;
-
- if val - reply_len > 0 {
- rec_func(val - reply_len).await;
- }
- }
-
- #[gstd::async_main]
- async fn main() {
- let arg = msg::load().expect("Failed to load argument");
- rec_func(arg).await;
- }
-}
+mod wasm;
diff --git a/examples/async-recursion/src/wasm.rs b/examples/async-recursion/src/wasm.rs
new file mode 100644
index 00000000000..40648a95b08
--- /dev/null
+++ b/examples/async-recursion/src/wasm.rs
@@ -0,0 +1,52 @@
+// This file is part of Gear.
+
+// Copyright (C) 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 async_recursion::async_recursion;
+use gstd::{msg, prelude::*, ActorId};
+
+static mut DESTINATION: ActorId = ActorId::zero();
+
+#[no_mangle]
+extern "C" fn init() {
+ let destination = msg::load().expect("Failed to load destination");
+ unsafe { DESTINATION = destination };
+}
+
+/// Send message "PING" and wait for a reply, then recursively
+/// repeat with `val` decreased by reply len while `val` > reply len.
+#[async_recursion]
+async fn rec_func(val: i32) {
+ let reply = msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0)
+ .expect("Failed to send message")
+ .await
+ .expect("Received error reply");
+
+ msg::send(msg::source(), val, 0).expect("Failed to send message");
+
+ let reply_len = reply.len() as i32;
+
+ if val - reply_len > 0 {
+ rec_func(val - reply_len).await;
+ }
+}
+
+#[gstd::async_main]
+async fn main() {
+ let arg = msg::load().expect("Failed to load argument");
+ rec_func(arg).await;
+}
diff --git a/examples/async-signal-entry/Cargo.toml b/examples/async-signal-entry/Cargo.toml
index e60c5baaceb..66067c35b43 100644
--- a/examples/async-signal-entry/Cargo.toml
+++ b/examples/async-signal-entry/Cargo.toml
@@ -2,13 +2,14 @@
name = "demo-async-signal-entry"
version = "0.1.0"
authors.workspace = true
-edition = "2021"
-license = "GPL-3.0"
-workspace = "../../"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+repository.workspace = true
[dependencies]
-parity-scale-codec = { workspace = true, features = ["derive"] }
gstd.workspace = true
+parity-scale-codec.workspace = true
[build-dependencies]
gear-wasm-builder.workspace = true
@@ -16,8 +17,6 @@ gear-wasm-builder.workspace = true
[dev-dependencies]
gtest.workspace = true
-[lib]
-
[features]
debug = ["gstd/debug"]
std = ["parity-scale-codec/std"]
diff --git a/examples/async-signal-entry/src/lib.rs b/examples/async-signal-entry/src/lib.rs
index 921725da3ef..a6e3c737ab1 100644
--- a/examples/async-signal-entry/src/lib.rs
+++ b/examples/async-signal-entry/src/lib.rs
@@ -35,28 +35,4 @@ pub enum InitAction {
}
#[cfg(not(feature = "std"))]
-mod wasm {
- use super::*;
- use gstd::{exec, msg};
-
- #[gstd::async_init]
- async fn init() {
- let action = msg::load().unwrap();
- match action {
- InitAction::None => {}
- InitAction::Panic => {
- let _bytes = msg::send_for_reply(msg::source(), b"init", 0, 0)
- .unwrap()
- .await
- .unwrap();
- panic!();
- }
- }
- }
-
- #[gstd::async_main]
- async fn main() {
- msg::send(msg::source(), b"handle_signal", 0).unwrap();
- exec::wait();
- }
-}
+mod wasm;
diff --git a/examples/async-signal-entry/src/wasm.rs b/examples/async-signal-entry/src/wasm.rs
new file mode 100644
index 00000000000..a9192d60fd4
--- /dev/null
+++ b/examples/async-signal-entry/src/wasm.rs
@@ -0,0 +1,41 @@
+// This file is part of Gear.
+
+// Copyright (C) 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::InitAction;
+use gstd::{exec, msg};
+
+#[gstd::async_init]
+async fn init() {
+ let action = msg::load().unwrap();
+ match action {
+ InitAction::None => {}
+ InitAction::Panic => {
+ let _bytes = msg::send_for_reply(msg::source(), b"init", 0, 0)
+ .unwrap()
+ .await
+ .unwrap();
+ panic!();
+ }
+ }
+}
+
+#[gstd::async_main]
+async fn main() {
+ msg::send(msg::source(), b"handle_signal", 0).unwrap();
+ exec::wait();
+}
diff --git a/examples/async-tester/Cargo.toml b/examples/async-tester/Cargo.toml
index 114ec3a62a3..4e75128315a 100644
--- a/examples/async-tester/Cargo.toml
+++ b/examples/async-tester/Cargo.toml
@@ -2,13 +2,14 @@
name = "demo-async-tester"
version = "0.1.0"
authors.workspace = true
-edition = "2021"
-license = "GPL-3.0"
-workspace = "../../"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+repository.workspace = true
[dependencies]
-parity-scale-codec = { workspace = true, features = ["derive"] }
gstd.workspace = true
+parity-scale-codec.workspace = true
[build-dependencies]
gear-wasm-builder.workspace = true
diff --git a/examples/async-tester/src/lib.rs b/examples/async-tester/src/lib.rs
index 41822dd4176..d752d462007 100644
--- a/examples/async-tester/src/lib.rs
+++ b/examples/async-tester/src/lib.rs
@@ -10,9 +10,7 @@ mod code {
pub use code::WASM_BINARY_OPT as WASM_BINARY;
#[cfg(not(feature = "std"))]
-mod wasm {
- include! {"./code.rs"}
-}
+mod wasm;
#[derive(Clone, Copy, Debug, Decode, Encode, PartialEq, Eq)]
pub enum Kind {
diff --git a/examples/async-tester/src/code.rs b/examples/async-tester/src/wasm.rs
similarity index 91%
rename from examples/async-tester/src/code.rs
rename to examples/async-tester/src/wasm.rs
index 3cad9d5052f..fe32ce5f66e 100644
--- a/examples/async-tester/src/code.rs
+++ b/examples/async-tester/src/wasm.rs
@@ -36,14 +36,16 @@ async fn main() {
Kind::SendCommit => {
let handle = MessageHandle::init().expect("init message failed");
handle.push(&encoded_kind).expect("push payload failed");
- handle.commit_for_reply(msg::source(), 0, 0)
+ handle
+ .commit_for_reply(msg::source(), 0, 0)
.expect("send message failed")
.await
}
Kind::SendCommitWithGas(gas) => {
let handle = MessageHandle::init().expect("init message failed");
handle.push(&encoded_kind).expect("push payload failed");
- handle.commit_with_gas_for_reply(msg::source(), gas, 0, 0)
+ handle
+ .commit_with_gas_for_reply(msg::source(), gas, 0, 0)
.expect("send message failed")
.await
}
diff --git a/examples/async/Cargo.toml b/examples/async/Cargo.toml
index be01a96165c..45a6b2ddb94 100644
--- a/examples/async/Cargo.toml
+++ b/examples/async/Cargo.toml
@@ -4,11 +4,12 @@ version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
-workspace = "../../"
+homepage.workspace = true
+repository.workspace = true
[dependencies]
gstd.workspace = true
-parity-scale-codec = { workspace = true, features = ["derive"] }
+parity-scale-codec.workspace = true
[build-dependencies]
gear-wasm-builder.workspace = true
diff --git a/examples/async/src/lib.rs b/examples/async/src/lib.rs
index c193368d6d4..113fcda6c27 100644
--- a/examples/async/src/lib.rs
+++ b/examples/async/src/lib.rs
@@ -35,50 +35,4 @@ pub enum Command {
}
#[cfg(not(feature = "std"))]
-mod wasm {
- use crate::Command;
- use gstd::{msg, prelude::*, sync::Mutex, ActorId};
-
- static mut DESTINATION: ActorId = ActorId::zero();
- static MUTEX: Mutex = Mutex::new(0);
-
- #[no_mangle]
- extern "C" fn init() {
- let destination = msg::load().expect("Failed to load destination");
- unsafe { DESTINATION = destination };
- }
-
- async fn ping() -> Vec {
- msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0)
- .expect("Failed to send message")
- .await
- .expect("Received error reply")
- }
-
- #[gstd::async_main]
- async fn main() {
- let command = msg::load().expect("Failed to load command");
-
- match command {
- Command::Common => {
- let r1 = ping().await;
- let r2 = ping().await;
- let r3 = ping().await;
-
- assert_eq!(r1, b"PONG");
- assert_eq!(r1, r2);
- assert_eq!(r2, r3);
- }
- Command::Mutex => {
- let _val = MUTEX.lock().await;
-
- msg::send(msg::source(), msg::id(), 0).expect("Failed to send message");
- let r = ping().await;
-
- assert_eq!(r, b"PONG");
- }
- }
-
- msg::reply(msg::id(), 0).expect("Failed to send reply");
- }
-}
+mod wasm;
diff --git a/examples/async/src/wasm.rs b/examples/async/src/wasm.rs
new file mode 100644
index 00000000000..1b12121d16f
--- /dev/null
+++ b/examples/async/src/wasm.rs
@@ -0,0 +1,63 @@
+// This file is part of Gear.
+
+// Copyright (C) 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;
+use gstd::{msg, prelude::*, sync::Mutex, ActorId};
+
+static mut DESTINATION: ActorId = ActorId::zero();
+static MUTEX: Mutex = Mutex::new(0);
+
+#[no_mangle]
+extern "C" fn init() {
+ let destination = msg::load().expect("Failed to load destination");
+ unsafe { DESTINATION = destination };
+}
+
+async fn ping() -> Vec {
+ msg::send_bytes_for_reply(unsafe { DESTINATION }, "PING", 0, 0)
+ .expect("Failed to send message")
+ .await
+ .expect("Received error reply")
+}
+
+#[gstd::async_main]
+async fn main() {
+ let command = msg::load().expect("Failed to load command");
+
+ match command {
+ Command::Common => {
+ let r1 = ping().await;
+ let r2 = ping().await;
+ let r3 = ping().await;
+
+ assert_eq!(r1, b"PONG");
+ assert_eq!(r1, r2);
+ assert_eq!(r2, r3);
+ }
+ Command::Mutex => {
+ let _val = MUTEX.lock().await;
+
+ msg::send(msg::source(), msg::id(), 0).expect("Failed to send message");
+ let r = ping().await;
+
+ assert_eq!(r, b"PONG");
+ }
+ }
+
+ msg::reply(msg::id(), 0).expect("Failed to send reply");
+}
diff --git a/examples/autoreply/src/lib.rs b/examples/autoreply/src/lib.rs
index 90a59205f62..0c98a3a8179 100644
--- a/examples/autoreply/src/lib.rs
+++ b/examples/autoreply/src/lib.rs
@@ -18,6 +18,8 @@
#![no_std]
+extern crate alloc;
+
#[cfg(feature = "std")]
mod code {
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
@@ -31,6 +33,7 @@ mod wasm;
#[cfg(test)]
mod tests {
+ use alloc::vec::Vec;
use gstd::ActorId;
use gtest::{Program, System};
@@ -58,7 +61,9 @@ mod tests {
assert!(!res.main_failed());
// Check whether the auto-reply was received
- let reply_received: bool = prog2.read_state().expect("Failed to read state");
+ let reply_received: bool = prog2
+ .read_state(Vec::::default())
+ .expect("Failed to read state");
assert!(reply_received);
}
}
diff --git a/examples/calc-hash/Cargo.toml b/examples/calc-hash/Cargo.toml
index b61fb33ecf3..41a8bd8947a 100644
--- a/examples/calc-hash/Cargo.toml
+++ b/examples/calc-hash/Cargo.toml
@@ -2,12 +2,13 @@
name = "demo-calc-hash"
version = "0.1.0"
authors.workspace = true
-edition = "2021"
-license = "GPL-3.0"
-workspace = "../../"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+repository.workspace = true
[dependencies]
-parity-scale-codec = { workspace = true, features = ["derive"]}
+parity-scale-codec.workspace = true
sha2 = { version = "0.10.6", default-features = false }
[build-dependencies]
diff --git a/examples/calc-hash/in-one-block/Cargo.toml b/examples/calc-hash/in-one-block/Cargo.toml
index fcd0da368bb..7192e5baca9 100644
--- a/examples/calc-hash/in-one-block/Cargo.toml
+++ b/examples/calc-hash/in-one-block/Cargo.toml
@@ -2,13 +2,14 @@
name = "demo-calc-hash-in-one-block"
version = "0.1.0"
authors.workspace = true
-edition = "2021"
-license = "GPL-3.0"
-workspace = "../../../"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+repository.workspace = true
[dependencies]
-parity-scale-codec = { workspace = true, features = ["derive"]}
gstd.workspace = true
+parity-scale-codec.workspace = true
shared = { path = "..", package = "demo-calc-hash" }
[build-dependencies]
diff --git a/examples/calc-hash/in-one-block/src/lib.rs b/examples/calc-hash/in-one-block/src/lib.rs
index fafd39d6b22..1d609b29753 100644
--- a/examples/calc-hash/in-one-block/src/lib.rs
+++ b/examples/calc-hash/in-one-block/src/lib.rs
@@ -27,9 +27,7 @@ mod code {
pub use code::WASM_BINARY_OPT as WASM_BINARY;
#[cfg(not(feature = "std"))]
-mod wasm {
- include! {"./code.rs"}
-}
+mod wasm;
/// Package with expected
#[derive(Encode, Decode)]
diff --git a/examples/calc-hash/in-one-block/src/code.rs b/examples/calc-hash/in-one-block/src/wasm.rs
similarity index 100%
rename from examples/calc-hash/in-one-block/src/code.rs
rename to examples/calc-hash/in-one-block/src/wasm.rs
diff --git a/examples/calc-hash/over-blocks/Cargo.toml b/examples/calc-hash/over-blocks/Cargo.toml
index f3795a7d0b0..5d93098fe37 100644
--- a/examples/calc-hash/over-blocks/Cargo.toml
+++ b/examples/calc-hash/over-blocks/Cargo.toml
@@ -2,13 +2,14 @@
name = "demo-calc-hash-over-blocks"
version = "0.1.0"
authors.workspace = true
-edition = "2021"
-license = "GPL-3.0"
-workspace = "../../../"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+repository.workspace = true
[dependencies]
-parity-scale-codec = { workspace = true, features = ["derive"]}
gstd.workspace = true
+parity-scale-codec.workspace = true
shared = { path = "../", package = "demo-calc-hash" }
[build-dependencies]
diff --git a/examples/calc-hash/over-blocks/src/lib.rs b/examples/calc-hash/over-blocks/src/lib.rs
index 7c0054dd056..ab716fcd2da 100644
--- a/examples/calc-hash/over-blocks/src/lib.rs
+++ b/examples/calc-hash/over-blocks/src/lib.rs
@@ -29,9 +29,7 @@ mod code {
pub use code::WASM_BINARY_OPT as WASM_BINARY;
#[cfg(not(feature = "std"))]
-mod wasm {
- include! {"./code.rs"}
-}
+mod wasm;
/// Program methods.
#[derive(Debug, Encode, Decode)]
diff --git a/examples/calc-hash/over-blocks/src/code.rs b/examples/calc-hash/over-blocks/src/wasm.rs
similarity index 96%
rename from examples/calc-hash/over-blocks/src/code.rs
rename to examples/calc-hash/over-blocks/src/wasm.rs
index 2d304ce3493..2cdc19f8526 100644
--- a/examples/calc-hash/over-blocks/src/code.rs
+++ b/examples/calc-hash/over-blocks/src/wasm.rs
@@ -15,7 +15,9 @@ extern "C" fn handle() {
match method {
Method::Start { expected, id, src } => {
- registry.entry(id).or_insert_with(|| Package::new(expected, src));
+ registry
+ .entry(id)
+ .or_insert_with(|| Package::new(expected, src));
let pkg = registry.get(&id).expect("Calculation not found.");
diff --git a/examples/compose/Cargo.toml b/examples/compose/Cargo.toml
index ed7edbd9bda..bd4a1891822 100644
--- a/examples/compose/Cargo.toml
+++ b/examples/compose/Cargo.toml
@@ -2,19 +2,18 @@
name = "demo-compose"
version = "0.1.0"
authors.workspace = true
-edition = "2021"
-license = "GPL-3.0"
-workspace = "../../"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+repository.workspace = true
[dependencies]
gstd.workspace = true
-hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
+hex.workspace = true
[build-dependencies]
gear-wasm-builder.workspace = true
-[lib]
-
[features]
debug = ["gstd/debug"]
std = []
diff --git a/examples/compose/src/lib.rs b/examples/compose/src/lib.rs
index 442e6d7ea0f..cc2e84c6fc0 100644
--- a/examples/compose/src/lib.rs
+++ b/examples/compose/src/lib.rs
@@ -34,111 +34,4 @@ mod code {
pub use code::WASM_BINARY_OPT as WASM_BINARY;
#[cfg(not(feature = "std"))]
-mod wasm {
- extern crate alloc;
-
- use gstd::{debug, exec, msg, prelude::*, ActorId};
-
- static mut STATE: State = State {
- contract_a: Program {
- handle: ActorId::new([0u8; 32]),
- },
- contract_b: Program {
- handle: ActorId::new([0u8; 32]),
- },
- };
-
- struct State {
- contract_a: Program,
- contract_b: Program,
- }
-
- impl State {
- fn new(actor_a: impl Into, actor_b: impl Into) -> Self {
- Self {
- contract_a: Program::new(actor_a),
- contract_b: Program::new(actor_b),
- }
- }
-
- async fn compose(&mut self, input: Vec) -> Result, &'static str> {
- debug!(
- "[0x{} compose::compose] Composing programs 0x{} and 0x{} on input {input:?}",
- hex::encode(exec::program_id()),
- hex::encode(self.contract_a.handle),
- hex::encode(self.contract_b.handle),
- );
- debug!(
- "[0x{} compose::compose] Calling contract #1 at 0x{}",
- hex::encode(exec::program_id()),
- hex::encode(self.contract_a.handle)
- );
- let output_a = self.contract_a.call(input).await?;
- debug!(
- "[0x{} compose::compose] Calling contract #2 at 0x{}",
- hex::encode(exec::program_id()),
- hex::encode(self.contract_b.handle)
- );
- let output = self.contract_b.call(output_a).await?;
- debug!(
- "[0x{} compose::compose] Composition output: {output:?}",
- hex::encode(exec::program_id()),
- );
-
- Ok(output)
- }
- }
-
- #[derive(Eq, Ord, PartialEq, PartialOrd)]
- struct Program {
- handle: ActorId,
- }
-
- impl Program {
- fn new(handle: impl Into) -> Self {
- Self {
- handle: handle.into(),
- }
- }
-
- async fn call(&self, input: Vec) -> Result, &'static str> {
- let reply_bytes = msg::send_bytes_for_reply(self.handle, &input[..], 0, 0)
- .expect("Error sending message")
- .await
- .map_err(|_| "Error in async message processing")?;
- debug!(
- "[0x{} compose::Program::call] Received reply from remote contract: {}",
- hex::encode(exec::program_id()),
- hex::encode(&reply_bytes)
- );
-
- Ok(reply_bytes)
- }
- }
-
- #[gstd::async_main]
- async fn main() {
- let input = msg::load_bytes().expect("Failed to load payload bytes");
- debug!(
- "[0x{} compose::handle] input = {input:?}, gas_available = {}",
- hex::encode(exec::program_id()),
- exec::gas_available()
- );
-
- if let Ok(outcome) = (unsafe { STATE.compose(input) }).await {
- debug!(
- "[0x{} compose::handle] Composition output: {outcome:?}",
- hex::encode(exec::program_id()),
- );
- msg::reply(outcome, 0).unwrap();
- }
- }
-
- #[no_mangle]
- extern "C" fn init() {
- let (contract_a, contract_b): (ActorId, ActorId) =
- msg::load().expect("Expecting two contract addresses");
- unsafe { STATE = State::new(contract_a, contract_b) };
- msg::reply_bytes([], 0).unwrap();
- }
-}
+mod wasm;
diff --git a/examples/compose/src/wasm.rs b/examples/compose/src/wasm.rs
new file mode 100644
index 00000000000..a9c9c70a9a1
--- /dev/null
+++ b/examples/compose/src/wasm.rs
@@ -0,0 +1,131 @@
+// This file is part of Gear.
+
+// Copyright (C) 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 .
+
+//! This contract recursively composes itself with another contract (the other contract
+//! being applied to the input data first): `c(f) = (c(f) . f) x`.
+//! Every call to the auto_composer contract increments the internal `ITER` counter.
+//! As soon as the counter reaches the `MAX_ITER`, the recursion stops.
+//! Effectively, this procedure executes a composition of `MAX_ITER` contracts `f`
+//! where the output of the previous call is fed to the input of the next call.
+
+extern crate alloc;
+
+use gstd::{debug, exec, msg, prelude::*, ActorId};
+
+static mut STATE: State = State {
+ contract_a: Program {
+ handle: ActorId::new([0u8; 32]),
+ },
+ contract_b: Program {
+ handle: ActorId::new([0u8; 32]),
+ },
+};
+
+struct State {
+ contract_a: Program,
+ contract_b: Program,
+}
+
+impl State {
+ fn new(actor_a: impl Into, actor_b: impl Into) -> Self {
+ Self {
+ contract_a: Program::new(actor_a),
+ contract_b: Program::new(actor_b),
+ }
+ }
+
+ async fn compose(&mut self, input: Vec) -> Result, &'static str> {
+ debug!(
+ "[0x{} compose::compose] Composing programs 0x{} and 0x{} on input {input:?}",
+ hex::encode(exec::program_id()),
+ hex::encode(self.contract_a.handle),
+ hex::encode(self.contract_b.handle),
+ );
+ debug!(
+ "[0x{} compose::compose] Calling contract #1 at 0x{}",
+ hex::encode(exec::program_id()),
+ hex::encode(self.contract_a.handle)
+ );
+ let output_a = self.contract_a.call(input).await?;
+ debug!(
+ "[0x{} compose::compose] Calling contract #2 at 0x{}",
+ hex::encode(exec::program_id()),
+ hex::encode(self.contract_b.handle)
+ );
+ let output = self.contract_b.call(output_a).await?;
+ debug!(
+ "[0x{} compose::compose] Composition output: {output:?}",
+ hex::encode(exec::program_id()),
+ );
+
+ Ok(output)
+ }
+}
+
+#[derive(Eq, Ord, PartialEq, PartialOrd)]
+struct Program {
+ handle: ActorId,
+}
+
+impl Program {
+ fn new(handle: impl Into) -> Self {
+ Self {
+ handle: handle.into(),
+ }
+ }
+
+ async fn call(&self, input: Vec) -> Result, &'static str> {
+ let reply_bytes = msg::send_bytes_for_reply(self.handle, &input[..], 0, 0)
+ .expect("Error sending message")
+ .await
+ .map_err(|_| "Error in async message processing")?;
+ debug!(
+ "[0x{} compose::Program::call] Received reply from remote contract: {}",
+ hex::encode(exec::program_id()),
+ hex::encode(&reply_bytes)
+ );
+
+ Ok(reply_bytes)
+ }
+}
+
+#[gstd::async_main]
+async fn main() {
+ let input = msg::load_bytes().expect("Failed to load payload bytes");
+ debug!(
+ "[0x{} compose::handle] input = {input:?}, gas_available = {}",
+ hex::encode(exec::program_id()),
+ exec::gas_available()
+ );
+
+ if let Ok(outcome) = (unsafe { STATE.compose(input) }).await {
+ debug!(
+ "[0x{} compose::handle] Composition output: {outcome:?}",
+ hex::encode(exec::program_id()),
+ );
+ msg::reply(outcome, 0).unwrap();
+ }
+}
+
+#[no_mangle]
+extern "C" fn init() {
+ let (contract_a, contract_b): (ActorId, ActorId) =
+ msg::load().expect("Expecting two contract addresses");
+ unsafe { STATE = State::new(contract_a, contract_b) };
+ msg::reply_bytes([], 0).unwrap();
+}
diff --git a/examples/constructor/Cargo.toml b/examples/constructor/Cargo.toml
index 383ed6e29f7..093e3a2b005 100644
--- a/examples/constructor/Cargo.toml
+++ b/examples/constructor/Cargo.toml
@@ -4,13 +4,14 @@ version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
-workspace = "../../"
+homepage.workspace = true
+repository.workspace = true
[dependencies]
gcore.workspace = true
gstd.workspace = true
-parity-scale-codec = { workspace = true, features = ["derive"] }
hex.workspace = true
+parity-scale-codec.workspace = true
[build-dependencies]
gear-wasm-builder.workspace = true
diff --git a/examples/custom/Cargo.toml b/examples/custom/Cargo.toml
index 164f8415084..bcf618a3c63 100644
--- a/examples/custom/Cargo.toml
+++ b/examples/custom/Cargo.toml
@@ -4,7 +4,8 @@ version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
-workspace = "../../"
+homepage.workspace = true
+repository.workspace = true
[dependencies]
gstd.workspace = true
diff --git a/examples/delayed-sender/Cargo.toml b/examples/delayed-sender/Cargo.toml
index 7c386c1b22a..199aaa4efa4 100644
--- a/examples/delayed-sender/Cargo.toml
+++ b/examples/delayed-sender/Cargo.toml
@@ -2,9 +2,10 @@
name = "demo-delayed-sender"
version = "0.1.0"
authors.workspace = true
-edition = "2021"
-license = "GPL-3.0"
-workspace = "../../"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+repository.workspace = true
[dependencies]
gstd.workspace = true
diff --git a/examples/delayed-sender/src/lib.rs b/examples/delayed-sender/src/lib.rs
index 1175ebd0d91..a2bb360b9a4 100644
--- a/examples/delayed-sender/src/lib.rs
+++ b/examples/delayed-sender/src/lib.rs
@@ -27,6 +27,4 @@ mod code {
pub use code::WASM_BINARY_OPT as WASM_BINARY;
#[cfg(not(feature = "wasm-wrapper"))]
-mod wasm {
- include! {"./code.rs"}
-}
+mod wasm;
diff --git a/examples/delayed-sender/src/code.rs b/examples/delayed-sender/src/wasm.rs
similarity index 89%
rename from examples/delayed-sender/src/code.rs
rename to examples/delayed-sender/src/wasm.rs
index c1c1c2d61f8..395f2e7e03e 100644
--- a/examples/delayed-sender/src/code.rs
+++ b/examples/delayed-sender/src/wasm.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 gstd::{msg, MessageId, exec};
+use gstd::{exec, msg, MessageId};
static mut MID: Option = None;
static mut DONE: bool = false;
@@ -33,11 +33,15 @@ extern "C" fn handle() {
if let Some(message_id) = unsafe { MID.take() } {
let delay: u32 = msg::load().unwrap();
- unsafe { DONE = true; }
+ unsafe {
+ DONE = true;
+ }
exec::wake_delayed(message_id, delay).expect("Failed to wake message");
} else if unsafe { !DONE } {
- unsafe { MID = Some(msg::id()); }
+ unsafe {
+ MID = Some(msg::id());
+ }
exec::wait();
}
diff --git a/examples/distributor/Cargo.toml b/examples/distributor/Cargo.toml
index 00d2f03613f..73887d6fd87 100644
--- a/examples/distributor/Cargo.toml
+++ b/examples/distributor/Cargo.toml
@@ -2,13 +2,14 @@
name = "demo-distributor"
version = "0.1.0"
authors.workspace = true
-edition = "2021"
-license = "GPL-3.0"
-workspace = "../../"
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+repository.workspace = true
[dependencies]
-parity-scale-codec = { workspace = true, features = ["derive"] }
gstd.workspace = true
+parity-scale-codec.workspace = true
[build-dependencies]
gear-wasm-builder.workspace = true
@@ -17,8 +18,6 @@ gear-wasm-builder.workspace = true
gstd = { workspace = true, features = ["debug"] }
gtest.workspace = true
-[lib]
-
[features]
debug = ["gstd/debug"]
std = ["parity-scale-codec/std"]
diff --git a/examples/distributor/src/lib.rs b/examples/distributor/src/lib.rs
index 0508f3a4d2c..53fd344ee84 100644
--- a/examples/distributor/src/lib.rs
+++ b/examples/distributor/src/lib.rs
@@ -52,174 +52,7 @@ struct Program {
}
#[cfg(not(feature = "std"))]
-mod wasm {
- use super::*;
-
- use alloc::collections::BTreeSet;
- use core::future::Future;
- use gstd::{debug, msg, sync::Mutex};
-
- static mut STATE: Option = None;
-
- struct ProgramState {
- nodes: Mutex>,
- amount: u64,
- }
-
- impl Default for ProgramState {
- fn default() -> Self {
- Self {
- nodes: Mutex::new(BTreeSet::default()),
- amount: 0,
- }
- }
- }
-
- impl Program {
- fn new(handle: impl Into) -> Self {
- Self {
- handle: handle.into(),
- }
- }
-
- fn do_request(
- &self,
- request: Req,
- ) -> impl Future