From 5899eedc8c72611d17d5ec66deb3fa47cf222869 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Silva?=
 <123550+andresilva@users.noreply.github.com>
Date: Mon, 21 Jun 2021 17:02:08 +0100
Subject: [PATCH] grandpa: don't use block_on in
 Environment::report_equivocation (#9154)

* grandpa: don't use block_on in Environment::report_equivocation

* grandpa: add issue number to todo
---
 .../finality-grandpa/src/environment.rs       | 20 +++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/substrate/client/finality-grandpa/src/environment.rs b/substrate/client/finality-grandpa/src/environment.rs
index 77c7ccda7da..964e199f909 100644
--- a/substrate/client/finality-grandpa/src/environment.rs
+++ b/substrate/client/finality-grandpa/src/environment.rs
@@ -503,19 +503,19 @@ where
 
 		let is_descendent_of = is_descendent_of(&*self.client, None);
 
-		// TODO: add proper async support here
-		let best_header = futures::executor::block_on(
-			self.select_chain
-				.best_chain()
-				.map_err(|e| Error::Blockchain(e.to_string())),
-		)?;
+		let (best_block_hash, best_block_number) = {
+			// TODO [#9158]: Use SelectChain::best_chain() to get a potentially
+			// more accurate best block
+			let info = self.client.info();
+			(info.best_hash, info.best_number)
+		};
 
 		let authority_set = self.authority_set.inner();
 
 		// block hash and number of the next pending authority set change in the
 		// given best chain.
 		let next_change = authority_set
-			.next_change(&best_header.hash(), &is_descendent_of)
+			.next_change(&best_block_hash, &is_descendent_of)
 			.map_err(|e| Error::Safety(e.to_string()))?;
 
 		// find the hash of the latest block in the current set
@@ -528,7 +528,7 @@ where
 			// the next set starts at `n` so the current one lasts until `n - 1`. if
 			// `n` is later than the best block, then the current set is still live
 			// at best block.
-			Some((_, n)) if n > *best_header.number() => best_header.hash(),
+			Some((_, n)) if n > best_block_number => best_block_hash,
 			Some((h, _)) => {
 				// this is the header at which the new set will start
 				let header = self.client.header(BlockId::Hash(h))?.expect(
@@ -541,7 +541,7 @@ where
 			}
 			// there is no pending change, the latest block for the current set is
 			// the best block.
-			None => best_header.hash(),
+			None => best_block_hash,
 		};
 
 		// generate key ownership proof at that block
@@ -570,7 +570,7 @@ where
 		self.client
 			.runtime_api()
 			.submit_report_equivocation_unsigned_extrinsic(
-				&BlockId::Hash(best_header.hash()),
+				&BlockId::Hash(best_block_hash),
 				equivocation_proof,
 				key_owner_proof,
 			)
-- 
GitLab