Remove tokio dependencies (#2935)

* Remove dependencies on tokio

* Make service not depend on tokio

* Fix service tests

* Manually poll the import queue if failed to start

* Spawn all tasks at the end

* Remove executor from TelemetryOnConnect

* Remove TaskExecutor from offchain workers

* Remove TaskExecutor from AuthoritySetup

* Remove TaskExecutor from service

* Remove tokio dependency from RPC

* Remove finality-grandpa from WASM checks

* Fix offchain tests

* Line widths

* Fix RPC tests

* Fix service tests

* Fix bad futures polling

* Address some concerns

* Better error handling

* Is it the connectivity test that's not passing? I don't know, let's try

* Revert "Is it the connectivity test that's not passing? I don't know, let's try"

This reverts commit 28bbe51f0e2e4885fe1f901e11078604604cb212.

* Fix test
This commit is contained in:
Pierre Krieger
2019-06-26 17:21:17 +02:00
committed by Bastian Köcher
parent f69c48c7b8
commit 1b73b6532a
26 changed files with 287 additions and 154 deletions
+5 -5
View File
@@ -44,7 +44,7 @@ fn submit_transaction_should_not_cause_error() {
let p = Author {
client: client.clone(),
pool: Arc::new(Pool::new(Default::default(), ChainApi::new(client))),
subscriptions: Subscriptions::new(runtime.executor()),
subscriptions: Subscriptions::new(Arc::new(runtime.executor())),
};
let xt = uxt(AccountKeyring::Alice, 1).encode();
let h: H256 = blake2_256(&xt).into();
@@ -65,7 +65,7 @@ fn submit_rich_transaction_should_not_cause_error() {
let p = Author {
client: client.clone(),
pool: Arc::new(Pool::new(Default::default(), ChainApi::new(client.clone()))),
subscriptions: Subscriptions::new(runtime.executor()),
subscriptions: Subscriptions::new(Arc::new(runtime.executor())),
};
let xt = uxt(AccountKeyring::Alice, 0).encode();
let h: H256 = blake2_256(&xt).into();
@@ -88,7 +88,7 @@ fn should_watch_extrinsic() {
let p = Author {
client,
pool: pool.clone(),
subscriptions: Subscriptions::new(runtime.executor()),
subscriptions: Subscriptions::new(Arc::new(runtime.executor())),
};
let (subscriber, id_rx, data) = ::jsonrpc_pubsub::typed::Subscriber::new_test("test");
@@ -128,7 +128,7 @@ fn should_return_pending_extrinsics() {
let p = Author {
client,
pool: pool.clone(),
subscriptions: Subscriptions::new(runtime.executor()),
subscriptions: Subscriptions::new(Arc::new(runtime.executor())),
};
let ex = uxt(AccountKeyring::Alice, 0);
AuthorApi::submit_extrinsic(&p, ex.encode().into()).unwrap();
@@ -146,7 +146,7 @@ fn should_remove_extrinsics() {
let p = Author {
client,
pool: pool.clone(),
subscriptions: Subscriptions::new(runtime.executor()),
subscriptions: Subscriptions::new(Arc::new(runtime.executor())),
};
let ex1 = uxt(AccountKeyring::Alice, 0);
p.submit_extrinsic(ex1.encode().into()).unwrap();
+6 -6
View File
@@ -29,7 +29,7 @@ fn should_return_header() {
let client = Chain {
client: Arc::new(test_client::new()),
subscriptions: Subscriptions::new(remote),
subscriptions: Subscriptions::new(Arc::new(remote)),
};
assert_matches!(
@@ -67,7 +67,7 @@ fn should_return_a_block() {
let api = Chain {
client: Arc::new(test_client::new()),
subscriptions: Subscriptions::new(remote),
subscriptions: Subscriptions::new(Arc::new(remote)),
};
let block = api.client.new_block(Default::default()).unwrap().bake().unwrap();
@@ -121,7 +121,7 @@ fn should_return_block_hash() {
let client = Chain {
client: Arc::new(test_client::new()),
subscriptions: Subscriptions::new(remote),
subscriptions: Subscriptions::new(Arc::new(remote)),
};
assert_matches!(
@@ -165,7 +165,7 @@ fn should_return_finalized_hash() {
let client = Chain {
client: Arc::new(test_client::new()),
subscriptions: Subscriptions::new(remote),
subscriptions: Subscriptions::new(Arc::new(remote)),
};
assert_matches!(
@@ -199,7 +199,7 @@ fn should_notify_about_latest_block() {
{
let api = Chain {
client: Arc::new(test_client::new()),
subscriptions: Subscriptions::new(remote),
subscriptions: Subscriptions::new(Arc::new(remote)),
};
api.subscribe_new_head(Default::default(), subscriber);
@@ -230,7 +230,7 @@ fn should_notify_about_finalized_block() {
{
let api = Chain {
client: Arc::new(test_client::new()),
subscriptions: Subscriptions::new(remote),
subscriptions: Subscriptions::new(Arc::new(remote)),
};
api.subscribe_finalized_heads(Default::default(), subscriber);
+8 -8
View File
@@ -32,7 +32,7 @@ fn should_return_storage() {
let core = tokio::runtime::Runtime::new().unwrap();
let client = Arc::new(test_client::new());
let genesis_hash = client.genesis_hash();
let client = State::new(client, Subscriptions::new(core.executor()));
let client = State::new(client, Subscriptions::new(Arc::new(core.executor())));
let key = StorageKey(b":code".to_vec());
assert_eq!(
@@ -57,7 +57,7 @@ fn should_return_child_storage() {
.add_child_storage("test", "key", vec![42_u8])
.build());
let genesis_hash = client.genesis_hash();
let client = State::new(client, Subscriptions::new(core.executor()));
let client = State::new(client, Subscriptions::new(Arc::new(core.executor())));
let child_key = StorageKey(well_known_keys::CHILD_STORAGE_KEY_PREFIX.iter().chain(b"test").cloned().collect());
let key = StorageKey(b"key".to_vec());
@@ -82,7 +82,7 @@ fn should_call_contract() {
let core = tokio::runtime::Runtime::new().unwrap();
let client = Arc::new(test_client::new());
let genesis_hash = client.genesis_hash();
let client = State::new(client, Subscriptions::new(core.executor()));
let client = State::new(client, Subscriptions::new(Arc::new(core.executor())));
assert_matches!(
client.call("balanceOf".into(), Bytes(vec![1,2,3]), Some(genesis_hash).into()),
@@ -97,7 +97,7 @@ fn should_notify_about_storage_changes() {
let (subscriber, id, transport) = Subscriber::new_test("test");
{
let api = State::new(Arc::new(test_client::new()), Subscriptions::new(remote));
let api = State::new(Arc::new(test_client::new()), Subscriptions::new(Arc::new(remote)));
api.subscribe_storage(Default::default(), subscriber, None.into());
@@ -128,7 +128,7 @@ fn should_send_initial_storage_changes_and_notifications() {
let (subscriber, id, transport) = Subscriber::new_test("test");
{
let api = State::new(Arc::new(test_client::new()), Subscriptions::new(remote));
let api = State::new(Arc::new(test_client::new()), Subscriptions::new(Arc::new(remote)));
let alice_balance_key = blake2_256(&runtime::system::balance_of_key(AccountKeyring::Alice.into()));
@@ -163,7 +163,7 @@ fn should_send_initial_storage_changes_and_notifications() {
fn should_query_storage() {
fn run_tests(client: Arc<TestClient>) {
let core = tokio::runtime::Runtime::new().unwrap();
let api = State::new(client.clone(), Subscriptions::new(core.executor()));
let api = State::new(client.clone(), Subscriptions::new(Arc::new(core.executor())));
let add_block = |nonce| {
let mut builder = client.new_block(Default::default()).unwrap();
@@ -254,7 +254,7 @@ fn should_return_runtime_version() {
let core = tokio::runtime::Runtime::new().unwrap();
let client = Arc::new(test_client::new());
let api = State::new(client.clone(), Subscriptions::new(core.executor()));
let api = State::new(client.clone(), Subscriptions::new(Arc::new(core.executor())));
let result = "{\"specName\":\"test\",\"implName\":\"parity-test\",\"authoringVersion\":1,\
\"specVersion\":1,\"implVersion\":1,\"apis\":[[\"0xdf6acb689907609b\",2],\
@@ -274,7 +274,7 @@ fn should_notify_on_runtime_version_initially() {
{
let client = Arc::new(test_client::new());
let api = State::new(client.clone(), Subscriptions::new(core.executor()));
let api = State::new(client.clone(), Subscriptions::new(Arc::new(core.executor())));
api.subscribe_runtime_version(Default::default(), subscriber);
+7 -6
View File
@@ -17,12 +17,11 @@
use std::collections::HashMap;
use std::sync::{Arc, atomic::{self, AtomicUsize}};
use log::warn;
use log::{error, warn};
use jsonrpc_pubsub::{SubscriptionId, typed::{Sink, Subscriber}};
use parking_lot::Mutex;
use crate::rpc::futures::sync::oneshot;
use crate::rpc::futures::{Future, future};
use tokio::runtime::TaskExecutor;
type Id = u64;
@@ -50,16 +49,16 @@ impl IdProvider {
///
/// Takes care of assigning unique subscription ids and
/// driving the sinks into completion.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Subscriptions {
next_id: IdProvider,
active_subscriptions: Arc<Mutex<HashMap<Id, oneshot::Sender<()>>>>,
executor: TaskExecutor,
executor: Arc<dyn future::Executor<Box<dyn Future<Item = (), Error = ()> + Send>> + Send + Sync>,
}
impl Subscriptions {
/// Creates new `Subscriptions` object.
pub fn new(executor: TaskExecutor) -> Self {
pub fn new(executor: Arc<dyn future::Executor<Box<dyn Future<Item = (), Error = ()> + Send>> + Send + Sync>) -> Self {
Subscriptions {
next_id: Default::default(),
active_subscriptions: Default::default(),
@@ -86,7 +85,9 @@ impl Subscriptions {
.then(|_| Ok(()));
self.active_subscriptions.lock().insert(id, tx);
self.executor.spawn(future);
if self.executor.execute(Box::new(future)).is_err() {
error!("Failed to spawn RPC subscription task");
}
}
}