state

package
v0.2.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GovernanceStateActive is the enum to an active Governance voting state
	GovernanceStateActive uint64 = iota
	// GovernanceStateVoting is the enum to an voting Governance voting state
	GovernanceStateVoting
)

Variables

View Source
var (
	// ErrorVoteSlot returns when the vote data slot is out of range
	ErrorVoteSlot = errors.New("slot out of range")
	// ErrorFromEpoch returns when the vote From Epoch doesn't match a justified epoch
	ErrorFromEpoch = errors.New("expected from epoch to match justified epoch")
	// ErrorJustifiedHashWrong returns when the vote justified hash doesn't match state justified hash
	ErrorJustifiedHash = errors.New("justified block hash is wrong")
	// ErrorFromEpochPreviousJustified returns when the from epoch slot doesn't match the previous justified epoch
	ErrorFromEpochPreviousJustified = errors.New("expected from epoch to match previous justified epoch")
	// ErrorFromEpochPreviousJustifiedHash returns when the from epoch hash doesn't match the previous justified epoch hash
	ErrorFromEpochPreviousJustifiedHash = errors.New("expected from epoch hash to match previous justified epoch hash")
	// ErrorTargetEpoch returns when the to epoch hash a wrong target
	ErrorTargetEpoch = errors.New("vote should have target epoch of either the current epoch or the previous epoch")
	// ErrorVoteSignature returns when the vote aggregate signature doesn't validate
	ErrorVoteSignature = errors.New("vote aggregate signature did not validate")
)

Functions

func DetermineNextProposers

func DetermineNextProposers(randao chainhash.Hash, activeValidators []uint64) []uint64

DetermineNextProposers gets the next shuffling.

func Shuffle

func Shuffle(randao chainhash.Hash, vals []uint64) []uint64

Shuffle shuffles validator using a RANDAO.

Types

type BlockView

type BlockView interface {
	GetHashBySlot(slot uint64) (chainhash.Hash, error)
	Tip() (chainhash.Hash, error)
	SetTipSlot(slot uint64)
}

BlockView is the view of the blockchain at a certain tip.

type State

type State interface {

	// Processors
	ProcessSlot(previousBlockRoot chainhash.Hash)
	ProcessSlots(requestedSlot uint64, view BlockView) ([]*primitives.EpochReceipt, error)
	ProcessBlock(b *primitives.Block) error
	ProcessVote(v *primitives.MultiValidatorVote, proposerIndex uint64) error
	ProcessGovernanceVote(vote *primitives.GovernanceVote) error
	ProcessEpochTransition() ([]*primitives.EpochReceipt, error)

	// Checkers
	CheckForVoteTransitions()
	CheckBlockSignature(b *primitives.Block) error
	IsGovernanceVoteValid(vote *primitives.GovernanceVote) error
	IsCoinProofValid(p *burnproof.CoinsProofSerializable) error
	IsProposerSlashingValid(ps *primitives.ProposerSlashing) (uint64, error)
	IsVoteSlashingValid(vs *primitives.VoteSlashing) ([]uint64, error)
	IsRANDAOSlashingValid(rs *primitives.RANDAOSlashing) (uint64, error)
	IsExitValid(exit *primitives.Exit) error
	IsDepositValid(deposit *primitives.Deposit) error
	IsVoteValid(v *primitives.MultiValidatorVote) error
	IsPartialExitValid(p *primitives.PartialExit) error

	// Checkers Multi
	AreDepositsValid(deposits []*primitives.Deposit) error

	// Validators
	ActivateValidator(index uint64) error
	InitiateValidatorExit(index uint64) error
	ExitValidator(index uint64, status uint64) error
	UpdateValidatorStatus(index uint64, status uint64) error

	// Appliers
	ApplyRANDAOSlashing(rs *primitives.RANDAOSlashing) error
	ApplyTransactionSingle(tx *primitives.Tx, blockWithdrawalAddress [20]byte) error
	ApplyMultiSignatureTx(tx *primitives.MultiSignatureTx, blockWithdrawalAddress [20]byte) error
	ApplyCoinProof(p *burnproof.CoinsProofSerializable) error
	ApplyProposerSlashing(ps *primitives.ProposerSlashing) error
	ApplyVoteSlashing(vs *primitives.VoteSlashing) error
	ApplyExit(exit *primitives.Exit) error
	ApplyDeposit(deposit *primitives.Deposit) error
	ApplyPartialExit(p *primitives.PartialExit) error
	NextVoteEpoch(newState uint64)
	SetSlot(slot uint64)

	// Appliers Multi
	ApplyMultiTransactionSingle(txs []*primitives.Tx, blockWithdrawalAddress [20]byte) error
	ApplyMultiDeposit(deposits []*primitives.Deposit) error

	// Utils
	Copy() State
	ToSerializable() *primitives.SerializableState
	FromSerializable(ser *primitives.SerializableState)
	Marshal() ([]byte, error)
	Unmarshal(b []byte) error

	// Getters
	GetVoteCommittee(slot uint64) ([]uint64, error)
	GetProposerPublicKey(b *primitives.Block) (common.PublicKey, error)
	GetRecentBlockHash(slotToGet uint64) chainhash.Hash
	GetTotalBalances() uint64
	GetEffectiveBalance(index uint64) uint64
	GetValidatorIndicesActiveAt(epoch uint64) []uint64
	GetValidators() ValidatorsInfo
	GetValidatorsForAccount(acc []byte) ValidatorsInfo
	GetCoinsState() primitives.CoinsState
	GetValidatorRegistry() []*primitives.Validator
	GetProposerQueue() []uint64
	GetSlot() uint64
	GetEpochIndex() uint64
	GetFinalizedEpoch() uint64
	GetJustifiedEpoch() uint64
	GetJustifiedEpochHash() chainhash.Hash
}

func GetGenesisStateWithInitializationParameters

func GetGenesisStateWithInitializationParameters(genesisHash chainhash.Hash, ip *initialization.InitializationParameters, p *params.ChainParams) (State, error)

GetGenesisStateWithInitializationParameters gets the genesis state with certain parameters.

func NewEmptyState

func NewEmptyState() State

type ValidatorsInfo

type ValidatorsInfo struct {
	Validators  []*primitives.Validator
	Active      int64
	PendingExit int64
	PenaltyExit int64
	Exited      int64
	Starting    int64
}

ValidatorsInfo returns the state validators information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL