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.planConfigChangeType
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.reportEquivocationType
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.reportEquivocationUnsignedType
function reportEquivocationUnsigned(
equivocation_proof: SpConsensusSlotsEquivocationProof,
key_owner_proof: SpSessionMembershipProof
)Storage
authorities
Current epoch authorities.
Namespace
api.query.babe.authoritiesType
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.authorVrfRandomnessType
function authorVrfRandomness(
): Option<[u8;32]>currentSlot
Current slot number.
Namespace
api.query.babe.currentSlotType
function currentSlot(
): u64epochConfig
The configuration for the current epoch. Should never be None as it is initialized in genesis.
Namespace
api.query.babe.epochConfigType
function epochConfig(
): Option<SpConsensusBabeBabeEpochConfiguration>epochIndex
Current epoch index.
Namespace
api.query.babe.epochIndexType
function epochIndex(
): u64epochStart
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.epochStartType
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.genesisSlotType
function genesisSlot(
): u64initialized
Temporary value (cleared at block finalization) which is Some if per-block initialization has already been called for current block.
Namespace
api.query.babe.initializedType
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.latenessType
function lateness(
): u32nextAuthorities
Next epoch authorities.
Namespace
api.query.babe.nextAuthoritiesType
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.nextEpochConfigType
function nextEpochConfig(
): Option<SpConsensusBabeBabeEpochConfiguration>nextRandomness
Next epoch randomness.
Namespace
api.query.babe.nextRandomnessType
function nextRandomness(
): [u8;32]pendingEpochConfigChange
Pending epoch configuration change that will be applied when the next epoch is enacted.
Namespace
api.query.babe.pendingEpochConfigChangeType
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.randomnessType
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.segmentIndexType
function segmentIndex(
): u32underConstruction
TWOX-NOTE: SegmentIndex is an increasing integer, so this is okay.
Namespace
api.query.babe.underConstructionType
function underConstruction(
u32
): Vec<[u8;32]>undefined## Errors
DuplicateOffenceReport
A given equivocation report is valid but already previously reported.
Namespace
api.errors.babe.DuplicateOffenceReportInvalidConfiguration
Submitted configuration is invalid.
Namespace
api.errors.babe.InvalidConfigurationInvalidEquivocationProof
An equivocation proof provided as part of an equivocation report is invalid.
Namespace
api.errors.babe.InvalidEquivocationProofInvalidKeyOwnershipProof
A key ownership proof provided as part of an equivocation report is invalid.
Namespace
api.errors.babe.InvalidKeyOwnershipProofConstants
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.epochDurationType
type epochDuration = u64expectedBlockTime
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.expectedBlockTimeType
type expectedBlockTime = u64maxAuthorities
Max number of authorities allowed
Namespace
api.consts.babe.maxAuthoritiesType
type maxAuthorities = u32JSON-RPC Methods
epochAuthorship
Returns data about which slots (primary or secondary) can be claimed in the current epoch with the keys in the keystore.
Info: 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":[] }