mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 09:17:58 +00:00
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:
@@ -16,7 +16,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use futures::FutureExt;
|
||||
use sc_client_api::execution_extensions::ExecutionStrategies;
|
||||
use sc_executor::WasmExecutionMethod;
|
||||
use sc_informant::OutputFormat;
|
||||
@@ -26,7 +25,7 @@ use sc_network::{
|
||||
};
|
||||
use sc_service::{
|
||||
config::KeystoreConfig, BasePath, ChainSpec, Configuration, DatabaseSource, KeepBlocks,
|
||||
TaskExecutor, TaskType, TransactionStorageMode,
|
||||
TransactionStorageMode,
|
||||
};
|
||||
use sp_keyring::sr25519::Keyring::Alice;
|
||||
use tokio::runtime::Handle;
|
||||
@@ -43,10 +42,7 @@ pub fn base_path() -> BasePath {
|
||||
}
|
||||
|
||||
/// Produces a default configuration object, suitable for use with most set ups.
|
||||
pub fn default_config(
|
||||
task_executor: TaskExecutor,
|
||||
mut chain_spec: Box<dyn ChainSpec>,
|
||||
) -> Configuration {
|
||||
pub fn default_config(tokio_handle: Handle, mut chain_spec: Box<dyn ChainSpec>) -> Configuration {
|
||||
let base_path = base_path();
|
||||
let root_path = base_path.path().to_path_buf().join("chains").join(chain_spec.id());
|
||||
|
||||
@@ -75,7 +71,7 @@ pub fn default_config(
|
||||
impl_name: "test-node".to_string(),
|
||||
impl_version: "0.1".to_string(),
|
||||
role: Role::Authority,
|
||||
task_executor: task_executor.into(),
|
||||
tokio_handle,
|
||||
transaction_pool: Default::default(),
|
||||
network: network_config,
|
||||
keystore: KeystoreConfig::Path { path: root_path.join("key"), password: None },
|
||||
@@ -95,7 +91,6 @@ pub fn default_config(
|
||||
rpc_ws: None,
|
||||
rpc_ipc: None,
|
||||
rpc_ws_max_connections: None,
|
||||
rpc_http_threads: None,
|
||||
rpc_cors: None,
|
||||
rpc_methods: Default::default(),
|
||||
rpc_max_payload: None,
|
||||
@@ -120,14 +115,3 @@ pub fn default_config(
|
||||
transaction_storage: TransactionStorageMode::BlockBody,
|
||||
}
|
||||
}
|
||||
|
||||
/// Produce a task executor given a handle to a tokio runtime
|
||||
pub fn task_executor(handle: Handle) -> TaskExecutor {
|
||||
let task_executor = move |fut, task_type| match task_type {
|
||||
TaskType::Async => handle.spawn(fut).map(drop),
|
||||
TaskType::Blocking =>
|
||||
handle.spawn_blocking(move || futures::executor::block_on(fut)).map(drop),
|
||||
};
|
||||
|
||||
task_executor.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user