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 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") ErrNilBlockState = errors.New("cannot have nil BlockState") ErrNilTransactionState = errors.New("cannot create block builder; transaction state is nil") ErrNilVRFProof = errors.New("cannot create block builder; slot VRF proof is nil") )
Functions ¶
func CalculateThreshold ¶
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 ¶
type AncientBirthBlock struct{}
AncientBirthBlock The transaction birth block is ancient
type Authorities ¶
Authorities is an alias for []*types.Authority
func (Authorities) String ¶
func (d Authorities) String() string
String returns the Authorities as a formatted string
type BadMandatory ¶
type BadMandatory struct{}
BadMandatory An extrinsic with a Mandatory dispatch resulted in Error
type BadProof ¶
type BadProof struct{}
BadProof General error to do with the transaction’s proofs (e.g. signature)
type BlockBuilder ¶
type BlockBuilder struct {
// contains filtered or unexported fields
}
BlockBuilder builds blocks.
func NewBlockBuilder ¶
func NewBlockBuilder( kp *sr25519.Keypair, ts TransactionState, bs BlockState, authidx uint32, preRuntimeDigest *types.PreRuntimeDigest, ) (*BlockBuilder, error)
NewBlockBuilder creates a new block builder.
type BlockImportHandler ¶
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) 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(*common.Hash) (runtime.Instance, error) StoreRuntime(common.Hash, runtime.Instance) ImportedBlockNotifierManager }
BlockState interface for block state methods
type Builder ¶
type Builder struct{}
Builder struct to hold babe builder functions
func (Builder) NewServiceIFace ¶
func (Builder) NewServiceIFace(cfg *ServiceConfig) (ServiceIFace, error)
NewServiceIFace returns a new Babe Service using the provided VRF keys and runtime
type DigestHandler ¶
DigestHandler is the interface for the consensus digest handler
type DispatchOutcomeError ¶
type DispatchOutcomeError struct {
// contains filtered or unexported fields
}
A DispatchOutcomeError is outcome of dispatching the extrinsic
func (DispatchOutcomeError) Error ¶
func (e DispatchOutcomeError) Error() string
type EpochState ¶
type EpochState interface { GetEpochLength() (uint64, error) GetSlotDuration() (time.Duration, error) SetCurrentEpoch(epoch uint64) error GetCurrentEpoch() (uint64, error) SetEpochData(uint64, *types.EpochData) error HasEpochData(epoch uint64) (bool, error) GetEpochData(epoch uint64, header *types.Header) (*types.EpochData, error) GetConfigData(epoch uint64, header *types.Header) (*types.ConfigData, error) HasConfigData(epoch uint64) (bool, 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 ¶
type ExhaustsResources struct{}
ExhaustsResources The transaction would exhaust the resources of current block
type Future ¶
type Future struct{}
Future General error to do with the transaction not yet being valid (e.g. nonce too high)
type ImportedBlockNotifierManager ¶
type ImportedBlockNotifierManager interface { GetImportedBlockNotifierChannel() chan *types.Block FreeImportedBlockNotifierChannel(ch chan *types.Block) }
ImportedBlockNotifierManager is the interface for block notification channels
type InvalidCustom ¶
type InvalidCustom uint8
InvalidCustom Any other custom invalid validity that is not covered
type MandatoryDispatch ¶
type MandatoryDispatch struct{}
MandatoryDispatch A transaction with a mandatory dispatch
type NoUnsignedValidator ¶
type NoUnsignedValidator struct{}
NoUnsignedValidator No validator found for the given unsigned transaction
func (NoUnsignedValidator) Index ¶
func (err NoUnsignedValidator) Index() uint
Index Returns VDT index
type Payment ¶
type Payment struct{}
Payment General error to do with the inability to pay some fees (e.g. account balance too low)
type Randomness ¶
type Randomness = [types.RandomnessLength]byte
Randomness is an alias for a byte array with length types.RandomnessLength
type Service ¶
Service contains the VRF keys for the validator, as well as BABE configuation data
func NewService ¶
func NewService(cfg *ServiceConfig) (*Service, error)
NewService function to create babe service
func (*Service) Authorities ¶
Authorities returns the current BABE authorities
func (*Service) EpochLength ¶
EpochLength returns the current service epoch duration
func (*Service) IsStopped ¶
IsStopped returns true if the service is stopped (ie not producing blocks)
func (*Service) SlotDuration ¶
SlotDuration returns the current service slot duration in milliseconds
type ServiceConfig ¶
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 ¶
func (sc *ServiceConfig) Validate() error
Validate returns error if config does not contain required attributes
type ServiceIFace ¶
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 ¶
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 ¶
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 TransactionValidityError ¶
type TransactionValidityError struct {
// contains filtered or unexported fields
}
A TransactionValidityError is possible errors while checking the validity of a transaction
func (TransactionValidityError) Error ¶
func (e TransactionValidityError) Error() string
type UnknownCustom ¶
type UnknownCustom uint8
UnknownCustom Any other custom unknown validity that is not covered
type UnmarshalError ¶
type UnmarshalError struct {
// contains filtered or unexported fields
}
UnmarshalError occurs when unmarshalling fails
func (UnmarshalError) Error ¶
func (e UnmarshalError) Error() string
type ValidityCannotLookup ¶
type ValidityCannotLookup struct{}
ValidityCannotLookup Could not lookup some information that is required to validate the transaction
func (ValidityCannotLookup) Index ¶
func (err 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, error)
NewVerificationManager returns a new NewVerificationManager
func (*VerificationManager) SetOnDisabled ¶
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