blockchain

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2020 License: GPL-3.0 Imports: 35 Imported by: 90

Documentation

Overview

Package blockchain defines the life-cycle and status of the beacon chain as well as the Ethereum Serenity beacon chain fork-choice rule based on Casper Proof of Stake finality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttestationReceiver

type AttestationReceiver interface {
	ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Attestation) error
}

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
}

BlockReceiver interface defines the methods of chain service receive and processing new blocks.

type CanonicalRootFetcher

type CanonicalRootFetcher interface {
	CanonicalRoot(slot uint64) []byte
}

CanonicalRootFetcher defines a common interface for methods in blockchain service which directly retrieves canonical roots related data.

type ChainInfoFetcher

type ChainInfoFetcher interface {
	HeadFetcher
	CanonicalRootFetcher
	FinalizationFetcher
}

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.Database
	DepositCache      *depositcache.DepositCache
	AttPool           attestations.Pool
	P2p               p2p.Broadcaster
	MaxRoutines       int64
	StateNotifier     statefeed.Notifier
}

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

type ForkFetcher interface {
	CurrentFork() *pb.Fork
}

ForkFetcher retrieves the current fork information of the Ethereum beacon chain.

type GenesisTimeFetcher

type GenesisTimeFetcher interface {
	GenesisTime() time.Time
}

GenesisTimeFetcher retrieves the Eth2 genesis timestamp.

type HeadFetcher

type HeadFetcher interface {
	HeadSlot() uint64
	HeadRoot() []byte
	HeadBlock() *ethpb.SignedBeaconBlock
	HeadState(ctx context.Context) (*pb.BeaconState, error)
	HeadValidatorsIndices(epoch uint64) ([]uint64, error)
	HeadSeed(epoch uint64) ([32]byte, error)
}

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

func NewService(ctx context.Context, cfg *Config) (*Service, error)

NewService instantiates a new block service instance that will be registered into a running beacon node.

func (*Service) CanonicalRoot

func (s *Service) CanonicalRoot(slot uint64) []byte

CanonicalRoot returns the canonical root of a given slot.

func (*Service) CurrentFork

func (s *Service) CurrentFork() *pb.Fork

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) FinalizedCheckpt

func (s *Service) FinalizedCheckpt() *ethpb.Checkpoint

FinalizedCheckpt returns the latest finalized checkpoint from head state.

func (*Service) GenesisTime

func (s *Service) GenesisTime() time.Time

GenesisTime returns the genesis time of beacon chain.

func (*Service) HeadBlock

func (s *Service) HeadBlock() *ethpb.SignedBeaconBlock

HeadBlock returns the head block of the chain.

func (*Service) HeadRoot

func (s *Service) HeadRoot() []byte

HeadRoot returns the root of the head of the chain.

func (*Service) HeadSeed added in v0.3.0

func (s *Service) HeadSeed(epoch uint64) ([32]byte, error)

HeadSeed returns the seed from the head view of a given epoch.

func (*Service) HeadSlot

func (s *Service) HeadSlot() uint64

HeadSlot returns the slot of the head of the chain.

func (*Service) HeadState

func (s *Service) HeadState(ctx context.Context) (*pb.BeaconState, error)

HeadState returns the head state of the chain. If the head state is nil from service struct, it will attempt to get from DB and error if nil again.

func (*Service) HeadValidatorsIndices added in v0.3.0

func (s *Service) HeadValidatorsIndices(epoch uint64) ([]uint64, error)

HeadValidatorsIndices returns a list of active validator indices from the head view of a given epoch.

func (*Service) HeadsHandler

func (s *Service) HeadsHandler(w http.ResponseWriter, _ *http.Request)

HeadsHandler is a handler to serve /heads page in metrics.

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

func (s *Service) ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Attestation) error

ReceiveAttestationNoPubsub is a function that defines the operations that are preformed on attestation that is received from regular sync. The operations consist of:

  1. Validate attestation, update validator's latest vote
  2. Apply fork choice to the processed attestation
  3. Save latest head info

func (*Service) ReceiveBlock

func (s *Service) ReceiveBlock(ctx context.Context, block *ethpb.SignedBeaconBlock) error

ReceiveBlock is a function that defines the operations that are preformed on blocks that is received from rpc service. The operations consists of:

  1. Gossip block to other peers
  2. Validate block, apply state transition and update check points
  3. Apply fork choice to the processed block
  4. Save latest head info

func (*Service) ReceiveBlockNoPubsub

func (s *Service) ReceiveBlockNoPubsub(ctx context.Context, block *ethpb.SignedBeaconBlock) error

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:

  1. Validate block, apply state transition and update check points
  2. Apply fork choice to the processed block
  3. 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:

  1. Validate block, apply state transition and update check points
  2. Save latest head info

func (*Service) ReceiveBlockNoVerify

func (s *Service) ReceiveBlockNoVerify(ctx context.Context, block *ethpb.SignedBeaconBlock) error

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) Start

func (s *Service) Start()

Start a blockchain service's main event loop.

func (*Service) Status

func (s *Service) Status() error

Status always returns nil unless there is an error condition that causes this service to be unhealthy.

func (*Service) Stop

func (s *Service) Stop() error

Stop the blockchain service's main event loop and associated goroutines.

Directories

Path Synopsis
Package forkchoice implements the Latest Message Driven GHOST (Greediest Heaviest Observed Sub-Tree) algorithm as the Ethereum Serenity beacon chain fork choice rule.
Package forkchoice implements the Latest Message Driven GHOST (Greediest Heaviest Observed Sub-Tree) algorithm as the Ethereum Serenity beacon chain fork choice rule.

Jump to

Keyboard shortcuts

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