mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 04:07:57 +00:00
Kill the light client, CHTs and change tries. (#10080)
* Remove light client, change tries and CHTs * Update tests * fmt * Restore changes_root * Fixed benches * Cargo fmt * fmt * fmt
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
use sc_client_api::backend;
|
||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||
use sp_core::ChangesTrieConfiguration;
|
||||
|
||||
use sc_block_builder::BlockBuilderApi;
|
||||
|
||||
@@ -36,11 +35,6 @@ pub trait BlockBuilderExt {
|
||||
key: Vec<u8>,
|
||||
value: Option<Vec<u8>>,
|
||||
) -> Result<(), sp_blockchain::Error>;
|
||||
/// Add changes trie configuration update extrinsic to the block.
|
||||
fn push_changes_trie_configuration_update(
|
||||
&mut self,
|
||||
new_config: Option<ChangesTrieConfiguration>,
|
||||
) -> Result<(), sp_blockchain::Error>;
|
||||
}
|
||||
|
||||
impl<'a, A, B> BlockBuilderExt
|
||||
@@ -68,11 +62,4 @@ where
|
||||
) -> Result<(), sp_blockchain::Error> {
|
||||
self.push(substrate_test_runtime::Extrinsic::StorageChange(key, value))
|
||||
}
|
||||
|
||||
fn push_changes_trie_configuration_update(
|
||||
&mut self,
|
||||
new_config: Option<ChangesTrieConfiguration>,
|
||||
) -> Result<(), sp_blockchain::Error> {
|
||||
self.push(substrate_test_runtime::Extrinsic::ChangesTrieConfigUpdate(new_config))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,22 +24,18 @@ pub mod trait_tests;
|
||||
mod block_builder_ext;
|
||||
|
||||
pub use sc_consensus::LongestChain;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
pub use substrate_test_client::*;
|
||||
pub use substrate_test_runtime as runtime;
|
||||
|
||||
pub use self::block_builder_ext::BlockBuilderExt;
|
||||
|
||||
use sc_client_api::light::{
|
||||
Fetcher, RemoteBodyRequest, RemoteCallRequest, RemoteChangesRequest, RemoteHeaderRequest,
|
||||
RemoteReadChildRequest, RemoteReadRequest,
|
||||
};
|
||||
use sp_core::{
|
||||
sr25519,
|
||||
storage::{ChildInfo, Storage, StorageChild},
|
||||
ChangesTrieConfiguration, Pair,
|
||||
Pair,
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, HashFor, Header as HeaderT, NumberFor};
|
||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
|
||||
use substrate_test_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
|
||||
|
||||
/// A prelude to import in tests.
|
||||
@@ -51,8 +47,8 @@ pub mod prelude {
|
||||
};
|
||||
// Client structs
|
||||
pub use super::{
|
||||
Backend, ExecutorDispatch, LightBackend, LightExecutor, LocalExecutorDispatch,
|
||||
NativeElseWasmExecutor, TestClient, TestClientBuilder, WasmExecutionMethod,
|
||||
Backend, ExecutorDispatch, LocalExecutorDispatch, NativeElseWasmExecutor, TestClient,
|
||||
TestClientBuilder, WasmExecutionMethod,
|
||||
};
|
||||
// Keyring
|
||||
pub use super::{AccountKeyring, Sr25519Keyring};
|
||||
@@ -84,26 +80,9 @@ pub type ExecutorDispatch = client::LocalCallExecutor<
|
||||
NativeElseWasmExecutor<LocalExecutorDispatch>,
|
||||
>;
|
||||
|
||||
/// Test client light database backend.
|
||||
pub type LightBackend = substrate_test_client::LightBackend<substrate_test_runtime::Block>;
|
||||
|
||||
/// Test client light executor.
|
||||
pub type LightExecutor = sc_light::GenesisCallExecutor<
|
||||
LightBackend,
|
||||
client::LocalCallExecutor<
|
||||
substrate_test_runtime::Block,
|
||||
sc_light::Backend<
|
||||
sc_client_db::light::LightStorage<substrate_test_runtime::Block>,
|
||||
HashFor<substrate_test_runtime::Block>,
|
||||
>,
|
||||
NativeElseWasmExecutor<LocalExecutorDispatch>,
|
||||
>,
|
||||
>;
|
||||
|
||||
/// Parameters of test-client builder with test-runtime.
|
||||
#[derive(Default)]
|
||||
pub struct GenesisParameters {
|
||||
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||
heap_pages_override: Option<u64>,
|
||||
extra_storage: Storage,
|
||||
wasm_code: Option<Vec<u8>>,
|
||||
@@ -112,7 +91,6 @@ pub struct GenesisParameters {
|
||||
impl GenesisParameters {
|
||||
fn genesis_config(&self) -> GenesisConfig {
|
||||
GenesisConfig::new(
|
||||
self.changes_trie_config.clone(),
|
||||
vec![
|
||||
sr25519::Public::from(Sr25519Keyring::Alice).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
||||
@@ -215,12 +193,6 @@ pub trait TestClientBuilderExt<B>: Sized {
|
||||
/// Returns a mutable reference to the genesis parameters.
|
||||
fn genesis_init_mut(&mut self) -> &mut GenesisParameters;
|
||||
|
||||
/// Set changes trie configuration for genesis.
|
||||
fn changes_trie_config(mut self, config: Option<ChangesTrieConfiguration>) -> Self {
|
||||
self.genesis_init_mut().changes_trie_config = config;
|
||||
self
|
||||
}
|
||||
|
||||
/// Override the default value for Wasm heap pages.
|
||||
fn set_heap_pages(mut self, heap_pages: u64) -> Self {
|
||||
self.genesis_init_mut().heap_pages_override = Some(heap_pages);
|
||||
@@ -308,142 +280,11 @@ impl<B> TestClientBuilderExt<B>
|
||||
}
|
||||
}
|
||||
|
||||
/// Type of optional fetch callback.
|
||||
type MaybeFetcherCallback<Req, Resp> =
|
||||
Option<Box<dyn Fn(Req) -> Result<Resp, sp_blockchain::Error> + Send + Sync>>;
|
||||
|
||||
/// Type of fetcher future result.
|
||||
type FetcherFutureResult<Resp> = futures::future::Ready<Result<Resp, sp_blockchain::Error>>;
|
||||
|
||||
/// Implementation of light client fetcher used in tests.
|
||||
#[derive(Default)]
|
||||
pub struct LightFetcher {
|
||||
call: MaybeFetcherCallback<RemoteCallRequest<substrate_test_runtime::Header>, Vec<u8>>,
|
||||
body: MaybeFetcherCallback<
|
||||
RemoteBodyRequest<substrate_test_runtime::Header>,
|
||||
Vec<substrate_test_runtime::Extrinsic>,
|
||||
>,
|
||||
}
|
||||
|
||||
impl LightFetcher {
|
||||
/// Sets remote call callback.
|
||||
pub fn with_remote_call(
|
||||
self,
|
||||
call: MaybeFetcherCallback<RemoteCallRequest<substrate_test_runtime::Header>, Vec<u8>>,
|
||||
) -> Self {
|
||||
LightFetcher { call, body: self.body }
|
||||
}
|
||||
|
||||
/// Sets remote body callback.
|
||||
pub fn with_remote_body(
|
||||
self,
|
||||
body: MaybeFetcherCallback<
|
||||
RemoteBodyRequest<substrate_test_runtime::Header>,
|
||||
Vec<substrate_test_runtime::Extrinsic>,
|
||||
>,
|
||||
) -> Self {
|
||||
LightFetcher { call: self.call, body }
|
||||
}
|
||||
}
|
||||
|
||||
impl Fetcher<substrate_test_runtime::Block> for LightFetcher {
|
||||
type RemoteHeaderResult = FetcherFutureResult<substrate_test_runtime::Header>;
|
||||
type RemoteReadResult = FetcherFutureResult<HashMap<Vec<u8>, Option<Vec<u8>>>>;
|
||||
type RemoteCallResult = FetcherFutureResult<Vec<u8>>;
|
||||
type RemoteChangesResult =
|
||||
FetcherFutureResult<Vec<(NumberFor<substrate_test_runtime::Block>, u32)>>;
|
||||
type RemoteBodyResult = FetcherFutureResult<Vec<substrate_test_runtime::Extrinsic>>;
|
||||
|
||||
fn remote_header(
|
||||
&self,
|
||||
_: RemoteHeaderRequest<substrate_test_runtime::Header>,
|
||||
) -> Self::RemoteHeaderResult {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn remote_read(
|
||||
&self,
|
||||
_: RemoteReadRequest<substrate_test_runtime::Header>,
|
||||
) -> Self::RemoteReadResult {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn remote_read_child(
|
||||
&self,
|
||||
_: RemoteReadChildRequest<substrate_test_runtime::Header>,
|
||||
) -> Self::RemoteReadResult {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn remote_call(
|
||||
&self,
|
||||
req: RemoteCallRequest<substrate_test_runtime::Header>,
|
||||
) -> Self::RemoteCallResult {
|
||||
match self.call {
|
||||
Some(ref call) => futures::future::ready(call(req)),
|
||||
None => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn remote_changes(
|
||||
&self,
|
||||
_: RemoteChangesRequest<substrate_test_runtime::Header>,
|
||||
) -> Self::RemoteChangesResult {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn remote_body(
|
||||
&self,
|
||||
req: RemoteBodyRequest<substrate_test_runtime::Header>,
|
||||
) -> Self::RemoteBodyResult {
|
||||
match self.body {
|
||||
Some(ref body) => futures::future::ready(body(req)),
|
||||
None => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates new client instance used for tests.
|
||||
pub fn new() -> Client<Backend> {
|
||||
TestClientBuilder::new().build()
|
||||
}
|
||||
|
||||
/// Creates new light client instance used for tests.
|
||||
pub fn new_light() -> (
|
||||
client::Client<
|
||||
LightBackend,
|
||||
LightExecutor,
|
||||
substrate_test_runtime::Block,
|
||||
substrate_test_runtime::RuntimeApi,
|
||||
>,
|
||||
Arc<LightBackend>,
|
||||
) {
|
||||
let storage = sc_client_db::light::LightStorage::new_test();
|
||||
let blockchain = Arc::new(sc_light::Blockchain::new(storage));
|
||||
let backend = Arc::new(LightBackend::new(blockchain));
|
||||
let executor = new_native_executor();
|
||||
let local_call_executor = client::LocalCallExecutor::new(
|
||||
backend.clone(),
|
||||
executor,
|
||||
Box::new(sp_core::testing::TaskExecutor::new()),
|
||||
Default::default(),
|
||||
)
|
||||
.expect("Creates LocalCallExecutor");
|
||||
let call_executor = LightExecutor::new(backend.clone(), local_call_executor);
|
||||
|
||||
(
|
||||
TestClientBuilder::with_backend(backend.clone())
|
||||
.build_with_executor(call_executor)
|
||||
.0,
|
||||
backend,
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates new light client fetcher used for tests.
|
||||
pub fn new_light_fetcher() -> LightFetcher {
|
||||
LightFetcher::default()
|
||||
}
|
||||
|
||||
/// Create a new native executor.
|
||||
pub fn new_native_executor() -> sc_executor::NativeElseWasmExecutor<LocalExecutorDispatch> {
|
||||
sc_executor::NativeElseWasmExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None, 8)
|
||||
|
||||
Reference in New Issue
Block a user