precompute

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttestedCurrentEpoch

func AttestedCurrentEpoch(s *pb.BeaconState, a *pb.PendingAttestation) (bool, bool, error)

AttestedCurrentEpoch returns true if attestation `a` attested once in current epoch and/or epoch boundary block.

func AttestedPrevEpoch

func AttestedPrevEpoch(s *pb.BeaconState, a *pb.PendingAttestation) (bool, bool, bool, error)

AttestedPrevEpoch returns true if attestation `a` attested once in previous epoch and epoch boundary block and/or the same head.

func New

func New(ctx context.Context, state *pb.BeaconState) ([]*Validator, *Balance)

New gets called at the beginning of process epoch cycle to return pre computed instances of validators attesting records and total balances attested in an epoch.

func ProcessAttestations

func ProcessAttestations(
	ctx context.Context,
	state *pb.BeaconState,
	vp []*Validator,
	bp *Balance) ([]*Validator, *Balance, error)

ProcessAttestations process the attestations in state and update individual validator's pre computes, it also tracks and updates epoch attesting balances.

func ProcessJustificationAndFinalizationPreCompute

func ProcessJustificationAndFinalizationPreCompute(state *pb.BeaconState, p *Balance) (*pb.BeaconState, error)

ProcessJustificationAndFinalizationPreCompute processes justification and finalization during epoch processing. This is where a beacon node can justify and finalize a new epoch. Note: this is an optimized version by passing in precomputed total and attesting balances.

func ProcessRewardsAndPenaltiesPrecompute

func ProcessRewardsAndPenaltiesPrecompute(state *pb.BeaconState, bp *Balance, vp []*Validator) (*pb.BeaconState, error)

ProcessRewardsAndPenaltiesPrecompute processes the rewards and penalties of individual validator. This is an optimized version by passing in precomputed validator attesting records and and total epoch balances.

func ProcessSlashingsPrecompute

func ProcessSlashingsPrecompute(state *pb.BeaconState, p *Balance) *pb.BeaconState

ProcessSlashingsPrecompute processes the slashed validators during epoch processing. This is an optimized version by passing in precomputed total epoch balances.

func SameHead

func SameHead(state *pb.BeaconState, a *pb.PendingAttestation) (bool, error)

SameHead returns true if attestation `a` attested to the same block by attestation slot in state.

func SameTarget

func SameTarget(state *pb.BeaconState, a *pb.PendingAttestation, e uint64) (bool, error)

SameTarget returns true if attestation `a` attested to the same target block in state.

Types

type Balance

type Balance struct {
	// CurrentEpoch is the total effective balance of all active validators during current epoch.
	CurrentEpoch uint64
	// PrevEpoch is the total effective balance of all active validators during prev epoch.
	PrevEpoch uint64
	// CurrentEpochAttesters is the total effective balance of all validators who attested during current epoch.
	CurrentEpochAttesters uint64
	// CurrentEpochTargetAttesters is the total effective balance of all validators who attested
	// for epoch boundary block during current epoch.
	CurrentEpochTargetAttesters uint64
	// PrevEpochAttesters is the total effective balance of all validators who attested during prev epoch.
	PrevEpochAttesters uint64
	// PrevEpochTargetAttesters is the total effective balance of all validators who attested
	// for epoch boundary block during prev epoch.
	PrevEpochTargetAttesters uint64
	// PrevEpochHeadAttesters is the total effective balance of all validators who attested
	// correctly for head block during prev epoch.
	PrevEpochHeadAttesters uint64
}

Balance stores the pre computation of the total participated balances for a given epoch Pre computing and storing such record is essential for process epoch optimizations.

func UpdateBalance

func UpdateBalance(vp []*Validator, bp *Balance) *Balance

UpdateBalance updates pre computed balance store.

type Validator

type Validator struct {
	// IsSlashed is true if the validator has been slashed.
	IsSlashed bool
	// IsWithdrawableCurrentEpoch is true if the validator can withdraw current epoch.
	IsWithdrawableCurrentEpoch bool
	// IsActiveCurrentEpoch is true if the validator was active current epoch.
	IsActiveCurrentEpoch bool
	// IsActivePrevEpoch is true if the validator was active prev epoch.
	IsActivePrevEpoch bool
	// IsCurrentEpochAttester is true if the validator attested current epoch.
	IsCurrentEpochAttester bool
	// IsCurrentEpochTargetAttester is true if the validator attested current epoch target.
	IsCurrentEpochTargetAttester bool
	// IsPrevEpochAttester is true if the validator attested previous epoch.
	IsPrevEpochAttester bool
	// IsPrevEpochTargetAttester is true if the validator attested previous epoch target.
	IsPrevEpochTargetAttester bool
	// IsHeadAttester is true if the validator attested head.
	IsPrevEpochHeadAttester bool

	// CurrentEpochEffectiveBalance is how much effective balance this validator validator has current epoch.
	CurrentEpochEffectiveBalance uint64
	// InclusionSlot is the slot of when the attestation gets included in the chain.
	InclusionSlot uint64
	// InclusionDistance is the distance between the assigned slot and this validator's attestation was included in block.
	InclusionDistance uint64
	// ProposerIndex is the index of proposer at slot where this validator's attestation was included.
	ProposerIndex uint64
}

Validator stores the pre computation of individual validator's attesting records these records consist of attestation votes, block inclusion record. Pre computing and storing such record is essential for process epoch optimizations.

func UpdateValidator

func UpdateValidator(vp []*Validator, record *Validator, indices []uint64, a *pb.PendingAttestation, aSlot uint64) []*Validator

UpdateValidator updates pre computed validator store.

Jump to

Keyboard shortcuts

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