Documentation ¶
Index ¶
- Variables
- func CalculateThreshold(C1, C2 uint64, numAuths int) (*scale.Uint128, error)
- type AncientBirthBlock
- type Authorities
- type BadMandatory
- type BadOrigin
- type BadProof
- type BadSigner
- type BlockBuilder
- type BlockHandler
- type BlockImportHandler
- type BlockState
- type Builder
- type Call
- type CannotLookup
- type DispatchOutcomeError
- type EpochState
- type ExhaustsResources
- type ExtrinsicHandler
- type Future
- type ImportedBlockNotifierManager
- type InvalidCustom
- type MandatoryDispatch
- type Module
- type NoUnsignedValidator
- type Other
- type Payment
- type Randomness
- type Runtime
- type Service
- func (b *Service) AuthoritiesRaw() []types.AuthorityRaw
- func (b *Service) EpochLength() uint64
- func (b *Service) IsPaused() bool
- func (b *Service) IsStopped() bool
- func (b *Service) Pause() error
- func (b *Service) Resume() error
- func (b *Service) SlotDuration() uint64
- func (b *Service) Start() error
- func (b *Service) Stop() error
- type ServiceConfig
- type Slot
- type SlotState
- type Stale
- type StorageState
- type Telemetry
- type TransactionState
- type TransactionValidityError
- type UnknownCustom
- type UnmarshalError
- type ValidityCannotLookup
- type VerificationManager
- type VrfOutputAndProof
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAuthIndexOutOfBound is returned when a authority index doesn't exist ErrAuthIndexOutOfBound = errors.New("authority index doesn't exist") // 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") )
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 AncientBirthBlock ¶ added in v0.7.0
type AncientBirthBlock struct{}
AncientBirthBlock The transaction birth block is ancient
func (AncientBirthBlock) String ¶ added in v0.8.0
func (AncientBirthBlock) String() string
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 BadMandatory ¶ added in v0.7.0
type BadMandatory struct{}
BadMandatory An extrinsic with a Mandatory dispatch resulted in Error
func (BadMandatory) String ¶ added in v0.8.0
func (BadMandatory) String() string
type BadProof ¶ added in v0.7.0
type BadProof struct{}
BadProof General error to do with the transaction’s proofs (e.g. signature)
type BadSigner ¶ added in v0.8.0
type BadSigner struct{}
BadSigner A transaction with a mandatory dispatch
type BlockBuilder ¶ added in v0.7.0
type BlockBuilder struct {
// contains filtered or unexported fields
}
BlockBuilder builds blocks.
func NewBlockBuilder ¶ added in v0.7.0
func NewBlockBuilder( kp *sr25519.Keypair, ts TransactionState, bs BlockState, authidx uint32, preRuntimeDigest *types.PreRuntimeDigest, ) *BlockBuilder
NewBlockBuilder creates a new block builder.
type BlockHandler ¶ added in v0.8.0
type BlockHandler interface { InitializeBlock(header *types.Header) error FinalizeBlock() (*types.Header, error) }
BlockHandler handles block initialisation and finalisation.
type BlockImportHandler ¶ added in v0.7.0
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) AddBlock(*types.Block) error GetAllBlocksAtDepth(hash common.Hash) []common.Hash GetHeader(common.Hash) (*types.Header, error) GetBlockByNumber(blockNumber uint) (*types.Block, error) GetBlockHashesBySlot(slot uint64) (blockHashes []common.Hash, err error) GenesisHash() common.Hash GetSlotForBlock(common.Hash) (uint64, error) IsDescendantOf(parent, child common.Hash) (bool, error) NumberIsFinalised(blockNumber uint) (bool, error) GetRuntime(blockHash common.Hash) (runtime runtime.Instance, err error) StoreRuntime(common.Hash, runtime.Instance) ImportedBlockNotifierManager }
BlockState interface for block state methods
type Builder ¶ added in v0.7.0
type Builder struct{}
Builder struct to hold babe builder functions
func (Builder) NewServiceIFace ¶ added in v0.7.0
func (Builder) NewServiceIFace(cfg *ServiceConfig) (service *Service, err error)
NewServiceIFace returns a new Babe Service using the provided VRF keys and runtime
type CannotLookup ¶ added in v0.7.0
type CannotLookup struct{}
CannotLookup Failed to lookup some data
func (CannotLookup) String ¶ added in v0.8.0
func (CannotLookup) String() string
type DispatchOutcomeError ¶ added in v0.7.0
type DispatchOutcomeError struct {
// contains filtered or unexported fields
}
A DispatchOutcomeError is outcome of dispatching the extrinsic
func (DispatchOutcomeError) Error ¶ added in v0.7.0
func (e DispatchOutcomeError) Error() string
type EpochState ¶ added in v0.2.0
type EpochState interface { GetEpochLength() (uint64, error) GetSlotDuration() (time.Duration, error) SetCurrentEpoch(epoch uint64) error GetCurrentEpoch() (uint64, error) GetEpochDataRaw(epoch uint64, header *types.Header) (*types.EpochDataRaw, error) GetConfigData(epoch uint64, header *types.Header) (*types.ConfigData, error) GetLatestConfigData() (*types.ConfigData, error) GetStartSlotForEpoch(epoch uint64) (uint64, error) GetEpochForBlock(header *types.Header) (uint64, error) SetFirstSlot(slot uint64) error GetLatestEpochDataRaw() (*types.EpochDataRaw, error) SkipVerify(*types.Header) (bool, error) }
EpochState is the interface for epoch methods
type ExhaustsResources ¶ added in v0.7.0
type ExhaustsResources struct{}
ExhaustsResources The transaction would exhaust the resources of current block
func (ExhaustsResources) String ¶ added in v0.8.0
func (ExhaustsResources) String() string
type ExtrinsicHandler ¶ added in v0.8.0
type ExtrinsicHandler interface { InherentExtrinsics(data []byte) ([]byte, error) ApplyExtrinsic(data types.Extrinsic) ([]byte, error) }
ExtrinsicHandler deals with extrinsics.
type Future ¶ added in v0.7.0
type Future struct{}
Future General error to do with the transaction not yet being valid (e.g. nonce too high)
type ImportedBlockNotifierManager ¶ added in v0.7.0
type ImportedBlockNotifierManager interface { GetImportedBlockNotifierChannel() chan *types.Block FreeImportedBlockNotifierChannel(ch chan *types.Block) }
ImportedBlockNotifierManager is the interface for block notification channels
type InvalidCustom ¶ added in v0.7.0
type InvalidCustom uint8
InvalidCustom Any other custom invalid validity that is not covered
func (InvalidCustom) String ¶ added in v0.8.0
func (ic InvalidCustom) String() string
type MandatoryDispatch ¶ added in v0.7.0
type MandatoryDispatch struct{}
MandatoryDispatch A transaction with a mandatory dispatch
func (MandatoryDispatch) String ¶ added in v0.8.0
func (MandatoryDispatch) String() string
type NoUnsignedValidator ¶ added in v0.7.0
type NoUnsignedValidator struct{}
NoUnsignedValidator No validator found for the given unsigned transaction
func (NoUnsignedValidator) String ¶ added in v0.8.0
func (NoUnsignedValidator) String() string
type Payment ¶ added in v0.7.0
type Payment struct{}
Payment General error to do with the inability to pay some fees (e.g. account balance too low)
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 Runtime ¶ added in v0.8.0
type Runtime interface { BlockHandler ExtrinsicHandler }
Runtime is the runtime interface for the babe package.
type Service ¶ added in v0.2.0
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 function to create babe service
func (*Service) AuthoritiesRaw ¶ added in v0.8.0
func (b *Service) AuthoritiesRaw() []types.AuthorityRaw
Authorities returns the current BABE authorities
func (*Service) EpochLength ¶ added in v0.3.0
EpochLength returns the current service epoch duration
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) 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.Level BlockState BlockState StorageState StorageState TransactionState TransactionState EpochState EpochState BlockImportHandler BlockImportHandler Keypair *sr25519.Keypair AuthData []types.Authority IsDev bool Authority bool Telemetry Telemetry }
ServiceConfig represents a BABE configuration
func (*ServiceConfig) Validate ¶ added in v0.7.0
func (sc *ServiceConfig) Validate() error
Validate returns error if config does not contain required attributes
type Slot ¶
type Slot struct {
// contains filtered or unexported fields
}
Slot represents a BABE slot
type SlotState ¶ added in v0.8.0
type SlotState interface { CheckEquivocation(slotNow, slot uint64, header *types.Header, signer types.AuthorityID) (*types.BabeEquivocationProof, error) }
type Stale ¶ added in v0.7.0
type Stale struct{}
Stale General error to do with the transaction being outdated (e.g. nonce too low)
type StorageState ¶
type StorageState interface { TrieState(hash *common.Hash) (*rtstorage.TrieState, error) sync.Locker }
StorageState interface for storage state methods
type TransactionState ¶ added in v0.2.0
type TransactionState interface { Push(vt *transaction.ValidTransaction) (common.Hash, error) PopWithTimer(timerCh <-chan time.Time) (tx *transaction.ValidTransaction) }
TransactionState is the interface for transaction queue methods
type TransactionValidityError ¶ added in v0.7.0
type TransactionValidityError struct {
// contains filtered or unexported fields
}
A TransactionValidityError is possible errors while checking the validity of a transaction
func (TransactionValidityError) Error ¶ added in v0.7.0
func (e TransactionValidityError) Error() string
type UnknownCustom ¶ added in v0.7.0
type UnknownCustom uint8
UnknownCustom Any other custom unknown validity that is not covered
func (UnknownCustom) String ¶ added in v0.8.0
func (uc UnknownCustom) String() string
type UnmarshalError ¶ added in v0.7.0
type UnmarshalError struct {
// contains filtered or unexported fields
}
UnmarshalError occurs when unmarshalling fails
func (UnmarshalError) Error ¶ added in v0.7.0
func (e UnmarshalError) Error() string
type ValidityCannotLookup ¶ added in v0.7.0
type ValidityCannotLookup struct{}
ValidityCannotLookup Could not lookup some information that is required to validate the transaction
func (ValidityCannotLookup) String ¶ added in v0.8.0
func (ValidityCannotLookup) String() string
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 tracks the BABE epoch data that is needed for verification.
func NewVerificationManager ¶
func NewVerificationManager(blockState BlockState, slotState SlotState, epochState EpochState) *VerificationManager
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 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