Skip to content

Commit

Permalink
Merge branch 'main' of github.com:paritytech/try-runtime-cli into lia…
Browse files Browse the repository at this point in the history
…m-tests-workflow
  • Loading branch information
liamaharon committed Nov 3, 2023
2 parents 59429e2 + a72d592 commit dda1bec
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 42 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/rust-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions core/src/commands/create_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -76,7 +76,13 @@ where

let executor = build_executor::<HostFns>(&shared);
let _ = State::Live(command.from)
.to_ext::<Block, HostFns>(&shared, &executor, Some(path.into()), false, false)
.to_ext::<Block, HostFns>(
&shared,
&executor,
Some(path.into()),
TryRuntimeFeatureCheck::Skip,
SpecVersionCheck::Skip,
)
.await?;

Ok(())
Expand Down
10 changes: 8 additions & 2 deletions core/src/commands/execute_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -97,7 +97,13 @@ where
let executor = build_executor::<HostFns>(&shared);
let ext = command
.state
.to_ext::<Block, HostFns>(&shared, &executor, None, true, false)
.to_ext::<Block, HostFns>(
&shared,
&executor,
None,
TryRuntimeFeatureCheck::Check,
SpecVersionCheck::Skip,
)
.await?;

// get the block number associated with this block.
Expand Down
10 changes: 8 additions & 2 deletions core/src/commands/fast_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -234,7 +234,13 @@ where
let executor = build_executor::<HostFns>(&shared);
let ext = command
.state
.to_ext::<Block, HostFns>(&shared, &executor, None, true, false)
.to_ext::<Block, HostFns>(
&shared,
&executor,
None,
TryRuntimeFeatureCheck::Check,
SpecVersionCheck::Skip,
)
.await?;

if command.run_migrations {
Expand Down
10 changes: 8 additions & 2 deletions core/src/commands/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -143,7 +143,13 @@ where
hashed_prefixes: vec![],
});
let ext = state
.to_ext::<Block, HostFns>(&shared, &executor, None, true, false)
.to_ext::<Block, HostFns>(
&shared,
&executor,
None,
TryRuntimeFeatureCheck::Check,
SpecVersionCheck::Skip,
)
.await?;
maybe_state_ext = Some(ext);
}
Expand Down
10 changes: 8 additions & 2 deletions core/src/commands/offchain_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -78,7 +78,13 @@ where
// we first build the externalities with the remote code.
let ext = command
.state
.to_ext::<Block, HostFns>(&shared, &executor, None, true, false)
.to_ext::<Block, HostFns>(
&shared,
&executor,
None,
TryRuntimeFeatureCheck::Check,
SpecVersionCheck::Skip,
)
.await?;

let header_ws_uri = command.header_ws_uri();
Expand Down
13 changes: 10 additions & 3 deletions core/src/commands/on_runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down Expand Up @@ -76,7 +77,13 @@ where
let executor = build_executor(&shared);
let ext = command
.state
.to_ext::<Block, HostFns>(&shared, &executor, None, true, true)
.to_ext::<Block, HostFns>(
&shared,
&executor,
None,
TryRuntimeFeatureCheck::Check,
SpecVersionCheck::Check,
)
.await?;

if let State::Live(_) = command.state {
Expand Down
11 changes: 6 additions & 5 deletions core/src/shared_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
36 changes: 32 additions & 4 deletions core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
///
Expand All @@ -107,8 +131,8 @@ impl State {
shared: &SharedParams,
executor: &WasmExecutor<HostFns>,
state_snapshot: Option<SnapshotConfig>,
try_runtime_check: bool,
spec_version_check: bool,
try_runtime_check: TryRuntimeFeatureCheck,
spec_version_check: SpecVersionCheck,
) -> sc_cli::Result<RemoteExternalities<Block>>
where
Block::Header: DeserializeOwned,
Expand Down Expand Up @@ -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."
Expand All @@ -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::<Block, HostFns>(executor, &mut ext) {
if try_runtime_check == TryRuntimeFeatureCheck::Check
&& !ensure_try_runtime::<Block, HostFns>(executor, &mut ext)
{
return Err("given runtime is NOT compiled with try-runtime feature!".into());
}

Expand Down

0 comments on commit dda1bec

Please sign in to comment.