Use tokio runtime handle instead of TaskExecutor abstraction (#9737)

* Use tokio runtime handle instead of TaskExecutor abstraction

Before this pr we had the `TaskExecutor` abstraction which theoretically
allowed that any futures executor could have been used. However, this
was never tested and is currently not really required. Anyone running a
node currently only used tokio and nothing else (because this was hard
coded in CLI). So, this pr removes the `TaskExecutor` abstraction and
relies directly on the tokio runtime handle.

Besides this changes, this pr also makes sure that the http and ws rpc
server use the same tokio runtime. This fixes a panic that occurred when
you drop the rpc servers inside an async function (tokio doesn't like
that a tokio runtime is dropped in the async context of another tokio
runtime).

As we don't use any custom runtime in the http rpc server anymore, this
pr also removes the `rpc-http-threads` cli argument. If external parties
complain that there aren't enough threads for the rpc server, we could
bring support for increasing the thread count of the tokio runtime.

* FMT

* Fix try runtime

* Fix integration tests and some other optimizations

* Remove warnings
This commit is contained in:
Bastian Köcher
2021-09-12 14:29:11 +02:00
committed by GitHub
parent be69e4d2b2
commit c09d52ead7
31 changed files with 197 additions and 302 deletions
@@ -1,24 +0,0 @@
// This file is part of Substrate.
// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#[substrate_test_utils::test]
async fn missing_func_parameter() {
assert!(true);
}
fn main() {}
@@ -1,5 +0,0 @@
error: the test function accepts only one argument of type sc_service::TaskExecutor
--> $DIR/missing-func-parameter.rs:20:1
|
20 | async fn missing_func_parameter() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,11 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#[allow(unused_imports)]
use sc_service::TaskExecutor;
#[substrate_test_utils::test]
async fn too_many_func_parameters(task_executor_1: TaskExecutor, task_executor_2: TaskExecutor) {
async fn too_many_func_parameters(_: u32) {
assert!(true);
}
@@ -1,5 +1,5 @@
error: the test function accepts only one argument of type sc_service::TaskExecutor
--> $DIR/too-many-func-parameters.rs:23:1
error: No arguments expected for tests.
--> $DIR/too-many-func-parameters.rs:20:1
|
23 | async fn too_many_func_parameters(task_executor_1: TaskExecutor, task_executor_2: TaskExecutor) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20 | async fn too_many_func_parameters(_: u32) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^