Name all the tasks! (#6726)

* Remove any implementation of `Spawn` or `Executor` from our task executors

* Fix compilation

* Rename `SpawnBlockingExecutor`

* Update primitives/core/src/traits.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Fix tests

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Bastian Köcher
2020-07-26 14:56:17 +02:00
committed by GitHub
parent 2ec131142b
commit 9310f15ac2
43 changed files with 280 additions and 280 deletions
+28
View File
@@ -1202,6 +1202,33 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "dyn-clonable"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e9232f0e607a262ceb9bd5141a3dfb3e4db6994b31989bbfd845878cba59fd4"
dependencies = [
"dyn-clonable-impl",
"dyn-clone",
]
[[package]]
name = "dyn-clonable-impl"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "558e40ea573c374cf53507fd240b7ee2f5477df7cfebdb97323ec61c719399c5"
dependencies = [
"proc-macro2",
"quote 1.0.6",
"syn 1.0.33",
]
[[package]]
name = "dyn-clone"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c53dc3a653e0f64081026e4bf048d48fec9fce90c66e8326ca7292df0ff2d82"
[[package]] [[package]]
name = "ed25519" name = "ed25519"
version = "1.0.1" version = "1.0.1"
@@ -7814,6 +7841,7 @@ dependencies = [
"byteorder", "byteorder",
"criterion 0.2.11", "criterion 0.2.11",
"derive_more", "derive_more",
"dyn-clonable",
"ed25519-dalek", "ed25519-dalek",
"futures 0.3.5", "futures 0.3.5",
"hash-db", "hash-db",
+1 -1
View File
@@ -71,7 +71,7 @@ impl core::Benchmark for PoolBenchmark {
std::thread::park_timeout(std::time::Duration::from_secs(3)); std::thread::park_timeout(std::time::Duration::from_secs(3));
} }
let executor = sp_core::testing::SpawnBlockingExecutor::new(); let executor = sp_core::testing::TaskExecutor::new();
let txpool = BasicPool::new_full( let txpool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(context.client.clone(), None)), Arc::new(FullChainApi::new(context.client.clone(), None)),
+8 -12
View File
@@ -50,7 +50,7 @@ use node_runtime::{
AccountId, AccountId,
Signature, Signature,
}; };
use sp_core::{ExecutionContext, blake2_256, traits::CloneableSpawn}; use sp_core::{ExecutionContext, blake2_256, traits::SpawnNamed, Pair, Public, sr25519, ed25519};
use sp_api::ProvideRuntimeApi; use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder; use sp_block_builder::BlockBuilder;
use sp_inherents::InherentData; use sp_inherents::InherentData;
@@ -58,9 +58,8 @@ use sc_client_api::{
ExecutionStrategy, BlockBackend, ExecutionStrategy, BlockBackend,
execution_extensions::{ExecutionExtensions, ExecutionStrategies}, execution_extensions::{ExecutionExtensions, ExecutionStrategies},
}; };
use sp_core::{Pair, Public, sr25519, ed25519};
use sc_block_builder::BlockBuilderProvider; use sc_block_builder::BlockBuilderProvider;
use futures::{executor, task}; use futures::executor;
/// Keyring full of accounts for benching. /// Keyring full of accounts for benching.
/// ///
@@ -145,7 +144,7 @@ impl BlockType {
pub fn to_content(self, size: Option<usize>) -> BlockContent { pub fn to_content(self, size: Option<usize>) -> BlockContent {
BlockContent { BlockContent {
block_type: self, block_type: self,
size: size, size,
} }
} }
} }
@@ -197,16 +196,13 @@ impl TaskExecutor {
} }
} }
impl task::Spawn for TaskExecutor { impl SpawnNamed for TaskExecutor {
fn spawn_obj(&self, future: task::FutureObj<'static, ()>) fn spawn(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
-> Result<(), task::SpawnError> { self.pool.spawn_ok(future);
self.pool.spawn_obj(future)
} }
}
impl CloneableSpawn for TaskExecutor { fn spawn_blocking(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
fn clone(&self) -> Box<dyn CloneableSpawn> { self.pool.spawn_ok(future);
Box::new(Clone::clone(self))
} }
} }
+1 -1
View File
@@ -37,7 +37,7 @@ pub use light::*;
pub use notifications::*; pub use notifications::*;
pub use proof_provider::*; pub use proof_provider::*;
pub use sp_state_machine::{StorageProof, ExecutionStrategy, CloneableSpawn}; pub use sp_state_machine::{StorageProof, ExecutionStrategy};
/// Usage Information Provider interface /// Usage Information Provider interface
/// ///
@@ -358,7 +358,7 @@ mod tests {
fn should_cease_building_block_when_deadline_is_reached() { fn should_cease_building_block_when_deadline_is_reached() {
// given // given
let client = Arc::new(substrate_test_runtime_client::new()); let client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let txpool = BasicPool::new_full( let txpool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
@@ -412,7 +412,7 @@ mod tests {
#[test] #[test]
fn should_not_panic_when_deadline_is_reached() { fn should_not_panic_when_deadline_is_reached() {
let client = Arc::new(substrate_test_runtime_client::new()); let client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let txpool = BasicPool::new_full( let txpool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
@@ -448,7 +448,7 @@ mod tests {
fn proposed_storage_changes_should_match_execute_block_storage_changes() { fn proposed_storage_changes_should_match_execute_block_storage_changes() {
let (client, backend) = TestClientBuilder::new().build_with_backend(); let (client, backend) = TestClientBuilder::new().build_with_backend();
let client = Arc::new(client); let client = Arc::new(client);
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let txpool = BasicPool::new_full( let txpool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
@@ -511,7 +511,7 @@ mod tests {
fn should_not_remove_invalid_transactions_when_skipping() { fn should_not_remove_invalid_transactions_when_skipping() {
// given // given
let mut client = Arc::new(substrate_test_runtime_client::new()); let mut client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let txpool = BasicPool::new_full( let txpool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
+1 -1
View File
@@ -31,7 +31,7 @@
//! # }; //! # };
//! # use sc_transaction_pool::{BasicPool, FullChainApi}; //! # use sc_transaction_pool::{BasicPool, FullChainApi};
//! # let client = Arc::new(substrate_test_runtime_client::new()); //! # let client = Arc::new(substrate_test_runtime_client::new());
//! # let spawner = sp_core::testing::SpawnBlockingExecutor::new(); //! # let spawner = sp_core::testing::TaskExecutor::new();
//! # let txpool = BasicPool::new_full( //! # let txpool = BasicPool::new_full(
//! # Default::default(), //! # Default::default(),
//! # Arc::new(FullChainApi::new(client.clone(), None)), //! # Arc::new(FullChainApi::new(client.clone(), None)),
@@ -220,7 +220,7 @@ mod tests {
let (client, select_chain) = builder.build_with_longest_chain(); let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client); let client = Arc::new(client);
let inherent_data_providers = InherentDataProviders::new(); let inherent_data_providers = InherentDataProviders::new();
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = Arc::new(BasicPool::with_revalidation_type( let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(), api(), None, RevalidationType::Full, spawner, Options::default(), api(), None, RevalidationType::Full, spawner,
)); ));
@@ -288,7 +288,7 @@ mod tests {
let (client, select_chain) = builder.build_with_longest_chain(); let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client); let client = Arc::new(client);
let inherent_data_providers = InherentDataProviders::new(); let inherent_data_providers = InherentDataProviders::new();
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = Arc::new(BasicPool::with_revalidation_type( let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(), api(), None, RevalidationType::Full, spawner, Options::default(), api(), None, RevalidationType::Full, spawner,
)); ));
@@ -360,7 +360,7 @@ mod tests {
let client = Arc::new(client); let client = Arc::new(client);
let inherent_data_providers = InherentDataProviders::new(); let inherent_data_providers = InherentDataProviders::new();
let pool_api = api(); let pool_api = api();
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = Arc::new(BasicPool::with_revalidation_type( let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(), pool_api.clone(), None, RevalidationType::Full, spawner, Options::default(), pool_api.clone(), None, RevalidationType::Full, spawner,
)); ));
+9 -6
View File
@@ -23,14 +23,17 @@ use std::{
}; };
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use sp_core::{convert_hash, NativeOrEncoded, traits::CodeExecutor, offchain::storage::OffchainOverlayedChanges}; use sp_core::{
convert_hash, NativeOrEncoded, traits::{CodeExecutor, SpawnNamed},
offchain::storage::OffchainOverlayedChanges,
};
use sp_runtime::{ use sp_runtime::{
generic::BlockId, traits::{One, Block as BlockT, Header as HeaderT, HashFor}, generic::BlockId, traits::{One, Block as BlockT, Header as HeaderT, HashFor},
}; };
use sp_externalities::Extensions; use sp_externalities::Extensions;
use sp_state_machine::{ use sp_state_machine::{
self, Backend as StateBackend, OverlayedChanges, ExecutionStrategy, create_proof_check_backend, self, Backend as StateBackend, OverlayedChanges, ExecutionStrategy, create_proof_check_backend,
execution_proof_check_on_trie_backend, ExecutionManager, StorageProof, CloneableSpawn, execution_proof_check_on_trie_backend, ExecutionManager, StorageProof,
}; };
use hash_db::Hasher; use hash_db::Hasher;
@@ -220,7 +223,7 @@ pub fn prove_execution<Block, S, E>(
/// Proof should include both environment preparation proof and method execution proof. /// Proof should include both environment preparation proof and method execution proof.
pub fn check_execution_proof<Header, E, H>( pub fn check_execution_proof<Header, E, H>(
executor: &E, executor: &E,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
request: &RemoteCallRequest<Header>, request: &RemoteCallRequest<Header>,
remote_proof: StorageProof, remote_proof: StorageProof,
) -> ClientResult<Vec<u8>> ) -> ClientResult<Vec<u8>>
@@ -251,7 +254,7 @@ pub fn check_execution_proof<Header, E, H>(
/// Proof should include both environment preparation proof and method execution proof. /// Proof should include both environment preparation proof and method execution proof.
pub fn check_execution_proof_with_make_header<Header, E, H, MakeNextHeader>( pub fn check_execution_proof_with_make_header<Header, E, H, MakeNextHeader>(
executor: &E, executor: &E,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
request: &RemoteCallRequest<Header>, request: &RemoteCallRequest<Header>,
remote_proof: StorageProof, remote_proof: StorageProof,
make_next_header: MakeNextHeader, make_next_header: MakeNextHeader,
@@ -275,7 +278,7 @@ pub fn check_execution_proof_with_make_header<Header, E, H, MakeNextHeader>(
let backend_runtime_code = sp_state_machine::backend::BackendRuntimeCode::new(&trie_backend); let backend_runtime_code = sp_state_machine::backend::BackendRuntimeCode::new(&trie_backend);
let runtime_code = backend_runtime_code.runtime_code()?; let runtime_code = backend_runtime_code.runtime_code()?;
execution_proof_check_on_trie_backend::<H, Header::Number, _>( execution_proof_check_on_trie_backend::<H, Header::Number, _, _>(
&trie_backend, &trie_backend,
&mut changes, &mut changes,
executor, executor,
@@ -286,7 +289,7 @@ pub fn check_execution_proof_with_make_header<Header, E, H, MakeNextHeader>(
)?; )?;
// execute method // execute method
execution_proof_check_on_trie_backend::<H, Header::Number, _>( execution_proof_check_on_trie_backend::<H, Header::Number, _, _>(
&trie_backend, &trie_backend,
&mut changes, &mut changes,
executor, executor,
+9 -7
View File
@@ -24,8 +24,7 @@ use std::marker::PhantomData;
use hash_db::{HashDB, Hasher, EMPTY_PREFIX}; use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use sp_core::{convert_hash, traits::CodeExecutor}; use sp_core::{convert_hash, traits::{CodeExecutor, SpawnNamed}, storage::{ChildInfo, ChildType}};
use sp_core::storage::{ChildInfo, ChildType};
use sp_runtime::traits::{ use sp_runtime::traits::{
Block as BlockT, Header as HeaderT, Hash, HashFor, NumberFor, Block as BlockT, Header as HeaderT, Hash, HashFor, NumberFor,
AtLeast32Bit, CheckedConversion, AtLeast32Bit, CheckedConversion,
@@ -33,7 +32,7 @@ use sp_runtime::traits::{
use sp_state_machine::{ use sp_state_machine::{
ChangesTrieRootsStorage, ChangesTrieAnchorBlockId, ChangesTrieConfigurationRange, ChangesTrieRootsStorage, ChangesTrieAnchorBlockId, ChangesTrieConfigurationRange,
InMemoryChangesTrieStorage, TrieBackend, read_proof_check, key_changes_proof_check_with_db, InMemoryChangesTrieStorage, TrieBackend, read_proof_check, key_changes_proof_check_with_db,
read_child_proof_check, CloneableSpawn, read_child_proof_check,
}; };
pub use sp_state_machine::StorageProof; pub use sp_state_machine::StorageProof;
use sp_blockchain::{Error as ClientError, Result as ClientResult}; use sp_blockchain::{Error as ClientError, Result as ClientResult};
@@ -46,20 +45,23 @@ pub use sc_client_api::{
}, },
cht, cht,
}; };
use crate::blockchain::Blockchain; use crate::{blockchain::Blockchain, call_executor::check_execution_proof};
use crate::call_executor::check_execution_proof;
/// Remote data checker. /// Remote data checker.
pub struct LightDataChecker<E, H, B: BlockT, S: BlockchainStorage<B>> { pub struct LightDataChecker<E, H, B: BlockT, S: BlockchainStorage<B>> {
blockchain: Arc<Blockchain<S>>, blockchain: Arc<Blockchain<S>>,
executor: E, executor: E,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
_hasher: PhantomData<(B, H)>, _hasher: PhantomData<(B, H)>,
} }
impl<E, H, B: BlockT, S: BlockchainStorage<B>> LightDataChecker<E, H, B, S> { impl<E, H, B: BlockT, S: BlockchainStorage<B>> LightDataChecker<E, H, B, S> {
/// Create new light data checker. /// Create new light data checker.
pub fn new(blockchain: Arc<Blockchain<S>>, executor: E, spawn_handle: Box<dyn CloneableSpawn>) -> Self { pub fn new(
blockchain: Arc<Blockchain<S>>,
executor: E,
spawn_handle: Box<dyn SpawnNamed>,
) -> Self {
Self { Self {
blockchain, executor, spawn_handle, _hasher: PhantomData blockchain, executor, spawn_handle, _hasher: PhantomData
} }
+2 -3
View File
@@ -19,9 +19,8 @@
//! Light client components. //! Light client components.
use sp_runtime::traits::{Block as BlockT, HashFor}; use sp_runtime::traits::{Block as BlockT, HashFor};
use sc_client_api::CloneableSpawn;
use std::sync::Arc; use std::sync::Arc;
use sp_core::traits::CodeExecutor; use sp_core::traits::{CodeExecutor, SpawnNamed};
pub mod backend; pub mod backend;
pub mod blockchain; pub mod blockchain;
@@ -34,7 +33,7 @@ pub use {backend::*, blockchain::*, call_executor::*, fetcher::*};
pub fn new_fetch_checker<E, B: BlockT, S: BlockchainStorage<B>>( pub fn new_fetch_checker<E, B: BlockT, S: BlockchainStorage<B>>(
blockchain: Arc<Blockchain<S>>, blockchain: Arc<Blockchain<S>>,
executor: E, executor: E,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
) -> LightDataChecker<E, HashFor<B>, B, S> ) -> LightDataChecker<E, HashFor<B>, B, S>
where where
E: CodeExecutor, E: CodeExecutor,
@@ -88,7 +88,7 @@ fn build_test_full_node(config: config::NetworkConfiguration)
Box::new(client.clone()), Box::new(client.clone()),
None, None,
None, None,
&sp_core::testing::SpawnBlockingExecutor::new(), &sp_core::testing::TaskExecutor::new(),
None, None,
)); ));
@@ -98,7 +98,7 @@ fn import_single_good_block_without_header_fails() {
#[test] #[test]
fn async_import_queue_drops() { fn async_import_queue_drops() {
let executor = sp_core::testing::SpawnBlockingExecutor::new(); let executor = sp_core::testing::TaskExecutor::new();
// Perform this test multiple times since it exhibits non-deterministic behavior. // Perform this test multiple times since it exhibits non-deterministic behavior.
for _ in 0..100 { for _ in 0..100 {
let verifier = PassThroughVerifier::new(true); let verifier = PassThroughVerifier::new(true);
+2 -2
View File
@@ -648,7 +648,7 @@ pub trait TestNetFactory: Sized {
Box::new(block_import.clone()), Box::new(block_import.clone()),
justification_import, justification_import,
finality_proof_import, finality_proof_import,
&sp_core::testing::SpawnBlockingExecutor::new(), &sp_core::testing::TaskExecutor::new(),
None, None,
)); ));
@@ -728,7 +728,7 @@ pub trait TestNetFactory: Sized {
Box::new(block_import.clone()), Box::new(block_import.clone()),
justification_import, justification_import,
finality_proof_import, finality_proof_import,
&sp_core::testing::SpawnBlockingExecutor::new(), &sp_core::testing::TaskExecutor::new(),
None, None,
)); ));
+1 -1
View File
@@ -334,7 +334,7 @@ mod tests {
// Compare. // Compare.
assert!(timestamp.unix_millis() > 0); assert!(timestamp.unix_millis() > 0);
assert_eq!(timestamp.unix_millis(), d); assert!(timestamp.unix_millis() >= d);
} }
#[test] #[test]
+1 -1
View File
@@ -247,7 +247,7 @@ mod tests {
let _ = env_logger::try_init(); let _ = env_logger::try_init();
let client = Arc::new(substrate_test_runtime_client::new()); let client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = TestPool(BasicPool::new_full( let pool = TestPool(BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
+1 -1
View File
@@ -61,7 +61,7 @@ impl Default for TestSetup {
let client_builder = substrate_test_runtime_client::TestClientBuilder::new(); let client_builder = substrate_test_runtime_client::TestClientBuilder::new();
let client = Arc::new(client_builder.set_keystore(keystore.clone()).build()); let client = Arc::new(client_builder.set_keystore(keystore.clone()).build());
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = BasicPool::new_full( let pool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
+26
View File
@@ -22,6 +22,11 @@
#![warn(missing_docs)] #![warn(missing_docs)]
use futures::{compat::Future01CompatExt, FutureExt};
use rpc::futures::future::{Executor, ExecuteError, Future};
use sp_core::traits::SpawnNamed;
use std::sync::Arc;
mod metadata; mod metadata;
pub use sc_rpc_api::DenyUnsafe; pub use sc_rpc_api::DenyUnsafe;
@@ -35,3 +40,24 @@ pub mod state;
pub mod system; pub mod system;
#[cfg(test)] #[cfg(test)]
mod testing; mod testing;
/// Task executor that is being used by RPC subscriptions.
#[derive(Clone)]
pub struct SubscriptionTaskExecutor(Arc<dyn SpawnNamed>);
impl SubscriptionTaskExecutor {
/// Create a new `Self` with the given spawner.
pub fn new(spawn: impl SpawnNamed + 'static) -> Self {
Self(Arc::new(spawn))
}
}
impl Executor<Box<dyn Future<Item = (), Error = ()> + Send>> for SubscriptionTaskExecutor {
fn execute(
&self,
future: Box<dyn Future<Item = (), Error = ()> + Send>,
) -> Result<(), ExecuteError<Box<dyn Future<Item = (), Error = ()> + Send>>> {
self.0.spawn("substrate_rpc_subscription", future.compat().map(drop).boxed());
Ok(())
}
}
+5 -5
View File
@@ -24,8 +24,7 @@ use crate::{
config::{Configuration, KeystoreConfig, PrometheusConfig, OffchainWorkerConfig}, config::{Configuration, KeystoreConfig, PrometheusConfig, OffchainWorkerConfig},
}; };
use sc_client_api::{ use sc_client_api::{
light::RemoteBlockchain, ForkBlocks, BadBlocks, CloneableSpawn, UsageProvider, light::RemoteBlockchain, ForkBlocks, BadBlocks, UsageProvider, ExecutorProvider,
ExecutorProvider,
}; };
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedSender, TracingUnboundedReceiver}; use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedSender, TracingUnboundedReceiver};
use sc_chain_spec::get_extension; use sc_chain_spec::get_extension;
@@ -55,7 +54,7 @@ use sc_telemetry::{telemetry, SUBSTRATE_INFO};
use sp_transaction_pool::MaintainedTransactionPool; use sp_transaction_pool::MaintainedTransactionPool;
use prometheus_endpoint::Registry; use prometheus_endpoint::Registry;
use sc_client_db::{Backend, DatabaseSettings}; use sc_client_db::{Backend, DatabaseSettings};
use sp_core::traits::CodeExecutor; use sp_core::traits::{CodeExecutor, SpawnNamed};
use sp_runtime::BuildStorage; use sp_runtime::BuildStorage;
use sc_client_api::{ use sc_client_api::{
BlockBackend, BlockchainEvents, BlockBackend, BlockchainEvents,
@@ -334,7 +333,7 @@ pub fn new_client<E, Block, RA>(
fork_blocks: ForkBlocks<Block>, fork_blocks: ForkBlocks<Block>,
bad_blocks: BadBlocks<Block>, bad_blocks: BadBlocks<Block>,
execution_extensions: ExecutionExtensions<Block>, execution_extensions: ExecutionExtensions<Block>,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
prometheus_registry: Option<Registry>, prometheus_registry: Option<Registry>,
config: ClientConfig, config: ClientConfig,
) -> Result<( ) -> Result<(
@@ -750,7 +749,8 @@ fn gen_handler<TBl, TBackend, TExPool, TRpc, TCl>(
chain_type: config.chain_spec.chain_type(), chain_type: config.chain_spec.chain_type(),
}; };
let subscriptions = SubscriptionManager::new(Arc::new(spawn_handle)); let task_executor = sc_rpc::SubscriptionTaskExecutor::new(spawn_handle);
let subscriptions = SubscriptionManager::new(Arc::new(task_executor));
let (chain, state, child_state) = if let (Some(remote_blockchain), Some(on_demand)) = let (chain, state, child_state) = if let (Some(remote_blockchain), Some(on_demand)) =
(remote_blockchain, on_demand) { (remote_blockchain, on_demand) {
@@ -27,9 +27,12 @@ use sp_state_machine::{
}; };
use sc_executor::{RuntimeVersion, RuntimeInfo, NativeVersion}; use sc_executor::{RuntimeVersion, RuntimeInfo, NativeVersion};
use sp_externalities::Extensions; use sp_externalities::Extensions;
use sp_core::{NativeOrEncoded, NeverNativeValue, traits::CodeExecutor, offchain::storage::OffchainOverlayedChanges}; use sp_core::{
NativeOrEncoded, NeverNativeValue, traits::{CodeExecutor, SpawnNamed},
offchain::storage::OffchainOverlayedChanges,
};
use sp_api::{ProofRecorder, InitializeBlock, StorageTransactionCache}; use sp_api::{ProofRecorder, InitializeBlock, StorageTransactionCache};
use sc_client_api::{backend, call_executor::CallExecutor, CloneableSpawn}; use sc_client_api::{backend, call_executor::CallExecutor};
use super::client::ClientConfig; use super::client::ClientConfig;
/// Call executor that executes methods locally, querying all required /// Call executor that executes methods locally, querying all required
@@ -37,7 +40,7 @@ use super::client::ClientConfig;
pub struct LocalCallExecutor<B, E> { pub struct LocalCallExecutor<B, E> {
backend: Arc<B>, backend: Arc<B>,
executor: E, executor: E,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
client_config: ClientConfig, client_config: ClientConfig,
} }
@@ -46,7 +49,7 @@ impl<B, E> LocalCallExecutor<B, E> {
pub fn new( pub fn new(
backend: Arc<B>, backend: Arc<B>,
executor: E, executor: E,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
client_config: ClientConfig, client_config: ClientConfig,
) -> Self { ) -> Self {
LocalCallExecutor { LocalCallExecutor {
@@ -242,7 +245,7 @@ where
method: &str, method: &str,
call_data: &[u8] call_data: &[u8]
) -> Result<(Vec<u8>, StorageProof), sp_blockchain::Error> { ) -> Result<(Vec<u8>, StorageProof), sp_blockchain::Error> {
sp_state_machine::prove_execution_on_trie_backend::<_, _, NumberFor<Block>, _>( sp_state_machine::prove_execution_on_trie_backend::<_, _, NumberFor<Block>, _, _>(
trie_state, trie_state,
overlay, overlay,
&self.executor, &self.executor,
@@ -92,8 +92,8 @@ use rand::Rng;
#[cfg(feature="test-helpers")] #[cfg(feature="test-helpers")]
use { use {
sp_core::traits::CodeExecutor, sp_core::traits::{CodeExecutor, SpawnNamed},
sc_client_api::{CloneableSpawn, in_mem}, sc_client_api::in_mem,
sc_executor::RuntimeInfo, sc_executor::RuntimeInfo,
super::call_executor::LocalCallExecutor, super::call_executor::LocalCallExecutor,
}; };
@@ -149,7 +149,7 @@ pub fn new_in_mem<E, Block, S, RA>(
genesis_storage: &S, genesis_storage: &S,
keystore: Option<sp_core::traits::BareCryptoStorePtr>, keystore: Option<sp_core::traits::BareCryptoStorePtr>,
prometheus_registry: Option<Registry>, prometheus_registry: Option<Registry>,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
config: ClientConfig, config: ClientConfig,
) -> sp_blockchain::Result<Client< ) -> sp_blockchain::Result<Client<
in_mem::Backend<Block>, in_mem::Backend<Block>,
@@ -189,7 +189,7 @@ pub fn new_with_backend<B, E, Block, S, RA>(
executor: E, executor: E,
build_genesis_storage: &S, build_genesis_storage: &S,
keystore: Option<sp_core::traits::BareCryptoStorePtr>, keystore: Option<sp_core::traits::BareCryptoStorePtr>,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
prometheus_registry: Option<Registry>, prometheus_registry: Option<Registry>,
config: ClientConfig, config: ClientConfig,
) -> sp_blockchain::Result<Client<B, LocalCallExecutor<B, E>, Block, RA>> ) -> sp_blockchain::Result<Client<B, LocalCallExecutor<B, E>, Block, RA>>
+4 -7
View File
@@ -21,17 +21,14 @@
use std::sync::Arc; use std::sync::Arc;
use sc_executor::RuntimeInfo; use sc_executor::RuntimeInfo;
use sp_core::traits::CodeExecutor; use sp_core::traits::{CodeExecutor, SpawnNamed};
use sp_runtime::BuildStorage; use sp_runtime::BuildStorage;
use sp_runtime::traits::{Block as BlockT, HashFor}; use sp_runtime::traits::{Block as BlockT, HashFor};
use sp_blockchain::Result as ClientResult; use sp_blockchain::Result as ClientResult;
use prometheus_endpoint::Registry; use prometheus_endpoint::Registry;
use super::call_executor::LocalCallExecutor; use super::{call_executor::LocalCallExecutor, client::{Client, ClientConfig}};
use super::client::{Client,ClientConfig}; use sc_client_api::light::Storage as BlockchainStorage;
use sc_client_api::{
light::Storage as BlockchainStorage, CloneableSpawn,
};
use sc_light::{Backend, GenesisCallExecutor}; use sc_light::{Backend, GenesisCallExecutor};
@@ -40,7 +37,7 @@ pub fn new_light<B, S, RA, E>(
backend: Arc<Backend<S, HashFor<B>>>, backend: Arc<Backend<S, HashFor<B>>>,
genesis_storage: &dyn BuildStorage, genesis_storage: &dyn BuildStorage,
code_executor: E, code_executor: E,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Box<dyn SpawnNamed>,
prometheus_registry: Option<Registry>, prometheus_registry: Option<Registry>,
) -> ClientResult< ) -> ClientResult<
Client< Client<
+1 -1
View File
@@ -556,7 +556,7 @@ mod tests {
// given // given
let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain(); let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain();
let client = Arc::new(client); let client = Arc::new(client);
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = BasicPool::new_full( let pool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
@@ -19,8 +19,6 @@ use log::{debug, error};
use futures::{ use futures::{
Future, FutureExt, StreamExt, Future, FutureExt, StreamExt,
future::{select, Either, BoxFuture}, future::{select, Either, BoxFuture},
compat::*,
task::{Spawn, FutureObj, SpawnError},
sink::SinkExt, sink::SinkExt,
}; };
use prometheus_endpoint::{ use prometheus_endpoint::{
@@ -28,7 +26,6 @@ use prometheus_endpoint::{
PrometheusError, PrometheusError,
CounterVec, HistogramOpts, HistogramVec, Opts, Registry, U64 CounterVec, HistogramOpts, HistogramVec, Opts, Registry, U64
}; };
use sc_client_api::CloneableSpawn;
use sp_utils::mpsc::{TracingUnboundedSender, TracingUnboundedReceiver, tracing_unbounded}; use sp_utils::mpsc::{TracingUnboundedSender, TracingUnboundedReceiver, tracing_unbounded};
use crate::{config::{TaskExecutor, TaskType, JoinFuture}, Error}; use crate::{config::{TaskExecutor, TaskType, JoinFuture}, Error};
@@ -132,14 +129,6 @@ impl SpawnTaskHandle {
} }
} }
impl Spawn for SpawnTaskHandle {
fn spawn_obj(&self, future: FutureObj<'static, ()>)
-> Result<(), SpawnError> {
self.spawn("unnamed", future);
Ok(())
}
}
impl sp_core::traits::SpawnNamed for SpawnTaskHandle { impl sp_core::traits::SpawnNamed for SpawnTaskHandle {
fn spawn_blocking(&self, name: &'static str, future: BoxFuture<'static, ()>) { fn spawn_blocking(&self, name: &'static str, future: BoxFuture<'static, ()>) {
self.spawn_blocking(name, future); self.spawn_blocking(name, future);
@@ -150,21 +139,6 @@ impl sp_core::traits::SpawnNamed for SpawnTaskHandle {
} }
} }
impl sc_client_api::CloneableSpawn for SpawnTaskHandle {
fn clone(&self) -> Box<dyn CloneableSpawn> {
Box::new(Clone::clone(self))
}
}
type Boxed01Future01 = Box<dyn futures01::Future<Item = (), Error = ()> + Send + 'static>;
impl futures01::future::Executor<Boxed01Future01> for SpawnTaskHandle {
fn execute(&self, future: Boxed01Future01) -> Result<(), futures01::future::ExecuteError<Boxed01Future01>>{
self.spawn("unnamed", future.compat().map(drop));
Ok(())
}
}
/// A wrapper over `SpawnTaskHandle` that will notify a receiver whenever any /// A wrapper over `SpawnTaskHandle` that will notify a receiver whenever any
/// task spawned through it fails. The service should be on the receiver side /// task spawned through it fails. The service should be on the receiver side
/// and will shut itself down whenever it receives any message, i.e. an /// and will shut itself down whenever it receives any message, i.e. an
@@ -37,9 +37,9 @@ use substrate_test_runtime_client::{
runtime::{Hash, Block, Header}, TestClient, ClientBlockImportExt, runtime::{Hash, Block, Header}, TestClient, ClientBlockImportExt,
}; };
use sp_api::{InitializeBlock, StorageTransactionCache, ProofRecorder, OffchainOverlayedChanges}; use sp_api::{InitializeBlock, StorageTransactionCache, ProofRecorder, OffchainOverlayedChanges};
use sp_consensus::{BlockOrigin}; use sp_consensus::BlockOrigin;
use sc_executor::{NativeExecutor, WasmExecutionMethod, RuntimeVersion, NativeVersion}; use sc_executor::{NativeExecutor, WasmExecutionMethod, RuntimeVersion, NativeVersion};
use sp_core::{H256, tasks::executor as tasks_executor, NativeOrEncoded}; use sp_core::{H256, NativeOrEncoded, testing::TaskExecutor};
use sc_client_api::{ use sc_client_api::{
blockchain::Info, backend::NewBlockState, Backend as ClientBackend, ProofProvider, blockchain::Info, backend::NewBlockState, Backend as ClientBackend, ProofProvider,
in_mem::{Backend as InMemBackend, Blockchain as InMemoryBlockchain}, in_mem::{Backend as InMemBackend, Blockchain as InMemoryBlockchain},
@@ -317,7 +317,7 @@ fn execution_proof_is_generated_and_checked() {
// check remote execution proof locally // check remote execution proof locally
let local_result = check_execution_proof::<_, _, BlakeTwo256>( let local_result = check_execution_proof::<_, _, BlakeTwo256>(
&local_executor(), &local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
&RemoteCallRequest { &RemoteCallRequest {
block: substrate_test_runtime_client::runtime::Hash::default(), block: substrate_test_runtime_client::runtime::Hash::default(),
header: remote_header, header: remote_header,
@@ -345,7 +345,7 @@ fn execution_proof_is_generated_and_checked() {
// check remote execution proof locally // check remote execution proof locally
let execution_result = check_execution_proof_with_make_header::<_, _, BlakeTwo256, _>( let execution_result = check_execution_proof_with_make_header::<_, _, BlakeTwo256, _>(
&local_executor(), &local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
&RemoteCallRequest { &RemoteCallRequest {
block: substrate_test_runtime_client::runtime::Hash::default(), block: substrate_test_runtime_client::runtime::Hash::default(),
header: remote_header, header: remote_header,
@@ -479,7 +479,7 @@ fn prepare_for_read_proof_check() -> (TestChecker, Header, StorageProof, u32) {
let local_checker = LightDataChecker::new( let local_checker = LightDataChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())), Arc::new(DummyBlockchain::new(DummyStorage::new())),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
(local_checker, remote_block_header, remote_read_proof, heap_pages) (local_checker, remote_block_header, remote_read_proof, heap_pages)
} }
@@ -527,7 +527,7 @@ fn prepare_for_read_child_proof_check() -> (TestChecker, Header, StorageProof, V
let local_checker = LightDataChecker::new( let local_checker = LightDataChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())), Arc::new(DummyBlockchain::new(DummyStorage::new())),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
(local_checker, remote_block_header, remote_read_proof, child_value) (local_checker, remote_block_header, remote_read_proof, child_value)
} }
@@ -558,7 +558,7 @@ fn prepare_for_header_proof_check(insert_cht: bool) -> (TestChecker, Hash, Heade
let local_checker = LightDataChecker::new( let local_checker = LightDataChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())), Arc::new(DummyBlockchain::new(DummyStorage::new())),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
(local_checker, local_cht_root, remote_block_header, remote_header_proof) (local_checker, local_cht_root, remote_block_header, remote_header_proof)
} }
@@ -642,7 +642,7 @@ fn changes_proof_is_generated_and_checked_when_headers_are_not_pruned() {
let local_checker = TestChecker::new( let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())), Arc::new(DummyBlockchain::new(DummyStorage::new())),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
let local_checker = &local_checker as &dyn FetchChecker<Block>; let local_checker = &local_checker as &dyn FetchChecker<Block>;
let max = remote_client.chain_info().best_number; let max = remote_client.chain_info().best_number;
@@ -717,7 +717,7 @@ fn changes_proof_is_generated_and_checked_when_headers_are_pruned() {
let local_checker = TestChecker::new( let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(local_storage)), Arc::new(DummyBlockchain::new(local_storage)),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
// check proof on local client // check proof on local client
@@ -752,7 +752,7 @@ fn check_changes_proof_fails_if_proof_is_wrong() {
let local_checker = TestChecker::new( let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())), Arc::new(DummyBlockchain::new(DummyStorage::new())),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
let local_checker = &local_checker as &dyn FetchChecker<Block>; let local_checker = &local_checker as &dyn FetchChecker<Block>;
let max = remote_client.chain_info().best_number; let max = remote_client.chain_info().best_number;
@@ -840,7 +840,7 @@ fn check_changes_tries_proof_fails_if_proof_is_wrong() {
let local_checker = TestChecker::new( let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())), Arc::new(DummyBlockchain::new(DummyStorage::new())),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
assert!(local_checker.check_changes_tries_proof(4, &remote_proof.roots, assert!(local_checker.check_changes_tries_proof(4, &remote_proof.roots,
remote_proof.roots_proof.clone()).is_err()); remote_proof.roots_proof.clone()).is_err());
@@ -851,7 +851,7 @@ fn check_changes_tries_proof_fails_if_proof_is_wrong() {
let local_checker = TestChecker::new( let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(local_storage)), Arc::new(DummyBlockchain::new(local_storage)),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
let result = local_checker.check_changes_tries_proof( let result = local_checker.check_changes_tries_proof(
4, &remote_proof.roots, StorageProof::empty() 4, &remote_proof.roots, StorageProof::empty()
@@ -869,7 +869,7 @@ fn check_body_proof_faulty() {
let local_checker = TestChecker::new( let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())), Arc::new(DummyBlockchain::new(DummyStorage::new())),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
let body_request = RemoteBodyRequest { let body_request = RemoteBodyRequest {
@@ -893,7 +893,7 @@ fn check_body_proof_of_same_data_should_succeed() {
let local_checker = TestChecker::new( let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())), Arc::new(DummyBlockchain::new(DummyStorage::new())),
local_executor(), local_executor(),
tasks_executor(), Box::new(TaskExecutor::new()),
); );
let body_request = RemoteBodyRequest { let body_request = RemoteBodyRequest {
@@ -40,8 +40,7 @@ use sp_runtime::traits::{
use substrate_test_runtime::TestAPI; use substrate_test_runtime::TestAPI;
use sp_state_machine::backend::Backend as _; use sp_state_machine::backend::Backend as _;
use sp_api::{ProvideRuntimeApi, OffchainOverlayedChanges}; use sp_api::{ProvideRuntimeApi, OffchainOverlayedChanges};
use sp_core::tasks::executor as tasks_executor; use sp_core::{H256, ChangesTrieConfiguration, blake2_256, testing::TaskExecutor};
use sp_core::{H256, ChangesTrieConfiguration, blake2_256};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::sync::Arc; use std::sync::Arc;
use sp_consensus::{ use sp_consensus::{
@@ -165,6 +164,7 @@ fn construct_block(
let mut offchain_overlay = OffchainOverlayedChanges::default(); let mut offchain_overlay = OffchainOverlayedChanges::default();
let backend_runtime_code = sp_state_machine::backend::BackendRuntimeCode::new(&backend); let backend_runtime_code = sp_state_machine::backend::BackendRuntimeCode::new(&backend);
let runtime_code = backend_runtime_code.runtime_code().expect("Code is part of the backend"); let runtime_code = backend_runtime_code.runtime_code().expect("Code is part of the backend");
let task_executor = Box::new(TaskExecutor::new());
StateMachine::new( StateMachine::new(
backend, backend,
@@ -176,7 +176,7 @@ fn construct_block(
&header.encode(), &header.encode(),
Default::default(), Default::default(),
&runtime_code, &runtime_code,
tasks_executor(), task_executor.clone() as Box<_>,
).execute( ).execute(
ExecutionStrategy::NativeElseWasm, ExecutionStrategy::NativeElseWasm,
).unwrap(); ).unwrap();
@@ -192,7 +192,7 @@ fn construct_block(
&tx.encode(), &tx.encode(),
Default::default(), Default::default(),
&runtime_code, &runtime_code,
tasks_executor(), task_executor.clone() as Box<_>,
).execute( ).execute(
ExecutionStrategy::NativeElseWasm, ExecutionStrategy::NativeElseWasm,
).unwrap(); ).unwrap();
@@ -208,7 +208,7 @@ fn construct_block(
&[], &[],
Default::default(), Default::default(),
&runtime_code, &runtime_code,
tasks_executor(), task_executor.clone() as Box<_>,
).execute( ).execute(
ExecutionStrategy::NativeElseWasm, ExecutionStrategy::NativeElseWasm,
).unwrap(); ).unwrap();
@@ -262,7 +262,7 @@ fn construct_genesis_should_work_with_native() {
&b1data, &b1data,
Default::default(), Default::default(),
&runtime_code, &runtime_code,
tasks_executor(), TaskExecutor::new(),
).execute( ).execute(
ExecutionStrategy::NativeElseWasm, ExecutionStrategy::NativeElseWasm,
).unwrap(); ).unwrap();
@@ -298,7 +298,7 @@ fn construct_genesis_should_work_with_wasm() {
&b1data, &b1data,
Default::default(), Default::default(),
&runtime_code, &runtime_code,
tasks_executor(), TaskExecutor::new(),
).execute( ).execute(
ExecutionStrategy::AlwaysWasm, ExecutionStrategy::AlwaysWasm,
).unwrap(); ).unwrap();
@@ -334,7 +334,7 @@ fn construct_genesis_with_bad_transaction_should_panic() {
&b1data, &b1data,
Default::default(), Default::default(),
&runtime_code, &runtime_code,
tasks_executor(), TaskExecutor::new(),
).execute( ).execute(
ExecutionStrategy::NativeElseWasm, ExecutionStrategy::NativeElseWasm,
); );
@@ -1743,7 +1743,7 @@ fn cleans_up_closed_notification_sinks_on_block_import() {
&substrate_test_runtime_client::GenesisParameters::default().genesis_storage(), &substrate_test_runtime_client::GenesisParameters::default().genesis_storage(),
None, None,
None, None,
sp_core::tasks::executor(), Box::new(TaskExecutor::new()),
Default::default(), Default::default(),
) )
.unwrap(); .unwrap();
@@ -197,11 +197,11 @@ fn record_proof_works() {
None, None,
8, 8,
); );
execution_proof_check_on_trie_backend::<_, u64, _>( execution_proof_check_on_trie_backend::<_, u64, _, _>(
&backend, &backend,
&mut overlay, &mut overlay,
&executor, &executor,
sp_core::tasks::executor(), sp_core::testing::TaskExecutor::new(),
"Core_execute_block", "Core_execute_block",
&block.encode(), &block.encode(),
&runtime_code, &runtime_code,
+2
View File
@@ -39,6 +39,7 @@ sp-externalities = { version = "0.8.0-rc5", optional = true, path = "../external
sp-storage = { version = "2.0.0-rc5", default-features = false, path = "../storage" } sp-storage = { version = "2.0.0-rc5", default-features = false, path = "../storage" }
parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] }
futures = { version = "0.3.1", optional = true } futures = { version = "0.3.1", optional = true }
dyn-clonable = { version = "0.9.0", optional = true }
# full crypto # full crypto
ed25519-dalek = { version = "1.0.0-pre.4", default-features = false, features = ["u64_backend", "alloc"], optional = true } ed25519-dalek = { version = "1.0.0-pre.4", default-features = false, features = ["u64_backend", "alloc"], optional = true }
@@ -111,6 +112,7 @@ std = [
"futures", "futures",
"futures/thread-pool", "futures/thread-pool",
"libsecp256k1/std", "libsecp256k1/std",
"dyn-clonable",
] ]
# This feature enables all crypto primitives for `no_std` builds like microcontrollers # This feature enables all crypto primitives for `no_std` builds like microcontrollers
-2
View File
@@ -72,8 +72,6 @@ mod changes_trie;
pub mod traits; pub mod traits;
pub mod testing; pub mod testing;
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub mod tasks;
#[cfg(feature = "std")]
pub mod vrf; pub mod vrf;
pub use self::hash::{H160, H256, H512, convert_hash}; pub use self::hash::{H160, H256, H512, convert_hash};
-57
View File
@@ -1,57 +0,0 @@
// This file is part of Substrate.
// Copyright (C) 2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Module for low-level asynchronous processing.
use crate::traits::CloneableSpawn;
use futures::{executor, task};
/// Simple task executor.
///
/// Uses single thread for scheduling tasks. Can be cloned and used in
/// runtime host (implements `CloneableSpawn`).
#[derive(Debug, Clone)]
pub struct Executor {
pool: executor::ThreadPool,
}
impl Executor {
fn new() -> Self {
Self {
pool: executor::ThreadPool::builder().pool_size(1).create()
.expect("Failed to create task executor")
}
}
}
impl task::Spawn for Executor {
fn spawn_obj(&self, future: task::FutureObj<'static, ()>)
-> Result<(), task::SpawnError> {
self.pool.spawn_obj(future)
}
}
impl CloneableSpawn for Executor {
fn clone(&self) -> Box<dyn CloneableSpawn> {
Box::new(Clone::clone(self))
}
}
/// Create tasks executor.
pub fn executor() -> Box<dyn CloneableSpawn> {
Box::new(Executor::new())
}
+4 -4
View File
@@ -359,16 +359,16 @@ macro_rules! wasm_export_functions {
}; };
} }
/// An executor that supports spawning blocking futures in tests. /// A task executor that can be used in tests.
/// ///
/// Internally this just wraps a `ThreadPool` with a pool size of `8`. This /// Internally this just wraps a `ThreadPool` with a pool size of `8`. This
/// should ensure that we have enough threads in tests for spawning blocking futures. /// should ensure that we have enough threads in tests for spawning blocking futures.
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[derive(Clone)] #[derive(Clone)]
pub struct SpawnBlockingExecutor(futures::executor::ThreadPool); pub struct TaskExecutor(futures::executor::ThreadPool);
#[cfg(feature = "std")] #[cfg(feature = "std")]
impl SpawnBlockingExecutor { impl TaskExecutor {
/// Create a new instance of `Self`. /// Create a new instance of `Self`.
pub fn new() -> Self { pub fn new() -> Self {
let mut builder = futures::executor::ThreadPoolBuilder::new(); let mut builder = futures::executor::ThreadPoolBuilder::new();
@@ -377,7 +377,7 @@ impl SpawnBlockingExecutor {
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]
impl crate::traits::SpawnNamed for SpawnBlockingExecutor { impl crate::traits::SpawnNamed for TaskExecutor {
fn spawn_blocking(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) { fn spawn_blocking(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
self.0.spawn_ok(future); self.0.spawn_ok(future);
} }
+16 -11
View File
@@ -352,26 +352,21 @@ impl CallInWasmExt {
} }
} }
/// Something that can spawn tasks and also can be cloned.
pub trait CloneableSpawn: futures::task::Spawn + Send + Sync {
/// Clone as heap-allocated handle.
fn clone(&self) -> Box<dyn CloneableSpawn>;
}
sp_externalities::decl_extension! { sp_externalities::decl_extension! {
/// Task executor extension. /// Task executor extension.
pub struct TaskExecutorExt(Box<dyn CloneableSpawn>); pub struct TaskExecutorExt(Box<dyn SpawnNamed>);
} }
impl TaskExecutorExt { impl TaskExecutorExt {
/// New instance of task executor extension. /// New instance of task executor extension.
pub fn new(spawn_handle: Box<dyn CloneableSpawn>) -> Self { pub fn new(spawn_handle: impl SpawnNamed + Send + 'static) -> Self {
Self(spawn_handle) Self(Box::new(spawn_handle))
} }
} }
/// Something that can spawn futures (blocking and non-blocking) with am assigned name. /// Something that can spawn futures (blocking and non-blocking) with an assigned name.
pub trait SpawnNamed { #[dyn_clonable::clonable]
pub trait SpawnNamed: Clone + Send + Sync {
/// Spawn the given blocking future. /// Spawn the given blocking future.
/// ///
/// The given `name` is used to identify the future in tracing. /// The given `name` is used to identify the future in tracing.
@@ -381,3 +376,13 @@ pub trait SpawnNamed {
/// The given `name` is used to identify the future in tracing. /// The given `name` is used to identify the future in tracing.
fn spawn(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>); fn spawn(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>);
} }
impl SpawnNamed for Box<dyn SpawnNamed> {
fn spawn_blocking(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>) {
(**self).spawn_blocking(name, future)
}
fn spawn(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>) {
(**self).spawn(name, future)
}
}
@@ -108,9 +108,9 @@ pub struct Extensions {
} }
impl std::fmt::Debug for Extensions { impl std::fmt::Debug for Extensions {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Extensions: ({})", self.extensions.len()) write!(f, "Extensions: ({})", self.extensions.len())
} }
} }
impl Extensions { impl Extensions {
+38 -30
View File
@@ -17,9 +17,9 @@
//! Batch/parallel verification. //! Batch/parallel verification.
use sp_core::{ed25519, sr25519, ecdsa, crypto::Pair, traits::CloneableSpawn}; use sp_core::{ed25519, sr25519, ecdsa, crypto::Pair, traits::SpawnNamed};
use std::sync::{Arc, atomic::{AtomicBool, Ordering as AtomicOrdering}}; use std::sync::{Arc, atomic::{AtomicBool, Ordering as AtomicOrdering}};
use futures::{future::FutureExt, task::FutureObj, channel::oneshot}; use futures::{future::FutureExt, channel::oneshot};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct Sr25519BatchItem { struct Sr25519BatchItem {
@@ -35,14 +35,14 @@ struct Sr25519BatchItem {
/// call `verify_and_clear to get a result. After that, batch verifier is ready for the /// call `verify_and_clear to get a result. After that, batch verifier is ready for the
/// next batching job. /// next batching job.
pub struct BatchVerifier { pub struct BatchVerifier {
scheduler: Box<dyn CloneableSpawn>, scheduler: Box<dyn SpawnNamed>,
sr25519_items: Vec<Sr25519BatchItem>, sr25519_items: Vec<Sr25519BatchItem>,
invalid: Arc<AtomicBool>, invalid: Arc<AtomicBool>,
pending_tasks: Vec<oneshot::Receiver<()>>, pending_tasks: Vec<oneshot::Receiver<()>>,
} }
impl BatchVerifier { impl BatchVerifier {
pub fn new(scheduler: Box<dyn CloneableSpawn>) -> Self { pub fn new(scheduler: Box<dyn SpawnNamed>) -> Self {
BatchVerifier { BatchVerifier {
scheduler, scheduler,
sr25519_items: Default::default(), sr25519_items: Default::default(),
@@ -56,7 +56,9 @@ impl BatchVerifier {
/// Returns `false` if there was already an invalid verification or if /// Returns `false` if there was already an invalid verification or if
/// the verification could not be spawned. /// the verification could not be spawned.
fn spawn_verification_task( fn spawn_verification_task(
&mut self, f: impl FnOnce() -> bool + Send + 'static, &mut self,
f: impl FnOnce() -> bool + Send + 'static,
name: &'static str,
) -> bool { ) -> bool {
// there is already invalid transaction encountered // there is already invalid transaction encountered
if self.invalid.load(AtomicOrdering::Relaxed) { return false; } if self.invalid.load(AtomicOrdering::Relaxed) { return false; }
@@ -65,7 +67,8 @@ impl BatchVerifier {
let (sender, receiver) = oneshot::channel(); let (sender, receiver) = oneshot::channel();
self.pending_tasks.push(receiver); self.pending_tasks.push(receiver);
self.scheduler.spawn_obj(FutureObj::new( self.scheduler.spawn(
name,
async move { async move {
if !f() { if !f() {
invalid_clone.store(true, AtomicOrdering::Relaxed); invalid_clone.store(true, AtomicOrdering::Relaxed);
@@ -75,15 +78,10 @@ impl BatchVerifier {
log::warn!("Verification halted while result was pending"); log::warn!("Verification halted while result was pending");
invalid_clone.store(true, AtomicOrdering::Relaxed); invalid_clone.store(true, AtomicOrdering::Relaxed);
} }
}.boxed() }.boxed(),
)) );
.map_err(|_| {
log::debug!( true
target: "runtime",
"Batch-verification returns false because failed to spawn background task.",
)
})
.is_ok()
} }
/// Push ed25519 signature to verify. /// Push ed25519 signature to verify.
@@ -96,7 +94,10 @@ impl BatchVerifier {
pub_key: ed25519::Public, pub_key: ed25519::Public,
message: Vec<u8>, message: Vec<u8>,
) -> bool { ) -> bool {
self.spawn_verification_task(move || ed25519::Pair::verify(&signature, &message, &pub_key)) self.spawn_verification_task(
move || ed25519::Pair::verify(&signature, &message, &pub_key),
"substrate_ed25519_verify",
)
} }
/// Push sr25519 signature to verify. /// Push sr25519 signature to verify.
@@ -114,7 +115,10 @@ impl BatchVerifier {
if self.sr25519_items.len() >= 128 { if self.sr25519_items.len() >= 128 {
let items = std::mem::take(&mut self.sr25519_items); let items = std::mem::take(&mut self.sr25519_items);
self.spawn_verification_task(move || Self::verify_sr25519_batch(items)) self.spawn_verification_task(
move || Self::verify_sr25519_batch(items),
"substrate_sr25519_verify",
)
} else { } else {
true true
} }
@@ -130,7 +134,10 @@ impl BatchVerifier {
pub_key: ecdsa::Public, pub_key: ecdsa::Public,
message: Vec<u8>, message: Vec<u8>,
) -> bool { ) -> bool {
self.spawn_verification_task(move || ecdsa::Pair::verify(&signature, &message, &pub_key)) self.spawn_verification_task(
move || ecdsa::Pair::verify(&signature, &message, &pub_key),
"substrate_ecdsa_verify",
)
} }
fn verify_sr25519_batch(items: Vec<Sr25519BatchItem>) -> bool { fn verify_sr25519_batch(items: Vec<Sr25519BatchItem>) -> bool {
@@ -161,23 +168,24 @@ impl BatchVerifier {
if pending.len() > 0 { if pending.len() > 0 {
let (sender, receiver) = std::sync::mpsc::channel(); let (sender, receiver) = std::sync::mpsc::channel();
if self.scheduler.spawn_obj(FutureObj::new(async move { self.scheduler.spawn(
futures::future::join_all(pending).await; "substrate_batch_verify_join",
sender.send(()) async move {
.expect("Channel never panics if receiver is live. \ futures::future::join_all(pending).await;
Receiver is always live until received this data; qed. "); sender.send(())
}.boxed())).is_err() { .expect("Channel never panics if receiver is live. \
log::debug!( Receiver is always live until received this data; qed. ");
}.boxed(),
);
if receiver.recv().is_err() {
log::warn!(
target: "runtime", target: "runtime",
"Batch-verification returns false because failed to spawn background task.", "Haven't received async result from verification task. Returning false.",
); );
return false; return false;
} }
if receiver.recv().is_err() {
log::warn!(target: "runtime", "Haven't received async result from verification task. Returning false.");
return false;
}
} }
log::trace!( log::trace!(
+10 -5
View File
@@ -1206,9 +1206,10 @@ pub type SubstrateHostFunctions = (
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use sp_core::map;
use sp_state_machine::BasicExternalities; use sp_state_machine::BasicExternalities;
use sp_core::storage::Storage; use sp_core::{
storage::Storage, map, traits::TaskExecutorExt, testing::TaskExecutor,
};
use std::any::TypeId; use std::any::TypeId;
#[test] #[test]
@@ -1274,7 +1275,9 @@ mod tests {
#[test] #[test]
fn batch_verify_start_finish_works() { fn batch_verify_start_finish_works() {
let mut ext = BasicExternalities::with_tasks_executor(); let mut ext = BasicExternalities::default();
ext.register_extension(TaskExecutorExt::new(TaskExecutor::new()));
ext.execute_with(|| { ext.execute_with(|| {
crypto::start_batch_verify(); crypto::start_batch_verify();
}); });
@@ -1290,7 +1293,8 @@ mod tests {
#[test] #[test]
fn long_sr25519_batching() { fn long_sr25519_batching() {
let mut ext = BasicExternalities::with_tasks_executor(); let mut ext = BasicExternalities::default();
ext.register_extension(TaskExecutorExt::new(TaskExecutor::new()));
ext.execute_with(|| { ext.execute_with(|| {
let pair = sr25519::Pair::generate_with_phrase(None).0; let pair = sr25519::Pair::generate_with_phrase(None).0;
crypto::start_batch_verify(); crypto::start_batch_verify();
@@ -1320,7 +1324,8 @@ mod tests {
#[test] #[test]
fn batching_works() { fn batching_works() {
let mut ext = BasicExternalities::with_tasks_executor(); let mut ext = BasicExternalities::default();
ext.register_extension(TaskExecutorExt::new(TaskExecutor::new()));
ext.execute_with(|| { ext.execute_with(|| {
// invalid ed25519 signature // invalid ed25519 signature
crypto::start_batch_verify(); crypto::start_batch_verify();
+5 -1
View File
@@ -871,7 +871,11 @@ mod tests {
#[test] #[test]
#[should_panic(expected = "Signature verification has not been called")] #[should_panic(expected = "Signature verification has not been called")]
fn batching_still_finishes_when_not_called_directly() { fn batching_still_finishes_when_not_called_directly() {
let mut ext = sp_state_machine::BasicExternalities::with_tasks_executor(); let mut ext = sp_state_machine::BasicExternalities::default();
ext.register_extension(
sp_core::traits::TaskExecutorExt::new(sp_core::testing::TaskExecutor::new()),
);
ext.execute_with(|| { ext.execute_with(|| {
let _batching = SignatureBatching::start(); let _batching = SignatureBatching::start();
sp_io::crypto::sr25519_verify( sp_io::crypto::sr25519_verify(
@@ -33,7 +33,7 @@ use sp_core::{
}; };
use log::warn; use log::warn;
use codec::Encode; use codec::Encode;
use sp_externalities::Extensions; use sp_externalities::{Extensions, Extension};
/// Simple Map-based Externalities impl. /// Simple Map-based Externalities impl.
#[derive(Debug)] #[derive(Debug)]
@@ -53,17 +53,6 @@ impl BasicExternalities {
Self::new(Storage::default()) Self::new(Storage::default())
} }
/// New basic extternalities with tasks executor.
pub fn with_tasks_executor() -> Self {
let mut extensions = Extensions::default();
extensions.register(sp_core::traits::TaskExecutorExt(sp_core::tasks::executor()));
Self {
inner: Storage::default(),
extensions,
}
}
/// Insert key/value /// Insert key/value
pub fn insert(&mut self, k: StorageKey, v: StorageValue) -> Option<StorageValue> { pub fn insert(&mut self, k: StorageKey, v: StorageValue) -> Option<StorageValue> {
self.inner.top.insert(k, v) self.inner.top.insert(k, v)
@@ -107,6 +96,11 @@ impl BasicExternalities {
pub fn extensions(&mut self) -> &mut Extensions { pub fn extensions(&mut self) -> &mut Extensions {
&mut self.extensions &mut self.extensions
} }
/// Register an extension.
pub fn register_extension(&mut self, ext: impl Extension) {
self.extensions.register(ext);
}
} }
impl PartialEq for BasicExternalities { impl PartialEq for BasicExternalities {
+26 -21
View File
@@ -26,7 +26,7 @@ use codec::{Decode, Encode, Codec};
use sp_core::{ use sp_core::{
offchain::storage::OffchainOverlayedChanges, offchain::storage::OffchainOverlayedChanges,
storage::ChildInfo, NativeOrEncoded, NeverNativeValue, hexdisplay::HexDisplay, storage::ChildInfo, NativeOrEncoded, NeverNativeValue, hexdisplay::HexDisplay,
traits::{CodeExecutor, CallInWasmExt, RuntimeCode}, traits::{CodeExecutor, CallInWasmExt, RuntimeCode, SpawnNamed},
}; };
use sp_externalities::Extensions; use sp_externalities::Extensions;
@@ -77,7 +77,6 @@ pub use trie_backend::TrieBackend;
pub use error::{Error, ExecutionError}; pub use error::{Error, ExecutionError};
pub use in_memory_backend::new_in_mem; pub use in_memory_backend::new_in_mem;
pub use stats::{UsageInfo, UsageUnit, StateMachineStats}; pub use stats::{UsageInfo, UsageUnit, StateMachineStats};
pub use sp_core::traits::CloneableSpawn;
const PROOF_CLOSE_TRANSACTION: &str = "\ const PROOF_CLOSE_TRANSACTION: &str = "\
Closing a transaction that was started in this function. Client initiated transactions Closing a transaction that was started in this function. Client initiated transactions
@@ -233,7 +232,7 @@ impl<'a, B, H, N, Exec> StateMachine<'a, B, H, N, Exec> where
call_data: &'a [u8], call_data: &'a [u8],
mut extensions: Extensions, mut extensions: Extensions,
runtime_code: &'a RuntimeCode, runtime_code: &'a RuntimeCode,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: impl SpawnNamed + Send + 'static,
) -> Self { ) -> Self {
extensions.register(CallInWasmExt::new(exec.clone())); extensions.register(CallInWasmExt::new(exec.clone()));
extensions.register(sp_core::traits::TaskExecutorExt::new(spawn_handle)); extensions.register(sp_core::traits::TaskExecutorExt::new(spawn_handle));
@@ -463,11 +462,11 @@ impl<'a, B, H, N, Exec> StateMachine<'a, B, H, N, Exec> where
} }
/// Prove execution using the given state backend, overlayed changes, and call executor. /// Prove execution using the given state backend, overlayed changes, and call executor.
pub fn prove_execution<B, H, N, Exec>( pub fn prove_execution<B, H, N, Exec, Spawn>(
mut backend: B, mut backend: B,
overlay: &mut OverlayedChanges, overlay: &mut OverlayedChanges,
exec: &Exec, exec: &Exec,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Spawn,
method: &str, method: &str,
call_data: &[u8], call_data: &[u8],
runtime_code: &RuntimeCode, runtime_code: &RuntimeCode,
@@ -478,10 +477,11 @@ where
H::Out: Ord + 'static + codec::Codec, H::Out: Ord + 'static + codec::Codec,
Exec: CodeExecutor + Clone + 'static, Exec: CodeExecutor + Clone + 'static,
N: crate::changes_trie::BlockNumber, N: crate::changes_trie::BlockNumber,
Spawn: SpawnNamed + Send + 'static,
{ {
let trie_backend = backend.as_trie_backend() let trie_backend = backend.as_trie_backend()
.ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box<dyn Error>)?; .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box<dyn Error>)?;
prove_execution_on_trie_backend::<_, _, N, _>( prove_execution_on_trie_backend::<_, _, N, _, _>(
trie_backend, trie_backend,
overlay, overlay,
exec, exec,
@@ -501,11 +501,11 @@ where
/// ///
/// Note: changes to code will be in place if this call is made again. For running partial /// Note: changes to code will be in place if this call is made again. For running partial
/// blocks (e.g. a transaction at a time), ensure a different method is used. /// blocks (e.g. a transaction at a time), ensure a different method is used.
pub fn prove_execution_on_trie_backend<S, H, N, Exec>( pub fn prove_execution_on_trie_backend<S, H, N, Exec, Spawn>(
trie_backend: &TrieBackend<S, H>, trie_backend: &TrieBackend<S, H>,
overlay: &mut OverlayedChanges, overlay: &mut OverlayedChanges,
exec: &Exec, exec: &Exec,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Spawn,
method: &str, method: &str,
call_data: &[u8], call_data: &[u8],
runtime_code: &RuntimeCode, runtime_code: &RuntimeCode,
@@ -516,6 +516,7 @@ where
H::Out: Ord + 'static + codec::Codec, H::Out: Ord + 'static + codec::Codec,
Exec: CodeExecutor + 'static + Clone, Exec: CodeExecutor + 'static + Clone,
N: crate::changes_trie::BlockNumber, N: crate::changes_trie::BlockNumber,
Spawn: SpawnNamed + Send + 'static,
{ {
let mut offchain_overlay = OffchainOverlayedChanges::default(); let mut offchain_overlay = OffchainOverlayedChanges::default();
let proving_backend = proving_backend::ProvingBackend::new(trie_backend); let proving_backend = proving_backend::ProvingBackend::new(trie_backend);
@@ -541,12 +542,12 @@ where
} }
/// Check execution proof, generated by `prove_execution` call. /// Check execution proof, generated by `prove_execution` call.
pub fn execution_proof_check<H, N, Exec>( pub fn execution_proof_check<H, N, Exec, Spawn>(
root: H::Out, root: H::Out,
proof: StorageProof, proof: StorageProof,
overlay: &mut OverlayedChanges, overlay: &mut OverlayedChanges,
exec: &Exec, exec: &Exec,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Spawn,
method: &str, method: &str,
call_data: &[u8], call_data: &[u8],
runtime_code: &RuntimeCode, runtime_code: &RuntimeCode,
@@ -556,9 +557,10 @@ where
Exec: CodeExecutor + Clone + 'static, Exec: CodeExecutor + Clone + 'static,
H::Out: Ord + 'static + codec::Codec, H::Out: Ord + 'static + codec::Codec,
N: crate::changes_trie::BlockNumber, N: crate::changes_trie::BlockNumber,
Spawn: SpawnNamed + Send + 'static,
{ {
let trie_backend = create_proof_check_backend::<H>(root.into(), proof)?; let trie_backend = create_proof_check_backend::<H>(root.into(), proof)?;
execution_proof_check_on_trie_backend::<_, N, _>( execution_proof_check_on_trie_backend::<_, N, _, _>(
&trie_backend, &trie_backend,
overlay, overlay,
exec, exec,
@@ -570,11 +572,11 @@ where
} }
/// Check execution proof on proving backend, generated by `prove_execution` call. /// Check execution proof on proving backend, generated by `prove_execution` call.
pub fn execution_proof_check_on_trie_backend<H, N, Exec>( pub fn execution_proof_check_on_trie_backend<H, N, Exec, Spawn>(
trie_backend: &TrieBackend<MemoryDB<H>, H>, trie_backend: &TrieBackend<MemoryDB<H>, H>,
overlay: &mut OverlayedChanges, overlay: &mut OverlayedChanges,
exec: &Exec, exec: &Exec,
spawn_handle: Box<dyn CloneableSpawn>, spawn_handle: Spawn,
method: &str, method: &str,
call_data: &[u8], call_data: &[u8],
runtime_code: &RuntimeCode, runtime_code: &RuntimeCode,
@@ -584,6 +586,7 @@ where
H::Out: Ord + 'static + codec::Codec, H::Out: Ord + 'static + codec::Codec,
Exec: CodeExecutor + Clone + 'static, Exec: CodeExecutor + Clone + 'static,
N: crate::changes_trie::BlockNumber, N: crate::changes_trie::BlockNumber,
Spawn: SpawnNamed + Send + 'static,
{ {
let mut offchain_overlay = OffchainOverlayedChanges::default(); let mut offchain_overlay = OffchainOverlayedChanges::default();
let mut sm = StateMachine::<_, H, N, Exec>::new( let mut sm = StateMachine::<_, H, N, Exec>::new(
@@ -765,7 +768,9 @@ mod tests {
use super::*; use super::*;
use super::ext::Ext; use super::ext::Ext;
use super::changes_trie::Configuration as ChangesTrieConfig; use super::changes_trie::Configuration as ChangesTrieConfig;
use sp_core::{map, traits::{Externalities, RuntimeCode}}; use sp_core::{
map, traits::{Externalities, RuntimeCode}, testing::TaskExecutor,
};
use sp_runtime::traits::BlakeTwo256; use sp_runtime::traits::BlakeTwo256;
#[derive(Clone)] #[derive(Clone)]
@@ -859,7 +864,7 @@ mod tests {
&[], &[],
Default::default(), Default::default(),
&wasm_code, &wasm_code,
sp_core::tasks::executor(), TaskExecutor::new(),
); );
assert_eq!( assert_eq!(
@@ -891,7 +896,7 @@ mod tests {
&[], &[],
Default::default(), Default::default(),
&wasm_code, &wasm_code,
sp_core::tasks::executor(), TaskExecutor::new(),
); );
assert_eq!(state_machine.execute(ExecutionStrategy::NativeElseWasm).unwrap(), vec![66]); assert_eq!(state_machine.execute(ExecutionStrategy::NativeElseWasm).unwrap(), vec![66]);
@@ -920,7 +925,7 @@ mod tests {
&[], &[],
Default::default(), Default::default(),
&wasm_code, &wasm_code,
sp_core::tasks::executor(), TaskExecutor::new(),
); );
assert!( assert!(
@@ -947,23 +952,23 @@ mod tests {
// fetch execution proof from 'remote' full node // fetch execution proof from 'remote' full node
let remote_backend = trie_backend::tests::test_trie(); let remote_backend = trie_backend::tests::test_trie();
let remote_root = remote_backend.storage_root(std::iter::empty()).0; let remote_root = remote_backend.storage_root(std::iter::empty()).0;
let (remote_result, remote_proof) = prove_execution::<_, _, u64, _>( let (remote_result, remote_proof) = prove_execution::<_, _, u64, _, _>(
remote_backend, remote_backend,
&mut Default::default(), &mut Default::default(),
&executor, &executor,
sp_core::tasks::executor(), TaskExecutor::new(),
"test", "test",
&[], &[],
&RuntimeCode::empty(), &RuntimeCode::empty(),
).unwrap(); ).unwrap();
// check proof locally // check proof locally
let local_result = execution_proof_check::<BlakeTwo256, u64, _>( let local_result = execution_proof_check::<BlakeTwo256, u64, _, _>(
remote_root, remote_root,
remote_proof, remote_proof,
&mut Default::default(), &mut Default::default(),
&executor, &executor,
sp_core::tasks::executor(), TaskExecutor::new(),
"test", "test",
&[], &[],
&RuntimeCode::empty(), &RuntimeCode::empty(),
@@ -39,6 +39,8 @@ use sp_core::{
well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES, is_child_storage_key}, well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES, is_child_storage_key},
Storage, Storage,
}, },
traits::TaskExecutorExt,
testing::TaskExecutor,
}; };
use codec::Encode; use codec::Encode;
use sp_externalities::{Extensions, Extension}; use sp_externalities::{Extensions, Extension};
@@ -109,8 +111,7 @@ impl<H: Hasher, N: ChangesTrieBlockNumber> TestExternalities<H, N>
let offchain_overlay = OffchainOverlayedChanges::enabled(); let offchain_overlay = OffchainOverlayedChanges::enabled();
let mut extensions = Extensions::default(); let mut extensions = Extensions::default();
extensions.register(sp_core::traits::TaskExecutorExt(sp_core::tasks::executor())); extensions.register(TaskExecutorExt::new(TaskExecutor::new()));
let offchain_db = TestPersistentOffchainDB::new(); let offchain_db = TestPersistentOffchainDB::new();
+8 -3
View File
@@ -23,7 +23,7 @@ pub mod client_ext;
pub use sc_client_api::{ pub use sc_client_api::{
execution_extensions::{ExecutionStrategies, ExecutionExtensions}, execution_extensions::{ExecutionStrategies, ExecutionExtensions},
ForkBlocks, BadBlocks, CloneableSpawn, ForkBlocks, BadBlocks,
}; };
pub use sc_client_db::{Backend, self}; pub use sc_client_db::{Backend, self};
pub use sp_consensus; pub use sp_consensus;
@@ -33,7 +33,7 @@ pub use sp_keyring::{
ed25519::Keyring as Ed25519Keyring, ed25519::Keyring as Ed25519Keyring,
sr25519::Keyring as Sr25519Keyring, sr25519::Keyring as Sr25519Keyring,
}; };
pub use sp_core::{traits::BareCryptoStorePtr, tasks::executor as tasks_executor}; pub use sp_core::traits::BareCryptoStorePtr;
pub use sp_runtime::{Storage, StorageChild}; pub use sp_runtime::{Storage, StorageChild};
pub use sp_state_machine::ExecutionStrategy; pub use sp_state_machine::ExecutionStrategy;
pub use sc_service::{RpcHandlers, RpcSession, client}; pub use sc_service::{RpcHandlers, RpcSession, client};
@@ -254,7 +254,12 @@ impl<Block: BlockT, E, Backend, G: GenesisInit> TestClientBuilder<
let executor = executor.into().unwrap_or_else(|| let executor = executor.into().unwrap_or_else(||
NativeExecutor::new(WasmExecutionMethod::Interpreted, None, 8) NativeExecutor::new(WasmExecutionMethod::Interpreted, None, 8)
); );
let executor = LocalCallExecutor::new(self.backend.clone(), executor, tasks_executor(), Default::default()); let executor = LocalCallExecutor::new(
self.backend.clone(),
executor,
Box::new(sp_core::testing::TaskExecutor::new()),
Default::default(),
);
self.build_with_executor(executor) self.build_with_executor(executor)
} }
@@ -350,7 +350,12 @@ pub fn new_light() -> (
let blockchain = Arc::new(sc_light::Blockchain::new(storage)); let blockchain = Arc::new(sc_light::Blockchain::new(storage));
let backend = Arc::new(LightBackend::new(blockchain)); let backend = Arc::new(LightBackend::new(blockchain));
let executor = new_native_executor(); let executor = new_native_executor();
let local_call_executor = client::LocalCallExecutor::new(backend.clone(), executor, sp_core::tasks::executor(), Default::default()); let local_call_executor = client::LocalCallExecutor::new(
backend.clone(),
executor,
Box::new(sp_core::testing::TaskExecutor::new()),
Default::default(),
);
let call_executor = LightExecutor::new( let call_executor = LightExecutor::new(
backend.clone(), backend.clone(),
local_call_executor, local_call_executor,
@@ -24,11 +24,8 @@ use sc_executor::NativeExecutor;
use sp_state_machine::StateMachine; use sp_state_machine::StateMachine;
use sp_externalities::Extensions; use sp_externalities::Extensions;
use sc_service::{Configuration, NativeExecutionDispatch}; use sc_service::{Configuration, NativeExecutionDispatch};
use sp_runtime::{ use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
traits::{Block as BlockT, Header as HeaderT, NumberFor},
};
use sp_core::{ use sp_core::{
tasks,
testing::KeyStore, testing::KeyStore,
traits::KeystoreExt, traits::KeystoreExt,
offchain::{OffchainExt, testing::TestOffchainExt}, offchain::{OffchainExt, testing::TestOffchainExt},
@@ -81,7 +78,7 @@ impl BenchmarkCmd {
).encode(), ).encode(),
extensions, extensions,
&sp_state_machine::backend::BackendRuntimeCode::new(&state).runtime_code()?, &sp_state_machine::backend::BackendRuntimeCode::new(&state).runtime_code()?,
tasks::executor(), sp_core::testing::TaskExecutor::new(),
) )
.execute(strategy.into()) .execute(strategy.into())
.map_err(|e| format!("Error executing runtime benchmark: {:?}", e))?; .map_err(|e| format!("Error executing runtime benchmark: {:?}", e))?;
+4 -4
View File
@@ -298,7 +298,7 @@ mod tests {
// given // given
let client = Arc::new(substrate_test_runtime_client::new()); let client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = BasicPool::new_full( let pool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
@@ -338,7 +338,7 @@ mod tests {
// given // given
let client = Arc::new(substrate_test_runtime_client::new()); let client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = BasicPool::new_full( let pool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
@@ -362,7 +362,7 @@ mod tests {
// given // given
let client = Arc::new(substrate_test_runtime_client::new()); let client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = BasicPool::new_full( let pool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),
@@ -395,7 +395,7 @@ mod tests {
// given // given
let client = Arc::new(substrate_test_runtime_client::new()); let client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::SpawnBlockingExecutor::new(); let spawner = sp_core::testing::TaskExecutor::new();
let pool = BasicPool::new_full( let pool = BasicPool::new_full(
Default::default(), Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)), Arc::new(FullChainApi::new(client.clone(), None)),