More robust grandpa revert procedure (#11719)

* More robust revert procedure

Return an error if revert is called in a node that is not actively
running grandpa, i.e. grandpa genesis data has not been initialized.
Previous implementation was just firing an `unreachable!` code exception.

Furthermore we skip revert hassle if there is nothing to revert.

* Nit
This commit is contained in:
Davide Galassi
2022-06-21 11:50:51 +02:00
committed by GitHub
parent 939c31bfde
commit c189bd15de
2 changed files with 14 additions and 2 deletions
@@ -1873,7 +1873,11 @@ where
{
let best_number = client.info().best_number;
let finalized = client.info().finalized_number;
let revertible = blocks.min(best_number - finalized);
if revertible == Zero::zero() {
return Ok(())
}
let revert_up_to_number = best_number - revertible;
let revert_up_to_hash = client.hash(revert_up_to_number)?.ok_or(ClientError::Backend(