Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

companion for try-runtime revamp #6187

Merged
merged 15 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ polkadot-node-core-pvf = { path = "../node/core/pvf", optional = true }
polkadot-performance-test = { path = "../node/test/performance-test", optional = true }

sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
Expand All @@ -34,6 +35,7 @@ sc-service = { git = "https://github.com/paritytech/substrate", branch = "master
polkadot-node-metrics = { path = "../node/metrics" }
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
20 changes: 11 additions & 9 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,14 @@ pub fn run() -> Result<()> {
Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?),
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec;
set_default_ss58_version(chain_spec);
type HostFunctionsOf<E> = ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<E as NativeExecutionDispatch>::ExtendHostFunctions,
>;

use sc_service::TaskManager;
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
Expand All @@ -651,10 +656,9 @@ pub fn run() -> Result<()> {

#[cfg(feature = "kusama-native")]
if chain_spec.is_kusama() {
return runner.async_run(|config| {
return runner.async_run(|_| {
Ok((
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutorDispatch>(
config,
cmd.run::<service::kusama_runtime::Block, HostFunctionsOf<service::KusamaExecutorDispatch>>(
)
.map_err(Error::SubstrateCli),
task_manager,
Expand All @@ -664,10 +668,9 @@ pub fn run() -> Result<()> {

#[cfg(feature = "westend-native")]
if chain_spec.is_westend() {
return runner.async_run(|config| {
return runner.async_run(|_| {
Ok((
cmd.run::<service::westend_runtime::Block, service::WestendExecutorDispatch>(
config,
cmd.run::<service::westend_runtime::Block, HostFunctionsOf<service::WestendExecutorDispatch>>(
)
.map_err(Error::SubstrateCli),
task_manager,
Expand All @@ -677,10 +680,9 @@ pub fn run() -> Result<()> {
// else we assume it is polkadot.
#[cfg(feature = "polkadot-native")]
{
return runner.async_run(|config| {
return runner.async_run(|_| {
Ok((
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutorDispatch>(
config,
cmd.run::<service::polkadot_runtime::Block, HostFunctionsOf<service::PolkadotExecutorDispatch>>(
)
.map_err(Error::SubstrateCli),
task_manager,
Expand Down
24 changes: 12 additions & 12 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,21 +1913,21 @@ sp_api::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: bool) -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade kusama.");
let weight = Executive::try_runtime_upgrade().unwrap();
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, BlockWeights::get().max_block)
}

fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight {
log::info!(
target: "runtime::kusama", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}",
block.header.number,
block.header.hash(),
state_root_check,
select,
);
Executive::try_execute_block(block, state_root_check, select).expect("try_execute_block failed")
fn execute_block(
block: Block,
state_root_check: bool,
signature_check: bool,
select: frame_try_runtime::TryStateSelect,
) -> Weight {
// 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, signature_check, select).unwrap()
}
}

Expand Down Expand Up @@ -2233,6 +2233,6 @@ mod remote_tests {
.build()
.await
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade());
ext.execute_with(|| Runtime::on_runtime_upgrade(true));
}
}
24 changes: 12 additions & 12 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2015,21 +2015,21 @@ sp_api::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: bool) -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade polkadot.");
let weight = Executive::try_runtime_upgrade().unwrap();
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, BlockWeights::get().max_block)
}

fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight {
log::info!(
target: "runtime::polkadot", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}",
block.header.number,
block.header.hash(),
state_root_check,
select,
);
Executive::try_execute_block(block, state_root_check, select).expect("try_execute_block failed")
fn execute_block(
block: Block,
state_root_check: bool,
signature_check: bool,
select: frame_try_runtime::TryStateSelect,
) -> Weight {
// 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, signature_check, select).unwrap()
}
}

Expand Down Expand Up @@ -2441,6 +2441,6 @@ mod remote_tests {
.build()
.await
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade());
ext.execute_with(|| Runtime::on_runtime_upgrade(true));
}
}
24 changes: 12 additions & 12 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,21 +1630,21 @@ sp_api::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: bool) -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade westend.");
let weight = Executive::try_runtime_upgrade().unwrap();
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, BlockWeights::get().max_block)
}

fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight {
log::info!(
target: "runtime::westend", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}",
block.header.number,
block.header.hash(),
state_root_check,
select,
);
Executive::try_execute_block(block, state_root_check, select).expect("try_execute_block failed")
fn execute_block(
block: Block,
state_root_check: bool,
signature_check: bool,
select: frame_try_runtime::TryStateSelect,
) -> Weight {
// 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, signature_check, select).unwrap()
}
}

Expand Down Expand Up @@ -1832,6 +1832,6 @@ mod remote_tests {
.build()
.await
.unwrap();
ext.execute_with(|| Runtime::on_runtime_upgrade());
ext.execute_with(|| Runtime::on_runtime_upgrade(true));
}
}
7 changes: 4 additions & 3 deletions utils/staking-miner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ async fn create_election_ext<T, B>(
) -> Result<Ext, Error<T>>
where
T: EPM::Config,
B: BlockT,
B: BlockT + DeserializeOwned,
B::Header: DeserializeOwned,
{
use frame_support::{storage::generator::StorageMap, traits::PalletInfo};
Expand All @@ -317,13 +317,14 @@ where
transport: client.into_inner().into(),
at,
pallets,
hashed_prefixes: vec![<frame_system::BlockHash<T>>::prefix_hash()],
hashed_keys: vec![[twox_128(b"System"), twox_128(b"Number")].concat()],
..Default::default()
}))
.inject_hashed_prefix(&<frame_system::BlockHash<T>>::prefix_hash())
.inject_hashed_key(&[twox_128(b"System"), twox_128(b"Number")].concat())
.build()
.await
.map_err(|why| Error::RemoteExternalities(why))
.map(|rx| rx.inner_ext)
}

/// Compute the election. It expects to NOT be `Phase::Off`. In other words, the snapshot must
Expand Down