From 80fb8478fffe5316f64fc0e491e76b358adda40c Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Fri, 15 Sep 2023 19:39:02 +0400 Subject: [PATCH] chore(v1.0.0): Development features gate (#3277) --- .github/workflows/release.yml | 53 ++++++++++++++++++++--------- gsdk/build.rs | 6 +--- node/authorship/Cargo.toml | 2 +- node/cli/Cargo.toml | 8 ++--- node/cli/src/command.rs | 39 ++++++++++++++------- node/service/Cargo.toml | 6 ++-- node/service/src/chain_spec/gear.rs | 1 + node/service/src/chain_spec/vara.rs | 1 + node/testing/Cargo.toml | 4 +-- pallets/gear-debug/Cargo.toml | 2 +- pallets/gear-debug/src/tests/mod.rs | 8 ++--- pallets/gear-program/Cargo.toml | 2 +- pallets/gear-program/src/lib.rs | 4 +-- runtime/gear/Cargo.toml | 2 +- runtime/gear/src/lib.rs | 14 ++++---- runtime/vara/Cargo.toml | 2 +- runtime/vara/src/lib.rs | 14 ++++---- scripts/update-gsdk-metadata.sh | 2 +- 18 files changed, 101 insertions(+), 69 deletions(-) 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/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/node/authorship/Cargo.toml b/node/authorship/Cargo.toml index 9c9633d0ce9..041944ca157 100644 --- a/node/authorship/Cargo.toml +++ b/node/authorship/Cargo.toml @@ -55,6 +55,6 @@ 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 diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index 022e3f13c0c..02fe1c8c9d2 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -86,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..d88945fd663 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -52,20 +52,32 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { - #[cfg(feature = "gear-native")] + #[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 +87,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 8a7149183bc..79ff6da306f 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -123,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 3122e7326d8..95bb0eb244f 100644 --- a/node/service/src/chain_spec/vara.rs +++ b/node/service/src/chain_spec/vara.rs @@ -91,6 +91,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())?; diff --git a/node/testing/Cargo.toml b/node/testing/Cargo.toml index 807793fdf89..8607639dc26 100644 --- a/node/testing/Cargo.toml +++ b/node/testing/Cargo.toml @@ -72,5 +72,5 @@ std = [ "gear-runtime?/std", "vara-runtime?/std", ] -gear-native = ["gear-runtime"] -vara-native = ["vara-runtime"] +gear-native = ["gear-runtime/dev"] +vara-native = ["vara-runtime/dev"] diff --git a/pallets/gear-debug/Cargo.toml b/pallets/gear-debug/Cargo.toml index f4d0e4c3294..af5b894aecf 100644 --- a/pallets/gear-debug/Cargo.toml +++ b/pallets/gear-debug/Cargo.toml @@ -45,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-program/Cargo.toml b/pallets/gear-program/Cargo.toml index 0dd3e2653b9..72b9afd28e1 100644 --- a/pallets/gear-program/Cargo.toml +++ b/pallets/gear-program/Cargo.toml @@ -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/runtime/gear/Cargo.toml b/runtime/gear/Cargo.toml index 005773f2bed..fdd6f2deb3a 100644 --- a/runtime/gear/Cargo.toml +++ b/runtime/gear/Cargo.toml @@ -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/lib.rs b/runtime/gear/src/lib.rs index e7ed11281e6..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; @@ -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/vara/Cargo.toml b/runtime/vara/Cargo.toml index dcfed171e56..74551fefa6d 100644 --- a/runtime/vara/Cargo.toml +++ b/runtime/vara/Cargo.toml @@ -255,7 +255,7 @@ 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"] lazy-pages = [ "pallet-gear/lazy-pages", "pallet-gear-payment/lazy-pages", diff --git a/runtime/vara/src/lib.rs b/runtime/vara/src/lib.rs index 6317db2cc24..7b9f86b4447 100644 --- a/runtime/vara/src/lib.rs +++ b/runtime/vara/src/lib.rs @@ -104,7 +104,7 @@ pub use pallet_sudo::Call as SudoCall; 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; @@ -988,7 +988,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; @@ -1104,7 +1104,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, @@ -1163,12 +1163,12 @@ construct_runtime!( // 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, @@ -1269,9 +1269,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")] 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