babe

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Copyright 2019 ChainSafe Systems (ON) Corp. This file is part of gossamer.

The gossamer library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The gossamer library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.

Copyright 2019 ChainSafe Systems (ON) Corp. This file is part of gossamer.

The gossamer library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The gossamer library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthorityAlreadyDisabled = errors.New("authority has already been disabled")

ErrAuthorityAlreadyDisabled is returned when attempting to disabled an already-disabled authority

View Source
var ErrAuthorityDisabled = errors.New("authority has been disabled for the remaining slots in the epoch")

ErrAuthorityDisabled is returned when attempting to verify a block produced by a disabled authority

View Source
var ErrBadSecondarySlotClaim = errors.New("invalid secondary slot claim")

ErrBadSecondarySlotClaim is returned when a slot claim is invalid

View Source
var ErrBadSignature = errors.New("could not verify signature")

ErrBadSignature is returned when a seal is invalid

View Source
var ErrBadSlotClaim = errors.New("could not verify slot claim VRF proof")

ErrBadSlotClaim is returned when a slot claim is invalid

View Source
var ErrInvalidBlockProducerIndex = errors.New("block producer is not in authority set")

ErrInvalidBlockProducerIndex is returned when the producer of a block isn't in the authority set

View Source
var ErrNilBlockState = errors.New("cannot have nil BlockState")

ErrNilBlockState is returned when the BlockState is nil

View Source
var ErrNilEpochState = errors.New("cannot have nil EpochState")

ErrNilEpochState is returned when the EpochState is nil

View Source
var ErrNoBABEHeader = errors.New("no BABE header found for block")

ErrNoBABEHeader is returned when there is no BABE header found for a block, specifically when calculating randomness

View Source
var ErrNotAuthority = errors.New("node is not an authority")

ErrNotAuthority is returned when trying to perform authority functions when not an authority

View Source
var ErrNotAuthorized = errors.New("not authorized to produce block")

ErrNotAuthorized is returned when the node is not authorized to produce a block

View Source
var ErrProducerEquivocated = errors.New("block producer equivocated")

ErrProducerEquivocated is returned when a block producer has produced conflicting blocks

View Source
var ErrVRFOutputOverThreshold = errors.New("vrf output over threshold")

ErrVRFOutputOverThreshold is returned when the vrf output for a block is invalid

Functions

func CalculateThreshold added in v0.2.0

func CalculateThreshold(C1, C2 uint64, numAuths int) (*common.Uint128, error)

