powchain

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: GPL-3.0 Imports: 42 Imported by: 55

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

This section is empty.

Types

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 eth2 genesis time.

type ChainStartFetcher

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

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

type Client

Client defines a struct that combines all relevant ETH1.0 mainchain interactions required by the beacon chain node.

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

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

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

type RPCDataFetcher added in v1.0.0

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

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

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

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() *trieutil.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 added in v0.2.3

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

func (s *Service) PreGenesisState() *stateTrie.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 added in v0.2.3

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
}

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