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 ¶
- Variables
- func CalculateThreshold(C1, C2 uint64, numAuths int) (*common.Uint128, error)
- type Authorities
- type BlockState
- type EpochState
- type Randomness
- type Service
- func (b *Service) Authorities() []*types.Authority
- func (b *Service) BuildBlock(parent *types.Header, slot Slot) (*types.Block, error)
- func (b *Service) EpochLength() uint64
- 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) SetOnDisabled(authorityIndex uint32)
- func (b *Service) SetRuntime(rt runtime.Instance)
- func (b *Service) SlotDuration() uint64
- 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 ErrAuthorityAlreadyDisabled = errors.New("authority has already been disabled")
ErrAuthorityAlreadyDisabled is returned when attempting to disabled an already-disabled authority
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
var ErrBadSecondarySlotClaim = errors.New("invalid secondary slot claim")
ErrBadSecondarySlotClaim is returned when a slot claim is invalid
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 VRF proof")
ErrBadSlotClaim is returned when a slot claim is invalid
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
var ErrNilBlockState = errors.New("cannot have nil BlockState")
ErrNilBlockState is returned when the BlockState is nil
var ErrNilEpochState = errors.New("cannot have nil EpochState")
ErrNilEpochState is returned when the EpochState 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 ErrNotAuthority = errors.New("node is not an authority")
ErrNotAuthority is returned when trying to perform authority functions when not an authority
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
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
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
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
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) EpochLength ¶ added in v0.3.0
EpochLength returns the current service epoch duration
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) SetOnDisabled ¶ added in v0.3.0
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
SetRuntime sets the service's runtime
func (*Service) SlotDuration ¶ added in v0.3.0
SlotDuration returns the current service slot duration in milliseconds
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
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