Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Name all the tasks! #6726

Merged
6 commits merged into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/node/bench/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl core::Benchmark for PoolBenchmark {
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(
Default::default(),
Arc::new(FullChainApi::new(context.client.clone(), None)),
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ pub fn new_light_base(config: Configuration) -> Result<(
}

/// Builds a new service for a light client.
pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
new_light_base(config).map(|(task_manager, _, _, _, _)| {
task_manager
})
Expand Down
20 changes: 8 additions & 12 deletions bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ use node_runtime::{
AccountId,
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_block_builder::BlockBuilder;
use sp_inherents::InherentData;
use sc_client_api::{
ExecutionStrategy, BlockBackend,
execution_extensions::{ExecutionExtensions, ExecutionStrategies},
};
use sp_core::{Pair, Public, sr25519, ed25519};
use sc_block_builder::BlockBuilderProvider;
use futures::{executor, task};
use futures::executor;

/// Keyring full of accounts for benching.
///
Expand Down Expand Up @@ -145,7 +144,7 @@ impl BlockType {
pub fn to_content(self, size: Option<usize>) -> BlockContent {
BlockContent {
block_type: self,
size: size,
size,
}
}
}
Expand Down Expand Up @@ -197,16 +196,13 @@ impl TaskExecutor {
}
}

impl task::Spawn for TaskExecutor {
fn spawn_obj(&self, future: task::FutureObj<'static, ()>)
-> Result<(), task::SpawnError> {
self.pool.spawn_obj(future)
impl SpawnNamed for TaskExecutor {
fn spawn(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
self.pool.spawn_ok(future);
}
}

impl CloneableSpawn for TaskExecutor {
fn clone(&self) -> Box<dyn CloneableSpawn> {
Box::new(Clone::clone(self))
fn spawn_blocking(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
self.pool.spawn_ok(future);
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub use light::*;
pub use notifications::*;
pub use proof_provider::*;

pub use sp_state_machine::{StorageProof, ExecutionStrategy, CloneableSpawn};
pub use sp_state_machine::{StorageProof, ExecutionStrategy};

/// Usage Information Provider interface
///
Expand Down
8 changes: 4 additions & 4 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ mod tests {
fn should_cease_building_block_when_deadline_is_reached() {
// given
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(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
Expand Down Expand Up @@ -412,7 +412,7 @@ mod tests {
#[test]
fn should_not_panic_when_deadline_is_reached() {
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(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
Expand Down Expand Up @@ -448,7 +448,7 @@ mod tests {
fn proposed_storage_changes_should_match_execute_block_storage_changes() {
let (client, backend) = TestClientBuilder::new().build_with_backend();
let client = Arc::new(client);
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let spawner = sp_core::testing::TaskExecutor::new();
let txpool = BasicPool::new_full(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
Expand Down Expand Up @@ -511,7 +511,7 @@ mod tests {
fn should_not_remove_invalid_transactions_when_skipping() {
// given
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(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
Expand Down
2 changes: 1 addition & 1 deletion client/basic-authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//! # };
//! # use sc_transaction_pool::{BasicPool, FullChainApi};
//! # 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(
//! # Default::default(),
//! # Arc::new(FullChainApi::new(client.clone(), None)),
Expand Down
6 changes: 3 additions & 3 deletions client/consensus/manual-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ mod tests {
let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
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(
Options::default(), api(), None, RevalidationType::Full, spawner,
));
Expand Down Expand Up @@ -288,7 +288,7 @@ mod tests {
let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
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(
Options::default(), api(), None, RevalidationType::Full, spawner,
));
Expand Down Expand Up @@ -360,7 +360,7 @@ mod tests {
let client = Arc::new(client);
let inherent_data_providers = InherentDataProviders::new();
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(
Options::default(), pool_api.clone(), None, RevalidationType::Full, spawner,
));
Expand Down
15 changes: 9 additions & 6 deletions client/light/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ use std::{
};

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::{
generic::BlockId, traits::{One, Block as BlockT, Header as HeaderT, HashFor},
};
use sp_externalities::Extensions;
use sp_state_machine::{
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;

Expand Down Expand Up @@ -220,7 +223,7 @@ pub fn prove_execution<Block, S, E>(
/// Proof should include both environment preparation proof and method execution proof.
pub fn check_execution_proof<Header, E, H>(
executor: &E,
spawn_handle: Box<dyn CloneableSpawn>,
spawn_handle: Box<dyn SpawnNamed>,
request: &RemoteCallRequest<Header>,
remote_proof: StorageProof,
) -> ClientResult<Vec<u8>>
Expand Down Expand Up @@ -251,7 +254,7 @@ pub fn check_execution_proof<Header, E, H>(
/// Proof should include both environment preparation proof and method execution proof.
pub fn check_execution_proof_with_make_header<Header, E, H, MakeNextHeader>(
executor: &E,
spawn_handle: Box<dyn CloneableSpawn>,
spawn_handle: Box<dyn SpawnNamed>,
request: &RemoteCallRequest<Header>,
remote_proof: StorageProof,
make_next_header: MakeNextHeader,
Expand All @@ -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 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,
&mut changes,
executor,
Expand All @@ -286,7 +289,7 @@ pub fn check_execution_proof_with_make_header<Header, E, H, MakeNextHeader>(
)?;

// execute method
execution_proof_check_on_trie_backend::<H, Header::Number, _>(
execution_proof_check_on_trie_backend::<H, Header::Number, _, _>(
&trie_backend,
&mut changes,
executor,
Expand Down
16 changes: 9 additions & 7 deletions client/light/src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ use std::marker::PhantomData;

use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
use codec::{Decode, Encode};
use sp_core::{convert_hash, traits::CodeExecutor};
use sp_core::storage::{ChildInfo, ChildType};
use sp_core::{convert_hash, traits::{CodeExecutor, SpawnNamed}, storage::{ChildInfo, ChildType}};
use sp_runtime::traits::{
Block as BlockT, Header as HeaderT, Hash, HashFor, NumberFor,
AtLeast32Bit, CheckedConversion,
};
use sp_state_machine::{
ChangesTrieRootsStorage, ChangesTrieAnchorBlockId, ChangesTrieConfigurationRange,
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;
use sp_blockchain::{Error as ClientError, Result as ClientResult};
Expand All @@ -46,20 +45,23 @@ pub use sc_client_api::{
},
cht,
};
use crate::blockchain::Blockchain;
use crate::call_executor::check_execution_proof;
use crate::{blockchain::Blockchain, call_executor::check_execution_proof};

/// Remote data checker.
pub struct LightDataChecker<E, H, B: BlockT, S: BlockchainStorage<B>> {
blockchain: Arc<Blockchain<S>>,
executor: E,
spawn_handle: Box<dyn CloneableSpawn>,
spawn_handle: Box<dyn SpawnNamed>,
_hasher: PhantomData<(B, H)>,
}

impl<E, H, B: BlockT, S: BlockchainStorage<B>> LightDataChecker<E, H, B, S> {
/// 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 {
blockchain, executor, spawn_handle, _hasher: PhantomData
}
Expand Down
5 changes: 2 additions & 3 deletions client/light/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
//! Light client components.

use sp_runtime::traits::{Block as BlockT, HashFor};
use sc_client_api::CloneableSpawn;
use std::sync::Arc;
use sp_core::traits::CodeExecutor;
use sp_core::traits::{CodeExecutor, SpawnNamed};

pub mod backend;
pub mod blockchain;
Expand All @@ -34,7 +33,7 @@ pub use {backend::*, blockchain::*, call_executor::*, fetcher::*};
pub fn new_fetch_checker<E, B: BlockT, S: BlockchainStorage<B>>(
blockchain: Arc<Blockchain<S>>,
executor: E,
spawn_handle: Box<dyn CloneableSpawn>,
spawn_handle: Box<dyn SpawnNamed>,
) -> LightDataChecker<E, HashFor<B>, B, S>
where
E: CodeExecutor,
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/service/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn build_test_full_node(config: config::NetworkConfiguration)
Box::new(client.clone()),
None,
None,
&sp_core::testing::SpawnBlockingExecutor::new(),
&sp_core::testing::TaskExecutor::new(),
None,
));

Expand Down
2 changes: 1 addition & 1 deletion client/network/test/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn import_single_good_block_without_header_fails() {

#[test]
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.
for _ in 0..100 {
let verifier = PassThroughVerifier::new(true);
Expand Down
4 changes: 2 additions & 2 deletions client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ pub trait TestNetFactory: Sized {
Box::new(block_import.clone()),
justification_import,
finality_proof_import,
&sp_core::testing::SpawnBlockingExecutor::new(),
&sp_core::testing::TaskExecutor::new(),
None,
));

Expand Down Expand Up @@ -728,7 +728,7 @@ pub trait TestNetFactory: Sized {
Box::new(block_import.clone()),
justification_import,
finality_proof_import,
&sp_core::testing::SpawnBlockingExecutor::new(),
&sp_core::testing::TaskExecutor::new(),
None,
));

Expand Down
2 changes: 1 addition & 1 deletion client/offchain/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ mod tests {

// Compare.
assert!(timestamp.unix_millis() > 0);
assert_eq!(timestamp.unix_millis(), d);
assert!(timestamp.unix_millis() >= d);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion client/offchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ mod tests {
let _ = env_logger::try_init();

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(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/src/author/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Default for TestSetup {
let client_builder = substrate_test_runtime_client::TestClientBuilder::new();
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(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
Expand Down
Loading