Ensure we spawn the block import worker as an essential task (#8155)

* Ensure we spawn the block import worker as an essential task

This pr ensures that we spawn the block import worker as an essential
task. This is quite important as we need to bring down the node when the
block import is done. Besides that it adds some debug output to the
block import worker.

* Don't be stupid :D
This commit is contained in:
Bastian Köcher
2021-02-19 17:31:03 +01:00
committed by GitHub
parent 16a27c28a9
commit 821e018d75
10 changed files with 75 additions and 13 deletions
+10
View File
@@ -152,3 +152,13 @@ impl crate::traits::SpawnNamed for TaskExecutor {
self.0.spawn_ok(future);
}
}
#[cfg(feature = "std")]
impl crate::traits::SpawnEssentialNamed for TaskExecutor {
fn spawn_essential_blocking(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
self.0.spawn_ok(future);
}
fn spawn_essential(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
self.0.spawn_ok(future);
}
}
+26 -1
View File
@@ -205,7 +205,7 @@ sp_externalities::decl_extension! {
pub struct RuntimeSpawnExt(Box<dyn RuntimeSpawn>);
}
/// Something that can spawn futures (blocking and non-blocking) with an assigned name.
/// Something that can spawn tasks (blocking and non-blocking) with an assigned name.
#[dyn_clonable::clonable]
pub trait SpawnNamed: Clone + Send + Sync {
/// Spawn the given blocking future.
@@ -227,3 +227,28 @@ impl SpawnNamed for Box<dyn SpawnNamed> {
(**self).spawn(name, future)
}
}
/// Something that can spawn essential tasks (blocking and non-blocking) with an assigned name.
///
/// Essential tasks are special tasks that should take down the node when they end.
#[dyn_clonable::clonable]
pub trait SpawnEssentialNamed: Clone + Send + Sync {
/// Spawn the given blocking future.
///
/// The given `name` is used to identify the future in tracing.
fn spawn_essential_blocking(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>);
/// Spawn the given non-blocking future.
///
/// The given `name` is used to identify the future in tracing.
fn spawn_essential(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>);
}
impl SpawnEssentialNamed for Box<dyn SpawnEssentialNamed> {
fn spawn_essential_blocking(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>) {
(**self).spawn_essential_blocking(name, future)
}
fn spawn_essential(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>) {
(**self).spawn_essential(name, future)
}
}