beacon

package
v4.0.0-...-ae7b6de Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Overview

Package beacon provides a client for interacting with the standard Eth Beacon Node API. Interactive swagger documentation for the API is available here: https://ethereum.github.io/beacon-APIs/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*client.Client
}

Client provides a collection of helper methods for calling the Eth Beacon Node API endpoints.

func NewClient

func NewClient(host string, opts ...client.ClientOpt) (*Client, error)

NewClient returns a new Client that includes functions for rest calls to Beacon API.

func (*Client) GetBLStoExecutionChanges

func (c *Client) GetBLStoExecutionChanges(ctx context.Context) (*beacon.BLSToExecutionChangesPoolResponse, error)

GetBLStoExecutionChanges gets all the set withdrawal messages in the node's operation pool. Returns a struct representation of json response.

func (*Client) GetBlock

func (c *Client) GetBlock(ctx context.Context, blockId StateOrBlockId) ([]byte, error)

GetBlock retrieves the SignedBeaconBlock for the given block id. Block identifier can be one of: "head" (canonical head in node's view), "genesis", "finalized", <slot>, <hex encoded blockRoot with 0x prefix>. Variables of type StateOrBlockId are exported by this package for the named identifiers. The return value contains the ssz-encoded bytes.

func (*Client) GetBlockRoot

func (c *Client) GetBlockRoot(ctx context.Context, blockId StateOrBlockId) ([32]byte, error)

GetBlockRoot retrieves the hash_tree_root of the BeaconBlock for the given block id. Block identifier can be one of: "head" (canonical head in node's view), "genesis", "finalized", <slot>, <hex encoded blockRoot with 0x prefix>. Variables of type StateOrBlockId are exported by this package for the named identifiers.

func (*Client) GetConfigSpec

func (c *Client) GetConfigSpec(ctx context.Context) (*v1.SpecResponse, error)

GetConfigSpec retrieve the current configs of the network used by the beacon node.

func (*Client) GetFork

func (c *Client) GetFork(ctx context.Context, stateId StateOrBlockId) (*ethpb.Fork, error)

GetFork queries the Beacon Node API for the Fork from the state identified by stateId. Block identifier can be one of: "head" (canonical head in node's view), "genesis", "finalized", <slot>, <hex encoded blockRoot with 0x prefix>. Variables of type StateOrBlockId are exported by this package for the named identifiers.

func (*Client) GetForkSchedule

func (c *Client) GetForkSchedule(ctx context.Context) (forks.OrderedSchedule, error)

GetForkSchedule retrieve all forks, past present and future, of which this node is aware.

func (*Client) GetNodeVersion

func (c *Client) GetNodeVersion(ctx context.Context) (*NodeVersion, error)

GetNodeVersion requests that the beacon node identify information about its implementation in a format similar to a HTTP User-Agent field. ex: Lighthouse/v0.1.5 (Linux x86_64)

func (*Client) GetState

func (c *Client) GetState(ctx context.Context, stateId StateOrBlockId) ([]byte, error)

GetState retrieves the BeaconState for the given state id. State identifier can be one of: "head" (canonical head in node's view), "genesis", "finalized", <slot>, <hex encoded stateRoot with 0x prefix>. Variables of type StateOrBlockId are exported by this package for the named identifiers. The return value contains the ssz-encoded bytes.

func (*Client) GetWeakSubjectivity

func (c *Client) GetWeakSubjectivity(ctx context.Context) (*WeakSubjectivityData, error)

GetWeakSubjectivity calls a proposed API endpoint that is unique to prysm This api method does the following: - computes weak subjectivity epoch - finds the highest non-skipped block preceding the epoch - returns the htr of the found block and returns this + the value of state_root from the block

func (*Client) SubmitChangeBLStoExecution

func (c *Client) SubmitChangeBLStoExecution(ctx context.Context, request []*shared.SignedBLSToExecutionChange) error

SubmitChangeBLStoExecution calls a beacon API endpoint to set the withdrawal addresses based on the given signed messages. If the API responds with something other than OK there will be failure messages associated to the corresponding request message.

type NodeVersion

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

type OriginData

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

OriginData represents the BeaconState and ReadOnlySignedBeaconBlock necessary to start an empty Beacon Node using Checkpoint Sync.

func DownloadFinalizedData

func DownloadFinalizedData(ctx context.Context, client *Client) (*OriginData, error)

DownloadFinalizedData downloads the most recently finalized state, and the block most recently applied to that state. This pair can be used to initialize a new beacon node via checkpoint sync.

func (*OriginData) BlockBytes

func (o *OriginData) BlockBytes() []byte

BlockBytes returns the ssz-encoded bytes of the downloaded ReadOnlySignedBeaconBlock value.

func (*OriginData) SaveBlock

func (o *OriginData) SaveBlock(dir string) (string, error)

SaveBlock saves the downloaded block to a unique file in the given path. For readability and collision avoidance, the file name includes: type, config name, slot and root

func (*OriginData) SaveState

func (o *OriginData) SaveState(dir string) (string, error)

SaveState saves the downloaded state to a unique file in the given path. For readability and collision avoidance, the file name includes: type, config name, slot and root

func (*OriginData) StateBytes

func (o *OriginData) StateBytes() []byte

StateBytes returns the ssz-encoded bytes of the downloaded BeaconState value.

type StateOrBlockId

type StateOrBlockId string

StateOrBlockId represents the block_id / state_id parameters that several of the Eth Beacon API methods accept. StateOrBlockId constants are defined for named identifiers, and helper methods are provided for slot and root identifiers. Example text from the Eth Beacon Node API documentation:

"Block identifier can be one of: "head" (canonical head in node's view), "genesis", "finalized", <slot>, <hex encoded blockRoot with 0x prefix>."

const (
	IdGenesis   StateOrBlockId = "genesis"
	IdHead      StateOrBlockId = "head"
	IdFinalized StateOrBlockId = "finalized"
)

func IdFromRoot

func IdFromRoot(r [32]byte) StateOrBlockId

IdFromRoot encodes a block root in the format expected by the API in places where a root can be used to identify a BeaconState or SignedBeaconBlock.

func IdFromSlot

func IdFromSlot(s primitives.Slot) StateOrBlockId

IdFromSlot encodes a Slot in the format expected by the API in places where a slot can be used to identify a BeaconState or SignedBeaconBlock.

type WeakSubjectivityData

type WeakSubjectivityData struct {
	BlockRoot [32]byte
	StateRoot [32]byte
	Epoch     primitives.Epoch
}

WeakSubjectivityData represents the state root, block root and epoch of the BeaconState + ReadOnlySignedBeaconBlock that falls at the beginning of the current weak subjectivity period. These values can be used to construct a weak subjectivity checkpoint beacon node flag to be used for validation.

func ComputeWeakSubjectivityCheckpoint

func ComputeWeakSubjectivityCheckpoint(ctx context.Context, client *Client) (*WeakSubjectivityData, error)

ComputeWeakSubjectivityCheckpoint attempts to use the prysm weak_subjectivity api to obtain the current weak_subjectivity checkpoint. For non-prysm nodes, the same computation will be performed with extra steps, using the head state downloaded from the beacon node api.

func (*WeakSubjectivityData) CheckpointString

func (wsd *WeakSubjectivityData) CheckpointString() string

CheckpointString returns the standard string representation of a Checkpoint. The format is a hex-encoded block root, followed by the epoch of the block, separated by a colon. For example: "0x1c35540cac127315fabb6bf29181f2ae0de1a3fc909d2e76ba771e61312cc49a:74888"

Jump to

Keyboard shortcuts

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