mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 14:58:03 +00:00
Move spawning tasks from thread pools to Service's TaskManager for block importing (#5647)
Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@ use names::{Generator, Name};
|
||||
use sc_service::config::{
|
||||
WasmExecutionMethod, Role, OffchainWorkerConfig,
|
||||
Configuration, DatabaseConfig, ExtTransport, KeystoreConfig, NetworkConfiguration,
|
||||
NodeKeyConfig, PrometheusConfig, PruningMode, TelemetryEndpoints, TransactionPoolOptions,
|
||||
NodeKeyConfig, PrometheusConfig, PruningMode, TelemetryEndpoints, TransactionPoolOptions, TaskType
|
||||
};
|
||||
use sc_client_api::execution_extensions::ExecutionStrategies;
|
||||
use sc_service::{ChainSpec, TracingReceiver};
|
||||
@@ -385,7 +385,7 @@ pub trait CliConfiguration: Sized {
|
||||
fn create_configuration<C: SubstrateCli>(
|
||||
&self,
|
||||
cli: &C,
|
||||
task_executor: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>,
|
||||
task_executor: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>, TaskType) + Send + Sync>,
|
||||
) -> Result<Configuration> {
|
||||
let is_dev = self.is_dev()?;
|
||||
let chain_id = self.chain_id(is_dev)?;
|
||||
|
||||
@@ -35,7 +35,7 @@ use log::info;
|
||||
pub use params::*;
|
||||
use regex::Regex;
|
||||
pub use runner::*;
|
||||
use sc_service::{ChainSpec, Configuration};
|
||||
use sc_service::{ChainSpec, Configuration, TaskType};
|
||||
use std::future::Future;
|
||||
use std::io::Write;
|
||||
use std::pin::Pin;
|
||||
@@ -177,7 +177,7 @@ pub trait SubstrateCli: Sized {
|
||||
fn create_configuration<T: CliConfiguration>(
|
||||
&self,
|
||||
command: &T,
|
||||
task_executor: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>,
|
||||
task_executor: Arc<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>, TaskType) + Send + Sync>,
|
||||
) -> error::Result<Configuration> {
|
||||
command.create_configuration(self, task_executor)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use futures::pin_mut;
|
||||
use futures::select;
|
||||
use futures::{future, future::FutureExt, Future};
|
||||
use log::info;
|
||||
use sc_service::{AbstractService, Configuration, Role, ServiceBuilderCommand};
|
||||
use sc_service::{AbstractService, Configuration, Role, ServiceBuilderCommand, TaskType};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
use sp_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL};
|
||||
use std::fmt::Debug;
|
||||
@@ -116,13 +116,22 @@ impl<C: SubstrateCli> Runner<C> {
|
||||
/// Create a new runtime with the command provided in argument
|
||||
pub fn new<T: CliConfiguration>(cli: &C, command: &T) -> Result<Runner<C>> {
|
||||
let tokio_runtime = build_runtime()?;
|
||||
let runtime_handle = tokio_runtime.handle().clone();
|
||||
|
||||
let task_executor = {
|
||||
let runtime_handle = tokio_runtime.handle().clone();
|
||||
Arc::new(move |fut| {
|
||||
runtime_handle.spawn(fut);
|
||||
})
|
||||
};
|
||||
let task_executor = Arc::new(
|
||||
move |fut, task_type| {
|
||||
match task_type {
|
||||
TaskType::Async => { runtime_handle.spawn(fut); }
|
||||
TaskType::Blocking => {
|
||||
runtime_handle.spawn( async move {
|
||||
// `spawn_blocking` is looking for the current runtime, and as such has to be called
|
||||
// from within `spawn`.
|
||||
tokio::task::spawn_blocking(move || futures::executor::block_on(fut))
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Ok(Runner {
|
||||
config: command.create_configuration(cli, task_executor)?,
|
||||
|
||||
Reference in New Issue
Block a user