From d07186b8e3ec6634187936caaae48bb8558e3346 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?D=C3=B3nal=20Murray?= <donal.murray@parity.io>
Date: Fri, 24 Nov 2023 16:48:56 +0000
Subject: [PATCH] Remove `RuntimeApi` dependency on system parachain runtime
 code (#2455)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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>
---
 Cargo.lock                                    |   9 +
 cumulus/polkadot-parachain/Cargo.toml         |  13 +
 .../src/chain_spec/bridge_hubs.rs             |   5 -
 cumulus/polkadot-parachain/src/command.rs     | 285 +++---------------
 .../asset_hub_polkadot_aura.rs                | 200 ++++++++++++
 .../src/fake_runtime_api/aura.rs              | 200 ++++++++++++
 .../src/fake_runtime_api/mod.rs               |  21 ++
 cumulus/polkadot-parachain/src/main.rs        |   1 +
 cumulus/polkadot-parachain/src/service.rs     |  24 +-
 9 files changed, 497 insertions(+), 261 deletions(-)
 create mode 100644 cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs
 create mode 100644 cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs
 create mode 100644 cumulus/polkadot-parachain/src/fake_runtime_api/mod.rs

diff --git a/Cargo.lock b/Cargo.lock
index ce43f78fa4f..3fbede968bc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -12964,6 +12964,9 @@ dependencies = [
  "cumulus-relay-chain-interface",
  "frame-benchmarking",
  "frame-benchmarking-cli",
+ "frame-support",
+ "frame-system-rpc-runtime-api",
+ "frame-try-runtime",
  "futures",
  "glutton-runtime",
  "glutton-westend-runtime",
@@ -12971,7 +12974,9 @@ dependencies = [
  "jsonrpsee",
  "log",
  "nix 0.26.2",
+ "pallet-transaction-payment",
  "pallet-transaction-payment-rpc",
+ "pallet-transaction-payment-rpc-runtime-api",
  "parachains-common",
  "parity-scale-codec",
  "penpal-runtime",
@@ -13003,14 +13008,18 @@ dependencies = [
  "sp-blockchain",
  "sp-consensus-aura",
  "sp-core",
+ "sp-genesis-builder",
+ "sp-inherents",
  "sp-io",
  "sp-keystore",
  "sp-offchain",
  "sp-runtime",
  "sp-session",
+ "sp-std 8.0.0",
  "sp-timestamp",
  "sp-tracing 10.0.0",
  "sp-transaction-pool",
+ "sp-version",
  "staging-xcm",
  "substrate-build-script-utils",
  "substrate-frame-rpc-system",
diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml
index d5deda9e7bf..e23a7aeb22b 100644
--- a/cumulus/polkadot-parachain/Cargo.toml
+++ b/cumulus/polkadot-parachain/Cargo.toml
@@ -49,8 +49,10 @@ sp-runtime = { path = "../../substrate/primitives/runtime", default-features = f
 sp-io = { path = "../../substrate/primitives/io" }
 sp-core = { path = "../../substrate/primitives/core" }
 sp-session = { path = "../../substrate/primitives/session" }
+frame-try-runtime = { path = "../../substrate/frame/try-runtime", optional = true }
 sc-consensus = { path = "../../substrate/client/consensus/common" }
 sp-tracing = { path = "../../substrate/primitives/tracing" }
+frame-support = { path = "../../substrate/frame/support" }
 sc-cli = { path = "../../substrate/client/cli" }
 sc-client-api = { path = "../../substrate/client/api" }
 sc-executor = { path = "../../substrate/client/executor" }
@@ -63,12 +65,19 @@ sc-network-sync = { path = "../../substrate/client/network/sync" }
 sc-basic-authorship = { path = "../../substrate/client/basic-authorship" }
 sp-timestamp = { path = "../../substrate/primitives/timestamp" }
 sp-blockchain = { path = "../../substrate/primitives/blockchain" }
+sp-genesis-builder = { path = "../../substrate/primitives/genesis-builder", default-features = false }
 sp-block-builder = { path = "../../substrate/primitives/block-builder" }
 sp-keystore = { path = "../../substrate/primitives/keystore" }
 sc-chain-spec = { path = "../../substrate/client/chain-spec" }
 sc-rpc = { path = "../../substrate/client/rpc" }
+sp-version = { path = "../../substrate/primitives/version" }
 sc-tracing = { path = "../../substrate/client/tracing" }
 sp-offchain = { path = "../../substrate/primitives/offchain" }
+frame-system-rpc-runtime-api = { path = "../../substrate/frame/system/rpc/runtime-api" }
+pallet-transaction-payment = { path = "../../substrate/frame/transaction-payment" }
+pallet-transaction-payment-rpc-runtime-api = { path = "../../substrate/frame/transaction-payment/rpc/runtime-api" }
+sp-std = { path = "../../substrate/primitives/std" }
+sp-inherents = { path = "../../substrate/primitives/inherents" }
 sp-api = { path = "../../substrate/primitives/api" }
 sp-consensus-aura = { path = "../../substrate/primitives/consensus/aura" }
 sc-sysinfo = { path = "../../substrate/client/sysinfo" }
@@ -126,6 +135,7 @@ runtime-benchmarks = [
 	"cumulus-primitives-core/runtime-benchmarks",
 	"frame-benchmarking-cli/runtime-benchmarks",
 	"frame-benchmarking/runtime-benchmarks",
+	"frame-support/runtime-benchmarks",
 	"glutton-runtime/runtime-benchmarks",
 	"glutton-westend-runtime/runtime-benchmarks",
 	"parachains-common/runtime-benchmarks",
@@ -149,8 +159,11 @@ try-runtime = [
 	"collectives-polkadot-runtime/try-runtime",
 	"collectives-westend-runtime/try-runtime",
 	"contracts-rococo-runtime/try-runtime",
+	"frame-support/try-runtime",
+	"frame-try-runtime/try-runtime",
 	"glutton-runtime/try-runtime",
 	"glutton-westend-runtime/try-runtime",
+	"pallet-transaction-payment/try-runtime",
 	"penpal-runtime/try-runtime",
 	"polkadot-cli/try-runtime",
 	"polkadot-service/try-runtime",
diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs
index 94cef106001..eb253908f5f 100644
--- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs
+++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs
@@ -199,8 +199,6 @@ pub mod rococo {
 	/// Specialized `ChainSpec` for the normal parachain runtime.
 	pub type BridgeHubChainSpec = sc_service::GenericChainSpec<(), Extensions>;
 
-	pub type RuntimeApi = bridge_hub_rococo_runtime::RuntimeApi;
-
 	pub fn local_config<ModifyProperties: Fn(&mut sc_chain_spec::Properties)>(
 		id: &str,
 		chain_name: &str,
@@ -319,7 +317,6 @@ pub mod kusama {
 
 	/// Specialized `ChainSpec` for the normal parachain runtime.
 	pub type BridgeHubChainSpec = sc_service::GenericChainSpec<(), Extensions>;
-	pub type RuntimeApi = bridge_hub_kusama_runtime::RuntimeApi;
 
 	pub fn local_config(
 		id: &str,
@@ -429,7 +426,6 @@ pub mod westend {
 	/// Specialized `ChainSpec` for the normal parachain runtime.
 	pub type BridgeHubChainSpec =
 		sc_service::GenericChainSpec<bridge_hub_westend_runtime::RuntimeGenesisConfig, Extensions>;
-	pub type RuntimeApi = bridge_hub_westend_runtime::RuntimeApi;
 
 	pub fn local_config(
 		id: &str,
@@ -545,7 +541,6 @@ pub mod polkadot {
 
 	/// Specialized `ChainSpec` for the normal parachain runtime.
 	pub type BridgeHubChainSpec = sc_service::GenericChainSpec<(), Extensions>;
-	pub type RuntimeApi = bridge_hub_polkadot_runtime::RuntimeApi;
 
 	pub fn local_config(
 		id: &str,
diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs
index 7bede22fea7..ea19ad12ba0 100644
--- a/cumulus/polkadot-parachain/src/command.rs
+++ b/cumulus/polkadot-parachain/src/command.rs
@@ -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 => {
-				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, _>(
-						&$config,
-						crate::service::shell_build_import_queue,
-					)?;
-					let task_manager = $components.task_manager;
-					{ $( $code )* }.map(|v| (v, task_manager))
-				})
-			},
-			Runtime::Seedling => {
+			Runtime::Shell |
+			Runtime::Seedling |
+			Runtime::GluttonWestend |
+			Runtime::Glutton => {
 				runner.async_run(|$config| {
-					let $components = new_partial::<seedling_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::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
diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs
new file mode 100644
index 00000000000..76dd7347ccb
--- /dev/null
+++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs
@@ -0,0 +1,200 @@
+// Copyright (C) Parity Technologies (UK) Ltd.
+// This file is part of Cumulus.
+
+// Cumulus is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Cumulus is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Cumulus.  If not, see <http://www.gnu.org/licenses/>.
+
+//! These are used to provide a type that implements these runtime APIs without requiring to import
+//! the native runtimes.
+
+use frame_support::weights::Weight;
+use parachains_common::{AccountId, AssetHubPolkadotAuraId, Balance, Nonce};
+use polkadot_primitives::Block;
+use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
+use sp_runtime::{
+	traits::Block as BlockT,
+	transaction_validity::{TransactionSource, TransactionValidity},
+	ApplyExtrinsicResult,
+};
+
+pub struct Runtime;
+
+sp_api::impl_runtime_apis! {
+	impl sp_api::Core<Block> for Runtime {
+		fn version() -> sp_version::RuntimeVersion {
+			unimplemented!()
+		}
+
+		fn execute_block(_: Block) {
+			unimplemented!()
+		}
+
+		fn initialize_block(_: &<Block as BlockT>::Header) {
+			unimplemented!()
+		}
+	}
+
+	impl sp_api::Metadata<Block> for Runtime {
+		fn metadata() -> OpaqueMetadata {
+			unimplemented!()
+		}
+
+		fn metadata_at_version(_: u32) -> Option<OpaqueMetadata> {
+			unimplemented!()
+		}
+
+		fn metadata_versions() -> sp_std::vec::Vec<u32> {
+			unimplemented!()
+		}
+	}
+
+	impl sp_consensus_aura::AuraApi<Block, AssetHubPolkadotAuraId> for Runtime {
+		fn slot_duration() -> sp_consensus_aura::SlotDuration {
+			unimplemented!()
+		}
+
+		fn authorities() -> Vec<AssetHubPolkadotAuraId> {
+			unimplemented!()
+		}
+	}
+
+	impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
+		fn can_build_upon(
+			_: <Block as BlockT>::Hash,
+			_: cumulus_primitives_aura::Slot,
+		) -> bool {
+			unimplemented!()
+		}
+	}
+
+	impl sp_block_builder::BlockBuilder<Block> for Runtime {
+		fn apply_extrinsic(_: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
+			unimplemented!()
+		}
+
+		fn finalize_block() -> <Block as BlockT>::Header {
+			unimplemented!()
+		}
+
+		fn inherent_extrinsics(_: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
+			unimplemented!()
+		}
+
+		fn check_inherents(_: Block, _: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
+			unimplemented!()
+		}
+	}
+
+	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
+		fn validate_transaction(
+			_: TransactionSource,
+			_: <Block as BlockT>::Extrinsic,
+			_: <Block as BlockT>::Hash,
+		) -> TransactionValidity {
+			unimplemented!()
+		}
+	}
+
+	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
+		fn offchain_worker(_: &<Block as BlockT>::Header) {
+			unimplemented!()
+		}
+	}
+
+	impl sp_session::SessionKeys<Block> for Runtime {
+		fn generate_session_keys(_: Option<Vec<u8>>) -> Vec<u8> {
+			unimplemented!()
+		}
+
+		fn decode_session_keys(
+			_: Vec<u8>,
+		) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
+			unimplemented!()
+		}
+	}
+
+	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
+		fn query_info(
+			_: <Block as BlockT>::Extrinsic,
+			_: u32,
+		) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
+			unimplemented!()
+		}
+		fn query_fee_details(
+			_: <Block as BlockT>::Extrinsic,
+			_: u32,
+		) -> pallet_transaction_payment::FeeDetails<Balance> {
+			unimplemented!()
+		}
+		fn query_weight_to_fee(_: Weight) -> Balance {
+			unimplemented!()
+		}
+		fn query_length_to_fee(_: u32) -> Balance {
+			unimplemented!()
+		}
+	}
+
+	impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
+		fn collect_collation_info(_: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
+			unimplemented!()
+		}
+	}
+
+	#[cfg(feature = "try-runtime")]
+	impl frame_try_runtime::TryRuntime<Block> for Runtime {
+		fn on_runtime_upgrade(_: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
+			unimplemented!()
+		}
+
+		fn execute_block(
+			_: Block,
+			_: bool,
+			_: bool,
+			_: frame_try_runtime::TryStateSelect,
+		) -> Weight {
+			unimplemented!()
+		}
+	}
+
+	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
+		fn account_nonce(_: AccountId) -> Nonce {
+			unimplemented!()
+		}
+	}
+
+	#[cfg(feature = "runtime-benchmarks")]
+	impl frame_benchmarking::Benchmark<Block> for Runtime {
+		fn benchmark_metadata(_: bool) -> (
+			Vec<frame_benchmarking::BenchmarkList>,
+			Vec<frame_support::traits::StorageInfo>,
+		) {
+			unimplemented!()
+		}
+
+		fn dispatch_benchmark(
+			_: frame_benchmarking::BenchmarkConfig
+		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
+			unimplemented!()
+		}
+	}
+
+	impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
+		fn create_default_config() -> Vec<u8> {
+			unimplemented!()
+		}
+
+		fn build_config(_: Vec<u8>) -> sp_genesis_builder::Result {
+			unimplemented!()
+		}
+	}
+}
diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs
new file mode 100644
index 00000000000..0f01b85ebcf
--- /dev/null
+++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs
@@ -0,0 +1,200 @@
+// Copyright (C) Parity Technologies (UK) Ltd.
+// This file is part of Cumulus.
+
+// Cumulus is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Cumulus is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Cumulus.  If not, see <http://www.gnu.org/licenses/>.
+
+//! These are used to provide a type that implements these runtime APIs without requiring to import
+//! the native runtimes.
+
+use frame_support::weights::Weight;
+use parachains_common::{AccountId, AuraId, Balance, Nonce};
+use polkadot_primitives::Block;
+use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
+use sp_runtime::{
+	traits::Block as BlockT,
+	transaction_validity::{TransactionSource, TransactionValidity},
+	ApplyExtrinsicResult,
+};
+
+pub struct Runtime;
+
+sp_api::impl_runtime_apis! {
+	impl sp_api::Core<Block> for Runtime {
+		fn version() -> sp_version::RuntimeVersion {
+			unimplemented!()
+		}
+
+		fn execute_block(_: Block) {
+			unimplemented!()
+		}
+
+		fn initialize_block(_: &<Block as BlockT>::Header) {
+			unimplemented!()
+		}
+	}
+
+	impl sp_api::Metadata<Block> for Runtime {
+		fn metadata() -> OpaqueMetadata {
+			unimplemented!()
+		}
+
+		fn metadata_at_version(_: u32) -> Option<OpaqueMetadata> {
+			unimplemented!()
+		}
+
+		fn metadata_versions() -> sp_std::vec::Vec<u32> {
+			unimplemented!()
+		}
+	}
+
+	impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
+		fn slot_duration() -> sp_consensus_aura::SlotDuration {
+			unimplemented!()
+		}
+
+		fn authorities() -> Vec<AuraId> {
+			unimplemented!()
+		}
+	}
+
+	impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
+		fn can_build_upon(
+			_: <Block as BlockT>::Hash,
+			_: cumulus_primitives_aura::Slot,
+		) -> bool {
+			unimplemented!()
+		}
+	}
+
+	impl sp_block_builder::BlockBuilder<Block> for Runtime {
+		fn apply_extrinsic(_: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
+			unimplemented!()
+		}
+
+		fn finalize_block() -> <Block as BlockT>::Header {
+			unimplemented!()
+		}
+
+		fn inherent_extrinsics(_: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
+			unimplemented!()
+		}
+
+		fn check_inherents(_: Block, _: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
+			unimplemented!()
+		}
+	}
+
+	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
+		fn validate_transaction(
+			_: TransactionSource,
+			_: <Block as BlockT>::Extrinsic,
+			_: <Block as BlockT>::Hash,
+		) -> TransactionValidity {
+			unimplemented!()
+		}
+	}
+
+	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
+		fn offchain_worker(_: &<Block as BlockT>::Header) {
+			unimplemented!()
+		}
+	}
+
+	impl sp_session::SessionKeys<Block> for Runtime {
+		fn generate_session_keys(_: Option<Vec<u8>>) -> Vec<u8> {
+			unimplemented!()
+		}
+
+		fn decode_session_keys(
+			_: Vec<u8>,
+		) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
+			unimplemented!()
+		}
+	}
+
+	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
+		fn query_info(
+			_: <Block as BlockT>::Extrinsic,
+			_: u32,
+		) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
+			unimplemented!()
+		}
+		fn query_fee_details(
+			_: <Block as BlockT>::Extrinsic,
+			_: u32,
+		) -> pallet_transaction_payment::FeeDetails<Balance> {
+			unimplemented!()
+		}
+		fn query_weight_to_fee(_: Weight) -> Balance {
+			unimplemented!()
+		}
+		fn query_length_to_fee(_: u32) -> Balance {
+			unimplemented!()
+		}
+	}
+
+	impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
+		fn collect_collation_info(_: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
+			unimplemented!()
+		}
+	}
+
+	#[cfg(feature = "try-runtime")]
+	impl frame_try_runtime::TryRuntime<Block> for Runtime {
+		fn on_runtime_upgrade(_: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
+			unimplemented!()
+		}
+
+		fn execute_block(
+			_: Block,
+			_: bool,
+			_: bool,
+			_: frame_try_runtime::TryStateSelect,
+		) -> Weight {
+			unimplemented!()
+		}
+	}
+
+	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
+		fn account_nonce(_: AccountId) -> Nonce {
+			unimplemented!()
+		}
+	}
+
+	#[cfg(feature = "runtime-benchmarks")]
+	impl frame_benchmarking::Benchmark<Block> for Runtime {
+		fn benchmark_metadata(_: bool) -> (
+			Vec<frame_benchmarking::BenchmarkList>,
+			Vec<frame_support::traits::StorageInfo>,
+		) {
+			unimplemented!()
+		}
+
+		fn dispatch_benchmark(
+			_: frame_benchmarking::BenchmarkConfig
+		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
+			unimplemented!()
+		}
+	}
+
+	impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
+		fn create_default_config() -> Vec<u8> {
+			unimplemented!()
+		}
+
+		fn build_config(_: Vec<u8>) -> sp_genesis_builder::Result {
+			unimplemented!()
+		}
+	}
+}
diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/mod.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/mod.rs
new file mode 100644
index 00000000000..29e2736b06f
--- /dev/null
+++ b/cumulus/polkadot-parachain/src/fake_runtime_api/mod.rs
@@ -0,0 +1,21 @@
+// Copyright (C) Parity Technologies (UK) Ltd.
+// This file is part of Cumulus.
+
+// Cumulus is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Cumulus is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Cumulus.  If not, see <http://www.gnu.org/licenses/>.
+
+//! In an ideal world this would be one runtime which would simplify the code massively.
+//! This is not an ideal world - Polkadot Asset Hub has a different key type.
+
+pub mod asset_hub_polkadot_aura;
+pub mod aura;
diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs
index 26d7dae4b8a..0757bea84aa 100644
--- a/cumulus/polkadot-parachain/src/main.rs
+++ b/cumulus/polkadot-parachain/src/main.rs
@@ -22,6 +22,7 @@
 mod chain_spec;
 mod cli;
 mod command;
