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 ¶
- Variables
- func HttpEndpoint(eth1Provider string) network.Endpoint
- type BeaconNodeStatsUpdater
- type Chain
- type ChainInfoFetcher
- type ChainStartFetcher
- type NopBeaconNodeStatsUpdater
- type POWBlockFetcher
- type PowchainCollector
- type RPCClient
- type RPCDataFetcher
- type Service
- func (s *Service) AreAllDepositsProcessed() (bool, error)
- func (s *Service) BlockByTimestamp(ctx context.Context, time uint64) (*types.HeaderInfo, error)
- func (s *Service) BlockExists(ctx context.Context, hash common.Hash) (bool, *big.Int, error)
- func (s *Service) BlockExistsWithCache(ctx context.Context, hash common.Hash) (bool, *big.Int, error)
- func (s *Service) BlockHashByHeight(ctx context.Context, height *big.Int) (common.Hash, error)
- func (s *Service) BlockTimeByHeight(ctx context.Context, height *big.Int) (uint64, error)
- func (s *Service) ChainStartDeposits() []*ethpb.Deposit
- func (s *Service) ChainStartEth1Data() *ethpb.Eth1Data
- func (s *Service) ClearPreGenesisData()
- func (s *Service) DepositRoot() [32]byte
- func (s *Service) DepositTrie() *trie.SparseMerkleTrie
- func (s *Service) Eth2GenesisPowchainInfo() (uint64, *big.Int)
- func (s *Service) IsConnectedToETH1() bool
- func (s *Service) LatestBlockHash() common.Hash
- func (s *Service) LatestBlockHeight() *big.Int
- func (s *Service) PreGenesisState() state.BeaconState
- func (s *Service) ProcessChainStart(genesisTime uint64, eth1BlockHash [32]byte, blockNumber *big.Int)
- func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethTypes.Log) error
- func (s *Service) ProcessETH1Block(ctx context.Context, blkNum *big.Int) error
- func (s *Service) ProcessLog(ctx context.Context, depositLog gethTypes.Log) error
- func (s *Service) Start()
- func (s *Service) Status() error
- func (s *Service) Stop() error
- type Web3ServiceConfig
Constants ¶
This section is empty.
Variables ¶
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 ¶
HttpEndpoint extracts an httputils.Endpoint from the provider parameter.
Types ¶
type BeaconNodeStatsUpdater ¶
type BeaconNodeStatsUpdater interface {
Update(stats clientstats.BeaconNodeStats)
}
type Chain ¶
type Chain interface { ChainStartFetcher ChainInfoFetcher POWBlockFetcher }
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 ¶
func (nop *NopBeaconNodeStatsUpdater) Update(_ clientstats.BeaconNodeStats)
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 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 ¶
AreAllDepositsProcessed determines if all the logs from the deposit contract are processed.
func (*Service) BlockByTimestamp ¶
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 ¶
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 ¶
BlockHashByHeight returns the block hash of the block at the given height.
func (*Service) BlockTimeByHeight ¶
BlockTimeByHeight fetches an eth1.0 block timestamp by its height.
func (*Service) ChainStartDeposits ¶
ChainStartDeposits returns a slice of validator deposit data processed by the deposit contract and cached in the powchain service.
func (*Service) ChainStartEth1Data ¶
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 ¶
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 ¶
Eth2GenesisPowchainInfo retrieves the genesis time and eth1 block number of the beacon chain from the deposit contract.
func (*Service) IsConnectedToETH1 ¶
IsConnectedToETH1 checks if the beacon node is connected to a ETH1 Node.
func (*Service) LatestBlockHash ¶
LatestBlockHash in the ETH1.0 chain.
func (*Service) LatestBlockHeight ¶
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 ¶
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 ¶
ProcessETH1Block processes the logs from the provided eth1Block.
func (*Service) ProcessLog ¶
ProcessLog is the main method which handles the processing of all logs from the deposit contract on the ETH1.0 chain.
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.