Skip to content

Commit

Permalink
Re-enable try-runtime (#139)
Browse files Browse the repository at this point in the history
* Add `try-runtime` & fix `avail-core` versions
* Toolchain to nightly-2022-11-25
  • Loading branch information
MiguelDD1 authored Feb 24, 2023
1 parent 64e4fa1 commit ce4e9aa
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 23 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main
- develop
env:
BUILD_TOOLCHAIN: nightly-2022-09-22
BUILD_TOOLCHAIN: nightly-2022-11-15
CARGO_SCCACHE_COMMIT: bed5571c
SCCACHE_DIR: /home/runner/.cache/cargo-sccache-bed5571c
SCCACHE_BIN: /home/runner/.cache/cargo-sccache-bed5571c/bin/sccache
Expand Down Expand Up @@ -60,9 +60,8 @@ jobs:
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
source "$HOME/.cargo/env"
rustup toolchain install nightly
rustup default nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup default ${{ env.BUILD_TOOLCHAIN }}
rustup target add wasm32-unknown-unknown --toolchain ${{ env.BUILD_TOOLCHAIN }}
- name: SCCache
run: |
Expand Down Expand Up @@ -119,9 +118,8 @@ jobs:
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
source "$HOME/.cargo/env"
rustup toolchain install nightly
rustup default nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup default ${{ env.BUILD_TOOLCHAIN }}
rustup target add wasm32-unknown-unknown --toolchain ${{ env.BUILD_TOOLCHAIN }}
- name: SCCache
run: |
Expand Down Expand Up @@ -181,9 +179,8 @@ jobs:
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
source "$HOME/.cargo/env"
rustup toolchain install nightly
rustup default nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup default ${{ env.BUILD_TOOLCHAIN }}
rustup target add wasm32-unknown-unknown --toolchain ${{ env.BUILD_TOOLCHAIN }}
- name: SCCache
run: |
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion avail-subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ num_enum = "0.5.9"

[dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
sp-keyring = "7.0.0"
sp-keyring = "6.0.0"
futures = "0.3.13"
hex-literal = "0.3.4"
test-case = "1.2.3"
Expand Down
4 changes: 3 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ hex-literal = "0.3.4"
# Substrate
## Primitives
sc-cli = "0.10.0-dev"
sp-io = "7.0.0"
sp-core = "7.0.0"
sc-executor = "0.10.0-dev"
sc-service = "0.10.0-dev"
Expand Down Expand Up @@ -135,7 +136,8 @@ runtime-benchmarks = [
# in the near future.
try-runtime = [
"da-runtime/try-runtime",
"try-runtime-cli/try-runtime"
"try-runtime-cli/try-runtime",
"da-primitives/try-runtime"
]


9 changes: 8 additions & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ pub fn run() -> Result<()> {
},
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
// we don't need any of the components of new_partial, just a runtime, or a task
Expand All @@ -255,7 +256,13 @@ pub fn run() -> Result<()> {
sc_service::TaskManager::new(config.tokio_handle.clone(), registry)
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;

Ok((cmd.run::<Block, ExecutorDispatch>(config), task_manager))
Ok((
cmd.run::<Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<ExecutorDispatch as NativeExecutionDispatch>::ExtendHostFunctions,
>>(),
task_manager,
))
})
},
#[cfg(not(feature = "try-runtime"))]
Expand Down
5 changes: 4 additions & 1 deletion pallets/dactr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"da-primitives/try-runtime"
]
7 changes: 6 additions & 1 deletion pallets/executive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ std = [
"sp-tracing/std",
"da-primitives/std",
]
try-runtime = ["frame-support/try-runtime", "frame-try-runtime/try-runtime" ]
try-runtime = [
"frame-support/try-runtime",
"frame-try-runtime/try-runtime" ,
"da-primitives/try-runtime",
"mocked-runtime/try-runtime"
]
4 changes: 3 additions & 1 deletion pallets/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Codec, Encode};
#[cfg(feature = "try-runtime")]
use da_primitives::asdr::AppId;
use da_primitives::asdr::GetAppId;
use frame_support::{
dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, PostDispatchInfo},
Expand Down Expand Up @@ -265,7 +267,7 @@ where
} else {
uxt.unchecked_into_checked_i_know_what_i_am_doing(&Default::default())
}?;
<frame_system::Pallet<System>>::note_extrinsic(encoded);
<frame_system::Pallet<System>>::note_extrinsic(AppId::default(), encoded);

let dispatch_info = xt.get_dispatch_info();
let r = Applyable::apply::<UnsignedValidator>(xt, &dispatch_info, encoded_len)?;
Expand Down
1 change: 1 addition & 0 deletions pallets/mocked_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ pallet-staking = "4.0.0-dev"
[features]
default = ["std"]
std = [ ]
try-runtime = []
8 changes: 8 additions & 0 deletions pallets/mocked_runtime/src/test_xt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ impl<Call: Codec + Sync + Send, Context, Extra> Checkable<Context> for TestXt<Ca
type Checked = Self;

fn check(self, _: &Context) -> Result<Self::Checked, TransactionValidityError> { Ok(self) }

#[cfg(feature = "try-runtime")]
fn unchecked_into_checked_i_know_what_i_am_doing(
self,
_: &Context,
) -> Result<Self::Checked, TransactionValidityError> {
unreachable!()
}
}

impl<Call: Codec + Sync + Send, Extra> Extrinsic for TestXt<Call, Extra> {
Expand Down
5 changes: 4 additions & 1 deletion pallets/nomad/da-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"da-primitives/try-runtime"
]
5 changes: 4 additions & 1 deletion pallets/nomad/home/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"da-primitives/try-runtime"
]
5 changes: 4 additions & 1 deletion pallets/nomad/updater-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"da-primitives/try-runtime"
]
5 changes: 4 additions & 1 deletion pallets/system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"da-primitives/try-runtime"
]
force-rs-merkle = [ "rs_merkle" ]

# For testing backward/forward header compatibility.
Expand Down
3 changes: 3 additions & 0 deletions pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ impl Config for Test {
type Version = Version;
}

#[allow(dead_code)]
pub type SysEvent = frame_system::Event<Test>;

/// A simple call, which one doesn't matter.
#[allow(dead_code)]
pub const CALL: &<Test as Config>::RuntimeCall =
&RuntimeCall::System(frame_system::Call::set_heap_pages { pages: 0u64 });

/// Create new externalities for `System` module tests.
#[allow(dead_code)]
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut ext: sp_io::TestExternalities = GenesisConfig::default()
.system
Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,5 @@ try-runtime = [
"pallet-nomination-pools/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-tips/try-runtime",
"da-primitives/try-runtime",
]
7 changes: 4 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,17 +1618,18 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> (Weight, Weight) {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here. If any of the pre/post migration checks fail, we shall stop
// right here and right now.
let weight = Executive::try_runtime_upgrade().unwrap();
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, RuntimeBlockWeights::get().max_block)
}

fn execute_block(
block: Block,
state_root_check: bool,
signature_check: bool,
select: frame_try_runtime::TryStateSelect
) -> Weight {
log::info!(
Expand All @@ -1640,7 +1641,7 @@ impl_runtime_apis! {
);
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here.
Executive::try_execute_block(block, state_root_check, select).unwrap()
Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
}
}

Expand Down

0 comments on commit ce4e9aa

Please sign in to comment.