+mod fake_runtime_api;
 mod rpc;
 mod service;
 
diff --git a/cumulus/polkadot-parachain/src/service.rs b/cumulus/polkadot-parachain/src/service.rs
index f580835db55..b0fca518201 100644
--- a/cumulus/polkadot-parachain/src/service.rs
+++ b/cumulus/polkadot-parachain/src/service.rs
@@ -40,7 +40,7 @@ use sp_core::Pair;
 
 use jsonrpsee::RpcModule;
 
-use crate::rpc;
+use crate::{fake_runtime_api::aura::RuntimeApi, rpc};
 pub use parachains_common::{AccountId, Balance, Block, BlockNumber, Hash, Header, Nonce};
 
 use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier;
@@ -917,8 +917,8 @@ where
 
 /// Build the import queue for the rococo parachain runtime.
 pub fn rococo_parachain_build_import_queue(
-	client: Arc<ParachainClient<rococo_parachain_runtime::RuntimeApi>>,
-	block_import: ParachainBlockImport<rococo_parachain_runtime::RuntimeApi>,
+	client: Arc<ParachainClient<RuntimeApi>>,
+	block_import: ParachainBlockImport<RuntimeApi>,
 	config: &Configuration,
 	telemetry: Option<TelemetryHandle>,
 	task_manager: &TaskManager,
@@ -960,11 +960,8 @@ pub async fn start_rococo_parachain_node(
 	collator_options: CollatorOptions,
 	para_id: ParaId,
 	hwbench: Option<sc_sysinfo::HwBench>,
-) -> sc_service::error::Result<(
-	TaskManager,
-	Arc<ParachainClient<rococo_parachain_runtime::RuntimeApi>>,
-)> {
-	start_node_impl::<rococo_parachain_runtime::RuntimeApi, _, _, _>(
+) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient<RuntimeApi>>)> {
+	start_node_impl::<RuntimeApi, _, _, _>(
 		parachain_config,
 		polkadot_config,
 		collator_options,
@@ -1866,8 +1863,8 @@ where
 
 #[allow(clippy::type_complexity)]
 pub fn contracts_rococo_build_import_queue(
-	client: Arc<ParachainClient<contracts_rococo_runtime::RuntimeApi>>,
-	block_import: ParachainBlockImport<contracts_rococo_runtime::RuntimeApi>,
+	client: Arc<ParachainClient<RuntimeApi>>,
+	block_import: ParachainBlockImport<RuntimeApi>,
 	config: &Configuration,
 	telemetry: Option<TelemetryHandle>,
 	task_manager: &TaskManager,
@@ -1909,11 +1906,8 @@ pub async fn start_contracts_rococo_node(
 	collator_options: CollatorOptions,
 	para_id: ParaId,
 	hwbench: Option<sc_sysinfo::HwBench>,
-) -> sc_service::error::Result<(
-	TaskManager,
-	Arc<ParachainClient<contracts_rococo_runtime::RuntimeApi>>,
-)> {
-	start_contracts_rococo_node_impl::<contracts_rococo_runtime::RuntimeApi, _, _, _>(
+) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient<RuntimeApi>>)> {
+	start_contracts_rococo_node_impl::<RuntimeApi, _, _, _>(
 		parachain_config,
 		polkadot_config,
 		collator_options,
-- 
GitLab