fork tree: rebalance fork tree by max fork depth (#4605)

* fork-tree: rebalance fork tree by maximum branch height

* fork-tree: add docs for tree rebalancing

* fork-tree: add test

* babe: rebalance epoch changes tree on deserialization

* fork-tree: fix doc

* fork-tree: fix test
This commit is contained in:
André Silva
2020-01-13 07:51:48 +00:00
committed by Gavin Wood
parent 507909c3be
commit f1ef0a1bae
3 changed files with 81 additions and 6 deletions
@@ -185,6 +185,12 @@ impl<Hash, Number> EpochChanges<Hash, Number> where
EpochChanges { inner: ForkTree::new() }
}
/// Rebalances the tree of epoch changes so that it is sorted by length of
/// fork (longest fork first).
pub fn rebalance(&mut self) {
self.inner.rebalance()
}
/// Prune out finalized epochs, except for the ancestor of the finalized
/// block. The given slot should be the slot number at which the finalized
/// block was authored.