mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 04:27:57 +00:00
BABE's revert procedure (#11022)
* First rough draft for BABE revert * Proper babe revert test * Cleanup * Test trivial cleanup * Fix to make clippy happy * Check polkadot companion * Check cumulus companion * Remove babe's blocks weight on revert * Handle "empty" blockchain edge case * Run companions * Simplify the filter predicate * Saturating sub is not required * Run pipeline * Run pipeline again...
This commit is contained in:
@@ -24,7 +24,7 @@ use crate::{
|
||||
use clap::Parser;
|
||||
use sc_client_api::{Backend, UsageProvider};
|
||||
use sc_service::chain_ops::revert_chain;
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
|
||||
use std::{fmt::Debug, str::FromStr, sync::Arc};
|
||||
|
||||
/// The `revert` command used revert the chain to a previous state.
|
||||
@@ -43,9 +43,18 @@ pub struct RevertCmd {
|
||||
pub pruning_params: PruningParams,
|
||||
}
|
||||
|
||||
/// Revert handler for auxiliary data (e.g. consensus).
|
||||
type AuxRevertHandler<C, BA, B> =
|
||||
Box<dyn FnOnce(Arc<C>, Arc<BA>, NumberFor<B>) -> error::Result<()>>;
|
||||
|
||||
impl RevertCmd {
|
||||
/// Run the revert command
|
||||
pub async fn run<B, BA, C>(&self, client: Arc<C>, backend: Arc<BA>) -> error::Result<()>
|
||||
pub async fn run<B, BA, C>(
|
||||
&self,
|
||||
client: Arc<C>,
|
||||
backend: Arc<BA>,
|
||||
aux_revert: Option<AuxRevertHandler<C, BA, B>>,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
B: BlockT,
|
||||
BA: Backend<B>,
|
||||
@@ -53,6 +62,9 @@ impl RevertCmd {
|
||||
<<<B as BlockT>::Header as HeaderT>::Number as FromStr>::Err: Debug,
|
||||
{
|
||||
let blocks = self.num.parse()?;
|
||||
if let Some(aux_revert) = aux_revert {
|
||||
aux_revert(client.clone(), backend.clone(), blocks)?;
|
||||
}
|
||||
revert_chain(client, backend, blocks)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user