Documentation ¶
Overview ¶
Package execution 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
- Variables
- func DepositContractAddress() (string, error)
- func HttpEndpoint(eth1Provider string) network.Endpoint
- type BeaconNodeStatsUpdater
- type Chain
- type ChainInfoFetcher
- type ChainStartFetcher
- type EngineCaller
- type ExecutionPayloadReconstructor
- type ForkchoiceUpdatedResponse
- type NopBeaconNodeStatsUpdater
- type Option
- func WithBeaconNodeStatsUpdater(updater BeaconNodeStatsUpdater) Option
- func WithDatabase(database db.HeadAccessDatabase) Option
- func WithDepositCache(cache *depositcache.DepositCache) Option
- func WithDepositContractAddress(addr common.Address) Option
- func WithEth1HeaderRequestLimit(limit uint64) Option
- func WithFinalizedStateAtStartup(st state.BeaconState) Option
- func WithHeaders(headers []string) Option
- func WithHttpEndpoint(endpointString string) Option
- func WithHttpEndpointAndJWTSecret(endpointString string, secret []byte) Option
- func WithStateGen(gen *stategen.State) Option
- func WithStateNotifier(notifier statefeed.Notifier) Option
- type POWBlockFetcher
- type PowchainCollector
- type RPCClient
- type RPCClientEmpty
- type RPCDataFetcher
- type Service
- 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) 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) ChainStartEth1Data() *ethpb.Eth1Data
- func (s *Service) ClearPreGenesisData()
- func (s *Service) ExchangeTransitionConfiguration(ctx context.Context, cfg *pb.TransitionConfiguration) error
- func (s *Service) ExecutionBlockByHash(ctx context.Context, hash common.Hash, withTxs bool) (*pb.ExecutionBlock, error)
- func (s *Service) ExecutionBlocksByHashes(ctx context.Context, hashes []common.Hash, withTxs bool) ([]*pb.ExecutionBlock, error)
- func (s *Service) ExecutionClientConnected() bool
- func (s *Service) ExecutionClientConnectionErr() error
- func (s *Service) ExecutionClientEndpoint() string
- func (s *Service) ForkchoiceUpdated(ctx context.Context, state *pb.ForkchoiceState, attrs *pb.PayloadAttributes) (*pb.PayloadIDBytes, []byte, error)
- func (s *Service) GenesisExecutionChainInfo() (uint64, *big.Int)
- func (s *Service) GetPayload(ctx context.Context, payloadId [8]byte) (*pb.ExecutionPayload, error)
- func (s *Service) GetTerminalBlockHash(ctx context.Context, transitionTime uint64) ([]byte, bool, error)
- func (s *Service) LatestExecutionBlock(ctx context.Context) (*pb.ExecutionBlock, error)
- func (s *Service) NewPayload(ctx context.Context, payload interfaces.ExecutionData) ([]byte, error)
- 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) ReconstructFullBellatrixBlock(ctx context.Context, blindedBlock interfaces.SignedBeaconBlock) (interfaces.SignedBeaconBlock, error)
- func (s *Service) ReconstructFullBellatrixBlockBatch(ctx context.Context, blindedBlocks []interfaces.SignedBeaconBlock) ([]interfaces.SignedBeaconBlock, error)
- func (s *Service) Start()
- func (s *Service) Status() error
- func (s *Service) Stop() error
Constants ¶
const ( // NewPayloadMethod v1 request string for JSON-RPC. NewPayloadMethod = "engine_newPayloadV1" // ForkchoiceUpdatedMethod v1 request string for JSON-RPC. ForkchoiceUpdatedMethod = "engine_forkchoiceUpdatedV1" // GetPayloadMethod v1 request string for JSON-RPC. GetPayloadMethod = "engine_getPayloadV1" // ExchangeTransitionConfigurationMethod v1 request string for JSON-RPC. ExchangeTransitionConfigurationMethod = "engine_exchangeTransitionConfigurationV1" // ExecutionBlockByHashMethod request string for JSON-RPC. ExecutionBlockByHashMethod = "eth_getBlockByHash" // ExecutionBlockByNumberMethod request string for JSON-RPC. ExecutionBlockByNumberMethod = "eth_getBlockByNumber" )
Variables ¶
var ( // ErrParse corresponds to JSON-RPC code -32700. ErrParse = errors.New("invalid JSON was received by the server") // ErrInvalidRequest corresponds to JSON-RPC code -32600. ErrInvalidRequest = errors.New("JSON sent is not valid request object") // ErrMethodNotFound corresponds to JSON-RPC code -32601. ErrMethodNotFound = errors.New("method not found") // ErrInvalidParams corresponds to JSON-RPC code -32602. ErrInvalidParams = errors.New("invalid method parameter(s)") // ErrInternal corresponds to JSON-RPC code -32603. ErrInternal = errors.New("internal JSON-RPC error") // ErrServer corresponds to JSON-RPC code -32000. ErrServer = errors.New("client error while processing request") // ErrUnknownPayload corresponds to JSON-RPC code -38001. ErrUnknownPayload = errors.New("payload does not exist or is not available") // ErrInvalidForkchoiceState corresponds to JSON-RPC code -38002. ErrInvalidForkchoiceState = errors.New("invalid forkchoice state") // ErrInvalidPayloadAttributes corresponds to JSON-RPC code -38003. ErrInvalidPayloadAttributes = errors.New("payload attributes are invalid / inconsistent") // ErrUnknownPayloadStatus when the payload status is unknown. ErrUnknownPayloadStatus = errors.New("unknown payload status") // ErrConfigMismatch when the execution node's terminal total difficulty or // terminal block hash received via the API mismatches Prysm's configuration value. ErrConfigMismatch = errors.New("execution client configuration mismatch") // ErrAcceptedSyncingPayloadStatus when the status of the payload is syncing or accepted. ErrAcceptedSyncingPayloadStatus = errors.New("payload status is SYNCING or ACCEPTED") // ErrInvalidPayloadStatus when the status of the payload is invalid. ErrInvalidPayloadStatus = errors.New("payload status is INVALID") // ErrInvalidBlockHashPayloadStatus when the status of the payload fails to validate block hash. ErrInvalidBlockHashPayloadStatus = errors.New("payload status is INVALID_BLOCK_HASH") // ErrNilResponse when the response is nil. ErrNilResponse = errors.New("nil response") )
var ErrHTTPTimeout = errors.New("timeout from http.Client")
ErrHTTPTimeout returns true if the error is a http.Client timeout error.
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 DepositContractAddress ¶
DepositContractAddress returns the deposit contract address for the given chain.
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 { GenesisExecutionChainInfo() (uint64, *big.Int) ExecutionClientConnected() bool ExecutionClientEndpoint() string ExecutionClientConnectionErr() error }
ChainInfoFetcher retrieves information about eth1 metadata at the Ethereum consensus genesis time.
type ChainStartFetcher ¶
type ChainStartFetcher interface { 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 EngineCaller ¶
type EngineCaller interface { NewPayload(ctx context.Context, payload interfaces.ExecutionData) ([]byte, error) ForkchoiceUpdated( ctx context.Context, state *pb.ForkchoiceState, attrs *pb.PayloadAttributes, ) (*pb.PayloadIDBytes, []byte, error) GetPayload(ctx context.Context, payloadId [8]byte) (*pb.ExecutionPayload, error) ExchangeTransitionConfiguration( ctx context.Context, cfg *pb.TransitionConfiguration, ) error ExecutionBlockByHash(ctx context.Context, hash common.Hash, withTxs bool) (*pb.ExecutionBlock, error) GetTerminalBlockHash(ctx context.Context, transitionTime uint64) ([]byte, bool, error) }
EngineCaller defines a client that can interact with an Ethereum execution node's engine service via JSON-RPC.
type ExecutionPayloadReconstructor ¶
type ExecutionPayloadReconstructor interface { ReconstructFullBellatrixBlock( ctx context.Context, blindedBlock interfaces.SignedBeaconBlock, ) (interfaces.SignedBeaconBlock, error) ReconstructFullBellatrixBlockBatch( ctx context.Context, blindedBlocks []interfaces.SignedBeaconBlock, ) ([]interfaces.SignedBeaconBlock, error) }
ExecutionPayloadReconstructor defines a service that can reconstruct a full beacon block with an execution payload from a signed beacon block and a connection to an execution client's engine API.
type ForkchoiceUpdatedResponse ¶
type ForkchoiceUpdatedResponse struct { Status *pb.PayloadStatus `json:"payloadStatus"` PayloadId *pb.PayloadIDBytes `json:"payloadId"` }
ForkchoiceUpdatedResponse is the response kind received by the engine_forkchoiceUpdatedV1 endpoint.
type NopBeaconNodeStatsUpdater ¶
type NopBeaconNodeStatsUpdater struct{}
func (*NopBeaconNodeStatsUpdater) Update ¶
func (_ *NopBeaconNodeStatsUpdater) Update(_ clientstats.BeaconNodeStats)
type Option ¶
func WithBeaconNodeStatsUpdater ¶
func WithBeaconNodeStatsUpdater(updater BeaconNodeStatsUpdater) Option
WithBeaconNodeStatsUpdater to set the beacon node stats updater.
func WithDatabase ¶
func WithDatabase(database db.HeadAccessDatabase) Option
WithDatabase for the beacon chain database.
func WithDepositCache ¶
func WithDepositCache(cache *depositcache.DepositCache) Option
WithDepositCache for caching deposits.
func WithDepositContractAddress ¶
WithDepositContractAddress for the deposit contract.
func WithEth1HeaderRequestLimit ¶
WithEth1HeaderRequestLimit to set the upper limit of eth1 header requests.
func WithFinalizedStateAtStartup ¶
func WithFinalizedStateAtStartup(st state.BeaconState) Option
WithFinalizedStateAtStartup to set the beacon node's finalized state at startup.
func WithHeaders ¶ added in v3.1.0
WithHeaders adds headers to the execution node JSON-RPC requests.
func WithHttpEndpoint ¶
WithHttpEndpoint parse http endpoint for the powchain service to use.
func WithHttpEndpointAndJWTSecret ¶
WithHttpEndpointAndJWTSecret for authenticating the execution node JSON-RPC endpoint.
func WithStateGen ¶
WithStateGen to regenerate beacon states from checkpoints.
func WithStateNotifier ¶
WithStateNotifier for subscribing to state changes.
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) }
POWBlockFetcher defines a struct that can retrieve mainchain blocks.
type PowchainCollector ¶
type PowchainCollector struct { SyncEth1Connected *prometheus.Desc 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 { Close() BatchCall(b []gethRPC.BatchElem) error CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error }
RPCClient defines the rpc methods required to interact with the eth1 node.
type RPCClientEmpty ¶ added in v3.1.2
type RPCClientEmpty struct { }
func (RPCClientEmpty) BatchCall ¶ added in v3.1.2
func (RPCClientEmpty) BatchCall([]gethRPC.BatchElem) error
func (RPCClientEmpty) CallContext ¶ added in v3.1.2
func (RPCClientEmpty) CallContext(context.Context, interface{}, string, ...interface{}) error
func (RPCClientEmpty) Close ¶ added in v3.1.2
func (RPCClientEmpty) Close()
type RPCDataFetcher ¶
type RPCDataFetcher interface { Close() HeaderByNumber(ctx context.Context, number *big.Int) (*gethTypes.Header, error) HeaderByHash(ctx context.Context, hash common.Hash) (*gethTypes.Header, 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 eth1 chain via a web3 endpoint using an ethclient. The beacon chain requires synchronization with the eth1 chain's current block hash, block number, and access to logs within the Validator Registration Contract on the eth1 chain to kick off the beacon chain's validator registration process.
func NewService ¶
NewService sets up a new instance with an ethclient when given a web3 endpoint as a string in the config.
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) BlockHashByHeight ¶
BlockHashByHeight returns the block hash of the block at the given height.
func (*Service) BlockTimeByHeight ¶
BlockTimeByHeight fetches an eth1 block timestamp by its height.
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) ExchangeTransitionConfiguration ¶
func (s *Service) ExchangeTransitionConfiguration( ctx context.Context, cfg *pb.TransitionConfiguration, ) error
ExchangeTransitionConfiguration calls the engine_exchangeTransitionConfigurationV1 method via JSON-RPC.
func (*Service) ExecutionBlockByHash ¶
func (s *Service) ExecutionBlockByHash(ctx context.Context, hash common.Hash, withTxs bool) (*pb.ExecutionBlock, error)
ExecutionBlockByHash fetches an execution engine block by hash by calling eth_blockByHash via JSON-RPC.
func (*Service) ExecutionBlocksByHashes ¶
func (s *Service) ExecutionBlocksByHashes(ctx context.Context, hashes []common.Hash, withTxs bool) ([]*pb.ExecutionBlock, error)
ExecutionBlocksByHashes fetches a batch of execution engine blocks by hash by calling eth_blockByHash via JSON-RPC.
func (*Service) ExecutionClientConnected ¶
ExecutionClientConnected checks whether are connected via RPC.
func (*Service) ExecutionClientConnectionErr ¶
ExecutionClientConnectionErr returns the error (if any) of the current connection.
func (*Service) ExecutionClientEndpoint ¶
ExecutionClientEndpoint returns the URL of the current, connected execution client.
func (*Service) ForkchoiceUpdated ¶
func (s *Service) ForkchoiceUpdated( ctx context.Context, state *pb.ForkchoiceState, attrs *pb.PayloadAttributes, ) (*pb.PayloadIDBytes, []byte, error)
ForkchoiceUpdated calls the engine_forkchoiceUpdatedV1 method via JSON-RPC.
func (*Service) GenesisExecutionChainInfo ¶
GenesisExecutionChainInfo retrieves the genesis time and execution block number of the beacon chain from the deposit contract.
func (*Service) GetPayload ¶
GetPayload calls the engine_getPayloadV1 method via JSON-RPC.
func (*Service) GetTerminalBlockHash ¶
func (s *Service) GetTerminalBlockHash(ctx context.Context, transitionTime uint64) ([]byte, bool, error)
GetTerminalBlockHash returns the valid terminal block hash based on total difficulty.
Spec code: def get_pow_block_at_terminal_total_difficulty(pow_chain: Dict[Hash32, PowBlock]) -> Optional[PowBlock]:
# `pow_chain` abstractly represents all blocks in the PoW chain for block in pow_chain: parent = pow_chain[block.parent_hash] block_reached_ttd = block.total_difficulty >= TERMINAL_TOTAL_DIFFICULTY parent_reached_ttd = parent.total_difficulty >= TERMINAL_TOTAL_DIFFICULTY if block_reached_ttd and not parent_reached_ttd: return block return None
func (*Service) LatestExecutionBlock ¶
LatestExecutionBlock fetches the latest execution engine block by calling eth_blockByNumber via JSON-RPC.
func (*Service) NewPayload ¶
func (s *Service) NewPayload(ctx context.Context, payload interfaces.ExecutionData) ([]byte, error)
NewPayload calls the engine_newPayloadV1 method via JSON-RPC.
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 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 chain by trying to ascertain which participant deposited in the contract.
func (*Service) ProcessETH1Block ¶
ProcessETH1Block processes logs from the provided eth1 block.
func (*Service) ProcessLog ¶
ProcessLog is the main method which handles the processing of all logs from the deposit contract on the eth1 chain.
func (*Service) ReconstructFullBellatrixBlock ¶
func (s *Service) ReconstructFullBellatrixBlock( ctx context.Context, blindedBlock interfaces.SignedBeaconBlock, ) (interfaces.SignedBeaconBlock, error)
ReconstructFullBellatrixBlock takes in a blinded beacon block and reconstructs a beacon block with a full execution payload via the engine API.
func (*Service) ReconstructFullBellatrixBlockBatch ¶
func (s *Service) ReconstructFullBellatrixBlockBatch( ctx context.Context, blindedBlocks []interfaces.SignedBeaconBlock, ) ([]interfaces.SignedBeaconBlock, error)
ReconstructFullBellatrixBlockBatch takes in a batch of blinded beacon blocks and reconstructs them with a full execution payload for each block via the engine API.