babe

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: LGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MaxThreshold is the maximum BABE threshold (node authorized to produce a block every slot)
	MaxThreshold = big.NewInt(0).SetBytes([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})
	// MinThreshold is the minimum BABE threshold (node never authorized to produce a block)
	MinThreshold = big.NewInt(0)
)
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")

ErrBadSlotClaim is returned when a slot claim is invalid

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

ErrNilBlockState is returned when the BlockState 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 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

Functions

func CalculateThreshold added in v0.2.0

func CalculateThreshold(C1, C2 uint64, numAuths int) (*big.Int, error)

CalculateThreshold calculates the slot lottery threshold equation: threshold = 2^128 * (1 - (1-c)^(1/len(authorities))

Types

type AuthorityData added in v0.2.0

type AuthorityData []*types.Authority

AuthorityData is an alias for []*types.Authority

func (AuthorityData) String added in v0.2.0

func (d AuthorityData) String() string

String returns the AuthorityData 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
	AddBlockWithArrivalTime(*types.Block, uint64) error
	GetHeader(common.Hash) (*types.Header, error)
	GetBlockByNumber(*big.Int) (*types.Block, error)
	GetBlockByHash(common.Hash) (*types.Block, error)
	GetArrivalTime(common.Hash) (uint64, error)
	GenesisHash() common.Hash
	GetSlotForBlock(common.Hash) (uint64, error)
	HighestBlockHash() common.Hash
	HighestBlockNumber() *big.Int
	GetFinalizedHeader(uint64, uint64) (*types.Header, error)
	IsDescendantOf(parent, child common.Hash) (bool, error)
}

BlockState interface for block state methods

type Descriptor added in v0.2.0

type Descriptor struct {
	AuthorityData []*types.Authority
	Randomness    [types.RandomnessLength]byte
	Threshold     *big.Int
}

Descriptor contains the information needed to verify blocks

type EpochState added in v0.2.0

type EpochState interface {
	SetCurrentEpoch(epoch uint64) error
	GetCurrentEpoch() (uint64, error)
	SetEpochInfo(epoch uint64, info *types.EpochInfo) error
	GetEpochInfo(epoch uint64) (*types.EpochInfo, error)
	HasEpochInfo(epoch uint64) (bool, error)
	GetStartSlotForEpoch(epoch uint64) (uint64, error)
}

EpochState is the interface for epoch methods

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) Descriptor added in v0.2.0

func (b *Service) Descriptor() *Descriptor

Descriptor returns the Descriptor for the current Service.

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) SetAuthorities added in v0.2.0

func (b *Service) SetAuthorities(data []*types.Authority) error

SetAuthorities sets the current Block Producer Authorities and sets Authority index

func (*Service) SetRandomness added in v0.2.0

func (b *Service) SetRandomness(a [types.RandomnessLength]byte)

SetRandomness sets randomness for BABE service Note that this only takes effect at the end of an epoch, where it is used to calculate the next epoch's randomness

func (*Service) SetRuntime added in v0.2.0

func (b *Service) SetRuntime(rt runtime.LegacyInstance) error

SetRuntime sets the service's runtime

func (*Service) SetThreshold added in v0.2.0

func (b *Service) SetThreshold(a *big.Int)

SetThreshold sets the threshold for a block producer

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.LegacyInstance
	AuthData         []*types.Authority
	Threshold        *big.Int // for development purposes
	SlotDuration     uint64   // for development purposes; in milliseconds
	StartSlot        uint64   // slot to start at
	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, duration, number uint64) *Slot

NewSlot returns a new Slot

type StorageState

type StorageState interface {
	TrieState(hash *common.Hash) (*state.TrieState, error)
	StoreTrie(root common.Hash, ts *state.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 assists the syncer in keeping track of what epoch is it currently syncing and verifying, as well as keeping track of the NextEpochDesciptor which is required to create a Verifier for an epoch.

func NewVerificationManager

func NewVerificationManager(blockState BlockState, descriptor *Descriptor) (*VerificationManager, error)

NewVerificationManager returns a new NewVerificationManager

func NewVerificationManagerFromRuntime added in v0.2.0

func NewVerificationManagerFromRuntime(blockState BlockState, rt runtime.LegacyInstance) (*VerificationManager, error)

NewVerificationManagerFromRuntime returns a new VerificationManager

func (*VerificationManager) SetAuthorityChangeAtBlock added in v0.2.0

func (v *VerificationManager) SetAuthorityChangeAtBlock(header *types.Header, authorities []*types.Authority)

SetAuthorityChangeAtBlock sets an authority change at the given block and all descendants of that block

func (*VerificationManager) SetRuntimeChangeAtBlock added in v0.2.0

func (v *VerificationManager) SetRuntimeChangeAtBlock(header *types.Header, rt runtime.LegacyInstance) error

SetRuntimeChangeAtBlock sets a runtime change at the given block Blocks that are descendants of this block will be verified using the given runtime

func (*VerificationManager) VerifyBlock

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

VerifyBlock verifies the given header with verifyAuthorshipRight.

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