Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

grandpa: don't use block_on in Environment::report_equivocation #9154

Merged
3 commits merged into from
Jun 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions client/finality-grandpa/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down