Skip to content

Commit

Permalink
chore(v1.0.0): Development features gate (#3277)
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx authored Sep 15, 2023
1 parent 9e2576b commit 80fb847
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 69 deletions.
53 changes: 37 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions gsdk/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ fn generate_api() -> Vec<u8> {
// 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));
Expand Down
2 changes: 1 addition & 1 deletion node/authorship/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 26 additions & 13 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,32 @@ impl SubstrateCli for Cli {

fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, 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")[..],
)?),
Expand All @@ -75,24 +87,25 @@ impl SubstrateCli for Cli {
let chain_spec = Box::new(chain_spec::RawChainSpec::from_json_file(path.clone())?)
as Box<dyn ChainSpec>;

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());
}
}
})
Expand Down
6 changes: 3 additions & 3 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions node/service/src/chain_spec/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn authority_keys_from_seed(s: &str) -> (AccountId, BabeId, GrandpaId) {
)
}

#[cfg(feature = "dev")]
pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

Expand Down
1 change: 1 addition & 0 deletions node/service/src/chain_spec/vara.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn authority_keys_from_seed(
)
}

#[cfg(feature = "dev")]
pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

Expand Down
4 changes: 2 additions & 2 deletions node/testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion pallets/gear-debug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pallets/gear-debug/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn debug_mode_works() {
)
.expect("Failed to submit program");

// Enable debug-mode
// Enable debug mode.
DebugMode::<Test>::put(true);

run_to_block(2, None);
Expand Down Expand Up @@ -528,7 +528,7 @@ fn check_not_allocated_pages() {
0_u128,
));

// Enable debug-mode
// Enable debug mode.
DebugMode::<Test>::put(true);

run_to_block(2, None);
Expand Down Expand Up @@ -756,7 +756,7 @@ fn check_changed_pages_in_storage() {
0_u128,
));

// Enable debug-mode
// Enable debug mode.
DebugMode::<Test>::put(true);

run_to_block(2, None);
Expand Down Expand Up @@ -886,7 +886,7 @@ fn check_gear_stack_end() {
0_u128,
));

// Enable debug-mode
// Enable debug mode.
DebugMode::<Test>::put(true);

run_to_block(2, None);
Expand Down
2 changes: 1 addition & 1 deletion pallets/gear-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ std = [
"primitive-types/std",
]
try-runtime = ["frame-support/try-runtime"]
debug-mode = []
dev = []
4 changes: 2 additions & 2 deletions pallets/gear-program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -388,7 +388,7 @@ pub mod pallet {
type SessionMemoryPages = SessionMemoryPagesWrap<T>;
}

#[cfg(feature = "debug-mode")]
#[cfg(feature = "dev")]
impl<T: Config> IterableMap<(ProgramId, Program<BlockNumberFor<T>>)> for pallet::Pallet<T> {
type DrainIter = PrefixIterator<(ProgramId, Program<BlockNumberFor<T>>)>;
type Iter = PrefixIterator<(ProgramId, Program<BlockNumberFor<T>>)>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/gear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions runtime/gear/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Runtime>;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion runtime/vara/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 80fb847

Please sign in to comment.