powchain

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: GPL-3.0 Imports: 49 Imported by: 0

Documentation

Overview

Package powchain defines a runtime service which is tasked with communicating with an eth1 endpoint, processing logs from a deposit contract, and the latest eth1 data headers for usage in the beacon node.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotAHeaderInfo will be returned when a cache object is not a pointer to
	// a headerInfo struct.
	ErrNotAHeaderInfo = errors.New("object is not a header info")
)

Functions

func HttpEndpoint

func HttpEndpoint(eth1Provider string) network.Endpoint

HttpEndpoint extracts an httputils.Endpoint from the provider parameter.

Types

type BeaconNodeStatsUpdater

type BeaconNodeStatsUpdater interface {
	Update(stats clientstats.BeaconNodeStats)
}

type Chain

Chain defines a standard interface for the powchain service in Prysm.

type ChainInfoFetcher

type ChainInfoFetcher interface {
	Eth2GenesisPowchainInfo() (uint64, *big.Int)
	IsConnectedToETH1() bool
}

ChainInfoFetcher retrieves information about eth1 metadata at the Ethereum consensus genesis time.

type ChainStartFetcher

type ChainStartFetcher interface {
	ChainStartDeposits() []*ethpb.Deposit
	ChainStartEth1Data() *ethpb.Eth1Data
	PreGenesisState() state.BeaconState
	ClearPreGenesisData()
}

ChainStartFetcher retrieves information pertaining to the chain start event of the beacon chain for usage across various services.

type NopBeaconNodeStatsUpdater

type NopBeaconNodeStatsUpdater struct{}

func (*NopBeaconNodeStatsUpdater) Update

type POWBlockFetcher

type POWBlockFetcher interface {
	BlockTimeByHeight(ctx context.Context, height *big.Int) (uint64, error)
	BlockByTimestamp(ctx context.Context, time uint64) (*types.HeaderInfo, error)
	BlockHashByHeight(ctx context.Context, height *big.Int) (common.Hash, error)
	BlockExists(ctx context.Context, hash common.Hash) (bool, *big.Int, error)
	BlockExistsWithCache(ctx context.Context, hash common.Hash) (bool, *big.Int, error)
}

POWBlockFetcher defines a struct that can retrieve mainchain blocks.

type PowchainCollector

type PowchainCollector struct {
	SyncEth1Connected          *prometheus.Desc
	SyncEth1FallbackConnected  *prometheus.Desc
	SyncEth1FallbackConfigured *prometheus.Desc // true if flag specified: --fallback-web3provider

	sync.Mutex
	// contains filtered or unexported fields
}

func NewPowchainCollector

func NewPowchainCollector(ctx context.Context) (*PowchainCollector, error)

func (*PowchainCollector) Collect

func (pc *PowchainCollector) Collect(ch chan<- prometheus.Metric)

Collect is invoked by the prometheus collection loop. It returns a set of Metrics representing the observation for the current collection period. In the case of this collector, we use values from the latest BeaconNodeStats value sent by the powchain Service, which updates this value whenever an internal event could change the state of one of the metrics. Describe and Collect together satisfy the prometheus.Collector interface.

func (*PowchainCollector) Describe

func (pc *PowchainCollector) Describe(ch chan<- *prometheus.Desc)

Describe is invoked by the prometheus collection loop. It returns a set of metric Descriptor references which are also used in Collect to group collected metrics into a family. Describe and Collect together satisfy the prometheus.Collector interface.

func (*PowchainCollector) Update

func (pc *PowchainCollector) Update(update clientstats.BeaconNodeStats)

Update satisfies the BeaconNodeStatsUpdater

type RPCClient

type RPCClient interface {
	BatchCall(b []gethRPC.BatchElem) error
}

RPCClient defines the rpc methods required to interact with the eth1 node.

type RPCDataFetcher

type RPCDataFetcher interface {
	HeaderByNumber(ctx context.Context, number *big.Int) (*gethTypes.Header, error)
	HeaderByHash(ctx context.Context, hash common.Hash) (*gethTypes.Header, error)
	SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
}

RPCDataFetcher defines a subset of methods conformed to by ETH1.0 RPC clients for fetching eth1 data from the clients.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service fetches important information about the canonical Ethereum ETH1.0 chain via a web3 endpoint using an ethclient. The Random Beacon Chain requires synchronization with the ETH1.0 chain's current blockhash, block number, and access to logs within the Validator Registration Contract on the ETH1.0 chain to kick off the beacon chain's validator registration process.

func NewService

func NewService(ctx context.Context, config *Web3ServiceConfig) (*Service, error)

NewService sets up a new instance with an ethclient when given a web3 endpoint as a string in the config.

func (*Service) AreAllDepositsProcessed

func (s *Service) AreAllDepositsProcessed() (bool, error)

AreAllDepositsProcessed determines if all the logs from the deposit contract are processed.

