Documentation
¶
Index ¶
- Variables
- func CalculateThreshold(C1, C2 uint64, numAuths int) (*big.Int, error)
- type AuthorityData
- type BlockState
- type Descriptor
- type EpochState
- type Service
- func (b *Service) Authorities() []*types.Authority
- func (b *Service) BuildBlock(parent *types.Header, slot Slot) (*types.Block, error)
- func (b *Service) Descriptor() *Descriptor
- func (b *Service) GetBlockChannel() <-chan types.Block
- func (b *Service) IsPaused() bool
- func (b *Service) IsStopped() bool
- func (b *Service) Pause() error
- func (b *Service) Resume() error
- func (b *Service) SetAuthorities(data []*types.Authority) error
- func (b *Service) SetRandomness(a [types.RandomnessLength]byte)
- func (b *Service) SetRuntime(rt runtime.LegacyInstance) error
- func (b *Service) SetThreshold(a *big.Int)
- func (b *Service) Start() error
- func (b *Service) Stop() error
- type ServiceConfig
- type Slot
- type StorageState
- type TransactionState
- type VerificationManager
- type VrfOutputAndProof
Constants ¶
This section is empty.
Variables ¶
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) )
var ErrBadSignature = errors.New("could not verify signature")
ErrBadSignature is returned when a seal is invalid
var ErrBadSlotClaim = errors.New("could not verify slot claim")
ErrBadSlotClaim is returned when a slot claim is invalid
var ErrNilBlockState = errors.New("cannot have nil BlockState")
ErrNilBlockState is returned when the BlockState is nil
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
var ErrNotAuthorized = errors.New("not authorized to produce block")
ErrNotAuthorized is returned when the node is not authorized to produce a block
var ErrProducerEquivocated = errors.New("block producer equivocated")
ErrProducerEquivocated is returned when a block producer has produced conflicting blocks
Functions ¶
Types ¶
type AuthorityData ¶ added in v0.2.0
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
Authorities returns the current BABE authorities
func (*Service) BuildBlock ¶ added in v0.2.0
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
GetBlockChannel returns the channel where new blocks are passed
func (*Service) IsPaused ¶ added in v0.2.0
IsPaused returns if the service is paused or not (ie. producing blocks)
func (*Service) IsStopped ¶ added in v0.2.0
IsStopped returns true if the service is stopped (ie not producing blocks)
func (*Service) SetAuthorities ¶ added in v0.2.0
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
SetThreshold sets the threshold for a block producer
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
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