Avail is a rollup infrastructure designed to provide scalable blockspace and data availability as a base layer for rollups. Being built on Polkadot SDK (Substrate) it also adopts some of the core parts of its consensus from substrate, namely BABE & GRANDPA.
Unlike alternatives like Tendermint Consensus which couple block production and finality together, Avail decouples consensus into 2 phases:
Block Production (BABE)
Finalization (GRANDPA)
In this post, we will cover what BABE is and we will dive into GRANDPA later.
BABE (Blind Assignment for Blockchain Extension) is a slot-based block production engine that can be used on its own as it gives probabilistic finality but is often coupled with a finality gadget like GRANDPA.
Let’s break down what that means, especially what it means to be “slot-based”.
In BABE, time is broken into epochs, which are further broken into slots (block time). BABE will select an author (or several) to author a block in each slot.
Instead of a round-robin to select a block author that could be vulnerable to coordinated attacks, BABE uses a VRF to randomly assign block authors and uses a round-robin as a fallback if no primary author is found for the slot.
Primary Slot Leader:
As mentioned, BABE uses a VRF to find the slot leader to author a block. VRFs generate a random number with proof that it was properly created. They input some params, including a private key. Each author computes its VRF for each slot in an epoch.
For each slot whose output is below some threshold, the validator has the right to author a block in that slot. Before you ask, yes…it’s possible to have slots WITHOUT a primary as well as slots WITH MULTIPLE primaries.
What happens if there is a slot with no primaries?
In case this happens, BABE falls back to a round-robin, which ensures there is always a secondary author for each slot.
What happens on the contrary? What if there are multiple primary authors? This will lead to forks on the chain. Which are common in BABE. This is where BABE’s fork choice rule comes into play. The rules are simple.
BABE must build on a chain that has been finalized by GRANDPA.
The best chain is the one with the most blocks authored by primaries.
This ensures BABE has probabilistic finality (and can hence work without GRANDPA too)
Forks are common in BABE. But since we have a finality gadget like GRANDPA, this system lets us produce blocks in an efficient way and lets GRANDPA deterministically finalize a set of them.