diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 190dfc4f524..7dc8cfc4c84 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,7 +66,7 @@ jobs: run: ./scripts/gear.sh init cargo - name: "Build: Gear" - run: ./scripts/gear.sh build gear --locked --release + run: ./scripts/gear.sh build gear -F gear-cli/dev --locked --release - name: "Build fuzzer" run: ./scripts/gear.sh build fuzz --locked --release @@ -96,7 +96,7 @@ jobs: - name: "Test: Runtime benchmarks and benchmark tests work" run: | - cargo build -p gear-cli --release --features=runtime-benchmarks,runtime-benchmarks-checkers + cargo build -p gear-cli --release --features=dev,runtime-benchmarks,runtime-benchmarks-checkers # check that perf benchmarks works. `--steps=20` need to test, that benchmarks works for different input number. ./target/release/gear benchmark pallet --chain=dev --pallet=pallet_gear --steps=20 --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 # check that read_big_state benchmarks works @@ -111,11 +111,11 @@ jobs: - name: "Test: `try-runtime` feature tests" run: | - cargo test -p "pallet-*" --features try-runtime --release --locked + cargo test -p "pallet-*" --features try-runtime,dev --release --locked - name: "Test: Try runtime migrations" run: | - cargo build -p gear-cli --features try-runtime --release --locked + cargo build -p gear-cli --features try-runtime,dev --release --locked ./target/release/gear try-runtime --runtime ./target/release/wbuild/gear-runtime/gear_runtime.wasm on-runtime-upgrade --checks live --uri wss://rpc-private-testnet.gear-tech.io:443 env: RUST_LOG: info diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c69b1afdf27..5d0588a862e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -43,7 +43,7 @@ jobs: run: ./scripts/gear.sh clippy examples --all-targets --locked - name: "Test: Doc tests" - run: ./scripts/gear.sh test doc + run: ./scripts/gear.sh test docs - name: "Test: Changes in gsdk generated code" run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5c62aa29c58..07d09151710 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,46 +49,67 @@ jobs: needs: prepare runs-on: [kuberunner] steps: - - name: Checkout + - name: "Actions: Checkout" uses: actions/checkout@v4 - - name: Set cargo path - run: echo "/tmp/cargo/bin" >> $GITHUB_PATH + - name: "Environment: Cargo path" + run: > + echo "/tmp/cargo/bin" >> $GITHUB_PATH - name: "Install: Rust toolchain" uses: dsherret/rust-toolchain-file@v1 - - name: Install build deps + - name: "Install: Build dependencies" run: | sudo apt update -y sudo apt install -y git clang curl libssl-dev llvm libudev-dev cmake protobuf-compiler wget bzip2 - - name: Build wasm-proc + - name: "Environment: Export versions" + run: | + export GEAR_SPEC="$(cat runtime/gear/src/lib.rs | grep "spec_version: " | awk -F " " '{print substr($2, 1, length($2)-1)}')" + export VARA_SPEC="$(cat runtime/vara/src/lib.rs | grep "spec_version: " | awk -F " " '{print substr($2, 1, length($2)-1)}')" + + - name: "Artifact: Make `artifact` directory" + run: > + mkdir -p artifact + + - name: "Build: `wasm-proc`" run: | cargo build -p wasm-proc --release cp -vf target/release/wasm-proc ./ - - name: Build binaries + - name: "Build: Production `gear-cli`" run: > cargo build -p gear-cli --profile production - - name: Test runtimes + - name: "Test: Production runtimes" run: | ./wasm-proc --check-runtime-imports target/production/wbuild/gear-runtime/gear_runtime.wasm ./wasm-proc --check-runtime-imports target/production/wbuild/vara-runtime/vara_runtime.wasm - - name: Prepare artifacts + - name: "Artifact: Production binaries" run: | - mkdir -p artifact - cp target/production/wbuild/gear-runtime/gear_runtime.compact.compressed.wasm artifact/ - cp target/production/wbuild/gear-runtime/gear_runtime.compact.wasm artifact/ - cp target/production/wbuild/gear-runtime/gear_runtime.wasm artifact/ - cp target/production/wbuild/vara-runtime/vara_runtime.compact.compressed.wasm artifact/ - cp target/production/wbuild/vara-runtime/vara_runtime.compact.wasm artifact/ - cp target/production/wbuild/vara-runtime/vara_runtime.wasm artifact/ - cp target/production/gear artifact/ + cp target/production/wbuild/gear-runtime/gear_runtime.compact.compressed.wasm "artifact/gear_v$GEAR_SPEC.wasm" + cp target/production/wbuild/vara-runtime/vara_runtime.compact.compressed.wasm "artifact/vara_v$VARA_SPEC.wasm" + cp target/production/gear artifact/gear strip artifact/gear || true + - name: "Build: Development `gear-cli`" + run: > + cargo build -p gear-cli --profile production -F dev + + - name: "Test: Development runtimes" + run: | + ./wasm-proc --check-runtime-imports target/production/wbuild/gear-runtime/gear_runtime.wasm + ./wasm-proc --check-runtime-imports target/production/wbuild/vara-runtime/vara_runtime.wasm + + - name: "Artifact: Development binaries" + run: | + cp target/production/wbuild/gear-runtime/gear_runtime.compact.compressed.wasm "artifact/dev_gear_v$GEAR_SPEC.wasm" + cp target/production/wbuild/vara-runtime/vara_runtime.compact.compressed.wasm "artifact/dev_vara_v$VARA_SPEC.wasm" + cp target/production/gear artifact/dev-gear + strip artifact/dev-gear || true + - name: Publish uses: softprops/action-gh-release@v1 with: diff --git a/.github/workflows/test-measurements.yaml b/.github/workflows/test-measurements.yaml index 1368cadb136..b9c3a16a657 100644 --- a/.github/workflows/test-measurements.yaml +++ b/.github/workflows/test-measurements.yaml @@ -42,7 +42,7 @@ jobs: tar -xf /cache/check_cargo_registry_${{ github.ref_name }}.tar -C / - name: "Build: Gear" - run: ./scripts/gear.sh build gear --release --locked --features=runtime-benchmarks,lazy-pages + run: ./scripts/gear.sh build gear --release --locked --features=dev,runtime-benchmarks,lazy-pages - name: "Collect: Gear workspace tests" run: | diff --git a/Cargo.lock b/Cargo.lock index 2500a3e11f1..76d3ff7a82e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1903,6 +1903,7 @@ dependencies = [ name = "demo-constructor" version = "0.1.0" dependencies = [ + "gcore", "gear-wasm-builder", "gstd", "hex", @@ -2314,6 +2315,7 @@ version = "0.1.0" dependencies = [ "demo-waiter", "futures", + "gcore", "gear-core", "gear-wasm-builder", "gstd", @@ -3631,14 +3633,14 @@ dependencies = [ [[package]] name = "galloc" -version = "0.3.4" +version = "1.0.0" dependencies = [ "dlmalloc", ] [[package]] name = "gcli" -version = "0.3.4" +version = "1.0.0" dependencies = [ "anyhow", "base64 0.21.3", @@ -3677,7 +3679,7 @@ dependencies = [ [[package]] name = "gclient" -version = "0.3.4" +version = "1.0.0" dependencies = [ "anyhow", "async-trait", @@ -3721,7 +3723,7 @@ dependencies = [ [[package]] name = "gcore" -version = "0.3.4" +version = "1.0.0" dependencies = [ "galloc", "gear-core-errors", @@ -3734,7 +3736,7 @@ dependencies = [ [[package]] name = "gear-authorship" -version = "0.1.0" +version = "1.0.0" dependencies = [ "demo-mul-by-const", "env_logger", @@ -3745,6 +3747,7 @@ dependencies = [ "gear-common", "gear-node-testing", "gear-runtime-primitives", + "gear-service", "log", "pallet-balances", "pallet-gear", @@ -3776,7 +3779,7 @@ dependencies = [ [[package]] name = "gear-backend-codegen" -version = "0.3.4" +version = "1.0.0" dependencies = [ "proc-macro2", "quote", @@ -3785,7 +3788,7 @@ dependencies = [ [[package]] name = "gear-backend-common" -version = "0.3.4" +version = "1.0.0" dependencies = [ "actor-system-error", "blake2-rfc", @@ -3844,7 +3847,7 @@ dependencies = [ [[package]] name = "gear-cli" -version = "0.3.4" +version = "1.0.0" dependencies = [ "clap 4.4.2", "frame-benchmarking", @@ -3878,7 +3881,7 @@ dependencies = [ [[package]] name = "gear-common" -version = "0.3.4" +version = "1.0.0" dependencies = [ "derive_more", "enum-iterator 1.4.1", @@ -3906,7 +3909,7 @@ dependencies = [ [[package]] name = "gear-common-codegen" -version = "0.3.4" +version = "1.0.0" dependencies = [ "quote", "syn 2.0.31", @@ -3914,7 +3917,7 @@ dependencies = [ [[package]] name = "gear-core" -version = "0.3.4" +version = "1.0.0" dependencies = [ "blake2-rfc", "byteorder", @@ -3936,7 +3939,7 @@ dependencies = [ [[package]] name = "gear-core-errors" -version = "0.3.4" +version = "1.0.0" dependencies = [ "derive_more", "enum-iterator 1.4.1", @@ -3945,7 +3948,7 @@ dependencies = [ [[package]] name = "gear-core-processor" -version = "0.3.4" +version = "1.0.0" dependencies = [ "actor-system-error", "derive_more", @@ -3963,7 +3966,7 @@ dependencies = [ [[package]] name = "gear-lazy-pages" -version = "0.1.0" +version = "1.0.0" dependencies = [ "cfg-if", "derive_more", @@ -4003,7 +4006,7 @@ dependencies = [ [[package]] name = "gear-node-loader" -version = "0.3.4" +version = "1.0.0" dependencies = [ "anyhow", "arbitrary", @@ -4035,7 +4038,7 @@ dependencies = [ [[package]] name = "gear-node-testing" -version = "0.1.0" +version = "1.0.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -4046,6 +4049,7 @@ dependencies = [ "gear-runtime", "gear-runtime-interface", "gear-runtime-primitives", + "gear-service", "log", "pallet-gear-rpc-runtime-api", "parity-scale-codec", @@ -4103,7 +4107,7 @@ dependencies = [ [[package]] name = "gear-runtime" -version = "0.1.0" +version = "1.0.0" dependencies = [ "const-str", "frame-benchmarking", @@ -4163,7 +4167,7 @@ dependencies = [ [[package]] name = "gear-runtime-common" -version = "0.1.0" +version = "1.0.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -4189,7 +4193,7 @@ dependencies = [ [[package]] name = "gear-runtime-interface" -version = "0.1.0" +version = "1.0.0" dependencies = [ "byteorder", "derive_more", @@ -4211,7 +4215,7 @@ dependencies = [ [[package]] name = "gear-runtime-primitives" -version = "0.1.0" +version = "1.0.0" 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)", @@ -4264,7 +4268,7 @@ dependencies = [ [[package]] name = "gear-service" -version = "0.1.0" +version = "1.0.0" dependencies = [ "frame-benchmarking", "frame-benchmarking-cli", @@ -4343,7 +4347,7 @@ dependencies = [ [[package]] name = "gear-stack-buffer" -version = "0.3.4" +version = "1.0.0" dependencies = [ "cc", ] @@ -4436,7 +4440,7 @@ dependencies = [ [[package]] name = "gear-wasm-instrument" -version = "0.3.4" +version = "1.0.0" dependencies = [ "enum-iterator 1.4.1", "gear-backend-common", @@ -4606,7 +4610,7 @@ dependencies = [ [[package]] name = "gmeta" -version = "0.3.4" +version = "1.0.0" dependencies = [ "blake2-rfc", "derive_more", @@ -4620,7 +4624,7 @@ dependencies = [ [[package]] name = "gmeta-codegen" -version = "0.3.4" +version = "1.0.0" dependencies = [ "gmeta", "gstd", @@ -4644,7 +4648,7 @@ dependencies = [ [[package]] name = "gsdk" -version = "0.3.4" +version = "1.0.0" dependencies = [ "anyhow", "base64 0.21.3", @@ -4695,7 +4699,7 @@ dependencies = [ [[package]] name = "gsdk-codegen" -version = "0.3.4" +version = "1.0.0" dependencies = [ "proc-macro2", "quote", @@ -4704,7 +4708,7 @@ dependencies = [ [[package]] name = "gstd" -version = "0.3.4" +version = "1.0.0" dependencies = [ "bs58", "futures", @@ -4733,7 +4737,7 @@ dependencies = [ [[package]] name = "gsys" -version = "0.3.4" +version = "1.0.0" [[package]] name = "gtest" @@ -7118,37 +7122,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "pallet-airdrop" -version = "1.0.0" -dependencies = [ - "env_logger", - "frame-benchmarking", - "frame-support", - "frame-support-test", - "frame-system", - "gear-common", - "log", - "pallet-authorship", - "pallet-balances", - "pallet-gear", - "pallet-gear-bank", - "pallet-gear-gas", - "pallet-gear-messenger", - "pallet-gear-program", - "pallet-gear-scheduler", - "pallet-sudo", - "pallet-timestamp", - "pallet-vesting", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core 7.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", - "sp-io 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)", - "sp-std 5.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", -] - [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" @@ -7330,7 +7303,7 @@ dependencies = [ [[package]] name = "pallet-gear" -version = "2.0.0" +version = "1.0.0" dependencies = [ "blake2-rfc", "demo-async", @@ -7446,7 +7419,7 @@ dependencies = [ [[package]] name = "pallet-gear-debug" -version = "2.0.0" +version = "1.0.0" dependencies = [ "demo-vec", "env_logger", @@ -7483,7 +7456,7 @@ dependencies = [ [[package]] name = "pallet-gear-gas" -version = "2.0.0" +version = "1.0.0" dependencies = [ "env_logger", "frame-benchmarking", @@ -7536,7 +7509,7 @@ dependencies = [ [[package]] name = "pallet-gear-payment" -version = "0.1.0" +version = "1.0.0" dependencies = [ "env_logger", "frame-benchmarking", @@ -7570,7 +7543,7 @@ dependencies = [ [[package]] name = "pallet-gear-proc-macro" -version = "2.0.0" +version = "1.0.0" dependencies = [ "proc-macro2", "quote", @@ -7579,7 +7552,7 @@ dependencies = [ [[package]] name = "pallet-gear-program" -version = "2.0.0" +version = "1.0.0" dependencies = [ "frame-support", "frame-system", @@ -7604,7 +7577,7 @@ dependencies = [ [[package]] name = "pallet-gear-rpc" -version = "2.0.0" +version = "1.0.0" dependencies = [ "gear-common", "gear-core", @@ -7620,7 +7593,7 @@ dependencies = [ [[package]] name = "pallet-gear-rpc-runtime-api" -version = "2.0.0" +version = "1.0.0" dependencies = [ "pallet-gear", "sp-api", @@ -13492,7 +13465,7 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "vara-runtime" -version = "0.1.0" +version = "1.0.0" dependencies = [ "const-str", "env_logger", @@ -13511,7 +13484,6 @@ dependencies = [ "gear-runtime-primitives", "hex-literal", "log", - "pallet-airdrop", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", diff --git a/Cargo.toml b/Cargo.toml index 6dbd8172a62..1b581dac2b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [workspace.package] -version = "0.3.4" +version = "1.0.0" authors = ["Gear Technologies"] edition = "2021" license = "GPL-3.0" -homepage = "https://www.gear-tech.io" +homepage = "https://gear-tech.io" repository = "https://github.com/gear-tech/gear" [workspace] @@ -221,21 +221,20 @@ 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" } -pallet-airdrop = { path = "pallets/airdrop", default-features = false } 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 } pallet-gear-messenger = { path = "pallets/gear-messenger", default-features = false } -pallet-gear-payment = { version = "0.1.0", path = "pallets/payment", default-features = false } +pallet-gear-payment = { path = "pallets/payment", default-features = false } pallet-gear-program = { path = "pallets/gear-program", default-features = false } pallet-gear-rpc = { path = "pallets/gear/rpc" } -pallet-gear-rpc-runtime-api = { version = "2.0.0", path = "pallets/gear/rpc/runtime-api", default-features = false } +pallet-gear-rpc-runtime-api = { path = "pallets/gear/rpc/runtime-api", default-features = false } pallet-gear-scheduler = { path = "pallets/gear-scheduler", default-features = false } -pallet-gear-staking-rewards = { version = "1.0.0", path = "pallets/staking-rewards", default-features = false } -pallet-gear-voucher = { version = "1.0.0", path = "pallets/gear-voucher", default-features = false } -pallet-gear-bank = { version = "1.0.0", path = "pallets/gear-bank", default-features = false } +pallet-gear-staking-rewards = { path = "pallets/staking-rewards", default-features = false } +pallet-gear-voucher = { path = "pallets/gear-voucher", default-features = false } +pallet-gear-bank = { path = "pallets/gear-bank", default-features = false } runtime-common = { package = "gear-runtime-common", path = "runtime/common", default-features = false } -runtime-primitives = { package = "gear-runtime-primitives", path = "runtime/primitives", version = "0.1.0", default-features = false } +runtime-primitives = { package = "gear-runtime-primitives", path = "runtime/primitives", default-features = false } service = { package = "gear-service", path = "node/service", default-features = false } testing = { package = "gear-node-testing", path = "node/testing" } vara-runtime = { path = "runtime/vara" } @@ -372,7 +371,7 @@ 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"] } @@ -380,7 +379,7 @@ 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" } @@ -397,7 +396,7 @@ 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" } @@ -405,7 +404,7 @@ 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" } diff --git a/Makefile b/Makefile index 0a253551404..23d3f966ed4 100644 --- a/Makefile +++ b/Makefile @@ -46,11 +46,11 @@ examples-proc: wasm-proc-release .PHONY: node node: - @ ./scripts/gear.sh build node + @ ./scripts/gear.sh build node -F dev .PHONY: node-release node-release: - @ ./scripts/gear.sh build node --release + @ ./scripts/gear.sh build node -F dev --release .PHONY: vara vara: @@ -191,7 +191,7 @@ test-release: test-gear-release .PHONY: test-doc test-doc: - @ ./scripts/gear.sh test doc + @ ./scripts/gear.sh test docs .PHONY: test-gear test-gear: #\ diff --git a/common/src/lib.rs b/common/src/lib.rs index 3d4873bb6a2..64f47fd4aa4 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -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; @@ -228,18 +231,6 @@ impl Program { }) ) } - - pub fn is_uninitialized(&self) -> Option { - if let Program::Active(ActiveProgram { - state: ProgramState::Uninitialized { message_id }, - .. - }) = self - { - Some(*message_id) - } else { - None - } - } } #[derive(Clone, Debug, derive_more::Display)] diff --git a/common/src/scheduler/task.rs b/common/src/scheduler/task.rs index ebeb0ff7e78..cbfd0575943 100644 --- a/common/src/scheduler/task.rs +++ b/common/src/scheduler/task.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 crate::paused_program_storage::SessionId; +use crate::{paused_program_storage::SessionId, Gas}; use frame_support::{ codec::{self, Decode, Encode, MaxEncodedLen}, scale_info::{self, TypeInfo}, @@ -85,7 +85,7 @@ pub enum ScheduledTask { } impl ScheduledTask { - pub fn process_with(self, handler: &mut impl TaskHandler) { + pub fn process_with(self, handler: &mut impl TaskHandler) -> Gas { use ScheduledTask::*; match self { @@ -117,32 +117,36 @@ pub trait TaskHandler { // 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] diff --git a/examples/constructor/Cargo.toml b/examples/constructor/Cargo.toml index 10782f0558e..383ed6e29f7 100644 --- a/examples/constructor/Cargo.toml +++ b/examples/constructor/Cargo.toml @@ -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 @@ -16,5 +17,6 @@ gear-wasm-builder.workspace = true [features] debug = ["gstd/debug"] -std = [] +wasm-wrapper = [] +std = ["wasm-wrapper"] default = ["std"] diff --git a/examples/constructor/build.rs b/examples/constructor/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/constructor/build.rs +++ b/examples/constructor/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/constructor/src/arg.rs b/examples/constructor/src/arg.rs index 2d78edf7576..b749bbc03b7 100644 --- a/examples/constructor/src/arg.rs +++ b/examples/constructor/src/arg.rs @@ -90,7 +90,7 @@ impl From<&'static str> for Arg { } } -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm { use super::*; diff --git a/examples/constructor/src/call.rs b/examples/constructor/src/call.rs index 0287abd0db5..06c0fde0edb 100644 --- a/examples/constructor/src/call.rs +++ b/examples/constructor/src/call.rs @@ -44,7 +44,7 @@ pub enum Call { Loop, } -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm { use super::*; use crate::DATA; diff --git a/examples/constructor/src/lib.rs b/examples/constructor/src/lib.rs index d112fb3d26b..0ebc224368d 100644 --- a/examples/constructor/src/lib.rs +++ b/examples/constructor/src/lib.rs @@ -16,22 +16,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![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; diff --git a/examples/constructor/src/scheme/demo_proxy_with_gas.rs b/examples/constructor/src/scheme/demo_proxy_with_gas.rs index 35c33e3b6c1..70b7e2a1ba5 100644 --- a/examples/constructor/src/scheme/demo_proxy_with_gas.rs +++ b/examples/constructor/src/scheme/demo_proxy_with_gas.rs @@ -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"; diff --git a/examples/delayed-sender/Cargo.toml b/examples/delayed-sender/Cargo.toml index e23c5e2f310..7c386c1b22a 100644 --- a/examples/delayed-sender/Cargo.toml +++ b/examples/delayed-sender/Cargo.toml @@ -14,5 +14,6 @@ gear-wasm-builder.workspace = true [features] debug = ["gstd/debug"] -std = [ ] +wasm-wrapper = [] +std = ["wasm-wrapper"] default = ["std"] diff --git a/examples/delayed-sender/build.rs b/examples/delayed-sender/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/delayed-sender/build.rs +++ b/examples/delayed-sender/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/delayed-sender/src/code.rs b/examples/delayed-sender/src/code.rs index 3107b539988..c1c1c2d61f8 100644 --- a/examples/delayed-sender/src/code.rs +++ b/examples/delayed-sender/src/code.rs @@ -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 . + use gstd::{msg, MessageId, exec}; static mut MID: Option = None; diff --git a/examples/delayed-sender/src/lib.rs b/examples/delayed-sender/src/lib.rs index 9348dfb7a52..1175ebd0d91 100644 --- a/examples/delayed-sender/src/lib.rs +++ b/examples/delayed-sender/src/lib.rs @@ -15,17 +15,18 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . + #![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"} } diff --git a/examples/init-wait/Cargo.toml b/examples/init-wait/Cargo.toml index 8b0d9b0b238..5a7c643798f 100644 --- a/examples/init-wait/Cargo.toml +++ b/examples/init-wait/Cargo.toml @@ -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] @@ -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"] diff --git a/examples/init-wait/build.rs b/examples/init-wait/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/init-wait/build.rs +++ b/examples/init-wait/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/init-wait/src/code.rs b/examples/init-wait/src/code.rs index 432a5fe94f1..c6ef0bc9edc 100644 --- a/examples/init-wait/src/code.rs +++ b/examples/init-wait/src/code.rs @@ -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 . + use gstd::{exec, msg, collections::BTreeMap, MessageId}; #[derive(PartialEq, Debug)] diff --git a/examples/init-wait/src/lib.rs b/examples/init-wait/src/lib.rs index e5e4ef17484..a4fc7ea8b42 100644 --- a/examples/init-wait/src/lib.rs +++ b/examples/init-wait/src/lib.rs @@ -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 . + #![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"} } diff --git a/examples/reserve-gas/Cargo.toml b/examples/reserve-gas/Cargo.toml index aef27afb79c..132b43911fa 100644 --- a/examples/reserve-gas/Cargo.toml +++ b/examples/reserve-gas/Cargo.toml @@ -18,5 +18,6 @@ gtest.workspace = true [features] debug = ["gstd/debug"] -std = [] +wasm-wrapper = [] +std = ["wasm-wrapper", "parity-scale-codec/std"] default = ["std"] diff --git a/examples/reserve-gas/build.rs b/examples/reserve-gas/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/reserve-gas/build.rs +++ b/examples/reserve-gas/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/reserve-gas/src/lib.rs b/examples/reserve-gas/src/lib.rs index da47e95a438..7644c983bb7 100644 --- a/examples/reserve-gas/src/lib.rs +++ b/examples/reserve-gas/src/lib.rs @@ -23,12 +23,12 @@ extern crate alloc; use alloc::vec::Vec; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] mod code { include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); } -#[cfg(feature = "std")] +#[cfg(feature = "wasm-wrapper")] pub use code::WASM_BINARY_OPT as WASM_BINARY; pub const RESERVATION_AMOUNT: u64 = 50_000_000; @@ -62,7 +62,7 @@ pub enum ReplyAction { pub type GasAmount = u64; pub type BlockCount = u32; -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "wasm-wrapper"))] mod wasm { use super::*; use gstd::{ diff --git a/examples/wait_wake/build.rs b/examples/wait_wake/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/wait_wake/build.rs +++ b/examples/wait_wake/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/waiter/Cargo.toml b/examples/waiter/Cargo.toml index a72ef94b3a5..3090fc3f7a0 100644 --- a/examples/waiter/Cargo.toml +++ b/examples/waiter/Cargo.toml @@ -2,14 +2,15 @@ name = "demo-waiter" version = "0.1.0" authors.workspace = true -edition = "2021" -license = "GPL-3.0" +edition.workspace = true +license.workspace = true workspace = "../../" [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } futures.workspace = true gstd.workspace = true +gcore.workspace = true [build-dependencies] gear-wasm-builder.workspace = true @@ -23,5 +24,6 @@ demo-waiter = { path = ".", features = ["debug"] } [features] debug = ["gstd/debug"] -std = ["parity-scale-codec/std"] +wasm-wrapper = [] +std = ["parity-scale-codec/std", "wasm-wrapper"] default = ["std"] diff --git a/examples/waiter/build.rs b/examples/waiter/build.rs index 4c502a3ddee..b911ce127bb 100644 --- a/examples/waiter/build.rs +++ b/examples/waiter/build.rs @@ -16,6 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use gear_wasm_builder::WasmBuilder; + fn main() { - gear_wasm_builder::build(); + WasmBuilder::new() + .exclude_features(vec!["std", "wasm-wrapper"]) + .build(); } diff --git a/examples/waiter/src/code.rs b/examples/waiter/src/code.rs index 9bc91cb726d..7a68dd08957 100644 --- a/examples/waiter/src/code.rs +++ b/examples/waiter/src/code.rs @@ -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 . + use crate::{ Command, LockContinuation, LockStaticAccessSubcommand, MxLockContinuation, RwLockContinuation, RwLockType, SleepForWaitType, WaitSubcommand, @@ -22,33 +40,33 @@ async fn main() { match cmd { Command::Wait(subcommand) => process_wait_subcommand(subcommand), Command::SendFor(to, duration) => { - msg::send_bytes_for_reply(to, [], 0, 0) + msg::send_bytes_for_reply(to.into(), [], 0, 0) .expect("send message failed") .exactly(Some(duration)) .expect("Invalid wait duration.") .await; } Command::SendUpTo(to, duration) => { - msg::send_bytes_for_reply(to, [], 0, 0) + msg::send_bytes_for_reply(to.into(), [], 0, 0) .expect("send message failed") .up_to(Some(duration)) .expect("Invalid wait duration.") .await; } Command::SendUpToWait(to, duration) => { - msg::send_bytes_for_reply(to, [], 0, 0) + msg::send_bytes_for_reply(to.into(), [], 0, 0) .expect("send message failed") .up_to(Some(duration)) .expect("Invalid wait duration.") .await; // after waking, wait again. - msg::send_bytes_for_reply(to, [], 0, 0) + msg::send_bytes_for_reply(to.into(), [], 0, 0) .expect("send message failed") .await; } Command::SendAndWaitFor(duration, to) => { - msg::send(to, b"ping", 0); + msg::send(to.into(), b"ping", 0); exec::wait_for(duration); } Command::ReplyAndWait(subcommand) => { diff --git a/examples/waiter/src/lib.rs b/examples/waiter/src/lib.rs index 1e744113065..b7d4619f789 100644 --- a/examples/waiter/src/lib.rs +++ b/examples/waiter/src/lib.rs @@ -15,29 +15,37 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![no_std] -use gstd::{ActorId, Vec}; +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +use alloc::vec::Vec; +use gcore::BlockCount; use parity_scale_codec::{Decode, Encode}; -#[cfg(feature = "std")] +type ActorId = [u8; 32]; + +#[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"} } +#[cfg(feature = "std")] pub fn system_reserve() -> u64 { gstd::Config::system_reserve() } // Re-exports for testing +#[cfg(feature = "std")] pub fn default_wait_up_to_duration() -> u32 { gstd::Config::wait_up_to() } @@ -94,14 +102,14 @@ pub enum RwLockContinuation { #[derive(Debug, Encode, Decode)] pub enum Command { Wait(WaitSubcommand), - SendFor(ActorId, gstd::BlockCount), - SendUpTo(ActorId, gstd::BlockCount), - SendUpToWait(ActorId, gstd::BlockCount), - SendAndWaitFor(gstd::BlockCount, ActorId), + SendFor(ActorId, BlockCount), + SendUpTo(ActorId, BlockCount), + SendUpToWait(ActorId, BlockCount), + SendAndWaitFor(BlockCount, ActorId), ReplyAndWait(WaitSubcommand), - SleepFor(Vec, SleepForWaitType), + SleepFor(Vec, SleepForWaitType), WakeUp([u8; 32]), - MxLock(gstd::BlockCount, MxLockContinuation), + MxLock(BlockCount, MxLockContinuation), MxLockStaticAccess(LockStaticAccessSubcommand), RwLock(RwLockType, RwLockContinuation), RwLockStaticAccess(RwLockType, LockStaticAccessSubcommand), diff --git a/gclient/Cargo.toml b/gclient/Cargo.toml index 3ee7de0f6ec..26f9d8b973a 100644 --- a/gclient/Cargo.toml +++ b/gclient/Cargo.toml @@ -38,7 +38,7 @@ demo-async-tester.workspace = true demo-calc-hash.workspace = true demo-calc-hash-in-one-block.workspace = true demo-custom.workspace = true -demo-constructor.workspace = true +demo-constructor = { workspace = true, features = ["std"] } demo-distributor.workspace = true demo-meta-io.workspace = true demo-new-meta.workspace = true @@ -47,7 +47,7 @@ demo-node.workspace = true demo-program-factory.workspace = true demo-proxy = { workspace = true, features = ["std"] } demo-proxy-relay.workspace = true -demo-reserve-gas.workspace = true +demo-reserve-gas = { workspace = true, features = ["std"] } gmeta = { workspace = true } gstd = { workspace = true, features = ["debug"] } demo-wat.workspace = true diff --git a/gsdk/Cargo.toml b/gsdk/Cargo.toml index d823fcd42d9..3985dbc5494 100644 --- a/gsdk/Cargo.toml +++ b/gsdk/Cargo.toml @@ -42,7 +42,7 @@ gsdk = { path = ".", features = ["testing"] } tokio = { workspace = true, features = [ "full" ] } demo-messager.workspace = true demo-new-meta.workspace = true -demo-waiter.workspace = true +demo-waiter = { workspace = true, features = ["std"] } [features] testing = [ "rand" ] diff --git a/gsdk/build.rs b/gsdk/build.rs index 992126a4a46..a7e74efbc13 100644 --- a/gsdk/build.rs +++ b/gsdk/build.rs @@ -40,11 +40,7 @@ fn generate_api() -> Vec { // NOTE: use vara here since vara includes all pallets gear have, // and the API we are building here is for both vara and gear. let [vara_runtime, api_gen] = [ - ( - VARA_RUNTIME_RELATIVE_PATH, - VARA_RUNTIME_PKG, - vec!["debug-mode"], - ), + (VARA_RUNTIME_RELATIVE_PATH, VARA_RUNTIME_PKG, vec!["dev"]), (GSDK_API_GEN_RELATIVE_PATH, GSDK_API_GEN_PKG, vec![]), ] .map(|(relative_path, pkg, features)| get_path(root, &profile, relative_path, pkg, features)); diff --git a/gsdk/src/metadata/errors.rs b/gsdk/src/metadata/errors.rs index fef6f00d76e..bfbd006d5a9 100644 --- a/gsdk/src/metadata/errors.rs +++ b/gsdk/src/metadata/errors.rs @@ -94,7 +94,6 @@ macro_rules! export_module_error { // pallets that don't have `Error` type. // // - pallet_transaction_payment -// - pallet_airdrop // // pallets that share the same `errors::RankedCollective` // diff --git a/gsdk/src/metadata/generated.rs b/gsdk/src/metadata/generated.rs index cfc17329d53..77010704434 100644 --- a/gsdk/src/metadata/generated.rs +++ b/gsdk/src/metadata/generated.rs @@ -1000,73 +1000,6 @@ pub mod runtime_types { } } } - pub mod pallet_airdrop { - use super::runtime_types; - pub mod pallet { - use super::runtime_types; - #[derive(Debug, crate::gp::Decode, crate::gp::DecodeAsType, crate::gp::Encode)] - #[doc = "Contains one variant per dispatchable that can be called by an extrinsic."] - pub enum Call { - #[codec(index = 0)] - #[doc = "Transfer tokens from pre-funded `source` to `dest` account."] - #[doc = ""] - #[doc = "The origin must be the root."] - #[doc = ""] - #[doc = "Parameters:"] - #[doc = "- `source`: the pre-funded account (i.e. root),"] - #[doc = "- `dest`: the beneficiary account,"] - #[doc = "- `amount`: the amount of tokens to be minted."] - #[doc = ""] - #[doc = "Emits the following events:"] - #[doc = "- `TokensDeposited{ dest, amount }`"] - transfer { - source: ::subxt::utils::AccountId32, - dest: ::subxt::utils::AccountId32, - amount: ::core::primitive::u128, - }, - #[codec(index = 1)] - #[doc = "Remove vesting for `source` account and transfer tokens to `dest` account."] - #[doc = ""] - #[doc = "The origin must be the root."] - #[doc = ""] - #[doc = "Parameters:"] - #[doc = "- `source`: the account with vesting running,"] - #[doc = "- `dest`: the beneficiary account,"] - #[doc = "- `schedule_index`: the index of `VestingInfo` for source account."] - #[doc = "- `amount`: the amount to be unlocked and transferred from `VestingInfo`."] - #[doc = ""] - #[doc = "Emits the following events:"] - #[doc = "- `VestingScheduleRemoved{ who, schedule_index }`"] - transfer_vested { - source: ::subxt::utils::AccountId32, - dest: ::subxt::utils::AccountId32, - schedule_index: ::core::primitive::u32, - amount: ::core::option::Option<::core::primitive::u128>, - }, - } - #[derive(Debug, crate::gp::Decode, crate::gp::DecodeAsType, crate::gp::Encode)] - #[doc = "Error for the airdrop pallet."] - pub enum Error { - #[codec(index = 0)] - #[doc = "Amount to being transferred is bigger than vested."] - AmountBigger, - } - #[derive(Debug, crate::gp::Decode, crate::gp::DecodeAsType, crate::gp::Encode)] - #[doc = "\n\t\t\tThe [event](https://docs.substrate.io/main-docs/build/events-errors/) emitted\n\t\t\tby this pallet.\n\t\t\t"] - pub enum Event { - #[codec(index = 0)] - TokensDeposited { - account: ::subxt::utils::AccountId32, - amount: ::core::primitive::u128, - }, - #[codec(index = 1)] - VestingScheduleRemoved { - who: ::subxt::utils::AccountId32, - schedule_index: ::core::primitive::u32, - }, - } - } - } pub mod pallet_babe { use super::runtime_types; pub mod pallet { @@ -9113,8 +9046,6 @@ pub mod runtime_types { GearVoucher(runtime_types::pallet_gear_voucher::pallet::Call), #[codec(index = 99)] Sudo(runtime_types::pallet_sudo::pallet::Call), - #[codec(index = 198)] - Airdrop(runtime_types::pallet_airdrop::pallet::Call), #[codec(index = 199)] GearDebug(runtime_types::pallet_gear_debug::pallet::Call), } @@ -9182,8 +9113,6 @@ pub mod runtime_types { GearVoucher(runtime_types::pallet_gear_voucher::pallet::Event), #[codec(index = 99)] Sudo(runtime_types::pallet_sudo::pallet::Event), - #[codec(index = 198)] - Airdrop(runtime_types::pallet_airdrop::pallet::Event), #[codec(index = 199)] GearDebug(runtime_types::pallet_gear_debug::pallet::Event), } @@ -9204,20 +9133,6 @@ pub mod calls { #[doc = r" returns call name."] fn call_name(&self) -> &'static str; } - #[doc = "Calls of pallet `Airdrop`."] - pub enum AirdropCall { - Transfer, - TransferVested, - } - impl CallInfo for AirdropCall { - const PALLET: &'static str = "Airdrop"; - fn call_name(&self) -> &'static str { - match self { - Self::Transfer => "transfer", - Self::TransferVested => "transfer_vested", - } - } - } #[doc = "Calls of pallet `Babe`."] pub enum BabeCall { ReportEquivocation, @@ -11061,15 +10976,6 @@ pub mod impls { )?, )); } - if pallet_name == "Airdrop" { - return Ok(Event::Airdrop( - crate::metadata::airdrop::Event::decode_with_metadata( - &mut &*pallet_bytes, - pallet_ty, - metadata, - )?, - )); - } if pallet_name == "GearDebug" { return Ok(Event::GearDebug( crate::metadata::gear_debug::Event::decode_with_metadata( @@ -11179,9 +11085,6 @@ pub mod exports { pub mod sudo { pub use super::runtime_types::pallet_sudo::pallet::Event; } - pub mod airdrop { - pub use super::runtime_types::pallet_airdrop::pallet::Event; - } pub mod gear_debug { pub use super::runtime_types::pallet_gear_debug::pallet::Event; } diff --git a/gsdk/tests/rpc.rs b/gsdk/tests/rpc.rs index c458cee94e8..376af7741de 100644 --- a/gsdk/tests/rpc.rs +++ b/gsdk/tests/rpc.rs @@ -151,7 +151,7 @@ async fn test_calculate_reply_gas() -> Result<()> { let salt = vec![]; let pid = ProgramId::generate(CodeId::generate(demo_waiter::WASM_BINARY), &salt); - let payload = demo_waiter::Command::SendUpTo(alice.into(), 10); + let payload = demo_waiter::Command::SendUpTo(alice, 10); // 1. upload program. let signer = Api::new(Some(&node_uri(&node))) diff --git a/lazy-pages/Cargo.toml b/lazy-pages/Cargo.toml index a088e0b9a48..56510ab1ed5 100644 --- a/lazy-pages/Cargo.toml +++ b/lazy-pages/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "gear-lazy-pages" -version = "0.1.0" -authors.workspace = true description = "Gear lazy-pages support" +version.workspace = true +authors.workspace = true edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true [dependencies] log = { workspace = true, features = ["std"] } diff --git a/node/authorship/Cargo.toml b/node/authorship/Cargo.toml index a445c9d5f08..7b474e043a6 100644 --- a/node/authorship/Cargo.toml +++ b/node/authorship/Cargo.toml @@ -1,12 +1,11 @@ [package] name = "gear-authorship" -version = "0.1.0" +version.workspace = true authors.workspace = true -description = "Gear Node" edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -56,6 +55,7 @@ pallet-balances = { workspace = true, features = ["std"] } pallet-gear = { workspace = true, features = ["std"] } pallet-gear-messenger = { workspace = true, features = ["std"] } testing = {workspace = true, features = ["vara-native"] } -vara-runtime = { workspace = true, features = ["std"] } +vara-runtime = { workspace = true, features = ["std", "dev"] } demo-mul-by-const.workspace = true env_logger.workspace = true +service = { workspace = true, features = ["dev", "vara-native"] } diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index 21fe8615206..02fe1c8c9d2 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -3,6 +3,9 @@ name = "gear-cli" version.workspace = true authors.workspace = true edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -83,10 +86,10 @@ runtime-benchmarks = [ runtime-benchmarks-checkers = [ "service/runtime-benchmarks-checkers", ] -debug-mode = [ - "service/debug-mode", - "gear-runtime?/debug-mode", - "vara-runtime?/debug-mode", +dev = [ + "service/dev", + "gear-runtime?/dev", + "vara-runtime?/dev", ] try-runtime = [ "service/try-runtime", diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 42cf04ca104..4daf4785562 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -52,20 +52,34 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { - #[cfg(feature = "gear-native")] + #[cfg(not(feature = "dev"))] + "dev" | "gear-dev" | "vara-dev" => return Err("Development runtimes are not available. Please compile the node with `-F dev` to enable it.".into()), + #[cfg(all(feature = "gear-native", feature = "dev"))] "dev" | "gear-dev" => Box::new(chain_spec::gear::development_config()?), - #[cfg(feature = "vara-native")] + #[cfg(all(feature = "vara-native", feature = "dev"))] "vara-dev" => Box::new(chain_spec::vara::development_config()?), #[cfg(feature = "gear-native")] - "local" | "gear-local" => Box::new(chain_spec::gear::local_testnet_config()?), + "local" | "gear-local" => { + #[cfg(feature = "dev")] + log::warn!("Running `gear-local` in `dev` mode"); + Box::new(chain_spec::gear::local_testnet_config()?) + } #[cfg(feature = "vara-native")] "vara" => Box::new(chain_spec::RawChainSpec::from_json_bytes( &include_bytes!("../../res/vara.json")[..], )?), #[cfg(feature = "vara-native")] - "vara-local" => Box::new(chain_spec::vara::local_testnet_config()?), + "vara-local" => { + #[cfg(feature = "dev")] + log::warn!("Running `vara-local` in `dev` mode"); + Box::new(chain_spec::vara::local_testnet_config()?) + } #[cfg(feature = "gear-native")] - "staging" | "gear-staging" => Box::new(chain_spec::gear::staging_testnet_config()?), + "staging" | "gear-staging" => { + #[cfg(feature = "dev")] + log::warn!("Running `gear-staging` in `dev` mode"); + Box::new(chain_spec::gear::staging_testnet_config()?) + } "test" | "" => Box::new(chain_spec::RawChainSpec::from_json_bytes( &include_bytes!("../../res/staging.json")[..], )?), @@ -75,24 +89,25 @@ impl SubstrateCli for Cli { let chain_spec = Box::new(chain_spec::RawChainSpec::from_json_file(path.clone())?) as Box; + if chain_spec.is_dev() { + #[cfg(not(feature = "dev"))] + return Err("Development runtimes are not available. Please compile the node with `-F dev` to enable it.".into()); + } + // When `force_*` is provide or the file name starts with the name of a known chain, // we use the chain spec for the specific chain. if self.run.force_vara || chain_spec.is_vara() { #[cfg(feature = "vara-native")] - { - Box::new(chain_spec::vara::ChainSpec::from_json_file(path)?) - } + return Ok(Box::new(chain_spec::vara::ChainSpec::from_json_file(path)?)); #[cfg(not(feature = "vara-native"))] - return Err("Vara runtime is not available. Please compile the node with `--features vara-native` to enable it.".into()); + return Err("Vara runtime is not available. Please compile the node with `-F vara-native` to enable it.".into()); } else { #[cfg(feature = "gear-native")] - { - Box::new(chain_spec::gear::ChainSpec::from_json_file(path)?) - } + return Ok(Box::new(chain_spec::gear::ChainSpec::from_json_file(path)?)); #[cfg(not(feature = "gear-native"))] - return Err("Gear runtime is not available. Please compile the node with default features to enable it.".into()); + return Err("Gear runtime is not available. Please compile the node with `-F gear-native` to enable it.".into()); } } }) diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index a51975375cb..79ff6da306f 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -1,12 +1,11 @@ [package] name = "gear-service" -version = "0.1.0" +version.workspace = true authors.workspace = true -description = "Gear Node" edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -124,9 +123,9 @@ runtime-benchmarks-checkers = [ "gear-runtime?/runtime-benchmarks-checkers", "vara-runtime?/runtime-benchmarks-checkers", ] -debug-mode = [ - "gear-runtime?/debug-mode", - "vara-runtime?/debug-mode", +dev = [ + "gear-runtime?/dev", + "vara-runtime?/dev", ] try-runtime = [ "gear-runtime?/try-runtime", diff --git a/node/service/src/chain_spec/gear.rs b/node/service/src/chain_spec/gear.rs index 89c4fd29c96..d180fde5185 100644 --- a/node/service/src/chain_spec/gear.rs +++ b/node/service/src/chain_spec/gear.rs @@ -41,6 +41,7 @@ pub fn authority_keys_from_seed(s: &str) -> (AccountId, BabeId, GrandpaId) { ) } +#[cfg(feature = "dev")] pub fn development_config() -> Result { let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; diff --git a/node/service/src/chain_spec/vara.rs b/node/service/src/chain_spec/vara.rs index b6522ae114a..3245ae1aef5 100644 --- a/node/service/src/chain_spec/vara.rs +++ b/node/service/src/chain_spec/vara.rs @@ -27,11 +27,13 @@ use sp_consensus_babe::AuthorityId as BabeId; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{crypto::UncheckedInto, sr25519}; use sp_runtime::{Perbill, Perquintill}; +#[cfg(feature = "dev")] +use vara_runtime::SudoConfig; use vara_runtime::{ - constants::currency::{DOLLARS, EXISTENTIAL_DEPOSIT, UNITS as TOKEN}, + constants::currency::{ECONOMIC_UNITS, EXISTENTIAL_DEPOSIT, UNITS as TOKEN}, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig, NominationPoolsConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, - StakingRewardsConfig, SudoConfig, SystemConfig, VestingConfig, WASM_BINARY, + StakingRewardsConfig, SystemConfig, VestingConfig, WASM_BINARY, }; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. @@ -91,6 +93,7 @@ pub fn authority_keys_from_seed( ) } +#[cfg(feature = "dev")] pub fn development_config() -> Result { let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; @@ -557,6 +560,9 @@ fn testnet_genesis( bank_account: AccountId, _enable_println: bool, ) -> GenesisConfig { + #[cfg(not(feature = "dev"))] + let _ = root_key; + const ENDOWMENT: u128 = 1_000_000 * TOKEN; const STASH: u128 = 100 * TOKEN; const MIN_NOMINATOR_BOND: u128 = 50 * TOKEN; @@ -608,6 +614,7 @@ fn testnet_genesis( min_nominator_bond: MIN_NOMINATOR_BOND, ..Default::default() }, + #[cfg(feature = "dev")] sudo: SudoConfig { // Assign network admin rights. key: Some(root_key), @@ -617,8 +624,8 @@ fn testnet_genesis( transaction_payment: Default::default(), treasury: Default::default(), nomination_pools: NominationPoolsConfig { - min_create_bond: 10 * DOLLARS, - min_join_bond: DOLLARS, + min_create_bond: 10 * ECONOMIC_UNITS, + min_join_bond: ECONOMIC_UNITS, ..Default::default() }, vesting: VestingConfig { vesting: vec![] }, diff --git a/node/testing/Cargo.toml b/node/testing/Cargo.toml index c3d823d90e9..6706a388f32 100644 --- a/node/testing/Cargo.toml +++ b/node/testing/Cargo.toml @@ -1,12 +1,11 @@ [package] name = "gear-node-testing" -version = "0.1.0" +version.workspace = true authors.workspace = true -description = "Gear Node" edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -26,6 +25,7 @@ pallet-gear-rpc-runtime-api.workspace = true gear-runtime = { workspace = true, optional = true } vara-runtime = { workspace = true, optional = true } gear-runtime-interface.workspace = true +service = { workspace = true, features = ["dev"] } # Substrate Client sc-block-builder.workspace = true @@ -73,5 +73,5 @@ std = [ "gear-runtime?/std", "vara-runtime?/std", ] -gear-native = ["gear-runtime"] -vara-native = ["vara-runtime"] +gear-native = ["gear-runtime/dev", "service/gear-native"] +vara-native = ["vara-runtime/dev", "service/vara-native"] diff --git a/node/testing/src/genesis.rs b/node/testing/src/genesis.rs index f5a63aa4629..019e3f93948 100644 --- a/node/testing/src/genesis.rs +++ b/node/testing/src/genesis.rs @@ -49,18 +49,18 @@ pub fn genesis_config(code: Option<&[u8]>) -> GenesisConfig { #[cfg(feature = "vara-native")] pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec) -> GenesisConfig { let mut endowed = vec![ - (alice(), 111 * DOLLARS), - (bob(), 100 * DOLLARS), - (charlie(), 100_000_000 * DOLLARS), - (dave(), 111 * DOLLARS), - (eve(), 101 * DOLLARS), - (ferdie(), 100 * DOLLARS), + (alice(), 111 * ECONOMIC_UNITS), + (bob(), 100 * ECONOMIC_UNITS), + (charlie(), 100_000_000 * ECONOMIC_UNITS), + (dave(), 111 * ECONOMIC_UNITS), + (eve(), 101 * ECONOMIC_UNITS), + (ferdie(), 100 * ECONOMIC_UNITS), ]; endowed.extend( extra_endowed .into_iter() - .map(|endowed| (endowed, 100 * DOLLARS)), + .map(|endowed| (endowed, 100 * ECONOMIC_UNITS)), ); GenesisConfig { @@ -98,9 +98,19 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec) -> Gen }, staking: StakingConfig { stakers: vec![ - (dave(), alice(), 111 * DOLLARS, StakerStatus::Validator), - (eve(), bob(), 100 * DOLLARS, StakerStatus::Validator), - (ferdie(), charlie(), 100 * DOLLARS, StakerStatus::Validator), + ( + dave(), + alice(), + 111 * ECONOMIC_UNITS, + StakerStatus::Validator, + ), + (eve(), bob(), 100 * ECONOMIC_UNITS, StakerStatus::Validator), + ( + ferdie(), + charlie(), + 100 * ECONOMIC_UNITS, + StakerStatus::Validator, + ), ], validator_count: 3, minimum_validator_count: 3, @@ -128,18 +138,18 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec) -> Gen #[cfg(all(not(feature = "vara-native"), feature = "gear-native"))] pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec) -> GenesisConfig { let mut endowed = vec![ - (alice(), 111 * DOLLARS), - (bob(), 100 * DOLLARS), - (charlie(), 100_000_000 * DOLLARS), - (dave(), 111 * DOLLARS), - (eve(), 101 * DOLLARS), - (ferdie(), 100 * DOLLARS), + (alice(), 111 * ECONOMIC_UNITS), + (bob(), 100 * ECONOMIC_UNITS), + (charlie(), 100_000_000 * ECONOMIC_UNITS), + (dave(), 111 * ECONOMIC_UNITS), + (eve(), 101 * ECONOMIC_UNITS), + (ferdie(), 100 * ECONOMIC_UNITS), ]; endowed.extend( extra_endowed .into_iter() - .map(|endowed| (endowed, 100 * DOLLARS)), + .map(|endowed| (endowed, 100 * ECONOMIC_UNITS)), ); GenesisConfig { diff --git a/pallets/airdrop/Cargo.toml b/pallets/airdrop/Cargo.toml deleted file mode 100644 index 35f74034b41..00000000000 --- a/pallets/airdrop/Cargo.toml +++ /dev/null @@ -1,70 +0,0 @@ -[package] -name = "pallet-airdrop" -version = "1.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" -description = "Airdrop pallet" -readme = "README.md" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive", "max-encoded-len"] } -scale-info = { workspace = true, features = ["derive"] } -log.workspace = true - -# Internal deps -common.workspace = true -pallet-gear.workspace = true -pallet-gear-bank.workspace = true - -# Substrate deps -frame-support.workspace = true -frame-system.workspace = true -frame-benchmarking = { workspace = true, optional = true } -sp-runtime.workspace = true -sp-std.workspace = true -pallet-balances.workspace = true -pallet-vesting.workspace = true - -[dev-dependencies] -serde.workspace = true -env_logger.workspace = true -sp-core = { workspace = true, features = ["std"] } -sp-io = { workspace = true, features = ["std"] } -pallet-authorship = { workspace = true, features = ["std"] } -pallet-sudo = { workspace = true, features = ["std"] } -pallet-timestamp = { workspace = true, features = ["std"] } -pallet-gear-program = { workspace = true, features = ["std"] } -pallet-gear-messenger = { workspace = true, features = ["std"] } -pallet-gear-scheduler = { workspace = true, features = ["std"] } -pallet-gear-gas = { workspace = true, features = ["std"] } -frame-support-test = { workspace = true, features = ["std"] } - -[features] -default = ["std"] -std = [ - "common/std", - "parity-scale-codec/std", - "log/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "scale-info/std", - "sp-std/std", - "pallet-balances/std", - "pallet-vesting/std", - "pallet-gear/std", - "pallet-gear-bank/std", -] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "common/runtime-benchmarks", -] -try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/airdrop/README.md b/pallets/airdrop/README.md deleted file mode 100644 index 3f75afc1b5b..00000000000 --- a/pallets/airdrop/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Airdrop pallet used on testnet to dispense funds to users - -A crate which provides a mechanism to transfer tokens from pre-funded account to users while generic balance transfers are disabled. - -### Dispatchable Functions - -License: Unlicense diff --git a/pallets/airdrop/src/benchmarking.rs b/pallets/airdrop/src/benchmarking.rs deleted file mode 100644 index 68064fca290..00000000000 --- a/pallets/airdrop/src/benchmarking.rs +++ /dev/null @@ -1,70 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2022-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 . - -#[allow(unused)] -use crate::Pallet as Airdrop; -use crate::*; -use common::{benchmarking, Origin}; -use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; -use frame_support::traits::Currency; -use frame_system::RawOrigin; -use pallet_vesting::VestingInfo; -use sp_runtime::traits::{StaticLookup, UniqueSaturatedInto}; - -benchmarks! { - where_clause { where - T::AccountId: Origin, - } - - transfer { - let q in 1 .. 256; - - let source: T::AccountId = benchmarking::account("source", 0, 0); - ::Currency::deposit_creating(&source, (1u128 << 60).unique_saturated_into()); - let recipient: T::AccountId = benchmarking::account("recipient", 0, 0); - // Keeping in mind the existential deposit - let amount = 10_000_000_000_000_u128.saturating_add(10_u128.saturating_mul(q.into())); - - }: _(RawOrigin::Root, source, recipient.clone(), amount.unique_saturated_into()) - verify { - assert_eq!(pallet_balances::Pallet::::total_balance(&recipient), amount.unique_saturated_into()); - } - - transfer_vested { - let q in 1 .. 256; - - let source: T::AccountId = benchmarking::account("source", 0, 0); - let source_lookup = T::Lookup::unlookup(source.clone()); - ::Currency::deposit_creating(&source, (1u128 << 60).unique_saturated_into()); - let recipient: T::AccountId = benchmarking::account("recipient", 0, 0); - let amount = ::MinVestedTransfer::get().saturating_mul(q.into()); - - // create vesting schedule amount * 2 - let vested_amount = amount.saturating_mul(2u128.unique_saturated_into()); - let vesting_schedule = VestingInfo::new(vested_amount.unique_saturated_into(), 10u128.unique_saturated_into(), 1000u32.into()); - pallet_vesting::Pallet::::vested_transfer(RawOrigin::Signed(source.clone()).into(), source_lookup, vesting_schedule)?; - - }: _(RawOrigin::Root, source.clone(), recipient.clone(), 0, Some(amount)) - verify { - // check that the total vested amount is halved between the source and the recipient - assert_eq!(pallet_vesting::Pallet::::vesting_balance(&source), Some(amount)); - assert_eq!(::Currency::free_balance(&recipient), amount); - } -} - -impl_benchmark_test_suite!(Airdrop, crate::mock::new_test_ext(), crate::mock::Test,); diff --git a/pallets/airdrop/src/lib.rs b/pallets/airdrop/src/lib.rs deleted file mode 100644 index 7609271c50e..00000000000 --- a/pallets/airdrop/src/lib.rs +++ /dev/null @@ -1,214 +0,0 @@ -// 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 . - -#![cfg_attr(not(feature = "std"), no_std)] - -use frame_support::{ - pallet_prelude::*, - traits::{Currency, ExistenceRequirement, VestingSchedule}, -}; -pub use pallet::*; -use sp_runtime::traits::{Convert, Saturating}; -pub use weights::WeightInfo; - -pub mod weights; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - -#[cfg(test)] -mod mock; - -#[cfg(test)] -mod tests; - -pub(crate) type BalanceOf = <::Currency as Currency< - ::AccountId, ->>::Balance; - -pub(crate) type VestingBalanceOf = <::Currency as Currency< - ::AccountId, ->>::Balance; - -#[frame_support::pallet] -pub mod pallet { - use super::*; - - use frame_system::pallet_prelude::*; - - #[pallet::config] - pub trait Config: - frame_system::Config - + pallet_gear::Config - + pallet_balances::Config - + pallet_vesting::Config - { - /// Because this pallet emits events, it depends on the runtime's definition of an event. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; - - /// To modify/remove vesting schedule - type VestingSchedule: VestingSchedule< - Self::AccountId, - Currency = ::Currency, - Moment = Self::BlockNumber, - >; - } - - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - TokensDeposited { - account: T::AccountId, - amount: BalanceOf, - }, - VestingScheduleRemoved { - who: T::AccountId, - schedule_index: u32, - }, - } - - /// Error for the airdrop pallet. - #[pallet::error] - pub enum Error { - /// Amount to being transferred is bigger than vested. - AmountBigger, - } - - #[pallet::call] - impl Pallet { - /// Transfer tokens from pre-funded `source` to `dest` account. - /// - /// The origin must be the root. - /// - /// Parameters: - /// - `source`: the pre-funded account (i.e. root), - /// - `dest`: the beneficiary account, - /// - `amount`: the amount of tokens to be minted. - /// - /// Emits the following events: - /// - `TokensDeposited{ dest, amount }` - #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::transfer(1))] - pub fn transfer( - origin: OriginFor, - source: T::AccountId, - dest: T::AccountId, - amount: BalanceOf, - ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - - <::Currency as Currency<_>>::transfer( - &source, - &dest, - amount, - ExistenceRequirement::KeepAlive, - )?; - Self::deposit_event(Event::TokensDeposited { - account: dest, - amount, - }); - - // This extrinsic is not chargeable - Ok(Pays::No.into()) - } - - /// Remove vesting for `source` account and transfer tokens to `dest` account. - /// - /// The origin must be the root. - /// - /// Parameters: - /// - `source`: the account with vesting running, - /// - `dest`: the beneficiary account, - /// - `schedule_index`: the index of `VestingInfo` for source account. - /// - `amount`: the amount to be unlocked and transferred from `VestingInfo`. - /// - /// Emits the following events: - /// - `VestingScheduleRemoved{ who, schedule_index }` - #[pallet::call_index(1)] - #[pallet::weight(::WeightInfo::transfer_vested(1))] - pub fn transfer_vested( - origin: OriginFor, - source: T::AccountId, - dest: T::AccountId, - schedule_index: u32, - amount: Option>, - ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - - let schedules = pallet_vesting::Pallet::::vesting(&source) - .ok_or(pallet_vesting::Error::::NotVesting)?; - - let schedule = schedules - .get(schedule_index as usize) - .ok_or(pallet_vesting::Error::::ScheduleIndexOutOfBounds)?; - - T::VestingSchedule::remove_vesting_schedule(&source, schedule_index)?; - - Self::deposit_event(Event::VestingScheduleRemoved { - who: source.clone(), - schedule_index, - }); - - let amount = if let Some(amount) = amount { - ensure!(amount <= schedule.locked(), Error::::AmountBigger); - let end_amount = schedule.locked().saturating_sub(amount); - let end_block = schedule.ending_block_as_balance::(); - let start_block = T::BlockNumberToBalance::convert(schedule.starting_block()); - let per_block = end_amount / end_block.saturating_sub(start_block); - - T::VestingSchedule::can_add_vesting_schedule( - &source, - end_amount, - per_block, - schedule.starting_block(), - )?; - let res = T::VestingSchedule::add_vesting_schedule( - &source, - end_amount, - per_block, - schedule.starting_block(), - ); - - debug_assert!( - res.is_ok(), - "Failed to add a schedule when we had to succeed." - ); - - amount - } else { - schedule.locked() - }; - - <::Currency as Currency<_>>::transfer( - &source, - &dest, - amount, - ExistenceRequirement::AllowDeath, - )?; - - // This extrinsic is not chargeable - Ok(Pays::No.into()) - } - } -} diff --git a/pallets/airdrop/src/mock.rs b/pallets/airdrop/src/mock.rs deleted file mode 100644 index 6e4f334f9f2..00000000000 --- a/pallets/airdrop/src/mock.rs +++ /dev/null @@ -1,247 +0,0 @@ -// 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 . - -use crate as pallet_airdrop; -use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU64, GenesisBuild, WithdrawReasons}, -}; -use frame_support_test::TestRandomness; -use frame_system as system; -use sp_core::ConstBool; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, ConvertInto, IdentityLookup}, -}; -use sp_std::convert::{TryFrom, TryInto}; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; -type AccountId = u64; -type BlockNumber = u64; -type Balance = u128; - -pub const ALICE: AccountId = 1; -pub const BOB: AccountId = 2; -pub const ROOT: AccountId = 255; - -// Configure a mock runtime to test the pallet. -construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: system, - Balances: pallet_balances, - Sudo: pallet_sudo, - Authorship: pallet_authorship, - Timestamp: pallet_timestamp, - GearProgram: pallet_gear_program, - GearMessenger: pallet_gear_messenger, - GearScheduler: pallet_gear_scheduler, - GearGas: pallet_gear_gas, - GearBank: pallet_gear_bank, - Gear: pallet_gear, - Airdrop: pallet_airdrop, - Vesting: pallet_vesting, - } -); - -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; - pub const ExistentialDeposit: Balance = 1; - pub const OutgoingLimit: u32 = 1024; - pub GearSchedule: pallet_gear::Schedule = >::default(); -} - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = sp_core::H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} - -impl pallet_sudo::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeCall = RuntimeCall; -} - -impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = ConstU64<500>; - type WeightInfo = (); -} - -impl pallet_authorship::Config for Test { - type FindAuthor = (); - - type EventHandler = (); -} - -impl pallet_gear_gas::Config for Test { - type BlockGasLimit = ConstU64<100_000_000>; -} - -impl pallet_gear_messenger::Config for Test { - type BlockLimiter = GearGas; - type CurrentBlockNumber = Gear; -} - -impl pallet_gear_program::Config for Test { - type Scheduler = GearScheduler; - type CurrentBlockNumber = (); -} - -parameter_types! { - pub RentFreePeriod: BlockNumber = 1_000; - pub RentCostPerBlock: Balance = 11; - pub ResumeMinimalPeriod: BlockNumber = 100; - pub ResumeSessionDuration: BlockNumber = 1_000; - pub const BankAddress: AccountId = 15082001; - pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(25); -} - -impl pallet_gear_bank::Config for Test { - type Currency = Balances; - type BankAddress = BankAddress; - type GasMultiplier = GasMultiplier; -} - -impl pallet_gear::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Randomness = TestRandomness; - type WeightInfo = (); - type Schedule = GearSchedule; - type OutgoingLimit = OutgoingLimit; - type DebugInfo = (); - type ProgramStorage = GearProgram; - type CodeStorage = GearProgram; - type MailboxThreshold = ConstU64<3000>; - type ReservationsLimit = ConstU64<256>; - type Messenger = GearMessenger; - type GasProvider = GearGas; - type BlockLimiter = GearGas; - type Scheduler = GearScheduler; - type QueueRunner = Gear; - type Voucher = (); - type ProgramRentFreePeriod = RentFreePeriod; - type ProgramResumeMinimalRentPeriod = ResumeMinimalPeriod; - type ProgramRentCostPerBlock = RentCostPerBlock; - type ProgramResumeSessionDuration = ResumeSessionDuration; - type ProgramRentEnabled = ConstBool; - type ProgramRentDisabledDelta = RentFreePeriod; -} - -impl pallet_gear_scheduler::Config for Test { - type BlockLimiter = GearGas; - type ReserveThreshold = ConstU64<1>; - type WaitlistCost = ConstU64<100>; - type MailboxCost = ConstU64<100>; - type ReservationCost = ConstU64<100>; - type DispatchHoldCost = ConstU64<100>; -} - -parameter_types! { - pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons = - WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE); -} - -impl pallet_vesting::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Currency = Balances; - type BlockNumberToBalance = ConvertInto; - type MinVestedTransfer = (); - type WeightInfo = (); - type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons; - const MAX_VESTING_SCHEDULES: u32 = 28; -} - -pub type VestingError = pallet_vesting::Error; - -impl pallet_airdrop::Config for Test { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); - type VestingSchedule = Vesting; -} - -pub type AirdropCall = pallet_airdrop::Call; -pub type AirdropError = pallet_airdrop::Error; - -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = system::GenesisConfig::default() - .build_storage::() - .unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![ - (ROOT, 100_000_000_u128), - (BOB, 100_000_000_u128), - (BankAddress::get(), ExistentialDeposit::get()), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - - pallet_sudo::GenesisConfig:: { key: Some(ROOT) } - .assimilate_storage(&mut t) - .unwrap(); - - pallet_vesting::GenesisConfig:: { - vesting: vec![(BOB, 100, 1000, 0)], - } - .assimilate_storage(&mut t) - .unwrap(); - - t.into() -} diff --git a/pallets/airdrop/src/tests.rs b/pallets/airdrop/src/tests.rs deleted file mode 100644 index 420b8c05930..00000000000 --- a/pallets/airdrop/src/tests.rs +++ /dev/null @@ -1,173 +0,0 @@ -// 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 . - -use super::*; -use crate::mock::{ - new_test_ext, Airdrop, AirdropCall, AirdropError, Balances, BankAddress, ExistentialDeposit, - RuntimeCall, RuntimeOrigin, Sudo, Test, Vesting, VestingError, ALICE, BOB, ROOT, -}; -use frame_support::{assert_err, assert_noop, assert_ok}; -use frame_system::Config; -use pallet_vesting::VestingInfo; - -#[test] -fn test_setup_works() { - new_test_ext().execute_with(|| { - assert_eq!(Sudo::key(), Some(ROOT)); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - }); -} - -#[test] -fn sudo_call_works() { - new_test_ext().execute_with(|| { - let call = Box::new(RuntimeCall::Airdrop(AirdropCall::transfer { - source: ROOT, - dest: ALICE, - amount: 10_000_000, - })); - assert_ok!(Sudo::sudo(RuntimeOrigin::signed(ROOT), call)); - assert_eq!(Balances::total_balance(&ALICE), 10_000_000); - assert_eq!(Balances::total_balance(&ROOT), 90_000_000); - assert_eq!( - Balances::total_balance(&BankAddress::get()), - ExistentialDeposit::get() - ); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - - assert_eq!(Balances::locks(BOB).len(), 1); - let call = Box::new(RuntimeCall::Airdrop(AirdropCall::transfer_vested { - source: BOB, - dest: ALICE, - schedule_index: 0, - amount: None, - })); - assert_ok!(Sudo::sudo(RuntimeOrigin::signed(ROOT), call)); - assert_eq!(Balances::total_balance(&BOB), 0); - assert_eq!(Balances::locks(BOB), vec![]); - assert_eq!(Balances::total_balance(&ALICE), 110_000_000); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - }); -} -#[test] -fn vesting_transfer_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::locks(BOB).len(), 1); - assert_eq!( - Vesting::vesting(BOB).unwrap().first().unwrap(), - &VestingInfo::, ::BlockNumber>::new( - 100_000_000, - 100_000, - 100, - ) - ); - assert_eq!(Balances::total_balance(&ALICE), 0); - assert_eq!(Balances::total_balance(&BOB), 100_000_000); - assert_eq!(Balances::total_balance(&ROOT), 100_000_000); - assert_eq!( - Balances::total_balance(&BankAddress::get()), - ExistentialDeposit::get() - ); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - - // Vesting must exist on the source account - assert_err!( - Airdrop::transfer_vested(RuntimeOrigin::root(), ALICE, BOB, 1, Some(200_000_000)), - VestingError::NotVesting - ); - - // Schedule must exist on the source account - assert_err!( - Airdrop::transfer_vested(RuntimeOrigin::root(), BOB, ALICE, 1, Some(200_000_000)), - VestingError::ScheduleIndexOutOfBounds - ); - - // Amount can't be bigger than locked funds - assert_err!( - Airdrop::transfer_vested(RuntimeOrigin::root(), BOB, ALICE, 0, Some(200_000_000)), - AirdropError::AmountBigger - ); - - // Transfer part of vested funds to ALICE - assert_ok!(Airdrop::transfer_vested( - RuntimeOrigin::root(), - BOB, - ALICE, - 0, - Some(10_000_000) - )); - - // Check that BOB have the same vesting schedule reduced by unlocked funds - assert_eq!( - Vesting::vesting(BOB).unwrap().first().unwrap(), - &VestingInfo::, ::BlockNumber>::new( - 90_000_000, 90_000, 100, - ) - ); - assert_eq!(Balances::total_balance(&BOB), 90_000_000); - assert_eq!(Balances::free_balance(ALICE), 10_000_000); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - - // Transfer all of vested funds to ALICE - assert_ok!(Airdrop::transfer_vested( - RuntimeOrigin::root(), - BOB, - ALICE, - 0, - None - )); - - // Check that BOB have no vesting and ALICE have all the unlocked funds. - assert_eq!(Vesting::vesting(BOB), None); - assert_eq!(Balances::total_balance(&BOB), 0); - assert_eq!(Balances::free_balance(ALICE), 100_000_000); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - }); -} - -#[test] -fn signed_extrinsic_fails() { - new_test_ext().execute_with(|| { - assert_noop!( - Airdrop::transfer(RuntimeOrigin::signed(ROOT), ROOT, ALICE, 10_000_000_u128), - DispatchError::BadOrigin, - ); - assert_noop!( - Airdrop::transfer_vested(RuntimeOrigin::signed(ROOT), BOB, ALICE, 0, None), - DispatchError::BadOrigin, - ); - }); -} diff --git a/pallets/airdrop/src/weights.rs b/pallets/airdrop/src/weights.rs deleted file mode 100644 index ddaa539a3d9..00000000000 --- a/pallets/airdrop/src/weights.rs +++ /dev/null @@ -1,95 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2022-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 . - -//! Autogenerated weights for pallet_airdrop -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("vara-dev"), DB CACHE: 1024 - -// Executed Command: -// ./target/production/gear benchmark pallet --chain=vara-dev --steps=50 --repeat=20 --pallet=pallet_airdrop --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=pallet_airdrop.rs --template=.maintain/frame-weight-template.hbs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; - -/// Weight functions needed for pallet_airdrop. -pub trait WeightInfo { - fn transfer(q: u32, ) -> Weight; - fn transfer_vested(q: u32, ) -> Weight; -} - -/// Weights for pallet_airdrop using the Gear node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// The range of component `q` is `[1, 256]`. - fn transfer(_q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `103` - // Estimated: `6196` - // Minimum execution time: 25_027_000 picoseconds. - Weight::from_parts(25_985_030, 6196) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// The range of component `q` is `[1, 256]`. - fn transfer_vested(q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `550` - // Estimated: `15482` - // Minimum execution time: 65_271_000 picoseconds. - Weight::from_parts(67_109_074, 15482) - // Standard Error: 328 - .saturating_add(Weight::from_parts(336, 0).saturating_mul(q.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) - } -} - -// For backwards compatibility and tests -impl WeightInfo for () { - /// The range of component `q` is `[1, 256]`. - fn transfer(_q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `103` - // Estimated: `6196` - // Minimum execution time: 25_027_000 picoseconds. - Weight::from_parts(25_985_030, 6196) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// The range of component `q` is `[1, 256]`. - fn transfer_vested(q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `550` - // Estimated: `15482` - // Minimum execution time: 65_271_000 picoseconds. - Weight::from_parts(67_109_074, 15482) - // Standard Error: 328 - .saturating_add(Weight::from_parts(336, 0).saturating_mul(q.into())) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) - } -} diff --git a/pallets/gas/Cargo.toml b/pallets/gas/Cargo.toml index 765924dc01c..2d78fad78e2 100644 --- a/pallets/gas/Cargo.toml +++ b/pallets/gas/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "pallet-gear-gas" -version = "2.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" description = "Gear gas pallet" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true readme = "README.md" [package.metadata.docs.rs] diff --git a/pallets/gas/src/lib.rs b/pallets/gas/src/lib.rs index 24d49b20d33..db681e5ca60 100644 --- a/pallets/gas/src/lib.rs +++ b/pallets/gas/src/lib.rs @@ -139,8 +139,6 @@ mod mock; #[cfg(test)] mod tests; -pub mod migrations; - type BlockGasLimitOf = ::BlockGasLimit; type AccountIdOf = ::AccountId; diff --git a/pallets/gas/src/migrations.rs b/pallets/gas/src/migrations.rs deleted file mode 100644 index 8ade4e216c1..00000000000 --- a/pallets/gas/src/migrations.rs +++ /dev/null @@ -1,243 +0,0 @@ -use crate::{Config, Error, Key, NodeOf, Pallet, Weight}; -use common::GasMultiplier; -use core::marker::PhantomData; -use frame_support::{ - dispatch::GetStorageVersion, - traits::{Get, OnRuntimeUpgrade}, -}; -#[cfg(feature = "try-runtime")] -use sp_std::vec::Vec; - -const MULTIPLIER: GasMultiplier = GasMultiplier::ValuePerGas(1_000); - -pub struct MigrateToV3(PhantomData); - -impl OnRuntimeUpgrade for MigrateToV3 { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - use parity_scale_codec::Encode as _; - - let version = >::on_chain_storage_version(); - - Ok(version.encode()) - } - - fn on_runtime_upgrade() -> Weight { - let onchain = Pallet::::on_chain_storage_version(); - let current = Pallet::::current_storage_version(); - - if current != 3 || onchain != 2 { - log::info!("❌ Migrations of `pallet-gear-gas` to V3 are outdated"); - - return T::DbWeight::get().reads(1); - } - - log::info!("🚚 Running migrations to version {current:?} from version {onchain:?}"); - - let mut writes = 0u64; - - crate::GasNodes::::translate::, _>(|key, value| { - writes += 1; - translate::(key, value) - .map_err(|e| { - log::error!("Error translating {key:?} node: {e:?})"); - e - }) - .ok() - }); - - log::info!("Upgraded {writes:?} gas nodes"); - - current.put::>(); - - T::DbWeight::get().reads_writes(1, writes + 1) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(state: Vec) -> Result<(), &'static str> { - use frame_support::traits::StorageVersion; - use parity_scale_codec::Decode; - - let previous: StorageVersion = - Decode::decode(&mut state.as_ref()).map_err(|_| "Cannot decode version")?; - - if previous == 2 { - let onchain = Pallet::::on_chain_storage_version(); - - assert_ne!(previous, onchain, "Must have upgraded from version 2 to 3"); - - log::info!("Storage `pallet-gear-gas` successfully migrated to V3"); - } else { - log::info!("Storage `pallet-gear-gas` was already migrated to V3"); - } - - Ok(()) - } -} - -fn translate(node_key: Key, node: v2::GasNode) -> Result, Error> { - log::info!("Translating {node_key:?} node"); - - let new_node = match node { - v2::GasNode::::Cut { id, value, lock } => NodeOf::::Cut { - id, - multiplier: MULTIPLIER, - value, - lock, - }, - v2::GasNode::::External { - id, - value, - lock, - system_reserve, - refs, - consumed, - deposit, - } => NodeOf::::External { - id, - multiplier: MULTIPLIER, - value, - lock, - system_reserve, - refs, - consumed, - deposit, - }, - v2::GasNode::::Reserved { - id, - value, - lock, - refs, - consumed, - } => NodeOf::::Reserved { - id, - multiplier: MULTIPLIER, - value, - lock, - refs, - consumed, - }, - v2::GasNode::::SpecifiedLocal { - parent, - value, - lock, - system_reserve, - refs, - consumed, - } => NodeOf::::SpecifiedLocal { - parent, - root: v2::root(node_key, node)?, - value, - lock, - system_reserve, - refs, - consumed, - }, - v2::GasNode::::UnspecifiedLocal { - parent, - lock, - system_reserve, - } => NodeOf::::UnspecifiedLocal { - parent, - root: v2::root(node_key, node)?, - lock, - system_reserve, - }, - }; - - Ok(new_node) -} - -mod v2 { - use crate::{AccountIdOf, Balance, Config, Error, Key, Pallet}; - use common::gas_provider::{ChildrenRefs, GasNodeId, NodeLock}; - use core::marker::PhantomData; - use frame_support::{ - storage::types::StorageMap, - traits::{PalletInfo, StorageInstance}, - Identity, - }; - use gear_core::ids::{MessageId, ReservationId}; - use parity_scale_codec::{Decode, Encode}; - - pub type GasNode = GasNodeImpl, GasNodeId, Balance>; - - pub struct GasNodesPrefix(PhantomData); - - impl StorageInstance for GasNodesPrefix { - const STORAGE_PREFIX: &'static str = "GasNodes"; - - fn pallet_prefix() -> &'static str { - <::PalletInfo as PalletInfo>::name::>() - .expect("No name found for the pallet in the runtime!") - } - } - - pub type GasNodes = StorageMap, Identity, Key, GasNode>; - - #[derive(Encode, Decode, Debug)] - pub enum GasNodeImpl { - External { - id: ExternalId, - value: Balance, - lock: NodeLock, - system_reserve: Balance, - refs: ChildrenRefs, - consumed: bool, - deposit: bool, - }, - - Cut { - id: ExternalId, - value: Balance, - lock: NodeLock, - }, - - Reserved { - id: ExternalId, - value: Balance, - lock: NodeLock, - refs: ChildrenRefs, - consumed: bool, - }, - - SpecifiedLocal { - parent: Id, - value: Balance, - lock: NodeLock, - system_reserve: Balance, - refs: ChildrenRefs, - consumed: bool, - }, - - UnspecifiedLocal { - parent: Id, - lock: NodeLock, - system_reserve: Balance, - }, - } - - impl GasNodeImpl { - pub fn parent(&self) -> Option { - match self { - Self::External { .. } | Self::Cut { .. } | Self::Reserved { .. } => None, - Self::SpecifiedLocal { parent, .. } | Self::UnspecifiedLocal { parent, .. } => { - Some(*parent) - } - } - } - } - - pub fn root(mut node_key: Key, mut node: GasNode) -> Result> { - log::trace!("Looking for root of {node_key:?} ({node:?}"); - - while let Some(parent) = node.parent() { - node_key = parent; - node = GasNodes::::get(node_key).ok_or(Error::::ParentIsLost)?; - } - - log::trace!("Root found: {node_key:?}"); - - Ok(node_key) - } -} diff --git a/pallets/gear-bank/Cargo.toml b/pallets/gear-bank/Cargo.toml index 0872ba22114..7075b18ace2 100644 --- a/pallets/gear-bank/Cargo.toml +++ b/pallets/gear-bank/Cargo.toml @@ -1,9 +1,11 @@ [package] name = "pallet-gear-bank" -version = "1.0.0" +version.workspace = true authors.workspace = true edition.workspace = true license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] parity-scale-codec = { workspace = true, features = ["derive"] } diff --git a/pallets/gear-debug/Cargo.toml b/pallets/gear-debug/Cargo.toml index b50cc788401..af5b894aecf 100644 --- a/pallets/gear-debug/Cargo.toml +++ b/pallets/gear-debug/Cargo.toml @@ -1,12 +1,11 @@ [package] name = "pallet-gear-debug" -version = "2.0.0" -authors = ['Gear Technologies'] -edition = '2021' +version.workspace = true +authors.workspace = true +edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" -description = "Gear main pallet" +homepage.workspace = true +repository.workspace = true readme = "README.md" [package.metadata.docs.rs] @@ -46,7 +45,7 @@ pallet-gear-bank = { workspace = true, features = ["std"] } pallet-gear-gas = { workspace = true, features = ["std"] } pallet-gear-messenger = { workspace = true, features = ["std"] } pallet-gear-scheduler = { workspace = true, features = ["std"] } -pallet-gear-program = { workspace = true, features = ["debug-mode", "std"] } +pallet-gear-program = { workspace = true, features = ["dev", "std"] } gear-wasm-instrument.workspace = true demo-vec.workspace = true test-syscalls.workspace = true diff --git a/pallets/gear-debug/src/tests/mod.rs b/pallets/gear-debug/src/tests/mod.rs index 66d5b8b57ef..2008ae84895 100644 --- a/pallets/gear-debug/src/tests/mod.rs +++ b/pallets/gear-debug/src/tests/mod.rs @@ -159,7 +159,7 @@ fn debug_mode_works() { ) .expect("Failed to submit program"); - // Enable debug-mode + // Enable debug mode. DebugMode::::put(true); run_to_block(2, None); @@ -528,7 +528,7 @@ fn check_not_allocated_pages() { 0_u128, )); - // Enable debug-mode + // Enable debug mode. DebugMode::::put(true); run_to_block(2, None); @@ -756,7 +756,7 @@ fn check_changed_pages_in_storage() { 0_u128, )); - // Enable debug-mode + // Enable debug mode. DebugMode::::put(true); run_to_block(2, None); @@ -886,7 +886,7 @@ fn check_gear_stack_end() { 0_u128, )); - // Enable debug-mode + // Enable debug mode. DebugMode::::put(true); run_to_block(2, None); diff --git a/pallets/gear-messenger/Cargo.toml b/pallets/gear-messenger/Cargo.toml index ba69981ea20..8037b76a09f 100644 --- a/pallets/gear-messenger/Cargo.toml +++ b/pallets/gear-messenger/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "pallet-gear-messenger" -version = "1.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" description = "Gear pallet to work with messages" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true readme = "README.md" [package.metadata.docs.rs] diff --git a/pallets/gear-program/Cargo.toml b/pallets/gear-program/Cargo.toml index e66e32b9fa3..72b9afd28e1 100644 --- a/pallets/gear-program/Cargo.toml +++ b/pallets/gear-program/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "pallet-gear-program" -version = "2.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" description = "Gear pallet to work with programs" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true readme = "README.md" [package.metadata.docs.rs] @@ -55,4 +55,4 @@ std = [ "primitive-types/std", ] try-runtime = ["frame-support/try-runtime"] -debug-mode = [] +dev = [] diff --git a/pallets/gear-program/src/lib.rs b/pallets/gear-program/src/lib.rs index 8d6e8c0cea3..281366bac31 100644 --- a/pallets/gear-program/src/lib.rs +++ b/pallets/gear-program/src/lib.rs @@ -145,7 +145,7 @@ pub mod pallet { storage::*, CodeMetadata, Program, }; - #[cfg(feature = "debug-mode")] + #[cfg(feature = "dev")] use frame_support::storage::PrefixIterator; use frame_support::{ dispatch::EncodeLike, pallet_prelude::*, traits::StorageVersion, StoragePrefixedMap, @@ -388,7 +388,7 @@ pub mod pallet { type SessionMemoryPages = SessionMemoryPagesWrap; } - #[cfg(feature = "debug-mode")] + #[cfg(feature = "dev")] impl IterableMap<(ProgramId, Program>)> for pallet::Pallet { type DrainIter = PrefixIterator<(ProgramId, Program>)>; type Iter = PrefixIterator<(ProgramId, Program>)>; diff --git a/pallets/gear-scheduler/Cargo.toml b/pallets/gear-scheduler/Cargo.toml index 58b1be5353f..b8d9a29ccb6 100644 --- a/pallets/gear-scheduler/Cargo.toml +++ b/pallets/gear-scheduler/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "pallet-gear-scheduler" -version = "1.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" description = "Gear pallet to work with delayed tasks" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true readme = "README.md" [package.metadata.docs.rs] diff --git a/pallets/gear-scheduler/src/tests.rs b/pallets/gear-scheduler/src/tests.rs index d2ba06af84f..58a0285d026 100644 --- a/pallets/gear-scheduler/src/tests.rs +++ b/pallets/gear-scheduler/src/tests.rs @@ -89,6 +89,7 @@ fn populate_wl_from( (mid, pid) } +#[track_caller] fn task_and_wl_message_exist( mid: impl Into, pid: impl Into, @@ -100,9 +101,7 @@ fn task_and_wl_message_exist( let ts = TaskPoolOf::::contains(&bn, &ScheduledTask::RemoveFromWaitlist(pid, mid)); let wl = WaitlistOf::::contains(&pid, &mid); - if ts != wl { - panic!("Logic invalidated"); - } + assert_eq!(ts, wl, "Logic invalidated"); ts } @@ -196,12 +195,14 @@ fn gear_handles_tasks() { ); assert_eq!(GearBank::account_total(&USER_1), gas_price(DEFAULT_GAS)); + let task = ScheduledTask::RemoveFromWaitlist(Default::default(), Default::default()); + let task_gas = pallet_gear::manager::get_maximum_task_gas::(&task); // Check if task and message got processed in block `bn`. run_to_block(bn, Some(u64::MAX)); // Read of the first block of incomplete tasks and write for removal of task. assert_eq!( GasAllowanceOf::::get(), - u64::MAX - db_r_w(1, 1).ref_time() + u64::MAX - db_r_w(1, 1).ref_time() - task_gas ); // Storages checking. @@ -298,7 +299,9 @@ fn gear_handles_outdated_tasks() { // Check if task and message got processed before start of block `bn`. // But due to the low gas allowance, we may process the only first task. - run_to_block(bn, Some(db_r_w(1, 2).ref_time() + 1)); + let task = ScheduledTask::RemoveFromWaitlist(Default::default(), Default::default()); + let task_gas = pallet_gear::manager::get_maximum_task_gas::(&task); + run_to_block(bn, Some(db_r_w(2, 2).ref_time() + task_gas + 1)); // Read of the first block of incomplete tasks, write to it afterwards + single task processing. assert_eq!(GasAllowanceOf::::get(), 1); @@ -329,7 +332,7 @@ fn gear_handles_outdated_tasks() { // Delete of the first block of incomplete tasks + single task processing. assert_eq!( GasAllowanceOf::::get(), - u64::MAX - db_r_w(0, 2).ref_time() + u64::MAX - db_r_w(0, 2).ref_time() - task_gas ); let cost2 = wl_cost_for(bn + 1 - initial_block); diff --git a/pallets/gear-voucher/Cargo.toml b/pallets/gear-voucher/Cargo.toml index 7243aba712f..95a87591564 100644 --- a/pallets/gear-voucher/Cargo.toml +++ b/pallets/gear-voucher/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "pallet-gear-voucher" -version = "1.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" description = "Gear pallet implementing payment-voucher like functionality" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true readme = "README.md" [package.metadata.docs.rs] diff --git a/pallets/gear/Cargo.toml b/pallets/gear/Cargo.toml index efcf988b0a5..ac6f96b0a64 100644 --- a/pallets/gear/Cargo.toml +++ b/pallets/gear/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "pallet-gear" -version = "2.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" description = "Gear main pallet" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true readme = "README.md" [package.metadata.docs.rs] @@ -32,7 +32,7 @@ gear-core.workspace = true gear-core-errors.workspace = true gear-backend-common.workspace = true gear-backend-sandbox.workspace = true -pallet-gear-proc-macro = { version = "2.0.0", path = "proc-macro" } +pallet-gear-proc-macro = { path = "proc-macro" } gsys = { workspace = true, optional = true } pallet-gear-voucher.workspace = true pallet-gear-bank.workspace = true @@ -60,6 +60,11 @@ sp-consensus-slots = { workspace = true, optional = true } test-syscalls = { workspace = true, optional = true } demo-read-big-state = { workspace = true, optional = true } demo-proxy = { workspace = true, optional = true } +demo-reserve-gas = { workspace = true, optional = true } +demo-delayed-sender = { workspace = true, optional = true } +demo-constructor = { workspace = true, optional = true } +demo-waiter = { workspace = true, optional = true } +demo-init-wait = { workspace = true, optional = true } [dev-dependencies] wabt.workspace = true @@ -154,6 +159,11 @@ std = [ "test-syscalls?/std", "demo-read-big-state?/std", "demo-proxy?/std", + "demo-reserve-gas?/std", + "demo-delayed-sender?/std", + "demo-constructor?/std", + "demo-waiter?/std", + "demo-init-wait?/std", "gear-runtime-interface/std", ] runtime-benchmarks = [ @@ -172,6 +182,11 @@ runtime-benchmarks = [ "demo-read-big-state/wasm-wrapper", "demo-proxy/wasm-wrapper", "gsys", + "demo-reserve-gas/wasm-wrapper", + "demo-delayed-sender/wasm-wrapper", + "demo-constructor/wasm-wrapper", + "demo-waiter/wasm-wrapper", + "demo-init-wait/wasm-wrapper", ] runtime-benchmarks-checkers = [] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/gear/proc-macro/Cargo.toml b/pallets/gear/proc-macro/Cargo.toml index b325315e902..8100f907371 100644 --- a/pallets/gear/proc-macro/Cargo.toml +++ b/pallets/gear/proc-macro/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "pallet-gear-proc-macro" -version = "2.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" description = "Procedural macros used in pallet_gear" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/pallets/gear/rpc/Cargo.toml b/pallets/gear/rpc/Cargo.toml index 47e51e985f9..366c3bb3a48 100644 --- a/pallets/gear/rpc/Cargo.toml +++ b/pallets/gear/rpc/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "pallet-gear-rpc" -version = "2.0.0" +version.workspace = true authors.workspace = true edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true [dependencies] jsonrpsee = { workspace = true, features = ["server", "macros"] } diff --git a/pallets/gear/rpc/runtime-api/Cargo.toml b/pallets/gear/rpc/runtime-api/Cargo.toml index b4f28c1c773..252dc9e5d8e 100644 --- a/pallets/gear/rpc/runtime-api/Cargo.toml +++ b/pallets/gear/rpc/runtime-api/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "pallet-gear-rpc-runtime-api" -version = "2.0.0" -authors = ['Gear Technologies'] -edition = '2021' +version.workspace = true +authors.workspace = true +edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true [dependencies] sp-api.workspace = true diff --git a/pallets/gear/src/benchmarking/mod.rs b/pallets/gear/src/benchmarking/mod.rs index 089b6ba2799..354379bfe16 100644 --- a/pallets/gear/src/benchmarking/mod.rs +++ b/pallets/gear/src/benchmarking/mod.rs @@ -39,6 +39,7 @@ mod code; mod sandbox; mod syscalls; +mod tasks; mod utils; use syscalls::Benches; @@ -59,7 +60,7 @@ use crate::{ schedule::{API_BENCHMARK_BATCH_SIZE, INSTR_BENCHMARK_BATCH_SIZE}, BalanceOf, BenchmarkStorage, Call, Config, CurrencyOf, Event, ExecutionEnvironment, Ext as Externalities, GasHandlerOf, GearBank, MailboxOf, Pallet as Gear, Pallet, - ProgramStorageOf, QueueOf, RentFreePeriodOf, ResumeMinimalPeriodOf, Schedule, + ProgramStorageOf, QueueOf, RentFreePeriodOf, ResumeMinimalPeriodOf, Schedule, TaskPoolOf, }; use ::alloc::{ collections::{BTreeMap, BTreeSet}, @@ -68,6 +69,7 @@ use ::alloc::{ use common::{ self, benchmarking, paused_program_storage::SessionId, + scheduler::{ScheduledTask, TaskHandler}, storage::{Counter, *}, ActiveProgram, CodeMetadata, CodeStorage, GasTree, Origin, PausedProgramStorage, ProgramStorage, ReservableTree, @@ -241,6 +243,31 @@ where .unwrap_or_else(|e| unreachable!("core-processor logic invalidated: {}", e)) } +fn get_last_session_id() -> Option { + find_latest_event::(|event| match event { + Event::ProgramResumeSessionStarted { session_id, .. } => Some(session_id), + _ => None, + }) +} + +pub fn find_latest_event(mapping_filter: F) -> Option +where + T: Config, + F: Fn(Event) -> Option, +{ + SystemPallet::::events() + .into_iter() + .rev() + .filter_map(|event_record| { + let event = <::RuntimeEvent as From<_>>::from(event_record.event); + let event: Result, _> = event.try_into(); + + event.ok() + }) + .find_map(mapping_filter) +} + +#[track_caller] fn resume_session_prepare( c: u32, program_id: ProgramId, @@ -261,14 +288,6 @@ where ) .expect("failed to start resume session"); - let event_record = SystemPallet::::events().pop().unwrap(); - let event = <::RuntimeEvent as From<_>>::from(event_record.event); - let event: Result, _> = event.try_into(); - let session_id = match event { - Ok(Event::ProgramResumeSessionStarted { session_id, .. }) => session_id, - _ => unreachable!(), - }; - let memory_pages = { let mut pages = Vec::with_capacity(c as usize); for i in 0..c { @@ -278,7 +297,7 @@ where pages }; - (session_id, memory_pages) + (get_last_session_id::().unwrap(), memory_pages) } /// An instantiated and deployed program. @@ -2741,6 +2760,89 @@ benchmarks! { sbox.invoke(); } + tasks_remove_resume_session { + let session_id = tasks::remove_resume_session::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.remove_resume_session(session_id); + } + + tasks_remove_gas_reservation { + let (program_id, reservation_id) = tasks::remove_gas_reservation::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.remove_gas_reservation(program_id, reservation_id); + } + + tasks_send_user_message_to_mailbox { + let message_id = tasks::send_user_message::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.send_user_message(message_id, true); + } + + tasks_send_user_message { + let message_id = tasks::send_user_message::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.send_user_message(message_id, false); + } + + tasks_send_dispatch { + let message_id = tasks::send_dispatch::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.send_dispatch(message_id); + } + + tasks_wake_message { + let (program_id, message_id) = tasks::wake_message::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.wake_message(program_id, message_id); + } + + tasks_wake_message_no_wake { + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.wake_message(Default::default(), Default::default()); + } + + tasks_remove_from_waitlist { + let (program_id, message_id) = tasks::remove_from_waitlist::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.remove_from_waitlist(program_id, message_id); + } + + tasks_remove_from_mailbox { + let (user, message_id) = tasks::remove_from_mailbox::(); + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.remove_from_mailbox(T::AccountId::from_origin(user.into_origin()), message_id); + } + + tasks_pause_program { + let c in 0 .. (MAX_PAGES - 1) * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u32; + + let code = benchmarking::generate_wasm2(0.into()).unwrap(); + let program_id = tasks::pause_program_prepare::(c, code); + + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.pause_program(program_id); + } + + tasks_pause_program_uninited { + let c in 0 .. (MAX_PAGES - 1) * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u32; + + let program_id = tasks::pause_program_prepare::(c, demo_init_wait::WASM_BINARY.to_vec()); + + let mut ext_manager = ExtManager::::default(); + }: { + ext_manager.pause_program(program_id); + } + // This is no benchmark. It merely exist to have an easy way to pretty print the currently // configured `Schedule` during benchmark development. // It can be outputted using the following command: diff --git a/pallets/gear/src/benchmarking/tasks.rs b/pallets/gear/src/benchmarking/tasks.rs new file mode 100644 index 00000000000..6447b509f01 --- /dev/null +++ b/pallets/gear/src/benchmarking/tasks.rs @@ -0,0 +1,371 @@ +// 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. + +use super::*; +use gear_core::ids::ReservationId; + +#[track_caller] +fn send_user_message_prepare(delay: u32) +where + T: Config, + T::AccountId: Origin, +{ + use demo_delayed_sender::WASM_BINARY; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + Gear::::upload_program( + RawOrigin::Signed(caller).into(), + WASM_BINARY.to_vec(), + salt, + delay.encode(), + 100_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + Gear::::process_queue(Default::default()); +} + +#[track_caller] +pub(super) fn pause_program_prepare(c: u32, code: Vec) -> ProgramId +where + T: Config, + T::AccountId: Origin, +{ + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 400_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(&code), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller).into(), + code, + salt, + b"init_payload".to_vec(), + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + Gear::::process_queue(Default::default()); + + let memory_page = { + let mut page = PageBuf::new_zeroed(); + page[0] = 1; + + page + }; + + for i in 0..c { + ProgramStorageOf::::set_program_page_data( + program_id, + GearPage::from(i as u16), + memory_page.clone(), + ); + } + + ProgramStorageOf::::update_active_program(program_id, |program| { + program.pages_with_data = BTreeSet::from_iter((0..c).map(|i| GearPage::from(i as u16))); + + let wasm_pages = (c as usize * GEAR_PAGE_SIZE) / WASM_PAGE_SIZE; + program.allocations = + BTreeSet::from_iter((0..wasm_pages).map(|i| WasmPage::from(i as u16))); + }) + .expect("program should exist"); + + program_id +} + +#[track_caller] +pub(super) fn remove_resume_session() -> SessionId +where + T: Config, + T::AccountId: Origin, +{ + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let code = benchmarking::generate_wasm2(16.into()).unwrap(); + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(&code), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller.clone()).into(), + code, + salt, + b"init_payload".to_vec(), + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + init_block::(None); + + ProgramStorageOf::::pause_program(program_id, 100u32.into()).unwrap(); + + Gear::::resume_session_init( + RawOrigin::Signed(caller).into(), + program_id, + Default::default(), + CodeId::default(), + ) + .expect("failed to start resume session"); + + get_last_session_id::().unwrap() +} + +#[track_caller] +pub(super) fn remove_gas_reservation() -> (ProgramId, ReservationId) +where + T: Config, + T::AccountId: Origin, +{ + use demo_reserve_gas::{InitAction, WASM_BINARY}; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(WASM_BINARY), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller).into(), + WASM_BINARY.to_vec(), + salt, + InitAction::Normal(vec![(50_000, 100)]).encode(), + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + Gear::::process_queue(Default::default()); + + let program: ActiveProgram<_> = ProgramStorageOf::::get_program(program_id) + .expect("program should exist") + .try_into() + .expect("program should be active"); + + ( + program_id, + program + .gas_reservation_map + .first_key_value() + .map(|(k, _v)| *k) + .unwrap(), + ) +} + +#[track_caller] +pub(super) fn send_user_message() -> MessageId +where + T: Config, + T::AccountId: Origin, +{ + let delay = 1u32; + send_user_message_prepare::(delay); + + let task = TaskPoolOf::::iter_prefix_keys(Gear::::block_number() + delay.into()) + .next() + .expect("task should be scheduled"); + let (message_id, to_mailbox) = match task { + ScheduledTask::SendUserMessage { + message_id, + to_mailbox, + } => (message_id, to_mailbox), + _ => unreachable!("task should be SendUserMessage"), + }; + assert!(to_mailbox); + + message_id +} + +#[track_caller] +pub(super) fn send_dispatch() -> MessageId +where + T: Config, + T::AccountId: Origin, +{ + use demo_constructor::{Call, Calls, Scheme, WASM_BINARY}; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(WASM_BINARY), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller.clone()).into(), + WASM_BINARY.to_vec(), + salt, + Scheme::empty().encode(), + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + let delay = 1u32; + let calls = Calls::builder().add_call(Call::Send( + <[u8; 32]>::from(program_id.into_origin()).into(), + [].into(), + Some(0u64.into()), + 0u128.into(), + delay.into(), + )); + Gear::::send_message( + RawOrigin::Signed(caller).into(), + program_id, + calls.encode(), + 10_000_000_000, + 0u32.into(), + false, + ) + .expect("failed to send message"); + + Gear::::process_queue(Default::default()); + + let task = TaskPoolOf::::iter_prefix_keys(Gear::::block_number() + delay.into()) + .next() + .unwrap(); + + match task { + ScheduledTask::SendDispatch(message_id) => message_id, + _ => unreachable!(), + } +} + +#[track_caller] +pub(super) fn wake_message() -> (ProgramId, MessageId) +where + T: Config, + T::AccountId: Origin, +{ + use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(WASM_BINARY), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller.clone()).into(), + WASM_BINARY.to_vec(), + salt, + vec![], + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + let delay = 10u32; + Gear::::send_message( + RawOrigin::Signed(caller).into(), + program_id, + Command::Wait(WaitSubcommand::WaitFor(delay)).encode(), + 10_000_000_000, + 0u32.into(), + false, + ) + .expect("failed to send message"); + + Gear::::process_queue(Default::default()); + + let task = TaskPoolOf::::iter_prefix_keys(Gear::::block_number() + delay.into()) + .next() + .unwrap(); + let (_program_id, message_id) = match task { + ScheduledTask::WakeMessage(program_id, message_id) => (program_id, message_id), + _ => unreachable!(), + }; + + (program_id, message_id) +} + +#[track_caller] +pub(super) fn remove_from_waitlist() -> (ProgramId, MessageId) +where + T: Config, + T::AccountId: Origin, +{ + use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; + + let caller = benchmarking::account("caller", 0, 0); + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + + init_block::(None); + + let salt = vec![]; + let program_id = ProgramId::generate(CodeId::generate(WASM_BINARY), &salt); + Gear::::upload_program( + RawOrigin::Signed(caller.clone()).into(), + WASM_BINARY.to_vec(), + salt, + vec![], + 10_000_000_000, + 0u32.into(), + ) + .expect("submit program failed"); + + Gear::::send_message( + RawOrigin::Signed(caller).into(), + program_id, + Command::Wait(WaitSubcommand::Wait).encode(), + 10_000_000_000, + 0u32.into(), + false, + ) + .expect("failed to send message"); + + Gear::::process_queue(Default::default()); + + let expiration = find_latest_event::(|event| match event { + Event::MessageWaited { expiration, .. } => Some(expiration), + _ => None, + }) + .expect("message should be waited"); + + let task = TaskPoolOf::::iter_prefix_keys(expiration) + .next() + .unwrap(); + let (_program_id, message_id) = match task { + ScheduledTask::RemoveFromWaitlist(program_id, message_id) => (program_id, message_id), + _ => unreachable!(), + }; + + (program_id, message_id) +} + +#[track_caller] +pub(super) fn remove_from_mailbox() -> (ProgramId, MessageId) +where + T: Config, + T::AccountId: Origin, +{ + send_user_message_prepare::(0u32); + + find_latest_event::(|event| match event { + Event::UserMessageSent { message, .. } => Some((message.destination(), message.id())), + _ => None, + }) + .expect("message should be sent") +} diff --git a/pallets/gear/src/lib.rs b/pallets/gear/src/lib.rs index e236c02de33..0db25c86d60 100644 --- a/pallets/gear/src/lib.rs +++ b/pallets/gear/src/lib.rs @@ -934,7 +934,6 @@ pub mod pallet { ..=current_bn.saturated_into()) .map(|block| block.saturated_into::>()); for bn in missing_blocks { - // Tasks drain iterator. let tasks = TaskPoolOf::::drain_prefix_keys(bn); // Checking gas allowance. @@ -948,30 +947,63 @@ pub mod pallet { } // Iterating over tasks, scheduled on `bn`. + let mut last_task = None; for task in tasks { - log::debug!("Processing task: {:?}", task); - // Decreasing gas allowance due to DB deletion. GasAllowanceOf::::decrease(DbWeightOf::::get().writes(1).ref_time()); - // Processing task. - // - // NOTE: Gas allowance decrease should be implemented - // inside `TaskHandler` trait and/or inside other - // generic types, which interact with storage. - task.process_with(ext_manager); + // gas required to process task. + let max_task_gas = manager::get_maximum_task_gas::(&task); + log::debug!("Processing task: {task:?}, max gas = {max_task_gas}"); // Checking gas allowance. // - // Making sure we have gas to remove next task - // or update the first block of incomplete tasks. - if GasAllowanceOf::::get() <= DbWeightOf::::get().writes(2).ref_time() { + // Making sure we have gas to process the current task + // and update the first block of incomplete tasks. + if GasAllowanceOf::::get().saturating_sub(max_task_gas) + <= DbWeightOf::::get().writes(1).ref_time() + { + // Since the task is not processed write DB cost should be refunded. + // In the same time gas allowance should be charged for read DB cost. + GasAllowanceOf::::put( + GasAllowanceOf::::get() + .saturating_add(DbWeightOf::::get().writes(1).ref_time()) + .saturating_sub(DbWeightOf::::get().reads(1).ref_time()), + ); + + last_task = Some(task); + log::debug!("Not enough gas to process task at: {bn:?}"); + + break; + } + + // Processing task and update allowance of gas. + let task_gas = task.process_with(ext_manager); + GasAllowanceOf::::decrease(task_gas); + + // Check that there is enough gas allowance to query next task and update the first block of incomplete tasks. + if GasAllowanceOf::::get() + <= DbWeightOf::::get().reads_writes(1, 1).ref_time() + { stopped_at = Some(bn); - log::debug!("Stopping processing tasks at: {stopped_at:?}"); + log::debug!("Stopping processing tasks at (read next): {stopped_at:?}"); break; } } + if let Some(task) = last_task { + stopped_at = Some(bn); + + // since there is the overlay mechanism we don't need to subtract write cost + // from gas allowance on task insertion. + GasAllowanceOf::::put( + GasAllowanceOf::::get() + .saturating_add(DbWeightOf::::get().writes(1).ref_time()), + ); + TaskPoolOf::::add(bn, task) + .unwrap_or_else(|e| unreachable!("Scheduling logic invalidated! {:?}", e)); + } + // Stopping iteration over blocks if no resources left. if stopped_at.is_some() { break; diff --git a/pallets/gear/src/manager/task.rs b/pallets/gear/src/manager/task.rs index 41a399265f2..54f6eb85f2b 100644 --- a/pallets/gear/src/manager/task.rs +++ b/pallets/gear/src/manager/task.rs @@ -17,8 +17,8 @@ // along with this program. If not, see . use crate::{ - manager::ExtManager, Config, DispatchStashOf, Event, Pallet, ProgramStorageOf, QueueOf, - TaskPoolOf, WaitlistOf, + manager::ExtManager, weights::WeightInfo, Config, DbWeightOf, DispatchStashOf, Event, Pallet, + ProgramStorageOf, QueueOf, TaskPoolOf, WaitlistOf, }; use alloc::string::ToString; use common::{ @@ -29,21 +29,71 @@ use common::{ paused_program_storage::SessionId, scheduler::*, storage::*, - Origin, PausedProgramStorage, Program, ProgramStorage, + ActiveProgram, Gas, Origin, PausedProgramStorage, Program, ProgramState, ProgramStorage, }; +use core::cmp; use gear_core::{ + code::MAX_WASM_PAGE_COUNT, ids::{CodeId, MessageId, ProgramId, ReservationId}, message::{DispatchKind, ReplyMessage}, + pages::{GEAR_PAGE_SIZE, WASM_PAGE_SIZE}, }; use gear_core_errors::{ErrorReplyReason, SignalCode}; use sp_core::Get; use sp_runtime::Saturating; +pub fn get_maximum_task_gas(task: &ScheduledTask) -> Gas { + use ScheduledTask::*; + + match task { + PauseProgram(_) => { + // TODO: #3079 + if ::ProgramRentEnabled::get() { + let count = + u32::from(MAX_WASM_PAGE_COUNT * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u16 / 2); + cmp::max( + ::WeightInfo::tasks_pause_program(count).ref_time(), + ::WeightInfo::tasks_pause_program_uninited(count).ref_time(), + ) + } else { + DbWeightOf::::get().writes(2).ref_time() + } + } + RemoveCode(_) => todo!("#646"), + RemoveFromMailbox(_, _) => { + ::WeightInfo::tasks_remove_from_mailbox().ref_time() + } + RemoveFromWaitlist(_, _) => { + ::WeightInfo::tasks_remove_from_waitlist().ref_time() + } + RemovePausedProgram(_) => todo!("#646"), + WakeMessage(_, _) => cmp::max( + ::WeightInfo::tasks_wake_message().ref_time(), + ::WeightInfo::tasks_wake_message_no_wake().ref_time(), + ), + SendDispatch(_) => ::WeightInfo::tasks_send_dispatch().ref_time(), + SendUserMessage { .. } => cmp::max( + ::WeightInfo::tasks_send_user_message_to_mailbox().ref_time(), + ::WeightInfo::tasks_send_user_message().ref_time(), + ), + RemoveGasReservation(_, _) => { + ::WeightInfo::tasks_remove_gas_reservation().ref_time() + } + RemoveResumeSession(_) => { + ::WeightInfo::tasks_remove_resume_session().ref_time() + } + } +} + impl TaskHandler for ExtManager where T::AccountId: Origin, { - fn pause_program(&mut self, program_id: ProgramId) { + fn pause_program(&mut self, program_id: ProgramId) -> Gas { + // + // TODO: #3079 + // + if !::ProgramRentEnabled::get() { log::debug!("Program rent logic is disabled."); @@ -63,13 +113,17 @@ where TaskPoolOf::::add(expiration_block, task) .unwrap_or_else(|e| unreachable!("Scheduling logic invalidated! {:?}", e)); - return; + return DbWeightOf::::get().writes(1).ref_time(); } - let program = ProgramStorageOf::::get_program(program_id) - .unwrap_or_else(|| unreachable!("Program to pause not found.")); + let program: ActiveProgram<_> = ProgramStorageOf::::get_program(program_id) + .unwrap_or_else(|| unreachable!("Program to pause not found.")) + .try_into() + .unwrap_or_else(|e| unreachable!("Pause program task logic corrupted: {e:?}")); - let Some(init_message_id) = program.is_uninitialized() else { + let pages_with_data = program.pages_with_data.len() as u32; + + let ProgramState::Uninitialized{ message_id: init_message_id } = program.state else { // pause initialized program let gas_reservation_map = ProgramStorageOf::::pause_program(program_id, Pallet::::block_number()) @@ -90,7 +144,10 @@ where change: ProgramChangeKind::Paused, }); - return; + let gas = ::WeightInfo::tasks_pause_program(pages_with_data).ref_time(); + log::trace!("Task gas: tasks_pause_program = {gas}"); + + return gas; }; // terminate uninitialized program @@ -141,13 +198,19 @@ where id: program_id, change: ProgramChangeKind::Terminated, }); + + let gas = + ::WeightInfo::tasks_pause_program_uninited(pages_with_data).ref_time(); + log::trace!("Task gas: tasks_pause_program_uninited = {gas}"); + + gas } - fn remove_code(&mut self, _code_id: CodeId) { - todo!("#646"); + fn remove_code(&mut self, _code_id: CodeId) -> Gas { + todo!("#646") } - fn remove_from_mailbox(&mut self, user_id: T::AccountId, message_id: MessageId) { + fn remove_from_mailbox(&mut self, user_id: T::AccountId, message_id: MessageId) -> Gas { // Read reason. let reason = UserMessageReadSystemReason::OutOfRent.into_reason(); @@ -169,9 +232,14 @@ where // Queueing dispatch. QueueOf::::queue(dispatch) .unwrap_or_else(|e| unreachable!("Message queue corrupted! {:?}", e)); + + let gas = ::WeightInfo::tasks_remove_from_mailbox().ref_time(); + log::trace!("Task gas: tasks_remove_from_mailbox = {gas}"); + + gas } - 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 { // Wake reason. let reason = MessageWokenSystemReason::OutOfRent.into_reason(); @@ -240,24 +308,42 @@ where let origin = waitlisted.source(); Self::process_failed_init(program_id, origin, true); } + + let gas = ::WeightInfo::tasks_remove_from_waitlist().ref_time(); + log::trace!("Task gas: tasks_remove_from_waitlist = {gas}"); + + gas } - fn remove_paused_program(&mut self, _program_id: ProgramId) { - todo!("#646"); + fn remove_paused_program(&mut self, _program_id: ProgramId) -> Gas { + todo!("#646") } - fn wake_message(&mut self, program_id: ProgramId, message_id: MessageId) { - if let Some(dispatch) = Pallet::::wake_dispatch( + fn wake_message(&mut self, program_id: ProgramId, message_id: MessageId) -> Gas { + match Pallet::::wake_dispatch( program_id, message_id, MessageWokenRuntimeReason::WakeCalled.into_reason(), ) { - QueueOf::::queue(dispatch) - .unwrap_or_else(|e| unreachable!("Message queue corrupted! {:?}", e)); + Some(dispatch) => { + QueueOf::::queue(dispatch) + .unwrap_or_else(|e| unreachable!("Message queue corrupted! {:?}", e)); + + let gas = ::WeightInfo::tasks_wake_message().ref_time(); + log::trace!("Task gas: tasks_wake_message = {gas}"); + + gas + } + None => { + let gas = ::WeightInfo::tasks_wake_message_no_wake().ref_time(); + log::trace!("Task gas: tasks_wake_message_no_wake = {gas}"); + + gas + } } } - fn send_dispatch(&mut self, stashed_message_id: MessageId) { + fn send_dispatch(&mut self, stashed_message_id: MessageId) -> Gas { // No validation required. If program doesn't exist, then NotExecuted appears. let (dispatch, hold_interval) = DispatchStashOf::::take(stashed_message_id) @@ -268,9 +354,14 @@ where QueueOf::::queue(dispatch) .unwrap_or_else(|e| unreachable!("Message queue corrupted! {:?}", e)); + + let gas = ::WeightInfo::tasks_send_dispatch().ref_time(); + log::trace!("Task gas: tasks_send_dispatch = {gas}"); + + gas } - 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 { // TODO: validate here destination and send error reply, if required. // Atm despite the fact that program may exist, message goes into mailbox / event. let (message, hold_interval) = DispatchStashOf::::take(stashed_message_id) @@ -285,15 +376,40 @@ where .try_into() .unwrap_or_else(|_| unreachable!("Signal message sent to user")); Pallet::::send_user_message_after_delay(message, to_mailbox); + + if to_mailbox { + let gas = ::WeightInfo::tasks_send_user_message_to_mailbox().ref_time(); + log::trace!("Task gas: tasks_send_user_message_to_mailbox = {gas}"); + + gas + } else { + let gas = ::WeightInfo::tasks_send_user_message().ref_time(); + log::trace!("Task gas: tasks_send_user_message = {gas}"); + + gas + } } - 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 { let _slot = Self::remove_gas_reservation_impl(program_id, reservation_id); + + let gas = ::WeightInfo::tasks_remove_gas_reservation().ref_time(); + log::trace!("Task gas: tasks_remove_gas_reservation = {gas}"); + + gas } - fn remove_resume_session(&mut self, session_id: SessionId) { - log::debug!("Execute task to remove resume session with session_id = {session_id}"); + fn remove_resume_session(&mut self, session_id: SessionId) -> Gas { ProgramStorageOf::::remove_resume_session(session_id) .unwrap_or_else(|e| unreachable!("ProgramStorage corrupted! {:?}", e)); + + let gas = ::WeightInfo::tasks_remove_resume_session().ref_time(); + log::trace!("Task gas: tasks_remove_resume_session = {gas}"); + + gas } } diff --git a/pallets/gear/src/mock.rs b/pallets/gear/src/mock.rs index e4f29b149e2..6ddddaa70ca 100644 --- a/pallets/gear/src/mock.rs +++ b/pallets/gear/src/mock.rs @@ -302,7 +302,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { pallet_balances::GenesisConfig:: { balances: vec![ (USER_1, 5_000_000_000_000_000_u128), - (USER_2, 200_000_000_000_000_u128), + (USER_2, 350_000_000_000_000_u128), (USER_3, 500_000_000_000_000_u128), (LOW_BALANCE_USER, 1_000_000_u128), (BLOCK_AUTHOR, 500_000_u128), diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index ae861d0d365..019d2ac293b 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -5118,7 +5118,7 @@ fn test_requeue_after_wait_for_timeout() { run_to_next_block(None); let duration = 10; - let payload = Command::SendAndWaitFor(duration, USER_1.into()).encode(); + let payload = Command::SendAndWaitFor(duration, USER_1.into_origin().into()).encode(); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), program_id, @@ -5189,7 +5189,7 @@ fn test_sending_waits() { // // Send message and then wait_for. let duration = 5; - let payload = Command::SendFor(USER_1.into(), duration).encode(); + let payload = Command::SendFor(USER_1.into_origin().into(), duration).encode(); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), @@ -5209,7 +5209,7 @@ fn test_sending_waits() { // // Send message and then wait_up_to. let duration = 10; - let payload = Command::SendUpTo(USER_1.into(), duration).encode(); + let payload = Command::SendUpTo(USER_1.into_origin().into(), duration).encode(); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), program_id, @@ -5228,7 +5228,7 @@ fn test_sending_waits() { // // Send message and then wait no_more, wake, wait no_more again. let duration = 10; - let payload = Command::SendUpToWait(USER_2.into(), duration).encode(); + let payload = Command::SendUpToWait(USER_2.into_origin().into(), duration).encode(); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), program_id, @@ -8809,6 +8809,8 @@ fn free_storage_hold_on_scheduler_overwhelm() { #[test] fn execution_over_blocks() { + const MAX_BLOCK: u64 = 10_000_000_000; + init_logger(); let assert_last_message = |src: [u8; 32], count: u128| { @@ -8849,7 +8851,7 @@ fn execution_over_blocks() { )); let in_one_block = get_last_program_id(); - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); // estimate start cost let pkg = Package::new(times, src); @@ -8870,7 +8872,7 @@ fn execution_over_blocks() { use demo_calc_hash_in_one_block::{Package, WASM_BINARY}; // We suppose that gas limit is less than gas allowance - let block_gas_limit = BlockGasLimitOf::::get() - 10000; + let block_gas_limit = MAX_BLOCK - 10_000; // Deploy demo-calc-hash-in-one-block. assert_ok!(Gear::upload_program( @@ -8887,30 +8889,31 @@ fn execution_over_blocks() { let src = [0; 32]; + let expected = 64; assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), in_one_block, - Package::new(128, src).encode(), + Package::new(expected, src).encode(), block_gas_limit, 0, false, )); - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); - assert_last_message([0; 32], 128); + assert_last_message([0; 32], expected); assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), in_one_block, - Package::new(17_384, src).encode(), + Package::new(1_024, src).encode(), block_gas_limit, 0, false, )); let message_id = get_last_message_id(); - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); assert_failed( message_id, @@ -8921,7 +8924,7 @@ fn execution_over_blocks() { new_test_ext().execute_with(|| { use demo_calc_hash::sha2_512_256; use demo_calc_hash_over_blocks::{Method, WASM_BINARY}; - let block_gas_limit = BlockGasLimitOf::::get(); + let block_gas_limit = MAX_BLOCK; let (_, calc_threshold) = estimate_gas_per_calc(); @@ -8931,26 +8934,26 @@ fn execution_over_blocks() { WASM_BINARY.to_vec(), DEFAULT_SALT.to_vec(), calc_threshold.encode(), - 10_000_000_000, + 9_000_000_000, 0, )); let over_blocks = get_last_program_id(); assert!(ProgramStorageOf::::program_exists(over_blocks)); - let (src, id, expected) = ([0; 32], sha2_512_256(b"42"), 16_384); + let (src, id, expected) = ([0; 32], sha2_512_256(b"42"), 512); // trigger calculation assert_ok!(Gear::send_message( RuntimeOrigin::signed(USER_1), over_blocks, Method::Start { src, id, expected }.encode(), - 10_000_000_000, + 9_000_000_000, 0, false, )); - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); let mut count = 0; loop { @@ -8970,7 +8973,7 @@ fn execution_over_blocks() { )); count += 1; - run_to_next_block(None); + run_to_next_block(Some(MAX_BLOCK)); } assert!(count > 1); diff --git a/pallets/gear/src/weights.rs b/pallets/gear/src/weights.rs index c52d1f58fac..3ad8efedec0 100644 --- a/pallets/gear/src/weights.rs +++ b/pallets/gear/src/weights.rs @@ -215,6 +215,17 @@ pub trait WeightInfo { fn instr_i32rotl(r: u32, ) -> Weight; fn instr_i64rotr(r: u32, ) -> Weight; fn instr_i32rotr(r: u32, ) -> Weight; + fn tasks_remove_resume_session() -> Weight; + fn tasks_remove_gas_reservation() -> Weight; + fn tasks_send_user_message_to_mailbox() -> Weight; + fn tasks_send_user_message() -> Weight; + fn tasks_send_dispatch() -> Weight; + fn tasks_wake_message() -> Weight; + fn tasks_wake_message_no_wake() -> Weight; + fn tasks_remove_from_waitlist() -> Weight; + fn tasks_remove_from_mailbox() -> Weight; + fn tasks_pause_program(c: u32, ) -> Weight; + fn tasks_pause_program_uninited(c: u32, ) -> Weight; fn allocation_cost() -> Weight; fn grow_cost() -> Weight; fn initial_cost() -> Weight; @@ -2062,6 +2073,116 @@ impl WeightInfo for SubstrateWeight { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 5_698_000 picoseconds. + Weight::from_parts(5_953_000, 4169) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1003` + // Estimated: `23637` + // Minimum execution time: 61_615_000 picoseconds. + Weight::from_parts(64_309_000, 23637) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `784` + // Estimated: `21534` + // Minimum execution time: 43_449_000 picoseconds. + Weight::from_parts(44_990_000, 21534) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `906` + // Estimated: `33891` + // Minimum execution time: 75_764_000 picoseconds. + Weight::from_parts(77_875_000, 33891) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `591` + // Estimated: `19885` + // Minimum execution time: 31_362_000 picoseconds. + Weight::from_parts(32_425_000, 19885) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `872` + // Estimated: `25908` + // Minimum execution time: 45_023_000 picoseconds. + Weight::from_parts(46_479_000, 25908) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_365_000 picoseconds. + Weight::from_parts(3_639_000, 3545) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1522` + // Estimated: `57192` + // Minimum execution time: 114_023_000 picoseconds. + Weight::from_parts(117_157_000, 57192) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1228` + // Estimated: `46026` + // Minimum execution time: 90_320_000 picoseconds. + Weight::from_parts(93_096_000, 46026) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2200 + c * (16400 ±0)` + // Estimated: `19363 + c * (84480 ±0)` + // Minimum execution time: 28_326_000 picoseconds. + Weight::from_parts(28_612_000, 19363) + // Standard Error: 73_191 + .saturating_add(Weight::from_parts(39_403_570, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3025 + c * (42 ±0)` + // Estimated: `59431 + c * (2947 ±0)` + // Minimum execution time: 86_517_000 picoseconds. + Weight::from_parts(78_047_954, 59431) + // Standard Error: 2_660 + .saturating_add(Weight::from_parts(1_060_607, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(13_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(9_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } // For backwards compatibility and tests @@ -3903,4 +4024,114 @@ impl WeightInfo for () { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 5_698_000 picoseconds. + Weight::from_parts(5_953_000, 4169) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1003` + // Estimated: `23637` + // Minimum execution time: 61_615_000 picoseconds. + Weight::from_parts(64_309_000, 23637) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `784` + // Estimated: `21534` + // Minimum execution time: 43_449_000 picoseconds. + Weight::from_parts(44_990_000, 21534) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `906` + // Estimated: `33891` + // Minimum execution time: 75_764_000 picoseconds. + Weight::from_parts(77_875_000, 33891) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `591` + // Estimated: `19885` + // Minimum execution time: 31_362_000 picoseconds. + Weight::from_parts(32_425_000, 19885) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `872` + // Estimated: `25908` + // Minimum execution time: 45_023_000 picoseconds. + Weight::from_parts(46_479_000, 25908) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_365_000 picoseconds. + Weight::from_parts(3_639_000, 3545) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1522` + // Estimated: `57192` + // Minimum execution time: 114_023_000 picoseconds. + Weight::from_parts(117_157_000, 57192) + .saturating_add(RocksDbWeight::get().reads(16_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1228` + // Estimated: `46026` + // Minimum execution time: 90_320_000 picoseconds. + Weight::from_parts(93_096_000, 46026) + .saturating_add(RocksDbWeight::get().reads(14_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2200 + c * (16400 ±0)` + // Estimated: `19363 + c * (84480 ±0)` + // Minimum execution time: 28_326_000 picoseconds. + Weight::from_parts(28_612_000, 19363) + // Standard Error: 73_191 + .saturating_add(Weight::from_parts(39_403_570, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3025 + c * (42 ±0)` + // Estimated: `59431 + c * (2947 ±0)` + // Minimum execution time: 86_517_000 picoseconds. + Weight::from_parts(78_047_954, 59431) + // Standard Error: 2_660 + .saturating_add(Weight::from_parts(1_060_607, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(13_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(9_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } diff --git a/pallets/payment/Cargo.toml b/pallets/payment/Cargo.toml index bb6f5903037..93c809367f0 100644 --- a/pallets/payment/Cargo.toml +++ b/pallets/payment/Cargo.toml @@ -1,12 +1,11 @@ [package] name = "pallet-gear-payment" -version = "0.1.0" -authors = ['Gear Technologies'] -edition = '2021' +version.workspace = true +authors.workspace = true +edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" -description = "Gear main pallet" +homepage.workspace = true +repository.workspace = true readme = "README.md" [package.metadata.docs.rs] diff --git a/pallets/staking-rewards/Cargo.toml b/pallets/staking-rewards/Cargo.toml index db9f816b402..567659a9853 100644 --- a/pallets/staking-rewards/Cargo.toml +++ b/pallets/staking-rewards/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "pallet-gear-staking-rewards" -version = "1.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" description = "Gear tokenomics implementation" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true readme = "README.md" [package.metadata.docs.rs] diff --git a/pallets/staking-rewards/src/mock.rs b/pallets/staking-rewards/src/mock.rs index d491261680b..e5037ced27b 100644 --- a/pallets/staking-rewards/src/mock.rs +++ b/pallets/staking-rewards/src/mock.rs @@ -67,14 +67,11 @@ pub(crate) const NOM_1_CONTROLLER: AccountId = 41; pub(crate) const ROOT: AccountId = 101; pub(crate) const INITIAL_TOTAL_TOKEN_SUPPLY: u128 = 1_000_000 * UNITS; -pub(crate) const EXISTENTIAL_DEPOSIT: u128 = 10 * MILLICENTS; // 10 +pub(crate) const EXISTENTIAL_DEPOSIT: u128 = 10 * UNITS / 100_000; // 10 pub(crate) const VALIDATOR_STAKE: u128 = 100 * UNITS; // 10 pub(crate) const ENDOWMENT: u128 = 100 * UNITS; pub(crate) const UNITS: u128 = 100_000; // 10^(-5) precision -pub(crate) const DOLLARS: u128 = UNITS; // 1 to 1 -pub(crate) const CENTS: u128 = DOLLARS / 100; // 1_000 -pub(crate) const MILLICENTS: u128 = CENTS / 1_000; // 1 pub(crate) const MILLISECONDS_PER_YEAR: u64 = 1_000 * 3_600 * 24 * 36_525 / 100; pub(crate) const MILLISECS_PER_BLOCK: u64 = 2_400; pub(crate) const SESSION_DURATION: u64 = 1000; @@ -394,7 +391,7 @@ impl pallet_bags_list::Config for Test { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); - pub const ProposalBondMinimum: u128 = DOLLARS; + pub const ProposalBondMinimum: u128 = UNITS; pub const SpendPeriod: u32 = 100; pub const Burn: Permill = Permill::from_percent(50); pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); diff --git a/runtime-interface/Cargo.toml b/runtime-interface/Cargo.toml index 15b023165b2..f2dd78dbb68 100644 --- a/runtime-interface/Cargo.toml +++ b/runtime-interface/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "gear-runtime-interface" -version = "0.1.0" -authors.workspace = true description = "Gear Runtime Interface" +version.workspace = true +authors.workspace = true edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true [dependencies] gear-core.workspace = true diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index ab712a38152..b673f851b3d 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "gear-runtime-common" -version = "0.1.0" +version.workspace = true authors.workspace = true edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/runtime/gear/Cargo.toml b/runtime/gear/Cargo.toml index 00cf7a60141..fdd6f2deb3a 100644 --- a/runtime/gear/Cargo.toml +++ b/runtime/gear/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "gear-runtime" -version = "0.1.0" +version.workspace = true authors.workspace = true edition.workspace = true -build = "build.rs" license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true +build = "build.rs" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -176,7 +176,7 @@ try-runtime = [ "validator-set/try-runtime", "runtime-common/try-runtime", ] -debug-mode = ["pallet-gear-debug", "pallet-gear-program/debug-mode"] +dev = ["pallet-gear-debug", "pallet-gear-program/dev"] lazy-pages = [ "pallet-gear/lazy-pages", "pallet-gear-payment/lazy-pages", diff --git a/runtime/gear/src/constants.rs b/runtime/gear/src/constants.rs index 35c4873d511..0b4e927003b 100644 --- a/runtime/gear/src/constants.rs +++ b/runtime/gear/src/constants.rs @@ -20,6 +20,8 @@ pub mod currency { use runtime_primitives::Balance; + pub const UNITS: Balance = 1_000_000_000_000; // 10^(-12) precision + /// The existential deposit. pub const EXISTENTIAL_DEPOSIT: Balance = 500; diff --git a/runtime/gear/src/lib.rs b/runtime/gear/src/lib.rs index 16168baefca..6094556ebd9 100644 --- a/runtime/gear/src/lib.rs +++ b/runtime/gear/src/lib.rs @@ -89,7 +89,7 @@ pub use pallet_timestamp::Call as TimestampCall; pub use sp_runtime::BuildStorage; pub use pallet_gear; -#[cfg(feature = "debug-mode")] +#[cfg(feature = "dev")] pub use pallet_gear_debug; pub use pallet_gear_gas; pub use pallet_gear_payment; @@ -124,7 +124,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_name: create_runtime_str!("gear"), apis: RUNTIME_API_VERSIONS, authoring_version: 1, - spec_version: 360, + spec_version: 1000, impl_version: 1, transaction_version: 1, state_version: 1, @@ -495,7 +495,7 @@ impl pallet_gear::Config for Runtime { type ProgramRentDisabledDelta = ConstU32<{ WEEKS * RENT_DISABLED_DELTA_WEEK_FACTOR }>; } -#[cfg(feature = "debug-mode")] +#[cfg(feature = "dev")] impl pallet_gear_debug::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_gear_debug::weights::GearSupportWeight; @@ -600,7 +600,7 @@ where // // While updating the indexes, please update the indexes in `gsdk/src/metadata/mod.rs` // as well, example: https://github.com/gear-tech/gear/pull/2370/commits/a82cb5ba365cf47aef2c42a285a1793a86e711c1 -#[cfg(feature = "debug-mode")] +#[cfg(feature = "dev")] construct_runtime!( pub enum Runtime where Block = Block, @@ -631,12 +631,12 @@ construct_runtime!( GearVoucher: pallet_gear_voucher = 106, GearBank: pallet_gear_bank = 107, - // Only available with "debug-mode" feature on + // Only available with "dev" feature on GearDebug: pallet_gear_debug = 199, } ); -#[cfg(not(feature = "debug-mode"))] +#[cfg(not(feature = "dev"))] construct_runtime!( pub enum Runtime where Block = Block, @@ -704,9 +704,9 @@ pub type Executive = frame_executive::Executive< #[cfg(test)] mod tests; -#[cfg(feature = "debug-mode")] +#[cfg(feature = "dev")] type DebugInfo = GearDebug; -#[cfg(not(feature = "debug-mode"))] +#[cfg(not(feature = "dev"))] type DebugInfo = (); #[cfg(feature = "runtime-benchmarks")] diff --git a/runtime/gear/src/migrations.rs b/runtime/gear/src/migrations.rs index 8749826d911..248916f1fad 100644 --- a/runtime/gear/src/migrations.rs +++ b/runtime/gear/src/migrations.rs @@ -19,4 +19,4 @@ #[allow(unused)] use crate::*; -pub type Migrations = (pallet_gear_gas::migrations::MigrateToV3,); +pub type Migrations = (); diff --git a/runtime/gear/src/weights/pallet_gear.rs b/runtime/gear/src/weights/pallet_gear.rs index 707b287d5c5..8b14d71ab58 100644 --- a/runtime/gear/src/weights/pallet_gear.rs +++ b/runtime/gear/src/weights/pallet_gear.rs @@ -215,6 +215,17 @@ pub trait WeightInfo { fn instr_i32rotl(r: u32, ) -> Weight; fn instr_i64rotr(r: u32, ) -> Weight; fn instr_i32rotr(r: u32, ) -> Weight; + fn tasks_remove_resume_session() -> Weight; + fn tasks_remove_gas_reservation() -> Weight; + fn tasks_send_user_message_to_mailbox() -> Weight; + fn tasks_send_user_message() -> Weight; + fn tasks_send_dispatch() -> Weight; + fn tasks_wake_message() -> Weight; + fn tasks_wake_message_no_wake() -> Weight; + fn tasks_remove_from_waitlist() -> Weight; + fn tasks_remove_from_mailbox() -> Weight; + fn tasks_pause_program(c: u32, ) -> Weight; + fn tasks_pause_program_uninited(c: u32, ) -> Weight; fn allocation_cost() -> Weight; fn grow_cost() -> Weight; fn initial_cost() -> Weight; @@ -2062,6 +2073,116 @@ impl pallet_gear::WeightInfo for SubstrateWeight { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 5_698_000 picoseconds. + Weight::from_parts(5_953_000, 4169) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1003` + // Estimated: `23637` + // Minimum execution time: 61_615_000 picoseconds. + Weight::from_parts(64_309_000, 23637) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `784` + // Estimated: `21534` + // Minimum execution time: 43_449_000 picoseconds. + Weight::from_parts(44_990_000, 21534) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `906` + // Estimated: `33891` + // Minimum execution time: 75_764_000 picoseconds. + Weight::from_parts(77_875_000, 33891) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `591` + // Estimated: `19885` + // Minimum execution time: 31_362_000 picoseconds. + Weight::from_parts(32_425_000, 19885) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `872` + // Estimated: `25908` + // Minimum execution time: 45_023_000 picoseconds. + Weight::from_parts(46_479_000, 25908) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_365_000 picoseconds. + Weight::from_parts(3_639_000, 3545) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1522` + // Estimated: `57192` + // Minimum execution time: 114_023_000 picoseconds. + Weight::from_parts(117_157_000, 57192) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1228` + // Estimated: `46026` + // Minimum execution time: 90_320_000 picoseconds. + Weight::from_parts(93_096_000, 46026) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2200 + c * (16400 ±0)` + // Estimated: `19363 + c * (84480 ±0)` + // Minimum execution time: 28_326_000 picoseconds. + Weight::from_parts(28_612_000, 19363) + // Standard Error: 73_191 + .saturating_add(Weight::from_parts(39_403_570, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3025 + c * (42 ±0)` + // Estimated: `59431 + c * (2947 ±0)` + // Minimum execution time: 86_517_000 picoseconds. + Weight::from_parts(78_047_954, 59431) + // Standard Error: 2_660 + .saturating_add(Weight::from_parts(1_060_607, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(13_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(9_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } // For backwards compatibility and tests @@ -3903,4 +4024,114 @@ impl WeightInfo for () { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 5_698_000 picoseconds. + Weight::from_parts(5_953_000, 4169) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1003` + // Estimated: `23637` + // Minimum execution time: 61_615_000 picoseconds. + Weight::from_parts(64_309_000, 23637) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `784` + // Estimated: `21534` + // Minimum execution time: 43_449_000 picoseconds. + Weight::from_parts(44_990_000, 21534) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `906` + // Estimated: `33891` + // Minimum execution time: 75_764_000 picoseconds. + Weight::from_parts(77_875_000, 33891) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `591` + // Estimated: `19885` + // Minimum execution time: 31_362_000 picoseconds. + Weight::from_parts(32_425_000, 19885) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `872` + // Estimated: `25908` + // Minimum execution time: 45_023_000 picoseconds. + Weight::from_parts(46_479_000, 25908) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_365_000 picoseconds. + Weight::from_parts(3_639_000, 3545) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1522` + // Estimated: `57192` + // Minimum execution time: 114_023_000 picoseconds. + Weight::from_parts(117_157_000, 57192) + .saturating_add(RocksDbWeight::get().reads(16_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1228` + // Estimated: `46026` + // Minimum execution time: 90_320_000 picoseconds. + Weight::from_parts(93_096_000, 46026) + .saturating_add(RocksDbWeight::get().reads(14_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2200 + c * (16400 ±0)` + // Estimated: `19363 + c * (84480 ±0)` + // Minimum execution time: 28_326_000 picoseconds. + Weight::from_parts(28_612_000, 19363) + // Standard Error: 73_191 + .saturating_add(Weight::from_parts(39_403_570, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3025 + c * (42 ±0)` + // Estimated: `59431 + c * (2947 ±0)` + // Minimum execution time: 86_517_000 picoseconds. + Weight::from_parts(78_047_954, 59431) + // Standard Error: 2_660 + .saturating_add(Weight::from_parts(1_060_607, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(13_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(9_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } diff --git a/runtime/primitives/Cargo.toml b/runtime/primitives/Cargo.toml index 420c73e1de6..a4589cb002f 100644 --- a/runtime/primitives/Cargo.toml +++ b/runtime/primitives/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "gear-runtime-primitives" -version = "0.1.0" -authors.workspace = true description = "Gear Runtime primitives" +version.workspace = true +authors.workspace = true edition.workspace = true license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/runtime/vara/Cargo.toml b/runtime/vara/Cargo.toml index 99fa7782b58..f179c2bd346 100644 --- a/runtime/vara/Cargo.toml +++ b/runtime/vara/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "vara-runtime" -version = "0.1.0" +version.workspace = true authors.workspace = true edition.workspace = true -build = "build.rs" license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" +homepage.workspace = true +repository.workspace = true +build = "build.rs" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -49,7 +49,7 @@ pallet-referenda.workspace = true pallet-scheduler.workspace = true pallet-session = { workspace = true, features = [ "historical" ] } pallet-staking.workspace = true -pallet-sudo.workspace = true +pallet-sudo = { workspace = true, optional = true } pallet-timestamp.workspace = true pallet-transaction-payment.workspace = true pallet-treasury.workspace = true @@ -98,7 +98,6 @@ pallet-gear-staking-rewards.workspace = true pallet-gear-voucher.workspace = true pallet-gear-rpc-runtime-api.workspace = true runtime-primitives.workspace = true -pallet-airdrop.workspace = true [dev-dependencies] sp-io.workspace = true @@ -158,7 +157,7 @@ std = [ "pallet-session/std", "pallet-scheduler/std", "pallet-staking/std", - "pallet-sudo/std", + "pallet-sudo?/std", "pallet-timestamp/std", "pallet-transaction-payment/std", "pallet-transaction-payment-rpc-runtime-api/std", @@ -185,7 +184,6 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", - "pallet-airdrop/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -200,7 +198,6 @@ runtime-benchmarks = [ "pallet-gear/runtime-benchmarks", "pallet-gear-voucher/runtime-benchmarks", "sp-runtime/runtime-benchmarks", - "pallet-airdrop/runtime-benchmarks", "pallet-bags-list/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-conviction-voting/runtime-benchmarks", @@ -248,18 +245,21 @@ try-runtime = [ "pallet-scheduler/try-runtime", "pallet-session/try-runtime", "pallet-staking/try-runtime", - "pallet-sudo/try-runtime", + "pallet-sudo?/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-treasury/try-runtime", "pallet-utility/try-runtime", "pallet-vesting/try-runtime", "pallet-whitelist/try-runtime", - "pallet-airdrop/try-runtime", "pallet-bags-list/try-runtime", "runtime-common/try-runtime", ] -debug-mode = ["pallet-gear-debug", "pallet-gear-program/debug-mode"] +dev = [ + "pallet-gear-debug", + "pallet-gear-program/dev", + "pallet-sudo", +] lazy-pages = [ "pallet-gear/lazy-pages", "pallet-gear-payment/lazy-pages", diff --git a/runtime/vara/src/constants.rs b/runtime/vara/src/constants.rs index 75f273a42ee..b80d724a3ec 100644 --- a/runtime/vara/src/constants.rs +++ b/runtime/vara/src/constants.rs @@ -20,22 +20,22 @@ pub mod currency { use runtime_primitives::Balance; + pub const UNITS: Balance = 1_000_000_000_000; // 10^(-12) precision + + /// Base economic unit, 50 Vara. + pub const ECONOMIC_UNITS: Balance = UNITS * 50; + pub const ECONOMIC_CENTIUNITS: Balance = ECONOMIC_UNITS / 100; + /// The existential deposit. - pub const EXISTENTIAL_DEPOSIT: Balance = 10_000_000_000_000; // 10 Vara + pub const EXISTENTIAL_DEPOSIT: Balance = 10 * UNITS; // 10 Vara /// The program rent cost per block. pub const RENT_COST_PER_BLOCK: Balance = 125_000_000; - // TODO: review quantities based on economic model (issue #1277) - pub const UNITS: Balance = 1_000_000_000_000; // 10^(-12) precision - pub const DOLLARS: Balance = UNITS * 20; // 1 token is worth ~$0.05 - pub const CENTS: Balance = DOLLARS / 100; // 200_000_000_000 - pub const MILLICENTS: Balance = CENTS / 1_000; // 200_000_000 - /// Helper function to calculate various deposits for using pallets' storage pub const fn deposit(items: u32, bytes: u32) -> Balance { // TODO: review numbers (#2650) - items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS + items as Balance * 15 * ECONOMIC_CENTIUNITS + (bytes as Balance) * 6 * ECONOMIC_CENTIUNITS } } diff --git a/runtime/vara/src/governance/fellowship.rs b/runtime/vara/src/governance/fellowship.rs index e0e9a39c2c4..6adad66c76d 100644 --- a/runtime/vara/src/governance/fellowship.rs +++ b/runtime/vara/src/governance/fellowship.rs @@ -30,7 +30,7 @@ use sp_runtime::{ }; use super::*; -use crate::{DAYS, DOLLARS}; +use crate::{DAYS, ECONOMIC_UNITS}; parameter_types! { pub const AlarmInterval: BlockNumber = 1; @@ -49,7 +49,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "candidates", max_deciding: 10, - decision_deposit: 100 * DOLLARS, + decision_deposit: 100 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, @@ -71,7 +71,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "members", max_deciding: 10, - decision_deposit: 10 * DOLLARS, + decision_deposit: 10 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, @@ -93,7 +93,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "proficients", max_deciding: 10, - decision_deposit: 10 * DOLLARS, + decision_deposit: 10 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, @@ -115,7 +115,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "fellows", max_deciding: 10, - decision_deposit: 10 * DOLLARS, + decision_deposit: 10 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, @@ -137,7 +137,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "senior fellows", max_deciding: 10, - decision_deposit: 10 * DOLLARS, + decision_deposit: 10 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, @@ -159,7 +159,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "experts", max_deciding: 10, - decision_deposit: 1 * DOLLARS, + decision_deposit: 1 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, @@ -181,7 +181,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "senior experts", max_deciding: 10, - decision_deposit: 1 * DOLLARS, + decision_deposit: 1 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, @@ -203,7 +203,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "masters", max_deciding: 10, - decision_deposit: 1 * DOLLARS, + decision_deposit: 1 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, @@ -225,7 +225,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "senior masters", max_deciding: 10, - decision_deposit: 1 * DOLLARS, + decision_deposit: 1 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, @@ -247,7 +247,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::TrackInfo { name: "grand masters", max_deciding: 10, - decision_deposit: 1 * DOLLARS, + decision_deposit: 1 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 7 * DAYS, confirm_period: 30 * MINUTES, diff --git a/runtime/vara/src/governance/mod.rs b/runtime/vara/src/governance/mod.rs index cd3189fc2f4..6e435b4df51 100644 --- a/runtime/vara/src/governance/mod.rs +++ b/runtime/vara/src/governance/mod.rs @@ -53,7 +53,7 @@ impl pallet_conviction_voting::Config for Runtime { parameter_types! { pub const AlarmInterval: BlockNumber = 1; - pub const SubmissionDeposit: Balance = 10 * DOLLARS; + pub const SubmissionDeposit: Balance = 10 * ECONOMIC_UNITS; pub const UndecidingTimeout: BlockNumber = 14 * DAYS; } diff --git a/runtime/vara/src/governance/tracks.rs b/runtime/vara/src/governance/tracks.rs index b20bbf0b3ce..48170c7e827 100644 --- a/runtime/vara/src/governance/tracks.rs +++ b/runtime/vara/src/governance/tracks.rs @@ -67,7 +67,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "root", max_deciding: 1, - decision_deposit: 100_000 * DOLLARS, + decision_deposit: 100_000 * ECONOMIC_UNITS, prepare_period: 2 * HOURS, decision_period: 14 * DAYS, confirm_period: 24 * HOURS, @@ -81,7 +81,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "whitelisted_caller", max_deciding: 100, - decision_deposit: 10_000 * DOLLARS, + decision_deposit: 10_000 * ECONOMIC_UNITS, prepare_period: 30 * MINUTES, decision_period: 14 * DAYS, confirm_period: 10 * MINUTES, @@ -95,7 +95,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "staking_admin", max_deciding: 10, - decision_deposit: 5_000 * DOLLARS, + decision_deposit: 5_000 * ECONOMIC_UNITS, prepare_period: 2 * HOURS, decision_period: 14 * DAYS, confirm_period: 3 * HOURS, @@ -109,7 +109,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "treasurer", max_deciding: 10, - decision_deposit: 1_000 * DOLLARS, + decision_deposit: 1_000 * ECONOMIC_UNITS, prepare_period: 2 * HOURS, decision_period: 14 * DAYS, confirm_period: 3 * HOURS, @@ -123,7 +123,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "fellowship_admin", max_deciding: 10, - decision_deposit: 5_000 * DOLLARS, + decision_deposit: 5_000 * ECONOMIC_UNITS, prepare_period: 2 * HOURS, decision_period: 14 * DAYS, confirm_period: 3 * HOURS, @@ -137,7 +137,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "general_admin", max_deciding: 10, - decision_deposit: 5_000 * DOLLARS, + decision_deposit: 5_000 * ECONOMIC_UNITS, prepare_period: 2 * HOURS, decision_period: 14 * DAYS, confirm_period: 3 * HOURS, @@ -151,7 +151,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "referendum_canceller", max_deciding: 1_000, - decision_deposit: 10_000 * DOLLARS, + decision_deposit: 10_000 * ECONOMIC_UNITS, prepare_period: 2 * HOURS, decision_period: 7 * DAYS, confirm_period: 3 * HOURS, @@ -165,7 +165,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "referendum_killer", max_deciding: 1_000, - decision_deposit: 50_000 * DOLLARS, + decision_deposit: 50_000 * ECONOMIC_UNITS, prepare_period: 2 * HOURS, decision_period: 14 * DAYS, confirm_period: 3 * HOURS, @@ -179,7 +179,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "small_tipper", max_deciding: 200, - decision_deposit: DOLLARS, + decision_deposit: ECONOMIC_UNITS, prepare_period: MINUTES, decision_period: 7 * DAYS, confirm_period: 10 * MINUTES, @@ -193,7 +193,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "big_tipper", max_deciding: 100, - decision_deposit: 10 * DOLLARS, + decision_deposit: 10 * ECONOMIC_UNITS, prepare_period: 10 * MINUTES, decision_period: 7 * DAYS, confirm_period: HOURS, @@ -207,7 +207,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "small_spender", max_deciding: 50, - decision_deposit: 100 * DOLLARS, + decision_deposit: 100 * ECONOMIC_UNITS, prepare_period: 4 * HOURS, decision_period: 14 * DAYS, confirm_period: 12 * HOURS, @@ -221,7 +221,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "medium_spender", max_deciding: 50, - decision_deposit: 200 * DOLLARS, + decision_deposit: 200 * ECONOMIC_UNITS, prepare_period: 4 * HOURS, decision_period: 14 * DAYS, confirm_period: 24 * HOURS, @@ -235,7 +235,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 13 pallet_referenda::TrackInfo { name: "big_spender", max_deciding: 50, - decision_deposit: 400 * DOLLARS, + decision_deposit: 400 * ECONOMIC_UNITS, prepare_period: 4 * HOURS, decision_period: 14 * DAYS, confirm_period: 48 * HOURS, diff --git a/runtime/vara/src/lib.rs b/runtime/vara/src/lib.rs index f175c6d9125..fee12da3048 100644 --- a/runtime/vara/src/lib.rs +++ b/runtime/vara/src/lib.rs @@ -98,13 +98,13 @@ pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; #[cfg(any(feature = "std", test))] pub use pallet_staking::StakerStatus; -#[cfg(any(feature = "std", test))] +#[cfg(all(feature = "dev", any(feature = "std", test)))] pub use pallet_sudo::Call as SudoCall; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; pub use pallet_gear; -#[cfg(feature = "debug-mode")] +#[cfg(feature = "dev")] pub use pallet_gear_debug; pub use pallet_gear_gas; pub use pallet_gear_payment; @@ -142,7 +142,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // The version of the runtime specification. A full node will not attempt to use its native // runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`, // `spec_version`, and `authoring_version` are the same between Wasm and native. - spec_version: 360, + spec_version: 1000, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -313,8 +313,8 @@ impl pallet_scheduler::Config for Runtime { parameter_types! { pub const PreimageMaxSize: u32 = 4096 * 1024; - pub const PreimageBaseDeposit: Balance = DOLLARS; - pub const PreimageByteDeposit: Balance = CENTS; + pub const PreimageBaseDeposit: Balance = ECONOMIC_UNITS; + pub const PreimageByteDeposit: Balance = ECONOMIC_CENTIUNITS; } impl pallet_preimage::Config for Runtime { @@ -451,9 +451,9 @@ parameter_types! { pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4; // signed config - pub const SignedRewardBase: Balance = DOLLARS; - pub const SignedDepositBase: Balance = DOLLARS; - pub const SignedDepositByte: Balance = CENTS; + pub const SignedRewardBase: Balance = ECONOMIC_UNITS; + pub const SignedDepositBase: Balance = ECONOMIC_UNITS; + pub const SignedDepositByte: Balance = ECONOMIC_CENTIUNITS; pub BetterUnsignedThreshold: Perbill = Perbill::from_rational(1u32, 10_000); @@ -679,13 +679,13 @@ impl pallet_offences::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); - pub const ProposalBondMinimum: Balance = DOLLARS; + pub const ProposalBondMinimum: Balance = ECONOMIC_UNITS; pub const SpendPeriod: BlockNumber = DAYS; pub const Burn: Permill = Permill::from_percent(50); pub const TipCountdown: BlockNumber = DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); - pub const TipReportDepositBase: Balance = DOLLARS; - pub const DataDepositPerByte: Balance = CENTS; + pub const TipReportDepositBase: Balance = ECONOMIC_UNITS; + pub const DataDepositPerByte: Balance = ECONOMIC_CENTIUNITS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 300; pub const MaxApprovals: u32 = 100; @@ -712,11 +712,11 @@ impl pallet_treasury::Config for Runtime { parameter_types! { pub const BountyCuratorDeposit: Permill = Permill::from_percent(50); - pub const BountyValueMinimum: Balance = 5 * DOLLARS; - pub const BountyDepositBase: Balance = DOLLARS; + pub const BountyValueMinimum: Balance = 5 * ECONOMIC_UNITS; + pub const BountyDepositBase: Balance = ECONOMIC_UNITS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); - pub const CuratorDepositMin: Balance = DOLLARS; - pub const CuratorDepositMax: Balance = 100 * DOLLARS; + pub const CuratorDepositMin: Balance = ECONOMIC_UNITS; + pub const CuratorDepositMax: Balance = 100 * ECONOMIC_UNITS; pub const BountyDepositPayoutDelay: BlockNumber = DAYS; pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS; } @@ -737,7 +737,7 @@ impl pallet_bounties::Config for Runtime { } parameter_types! { - pub const ChildBountyValueMinimum: Balance = DOLLARS; + pub const ChildBountyValueMinimum: Balance = ECONOMIC_UNITS; } impl pallet_child_bounties::Config for Runtime { @@ -775,9 +775,9 @@ impl pallet_authority_discovery::Config for Runtime { } parameter_types! { - pub const BasicDeposit: Balance = 10 * DOLLARS; // 258 bytes on-chain - pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain - pub const SubAccountDeposit: Balance = 2 * DOLLARS; // 53 bytes on-chain + pub const BasicDeposit: Balance = 10 * ECONOMIC_UNITS; // 258 bytes on-chain + pub const FieldDeposit: Balance = 250 * ECONOMIC_CENTIUNITS; // 66 bytes on-chain + pub const SubAccountDeposit: Balance = 2 * ECONOMIC_UNITS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; pub const MaxAdditionalFields: u32 = 100; pub const MaxRegistrars: u32 = 20; @@ -798,6 +798,7 @@ impl pallet_identity::Config for Runtime { type WeightInfo = pallet_identity::weights::SubstrateWeight; } +#[cfg(feature = "dev")] impl pallet_sudo::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -869,13 +870,23 @@ impl InstanceFilter for ProxyType { fn filter(&self, c: &RuntimeCall) -> bool { match self { ProxyType::Any => true, - ProxyType::NonTransfer => !matches!( - c, - RuntimeCall::Balances(..) - | RuntimeCall::Sudo(..) - | RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) - | RuntimeCall::Vesting(pallet_vesting::Call::force_vested_transfer { .. }) - ), + ProxyType::NonTransfer => { + #[cfg(feature = "dev")] + return !matches!( + c, + RuntimeCall::Balances(..) + | RuntimeCall::Sudo(..) + | RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) + | RuntimeCall::Vesting(pallet_vesting::Call::force_vested_transfer { .. }) + ); + #[cfg(not(feature = "dev"))] + return !matches!( + c, + RuntimeCall::Balances(..) + | RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) + | RuntimeCall::Vesting(pallet_vesting::Call::force_vested_transfer { .. }) + ); + } ProxyType::Governance => matches!( c, RuntimeCall::Treasury(..) @@ -988,7 +999,7 @@ impl pallet_gear::Config for Runtime { type ProgramRentDisabledDelta = ConstU32<{ WEEKS * RENT_DISABLED_DELTA_WEEK_FACTOR }>; } -#[cfg(feature = "debug-mode")] +#[cfg(feature = "dev")] impl pallet_gear_debug::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_gear_debug::weights::GearSupportWeight; @@ -1015,12 +1026,6 @@ impl pallet_gear_messenger::Config for Runtime { type CurrentBlockNumber = Gear; } -impl pallet_airdrop::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::pallet_airdrop::SubstrateWeight; - type VestingSchedule = Vesting; -} - pub struct ExtraFeeFilter; impl Contains for ExtraFeeFilter { fn contains(call: &RuntimeCall) -> bool { @@ -1094,7 +1099,7 @@ where } parameter_types! { - pub const MinVestedTransfer: Balance = 100 * CENTS; + pub const MinVestedTransfer: Balance = 100 * ECONOMIC_CENTIUNITS; pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons = WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE); } @@ -1110,7 +1115,7 @@ impl pallet_vesting::Config for Runtime { } // Create the runtime by composing the FRAME pallets that were previously configured. -#[cfg(feature = "debug-mode")] +#[cfg(feature = "dev")] construct_runtime!( pub enum Runtime where Block = Block, @@ -1164,18 +1169,16 @@ construct_runtime!( GearVoucher: pallet_gear_voucher = 107, GearBank: pallet_gear_bank = 108, - // TODO: Remove in stage 3 Sudo: pallet_sudo = 99, - // TODO: remove from production version - Airdrop: pallet_airdrop = 198, + // NOTE (!): `pallet_airdrop` used to be idx(198). - // Only available with "debug-mode" feature on + // Only available with "dev" feature on GearDebug: pallet_gear_debug = 199, } ); -#[cfg(not(feature = "debug-mode"))] +#[cfg(not(feature = "dev"))] construct_runtime!( pub enum Runtime where Block = Block, @@ -1229,11 +1232,8 @@ construct_runtime!( GearVoucher: pallet_gear_voucher = 107, GearBank: pallet_gear_bank = 108, - // TODO: Remove in stage 3 - Sudo: pallet_sudo = 99, - - // TODO: remove from production version - Airdrop: pallet_airdrop = 198, + // NOTE (!): `pallet_sudo` used to be idx(99). + // NOTE (!): `pallet_airdrop` used to be idx(198). } ); @@ -1277,9 +1277,9 @@ mod tests; #[cfg(test)] mod integration_tests; -#[cfg(feature = "debug-mode")] +#[cfg(feature = "dev")] type DebugInfo = GearDebug; -#[cfg(not(feature = "debug-mode"))] +#[cfg(not(feature = "dev"))] type DebugInfo = (); #[cfg(feature = "runtime-benchmarks")] @@ -1295,7 +1295,6 @@ mod benches { [pallet_timestamp, Timestamp] [pallet_utility, Utility] // Gear pallets - [pallet_airdrop, Airdrop] [pallet_gear, Gear] [pallet_gear_voucher, GearVoucher] ); diff --git a/runtime/vara/src/migrations.rs b/runtime/vara/src/migrations.rs index 8749826d911..248916f1fad 100644 --- a/runtime/vara/src/migrations.rs +++ b/runtime/vara/src/migrations.rs @@ -19,4 +19,4 @@ #[allow(unused)] use crate::*; -pub type Migrations = (pallet_gear_gas::migrations::MigrateToV3,); +pub type Migrations = (); diff --git a/runtime/vara/src/weights/mod.rs b/runtime/vara/src/weights/mod.rs index 170d6f59e22..b4eebedfe52 100644 --- a/runtime/vara/src/weights/mod.rs +++ b/runtime/vara/src/weights/mod.rs @@ -19,7 +19,6 @@ //! A list of the different weight modules for our runtime. pub mod frame_system; -pub mod pallet_airdrop; pub mod pallet_balances; pub mod pallet_gear; pub mod pallet_gear_voucher; diff --git a/runtime/vara/src/weights/pallet_airdrop.rs b/runtime/vara/src/weights/pallet_airdrop.rs deleted file mode 100644 index ffe616fea00..00000000000 --- a/runtime/vara/src/weights/pallet_airdrop.rs +++ /dev/null @@ -1,95 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2022-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 . - -//! Autogenerated weights for pallet_airdrop -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-11, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("vara-dev"), DB CACHE: 1024 - -// Executed Command: -// ./target/production/gear benchmark pallet --chain=vara-dev --steps=50 --repeat=20 --pallet=pallet_airdrop --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./scripts/benchmarking/weights-output/pallet_airdrop.rs --template=.maintain/frame-weight-template.hbs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; - -/// Weight functions needed for pallet_airdrop. -pub trait WeightInfo { - fn transfer(q: u32, ) -> Weight; - fn transfer_vested(q: u32, ) -> Weight; -} - -/// Weights for pallet_airdrop using the Gear node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl pallet_airdrop::WeightInfo for SubstrateWeight { - /// The range of component `q` is `[1, 256]`. - fn transfer(_q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `103` - // Estimated: `6196` - // Minimum execution time: 25_162_000 picoseconds. - Weight::from_parts(26_300_954, 6196) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// The range of component `q` is `[1, 256]`. - fn transfer_vested(q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `550` - // Estimated: `15482` - // Minimum execution time: 65_671_000 picoseconds. - Weight::from_parts(67_524_170, 15482) - // Standard Error: 398 - .saturating_add(Weight::from_parts(280, 0).saturating_mul(q.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) - } -} - -// For backwards compatibility and tests -impl WeightInfo for () { - /// The range of component `q` is `[1, 256]`. - fn transfer(_q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `103` - // Estimated: `6196` - // Minimum execution time: 25_162_000 picoseconds. - Weight::from_parts(26_300_954, 6196) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// The range of component `q` is `[1, 256]`. - fn transfer_vested(q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `550` - // Estimated: `15482` - // Minimum execution time: 65_671_000 picoseconds. - Weight::from_parts(67_524_170, 15482) - // Standard Error: 398 - .saturating_add(Weight::from_parts(280, 0).saturating_mul(q.into())) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) - } -} diff --git a/runtime/vara/src/weights/pallet_gear.rs b/runtime/vara/src/weights/pallet_gear.rs index 707b287d5c5..c5702325ce6 100644 --- a/runtime/vara/src/weights/pallet_gear.rs +++ b/runtime/vara/src/weights/pallet_gear.rs @@ -215,6 +215,17 @@ pub trait WeightInfo { fn instr_i32rotl(r: u32, ) -> Weight; fn instr_i64rotr(r: u32, ) -> Weight; fn instr_i32rotr(r: u32, ) -> Weight; + fn tasks_remove_resume_session() -> Weight; + fn tasks_remove_gas_reservation() -> Weight; + fn tasks_send_user_message_to_mailbox() -> Weight; + fn tasks_send_user_message() -> Weight; + fn tasks_send_dispatch() -> Weight; + fn tasks_wake_message() -> Weight; + fn tasks_wake_message_no_wake() -> Weight; + fn tasks_remove_from_waitlist() -> Weight; + fn tasks_remove_from_mailbox() -> Weight; + fn tasks_pause_program(c: u32, ) -> Weight; + fn tasks_pause_program_uninited(c: u32, ) -> Weight; fn allocation_cost() -> Weight; fn grow_cost() -> Weight; fn initial_cost() -> Weight; @@ -2062,6 +2073,116 @@ impl pallet_gear::WeightInfo for SubstrateWeight { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 6_081_000 picoseconds. + Weight::from_parts(6_314_000, 4169) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1107` + // Estimated: `24053` + // Minimum execution time: 61_245_000 picoseconds. + Weight::from_parts(64_310_000, 24053) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `888` + // Estimated: `22158` + // Minimum execution time: 47_184_000 picoseconds. + Weight::from_parts(48_335_000, 22158) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `1010` + // Estimated: `34619` + // Minimum execution time: 75_767_000 picoseconds. + Weight::from_parts(77_229_000, 34619) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `695` + // Estimated: `20509` + // Minimum execution time: 31_513_000 picoseconds. + Weight::from_parts(33_232_000, 20509) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `976` + // Estimated: `26636` + // Minimum execution time: 48_739_000 picoseconds. + Weight::from_parts(49_963_000, 26636) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_513_000 picoseconds. + Weight::from_parts(3_670_000, 3545) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1626` + // Estimated: `58232` + // Minimum execution time: 109_582_000 picoseconds. + Weight::from_parts(112_343_000, 58232) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1332` + // Estimated: `46962` + // Minimum execution time: 90_789_000 picoseconds. + Weight::from_parts(93_329_000, 46962) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2303 + c * (16400 ±0)` + // Estimated: `19878 + c * (84480 ±0)` + // Minimum execution time: 31_262_000 picoseconds. + Weight::from_parts(31_610_000, 19878) + // Standard Error: 69_131 + .saturating_add(Weight::from_parts(39_928_419, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3129 + c * (42 ±0)` + // Estimated: `60575 + c * (2947 ±0)` + // Minimum execution time: 91_223_000 picoseconds. + Weight::from_parts(98_002_861, 60575) + // Standard Error: 2_086 + .saturating_add(Weight::from_parts(1_092_801, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(13_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(9_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } // For backwards compatibility and tests @@ -3903,4 +4024,114 @@ impl WeightInfo for () { // Standard Error: 5_851 .saturating_add(Weight::from_parts(639_333, 0).saturating_mul(r.into())) } + fn tasks_remove_resume_session() -> Weight { + // Proof Size summary in bytes: + // Measured: `352` + // Estimated: `4169` + // Minimum execution time: 6_081_000 picoseconds. + Weight::from_parts(6_314_000, 4169) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + fn tasks_remove_gas_reservation() -> Weight { + // Proof Size summary in bytes: + // Measured: `1107` + // Estimated: `24053` + // Minimum execution time: 61_245_000 picoseconds. + Weight::from_parts(64_310_000, 24053) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_send_user_message_to_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `888` + // Estimated: `22158` + // Minimum execution time: 47_184_000 picoseconds. + Weight::from_parts(48_335_000, 22158) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) + } + fn tasks_send_user_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `1010` + // Estimated: `34619` + // Minimum execution time: 75_767_000 picoseconds. + Weight::from_parts(77_229_000, 34619) + .saturating_add(RocksDbWeight::get().reads(11_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) + } + fn tasks_send_dispatch() -> Weight { + // Proof Size summary in bytes: + // Measured: `695` + // Estimated: `20509` + // Minimum execution time: 31_513_000 picoseconds. + Weight::from_parts(33_232_000, 20509) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `976` + // Estimated: `26636` + // Minimum execution time: 48_739_000 picoseconds. + Weight::from_parts(49_963_000, 26636) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + fn tasks_wake_message_no_wake() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3545` + // Minimum execution time: 3_513_000 picoseconds. + Weight::from_parts(3_670_000, 3545) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + } + fn tasks_remove_from_waitlist() -> Weight { + // Proof Size summary in bytes: + // Measured: `1626` + // Estimated: `58232` + // Minimum execution time: 109_582_000 picoseconds. + Weight::from_parts(112_343_000, 58232) + .saturating_add(RocksDbWeight::get().reads(16_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + fn tasks_remove_from_mailbox() -> Weight { + // Proof Size summary in bytes: + // Measured: `1332` + // Estimated: `46962` + // Minimum execution time: 90_789_000 picoseconds. + Weight::from_parts(93_329_000, 46962) + .saturating_add(RocksDbWeight::get().reads(14_u64)) + .saturating_add(RocksDbWeight::get().writes(13_u64)) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2303 + c * (16400 ±0)` + // Estimated: `19878 + c * (84480 ±0)` + // Minimum execution time: 31_262_000 picoseconds. + Weight::from_parts(31_610_000, 19878) + // Standard Error: 69_131 + .saturating_add(Weight::from_parts(39_928_419, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 84480).saturating_mul(c.into())) + } + /// The range of component `c` is `[0, 2044]`. + fn tasks_pause_program_uninited(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `3129 + c * (42 ±0)` + // Estimated: `60575 + c * (2947 ±0)` + // Minimum execution time: 91_223_000 picoseconds. + Weight::from_parts(98_002_861, 60575) + // Standard Error: 2_086 + .saturating_add(Weight::from_parts(1_092_801, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(13_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into()))) + .saturating_add(RocksDbWeight::get().writes(9_u64)) + .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2947).saturating_mul(c.into())) + } } diff --git a/scripts/benchmarking/run_all_benchmarks.sh b/scripts/benchmarking/run_all_benchmarks.sh index 87c957ca3f4..caa838da4f2 100755 --- a/scripts/benchmarking/run_all_benchmarks.sh +++ b/scripts/benchmarking/run_all_benchmarks.sh @@ -58,7 +58,7 @@ done if [ "$skip_build" != true ] then echo "[+] Compiling Gear benchmarks..." - cargo build --profile=production --locked --features=runtime-benchmarks + cargo build --profile=production --locked --features=dev,runtime-benchmarks fi # The executable to use. diff --git a/scripts/gear.sh b/scripts/gear.sh index e74c01c7145..05161f5c741 100755 --- a/scripts/gear.sh +++ b/scripts/gear.sh @@ -309,7 +309,7 @@ case "$COMMAND" in header "Running syscalls integrity test of pallet-gear 'benchmarking' module on WASMI executor" syscalls_integrity_test "$@"; ;; - doc) + docs) header "Testing examples in docs" doc_test "$ROOT_DIR/Cargo.toml" "$@"; ;; diff --git a/scripts/update-gsdk-metadata.sh b/scripts/update-gsdk-metadata.sh index 8ae3903eae0..b28692c0b81 100755 --- a/scripts/update-gsdk-metadata.sh +++ b/scripts/update-gsdk-metadata.sh @@ -5,7 +5,7 @@ set -ex -cargo build --package vara-runtime --features debug-mode --release +cargo build --package vara-runtime --features dev --release cargo build --package gsdk-api-gen --release touch gsdk/build.rs GSDK_API_GEN=1 cargo build --package gsdk --release