Do not depend on native runtimes for RuntimeApi (#7451)

* Implement runtime apis for fake runtime

These runtime api implementations are only used to make the compiler
think that we have implemented all required runtime apis. They will not
be called as we switch the executor to `WasmExecutor`. In the near
future we will not require these fake implementations anymore after
Substrate has shifted away from this compile time requirement.

This brings us the advantage that the `polkadot-service` doesn't need to
depend on the runtimes for getting the `RuntimeApi` type.

It also removes around 1min of build time on my machine ;)

* Fix warning

* FMT

* ".git/.scripts/commands/fmt/fmt.sh"

* Use more descriptive id

* Fix warnings

* Adapt path

* Fix 🙈

---------

Co-authored-by: command-bot <>
This commit is contained in:
Bastian Köcher
2023-07-04 10:09:14 +02:00
committed by GitHub
parent 77ef85b04d
commit e53d15aa20
19 changed files with 1155 additions and 1507 deletions
@@ -17,7 +17,8 @@
use crate::{Client, FullBackend};
use parity_scale_codec::{Decode, Encode};
use polkadot_primitives::{Block, InherentData as ParachainsInherentData};
use polkadot_test_runtime::{GetLastTimestamp, UncheckedExtrinsic};
use polkadot_test_runtime::UncheckedExtrinsic;
use polkadot_test_service::GetLastTimestamp;
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
use sp_api::ProvideRuntimeApi;
use sp_consensus_babe::{
+17 -3
View File
@@ -22,12 +22,12 @@ mod block_builder;
use polkadot_primitives::Block;
use sp_runtime::BuildStorage;
use std::sync::Arc;
pub use block_builder::*;
pub use polkadot_test_runtime as runtime;
pub use polkadot_test_service::{
construct_extrinsic, construct_transfer_extrinsic, Client, FullBackend,
PolkadotTestExecutorDispatch,
};
pub use substrate_test_client::*;
@@ -35,7 +35,7 @@ pub use substrate_test_client::*;
pub type Executor = client::LocalCallExecutor<
Block,
FullBackend,
sc_executor::NativeElseWasmExecutor<PolkadotTestExecutorDispatch>,
WasmExecutor<(sp_io::SubstrateHostFunctions, frame_benchmarking::benchmarking::HostFunctions)>,
>;
/// Test client builder for Polkadot.
@@ -70,7 +70,21 @@ pub trait TestClientBuilderExt: Sized {
impl TestClientBuilderExt for TestClientBuilder {
fn build_with_longest_chain(self) -> (Client, LongestChain) {
self.build_with_native_executor(None)
let executor = WasmExecutor::builder().build();
let executor = client::LocalCallExecutor::new(
self.backend().clone(),
executor.clone(),
Default::default(),
ExecutionExtensions::new(
Default::default(),
None,
sc_offchain::OffchainDb::factory_from_backend(&*self.backend()),
Arc::new(executor),
),
)
.unwrap();
self.build_with_executor(executor)
}
}