diff --git a/.github/workflows/rust-checks.yaml b/.github/workflows/rust-checks.yaml index 6fb26152264..db4b50ace0b 100644 --- a/.github/workflows/rust-checks.yaml +++ b/.github/workflows/rust-checks.yaml @@ -11,31 +11,31 @@ concurrency: cancel-in-progress: true jobs: - rust-checks: + rust-fmt: runs-on: ubuntu-20.04 steps: - name: Checkout source code uses: actions/checkout@v4 - - - name: Install Protoc - uses: arduino/setup-protoc@v1 + - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - version: "3.6.1" - - - name: Install clippy and fmt - run: rustup component add clippy rustfmt - - - name: Add wasm32-unknown-unknown target - run: rustup target add wasm32-unknown-unknown - - - name: Run Format Checks - uses: actions-rs/cargo@v1 + toolchain: nightly + components: rustfmt + - uses: actions-rust-lang/rustfmt@v1 + clippy-lint: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - command: fmt - args: --all - + toolchain: stable + components: clippy + - name: Install deps for musl build + run: | + sudo apt-get update + sudo apt-get install -y protobuf-compiler musl-tools clang build-essential curl llvm-dev libclang-dev linux-headers-generic libsnappy-dev liblz4-dev libzstd-dev libgflags-dev zlib1g-dev libbz2-dev + sudo ln -s /usr/bin/g++ /usr/bin/musl-g++ - name: Clippy - uses: actions-rs/cargo@v1 + uses: actions-rs-plus/clippy-check@v2 with: - command: clippy - args: --all-targets -- --no-deps -D warnings + toolchain: stable + args: --all-targets --all-features diff --git a/core/src/commands/create_snapshot.rs b/core/src/commands/create_snapshot.rs index 003d95df9fc..8594fb375d3 100644 --- a/core/src/commands/create_snapshot.rs +++ b/core/src/commands/create_snapshot.rs @@ -23,7 +23,7 @@ use substrate_rpc_client::{ws_client, StateApi}; use crate::{ build_executor, - state::{LiveState, State}, + state::{LiveState, SpecVersionCheck, State, TryRuntimeFeatureCheck}, SharedParams, LOG_TARGET, }; @@ -76,7 +76,13 @@ where let executor = build_executor::(&shared); let _ = State::Live(command.from) - .to_ext::(&shared, &executor, Some(path.into()), false, false) + .to_ext::( + &shared, + &executor, + Some(path.into()), + TryRuntimeFeatureCheck::Skip, + SpecVersionCheck::Skip, + ) .await?; Ok(()) diff --git a/core/src/commands/execute_block.rs b/core/src/commands/execute_block.rs index b36afcbaa67..d9dc17184b4 100644 --- a/core/src/commands/execute_block.rs +++ b/core/src/commands/execute_block.rs @@ -28,7 +28,7 @@ use substrate_rpc_client::{ws_client, ChainApi}; use crate::{ build_executor, full_extensions, rpc_err_handler, - state::{LiveState, State}, + state::{LiveState, SpecVersionCheck, State, TryRuntimeFeatureCheck}, state_machine_call_with_proof, SharedParams, LOG_TARGET, }; @@ -97,7 +97,13 @@ where let executor = build_executor::(&shared); let ext = command .state - .to_ext::(&shared, &executor, None, true, false) + .to_ext::( + &shared, + &executor, + None, + TryRuntimeFeatureCheck::Check, + SpecVersionCheck::Skip, + ) .await?; // get the block number associated with this block. diff --git a/core/src/commands/fast_forward.rs b/core/src/commands/fast_forward.rs index 10a2d964a83..3140e892f64 100644 --- a/core/src/commands/fast_forward.rs +++ b/core/src/commands/fast_forward.rs @@ -35,7 +35,7 @@ use crate::{ build_executor, full_extensions, inherent_provider::{Chain, InherentProvider}, rpc_err_handler, - state::{LiveState, State}, + state::{LiveState, SpecVersionCheck, State, TryRuntimeFeatureCheck}, state_machine_call, state_machine_call_with_proof, BlockT, SharedParams, }; @@ -234,7 +234,13 @@ where let executor = build_executor::(&shared); let ext = command .state - .to_ext::(&shared, &executor, None, true, false) + .to_ext::( + &shared, + &executor, + None, + TryRuntimeFeatureCheck::Check, + SpecVersionCheck::Skip, + ) .await?; if command.run_migrations { diff --git a/core/src/commands/follow_chain.rs b/core/src/commands/follow_chain.rs index 82af36abd30..f6ac38e9677 100644 --- a/core/src/commands/follow_chain.rs +++ b/core/src/commands/follow_chain.rs @@ -29,7 +29,7 @@ use substrate_rpc_client::{ws_client, ChainApi, FinalizedHeaders, Subscription, use crate::{ build_executor, full_extensions, parse, rpc_err_handler, - state::{LiveState, State}, + state::{LiveState, SpecVersionCheck, State, TryRuntimeFeatureCheck}, state_machine_call_with_proof, SharedParams, LOG_TARGET, }; @@ -143,7 +143,13 @@ where hashed_prefixes: vec![], }); let ext = state - .to_ext::(&shared, &executor, None, true, false) + .to_ext::( + &shared, + &executor, + None, + TryRuntimeFeatureCheck::Check, + SpecVersionCheck::Skip, + ) .await?; maybe_state_ext = Some(ext); } diff --git a/core/src/commands/offchain_worker.rs b/core/src/commands/offchain_worker.rs index 2b3daeca83c..fb9b54c2627 100644 --- a/core/src/commands/offchain_worker.rs +++ b/core/src/commands/offchain_worker.rs @@ -26,7 +26,7 @@ use crate::{ build_executor, commands::execute_block::next_hash_of, full_extensions, parse, rpc_err_handler, - state::{LiveState, State}, + state::{LiveState, SpecVersionCheck, State, TryRuntimeFeatureCheck}, state_machine_call, SharedParams, LOG_TARGET, }; @@ -78,7 +78,13 @@ where // we first build the externalities with the remote code. let ext = command .state - .to_ext::(&shared, &executor, None, true, false) + .to_ext::( + &shared, + &executor, + None, + TryRuntimeFeatureCheck::Check, + SpecVersionCheck::Skip, + ) .await?; let header_ws_uri = command.header_ws_uri(); diff --git a/core/src/commands/on_runtime_upgrade.rs b/core/src/commands/on_runtime_upgrade.rs index 22a8c9ef421..5787745858c 100644 --- a/core/src/commands/on_runtime_upgrade.rs +++ b/core/src/commands/on_runtime_upgrade.rs @@ -27,8 +27,9 @@ use sp_runtime::traits::{Block as BlockT, NumberFor}; use sp_state_machine::{CompactProof, StorageProof}; use crate::{ - build_executor, state::State, state_machine_call_with_proof, RefTimeInfo, SharedParams, - LOG_TARGET, + build_executor, + state::{SpecVersionCheck, State, TryRuntimeFeatureCheck}, + state_machine_call_with_proof, RefTimeInfo, SharedParams, LOG_TARGET, }; /// Configuration for [`run`]. @@ -76,7 +77,13 @@ where let executor = build_executor(&shared); let ext = command .state - .to_ext::(&shared, &executor, None, true, true) + .to_ext::( + &shared, + &executor, + None, + TryRuntimeFeatureCheck::Check, + SpecVersionCheck::Check, + ) .await?; if let State::Live(_) = command.state { diff --git a/core/src/shared_parameters.rs b/core/src/shared_parameters.rs index 84a457a706e..2f766e4cc5e 100644 --- a/core/src/shared_parameters.rs +++ b/core/src/shared_parameters.rs @@ -17,12 +17,13 @@ use std::{path::PathBuf, str::FromStr}; -use sc_cli::{WasmExecutionMethod, WasmtimeInstantiationStrategy}; -use sp_runtime::StateVersion; -use { - crate::parse, - sc_cli::{DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD}, +use sc_cli::{ + WasmExecutionMethod, WasmtimeInstantiationStrategy, DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, + DEFAULT_WASM_EXECUTION_METHOD, }; +use sp_runtime::StateVersion; + +use crate::parse; /// Shared parameters of the `try-runtime` commands #[derive(Debug, Clone, clap::Parser)] diff --git a/core/src/state.rs b/core/src/state.rs index aab58bc4aaa..03d986dc2ca 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -97,6 +97,30 @@ pub enum State { Live(LiveState), } +/// Options for [`to_ext`] +/// +/// Whether to check that the runtime was compiled with try-runtime feature +#[derive(PartialEq, PartialOrd)] +pub enum TryRuntimeFeatureCheck { + /// Check the runtime was compiled with try-runtime feature + Check, + /// Don't check if the runtime was compiled with try-runtime feature + Skip, +} +/// Options for [`to_ext`] +/// +/// Whether to check if the new runtime `spec_version` is greater than the previous runtime +/// `spec_version` +#[derive(PartialEq, PartialOrd)] +pub enum SpecVersionCheck { + /// Check that the new runtime `spec_version` is greater than the previous runtime + /// `spec_version` + Check, + /// Don't check that the new runtime `spec_version` is greater than the previous runtime + /// `spec_version` + Skip, +} + impl State { /// Create the [`RemoteExternalities`]. /// @@ -107,8 +131,8 @@ impl State { shared: &SharedParams, executor: &WasmExecutor, state_snapshot: Option, - try_runtime_check: bool, - spec_version_check: bool, + try_runtime_check: TryRuntimeFeatureCheck, + spec_version_check: SpecVersionCheck, ) -> sc_cli::Result> where Block::Header: DeserializeOwned, @@ -256,7 +280,9 @@ impl State { return Err("Spec names must match.".into()); } - if spec_version_check && new_version.spec_version <= old_version.spec_version { + if spec_version_check == SpecVersionCheck::Check + && new_version.spec_version <= old_version.spec_version + { log::warn!( target: LOG_TARGET, "New runtime spec version is not greater than the on-chain runtime spec version. Don't forget to increment the spec version if you intend to use the new code in a runtime upgrade." @@ -265,7 +291,9 @@ impl State { } // whatever runtime we have in store now must have been compiled with try-runtime feature. - if try_runtime_check && !ensure_try_runtime::(executor, &mut ext) { + if try_runtime_check == TryRuntimeFeatureCheck::Check + && !ensure_try_runtime::(executor, &mut ext) + { return Err("given runtime is NOT compiled with try-runtime feature!".into()); }