companion for try-runtime revamp (#1997)

* companion for try-rutnime revamp

* Fixes

Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
Kian Paimani
2022-12-15 10:50:52 +00:00
committed by GitHub
parent 7cab12e9d2
commit 42c9988600
13 changed files with 408 additions and 391 deletions
+265 -255
View File
File diff suppressed because it is too large Load Diff
@@ -45,6 +45,7 @@ sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch =
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -231,14 +231,20 @@ pub fn run() -> Result<()> {
Some(Subcommand::TryRuntime(cmd)) => { Some(Subcommand::TryRuntime(cmd)) => {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
type HostFunctionsOf<E> = ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<E as NativeExecutionDispatch>::ExtendHostFunctions,
>;
// grab the task manager. // grab the task manager.
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry); let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager = let task_manager =
sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry) sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)
.map_err(|e| format!("Error: {:?}", e))?; .map_err(|e| format!("Error: {:?}", e))?;
runner.async_run(|config| { runner.async_run(|_| {
Ok((cmd.run::<Block, ParachainNativeExecutor>(config), task_manager)) Ok((cmd.run::<Block, HostFunctionsOf<ParachainNativeExecutor>>(), task_manager))
}) })
}, },
#[cfg(not(feature = "try-runtime"))] #[cfg(not(feature = "try-runtime"))]
+11 -12
View File
@@ -632,21 +632,20 @@ impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for 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 parachain-template."); let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block) (weight, RuntimeBlockWeights::get().max_block)
} }
fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { fn execute_block(
log::info!( block: Block,
target: "runtime::parachain-template", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", state_root_check: bool,
block.header.number, signature_check: bool,
block.header.hash(), select: frame_try_runtime::TryStateSelect,
state_root_check, ) -> Weight {
select, // 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).expect("try_execute_block failed") Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
} }
} }
@@ -803,21 +803,20 @@ impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for 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 statemine."); let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block) (weight, RuntimeBlockWeights::get().max_block)
} }
fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { fn execute_block(
log::info!( block: Block,
target: "runtime::statemine", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", state_root_check: bool,
block.header.number, signature_check: bool,
block.header.hash(), select: frame_try_runtime::TryStateSelect,
state_root_check, ) -> Weight {
select, // 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).expect("try_execute_block failed") Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
} }
} }
@@ -816,21 +816,20 @@ impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for 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 statemint."); let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block) (weight, RuntimeBlockWeights::get().max_block)
} }
fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { fn execute_block(
log::info!( block: Block,
target: "runtime::statemint", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", state_root_check: bool,
block.header.number, signature_check: bool,
block.header.hash(), select: frame_try_runtime::TryStateSelect,
state_root_check, ) -> Weight {
select, // 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).expect("try_execute_block failed") Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
} }
} }
@@ -776,21 +776,20 @@ impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for 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 westmint."); let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block) (weight, RuntimeBlockWeights::get().max_block)
} }
fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { fn execute_block(
log::info!( block: Block,
target: "runtime::westmint", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", state_root_check: bool,
block.header.number, signature_check: bool,
block.header.hash(), select: frame_try_runtime::TryStateSelect,
state_root_check, ) -> Weight {
select, // 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).expect("try_execute_block failed") Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
} }
} }
@@ -551,21 +551,20 @@ impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for 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 bridge-hub-kusama."); let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block) (weight, RuntimeBlockWeights::get().max_block)
} }
fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { fn execute_block(
log::info!( block: Block,
target: "runtime::bridge-hub-kusama", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", state_root_check: bool,
block.header.number, signature_check: bool,
block.header.hash(), select: frame_try_runtime::TryStateSelect,
state_root_check, ) -> Weight {
select, // 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).expect("try_execute_block failed") Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
} }
} }
@@ -580,21 +580,20 @@ impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for 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 bridge-hub-rococo."); let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block) (weight, RuntimeBlockWeights::get().max_block)
} }
fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { fn execute_block(
log::info!( block: Block,
target: "runtime::bridge-hub-rococo", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", state_root_check: bool,
block.header.number, signature_check: bool,
block.header.hash(), select: frame_try_runtime::TryStateSelect,
state_root_check, ) -> Weight {
select, // 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).expect("try_execute_block failed") Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
} }
} }
@@ -715,21 +715,20 @@ impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for 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 collectives-polkadot."); let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block) (weight, RuntimeBlockWeights::get().max_block)
} }
fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { fn execute_block(
log::info!( block: Block,
target: "runtime::collectives-polkadot", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", state_root_check: bool,
block.header.number, signature_check: bool,
block.header.hash(), select: frame_try_runtime::TryStateSelect,
state_root_check, ) -> Weight {
select, // 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).expect("try_execute_block failed") Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
} }
} }
@@ -580,21 +580,20 @@ impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for 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 contracts"); let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block) (weight, RuntimeBlockWeights::get().max_block)
} }
fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { fn execute_block(
log::info!( block: Block,
target: "runtime::contracts", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", state_root_check: bool,
block.header.number, signature_check: bool,
block.header.hash(), select: frame_try_runtime::TryStateSelect,
state_root_check, ) -> Weight {
select, // 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).expect("try_execute_block failed") Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
} }
} }
@@ -696,21 +696,20 @@ impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for 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 penpal."); let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade().unwrap();
(weight, RuntimeBlockWeights::get().max_block) (weight, RuntimeBlockWeights::get().max_block)
} }
fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { fn execute_block(
log::info!( block: Block,
target: "runtime::penpal", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", state_root_check: bool,
block.header.number, signature_check: bool,
block.header.hash(), select: frame_try_runtime::TryStateSelect,
state_root_check, ) -> Weight {
select, // 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).expect("try_execute_block failed") Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
} }
} }
+27 -18
View File
@@ -682,40 +682,49 @@ pub fn run() -> Result<()> {
let task_manager = let task_manager =
sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry) sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)
.map_err(|e| format!("Error: {:?}", e))?; .map_err(|e| format!("Error: {:?}", e))?;
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
type HostFunctionsOf<E> = ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<E as NativeExecutionDispatch>::ExtendHostFunctions,
>;
match runner.config().chain_spec.runtime() { match runner.config().chain_spec.runtime() {
Runtime::Statemine => runner.async_run(|config| { Runtime::Statemine => runner.async_run(|_| {
Ok((cmd.run::<Block, StatemineRuntimeExecutor>(config), task_manager)) Ok((
cmd.run::<Block, HostFunctionsOf<StatemineRuntimeExecutor>>(),
task_manager,
))
}), }),
Runtime::Westmint => runner.async_run(|config| { Runtime::Westmint => runner.async_run(|_| {
Ok((cmd.run::<Block, WestmintRuntimeExecutor>(config), task_manager)) Ok((cmd.run::<Block, HostFunctionsOf<WestmintRuntimeExecutor>>(), task_manager))
}), }),
Runtime::Statemint => runner.async_run(|config| { Runtime::Statemint => runner.async_run(|_| {
Ok((cmd.run::<Block, StatemintRuntimeExecutor>(config), task_manager)) Ok((
cmd.run::<Block, HostFunctionsOf<StatemintRuntimeExecutor>>(),
task_manager,
))
}), }),
Runtime::CollectivesPolkadot | Runtime::CollectivesWestend => Runtime::CollectivesPolkadot | Runtime::CollectivesWestend =>
runner.async_run(|config| { runner.async_run(|_| {
Ok(( Ok((
cmd.run::<Block, CollectivesPolkadotRuntimeExecutor>(config), cmd.run::<Block, HostFunctionsOf<CollectivesPolkadotRuntimeExecutor>>(),
task_manager, task_manager,
)) ))
}), }),
Runtime::BridgeHub(bridge_hub_runtime_type) => match bridge_hub_runtime_type { Runtime::BridgeHub(bridge_hub_runtime_type) => match bridge_hub_runtime_type {
chain_spec::bridge_hubs::BridgeHubRuntimeType::Kusama | chain_spec::bridge_hubs::BridgeHubRuntimeType::Kusama |
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaLocal | chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaDevelopment => chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaDevelopment => runner.async_run(|_| {
runner.async_run(|config| {
Ok(( Ok((
cmd.run::<Block, BridgeHubKusamaRuntimeExecutor>(config), cmd.run::<Block, HostFunctionsOf<BridgeHubKusamaRuntimeExecutor>>(),
task_manager, task_manager,
)) ))
}), }),
chain_spec::bridge_hubs::BridgeHubRuntimeType::Rococo | chain_spec::bridge_hubs::BridgeHubRuntimeType::Rococo |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoLocal | chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoDevelopment => chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoDevelopment => runner.async_run(|_| {
runner.async_run(|config| {
Ok(( Ok((
cmd.run::<Block, BridgeHubRococoRuntimeExecutor>(config), cmd.run::<Block, HostFunctionsOf<BridgeHubRococoRuntimeExecutor>>(),
task_manager, task_manager,
)) ))
}), }),
@@ -726,15 +735,15 @@ pub fn run() -> Result<()> {
) )
.into()), .into()),
}, },
Runtime::Shell => runner.async_run(|config| { Runtime::Shell => runner.async_run(|_| {
Ok(( Ok((
cmd.run::<Block, crate::service::ShellRuntimeExecutor>(config), cmd.run::<Block, HostFunctionsOf<crate::service::ShellRuntimeExecutor>>(),
task_manager, task_manager,
)) ))
}), }),
Runtime::ContractsRococo => runner.async_run(|config| { Runtime::ContractsRococo => runner.async_run(|_| {
Ok(( Ok((
cmd.run::<Block, crate::service::ContractsRococoRuntimeExecutor>(config), cmd.run::<Block, HostFunctionsOf<crate::service::ContractsRococoRuntimeExecutor>>(),
task_manager, task_manager,
)) ))
}), }),