referrerpolicy=no-referrer-when-downgrade

Crate sc_consensus_babe

Source
Expand description

§BABE (Blind Assignment for Blockchain Extension)

BABE is a slot-based block production mechanism which uses a VRF PRNG to randomly perform the slot allocation. On every slot, all the authorities generate a new random number with the VRF function and if it is lower than a given threshold (which is proportional to their weight/stake) they have a right to produce a block. The proof of the VRF function execution will be used by other peer to validate the legitimacy of the slot claim.

The engine is also responsible for collecting entropy on-chain which will be used to seed the given VRF PRNG. An epoch is a contiguous number of slots under which we will be using the same authority set. During an epoch all VRF outputs produced as a result of block production will be collected on an on-chain randomness pool. Epoch changes are announced one epoch in advance, i.e. when ending epoch N, we announce the parameters (randomness, authorities, etc.) for epoch N+2.

Since the slot assignment is randomized, it is possible that a slot is assigned to multiple validators in which case we will have a temporary fork, or that a slot is assigned to no validator in which case no block is produced. Which means that block times are not deterministic.

The protocol has a parameter c [0, 1] for which 1 - c is the probability of a slot being empty. The choice of this parameter affects the security of the protocol relating to maximum tolerable network delays.

In addition to the VRF-based slot assignment described above, which we will call primary slots, the engine also supports a deterministic secondary slot assignment. Primary slots take precedence over secondary slots, when authoring the node starts by trying to claim a primary slot and falls back to a secondary slot claim attempt. The secondary slot assignment is done by picking the authority at index:

blake2_256(epoch_randomness ++ slot_number) % authorities_len.

The secondary slots supports either a SecondaryPlain or SecondaryVRF variant. Comparing with SecondaryPlain variant, the SecondaryVRF variant generates an additional VRF output. The output is not included in beacon randomness, but can be consumed by parachains.

The fork choice rule is weight-based, where weight equals the number of primary blocks in the chain. We will pick the heaviest chain (more primary blocks) and will go with the longest one in case of a tie.

An in-depth description and analysis of the protocol can be found here: https://research.web3.foundation/Polkadot/protocols/block-production/Babe

Re-exports§

pub use aux_schema::load_block_weight as block_weight;

Modules§

authorship
BABE authority selection and slot claiming.
aux_schema
Schema for BABE epoch changes in the aux-db.

Structs§

BabeBlockImport
A block-import handler for BABE.
BabeConfiguration
Configuration data used by the BABE consensus engine.
BabeEpochConfiguration
Configuration data used by the BABE consensus engine that may change with epochs.
BabeIntermediate
Intermediate value passed to block importer.
BabeLink
State that must be shared between the import queue and the authoring logic.
BabeParams
Parameters for BABE.
BabeVerifier
A verifier for Babe blocks.
BabeWorker
Worker for Babe which implements Future<Output=()>. This must be polled.
BabeWorkerHandle
A handle to the BABE worker for issuing requests.
Epoch
BABE epoch information
ImportQueueParams
Parameters passed to import_queue.
NextEpochDescriptor
Information about the next epoch. This is broadcast in the first block of the epoch.
PrimaryPreDigest
Raw BABE primary slot assignment pre-digest.
SecondaryPlainPreDigest
BABE secondary slot assignment pre-digest.
SlotProportion
A unit type wrapper to express the proportion of a slot.

Enums§

ConsensusLog
An consensus log item for BABE.
Error
Errors encountered by the babe authorship task.
NextConfigDescriptor
Information about the next epoch config, if changed. This is broadcast in the first block of the epoch, and applies using the same rules as NextEpochDescriptor.
PreDigest
A BABE pre-runtime digest. This contains all data required to validate a block and for the BABE runtime module. Slots can be assigned to a primary (VRF based) and to a secondary (slot number based).

Constants§

BABE_ENGINE_ID
The ConsensusEngineId of BABE.

Statics§

INTERMEDIATE_KEY
Intermediate key for Babe engine.

Traits§

BabeApi
API necessary for block authorship with BABE.
CompatibleDigestItem
A digest item which is usable with BABE consensus.
SyncOracle
An oracle for when major synchronization work is being undertaken.

Functions§

block_import
Produce a BABE block-import object to be used later on in the construction of an import-queue.
configuration
Read configuration from the runtime state at current best block.
find_next_epoch_digest
Extract the BABE epoch change digest from the given header, if it exists.
find_pre_digest
Extract the BABE pre digest from the given header. Pre-runtime digests are mandatory, the function will return Err if none is found.
import_queue
Start an import queue for the BABE consensus algorithm.
revert
Reverts protocol aux data to at most the last finalized block. In particular, epoch-changes and block weights announced after the revert point are removed.
start_babe
Start the babe worker.

Type Aliases§

AuthorityId
A Babe authority identifier. Necessarily equivalent to the schnorrkel public key used in the main Babe module. If that ever changes, then this must, too.
AuthorityPair
A Babe authority keypair. Necessarily equivalent to the schnorrkel public key used in the main Babe module. If that ever changes, then this must, too.
AuthoritySignature
A Babe authority signature.
BabeAuthorityWeight
The weight of an authority.
BabeBlockWeight
The cumulative weight of a BABE block, i.e. sum of block weights starting at this block until the genesis block.
Randomness
Randomness type required by BABE operations.