beaconclient

package
v0.0.0-...-a4e836c Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package beaconclient provides a beacon-node client

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBeaconNodeSyncing      = errors.New("beacon node is syncing or unavailable")
	ErrBeaconNodesUnavailable = errors.New("all beacon nodes responded with error")
)
View Source
var ErrHTTPErrorResponse = errors.New("got an HTTP error response")

Functions

This section is empty.

Types

type AllValidatorsResponse

type AllValidatorsResponse struct {
	Data []ValidatorResponseEntry
}

type GetBlockResponse

type GetBlockResponse struct {
	Data struct {
		Message struct {
			Slot uint64 `json:"slot,string"`
			Body struct {
				ExecutionPayload types.ExecutionPayload `json:"execution_payload"`
			}
		}
	}
}

type GetHeaderResponse

type GetHeaderResponse struct {
	Data struct {
		Root   string `json:"root"`
		Header struct {
			Message *GetHeaderResponseMessage
		}
	}
}

type GetHeaderResponseMessage

type GetHeaderResponseMessage struct {
	Slot          uint64 `json:"slot,string"`
	ProposerIndex uint64 `json:"proposer_index,string"`
	ParentRoot    string `json:"parent_root"`
}

type GetRandaoResponse

type GetRandaoResponse struct {
	Data struct {
		Randao string `json:"randao"`
	}
}

type GetWithdrawalsResponse

type GetWithdrawalsResponse struct {
	Data struct {
		Withdrawals []*capella.Withdrawal `json:"withdrawals"`
	}
}

type HeadEventData

type HeadEventData struct {
	Slot  uint64 `json:"slot,string"`
	Block string `json:"block"`
	State string `json:"state"`
}

HeadEventData represents the data of a head event {"slot":"827256","block":"0x56b683afa68170c775f3c9debc18a6a72caea9055584d037333a6fe43c8ceb83","state":"0x419e2965320d69c4213782dae73941de802a4f436408fddd6f68b671b3ff4e55","epoch_transition":false,"execution_optimistic":false,"previous_duty_dependent_root":"0x5b81a526839b7fb67c3896f1125451755088fb578ad27c2690b3209f3d7c6b54","current_duty_dependent_root":"0x5f3232c0d5741e27e13754e1d88285c603b07dd6164b35ca57e94344a9e42942"}

type IBeaconInstance

type IBeaconInstance interface {
	SyncStatus() (*SyncStatusPayloadData, error)
	CurrentSlot() (uint64, error)
	SubscribeToHeadEvents(slotC chan HeadEventData)
	SubscribeToPayloadAttributes(payloadAttributesChan chan PayloadAttributesData)
	FetchValidators(headSlot uint64) (map[types.PubkeyHex]ValidatorResponseEntry, error)
	GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error)
	GetURI() string
	GetSlotBlock(slot uint64) (res *common.BeaconBlockMessage, err error)

	GetWithdrawals(slot uint64) (withdrawalsResp *GetWithdrawalsResponse, err error)
	PublishBlock(block *capella.SignedBeaconBlock) (code int, err error)
}

IBeaconInstance is the interface for a single beacon client instance

type IMultiBeaconClient

type IMultiBeaconClient interface {
	BestSyncStatus() (*SyncStatusPayloadData, error)
	SubscribeToHeadEvents(slotC chan HeadEventData)
	SubscribeToPayloadAttributes(payloadAttributesChan chan PayloadAttributesData)

	// FetchValidators returns all active and pending validators from the beacon node
	FetchValidators(headSlot uint64) (map[types.PubkeyHex]ValidatorResponseEntry, error)
	GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error)
	PublishBlock(block *capella.SignedBeaconBlock) (code int, err error)
}

IMultiBeaconClient is the interface for the MultiBeaconClient, which can manage several beacon client instances under the hood

type MockBeaconInstance

type MockBeaconInstance struct {
	MockSyncStatus         *SyncStatusPayloadData
	MockSyncStatusErr      error
	MockProposerDuties     *ProposerDutiesResponse
	MockProposerDutiesErr  error
	MockFetchValidatorsErr error

	ResponseDelay time.Duration
	// contains filtered or unexported fields
}

func NewMockBeaconInstance

func NewMockBeaconInstance() *MockBeaconInstance

func (*MockBeaconInstance) AddValidator

func (c *MockBeaconInstance) AddValidator(entry ValidatorResponseEntry)

func (*MockBeaconInstance) CurrentSlot

func (c *MockBeaconInstance) CurrentSlot() (uint64, error)

func (*MockBeaconInstance) FetchValidators

func (c *MockBeaconInstance) FetchValidators(headSlot uint64) (map[types.PubkeyHex]ValidatorResponseEntry, error)

func (*MockBeaconInstance) GetProposerDuties

func (c *MockBeaconInstance) GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error)

func (*MockBeaconInstance) GetSlotBlock

func (c *MockBeaconInstance) GetSlotBlock(slot uint64) (res *common.BeaconBlockMessage, err error)

func (*MockBeaconInstance) GetURI

func (c *MockBeaconInstance) GetURI() string

func (*MockBeaconInstance) GetWithdrawals

func (c *MockBeaconInstance) GetWithdrawals(slot uint64) (withdrawalsResp *GetWithdrawalsResponse, err error)

func (*MockBeaconInstance) IsValidator

func (c *MockBeaconInstance) IsValidator(pubkey types.PubkeyHex) bool

func (*MockBeaconInstance) NumValidators

func (c *MockBeaconInstance) NumValidators() uint64

func (*MockBeaconInstance) PublishBlock

func (c *MockBeaconInstance) PublishBlock(block *capella.SignedBeaconBlock) (code int, err error)

func (*MockBeaconInstance) SetValidators

func (c *MockBeaconInstance) SetValidators(validatorSet map[types.PubkeyHex]ValidatorResponseEntry)

func (*MockBeaconInstance) SubscribeToHeadEvents

func (c *MockBeaconInstance) SubscribeToHeadEvents(slotC chan HeadEventData)

func (*MockBeaconInstance) SubscribeToPayloadAttributes

func (c *MockBeaconInstance) SubscribeToPayloadAttributes(payloadAttributesChan chan PayloadAttributesData)

func (*MockBeaconInstance) SyncStatus

func (c *MockBeaconInstance) SyncStatus() (*SyncStatusPayloadData, error)

type MultiBeaconClient

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

func NewMultiBeaconClient

func NewMultiBeaconClient(log *logrus.Entry, beaconInstances []IBeaconInstance) *MultiBeaconClient

func (*MultiBeaconClient) BestSyncStatus

func (c *MultiBeaconClient) BestSyncStatus() (*SyncStatusPayloadData, error)

func (*MultiBeaconClient) FetchValidators

func (c *MultiBeaconClient) FetchValidators(headSlot uint64) (map[types.PubkeyHex]ValidatorResponseEntry, error)

func (*MultiBeaconClient) GetBeaconNodeURLs

func (c *MultiBeaconClient) GetBeaconNodeURLs() []string

GetBeaconNodeURLs returns a list of beacon client URLs ordered by last successful client response

func (*MultiBeaconClient) GetProposerDuties

func (c *MultiBeaconClient) GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error)

func (*MultiBeaconClient) GetSlotBlock

func (c *MultiBeaconClient) GetSlotBlock(slot uint64) (res *common.BeaconBlockMessage, err error)

GetSlotBlock - /eth/v2/beacon/blocks/<slot>

func (*MultiBeaconClient) GetWithdrawals

func (c *MultiBeaconClient) GetWithdrawals(slot uint64) (withdrawalsResp *GetWithdrawalsResponse, err error)

GetWithdrawals - 3500/eth/v1/beacon/states/<slot>/withdrawals

func (*MultiBeaconClient) PublishBlock

func (c *MultiBeaconClient) PublishBlock(block *capella.SignedBeaconBlock) (code int, err error)

PublishBlock publishes the signed beacon block via https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/publishBlock

func (*MultiBeaconClient) SubscribeToHeadEvents

func (c *MultiBeaconClient) SubscribeToHeadEvents(slotC chan HeadEventData)

SubscribeToHeadEvents subscribes to head events from all beacon nodes. A single head event will be received multiple times, likely once for every beacon nodes.

func (*MultiBeaconClient) SubscribeToPayloadAttributes

func (c *MultiBeaconClient) SubscribeToPayloadAttributes(payloadAttributesChan chan PayloadAttributesData)

SubscribeToPayloadAttributes subscribes to payload_attributes events from all beacon nodes. A single head event will be received multiple times, likely once for every beacon nodes.

type PayloadAttributes

type PayloadAttributes struct {
	Timestamp             uint64                `json:"timestamp,string"`
	PrevRandao            string                `json:"prev_randao"`
	SuggestedFeeRecipient string                `json:"suggested_fee_recipient"`
	Withdrawals           []*capella.Withdrawal `json:"withdrawals"`
}

type PayloadAttributesData

type PayloadAttributesData struct {
	ProposerIndex     uint64            `json:"proposer_index,string"`
	ProposalSlot      uint64            `json:"proposal_slot,string"`
	ParentBlockNumber uint64            `json:"parent_block_number,string"`
	ParentBlockRoot   string            `json:"parent_block_root"`
	ParentBlockHash   string            `json:"parent_block_hash"`
	PayloadAttributes PayloadAttributes `json:"payload_attributes"`
}

type PayloadAttributesEvent

type PayloadAttributesEvent struct {
	Version string                `json:"version"`
	Data    PayloadAttributesData `json:"data"`
}

type ProdBeaconInstance

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

func NewProdBeaconInstance

func NewProdBeaconInstance(log *logrus.Entry, beaconURI string) *ProdBeaconInstance

func (*ProdBeaconInstance) CurrentSlot

func (c *ProdBeaconInstance) CurrentSlot() (uint64, error)

func (*ProdBeaconInstance) FetchValidators

func (c *ProdBeaconInstance) FetchValidators(headSlot uint64) (map[types.PubkeyHex]ValidatorResponseEntry, error)

func (*ProdBeaconInstance) GetBlock

func (c *ProdBeaconInstance) GetBlock() (*GetBlockResponse, error)

GetBlock returns the latest block - https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockV2

func (*ProdBeaconInstance) GetBlockForSlot

func (c *ProdBeaconInstance) GetBlockForSlot(slot uint64) (*GetBlockResponse, error)

GetBlockForSlot returns the block for a given slot - https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockV2

func (*ProdBeaconInstance) GetHeader

func (c *ProdBeaconInstance) GetHeader() (*GetHeaderResponse, error)

GetHeader returns the latest header - https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockHeader

func (*ProdBeaconInstance) GetHeaderForSlot

func (c *ProdBeaconInstance) GetHeaderForSlot(slot uint64) (*GetHeaderResponse, error)

GetHeaderForSlot returns the header for a given slot - https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockHeader

func (*ProdBeaconInstance) GetProposerDuties

func (c *ProdBeaconInstance) GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error)

GetProposerDuties returns proposer duties for every slot in this epoch https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties

func (*ProdBeaconInstance) GetSlotBlock

func (c *ProdBeaconInstance) GetSlotBlock(slot uint64) (res *common.BeaconBlockMessage, err error)

GetSlotBlock - /eth/v2/beacon/blocks/<slot>

func (*ProdBeaconInstance) GetURI

func (c *ProdBeaconInstance) GetURI() string

func (*ProdBeaconInstance) GetWithdrawals

func (c *ProdBeaconInstance) GetWithdrawals(slot uint64) (withdrawalsResp *GetWithdrawalsResponse, err error)

GetWithdrawals - /eth/v1/beacon/states/<slot>/withdrawals

func (*ProdBeaconInstance) PublishBlock

func (c *ProdBeaconInstance) PublishBlock(block *capella.SignedBeaconBlock) (code int, err error)

func (*ProdBeaconInstance) SubscribeToHeadEvents

func (c *ProdBeaconInstance) SubscribeToHeadEvents(slotC chan HeadEventData)

func (*ProdBeaconInstance) SubscribeToPayloadAttributes

func (c *ProdBeaconInstance) SubscribeToPayloadAttributes(payloadAttributesChan chan PayloadAttributesData)

func (*ProdBeaconInstance) SyncStatus

func (c *ProdBeaconInstance) SyncStatus() (*SyncStatusPayloadData, error)

SyncStatus returns the current node sync-status https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/getSyncingStatus

type ProposerDutiesResponse

type ProposerDutiesResponse struct {
	Data []ProposerDutiesResponseData
}

type ProposerDutiesResponseData

type ProposerDutiesResponseData struct {
	Pubkey string `json:"pubkey"`
	Slot   uint64 `json:"slot,string"`
	Index  uint64 `json:"validator_index,string"`
}

type SyncStatusPayload

type SyncStatusPayload struct {
	Data SyncStatusPayloadData
}

SyncStatusPayload is the response payload for /eth/v1/node/syncing {"data":{"head_slot":"251114","sync_distance":"0","is_syncing":false,"is_optimistic":false}}

type SyncStatusPayloadData

type SyncStatusPayloadData struct {
	HeadSlot  uint64 `json:"head_slot,string"`
	IsSyncing bool   `json:"is_syncing"`
}

type ValidatorResponseEntry

type ValidatorResponseEntry struct {
	Index     uint64                         `json:"index,string"` // Index of validator in validator registry.
	Balance   string                         `json:"balance"`      // Current validator balance in gwei.
	Status    string                         `json:"status"`
	Validator ValidatorResponseValidatorData `json:"validator"`
}

type ValidatorResponseValidatorData

type ValidatorResponseValidatorData struct {
	Pubkey string `json:"pubkey"`
}

Jump to

Keyboard shortcuts

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