mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-01 01:01:01 +00:00
Grandpa revert procedure (#11162)
* Grandpa revert procedure * Trigger ci pipeline * Test rename * Update client/finality-grandpa/src/authorities.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
use std::{cmp::Ord, fmt::Debug, ops::Add};
|
||||
|
||||
use finality_grandpa::voter_set::VoterSet;
|
||||
use fork_tree::ForkTree;
|
||||
use fork_tree::{FilterAction, ForkTree};
|
||||
use log::debug;
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use parking_lot::MappedMutexGuard;
|
||||
@@ -220,6 +220,37 @@ where
|
||||
pub(crate) fn current(&self) -> (u64, &[(AuthorityId, u64)]) {
|
||||
(self.set_id, &self.current_authorities[..])
|
||||
}
|
||||
|
||||
/// Revert to a specified block given its `hash` and `number`.
|
||||
/// This removes all the authority set changes that were announced after
|
||||
/// the revert point.
|
||||
/// Revert point is identified by `number` and `hash`.
|
||||
pub(crate) fn revert<F, E>(&mut self, hash: H, number: N, is_descendent_of: &F)
|
||||
where
|
||||
F: Fn(&H, &H) -> Result<bool, E>,
|
||||
{
|
||||
let mut filter = |node_hash: &H, node_num: &N, _: &PendingChange<H, N>| {
|
||||
if number >= *node_num &&
|
||||
(is_descendent_of(node_hash, &hash).unwrap_or_default() || *node_hash == hash)
|
||||
{
|
||||
// Continue the search in this subtree.
|
||||
FilterAction::KeepNode
|
||||
} else if number < *node_num && is_descendent_of(&hash, node_hash).unwrap_or_default() {
|
||||
// Found a node to be removed.
|
||||
FilterAction::Remove
|
||||
} else {
|
||||
// Not a parent or child of the one we're looking for, stop processing this branch.
|
||||
FilterAction::KeepTree
|
||||
}
|
||||
};
|
||||
|
||||
// Remove standard changes.
|
||||
let _ = self.pending_standard_changes.drain_filter(&mut filter);
|
||||
|
||||
// Remove forced changes.
|
||||
self.pending_forced_changes
|
||||
.retain(|change| !is_descendent_of(&hash, &change.canon_hash).unwrap_or_default());
|
||||
}
|
||||
}
|
||||
|
||||
impl<H: Eq, N> AuthoritySet<H, N>
|
||||
|
||||
Reference in New Issue
Block a user