CalculateThreshold calculates the slot lottery threshold equation: threshold = 2^128 * (1 - (1-c)^(1/len(authorities)) see https://github.com/paritytech/substrate/blob/master/client/consensus/babe/src/authorship.rs#L44

Types

type Authorities added in v0.3.0

type Authorities []*types.Authority

Authorities is an alias for []*types.Authority

func (Authorities) String added in v0.3.0

func (d Authorities) String() string

String returns the Authorities as a formatted string

type BlockState

type BlockState interface {
	BestBlockHash() common.Hash
	BestBlockHeader() (*types.Header, error)
	BestBlockNumber() (*big.Int, error)
	BestBlock() (*types.Block, error)
	SubChain(start, end common.Hash) ([]common.Hash, error)
	AddBlock(*types.Block) error
	GetAllBlocksAtDepth(hash common.Hash) []common.Hash
	GetHeader(common.Hash) (*types.Header, error)
	GetBlockByNumber(*big.Int) (*types.Block, error)
	GetBlockByHash(common.Hash) (*types.Block, error)
	GetArrivalTime(common.Hash) (time.Time, error)
	GenesisHash() common.Hash
	GetSlotForBlock(common.Hash) (uint64, error)
	GetFinalizedHeader(uint64, uint64) (*types.Header, error)
	IsDescendantOf(parent, child common.Hash) (bool, error)
}

BlockState interface for block state methods

type EpochState added in v0.2.0

type EpochState interface {
	SetCurrentEpoch(epoch uint64) error
	GetCurrentEpoch() (uint64, error)
	SetEpochData(uint64, *types.EpochData) error
	GetEpochData(epoch uint64) (*types.EpochData, error)
	HasEpochData(epoch uint64) (bool, error)
	GetConfigData(epoch uint64) (*types.ConfigData, error)
	HasConfigData(epoch uint64) (bool, error)
	GetStartSlotForEpoch(epoch uint64) (uint64, error)
	GetEpochForBlock(header *types.Header) (uint64, error)
	SetFirstSlot(slot uint64) error
	GetLatestEpochData() (*types.EpochData, error)
	SkipVerify(*types.Header) (bool, error)
}

EpochState is the interface for epoch methods

type Randomness added in v0.3.0

type Randomness = [types.RandomnessLength]byte

Randomness is an alias for a byte array with length types.RandomnessLength

type Service added in v0.2.0

type Service struct {
	// contains filtered or unexported fields
}

Service contains the VRF keys for the validator, as well as BABE configuation data

func NewService added in v0.2.0

func NewService(cfg *ServiceConfig) (*Service, error)

NewService returns a new Babe Service using the provided VRF keys and runtime

func (*Service) Authorities added in v0.2.0

func (b *Service) Authorities() []*types.Authority

Authorities returns the current BABE authorities

func (*Service) BuildBlock added in v0.2.0

func (b *Service) BuildBlock(parent *types.Header, slot Slot) (*types.Block, error)

BuildBlock builds a block for the slot with the given parent. TODO: separate block builder logic into separate module. The only reason this is exported is so other packages can build blocks for testing, but it would be preferred to have the builder functionality separated.

func (*Service) EpochLength added in v0.3.0

func (b *Service) EpochLength() uint64

EpochLength returns the current service epoch duration

func (*Service) GetBlockChannel added in v0.2.0

func (b *Service) GetBlockChannel() <-chan types.Block

GetBlockChannel returns the channel where new blocks are passed

func (*Service) IsPaused added in v0.2.0

func (b *Service) IsPaused() bool

IsPaused returns if the service is paused or not (ie. producing blocks)

func (*Service) IsStopped added in v0.2.0

func (b *Service) IsStopped() bool

IsStopped returns true if the service is stopped (ie not producing blocks)

func (*Service) Pause added in v0.2.0

func (b *Service) Pause() error

Pause pauses the service ie. halts block production

func (*Service) Resume added in v0.2.0

func (b *Service) Resume() error

Resume resumes the service ie. resumes block production

func (*Service) SetOnDisabled added in v0.3.0

func (b *Service) SetOnDisabled(authorityIndex uint32)

SetOnDisabled sets the block producer with the given index as disabled If this is our node, we stop producing blocks

func (*Service) SetRuntime added in v0.2.0

func (b *Service) SetRuntime(rt runtime.Instance)

SetRuntime sets the service's runtime

func (*Service) SlotDuration added in v0.3.0

func (b *Service) SlotDuration() uint64

SlotDuration returns the current service slot duration in milliseconds

func (*Service) Start added in v0.2.0

func (b *Service) Start() error

Start starts BABE block authoring

func (*Service) Stop added in v0.2.0

func (b *Service) Stop() error

Stop stops the service. If stop is called, it cannot be resumed.

type ServiceConfig added in v0.2.0

type ServiceConfig struct {
	LogLvl               log.Lvl
	BlockState           BlockState
	StorageState         StorageState
	TransactionState     TransactionState
	EpochState           EpochState
	Keypair              *sr25519.Keypair
	Runtime              runtime.Instance
	AuthData             []*types.Authority
	ThresholdNumerator   uint64 // for development purposes
	ThresholdDenominator uint64 // for development purposes
	SlotDuration         uint64 // for development purposes; in milliseconds
	EpochLength          uint64 // for development purposes; in slots
	Authority            bool
}

ServiceConfig represents a BABE configuration

type Slot

type Slot struct {
	// contains filtered or unexported fields
}

Slot represents a BABE slot

func NewSlot

func NewSlot(start time.Time, duration time.Duration, number uint64) *Slot

NewSlot returns a new Slot

type StorageState

type StorageState interface {
	TrieState(hash *common.Hash) (*rtstorage.TrieState, error)
	StoreTrie(ts *rtstorage.TrieState) error
}

StorageState interface for storage state methods

type TransactionState added in v0.2.0

type TransactionState interface {
	Push(vt *transaction.ValidTransaction) (common.Hash, error)
	Pop() *transaction.ValidTransaction
	Peek() *transaction.ValidTransaction
}

TransactionState is the interface for transaction queue methods

type VerificationManager

type VerificationManager struct {
	// contains filtered or unexported fields
}

VerificationManager deals with verification that a BABE block producer was authorized to produce a given block. It trakcs the BABE epoch data that is needed for verification.

func NewVerificationManager

func NewVerificationManager(blockState BlockState, epochState EpochState) (*VerificationManager, error)

NewVerificationManager returns a new NewVerificationManager

func (*VerificationManager) SetOnDisabled added in v0.3.0

func (v *VerificationManager) SetOnDisabled(index uint32, header *types.Header) error

SetOnDisabled sets the BABE authority with the given index as disabled for the rest of the epoch

func (*VerificationManager) VerifyBlock

func (v *VerificationManager) VerifyBlock(header *types.Header) error

VerifyBlock verifies that the block producer for the given block was authorized to produce it. It returns an error if the block is invalid.

type VrfOutputAndProof

type VrfOutputAndProof struct {
	// contains filtered or unexported fields
}

VrfOutputAndProof represents the fields for VRF output and proof

Jump to

Keyboard shortcuts

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