babe

package
v0.0.2-rc-2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// The epoch has changed. This provides information about the _next_
	// epoch - information about the _current_ epoch (i.e. the one we've just
	// entered) should already be available earlier in the chain.
	NextEpochData sc.U8
	// Disable the authority with given index.
	OnDisabled
	// The epoch has changed, and the epoch after the current one will
	// enact different epoch configurations.
	NextConfigData
)

An consensus log item for BABE.

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 (
	// An equivocation proof provided as part of an equivocation report is invalid.
	ErrorInvalidEquivocationProof sc.U8 = iota
	// A key ownership proof provided as part of an equivocation report is invalid.
	ErrorInvalidKeyOwnershipProof
	// A given equivocation report is valid but already previously reported.
	ErrorDuplicateOffenceReport
	// Submitted configuration is invalid.
	ErrorInvalidConfiguration
)
View Source
const (
	SkippedEpochsBound                    = 100
	UnderConstructionSegmentLength sc.U32 = 256
)
View Source
const (
	NextConfigDescriptorV1 sc.U8 = 1
)

Variables

View Source
var (
	EngineId  = [4]byte{'B', 'A', 'B', 'E'}
	KeyTypeId = [4]byte{'b', 'a', 'b', 'e'}
)
View Source
var RandomnessVrfContext = []byte("BabeVRFInOutContext")

VRF context used for per-slot randomness generation.

Functions

func AppendUint64

func AppendUint64(t *merlin.Transcript, label []byte, n uint64)

AppendUint64 appends a uint64 to the given transcript using the given label

func NewDispatchErrorDuplicateOffenceReport

func NewDispatchErrorDuplicateOffenceReport(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorInvalidConfiguration

func NewDispatchErrorInvalidConfiguration(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorInvalidEquivocationProof

func NewDispatchErrorInvalidEquivocationProof(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorInvalidKeyOwnershipProof

func NewDispatchErrorInvalidKeyOwnershipProof(moduleId sc.U8) primitives.DispatchError

Types

type Config

type Config struct {
	KeyType            primitives.PublicKeyType
	EpochConfig        babetypes.EpochConfiguration
	EpochDuration      sc.U64
	EpochChangeTrigger EpochChangeTrigger
	SessionModule      session.Module
	MaxAuthorities     sc.U32
	MinimumPeriod      sc.U64
	SystemDigest       func() (primitives.Digest, error)
	SystemModule       system.Module
}

func NewConfig

func NewConfig(
	keyType primitives.PublicKeyType,
	epochConfig babetypes.EpochConfiguration,
	epochDuration sc.U64,
	epochChangeTrigger EpochChangeTrigger,
	sessionModule session.Module,
	maxAuthorities sc.U32,
	minimumPeriod sc.U64,
	systemDigest func() (primitives.Digest, error),
	systemModule system.Module,
) *Config

type ConsensusLog

type ConsensusLog struct {
	sc.VaryingData
}

func NewNextConfigDataConsensusLog

func NewNextConfigDataConsensusLog(nextConfigData NextConfigDescriptor) ConsensusLog

func NewNextEpochDataConsensusLog

func NewNextEpochDataConsensusLog(next NextEpochDescriptor) ConsensusLog

func NewOnDisabledConsensusLog

func NewOnDisabledConsensusLog(index babetypes.AuthorityIndex) ConsensusLog

type EpochChangeTrigger

type EpochChangeTrigger interface {
	Trigger(now sc.U64)
}

type ExternalTrigger

type ExternalTrigger struct{}

A type signifying to BABE that an external trigger for epoch changes (e.g. pallet-session) is used.

func (ExternalTrigger) Trigger

func (t ExternalTrigger) Trigger(_ sc.U64)

Trigger an epoch change, if any should take place. This should be called during every block, after initialization is done.

type GenesisConfig

type GenesisConfig struct {
	Authorities sc.Sequence[babetypes.Authority]
	EpochConfig babetypes.EpochConfiguration
}

func (*GenesisConfig) UnmarshalJSON

func (gc *GenesisConfig) UnmarshalJSON(data []byte) error

type Module

type Module interface {
	primitives.Module
	hooks.OnTimestampSet[sc.U64]
	session.OneSessionHandler

	StorageAuthorities() (sc.Sequence[babetypes.Authority], error)
	StorageRandomness() (babetypes.Randomness, error)
	StorageSegmentIndexSet(sc.U32)
	StorageEpochConfig() (babetypes.EpochConfiguration, error)
	StorageEpochConfigSet(value babetypes.EpochConfiguration)

	EnactEpochChange(authorities sc.Sequence[babetypes.Authority], nextAuthorities sc.Sequence[babetypes.Authority], sessionIndex sc.Option[sc.U32]) error
	ShouldEpochChange(now sc.U64) bool

	SlotDuration() sc.U64
	EpochDuration() sc.U64

	EpochConfig() babetypes.EpochConfiguration
	EpochStartSlot(epochIndex sc.U64, genesisSlot babetypes.Slot, epochDuration sc.U64) (babetypes.Slot, error)

	CurrentEpochStart() (babetypes.Slot, error)
	CurrentEpoch() (babetypes.Epoch, error)
	NextEpoch() (babetypes.Epoch, error)
}

func New

func New(index sc.U8, config *Config, mdGenerator *primitives.MetadataTypeGenerator, logger log.Logger) Module

type NextConfigDescriptor

type NextConfigDescriptor struct {
	V1 babetypes.EpochConfiguration
}

func DecodeNextConfigDescriptor

func DecodeNextConfigDescriptor(buffer *bytes.Buffer) (NextConfigDescriptor, error)

func (NextConfigDescriptor) Bytes

func (d NextConfigDescriptor) Bytes() []byte

func (NextConfigDescriptor) Encode

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

type NextEpochDescriptor

type NextEpochDescriptor struct {
	Authorities sc.Sequence[babetypes.Authority]
	// The value of randomness to use for the slot-assignment.
	Randomness babetypes.Randomness
}

Information about the next epoch. This is broadcast in the first block of the epoch.

func (NextEpochDescriptor) Bytes

func (d NextEpochDescriptor) Bytes() []byte

func (NextEpochDescriptor) Encode

func (d NextEpochDescriptor) 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 babetypes.AuthorityIndex, slot babetypes.Slot, vrfSignature types.VrfSignature) PreDigest

func NewSecondaryPlainPreDigest

func NewSecondaryPlainPreDigest(authorityIndex babetypes.AuthorityIndex, slot babetypes.Slot) PreDigest

func NewSecondaryVRFPreDigest

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

func (PreDigest) AuthorityIndex

func (d PreDigest) AuthorityIndex() (babetypes.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() (babetypes.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 babetypes.AuthorityIndex
	Slot           babetypes.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 SameAuthoritiesForever

type SameAuthoritiesForever struct {
	Babe Module
}

A type signifying to BABE that it should perform epoch changes with an internal trigger, recycling the same authorities forever.

func (SameAuthoritiesForever) Trigger

func (t SameAuthoritiesForever) Trigger(now sc.U64)

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 babetypes.AuthorityIndex
	Slot           babetypes.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 babetypes.AuthorityIndex
	Slot           babetypes.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

Jump to

Keyboard shortcuts

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