From 62a238a81ba3fc0de476b66c0a76c075441431f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Silva?= <andre.beat@gmail.com>
Date: Thu, 24 Oct 2019 09:14:32 +0100
Subject: [PATCH] node: spawn grandpa voter as essential task (#3899)

* node: spawn grandpa voter as essential task

* node: stop babe authoring task on exit

* node: remove unnecessary future boxing

* Apply suggestions from code review
---
 substrate/node-template/src/service.rs | 8 ++++----
 substrate/node/cli/src/service.rs      | 9 ++++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/substrate/node-template/src/service.rs b/substrate/node-template/src/service.rs
index 79343558124..c46928c10ef 100644
--- a/substrate/node-template/src/service.rs
+++ b/substrate/node-template/src/service.rs
@@ -115,11 +115,11 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
 			service.keystore(),
 		)?;
 
-		let select = aura.select(service.on_exit()).then(|_| Ok(()));
+		let aura = aura.select(service.on_exit()).then(|_| Ok(()));
 
 		// the AURA authoring task is considered essential, i.e. if it
 		// fails we take down the service with it.
-		service.spawn_essential_task(select);
+		service.spawn_essential_task(aura);
 	}
 
 	let grandpa_config = grandpa::Config {
@@ -133,12 +133,12 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
 	match (is_authority, disable_grandpa) {
 		(false, false) => {
 			// start the lightweight GRANDPA observer
-			service.spawn_task(Box::new(grandpa::run_grandpa_observer(
+			service.spawn_task(grandpa::run_grandpa_observer(
 				grandpa_config,
 				grandpa_link,
 				service.network(),
 				service.on_exit(),
-			)?));
+			)?);
 		},
 		(true, false) => {
 			// start the full GRANDPA voter
diff --git a/substrate/node/cli/src/service.rs b/substrate/node/cli/src/service.rs
index 983908c07da..0f4a098f3d0 100644
--- a/substrate/node/cli/src/service.rs
+++ b/substrate/node/cli/src/service.rs
@@ -175,6 +175,7 @@ macro_rules! new_full {
 				service.network(),
 				dht_event_rx,
 			);
+
 			service.spawn_task(authority_discovery);
 		}
 
@@ -189,12 +190,12 @@ macro_rules! new_full {
 		match (is_authority, disable_grandpa) {
 			(false, false) => {
 				// start the lightweight GRANDPA observer
-				service.spawn_task(Box::new(grandpa::run_grandpa_observer(
+				service.spawn_task(grandpa::run_grandpa_observer(
 					config,
 					grandpa_link,
 					service.network(),
 					service.on_exit(),
-				)?));
+				)?);
 			},
 			(true, false) => {
 				// start the full GRANDPA voter
@@ -207,7 +208,9 @@ macro_rules! new_full {
 					telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
 					voting_rule: grandpa::VotingRulesBuilder::default().build(),
 				};
-				service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
+				// the GRANDPA voter task is considered infallible, i.e.
+				// if it fails we take down the service with it.
+				service.spawn_essential_task(grandpa::run_grandpa_voter(grandpa_config)?);
 			},
 			(_, true) => {
 				grandpa::setup_disabled_grandpa(
-- 
GitLab