Documentation ¶
Overview ¶
Package blockchain defines the life-cycle of the blockchain at the core of Ethereum, including processing of new blocks and attestations using proof of stake.
Index ¶
- type AttestationReceiver
- type AttestationStateFetcher
- type BlockReceiver
- type CanonicalFetcher
- type ChainInfoFetcher
- type Config
- type FinalizationFetcher
- type ForkFetcher
- type GenesisFetcher
- type HeadDomainFetcher
- type HeadFetcher
- type HeadSyncCommitteeFetcher
- type Service
- func (s *Service) AttestationTargetState(ctx context.Context, target *ethpb.Checkpoint) (state.BeaconState, error)
- func (s *Service) ChainHeads() ([][32]byte, []types.Slot)
- func (s *Service) CurrentFork() *ethpb.Fork
- func (s *Service) CurrentJustifiedCheckpt() *ethpb.Checkpoint
- func (s *Service) CurrentSlot() types.Slot
- func (s *Service) FinalizedCheckpt() *ethpb.Checkpoint
- func (s *Service) GenesisTime() time.Time
- func (s *Service) GenesisValidatorRoot() [32]byte
- func (s *Service) HasInitSyncBlock(root [32]byte) bool
- func (s *Service) HeadBlock(ctx context.Context) (block.SignedBeaconBlock, error)
- func (s *Service) HeadETH1Data() *ethpb.Eth1Data
- func (s *Service) HeadGenesisValidatorRoot() [32]byte
- func (s *Service) HeadPublicKeyToValidatorIndex(ctx context.Context, pubKey [48]byte) (types.ValidatorIndex, bool)
- func (s *Service) HeadRoot(ctx context.Context) ([]byte, error)
- func (s *Service) HeadSeed(ctx context.Context, epoch types.Epoch) ([32]byte, error)
- func (s *Service) HeadSlot() types.Slot
- func (s *Service) HeadState(ctx context.Context) (state.BeaconState, error)
- func (s *Service) HeadSyncCommitteeDomain(ctx context.Context, slot types.Slot) ([]byte, error)
- func (s *Service) HeadSyncCommitteeIndices(ctx context.Context, index types.ValidatorIndex, slot types.Slot) ([]types.CommitteeIndex, error)
- func (s *Service) HeadSyncCommitteePubKeys(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex) ([][]byte, error)
- func (s *Service) HeadSyncContributionProofDomain(ctx context.Context, slot types.Slot) ([]byte, error)
- func (s *Service) HeadSyncSelectionProofDomain(ctx context.Context, slot types.Slot) ([]byte, error)
- func (s *Service) HeadValidatorIndexToPublicKey(_ context.Context, index types.ValidatorIndex) ([48]byte, error)
- func (s *Service) HeadValidatorsIndices(ctx context.Context, epoch types.Epoch) ([]types.ValidatorIndex, error)
- func (s *Service) IsCanonical(ctx context.Context, blockRoot [32]byte) (bool, error)
- func (s *Service) PreviousJustifiedCheckpt() *ethpb.Checkpoint
- func (s *Service) ProtoArrayStore() *protoarray.Store
- func (s *Service) ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Attestation) error
- func (s *Service) ReceiveBlock(ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error
- func (s *Service) ReceiveBlockBatch(ctx context.Context, blocks []block.SignedBeaconBlock, blkRoots [][32]byte) error
- func (s *Service) Start()
- func (s *Service) Status() error
- func (s *Service) Stop() error
- func (s *Service) TreeHandler(w http.ResponseWriter, r *http.Request)
- func (s *Service) VerifyBlkDescendant(ctx context.Context, root [32]byte) error
- func (s *Service) VerifyFinalizedConsistency(ctx context.Context, root []byte) error
- func (s *Service) VerifyLmdFfgConsistency(ctx context.Context, a *ethpb.Attestation) error
- func (s *Service) VerifyWeakSubjectivityRoot(ctx context.Context) error
- type TimeFetcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttestationReceiver ¶
type AttestationReceiver interface { AttestationStateFetcher ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Attestation) error VerifyLmdFfgConsistency(ctx context.Context, att *ethpb.Attestation) error VerifyFinalizedConsistency(ctx context.Context, root []byte) error }
AttestationReceiver interface defines the methods of chain service receive and processing new attestations.
type AttestationStateFetcher ¶
type AttestationStateFetcher interface {
AttestationTargetState(ctx context.Context, target *ethpb.Checkpoint) (state.BeaconState, error)
}
AttestationStateFetcher allows for retrieving a beacon state corresponding to the block root of an attestation's target checkpoint.
type BlockReceiver ¶
type BlockReceiver interface { ReceiveBlock(ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error ReceiveBlockBatch(ctx context.Context, blocks []block.SignedBeaconBlock, blkRoots [][32]byte) error HasInitSyncBlock(root [32]byte) bool }
BlockReceiver interface defines the methods of chain service receive and processing new blocks.
type CanonicalFetcher ¶
type CanonicalFetcher interface { IsCanonical(ctx context.Context, blockRoot [32]byte) (bool, error) VerifyBlkDescendant(ctx context.Context, blockRoot [32]byte) error }
CanonicalFetcher retrieves the current chain's canonical information.
type ChainInfoFetcher ¶
type ChainInfoFetcher interface { HeadFetcher FinalizationFetcher GenesisFetcher CanonicalFetcher ForkFetcher TimeFetcher HeadDomainFetcher }
ChainInfoFetcher defines a common interface for methods in blockchain service which directly retrieves chain info related data.
type Config ¶
type Config struct { BeaconBlockBuf int ChainStartFetcher powchain.ChainStartFetcher BeaconDB db.HeadAccessDatabase DepositCache *depositcache.DepositCache AttPool attestations.Pool ExitPool voluntaryexits.PoolManager SlashingPool slashings.PoolManager P2p p2p.Broadcaster MaxRoutines int StateNotifier statefeed.Notifier ForkChoiceStore f.ForkChoicer AttService *attestations.Service StateGen *stategen.State SlasherAttestationsFeed *event.Feed WeakSubjectivityCheckpt *ethpb.Checkpoint }
Config options for the service.
type FinalizationFetcher ¶
type FinalizationFetcher interface { FinalizedCheckpt() *ethpb.Checkpoint CurrentJustifiedCheckpt() *ethpb.Checkpoint PreviousJustifiedCheckpt() *ethpb.Checkpoint }
FinalizationFetcher defines a common interface for methods in blockchain service which directly retrieves finalization and justification related data.
type ForkFetcher ¶
ForkFetcher retrieves the current fork information of the Ethereum beacon chain.
type GenesisFetcher ¶
type GenesisFetcher interface {
GenesisValidatorRoot() [32]byte
}
GenesisFetcher retrieves the Ethereum consensus data related to its genesis.
type HeadDomainFetcher ¶
type HeadDomainFetcher interface { HeadSyncCommitteeDomain(ctx context.Context, slot types.Slot) ([]byte, error) HeadSyncSelectionProofDomain(ctx context.Context, slot types.Slot) ([]byte, error) HeadSyncContributionProofDomain(ctx context.Context, slot types.Slot) ([]byte, error) }
HeadDomainFetcher is the interface that wraps the head sync domain related functions. The head sync committee domain functions return callers domain data with respect to slot and head state.
type HeadFetcher ¶
type HeadFetcher interface { HeadSlot() types.Slot HeadRoot(ctx context.Context) ([]byte, error) HeadBlock(ctx context.Context) (block.SignedBeaconBlock, error) HeadState(ctx context.Context) (state.BeaconState, error) HeadValidatorsIndices(ctx context.Context, epoch types.Epoch) ([]types.ValidatorIndex, error) HeadSeed(ctx context.Context, epoch types.Epoch) ([32]byte, error) HeadGenesisValidatorRoot() [32]byte HeadETH1Data() *ethpb.Eth1Data HeadPublicKeyToValidatorIndex(ctx context.Context, pubKey [48]byte) (types.ValidatorIndex, bool) HeadValidatorIndexToPublicKey(ctx context.Context, index types.ValidatorIndex) ([48]byte, error) ProtoArrayStore() *protoarray.Store ChainHeads() ([][32]byte, []types.Slot) HeadSyncCommitteeFetcher HeadDomainFetcher }
HeadFetcher defines a common interface for methods in blockchain service which directly retrieves head related data.
type HeadSyncCommitteeFetcher ¶
type HeadSyncCommitteeFetcher interface { HeadSyncCommitteeIndices(ctx context.Context, index types.ValidatorIndex, slot types.Slot) ([]types.CommitteeIndex, error) HeadSyncCommitteePubKeys(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex) ([][]byte, error) }
HeadSyncCommitteeFetcher is the interface that wraps the head sync committee related functions. The head sync committee functions return callers sync committee indices and public keys with respect to current head state.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents a service that handles the internal logic of managing the full PoS beacon chain.
func NewService ¶
NewService instantiates a new block service instance that will be registered into a running beacon node.
func (*Service) AttestationTargetState ¶
func (s *Service) AttestationTargetState(ctx context.Context, target *ethpb.Checkpoint) (state.BeaconState, error)
AttestationTargetState returns the pre state of attestation.
func (*Service) ChainHeads ¶
ChainHeads returns all possible chain heads (leaves of fork choice tree). Heads roots and heads slots are returned.
func (*Service) CurrentFork ¶
CurrentFork retrieves the latest fork information of the beacon chain.
func (*Service) CurrentJustifiedCheckpt ¶
func (s *Service) CurrentJustifiedCheckpt() *ethpb.Checkpoint
CurrentJustifiedCheckpt returns the current justified checkpoint from head state.
func (*Service) CurrentSlot ¶
CurrentSlot returns the current slot based on time.
func (*Service) FinalizedCheckpt ¶
func (s *Service) FinalizedCheckpt() *ethpb.Checkpoint
FinalizedCheckpt returns the latest finalized checkpoint from head state.
func (*Service) GenesisTime ¶
GenesisTime returns the genesis time of beacon chain.
func (*Service) GenesisValidatorRoot ¶
GenesisValidatorRoot returns the genesis validator root of the chain.
func (*Service) HasInitSyncBlock ¶
HasInitSyncBlock returns true if the block of the input root exists in initial sync blocks cache.
func (*Service) HeadBlock ¶
HeadBlock returns the head block of the chain. If the head is nil from service struct, it will attempt to get the head block from DB.
func (*Service) HeadETH1Data ¶
HeadETH1Data returns the eth1data of the current head state.
func (*Service) HeadGenesisValidatorRoot ¶
HeadGenesisValidatorRoot returns genesis validator root of the head state.
func (*Service) HeadPublicKeyToValidatorIndex ¶
func (s *Service) HeadPublicKeyToValidatorIndex(ctx context.Context, pubKey [48]byte) (types.ValidatorIndex, bool)
HeadPublicKeyToValidatorIndex returns the validator index of the `pubkey` in current head state.
func (*Service) HeadState ¶
HeadState returns the head state of the chain. If the head is nil from service struct, it will attempt to get the head state from DB.
func (*Service) HeadSyncCommitteeDomain ¶
HeadSyncCommitteeDomain returns the head sync committee domain using current head state advanced up to `slot`.
func (*Service) HeadSyncCommitteeIndices ¶
func (s *Service) HeadSyncCommitteeIndices(ctx context.Context, index types.ValidatorIndex, slot types.Slot) ([]types.CommitteeIndex, error)
HeadSyncCommitteeIndices returns the sync committee index position using the head state. Input `slot` is taken in consideration where validator's duty for `slot - 1` is used for block inclusion in `slot`. That means when a validator is at epoch boundary across EPOCHS_PER_SYNC_COMMITTEE_PERIOD then the valiator will be considered using next period sync committee.
Spec definition: Being assigned to a sync committee for a given slot means that the validator produces and broadcasts signatures for slot - 1 for inclusion in slot. This means that when assigned to an epoch sync committee signatures must be produced and broadcast for slots on range [compute_start_slot_at_epoch(epoch) - 1, compute_start_slot_at_epoch(epoch) + SLOTS_PER_EPOCH - 1) rather than for the range [compute_start_slot_at_epoch(epoch), compute_start_slot_at_epoch(epoch) + SLOTS_PER_EPOCH)
func (*Service) HeadSyncCommitteePubKeys ¶
func (s *Service) HeadSyncCommitteePubKeys(ctx context.Context, slot types.Slot, committeeIndex types.CommitteeIndex) ([][]byte, error)
HeadSyncCommitteePubKeys returns the head sync committee public keys with respect to `slot` and subcommittee index `committeeIndex`. Head state advanced up to `slot` is used for calculation.
func (*Service) HeadSyncContributionProofDomain ¶
func (s *Service) HeadSyncContributionProofDomain(ctx context.Context, slot types.Slot) ([]byte, error)
HeadSyncContributionProofDomain returns the head sync committee domain using current head state advanced up to `slot`.
func (*Service) HeadSyncSelectionProofDomain ¶
func (s *Service) HeadSyncSelectionProofDomain(ctx context.Context, slot types.Slot) ([]byte, error)
HeadSyncSelectionProofDomain returns the head sync committee domain using current head state advanced up to `slot`.
func (*Service) HeadValidatorIndexToPublicKey ¶
func (s *Service) HeadValidatorIndexToPublicKey(_ context.Context, index types.ValidatorIndex) ([48]byte, error)
HeadValidatorIndexToPublicKey returns the pubkey of the validator `index` in current head state.
func (*Service) HeadValidatorsIndices ¶
func (s *Service) HeadValidatorsIndices(ctx context.Context, epoch types.Epoch) ([]types.ValidatorIndex, error)
HeadValidatorsIndices returns a list of active validator indices from the head view of a given epoch.
func (*Service) IsCanonical ¶
IsCanonical returns true if the input block root is part of the canonical chain.
func (*Service) PreviousJustifiedCheckpt ¶
func (s *Service) PreviousJustifiedCheckpt() *ethpb.Checkpoint
PreviousJustifiedCheckpt returns the previous justified checkpoint from head state.
func (*Service) ProtoArrayStore ¶
func (s *Service) ProtoArrayStore() *protoarray.Store
ProtoArrayStore returns the proto array store object.
func (*Service) ReceiveAttestationNoPubsub ¶
ReceiveAttestationNoPubsub is a function that defines the operations that are performed on attestation that is received from regular sync. The operations consist of:
- Validate attestation, update validator's latest vote
- Apply fork choice to the processed attestation
- Save latest head info
func (*Service) ReceiveBlock ¶
func (s *Service) ReceiveBlock(ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error
ReceiveBlock is a function that defines the the operations (minus pubsub) that are performed on blocks that is received from regular sync service. The operations consists of:
- Validate block, apply state transition and update check points
- Apply fork choice to the processed block
- Save latest head info
func (*Service) ReceiveBlockBatch ¶
func (s *Service) ReceiveBlockBatch(ctx context.Context, blocks []block.SignedBeaconBlock, blkRoots [][32]byte) error
ReceiveBlockBatch processes the whole block batch at once, assuming the block batch is linear ,transitioning the state, performing batch verification of all collected signatures and then performing the appropriate actions for a block post-transition.
func (*Service) Status ¶
Status always returns nil unless there is an error condition that causes this service to be unhealthy.
func (*Service) TreeHandler ¶
func (s *Service) TreeHandler(w http.ResponseWriter, r *http.Request)
TreeHandler is a handler to serve /tree page in metrics.
func (*Service) VerifyBlkDescendant ¶
VerifyBlkDescendant validates input block root is a descendant of the current finalized block root.
func (*Service) VerifyFinalizedConsistency ¶
VerifyFinalizedConsistency verifies input root is consistent with finalized store. When the input root is not be consistent with finalized store then we know it is not on the finalized check point that leads to current canonical chain and should be rejected accordingly.
func (*Service) VerifyLmdFfgConsistency ¶
VerifyLmdFfgConsistency verifies that attestation's LMD and FFG votes are consistency to each other.
func (*Service) VerifyWeakSubjectivityRoot ¶
VerifyWeakSubjectivityRoot verifies the weak subjectivity root in the service struct. Reference design: https://github.com/ethereum/consensus-specs/blob/master/specs/phase0/weak-subjectivity.md#weak-subjectivity-sync-procedure