Documentation
¶
Index ¶
- Variables
- func CalculateThreshold(C1, C2 uint64, numAuths int) (*scale.Uint128, error)
- type AncientBirthBlock
- type Authorities
- type BadMandatory
- type BadOrigin
- type BadProof
- type BlockBuilder
- type BlockImportHandler
- type BlockState
- type Builder
- type Call
- type CannotLookup
- type DigestHandler
- type DispatchOutcomeError
- type EpochState
- type ExhaustsResources
- type Future
- type ImportedBlockNotifierManager
- type InvalidCustom
- type MandatoryDispatch
- type Module
- type NoUnsignedValidator
- type Other
- type ParachainInherentData
- type Payment
- type Randomness
- type Service
- func (b *Service) Authorities() []types.Authority
- 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 ServiceIFace
- type Slot
- type Stale
- type StorageState
- type TransactionState
- type TransactionValidityError
- type UnknownCustom
- type UnmarshalError
- type ValidityCannotLookup
- type VerificationManager
- type VrfOutputAndProof
Constants ¶
This section is empty.
Variables ¶
var ( // 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) Index ¶ added in v0.7.0
func (AncientBirthBlock) Index() uint
Index returns VDT index
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) Index ¶ added in v0.7.0
func (BadMandatory) Index() uint
Index returns VDT index
type BadProof ¶ added in v0.7.0
type BadProof struct{}
BadProof General error to do with the transaction’s proofs (e.g. signature)
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 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)
BestBlockNumber() (blockNumber uint, err 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(blockNumber uint) (*types.Block, error)
GetBlockByHash(common.Hash) (*types.Block, error)
GetBlockHashesBySlot(slot uint64) (blockHashes []common.Hash, err error)
GetArrivalTime(common.Hash) (time.Time, error)
GenesisHash() common.Hash
GetSlotForBlock(common.Hash) (uint64, error)
GetFinalisedHeader(uint64, uint64) (*types.Header, error)
IsDescendantOf(parent, child common.Hash) (bool, error)
NumberIsFinalised(blockNumber uint) (bool, error)
GetRuntime(blockHash common.Hash) (instance 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) (ServiceIFace, 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) Index ¶ added in v0.7.0
func (CannotLookup) Index() uint
Index returns VDT index
type DigestHandler ¶ added in v0.7.0
DigestHandler is the interface for the consensus digest handler
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)
SetEpochData(uint64, *types.EpochData) error
GetEpochData(epoch uint64, header *types.Header) (*types.EpochData, 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
GetLatestEpochData() (*types.EpochData, error)
SkipVerify(*types.Header) (bool, error)
GetEpochFromTime(time.Time) (uint64, 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) Index ¶ added in v0.7.0
func (ExhaustsResources) Index() uint
Index returns VDT index
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) Index ¶ added in v0.7.0
func (InvalidCustom) Index() uint
Index returns VDT index
type MandatoryDispatch ¶ added in v0.7.0
type MandatoryDispatch struct{}
MandatoryDispatch A transaction with a mandatory dispatch
func (MandatoryDispatch) Index ¶ added in v0.7.0
func (MandatoryDispatch) Index() uint
Index returns VDT index
type NoUnsignedValidator ¶ added in v0.7.0
type NoUnsignedValidator struct{}
NoUnsignedValidator No validator found for the given unsigned transaction
func (NoUnsignedValidator) Index ¶ added in v0.7.0
func (NoUnsignedValidator) Index() uint
Index returns VDT index
type ParachainInherentData ¶ added in v0.7.0
type ParachainInherentData struct {
// Signed bitfields by validators about availability.
Bitfields []uncheckedSignedAvailabilityBitfield `scale:"1"`
// Backed candidates for inclusion in the block.
BackedCandidates []backedCandidate `scale:"2"`
// Sets of dispute votes for inclusion,
Disputes multiDisputeStatementSet `scale:"3"`
// The parent block header. Used for checking state proofs.
ParentHeader types.Header `scale:"4"`
}
ParachainInherentData is parachains inherent-data passed into the runtime by a block author.
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 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) Authorities ¶ added in v0.2.0
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
Lead bool
Telemetry telemetry.Client
}
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 ServiceIFace ¶ added in v0.7.0
type ServiceIFace interface {
Start() error
Stop() error
EpochLength() uint64
Pause() error
IsPaused() bool
Resume() error
SlotDuration() uint64
}
ServiceIFace interface that defines methods available to BabeService
type Slot ¶
type Slot struct {
// contains filtered or unexported fields
}
Slot represents a BABE slot
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)
Pop() *transaction.ValidTransaction
Peek() *transaction.ValidTransaction
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) Index ¶ added in v0.7.0
func (UnknownCustom) Index() uint
Index returns VDT index
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) Index ¶ added in v0.7.0
func (ValidityCannotLookup) Index() uint
Index returns VDT index
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
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