babe

package
v0.0.3-rc-1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Only allow primary slots.
	PrimarySlots sc.U8 = iota
	// Allow primary and secondary plain slots.
	PrimaryAndSecondaryPlainSlots
	// Allow primary and secondary VRF slots.
	PrimaryAndSecondaryVRFSlots
)

Types of allowed slots.

View Source
const (

	// A primary VRF-based slot assignment.
	Primary sc.U8
	// A secondary deterministic slot assignment.
	SecondaryPlain
	// A secondary deterministic slot assignment with VRF outputs.
	SecondaryVRF
)

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).

View Source
const RandomnessLength = 32

VRF output length for per-slot randomness.

Variables

View Source
var (
	ErrInvalidAllowedSlots = errors.New("invalid 'AllowedSlots' type")
)

Functions

This section is empty.

Types

type AllowedSlots

type AllowedSlots struct {
	sc.VaryingData
}

func DecodeAllowedSlots

func DecodeAllowedSlots(buffer *bytes.Buffer) (AllowedSlots, error)

func NewPrimaryAndSecondaryPlainSlots

func NewPrimaryAndSecondaryPlainSlots() AllowedSlots

func NewPrimaryAndSecondaryVRFSlots

func NewPrimaryAndSecondaryVRFSlots() AllowedSlots

func NewPrimarySlots

func NewPrimarySlots() AllowedSlots

func (AllowedSlots) String

func (a AllowedSlots) String() string

type AuthorityIndex

type AuthorityIndex = sc.U32

type Configuration

type Configuration struct {
	// The slot duration in milliseconds for BABE. Currently, only
	// the value provided by this type at genesis will be used.
	//
	// Dynamic slot duration may be supported in the future.
	SlotDuration sc.U64

	// The duration of epochs in slots.
	EpochLength sc.U64

	// A constant value that is used in the threshold calculation formula.
	// In the threshold formula calculation, `1 - c` represents the probability
	// of a slot being empty.
	C primitives.Tuple2U64

	// The authorities
	Authorities sc.Sequence[primitives.Authority]

	// The randomness
	Randomness Randomness

	// Type of allowed slots.
	AllowedSlots AllowedSlots
}

Configuration data used by the BABE consensus engine.

func DecodeConfiguration

func DecodeConfiguration(buffer *bytes.Buffer) (Configuration, error)

func (Configuration) Bytes

func (c Configuration) Bytes() []byte

func (Configuration) Encode

func (c Configuration) Encode(buffer *bytes.Buffer) error

type Epoch

type Epoch struct {
	// The epoch index.
	EpochIndex sc.U64
	// The starting slot of the epoch.
	StartSlot Slot
	// The duration of this epoch.
	Duration sc.U64
	// The authorities and their weights.
	Authorities sc.Sequence[primitives.Authority]
	// Randomness for this epoch.
	Randomness Randomness
	// Configuration of the epoch.
	Config EpochConfiguration
}

BABE epoch information

func DecodeEpoch

func DecodeEpoch(buffer *bytes.Buffer) (Epoch, error)

func (Epoch) Bytes

func (e Epoch) Bytes() []byte

func (Epoch) Encode

func (e Epoch) Encode(buffer *bytes.Buffer) error

type EpochConfiguration

type EpochConfiguration struct {
	// A constant value that is used in the threshold calculation formula.
	// In the threshold formula calculation, `1 - c` represents the probability
	// of a slot being empty.
	C primitives.Tuple2U64

	// Whether this chain should run with secondary slots, which are assigned
	// in round-robin manner.
	AllowedSlots AllowedSlots
}

Configuration data used by the BABE consensus engine that may change with epochs.

func DecodeEpochConfiguration

func DecodeEpochConfiguration(buffer *bytes.Buffer) (EpochConfiguration, error)

func (EpochConfiguration) Bytes

func (c EpochConfiguration) Bytes() []byte

func (EpochConfiguration) Encode

func (c EpochConfiguration) Encode(buffer *bytes.Buffer) error

type EpochStartBlocks

type EpochStartBlocks struct {
	Previous sc.U64
	Current  sc.U64
}

func DecodeEpochStartBlocks

func DecodeEpochStartBlocks(buffer *bytes.Buffer) (EpochStartBlocks, error)

