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
+15 -10
View File
@@ -34,6 +34,7 @@
#![warn(missing_docs)]
use std::{
fmt,
marker::PhantomData,
sync::Arc,
};
@@ -45,7 +46,7 @@ use runtime_primitives::{
generic::BlockId,
traits::{self, ProvideRuntimeApi},
};
use tokio::runtime::TaskExecutor;
use futures::future::Future;
use transaction_pool::txpool::{Pool, ChainApi};
mod api;
@@ -55,22 +56,24 @@ pub mod testing;
pub use offchain_primitives::OffchainWorkerApi;
/// An offchain workers manager.
#[derive(Debug)]
pub struct OffchainWorkers<C, Block: traits::Block> {
client: Arc<C>,
executor: TaskExecutor,
_block: PhantomData<Block>,
}
impl<C, Block: traits::Block> fmt::Debug for OffchainWorkers<C, Block> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("OffchainWorkers").finish()
}
}
impl<C, Block: traits::Block> OffchainWorkers<C, Block> {
/// Creates new `OffchainWorkers`.
pub fn new(
client: Arc<C>,
executor: TaskExecutor,
) -> Self {
Self {
client,
executor,
_block: PhantomData,
}
}
@@ -82,11 +85,12 @@ impl<C, Block> OffchainWorkers<C, Block> where
C::Api: OffchainWorkerApi<Block>,
{
/// Start the offchain workers after given block.
#[must_use]
pub fn on_block_imported<A>(
&self,
number: &<Block::Header as traits::Header>::Number,
pool: &Arc<Pool<A>>,
) where
) -> impl Future<Item = (), Error = ()> where
A: ChainApi<Block=Block> + 'static,
{
let runtime = self.client.runtime_api();
@@ -96,11 +100,12 @@ impl<C, Block> OffchainWorkers<C, Block> where
if has_api.unwrap_or(false) {
let (api, runner) = api::Api::new(pool.clone(), at.clone());
self.executor.spawn(runner.process());
debug!("Running offchain workers at {:?}", at);
let api = Box::new(api);
runtime.offchain_worker_with_context(&at, ExecutionContext::OffchainWorker(api), *number).unwrap();
futures::future::Either::A(runner.process())
} else {
futures::future::Either::B(futures::future::ok(()))
}
}
}
@@ -119,8 +124,8 @@ mod tests {
let pool = Arc::new(Pool::new(Default::default(), ::transaction_pool::ChainApi::new(client.clone())));
// when
let offchain = OffchainWorkers::new(client, runtime.executor());
offchain.on_block_imported(&0u64, &pool);
let offchain = OffchainWorkers::new(client);
runtime.executor().spawn(offchain.on_block_imported(&0u64, &pool));
// then
runtime.shutdown_on_idle().wait().unwrap();