babe

package
v0.0.0-...-c69f244 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadSlotClaim is returned when a slot claim is invalid
	ErrBadSlotClaim = errors.New("could not verify slot claim VRF proof")

	// ErrBadSecondarySlotClaim is returned when a slot claim is invalid
	ErrBadSecondarySlotClaim = errors.New("invalid secondary slot claim")

	// ErrBadSignature is returned when a seal is invalid
	ErrBadSignature = errors.New("could not verify signature")

	// ErrProducerEquivocated is returned when a block producer has produced conflicting blocks
	ErrProducerEquivocated = errors.New("block producer equivocated")

	// ErrNotAuthorized is returned when the node is not authorized to produce a block
	ErrNotAuthorized = errors.New("not authorized to produce block")

	// ErrNoBABEHeader is returned when there is no BABE header found for a block, specifically when calculating randomness
	ErrNoBABEHeader = errors.New("no BABE header found for block")

	// ErrVRFOutputOverThreshold is returned when the vrf output for a block is invalid
	ErrVRFOutputOverThreshold = errors.New("vrf output over threshold")

	// ErrInvalidBlockProducerIndex is returned when the producer of a block isn't in the authority set
	ErrInvalidBlockProducerIndex = errors.New("block producer is not in authority set")

	// ErrAuthorityAlreadyDisabled is returned when attempting to disabled an already-disabled authority
	ErrAuthorityAlreadyDisabled = errors.New("authority has already been disabled")

	// ErrAuthorityDisabled is returned when attempting to verify a block produced by a disabled authority
	ErrAuthorityDisabled = errors.New("authority has been disabled for the remaining slots in the epoch")

	// ErrNotAuthority is returned when trying to perform authority functions when not an authority
	ErrNotAuthority = errors.New("node is not an authority")

	// ErrThresholdOneIsZero is returned when one of or both parameters to CalculateThreshold is zero
	ErrThresholdOneIsZero = errors.New("numerator or denominator cannot be 0")

	ErrNilBlockState       = errors.New("cannot have nil BlockState")
	ErrNilTransactionState = errors.New("cannot create block builder; transaction state is nil")
	ErrNilVRFProof         = errors.New("cannot create block builder; slot VRF proof is nil")
)

Functions

func CalculateThreshold

