Documentation ¶
Overview ¶
Package blockchain defines the life-cycle of the blockchain at the core of eth2, including processing of new blocks and attestations using casper proof of stake.
Index ¶
- Variables
- type AttestationReceiver
- type BlockReceiver
- type ChainInfoFetcher
- type Config
- type FinalizationFetcher
- type ForkFetcher
- type GenesisFetcher
- type HeadFetcher
- type ParticipationFetcher
- type Service
- func (s *Service) ClearCachedStates()
- func (s *Service) CurrentFork() *pb.Fork
- func (s *Service) CurrentJustifiedCheckpt() *ethpb.Checkpoint
- func (s *Service) CurrentSlot() uint64
- 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) (*ethpb.SignedBeaconBlock, error)
- func (s *Service) HeadGenesisValidatorRoot() [32]byte
- func (s *Service) HeadRoot(ctx context.Context) ([]byte, error)
- func (s *Service) HeadSeed(epoch uint64) ([32]byte, error)
- func (s *Service) HeadSlot() uint64
- func (s *Service) HeadState(ctx context.Context) (*state.BeaconState, error)
- func (s *Service) HeadValidatorsIndices(epoch uint64) ([]uint64, error)
- func (s *Service) IsValidAttestation(ctx context.Context, att *ethpb.Attestation) bool
- func (s *Service) Participation(epoch uint64) *precompute.Balance
- func (s *Service) PreviousJustifiedCheckpt() *ethpb.Checkpoint
- func (s *Service) ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Attestation) error
- func (s *Service) ReceiveBlock(ctx context.Context, block *ethpb.SignedBeaconBlock) error
- func (s *Service) ReceiveBlockNoPubsub(ctx context.Context, block *ethpb.SignedBeaconBlock) error
- func (s *Service) ReceiveBlockNoPubsubForkchoice(ctx context.Context, block *ethpb.SignedBeaconBlock) error
- func (s *Service) ReceiveBlockNoVerify(ctx context.Context, block *ethpb.SignedBeaconBlock) error
- func (s *Service) Start()
- func (s *Service) Status() error
- func (s *Service) Stop() error
- func (s *Service) TreeHandler(w http.ResponseWriter, _ *http.Request)
- type TimeFetcher
Constants ¶
This section is empty.
Variables ¶
var ErrTargetRootNotInDB = errors.New("target root does not exist in db")
ErrTargetRootNotInDB returns when the target block root of an attestation cannot be found in the beacon database.
Functions ¶
This section is empty.
Types ¶
type AttestationReceiver ¶
type AttestationReceiver interface { ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Attestation) error IsValidAttestation(ctx context.Context, att *ethpb.Attestation) bool }
AttestationReceiver interface defines the methods of chain service receive and processing new attestations.
type BlockReceiver ¶
type BlockReceiver interface { ReceiveBlock(ctx context.Context, block *ethpb.SignedBeaconBlock) error ReceiveBlockNoPubsub(ctx context.Context, block *ethpb.SignedBeaconBlock) error ReceiveBlockNoPubsubForkchoice(ctx context.Context, block *ethpb.SignedBeaconBlock) error ReceiveBlockNoVerify(ctx context.Context, block *ethpb.SignedBeaconBlock) error HasInitSyncBlock(root [32]byte) bool }
BlockReceiver interface defines the methods of chain service receive and processing new blocks.
type ChainInfoFetcher ¶
type ChainInfoFetcher interface { HeadFetcher FinalizationFetcher GenesisFetcher }
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.Pool SlashingPool *slashings.Pool P2p p2p.Broadcaster MaxRoutines int64 StateNotifier statefeed.Notifier ForkChoiceStore f.ForkChoicer OpsService *attestations.Service StateGen *stategen.State }
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 ¶ added in v1.0.0
type GenesisFetcher interface {
GenesisValidatorRoot() [32]byte
}
GenesisFetcher retrieves the eth2 data related to its genesis.
type HeadFetcher ¶
type HeadFetcher interface { HeadSlot() uint64 HeadRoot(ctx context.Context) ([]byte, error) HeadBlock(ctx context.Context) (*ethpb.SignedBeaconBlock, error) HeadState(ctx context.Context) (*state.BeaconState, error) HeadValidatorsIndices(epoch uint64) ([]uint64, error) HeadSeed(epoch uint64) ([32]byte, error) HeadGenesisValidatorRoot() [32]byte }
HeadFetcher defines a common interface for methods in blockchain service which directly retrieves head related data.
type ParticipationFetcher ¶ added in v0.3.0
type ParticipationFetcher interface {
Participation(epoch uint64) *precompute.Balance
}
ParticipationFetcher defines a common interface for methods in blockchain service which directly retrieves validator participation related data.
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) ClearCachedStates ¶ added in v0.3.2
func (s *Service) ClearCachedStates()
ClearCachedStates removes all stored caches states. This is done after the node is synced.
func (*Service) CurrentFork ¶
CurrentFork retrieves the latest fork information of the beacon chain.
func (*Service) CurrentJustifiedCheckpt ¶ added in v0.3.0
func (s *Service) CurrentJustifiedCheckpt() *ethpb.Checkpoint
CurrentJustifiedCheckpt returns the current justified checkpoint from head state.
func (*Service) CurrentSlot ¶ added in v0.3.2
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 ¶ added in v1.0.0
GenesisValidatorRoot returns the genesis validator root of the chain.
func (*Service) HasInitSyncBlock ¶ added in v0.3.9
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 state is nil from service struct, it will attempt to get the head block from DB.
func (*Service) HeadGenesisValidatorRoot ¶ added in v1.0.0
HeadGenesisValidatorRoot returns genesis validator root of the head state.
func (*Service) HeadSeed ¶ added in v0.3.0
HeadSeed returns the seed from the head view of a given epoch.
func (*Service) HeadState ¶
HeadState returns the head state of the chain. If the head state is nil from service struct, it will attempt to get the head state from DB.
func (*Service) HeadValidatorsIndices ¶ added in v0.3.0
HeadValidatorsIndices returns a list of active validator indices from the head view of a given epoch.
func (*Service) IsValidAttestation ¶ added in v0.3.2
IsValidAttestation returns true if the attestation can be verified against its pre-state.
func (*Service) Participation ¶ added in v0.3.0
func (s *Service) Participation(epoch uint64) *precompute.Balance
Participation returns the participation stats of a given epoch.
func (*Service) PreviousJustifiedCheckpt ¶ added in v0.3.0
func (s *Service) PreviousJustifiedCheckpt() *ethpb.Checkpoint
PreviousJustifiedCheckpt returns the previous justified checkpoint from head state.
func (*Service) ReceiveAttestationNoPubsub ¶
ReceiveAttestationNoPubsub is a function that defines the operations that are preformed 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 ¶
ReceiveBlock is a function that defines the operations that are preformed on blocks that is received from rpc service. The operations consists of:
- Gossip block to other peers
- Validate block, apply state transition and update check points
- Apply fork choice to the processed block
- Save latest head info
func (*Service) ReceiveBlockNoPubsub ¶
ReceiveBlockNoPubsub is a function that defines the the operations (minus pubsub) that are preformed 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) ReceiveBlockNoPubsubForkchoice ¶
func (s *Service) ReceiveBlockNoPubsubForkchoice(ctx context.Context, block *ethpb.SignedBeaconBlock) error
ReceiveBlockNoPubsubForkchoice is a function that defines the all operations (minus pubsub and forkchoice) that are preformed blocks that is received from initial sync service. The operations consists of:
- Validate block, apply state transition and update check points
- Save latest head info
func (*Service) ReceiveBlockNoVerify ¶
ReceiveBlockNoVerify runs state transition on a input block without verifying the block's BLS contents. Depends on the security model, this is the "minimal" work a node can do to sync the chain. It simulates light client behavior and assumes 100% trust with the syncing peer.
func (*Service) Status ¶
Status always returns nil unless there is an error condition that causes this service to be unhealthy.
func (*Service) TreeHandler ¶ added in v0.3.2
func (s *Service) TreeHandler(w http.ResponseWriter, _ *http.Request)
TreeHandler is a handler to serve /tree page in metrics.
type TimeFetcher ¶ added in v0.3.2
TimeFetcher retrieves the Eth2 data that's related to time.