blockchain

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: GPL-3.0 Imports: 49 Imported by: 70

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

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
	AttestationPreState(ctx context.Context, att *ethpb.Attestation) (iface.BeaconState, 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 BlockReceiver

type BlockReceiver interface {
	ReceiveBlock(ctx context.Context, block interfaces.SignedBeaconBlock, blockRoot [32]byte) error
	ReceiveBlockBatch(ctx context.Context, blocks []interfaces.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 added in v1.0.0

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

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

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

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 Ethereum consensus data related to its genesis.

type HeadFetcher

type HeadFetcher interface {
	HeadSlot() types.Slot
	HeadRoot(ctx context.Context) ([]byte, error)
	HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error)
	HeadState(ctx context.Context) (iface.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
	ProtoArrayStore() *protoarray.Store
	ChainHeads() ([][32]byte, []types.Slot)
}

HeadFetcher defines a common interface for methods in blockchain service which directly retrieves head 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) AttestationPreState added in v1.0.0

func (s *Service) AttestationPreState(ctx context.Context, att *ethpb.Attestation) (iface.BeaconState, error)

AttestationPreState returns the pre state of attestation.

func (*Service) ChainHeads added in v1.3.6

func (s *Service) ChainHeads() ([][32]byte, []types.Slot)

ChainHeads returns all possible chain heads (leaves of fork choice tree). Heads roots and heads slots are returned.

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) CurrentSlot added in v0.3.2

func (s *Service) CurrentSlot() types.Slot

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

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

GenesisTime returns the genesis time of beacon chain.

func (*Service) GenesisValidatorRoot added in v1.0.0

func (s *Service) GenesisValidatorRoot() [32]byte

GenesisValidatorRoot returns the genesis validator root of the chain.

func (*Service) HasInitSyncBlock added in v0.3.9

func (s *Service) HasInitSyncBlock(root [32]byte) bool

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 added in v1.0.0

func (s *Service) HeadETH1Data() *ethpb.Eth1Data

HeadETH1Data returns the eth1data of the current head state.

func (*Service) HeadGenesisValidatorRoot added in v1.0.0

func (s *Service) HeadGenesisValidatorRoot() [32]byte

HeadGenesisValidatorRoot returns genesis validator root of the head state.

func (*Service) HeadRoot

func (s *Service) HeadRoot(ctx context.Context) ([]byte, error)

HeadRoot returns the root of the head of the chain.

func (*Service) HeadSeed added in v0.3.0

func (s *Service) HeadSeed(ctx context.Context, epoch types.Epoch) ([32]byte, error)

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

func (*Service) HeadSlot

func (s *Service) HeadSlot() types.Slot

HeadSlot returns the slot of the head of the chain.

func (*Service) HeadState

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

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) HeadValidatorsIndices added in v0.3.0

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 added in v1.0.0

func (s *Service) IsCanonical(ctx context.Context, blockRoot [32]byte) (bool, error)

IsCanonical returns true if the input block root is part of the canonical chain.

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) ProtoArrayStore added in v1.0.0

func (s *Service) ProtoArrayStore() *protoarray.Store

ProtoArrayStore returns the proto array store object.

func (*Service) ReceiveAttestationNoPubsub

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

ReceiveAttestationNoPubsub is a function that defines the operations that are performed 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 interfaces.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:

  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) ReceiveBlockBatch added in v1.0.0

func (s *Service) ReceiveBlockBatch(ctx context.Context, blocks []interfaces.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) 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.

func (*Service) TreeHandler added in v0.3.2

func (s *Service) TreeHandler(w http.ResponseWriter, r *http.Request)

TreeHandler is a handler to serve /tree page in metrics.

func (*Service) VerifyBlkDescendant added in v1.0.0

func (s *Service) VerifyBlkDescendant(ctx context.Context, root [32]byte) error

VerifyBlkDescendant validates input block root is a descendant of the current finalized block root.

func (*Service) VerifyFinalizedConsistency added in v1.0.0

func (s *Service) VerifyFinalizedConsistency(ctx context.Context, root []byte) error

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 added in v1.0.0

func (s *Service) VerifyLmdFfgConsistency(ctx context.Context, a *ethpb.Attestation) error

VerifyLmdFfgConsistency verifies that attestation's LMD and FFG votes are consistency to each other.

func (*Service) VerifyWeakSubjectivityRoot added in v1.0.0

func (s *Service) VerifyWeakSubjectivityRoot(ctx context.Context) error

VerifyWeakSubjectivityRoot verifies the weak subjectivity root in the service struct. Reference design: https://github.com/ethereum/eth2.0-specs/blob/master/specs/phase0/weak-subjectivity.md#weak-subjectivity-sync-procedure

type TimeFetcher added in v0.3.2

type TimeFetcher interface {
	GenesisTime() time.Time
	CurrentSlot() types.Slot
}

TimeFetcher retrieves the Ethereum consensus data that's related to time.

Directories

Path Synopsis
Package testing includes useful mocks for writing unit tests which depend on logic from the blockchain package.
Package testing includes useful mocks for writing unit tests which depend on logic from the blockchain package.

Jump to

Keyboard shortcuts

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