mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 06:08:00 +00:00
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:
@@ -18,6 +18,7 @@ substrate-test-client = { git = "https://github.com/paritytech/substrate", branc
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-offchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
@@ -27,6 +28,8 @@ sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "mast
|
||||
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
[dev-dependencies]
|
||||
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -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::{
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ sc-authority-discovery = { git = "https://github.com/paritytech/substrate", bran
|
||||
babe = { package = "sc-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
babe-primitives = { package = "sp-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
consensus_common = { package = "sp-consensus", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
grandpa = { package = "sc-consensus-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
grandpa_primitives = { package = "sp-consensus-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
@@ -43,7 +42,6 @@ sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "mas
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -28,9 +28,7 @@ use polkadot_overseer::Handle;
|
||||
use polkadot_primitives::{Balance, CollatorPair, HeadData, Id as ParaId, ValidationCode};
|
||||
use polkadot_runtime_common::BlockHashCount;
|
||||
use polkadot_runtime_parachains::paras::{ParaGenesisArgs, ParaKind};
|
||||
use polkadot_service::{
|
||||
ClientHandle, Error, ExecuteWithClient, FullClient, IsCollator, NewFull, PrometheusConfig,
|
||||
};
|
||||
use polkadot_service::{Error, FullClient, IsCollator, NewFull, PrometheusConfig};
|
||||
use polkadot_test_runtime::{
|
||||
ParasCall, ParasSudoWrapperCall, Runtime, SignedExtra, SignedPayload, SudoCall,
|
||||
UncheckedExtrinsic, VERSION,
|
||||
@@ -63,26 +61,11 @@ use std::{
|
||||
use substrate_test_client::{
|
||||
BlockchainEventsExt, RpcHandlersExt, RpcTransactionError, RpcTransactionOutput,
|
||||
};
|
||||
/// Declare an instance of the native executor named `PolkadotTestExecutorDispatch`. Include the wasm binary as the
|
||||
/// equivalent wasm code.
|
||||
pub struct PolkadotTestExecutorDispatch;
|
||||
|
||||
impl sc_executor::NativeExecutionDispatch for PolkadotTestExecutorDispatch {
|
||||
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
|
||||
|
||||
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
|
||||
polkadot_test_runtime::api::dispatch(method, data)
|
||||
}
|
||||
|
||||
fn native_version() -> sc_executor::NativeVersion {
|
||||
polkadot_test_runtime::native_version()
|
||||
}
|
||||
}
|
||||
|
||||
/// The client type being used by the test service.
|
||||
pub type Client = FullClient<polkadot_test_runtime::RuntimeApi, PolkadotTestExecutorDispatch>;
|
||||
pub type Client = FullClient;
|
||||
|
||||
pub use polkadot_service::FullBackend;
|
||||
pub use polkadot_service::{FullBackend, GetLastTimestamp};
|
||||
|
||||
/// Create a new full node.
|
||||
#[sc_tracing::logging::prefix_logs_with(config.network.node_name.as_str())]
|
||||
@@ -90,8 +73,8 @@ pub fn new_full(
|
||||
config: Configuration,
|
||||
is_collator: IsCollator,
|
||||
worker_program_path: Option<PathBuf>,
|
||||
) -> Result<NewFull<Arc<Client>>, Error> {
|
||||
polkadot_service::new_full::<polkadot_test_runtime::RuntimeApi, PolkadotTestExecutorDispatch, _>(
|
||||
) -> Result<NewFull, Error> {
|
||||
polkadot_service::new_full(
|
||||
config,
|
||||
is_collator,
|
||||
None,
|
||||
@@ -107,15 +90,6 @@ pub fn new_full(
|
||||
)
|
||||
}
|
||||
|
||||
/// A wrapper for the test client that implements `ClientHandle`.
|
||||
pub struct TestClient(pub Arc<Client>);
|
||||
|
||||
impl ClientHandle for TestClient {
|
||||
fn execute_with<T: ExecuteWithClient>(&self, t: T) -> T::Output {
|
||||
T::execute_with_client::<_, _, polkadot_service::FullBackend>(t, self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a prometheus config usable for testing.
|
||||
pub fn test_prometheus_config(port: u16) -> PrometheusConfig {
|
||||
PrometheusConfig::new_with_default_registry(
|
||||
|
||||
Reference in New Issue
Block a user