Documentation
¶
Overview ¶
Package beacon provides a client for interacting with Ethereum consensus layer nodes.
Index ¶
- type AttestationEvent
- type BidEvent
- type BlockInfo
- type ChainStatusResult
- type Client
- func (c *Client) Close()
- func (c *Client) Events() *EventStream
- func (c *Client) GetBaseURL() string
- func (c *Client) GetBlockInfo(ctx context.Context, blockID string) (*BlockInfo, error)
- func (c *Client) GetChainStatus(ctx context.Context) (*ChainStatusResult, error)
- func (c *Client) GetCurrentForkVersion(ctx context.Context) (phase0.Version, error)
- func (c *Client) GetExecutionPayloadEnvelope(ctx context.Context, blockID string) (*PayloadEnvelopeInfo, error)
- func (c *Client) GetFinalityInfo(ctx context.Context) (*FinalityInfo, error)
- func (c *Client) GetForkVersion(ctx context.Context) (phase0.Version, error)
- func (c *Client) GetGenesis(ctx context.Context) (*Genesis, error)
- func (c *Client) GetNodeIdentity(ctx context.Context) (*NodeIdentity, error)
- func (c *Client) GetRawClient() eth2client.Service
- func (c *Client) GetRawSpecData(ctx context.Context) (map[string]string, map[string]json.RawMessage, error)
- func (c *Client) GetValidatorIndexToPubkeyMap(ctx context.Context, stateID string) (map[phase0.ValidatorIndex]phase0.BLSPubKey, error)
- func (c *Client) InitGlobalSSZSpecs(ctx context.Context) error
- func (c *Client) SubmitExecutionPayloadBid(ctx context.Context, bid *eth2all.SignedExecutionPayloadBid) error
- func (c *Client) SubmitExecutionPayloadEnvelope(ctx context.Context, envelope json.RawMessage, blobs [][]byte, ...) error
- func (c *Client) SubmitFuluBlock(ctx context.Context, contents *apiv1fulu.SignedBlockContents) error
- func (c *Client) SubmitProposal(ctx context.Context, opts *api.SubmitProposalOpts) error
- func (c *Client) SubmitVoluntaryExit(ctx context.Context, exit *phase0.SignedVoluntaryExit) error
- type EventStream
- func (e *EventStream) CleanupPayloadAttributesCache(beforeSlot phase0.Slot)
- func (e *EventStream) GetLatestPayloadAttributes(slot phase0.Slot) *PayloadAttributesEvent
- func (e *EventStream) Start(ctx context.Context) error
- func (e *EventStream) Stop()
- func (e *EventStream) SubscribeAttestations() *utils.Subscription[*AttestationEvent]
- func (e *EventStream) SubscribeBids() *utils.Subscription[*BidEvent]
- func (e *EventStream) SubscribeHead() *utils.Subscription[*HeadEvent]
- func (e *EventStream) SubscribePayloadAttributes() *utils.Subscription[*PayloadAttributesEvent]
- func (e *EventStream) SubscribePayloadAvailable() *utils.Subscription[*PayloadAvailableEvent]
- func (e *EventStream) SubscribeProposerPreferences() *utils.Subscription[*gloas.SignedProposerPreferences]
- type FinalityInfo
- type Genesis
- type HeadEvent
- type NodeIdentity
- type PayloadAttributesEvent
- type PayloadAvailableEvent
- type PayloadEnvelopeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttestationEvent ¶
type AttestationEvent struct {
AggregationBits []byte
Slot phase0.Slot
Index uint64
BeaconBlockRoot phase0.Root
CommitteeBits []byte // nil for pre-Electra
ReceivedAt time.Time
}
AttestationEvent represents an attestation event from the beacon node.
type BidEvent ¶
type BidEvent struct {
Slot phase0.Slot
ParentBlockHash phase0.Hash32
ParentBlockRoot phase0.Root
BlockHash phase0.Hash32
FeeRecipient [20]byte
GasLimit uint64
BuilderIndex uint64
Value uint64
ExecutionPayment uint64
BlobKZGCommitments [][]byte
Signature phase0.BLSSignature
ReceivedAt time.Time
}
BidEvent represents an execution payload bid event.
type BlockInfo ¶
type BlockInfo struct {
Slot phase0.Slot
Root phase0.Root
ExecutionBlockHash phase0.Hash32
ParentRoot phase0.Root
StateRoot phase0.Root
}
BlockInfo contains execution-relevant information from a beacon block.
type ChainStatusResult ¶
type ChainStatusResult struct {
FinalizedRoot phase0.Root
FinalizedEpoch uint64
HeadRoot phase0.Root
HeadSlot uint64
}
ChainStatusResult holds the head and finality data needed to populate a libp2p StatusV2 message. Fork digest computation is intentionally excluded here — callers that have access to the chain spec (BPO schedule) are responsible for computing it and applying all cumulative BPO XORs.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the consensus layer client for beacon node interactions.
func NewClient ¶
NewClient creates a new CL client connected to the specified beacon node. The client allows delayed start so it can be created even when the beacon node is not yet reachable; callers should retry API calls until the node is ready.
func (*Client) Events ¶
func (c *Client) Events() *EventStream
Events returns the event stream for subscribing to beacon events.
func (*Client) GetBaseURL ¶
GetBaseURL returns the base URL of the beacon node.
func (*Client) GetBlockInfo ¶
GetBlockInfo fetches beacon block info at the given block ID.
It uses the fork-agnostic block type and computes the block root via dynssz, which honours the network's spec (set via InitGlobalSSZSpecs). The versioned type's Root() routes through fastssz code generated for mainnet preset sizes, so it returns wrong roots on non-mainnet presets (e.g. minimal).
func (*Client) GetChainStatus ¶
func (c *Client) GetChainStatus(ctx context.Context) (*ChainStatusResult, error)
GetChainStatus fetches the current chain head and finality data from the beacon node. It does NOT compute the fork digest — use GetCurrentForkVersion alongside the chain spec's BlobSchedule to compute the correct BPO-modified fork digest for StatusV2 messages.
func (*Client) GetCurrentForkVersion ¶
GetCurrentForkVersion fetches the current fork version from the beacon node's head state. This reflects the currently active fork (e.g. Fulu or Gloas), not a future scheduled fork.
func (*Client) GetExecutionPayloadEnvelope ¶
func (c *Client) GetExecutionPayloadEnvelope( ctx context.Context, blockID string, ) (*PayloadEnvelopeInfo, error)
GetExecutionPayloadEnvelope fetches the signed execution payload envelope for a block. The blockID can be a block root (hex), slot number, or "head"/"finalized"/"genesis".
func (*Client) GetFinalityInfo ¶
func (c *Client) GetFinalityInfo(ctx context.Context) (*FinalityInfo, error)
GetFinalityInfo fetches finality checkpoints and returns execution block hashes.
func (*Client) GetForkVersion ¶
GetForkVersion returns the current fork version.
func (*Client) GetGenesis ¶
GetGenesis fetches genesis information from the beacon node via direct HTTP. This bypasses go-eth2-client's active check so it works before the node is fully ready.
func (*Client) GetNodeIdentity ¶
func (c *Client) GetNodeIdentity(ctx context.Context) (*NodeIdentity, error)
GetNodeIdentity fetches the beacon node's P2P identity via /eth/v1/node/identity.
func (*Client) GetRawClient ¶
func (c *Client) GetRawClient() eth2client.Service
GetRawClient returns the underlying eth2client.Service for direct API access.
func (*Client) GetRawSpecData ¶
func (c *Client) GetRawSpecData(ctx context.Context) (map[string]string, map[string]json.RawMessage, error)
GetRawSpecData fetches /eth/v1/config/spec via direct HTTP, bypassing go-eth2-client. Returns both a string map (for simple values) and the raw JSON map (for complex values like BLOB_SCHEDULE).
func (*Client) GetValidatorIndexToPubkeyMap ¶
func (c *Client) GetValidatorIndexToPubkeyMap(ctx context.Context, stateID string) (map[phase0.ValidatorIndex]phase0.BLSPubKey, error)
GetValidatorIndexToPubkeyMap fetches the beacon state once and returns a map of validator index to pubkey. Used to refresh an index→pubkey cache once per epoch instead of querying per payload build.
func (*Client) InitGlobalSSZSpecs ¶
InitGlobalSSZSpecs configures the global dynssz instance with this network's spec values. The go-eth2-client SSZ codecs (e.g. block.Root()) route through dynssz.GetGlobalDynSsz(), which otherwise defaults to mainnet preset sizes — producing wrong hash-tree-roots on minimal-preset networks. We reuse the spec map go-eth2-client already parses (SpecProvider.Spec), which is directly compatible with dynssz.SetGlobalSpecs.
func (*Client) SubmitExecutionPayloadBid ¶
func (c *Client) SubmitExecutionPayloadBid(ctx context.Context, bid *eth2all.SignedExecutionPayloadBid) error
SubmitExecutionPayloadBid submits a signed execution payload bid to the beacon node.
func (*Client) SubmitExecutionPayloadEnvelope ¶
func (c *Client) SubmitExecutionPayloadEnvelope(ctx context.Context, envelope json.RawMessage, blobs [][]byte, kzgProofs [][]byte) error
SubmitExecutionPayloadEnvelope submits a signed execution payload envelope. When blobs and kzg proofs are provided they are wrapped in the SignedExecutionPayloadEnvelopeContents body so the beacon node can derive and broadcast data column sidecars; otherwise the bare signed envelope is sent.
func (*Client) SubmitFuluBlock ¶
func (c *Client) SubmitFuluBlock(ctx context.Context, contents *apiv1fulu.SignedBlockContents) error
SubmitFuluBlock submits a Fulu SignedBlockContents (full unblinded block + blobs) to the beacon node.
func (*Client) SubmitProposal ¶
SubmitProposal submits a full signed proposal (e.g. Fulu SignedBlockContents) to the beacon node. Used by the builder API after unblinding a blinded block.
func (*Client) SubmitVoluntaryExit ¶
SubmitVoluntaryExit submits a signed voluntary exit to the beacon node.
type EventStream ¶
type EventStream struct {
// contains filtered or unexported fields
}
EventStream manages SSE connections to the beacon node event stream.
func NewEventStream ¶
func NewEventStream(client *Client) *EventStream
NewEventStream creates a new event stream for the given client.
func (*EventStream) CleanupPayloadAttributesCache ¶
func (e *EventStream) CleanupPayloadAttributesCache(beforeSlot phase0.Slot)
CleanupPayloadAttributesCache removes cached payload_attributes entries for slots older than beforeSlot.
func (*EventStream) GetLatestPayloadAttributes ¶
func (e *EventStream) GetLatestPayloadAttributes(slot phase0.Slot) *PayloadAttributesEvent
GetLatestPayloadAttributes returns the latest cached payload_attributes event for the given slot, or nil if none has been received.
func (*EventStream) Start ¶
func (e *EventStream) Start(ctx context.Context) error
Start begins listening to beacon node events.
func (*EventStream) SubscribeAttestations ¶
func (e *EventStream) SubscribeAttestations() *utils.Subscription[*AttestationEvent]
SubscribeAttestations returns a subscription for attestation events.
func (*EventStream) SubscribeBids ¶
func (e *EventStream) SubscribeBids() *utils.Subscription[*BidEvent]
SubscribeBids returns a subscription for bid events.
func (*EventStream) SubscribeHead ¶
func (e *EventStream) SubscribeHead() *utils.Subscription[*HeadEvent]
SubscribeHead returns a subscription for head events.
func (*EventStream) SubscribePayloadAttributes ¶
func (e *EventStream) SubscribePayloadAttributes() *utils.Subscription[*PayloadAttributesEvent]
SubscribePayloadAttributes returns a subscription for payload attributes events.
func (*EventStream) SubscribePayloadAvailable ¶
func (e *EventStream) SubscribePayloadAvailable() *utils.Subscription[*PayloadAvailableEvent]
SubscribePayloadAvailable returns a subscription for execution_payload_available events.
func (*EventStream) SubscribeProposerPreferences ¶
func (e *EventStream) SubscribeProposerPreferences() *utils.Subscription[*gloas.SignedProposerPreferences]
SubscribeProposerPreferences returns a subscription for proposer_preferences events.
type FinalityInfo ¶
type FinalityInfo struct {
HeadExecutionBlockHash phase0.Hash32
SafeExecutionBlockHash phase0.Hash32
FinalizedExecutionBlockHash phase0.Hash32
}
FinalityInfo contains finality checkpoint execution block hashes.
type Genesis ¶
type Genesis struct {
GenesisTime time.Time
GenesisValidatorsRoot phase0.Root
GenesisForkVersion phase0.Version
}
Genesis holds genesis information.
type HeadEvent ¶
type HeadEvent struct {
Slot phase0.Slot
Block phase0.Root
State phase0.Root
EpochTransition bool
ExecutionOptimistic bool
PreviousDutyDependentRoot phase0.Root
CurrentDutyDependentRoot phase0.Root
}
HeadEvent represents a head event from the beacon node.
type NodeIdentity ¶
type NodeIdentity struct {
PeerID string `json:"peer_id"`
P2PAddresses []string `json:"p2p_addresses"`
}
NodeIdentity holds the beacon node's P2P identity information.
type PayloadAttributesEvent ¶
type PayloadAttributesEvent struct {
Version string
ProposalSlot phase0.Slot
ProposerIndex phase0.ValidatorIndex
ParentBlockRoot phase0.Root
ParentBlockNumber uint64
ParentBlockHash phase0.Hash32
Timestamp uint64
PrevRandao phase0.Root
SuggestedFeeRecipient common.Address
Withdrawals []*capella.Withdrawal
ParentBeaconBlockRoot phase0.Root
TargetGasLimit uint64
InclusionListTransactions [][]byte
}
PayloadAttributesEvent represents a payload_attributes event from the beacon node. This is emitted when a validator is scheduled to propose and contains all parameters needed for building an execution payload.
type PayloadAvailableEvent ¶
type PayloadAvailableEvent struct {
Slot phase0.Slot
BlockRoot phase0.Root // Beacon block root this payload belongs to
ReceivedAt time.Time
}
PayloadAvailableEvent represents an execution_payload_available event (Gloas). This is emitted when the node has verified that the execution payload and blobs for a block are available and ready for payload attestation.