state

package
v0.0.0-...-b9de96a Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

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")
	// ErrorJustifiedHash 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 {
	ProcessSlot(previousBlockRoot chainhash.Hash)
	ProcessSlots(requestedSlot uint64, view BlockView) ([]*primitives.EpochReceipt, error)
	ProcessBlock(b *primitives.Block) error
	ProcessVote(v *primitives.MultiValidatorVote, proposerIndex uint64) error
	ProcessEpochTransition() ([]*primitives.EpochReceipt, error)

	CheckBlockSignature(b *primitives.Block) 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

	AreDepositsValid(deposits []*primitives.Deposit) error

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

	ApplyRANDAOSlashing(rs *primitives.RANDAOSlashing) error
	ApplyTransactionSingle(tx *primitives.Tx, blockWithdrawalAddress [20]byte) 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
	SetSlot(slot uint64)

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

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

	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

func NewState

func NewState(cs primitives.CoinsState, validators []*primitives.Validator, genHash chainhash.Hash, p *params.ChainParams) 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