Documentation ¶
Index ¶
- Constants
- func GetActiveValidatorIndices(validators []Validator) []uint32
- func GetDomain(forkData ForkData, slot uint64, domainType uint64) uint64
- func GetNewShuffling(seed chainhash.Hash, validators []Validator, crosslinkingStart int, ...) [][]ShardAndCommittee
- func GetNewValidatorRegistryDeltaChainTip(currentValidatorRegistryDeltaChainTip chainhash.Hash, validatorIndex uint32, ...) (chainhash.Hash, error)
- func MinEmptyValidator(validators []Validator, validatorBalances []uint64, c *config.Config, ...) int
- func ReceiptTypeToMeaning(t uint8) string
- func ShardCommitteeByShardID(shardID uint64, shardCommittees []ShardAndCommittee) ([]uint32, error)
- func ShuffleValidators(toShuffle []uint32, seed chainhash.Hash) []uint32
- func Split(l []uint32, splitCount uint32) [][]uint32
- type Attestation
- type AttestationData
- type AttestationDataAndCustodyBit
- type Block
- type BlockBody
- type BlockHeader
- type BlockView
- type CasperSlashing
- type Crosslink
- type Deposit
- type DepositParameters
- type Exit
- type ForkData
- type PendingAttestation
- type ProposalSignedData
- type ProposerSlashing
- type Receipt
- type ShardAndCommittee
- type SlashableVoteData
- type State
- func (s *State) ActivateValidator(index uint32) error
- func (s *State) ApplyCasperSlashing(casperSlashing CasperSlashing, c *config.Config) error
- func (s *State) ApplyExit(exit Exit, config *config.Config) error
- func (s *State) ApplyProposerSlashing(proposerSlashing ProposerSlashing, config *config.Config) error
- func (s *State) Copy() State
- func (s *State) ExitValidator(index uint32, status uint64, c *config.Config) error
- func (s *State) GetAttestationParticipants(data AttestationData, participationBitfield []byte, c *config.Config, ...) ([]uint32, error)
- func (s *State) GetAttesterCommitteeSize(slot uint64, con *config.Config) uint32
- func (s *State) GetBeaconProposerIndex(stateSlot uint64, slot uint64, c *config.Config) (uint32, error)
- func (s *State) GetCommitteeIndices(stateSlot uint64, slot uint64, shardID uint64, con *config.Config) ([]uint32, error)
- func (s *State) GetEffectiveBalance(index uint32, c *config.Config) uint64
- func (s *State) GetShardCommitteesAtSlot(stateSlot uint64, slot uint64, c *config.Config) ([]ShardAndCommittee, error)
- func (s *State) GetTotalBalance(activeValidators []uint32, c *config.Config) uint64
- func (s *State) GetTotalBalanceMap(activeValidators map[uint32]struct{}, c *config.Config) uint64
- func (s *State) InitiateValidatorExit(index uint32) error
- func (s *State) ProcessBlock(block *Block, con *config.Config, view BlockView, verifySignature bool) error
- func (s *State) ProcessDeposit(pubkey *bls.PublicKey, amount uint64, proofOfPossession [48]byte, ...) (uint32, error)
- func (s *State) ProcessEpochTransition(c *config.Config, view BlockView) ([]Receipt, error)
- func (s *State) ProcessSlot(previousBlockRoot chainhash.Hash, c *config.Config) error
- func (s *State) ProcessSlots(upTo uint64, view BlockView, c *config.Config) error
- func (s *State) ToProto() *pb.State
- func (s *State) UpdateValidatorRegistry(c *config.Config) error
- func (s *State) UpdateValidatorStatus(index uint32, status uint64, c *config.Config) error
- func (s *State) ValidateAttestation(att Attestation, verifySignature bool, view BlockView, c *config.Config, ...) error
- func (s *State) ValidateProofOfPossession(pubkey *bls.PublicKey, proofOfPossession bls.Signature, ...) (bool, error)
- type Validator
- type ValidatorRegistryDeltaBlock
Constants ¶
const ( // ActivationFlag is a flag to indicate a validator is joining ActivationFlag = iota // ExitFlag is a flag to indeicate a validator is leaving ExitFlag )
const ( // AttestedToPreviousEpochJustifiedSlot is a reward when a validator attests to the previous epoch justified slot. AttestedToPreviousEpochJustifiedSlot = iota // AttestedToPreviousEpochBoundaryHash is a reward when a validator attests to the previous epoch boundary hash. AttestedToPreviousEpochBoundaryHash // AttestedToCorrectBlockHashInPreviousEpoch is a reward when a validator attests to the correct beacon block hash for their slot. AttestedToCorrectBlockHashInPreviousEpoch // AttestationInclusionDistanceReward is a reward for including attestations in beacon blocks. AttestationInclusionDistanceReward // DidNotAttestToCorrectBeaconBlock is a penalty for not attesting to the correct beacon block. DidNotAttestToCorrectBeaconBlock // DidNotAttestToPreviousEpochBoundary is a penalty for not attesting to the previous epoch boundary. DidNotAttestToPreviousEpochBoundary // DidNotAttestToPreviousJustifiedSlot is a penalty for not attesting to the previous justified slot. DidNotAttestToPreviousJustifiedSlot // InactivityPenalty is a penalty for being exited with penalty. InactivityPenalty // AttestationInclusionDistancePenalty is a penalty for not including attestations in beacon blocks. AttestationInclusionDistancePenalty // ProposerReward is a reward for the proposer of a beacon block. ProposerReward // AttestationParticipationReward is a reward for choosing the correct shard block hash. AttestationParticipationReward // AttestationNonparticipationPenalty is a penalty for not choosing the correct shard block hash. AttestationNonparticipationPenalty )
const ( // Active is a status for a validator that is active. Active = iota // ActivePendingExit is a status for a validator that is active but pending exit. ActivePendingExit // PendingActivation is a status for a newly added validator PendingActivation // ExitedWithoutPenalty is a validator that gracefully exited ExitedWithoutPenalty // ExitedWithPenalty is a validator that exited not-so-gracefully ExitedWithPenalty )
Variables ¶
This section is empty.
Functions ¶
func GetActiveValidatorIndices ¶
GetActiveValidatorIndices gets validator indices that are active.
func GetNewShuffling ¶
func GetNewShuffling(seed chainhash.Hash, validators []Validator, crosslinkingStart int, con *config.Config) [][]ShardAndCommittee
GetNewShuffling calculates the new shuffling of validators to slots and shards.
func GetNewValidatorRegistryDeltaChainTip ¶
func GetNewValidatorRegistryDeltaChainTip(currentValidatorRegistryDeltaChainTip chainhash.Hash, validatorIndex uint32, pubkey [96]byte, flag uint64) (chainhash.Hash, error)
GetNewValidatorRegistryDeltaChainTip gets the new delta chain tip hash.
func MinEmptyValidator ¶
func MinEmptyValidator(validators []Validator, validatorBalances []uint64, c *config.Config, currentSlot uint64) int
MinEmptyValidator finds the first validator slot that is empty.
func ReceiptTypeToMeaning ¶ added in v0.2.4
ReceiptTypeToMeaning converts a receipt type to a meaningful string.
func ShardCommitteeByShardID ¶
func ShardCommitteeByShardID(shardID uint64, shardCommittees []ShardAndCommittee) ([]uint32, error)
ShardCommitteeByShardID gets the shards committee from a list of committees/shards in a list.
func ShuffleValidators ¶
ShuffleValidators shuffles an array of ints given a seed.
Types ¶
type Attestation ¶
type Attestation struct { // Signed data Data AttestationData // Attester participation bitfield ParticipationBitfield []uint8 // Proof of custody bitfield CustodyBitfield []uint8 // BLS aggregate signature AggregateSig [48]byte }
Attestation is a signed attestation of a shard block.
func AttestationFromProto ¶
func AttestationFromProto(att *pb.Attestation) (*Attestation, error)
AttestationFromProto gets a new attestation from a protobuf attestation message.
func (*Attestation) Copy ¶
func (a *Attestation) Copy() Attestation
Copy returns a copy of the attestation
func (*Attestation) ToProto ¶
func (a *Attestation) ToProto() *pb.Attestation
ToProto gets the protobuf representation of the attestation
type AttestationData ¶
type AttestationData struct { // Slot number Slot uint64 // Shard number Shard uint64 BeaconBlockHash chainhash.Hash EpochBoundaryHash chainhash.Hash ShardBlockHash chainhash.Hash LatestCrosslinkHash chainhash.Hash JustifiedSlot uint64 JustifiedBlockHash chainhash.Hash }
AttestationData is the part of the attestation that is signed.
func AttestationDataFromProto ¶
func AttestationDataFromProto(att *pb.AttestationData) (*AttestationData, error)
AttestationDataFromProto converts the protobuf representation to an attestationdata item.
func (*AttestationData) Copy ¶
func (a *AttestationData) Copy() AttestationData
Copy returns a copy of the data.
func (*AttestationData) Equals ¶
func (a *AttestationData) Equals(other *AttestationData) bool
Equals checks if this attestation data is equal to another.
func (AttestationData) ToProto ¶
func (a AttestationData) ToProto() *pb.AttestationData
ToProto converts the attestation to protobuf form.
type AttestationDataAndCustodyBit ¶
type AttestationDataAndCustodyBit struct { Data AttestationData PoCBit bool }
AttestationDataAndCustodyBit is an attestation data and custody bit combined.
type Block ¶
type Block struct { BlockHeader BlockHeader BlockBody BlockBody }
Block represents a single beacon chain block.
func BlockFromProto ¶
BlockFromProto returns a block from the protobuf representation.
type BlockBody ¶
type BlockBody struct { Attestations []Attestation ProposerSlashings []ProposerSlashing CasperSlashings []CasperSlashing Deposits []Deposit Exits []Exit }
BlockBody contains the beacon actions that happened this block.
func BlockBodyFromProto ¶
BlockBodyFromProto converts a protobuf representation of a block body to a block body.
type BlockHeader ¶
type BlockHeader struct { SlotNumber uint64 ParentRoot chainhash.Hash StateRoot chainhash.Hash RandaoReveal [48]byte Signature [48]byte }
BlockHeader is the header of the block.
func BlockHeaderFromProto ¶
func BlockHeaderFromProto(header *pb.BlockHeader) (*BlockHeader, error)
BlockHeaderFromProto converts a protobuf representation of a block header to a block header.
func (*BlockHeader) Copy ¶
func (bh *BlockHeader) Copy() BlockHeader
Copy returns a copy of the block header.
func (*BlockHeader) ToProto ¶
func (bh *BlockHeader) ToProto() *pb.BlockHeader
ToProto converts to block header to protobuf form.
type BlockView ¶
type BlockView interface { GetHashBySlot(slot uint64) (chainhash.Hash, error) Tip() (chainhash.Hash, error) SetTipSlot(slot uint64) GetLastStateRoot() (chainhash.Hash, error) }
BlockView is an interface the provides access to blocks.
type CasperSlashing ¶
type CasperSlashing struct { Votes1 SlashableVoteData Votes2 SlashableVoteData }
CasperSlashing is a claim to slash based on two votes.
func CasperSlashingFromProto ¶
func CasperSlashingFromProto(slashing *pb.CasperSlashing) (*CasperSlashing, error)
CasperSlashingFromProto returns the casper slashing from the protobuf representation.
func (*CasperSlashing) Copy ¶
func (cs *CasperSlashing) Copy() CasperSlashing
Copy returns a copy of the casper slashing.
func (*CasperSlashing) ToProto ¶
func (cs *CasperSlashing) ToProto() *pb.CasperSlashing
ToProto gets the protobuf representaton of the casper slashing.
type Crosslink ¶
type Crosslink struct { // Slot is the slot within the current dynasty. Slot uint64 // Shard chain block hash ShardBlockHash chainhash.Hash }
Crosslink goes in a collation to represent the last crystallized beacon block.
func CrosslinkFromProto ¶
CrosslinkFromProto gets the crosslink for a protobuf representation
type Deposit ¶
type Deposit struct {
Parameters DepositParameters
}
Deposit is a new deposit from a shard.
func DepositFromProto ¶
DepositFromProto gets the deposit from the protobuf representation.
type DepositParameters ¶
type DepositParameters struct { PubKey [96]byte ProofOfPossession [48]byte WithdrawalCredentials chainhash.Hash }
DepositParameters are the parameters the depositer needs to provide.
func DepositParametersFromProto ¶
func DepositParametersFromProto(parameters *pb.DepositParameters) (*DepositParameters, error)
DepositParametersFromProto gets the deposit parameters from the protobuf representation.
func (*DepositParameters) Copy ¶
func (dp *DepositParameters) Copy() DepositParameters
Copy returns a copy of the deposit parameters
func (*DepositParameters) ToProto ¶
func (dp *DepositParameters) ToProto() *pb.DepositParameters
ToProto gets the protobuf representation of the deposit parameters.
type Exit ¶
Exit exits the validator.
func ExitFromProto ¶
ExitFromProto gets the exit from the protobuf representation.
type ForkData ¶
type ForkData struct { // Previous fork version PreForkVersion uint64 // Post fork version PostForkVersion uint64 // Fork slot number ForkSlotNumber uint64 }
ForkData represents the fork information
func ForkDataFromProto ¶
ForkDataFromProto gets the fork data from the proto representation.
func (*ForkData) GetVersionForSlot ¶
GetVersionForSlot returns the version for a specific slot number.
type PendingAttestation ¶
type PendingAttestation struct { Data AttestationData ParticipationBitfield []byte CustodyBitfield []byte InclusionDelay uint64 ProposerIndex uint32 }
PendingAttestation is an attestation waiting to be included.
func PendingAttestationFromProto ¶
func PendingAttestationFromProto(pa *pb.PendingAttestation) (*PendingAttestation, error)
PendingAttestationFromProto converts a protobuf attestation to a pending attestation.
func (*PendingAttestation) Copy ¶
func (pa *PendingAttestation) Copy() PendingAttestation
Copy copies a pending attestation
func (*PendingAttestation) ToProto ¶
func (pa *PendingAttestation) ToProto() *pb.PendingAttestation
ToProto returns a protobuf representation of the pending attestation.
type ProposalSignedData ¶
ProposalSignedData is a block proposal for a shard or beacon chain.
func ProposalSignedDataFromProto ¶
func ProposalSignedDataFromProto(data *pb.ProposalSignedData) (*ProposalSignedData, error)
ProposalSignedDataFromProto gets the proposal for the protobuf representation.
func (*ProposalSignedData) Copy ¶
func (psd *ProposalSignedData) Copy() ProposalSignedData
Copy returns a copy of the proposal signed data.
func (*ProposalSignedData) ToProto ¶
func (psd *ProposalSignedData) ToProto() *pb.ProposalSignedData
ToProto gets the protobuf representation of a proposal signed data object
type ProposerSlashing ¶
type ProposerSlashing struct { ProposerIndex uint32 ProposalData1 ProposalSignedData ProposalSignature1 [48]byte ProposalData2 ProposalSignedData ProposalSignature2 [48]byte }
ProposerSlashing is a slashing request for a proposal violation.
func ProposerSlashingFromProto ¶
func ProposerSlashingFromProto(slashing *pb.ProposerSlashing) (*ProposerSlashing, error)
ProposerSlashingFromProto gets the proposer slashing from the protobuf representation
func (*ProposerSlashing) Copy ¶
func (ps *ProposerSlashing) Copy() ProposerSlashing
Copy returns a copy of the proposer slashing.
func (*ProposerSlashing) ToProto ¶
func (ps *ProposerSlashing) ToProto() *pb.ProposerSlashing
ToProto gets the protobuf representation of the proposer slashing.
type ShardAndCommittee ¶
type ShardAndCommittee struct { // Shard number Shard uint64 // Validator indices Committee []uint32 // Total validator count (for proofs of custody) TotalValidatorCount uint64 }
ShardAndCommittee keeps track of the validators assigned to a specific shard.
func ShardAndCommitteeFromProto ¶
func ShardAndCommitteeFromProto(committee *pb.ShardCommittee) (*ShardAndCommittee, error)
ShardAndCommitteeFromProto gets the shard and committee for the protobuf representation.
func (*ShardAndCommittee) Copy ¶
func (sc *ShardAndCommittee) Copy() ShardAndCommittee
Copy copies the ShardAndCommittee
func (*ShardAndCommittee) ToProto ¶
func (sc *ShardAndCommittee) ToProto() *pb.ShardCommittee
ToProto gets the protobuf representation of the shard and committee
type SlashableVoteData ¶
type SlashableVoteData struct { AggregateSignaturePoC0Indices []uint32 AggregateSignaturePoC1Indices []uint32 Data AttestationData AggregateSignature [48]byte }
SlashableVoteData is the vote data that should be slashed.
func SlashableVoteDataFromProto ¶
func SlashableVoteDataFromProto(voteData *pb.SlashableVoteData) (*SlashableVoteData, error)
SlashableVoteDataFromProto returns the vote data from the protobuf representation
func (*SlashableVoteData) Copy ¶
func (svd *SlashableVoteData) Copy() SlashableVoteData
Copy returns a copy of the slashable vote data.
func (*SlashableVoteData) ToProto ¶
func (svd *SlashableVoteData) ToProto() *pb.SlashableVoteData
ToProto returns the protobuf representation of the slashable vote data.
type State ¶
type State struct { // MISC ITEMS // Slot is the current slot. Slot uint64 EpochIndex uint64 // GenesisTime is the time of the genesis block. GenesisTime uint64 // ForkData is the versioning data for hard forks. ForkData ForkData // VALIDATOR REGISTRY // ValidatorRegistry is the registry mapping IDs to validators ValidatorRegistry []Validator // ValidatorBalances are the balances corresponding to each validator. ValidatorBalances []uint64 // ValidatorRegistryLatestChangeSlot is the slot where the validator registry // last changed. ValidatorRegistryLatestChangeSlot uint64 // ValidatorRegistryExitCount is the number of validators that are exited. ValidatorRegistryExitCount uint64 // ValidatorSetDeltaHashChange is for light clients to keep track of validator // registry changes. ValidatorRegistryDeltaChainTip chainhash.Hash // RANDOMNESS // RandaoMix is the mix of randao reveals to provide entropy. RandaoMix chainhash.Hash // NextSeed is the next RANDAO seed. NextSeed chainhash.Hash // COMMITTEES // ShardAndCommitteeForSlots is a list of committee members // and their assigned shard, per slot ShardAndCommitteeForSlots [][]ShardAndCommittee // FINALITY PreviousJustifiedSlot uint64 JustifiedSlot uint64 JustificationBitfield uint64 FinalizedSlot uint64 // RECENT STATE LatestCrosslinks []Crosslink LatestBlockHashes []chainhash.Hash LatestPenalizedExitBalances []uint64 LatestAttestations []PendingAttestation BatchedBlockRoots []chainhash.Hash }
State is the state of a beacon block
func StateFromProto ¶
StateFromProto gets the state fromo the protobuf representation.
func (*State) ActivateValidator ¶
ActivateValidator activates a validator in the state at a certain index.
func (*State) ApplyCasperSlashing ¶
func (s *State) ApplyCasperSlashing(casperSlashing CasperSlashing, c *config.Config) error
ApplyCasperSlashing applies a casper slashing claim to the current state.
func (*State) ApplyProposerSlashing ¶
func (s *State) ApplyProposerSlashing(proposerSlashing ProposerSlashing, config *config.Config) error
ApplyProposerSlashing applies a proposer slashing if valid.
func (*State) ExitValidator ¶
ExitValidator handles state changes when a validator exits.
func (*State) GetAttestationParticipants ¶
func (s *State) GetAttestationParticipants(data AttestationData, participationBitfield []byte, c *config.Config, stateSlot uint64) ([]uint32, error)
GetAttestationParticipants gets the indices of participants.
func (*State) GetAttesterCommitteeSize ¶
GetAttesterCommitteeSize gets the size of committee
func (*State) GetBeaconProposerIndex ¶
func (s *State) GetBeaconProposerIndex(stateSlot uint64, slot uint64, c *config.Config) (uint32, error)
GetBeaconProposerIndex gets the validator index of the block proposer at a certain slot.
func (*State) GetCommitteeIndices ¶
func (s *State) GetCommitteeIndices(stateSlot uint64, slot uint64, shardID uint64, con *config.Config) ([]uint32, error)
GetCommitteeIndices gets all of the validator indices involved with the committee assigned to the shard and slot of the committee.
func (*State) GetEffectiveBalance ¶
GetEffectiveBalance gets the effective balance for a validator
func (*State) GetShardCommitteesAtSlot ¶
func (s *State) GetShardCommitteesAtSlot(stateSlot uint64, slot uint64, c *config.Config) ([]ShardAndCommittee, error)
GetShardCommitteesAtSlot gets the committees assigned to a specific slot.
func (*State) GetTotalBalance ¶
GetTotalBalance gets the total balance of the provided validator indices.
func (*State) GetTotalBalanceMap ¶
GetTotalBalanceMap gets the total balance of the provided validator indices with a map input.
func (*State) InitiateValidatorExit ¶
InitiateValidatorExit moves a validator from active to pending exit.
func (*State) ProcessBlock ¶
func (s *State) ProcessBlock(block *Block, con *config.Config, view BlockView, verifySignature bool) error
ProcessBlock tries to apply a block to the state.
func (*State) ProcessDeposit ¶
func (s *State) ProcessDeposit(pubkey *bls.PublicKey, amount uint64, proofOfPossession [48]byte, withdrawalCredentials chainhash.Hash, skipValidation bool, c *config.Config) (uint32, error)
ProcessDeposit processes a deposit with the context of the current state.
func (*State) ProcessEpochTransition ¶
ProcessEpochTransition processes an epoch transition and modifies state.
func (*State) ProcessSlot ¶
ProcessSlot processes a single slot which should happen before the block transition and the epoch transition.
func (*State) ProcessSlots ¶
ProcessSlots uses the current head to process slots up to a certain slot, applying slot transitions and epoch transitions, and returns the updated state. Note that this should only process up to the current slot number so that the lastBlockHash remains constant.
func (*State) UpdateValidatorRegistry ¶
UpdateValidatorRegistry updates the registry and updates validator pending activation or exit.
func (*State) UpdateValidatorStatus ¶
UpdateValidatorStatus moves a validator to a specific status.
func (*State) ValidateAttestation ¶ added in v0.2.4
func (s *State) ValidateAttestation(att Attestation, verifySignature bool, view BlockView, c *config.Config, stateSlot uint64) error
ValidateAttestation checks if the attestation is valid.
type Validator ¶
type Validator struct { // BLS public key Pubkey [96]byte // XXXPubkeyCached is the cached deserialized public key. XXXPubkeyCached *bls.PublicKey // Withdrawal credentials WithdrawalCredentials chainhash.Hash // Status code Status uint64 // Slot when validator last changed status (or 0) LatestStatusChangeSlot uint64 // Sequence number when validator exited (or 0) ExitCount uint64 // LastPoCChangeSlot is the last time the PoC was changed LastPoCChangeSlot uint64 // SecondLastPoCChangeSlot is the second to last time the PoC was changed SecondLastPoCChangeSlot uint64 }
Validator is a single validator session (logging in and out)
func ValidatorFromProto ¶
ValidatorFromProto gets the validator for the protobuf representation
func (*Validator) GetPublicKey ¶
GetPublicKey gets the cached validator pubkey.