func CalculateThreshold(C1, C2 uint64, numAuths int) (*scale.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 AncientBirthBlock

type AncientBirthBlock struct{}

AncientBirthBlock The transaction birth block is ancient

func (AncientBirthBlock) Index

func (err AncientBirthBlock) Index() uint

Index Returns VDT index

type Authorities

type Authorities []types.Authority

Authorities is an alias for []*types.Authority

func (Authorities) String

func (d Authorities) String() string

String returns the Authorities as a formatted string

type BadMandatory

type BadMandatory struct{}

BadMandatory An extrinsic with a Mandatory dispatch resulted in Error

func (BadMandatory) Index

func (err BadMandatory) Index() uint

Index Returns VDT index

type BadOrigin

type BadOrigin struct{}

BadOrigin A bad origin

func (BadOrigin) Index

func (err BadOrigin) Index() uint

Index Returns VDT index

type BadProof

type BadProof struct{}

BadProof General error to do with the transaction’s proofs (e.g. signature)

func (BadProof) Index

func (err BadProof) Index() uint

Index Returns VDT index

type BlockBuilder

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

BlockBuilder builds blocks.

func NewBlockBuilder

func NewBlockBuilder(
	kp *sr25519.Keypair,
	ts TransactionState,
	bs BlockState,
	authidx uint32,
	preRuntimeDigest *types.PreRuntimeDigest,
) (*BlockBuilder, error)

NewBlockBuilder creates a new block builder.

type BlockImportHandler

type BlockImportHandler interface {
	HandleBlockProduced(block *types.Block, state *rtstorage.TrieState) error
}

BlockImportHandler is the interface for the handler of new blocks

type BlockState

type BlockState interface {
	BestBlockHash() common.Hash
	BestBlockHeader() (*types.Header, error)
	BestBlockNumber() (blockNumber uint, err 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(blockNumber uint) (*types.Block, error)
	GetBlockByHash(common.Hash) (*types.Block, error)
	GetArrivalTime(common.Hash) (time.Time, error)
	GenesisHash() common.Hash
	GetSlotForBlock(common.Hash) (uint64, error)
	GetFinalisedHeader(uint64, uint64) (*types.Header, error)
	IsDescendantOf(parent, child common.Hash) (bool, error)
	NumberIsFinalised(blockNumber uint) (bool, error)
	GetRuntime(*common.Hash) (runtime.Instance, error)
	StoreRuntime(common.Hash, runtime.Instance)
	ImportedBlockNotifierManager
}

BlockState interface for block state methods

type Builder

type Builder struct{}

Builder struct to hold babe builder functions

func (Builder) NewServiceIFace

func (Builder) NewServiceIFace(cfg *ServiceConfig) (ServiceIFace, error)

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

type Call

type Call struct{}

Call The call of the transaction is not expected

func (Call) Index

func (err Call) Index() uint

Index Returns VDT index

type CannotLookup

type CannotLookup struct{}

CannotLookup Failed to lookup some data

func (CannotLookup) Index

func (err CannotLookup) Index() uint

Index Returns VDT index

type DigestHandler

type DigestHandler interface {
	HandleDigests(*types.Header)
}

DigestHandler is the interface for the consensus digest handler

type DispatchOutcomeError

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

A DispatchOutcomeError is outcome of dispatching the extrinsic

func (DispatchOutcomeError) Error

func (e DispatchOutcomeError) Error() string

type EpochState

type EpochState interface {
	GetEpochLength() (uint64, error)
	GetSlotDuration() (time.Duration, error)
	SetCurrentEpoch(epoch uint64) error
	GetCurrentEpoch() (uint64, error)
	SetEpochData(uint64, *types.EpochData) error

	HasEpochData(epoch uint64) (bool, error)

	GetEpochData(epoch uint64, header *types.Header) (*types.EpochData, error)
	GetConfigData(epoch uint64, header *types.Header) (*types.ConfigData, error)

	HasConfigData(epoch uint64) (bool, error)
	GetLatestConfigData() (*types.ConfigData, 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)
	GetEpochFromTime(time.Time) (uint64, error)
}

EpochState is the interface for epoch methods

type ExhaustsResources

type ExhaustsResources struct{}

ExhaustsResources The transaction would exhaust the resources of current block

func (ExhaustsResources) Index

func (err ExhaustsResources) Index() uint

Index Returns VDT index

type Future

type Future struct{}

Future General error to do with the transaction not yet being valid (e.g. nonce too high)

func (Future) Index

func (err Future) Index() uint

Index Returns VDT index

type ImportedBlockNotifierManager

type ImportedBlockNotifierManager interface {
	GetImportedBlockNotifierChannel() chan *types.Block
	FreeImportedBlockNotifierChannel(ch chan *types.Block)
}

ImportedBlockNotifierManager is the interface for block notification channels

type InvalidCustom

type InvalidCustom uint8

InvalidCustom Any other custom invalid validity that is not covered

func (InvalidCustom) Index

func (err InvalidCustom) Index() uint

Index Returns VDT index

type MandatoryDispatch

type MandatoryDispatch struct{}

MandatoryDispatch A transaction with a mandatory dispatch

func (MandatoryDispatch) Index

func (err MandatoryDispatch) Index() uint

Index Returns VDT index

type Module

type Module struct {
	Idx     uint8
	Err     uint8
	Message *string
}

Module A custom error in a module

func (Module) Index

func (err Module) Index() uint

Index Returns VDT index

type NoUnsignedValidator

type NoUnsignedValidator struct{}

NoUnsignedValidator No validator found for the given unsigned transaction

func (NoUnsignedValidator) Index

func (err NoUnsignedValidator) Index() uint

Index Returns VDT index

type Other

type Other string

Other Some error occurred

func (Other) Index

func (err Other) Index() uint

Index Returns VDT index

type Payment

type Payment struct{}

Payment General error to do with the inability to pay some fees (e.g. account balance too low)

func (Payment) Index

func (err Payment) Index() uint

Index Returns VDT index

type Randomness

type Randomness = [types.RandomnessLength]byte

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

type Service

type Service struct {

	// State variables
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func NewService

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

NewService function to create babe service

func (*Service) Authorities

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

Authorities returns the current BABE authorities

func (*Service) EpochLength

func (b *Service) EpochLength() uint64

EpochLength returns the current service epoch duration

func (*Service) IsPaused

func (b *Service) IsPaused() bool

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

func (*Service) IsStopped

func (b *Service) IsStopped() bool

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

func (*Service) Pause

func (b *Service) Pause() error

Pause pauses the service ie. halts block production

func (*Service) Resume

func (b *Service) Resume() error

Resume resumes the service ie. resumes block production

func (*Service) SlotDuration

func (b *Service) SlotDuration() uint64

SlotDuration returns the current service slot duration in milliseconds

func (*Service) Start

func (b *Service) Start() error

Start starts BABE block authoring

func (*Service) Stop

func (b *Service) Stop() error

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

type ServiceConfig

type ServiceConfig struct {
	LogLvl             log.Level
	BlockState         BlockState
	StorageState       StorageState
	TransactionState   TransactionState
	EpochState         EpochState
	BlockImportHandler BlockImportHandler
	Keypair            *sr25519.Keypair
	AuthData           []types.Authority
	IsDev              bool
	Authority          bool
	Lead               bool
	Telemetry          telemetry.Client
}

ServiceConfig represents a BABE configuration

func (*ServiceConfig) Validate

func (sc *ServiceConfig) Validate() error

Validate returns error if config does not contain required attributes

type ServiceIFace

type ServiceIFace interface {
	Start() error
	Stop() error
	EpochLength() uint64
	Pause() error
	IsPaused() bool
	Resume() error
	SlotDuration() uint64
}

ServiceIFace interface that defines methods available to BabeService

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

func (Slot) String

func (s Slot) String() string

type Stale

type Stale struct{}

Stale General error to do with the transaction being outdated (e.g. nonce too low)

func (Stale) Index

func (err Stale) Index() uint

Index Returns VDT index

type StorageState

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

StorageState interface for storage state methods

type TransactionState

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 TransactionValidityError

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

A TransactionValidityError is possible errors while checking the validity of a transaction

func (TransactionValidityError) Error

func (e TransactionValidityError) Error() string

type UnknownCustom

type UnknownCustom uint8

UnknownCustom Any other custom unknown validity that is not covered

func (UnknownCustom) Index

func (err UnknownCustom) Index() uint

Index Returns VDT index

type UnmarshalError

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

UnmarshalError occurs when unmarshalling fails

func (UnmarshalError) Error

func (e UnmarshalError) Error() string

type ValidityCannotLookup

type ValidityCannotLookup struct{}

ValidityCannotLookup Could not lookup some information that is required to validate the transaction

func (ValidityCannotLookup) Index

func (err ValidityCannotLookup) Index() uint

Index Returns VDT index

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

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 checks the next epoch and config data stored in memory only if it cannot retrieve the data from database 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