Remove RuntimeApi dependency on system parachain runtime code (#2455)

The last issue blocking the removal of the Polkadot and Kusama system
parachains from the repo in #1737 is the dependency on the runtime code
through the RuntimeApi in `polkadot-parachain`.

This PR introduces two fake runtimes to satisfy the build requirements
and changes the `new_partial` function to make it not be generic over
the runtimes.
The reason for the second runtime is the different Aura keys used in
Polkadot Asset Hub, as the impl for AuraApi depends on this type.
If this changes the `RuntimeApi` generic could be removed completely
from all functions in `services.rs` and and generic type parameters in
`services.rs` and specified as a concrete type to TFullClient`.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Dónal Murray
2023-11-24 16:48:56 +00:00
committed by GitHub
parent 8af61d03b6
commit d07186b8e3
9 changed files with 497 additions and 261 deletions
+44 -241
View File
@@ -17,6 +17,9 @@
use crate::{
chain_spec,
cli::{Cli, RelayChainCli, Subcommand},
fake_runtime_api::{
asset_hub_polkadot_aura::RuntimeApi as AssetHubPolkadotRuntimeApi, aura::RuntimeApi,
},
service::{new_partial, Block},
};
use cumulus_primitives_core::ParaId;
@@ -439,128 +442,46 @@ impl SubstrateCli for RelayChainCli {
macro_rules! construct_partials {
($config:expr, |$partials:ident| $code:expr) => {
match $config.chain_spec.runtime() {
Runtime::AssetHubKusama => {
let $partials = new_partial::<asset_hub_kusama_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
Runtime::AssetHubRococo => {
let $partials = new_partial::<asset_hub_rococo_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
Runtime::AssetHubWestend => {
let $partials = new_partial::<asset_hub_westend_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
Runtime::AssetHubPolkadot => {
let $partials = new_partial::<asset_hub_polkadot_runtime::RuntimeApi, _>(
let $partials = new_partial::<AssetHubPolkadotRuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AssetHubPolkadotAuraId>,
)?;
$code
},
Runtime::BridgeHub(bridge_hub_runtime_type) => match bridge_hub_runtime_type {
chain_spec::bridge_hubs::BridgeHubRuntimeType::Polkadot |
chain_spec::bridge_hubs::BridgeHubRuntimeType::PolkadotLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::PolkadotDevelopment => {
let $partials = new_partial::<chain_spec::bridge_hubs::polkadot::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
chain_spec::bridge_hubs::BridgeHubRuntimeType::Kusama |
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaDevelopment => {
let $partials = new_partial::<chain_spec::bridge_hubs::kusama::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
chain_spec::bridge_hubs::BridgeHubRuntimeType::Westend |
chain_spec::bridge_hubs::BridgeHubRuntimeType::WestendLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::WestendDevelopment => {
let $partials = new_partial::<chain_spec::bridge_hubs::westend::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
chain_spec::bridge_hubs::BridgeHubRuntimeType::Rococo |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoDevelopment => {
let $partials = new_partial::<chain_spec::bridge_hubs::rococo::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
},
Runtime::CollectivesPolkadot => {
let $partials = new_partial::<collectives_polkadot_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
Runtime::AssetHubKusama |
Runtime::AssetHubRococo |
Runtime::AssetHubWestend |
Runtime::BridgeHub(_) |
Runtime::CollectivesPolkadot |
Runtime::CollectivesWestend => {
let $partials = new_partial::<collectives_westend_runtime::RuntimeApi, _>(
let $partials = new_partial::<RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
Runtime::Shell => {
let $partials = new_partial::<shell_runtime::RuntimeApi, _>(
&$config,
crate::service::shell_build_import_queue,
)?;
$code
},
Runtime::Seedling => {
let $partials = new_partial::<seedling_runtime::RuntimeApi, _>(
Runtime::GluttonWestend | Runtime::Glutton | Runtime::Shell | Runtime::Seedling => {
let $partials = new_partial::<RuntimeApi, _>(
&$config,
crate::service::shell_build_import_queue,
)?;
$code
},
Runtime::ContractsRococo => {
let $partials = new_partial::<contracts_rococo_runtime::RuntimeApi, _>(
let $partials = new_partial::<RuntimeApi, _>(
&$config,
crate::service::contracts_rococo_build_import_queue,
)?;
$code
},
Runtime::Penpal(_) | Runtime::Default => {
let $partials = new_partial::<rococo_parachain_runtime::RuntimeApi, _>(
let $partials = new_partial::<RuntimeApi, _>(
&$config,
crate::service::rococo_parachain_build_import_queue,
)?;
$code
},
Runtime::GluttonWestend => {
let $partials = new_partial::<glutton_westend_runtime::RuntimeApi, _>(
&$config,
crate::service::shell_build_import_queue,
)?;
$code
},
Runtime::Glutton => {
let $partials = new_partial::<glutton_runtime::RuntimeApi, _>(
&$config,
crate::service::shell_build_import_queue,
)?;
$code
},
}
};
}
@@ -569,39 +490,9 @@ macro_rules! construct_async_run {
(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
let runner = $cli.create_runner($cmd)?;
match runner.config().chain_spec.runtime() {
Runtime::AssetHubWestend => {
runner.async_run(|$config| {
let $components = new_partial::<asset_hub_westend_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::AssetHubRococo => {
runner.async_run(|$config| {
let $components = new_partial::<asset_hub_rococo_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::AssetHubKusama => {
runner.async_run(|$config| {
let $components = new_partial::<asset_hub_kusama_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::AssetHubPolkadot => {
runner.async_run(|$config| {
let $components = new_partial::<asset_hub_polkadot_runtime::RuntimeApi, _>(
let $components = new_partial::<AssetHubPolkadotRuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AssetHubPolkadotAuraId>,
)?;
@@ -609,9 +500,14 @@ macro_rules! construct_async_run {
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::CollectivesPolkadot => {
Runtime::AssetHubWestend |
Runtime::AssetHubRococo |
Runtime::AssetHubKusama |
Runtime::CollectivesPolkadot |
Runtime::CollectivesWestend |
Runtime::BridgeHub(_) => {
runner.async_run(|$config| {
let $components = new_partial::<collectives_polkadot_runtime::RuntimeApi, _>(
let $components = new_partial::<RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
@@ -619,39 +515,22 @@ macro_rules! construct_async_run {
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::CollectivesWestend => {
Runtime::Shell |
Runtime::Seedling |
Runtime::GluttonWestend |
Runtime::Glutton => {
runner.async_run(|$config| {
let $components = new_partial::<collectives_westend_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::Shell => {
runner.async_run(|$config| {
let $components = new_partial::<shell_runtime::RuntimeApi, _>(
let $components = new_partial::<RuntimeApi, _>(
&$config,
crate::service::shell_build_import_queue,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::Seedling => {
runner.async_run(|$config| {
let $components = new_partial::<seedling_runtime::RuntimeApi, _>(
&$config,
crate::service::shell_build_import_queue,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
}
Runtime::ContractsRococo => {
runner.async_run(|$config| {
let $components = new_partial::<contracts_rococo_runtime::RuntimeApi, _>(
let $components = new_partial::<RuntimeApi, _>(
&$config,
crate::service::contracts_rococo_build_import_queue,
)?;
@@ -659,66 +538,10 @@ macro_rules! construct_async_run {
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::BridgeHub(bridge_hub_runtime_type) => {
match bridge_hub_runtime_type {
chain_spec::bridge_hubs::BridgeHubRuntimeType::Polkadot |
chain_spec::bridge_hubs::BridgeHubRuntimeType::PolkadotLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::PolkadotDevelopment => {
runner.async_run(|$config| {
let $components = new_partial::<chain_spec::bridge_hubs::polkadot::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
chain_spec::bridge_hubs::BridgeHubRuntimeType::Kusama |
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaDevelopment => {
runner.async_run(|$config| {
let $components = new_partial::<chain_spec::bridge_hubs::kusama::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
chain_spec::bridge_hubs::BridgeHubRuntimeType::Westend |
chain_spec::bridge_hubs::BridgeHubRuntimeType::WestendLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::WestendDevelopment => {
runner.async_run(|$config| {
let $components = new_partial::<chain_spec::bridge_hubs::westend::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
chain_spec::bridge_hubs::BridgeHubRuntimeType::Rococo |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoDevelopment => {
runner.async_run(|$config| {
let $components = new_partial::<chain_spec::bridge_hubs::rococo::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
}
},
Runtime::Penpal(_) | Runtime::Default => {
runner.async_run(|$config| {
let $components = new_partial::<
rococo_parachain_runtime::RuntimeApi,
RuntimeApi,
_,
>(
&$config,
@@ -728,26 +551,6 @@ macro_rules! construct_async_run {
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::GluttonWestend => {
runner.async_run(|$config| {
let $components = new_partial::<glutton_westend_runtime::RuntimeApi, _>(
&$config,
crate::service::shell_build_import_queue,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::Glutton => {
runner.async_run(|$config| {
let $components = new_partial::<glutton_runtime::RuntimeApi, _>(
&$config,
crate::service::shell_build_import_queue,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
}
}
}}
}
@@ -927,28 +730,28 @@ pub fn run() -> Result<()> {
match config.chain_spec.runtime() {
Runtime::AssetHubPolkadot => crate::service::start_asset_hub_node::<
asset_hub_polkadot_runtime::RuntimeApi,
AssetHubPolkadotRuntimeApi,
AssetHubPolkadotAuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::AssetHubKusama => crate::service::start_asset_hub_node::<
asset_hub_kusama_runtime::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::AssetHubRococo => crate::service::start_asset_hub_node::<
asset_hub_rococo_runtime::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::AssetHubWestend => crate::service::start_asset_hub_node::<
asset_hub_westend_runtime::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
@@ -956,7 +759,7 @@ pub fn run() -> Result<()> {
.map_err(Into::into),
Runtime::CollectivesPolkadot =>
crate::service::start_generic_aura_node::<
collectives_polkadot_runtime::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
@@ -964,14 +767,14 @@ pub fn run() -> Result<()> {
.map_err(Into::into),
Runtime::CollectivesWestend =>
crate::service::start_generic_aura_node::<
collectives_westend_runtime::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::Shell =>
crate::service::start_shell_node::<shell_runtime::RuntimeApi>(
crate::service::start_shell_node::<RuntimeApi>(
config,
polkadot_config,
collator_options,
@@ -982,7 +785,7 @@ pub fn run() -> Result<()> {
.map(|r| r.0)
.map_err(Into::into),
Runtime::Seedling =>
crate::service::start_shell_node::<seedling_runtime::RuntimeApi>(
crate::service::start_shell_node::<RuntimeApi>(
config,
polkadot_config,
collator_options,
@@ -1007,7 +810,7 @@ chain_spec::bridge_hubs::BridgeHubRuntimeType::Polkadot |
chain_spec::bridge_hubs::BridgeHubRuntimeType::PolkadotLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::PolkadotDevelopment =>
crate::service::start_generic_aura_node::<
chain_spec::bridge_hubs::polkadot::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
@@ -1016,7 +819,7 @@ chain_spec::bridge_hubs::BridgeHubRuntimeType::Polkadot |
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaDevelopment =>
crate::service::start_generic_aura_node::<
chain_spec::bridge_hubs::kusama::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
@@ -1025,7 +828,7 @@ chain_spec::bridge_hubs::BridgeHubRuntimeType::Polkadot |
chain_spec::bridge_hubs::BridgeHubRuntimeType::WestendLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::WestendDevelopment =>
crate::service::start_generic_aura_node::<
chain_spec::bridge_hubs::westend::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
@@ -1034,7 +837,7 @@ chain_spec::bridge_hubs::BridgeHubRuntimeType::Polkadot |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoDevelopment =>
crate::service::start_generic_aura_node::<
chain_spec::bridge_hubs::rococo::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
@@ -1054,7 +857,7 @@ chain_spec::bridge_hubs::BridgeHubRuntimeType::Polkadot |
.map_err(Into::into),
Runtime::GluttonWestend =>
crate::service::start_basic_lookahead_node::<
glutton_westend_runtime::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
@@ -1062,7 +865,7 @@ chain_spec::bridge_hubs::BridgeHubRuntimeType::Polkadot |
.map_err(Into::into),
Runtime::Glutton =>
crate::service::start_basic_lookahead_node::<
glutton_runtime::RuntimeApi,
RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await