func (EpochStartBlocks) Bytes

func (e EpochStartBlocks) Bytes() []byte

func (EpochStartBlocks) Encode

func (e EpochStartBlocks) Encode(buffer *bytes.Buffer) error

type PreDigest

type PreDigest struct {
	sc.VaryingData
}

func DecodePreDigest

func DecodePreDigest(buffer *bytes.Buffer) (PreDigest, error)

func NewPrimaryPreDigest

func NewPrimaryPreDigest(authorityIndex AuthorityIndex, slot Slot, vrfSignature types.VrfSignature) PreDigest

func NewSecondaryPlainPreDigest

func NewSecondaryPlainPreDigest(authorityIndex AuthorityIndex, slot Slot) PreDigest

func NewSecondaryVRFPreDigest

func NewSecondaryVRFPreDigest(authorityIndex AuthorityIndex, slot Slot, vrfSignature types.VrfSignature) PreDigest

func (PreDigest) AuthorityIndex

func (d PreDigest) AuthorityIndex() (AuthorityIndex, error)

Returns the slot number of the pre digest.

func (PreDigest) IsPrimary

func (d PreDigest) IsPrimary() bool

Returns true if this pre-digest is for a primary slot assignment.

func (PreDigest) Slot

func (d PreDigest) Slot() (Slot, error)

Returns the slot of the pre digest.

func (PreDigest) VrfSignature

func (d PreDigest) VrfSignature() (sc.Option[types.VrfSignature], error)

Returns the VRF output and proof, if they exist.

type PrimaryPreDigest

type PrimaryPreDigest struct {
	AuthorityIndex AuthorityIndex
	Slot           Slot
	VrfSignature   types.VrfSignature
}

Raw BABE primary slot assignment pre-digest.

func DecodePrimaryPreDigest

func DecodePrimaryPreDigest(buffer *bytes.Buffer) (PrimaryPreDigest, error)

func (PrimaryPreDigest) Bytes

func (d PrimaryPreDigest) Bytes() []byte

func (PrimaryPreDigest) Encode

func (d PrimaryPreDigest) Encode(buffer *bytes.Buffer) error

type Randomness

type Randomness = sc.FixedSequence[sc.U8]

Randomness type required by BABE operations.

func NewRandomness

func NewRandomness() Randomness

type SecondaryPlainPreDigest

type SecondaryPlainPreDigest struct {
	// This is not strictly-speaking necessary, since the secondary slots
	// are assigned based on slot number and epoch randomness. But including
	// it makes things easier for higher-level users of the chain data to
	// be aware of the author of a secondary-slot block.
	AuthorityIndex AuthorityIndex
	Slot           Slot
}

BABE secondary slot assignment pre-digest.

func DecodeSecondaryPlainPreDigest

func DecodeSecondaryPlainPreDigest(buffer *bytes.Buffer) (SecondaryPlainPreDigest, error)

func (SecondaryPlainPreDigest) Bytes

func (d SecondaryPlainPreDigest) Bytes() []byte

func (SecondaryPlainPreDigest) Encode

func (d SecondaryPlainPreDigest) Encode(buffer *bytes.Buffer) error

type SecondaryVRFPreDigest

type SecondaryVRFPreDigest struct {
	AuthorityIndex AuthorityIndex
	Slot           Slot
	VrfSignature   types.VrfSignature
}

BABE secondary deterministic slot assignment with VRF outputs.

func DecodeSecondaryVRFPreDigest

func DecodeSecondaryVRFPreDigest(buffer *bytes.Buffer) (SecondaryVRFPreDigest, error)

func (SecondaryVRFPreDigest) Bytes

func (d SecondaryVRFPreDigest) Bytes() []byte

func (SecondaryVRFPreDigest) Encode

func (d SecondaryVRFPreDigest) Encode(buffer *bytes.Buffer) error

type SessionIndex

type SessionIndex = sc.U32

type SkippedEpoch

type SkippedEpoch struct {
	sc.U64
	SessionIndex
}

func (SkippedEpoch) Bytes

func (se SkippedEpoch) Bytes() []byte

func (SkippedEpoch) Encode

func (se SkippedEpoch) Encode(buffer *bytes.Buffer) error

type Slot

type Slot = sc.U64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL