babe

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const RandomnessLength = 32

RandomnessLength is the length of the epoch randomness (32 bytes)

Variables

View Source
var (
	Timstap0 = []byte("timstap0")
	Babeslot = []byte("babeslot")
)

nolint

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 ErrNilNextEpochDescriptor = errors.New("nil NextEpochDescriptor for epoch")

ErrNilNextEpochDescriptor is returned when attempting to get a NextEpochDescriptor that isn't set for an epoch

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

ErrProducerEquivocated is returned when a block producer has produced conflicting blocks

Functions

This section is empty.

Types

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
}

BlockState interface for block state methods

type InherentsData

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

InherentsData contains a mapping of inherent keys to values keys must be 8 bytes, values are a variable-length byte array

func NewInherentsData

func NewInherentsData() *InherentsData

NewInherentsData returns InherentsData

func (*InherentsData) Encode

func (d *InherentsData) Encode() ([]byte, error)

Encode will encode a given []byte using scale.Encode

func (*InherentsData) SetInt64Inherent

func (d *InherentsData) SetInt64Inherent(key []byte, data uint64) error

SetInt64Inherent set the Int64 scale.Encode for a given data

type NextEpochDescriptor

type NextEpochDescriptor struct {
	Authorities []*types.AuthorityData
	Randomness  [RandomnessLength]byte // TODO: update to [32]byte when runtime is updated
}

NextEpochDescriptor contains information about the next epoch. It is broadcast as part of the consensus digest in the first block of the epoch.

func (*NextEpochDescriptor) Decode

func (n *NextEpochDescriptor) Decode(in []byte) error

Decode sets the NextEpochDescriptor to the SCALE decoded input. TODO: change to io.Reader

func (*NextEpochDescriptor) Encode

func (n *NextEpochDescriptor) Encode() []byte

Encode returns the SCALE encoding of the NextEpochDescriptor.

type NextEpochDescriptorRaw

type NextEpochDescriptorRaw struct {
	Authorities []*types.AuthorityDataRaw
	Randomness  [RandomnessLength]byte
}

NextEpochDescriptorRaw contains information about the next epoch.

type Session

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

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

func NewSession

func NewSession(cfg *SessionConfig) (*Session, error)

NewSession returns a new Babe session using the provided VRF keys and runtime

func (*Session) AuthorityData

func (b *Session) AuthorityData() []*types.AuthorityData

AuthorityData returns the data related to the authority

func (*Session) BuildBlock

func (b *Session) 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 (*Session) Descriptor

func (b *Session) Descriptor() *NextEpochDescriptor

Descriptor returns the NextEpochDescriptor for the current session.

func (*Session) SetEpochData

func (b *Session) SetEpochData(data *NextEpochDescriptor) error

SetEpochData will set the authorityData and randomness

func (*Session) Start

func (b *Session) Start() error

Start a session

type SessionConfig

type SessionConfig struct {
	BlockState       BlockState
	StorageState     StorageState
	TransactionQueue TransactionQueue
	Keypair          *sr25519.Keypair
	Runtime          *runtime.Runtime
	NewBlocks        chan<- types.Block
	AuthData         []*types.AuthorityData
	EpochThreshold   *big.Int // should only be used for testing
	StartSlot        uint64   // slot to begin session at
	EpochDone        *sync.WaitGroup
	Kill             <-chan struct{}
	SyncLock         *sync.Mutex
}

SessionConfig struct

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 {
	StorageRoot() (common.Hash, error)
	SetStorage([]byte, []byte) error
}

StorageState interface for storage state methods

type TransactionQueue

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

TransactionQueue 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, currentEpoch uint64, currentDescriptor *NextEpochDescriptor) (*VerificationManager, error)

NewVerificationManager returns a new VerificationManager

func (*VerificationManager) EpochNumber

func (v *VerificationManager) EpochNumber() uint64

EpochNumber returns the current epoch number

func (*VerificationManager) IncrementEpoch

func (v *VerificationManager) IncrementEpoch() (*NextEpochDescriptor, error)

IncrementEpoch sets the NextEpochDescriptor for the current epoch and returns it. It also increments the epoch number.

func (*VerificationManager) VerifyBlock

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

VerifyBlock verifies the given header with verifyAuthorshipRight. It also checks for a NextEpochDescriptor for the current epoch.

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