func (*Service) BlockByTimestamp

func (s *Service) BlockByTimestamp(ctx context.Context, time uint64) (*types.HeaderInfo, error)

BlockByTimestamp returns the most recent block number up to a given timestamp. This is an optimized version with the worst case being O(2*repeatedSearches) number of calls while in best case search for the block is performed in O(1).

func (*Service) BlockExists

func (s *Service) BlockExists(ctx context.Context, hash common.Hash) (bool, *big.Int, error)

BlockExists returns true if the block exists, its height and any possible error encountered.

func (*Service) BlockExistsWithCache

func (s *Service) BlockExistsWithCache(ctx context.Context, hash common.Hash) (bool, *big.Int, error)

BlockExistsWithCache returns true if the block exists in cache, its height and any possible error encountered.

func (*Service) BlockHashByHeight

func (s *Service) BlockHashByHeight(ctx context.Context, height *big.Int) (common.Hash, error)

BlockHashByHeight returns the block hash of the block at the given height.

func (*Service) BlockTimeByHeight

func (s *Service) BlockTimeByHeight(ctx context.Context, height *big.Int) (uint64, error)

BlockTimeByHeight fetches an eth1.0 block timestamp by its height.

func (*Service) ChainStartDeposits

func (s *Service) ChainStartDeposits() []*ethpb.Deposit

ChainStartDeposits returns a slice of validator deposit data processed by the deposit contract and cached in the powchain service.

func (*Service) ChainStartEth1Data

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

ChainStartEth1Data returns the eth1 data at chainstart.

func (*Service) ClearPreGenesisData

func (s *Service) ClearPreGenesisData()

ClearPreGenesisData clears out the stored chainstart deposits and beacon state.

func (*Service) DepositRoot

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

DepositRoot returns the Merkle root of the latest deposit trie from the ETH1.0 deposit contract.

func (*Service) DepositTrie

func (s *Service) DepositTrie() *trie.SparseMerkleTrie

DepositTrie returns the sparse Merkle trie used for storing deposits from the ETH1.0 deposit contract.

func (*Service) Eth2GenesisPowchainInfo

func (s *Service) Eth2GenesisPowchainInfo() (uint64, *big.Int)

Eth2GenesisPowchainInfo retrieves the genesis time and eth1 block number of the beacon chain from the deposit contract.

func (*Service) IsConnectedToETH1

func (s *Service) IsConnectedToETH1() bool

IsConnectedToETH1 checks if the beacon node is connected to a ETH1 Node.

func (*Service) LatestBlockHash

func (s *Service) LatestBlockHash() common.Hash

LatestBlockHash in the ETH1.0 chain.

func (*Service) LatestBlockHeight

func (s *Service) LatestBlockHeight() *big.Int

LatestBlockHeight in the ETH1.0 chain.

func (*Service) PreGenesisState

func (s *Service) PreGenesisState() state.BeaconState

PreGenesisState returns a state that contains pre-chainstart deposits.

func (*Service) ProcessChainStart

func (s *Service) ProcessChainStart(genesisTime uint64, eth1BlockHash [32]byte, blockNumber *big.Int)

ProcessChainStart processes the log which had been received from the ETH1.0 chain by trying to determine when to start the beacon chain.

func (*Service) ProcessDepositLog

func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethTypes.Log) error

ProcessDepositLog processes the log which had been received from the ETH1.0 chain by trying to ascertain which participant deposited in the contract.

func (*Service) ProcessETH1Block

func (s *Service) ProcessETH1Block(ctx context.Context, blkNum *big.Int) error

ProcessETH1Block processes the logs from the provided eth1Block.

func (*Service) ProcessLog

func (s *Service) ProcessLog(ctx context.Context, depositLog gethTypes.Log) error

ProcessLog is the main method which handles the processing of all logs from the deposit contract on the ETH1.0 chain.

func (*Service) Start

func (s *Service) Start()

Start a web3 service's main event loop.

func (*Service) Status

func (s *Service) Status() error

Status is service health checks. Return nil or error.

func (*Service) Stop

func (s *Service) Stop() error

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

type Web3ServiceConfig

type Web3ServiceConfig struct {
	HttpEndpoints          []string
	DepositContract        common.Address
	BeaconDB               db.HeadAccessDatabase
	DepositCache           *depositcache.DepositCache
	StateNotifier          statefeed.Notifier
	StateGen               *stategen.State
	Eth1HeaderReqLimit     uint64
	BeaconNodeStatsUpdater BeaconNodeStatsUpdater
}

Web3ServiceConfig defines a config struct for web3 service to use through its life cycle.

Directories

Path Synopsis
Package testing provides useful mocks for an eth1 powchain service as needed by unit tests for the beacon node.
Package testing provides useful mocks for an eth1 powchain service as needed by unit tests for the beacon node.

Jump to

Keyboard shortcuts

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