Skip to main content

Babe

Calls

planConfigChange

Plan an epoch config change. The epoch config change is recorded and will be enacted on the next call to enact_epoch_change. The config will be activated one epoch after. Multiple calls to this method will replace any existing planned config change that had not been enacted yet.

Namespace

api.tx.babe.planConfigChange

Type

function planConfigChange(
  config: SpConsensusBabeDigestsNextConfigDescriptor
)

reportEquivocation

Report authority equivocation/misbehavior. This method will verify the equivocation proof and validate the given key ownership proof against the extracted offender. If both are valid, the offence will be reported.

Namespace

api.tx.babe.reportEquivocation

Type

function reportEquivocation(
  equivocation_proof: SpConsensusSlotsEquivocationProof,
  key_owner_proof: SpSessionMembershipProof
)

reportEquivocationUnsigned

Report authority equivocation/misbehavior. This method will verify the equivocation proof and validate the given key ownership proof against the extracted offender. If both are valid, the offence will be reported. This extrinsic must be called unsigned and it is expected that only block authors will call it (validated in ValidateUnsigned), as such if the block author is defined it will be defined as the equivocation reporter.

Namespace

api.tx.babe.reportEquivocationUnsigned

Type

function reportEquivocationUnsigned(
  equivocation_proof: SpConsensusSlotsEquivocationProof,
  key_owner_proof: SpSessionMembershipProof
)

Storage

authorities

Current epoch authorities.

Namespace

api.query.babe.authorities

Type

function authorities(

): Vec<(SpConsensusBabeAppPublic,u64)>

authorVrfRandomness

This field should always be populated during block processing unless secondary plain slots are enabled (which don't contain a VRF output).

It is set in on_finalize, before it will contain the value from the last block.

Namespace

api.query.babe.authorVrfRandomness

Type

function authorVrfRandomness(

): Option<[u8;32]>

currentSlot

Current slot number.

Namespace

api.query.babe.currentSlot

Type

function currentSlot(

): u64

epochConfig

The configuration for the current epoch. Should never be None as it is initialized in genesis.

Namespace

api.query.babe.epochConfig

Type

function epochConfig(

): Option<SpConsensusBabeBabeEpochConfiguration>

epochIndex

Current epoch index.

Namespace

api.query.babe.epochIndex

Type

function epochIndex(

): u64

epochStart

The block numbers when the last and current epoch have started, respectively N-1 and N. NOTE: We track this is in order to annotate the block number when a given pool of entropy was fixed (i.e. it was known to chain observers). Since epochs are defined in slots, which may be skipped, the block numbers may not line up with the slot numbers.

Namespace

api.query.babe.epochStart

Type

function epochStart(

): (u32,u32)

genesisSlot

The slot at which the first epoch actually started. This is 0 until the first block of the chain.

Namespace

api.query.babe.genesisSlot

Type

function genesisSlot(

): u64

initialized

Temporary value (cleared at block finalization) which is Some if per-block initialization has already been called for current block.

Namespace

api.query.babe.initialized

Type

function initialized(

): Option<Option<SpConsensusBabeDigestsPreDigest>>

lateness

How late the current block is compared to its parent.

This entry is populated as part of block execution and is cleaned up on block finalization. Querying this storage entry outside of block execution context should always yield zero.

Namespace

api.query.babe.lateness

Type

function lateness(

): u32

nextAuthorities

Next epoch authorities.

Namespace

api.query.babe.nextAuthorities

Type

function nextAuthorities(

): Vec<(SpConsensusBabeAppPublic,u64)>

nextEpochConfig

The configuration for the next epoch, None if the config will not change (you can fallback to EpochConfig instead in that case).

Namespace

api.query.babe.nextEpochConfig

Type

function nextEpochConfig(

): Option<SpConsensusBabeBabeEpochConfiguration>

nextRandomness

Next epoch randomness.

Namespace

api.query.babe.nextRandomness

Type

function nextRandomness(

): [u8;32]

pendingEpochConfigChange

Pending epoch configuration change that will be applied when the next epoch is enacted.

Namespace

api.query.babe.pendingEpochConfigChange

Type

function pendingEpochConfigChange(

): Option<SpConsensusBabeDigestsNextConfigDescriptor>

randomness

The epoch randomness for the current epoch.

Security

This MUST NOT be used for gambling, as it can be influenced by a malicious validator in the short term. It MAY be used in many cryptographic protocols, however, so long as one remembers that this (like everything else on-chain) it is public. For example, it can be used where a number is needed that cannot have been chosen by an adversary, for purposes such as public-coin zero-knowledge proofs.

Namespace

api.query.babe.randomness

Type

function randomness(

): [u8;32]

segmentIndex

Randomness under construction.

We make a trade-off between storage accesses and list length. We store the under-construction randomness in segments of up to UNDER_CONSTRUCTION_SEGMENT_LENGTH.

Once a segment reaches this length, we begin the next one. We reset all segments and return to 0 at the beginning of every epoch.

Namespace

api.query.babe.segmentIndex

Type

function segmentIndex(

): u32

underConstruction

TWOX-NOTE: SegmentIndex is an increasing integer, so this is okay.

Namespace

api.query.babe.underConstruction

Type

function underConstruction(
  u32
): Vec<[u8;32]>

undefined## Errors

DuplicateOffenceReport

A given equivocation report is valid but already previously reported.

Namespace

api.errors.babe.DuplicateOffenceReport

InvalidConfiguration

Submitted configuration is invalid.

Namespace

api.errors.babe.InvalidConfiguration

InvalidEquivocationProof

An equivocation proof provided as part of an equivocation report is invalid.

Namespace

api.errors.babe.InvalidEquivocationProof

InvalidKeyOwnershipProof

A key ownership proof provided as part of an equivocation report is invalid.

Namespace

api.errors.babe.InvalidKeyOwnershipProof

Constants

epochDuration

The amount of time, in slots, that each epoch should last. NOTE: Currently it is not possible to change the epoch duration after the chain has started. Attempting to do so will brick block production.

Namespace

api.consts.babe.epochDuration

Type

type epochDuration = u64

expectedBlockTime

The expected average block time at which BABE should be creating blocks. Since BABE is probabilistic it is not trivial to figure out what the expected average block time should be based on the slot duration and the security parameter c (where 1 - c represents the probability of a slot being empty).

Namespace

api.consts.babe.expectedBlockTime

Type

type expectedBlockTime = u64

maxAuthorities

Max number of authorities allowed

Namespace

api.consts.babe.maxAuthorities

Type

type maxAuthorities = u32

JSON-RPC Methods

epochAuthorship

Returns data about which slots (primary or secondary) can be claimed in the current epoch with the keys in the keystore

This method is only active with appropriate flags

Interface

api.rpc.babe.epochAuthorship(): HashMap<AuthorityId, EpochAuthorship>

JSON

{ "id":1, "jsonrpc":"2.0", "method":"babe_epochAuthorship", "params":[] }