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

Conversation

@andresilva
Copy link
Contributor

@andresilva andresilva commented Jan 12, 2020

BABE needs to keep track of the set of all epoch changes across all forks, only being able to prune those epoch changes as they are finalized, otherwise since it'd still be possible to re-org to the other forks we need to keep those nodes in the tree in order to be able to validate any blocks from those unfinalized forks. This tree can get potentially very large if finality is stalled (or lagging) and there is a high number of forks.

Most operations in the tree are performed with depth-first search starting from the leftmost node at every level. For our use-case a good heuristic is that the node we'll be looking for at any point will likely be in one of the deepest chains (i.e. the longest ones), therefore this PR introduces an optimization to rebalance the tree according to fork depth.

This implementation is very naive and simple, but given that searching for nodes in the tree incurs an expensive IO operation (to check block ancestry), the extra cost of traversing the tree multiple times to rebalance it is negligible compared to the gains.

In Kusama we experienced a high number of forks due to nodes going out of sync (caused by temporary 1s block times). Below are visualizations of the epoch changes tree before and after rebalancing. Rebalancing the tree made block import time go back to normal.

fork

fork-balance

@gavofyork gavofyork merged commit e8ba500 into master Jan 13, 2020
@gavofyork gavofyork deleted the andre/rebalance-fork-tree branch January 13, 2020 07:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants