networking

package
v0.0.0-...-f0f0ab8 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RequestFailedError = "GET %s failed. Error: %v"
	ReadBodyError      = "read contents of response failed. Error: %v"
	BadResponseError   = "GET %s failed. Status code: %d. Body: %s"
)
View Source
const (
	FinalizedCkptTopic = "/eth/v1/events?topics=finalized_checkpoint"
)

Variables

This section is empty.

Functions

func Subscribe

func Subscribe(done <-chan struct{}, sub SubscribeOpts) <-chan Checkpoint

Subscribe : Setup subscriptions to beacon chain events using several beacon node endpoints.

params :- a. done <- chan struct{} Channel to get stop listening signal from b. sub SubscribeOpts Subscription data and handlers

returns :- a. <-chan Checkpoint Channel to get new checkpoints from

Types

type BeaconAPI

type BeaconAPI interface {
	SetEndpoints(endpoints []string)
	ValidatorBalances(stateID string, validatorIdxs []string) ([]ValidatorBalance, error)
	Health(endpoints []string) []HealthResponse
	SyncStatus(endpoints []string) []BeaconSyncingStatus
}

BeaconAPI : Interface for Beacon chain HTTP API

type BeaconClient

type BeaconClient struct {
	// Beacon node endpoint to connect to. Probably needs to change when support for several endpoints is added
	Endpoint string
	// Time between retries when a request fails
	RetryDuration time.Duration
}

BeaconClient : Struct BeaconAPI interface implementation

func (*BeaconClient) Health

func (bc *BeaconClient) Health(endpoints []string) []HealthResponse

Health : Health check to the given endpoints using the API method '/eth/v1/beacon/health'.

params :- a. endpoints []string Endpoints to check

returns :- a. []HealthResponse Health responses from the given endpoints

func (*BeaconClient) SetEndpoints

func (bc *BeaconClient) SetEndpoints(endpoints []string)

SetEndpoints : Set the endpoints for the beacon client implementation.

params :- a. endpoints []string Endpoints to set for the beacon client

returns :- none

func (*BeaconClient) SyncStatus

func (bc *BeaconClient) SyncStatus(endpoints []string) []BeaconSyncingStatus

SyncStatus : Check sync status of the given endpoints using the API method '/eth/v1/node/syncing'.

params :- a. endpoints []string Endpoints to check

returns :- a. []BeaconSyncingStatus Sync status of the given endpoints

func (*BeaconClient) ValidatorBalances

func (bc *BeaconClient) ValidatorBalances(stateID string, validatorIdxs []string) ([]ValidatorBalance, error)

ValidatorBalances : Get the validator balances for the given checkpoint.

params :- a. stateID string Blockchain state ID from when to get the balances b. validatorIdxs []string Validator indexes to get the balances for

returns :- a. []ValidatorBalance Validator balances fetched from the beacon node b. error Error if any

type BeaconSyncingStatus

type BeaconSyncingStatus struct {
	HeadSlot     string `json:"head_slot"`
	SyncDistance string `json:"sync_distance"`
	IsSyncing    bool   `json:"is_syncing"`
	Error        error
	Endpoint     string
}

BeaconSyncingStatus : Struct Represent response data from 'http://<endpoint>/eth/v1/node/syncing' API call

type BeaconSyncingStatusResponse

type BeaconSyncingStatusResponse struct {
	Data BeaconSyncingStatus `json:"data"`
}

BeaconSyncingStatusResponse : Struct Represent response body from 'http://<endpoint>/eth/v1/node/syncing' API call

type Checkpoint

type Checkpoint struct {
	Block string `json:"block"`
	State string `json:"state"`
	Epoch string `json:"epoch"`
}

Checkpoint : Struct Represent event data from beacon chain

type Eth1Error

type Eth1Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (Eth1Error) Error

func (err Eth1Error) Error() string

type ExecutionAPI

type ExecutionAPI interface {
	Call(endpoint, method string, params ...any) (json.RawMessage, error)
	SyncStatus(endpoints []string) []ExecutionSyncingStatus
}

ExecutionAPI : Interface for ETH1 JSON RPC API

type ExecutionClient

type ExecutionClient struct {
	// Time between retries when a request fails
	RetryDuration time.Duration
}

ExecutionClient : Struct ExecutionAPI interface implementation

func (*ExecutionClient) Call

func (ec *ExecutionClient) Call(endpoint, method string, params ...any) (json.RawMessage, error)

Inspired by https://github.com/onrik/ethrpc/blob/master/ethrpc.go

Call : Logic for calling a ETH json-rpc method.

params :- a. method string

b. params []any

returns :- a. json.RawMessage Result field of the json response b. error Error if any

func (*ExecutionClient) SyncStatus

func (ec *ExecutionClient) SyncStatus(endpoints []string) []ExecutionSyncingStatus

SyncStatus : Check sync status of the execution client using the json-rpc API method 'eth_syncing'.

params :- none

returns :- a. ExecutionSyncingStatus Sync status of the execution client

type ExecutionSyncingStatus

type ExecutionSyncingStatus struct {
	StartingBlock string `json:"startingBloc"`
	CurrentBlock  string `json:"currentBlock"`
	HighestBlock  string `json:"highestBlock"`
	IsSyncing     bool
	Error         error
	Endpoint      string
}

ExecutionSyncingStatus : Struct Represent response data from 'eth_syncing' json-rpc API call

type HealthResponse

type HealthResponse struct {
	Endpoint string
	Healthy  bool
	Error    error
}

HealthResponse : Struct Represent response information from 'http://<endpoint>/eth/v1/beacon/health' API call

type SSESubscriber

type SSESubscriber struct {
}

SSESubscriber : Struct Subscriber interface implementation

func (SSESubscriber) Listen

func (s SSESubscriber) Listen(url string, ch chan<- Checkpoint)

Listen : Subscribe to beacon chain SSE events and listen for new beacon chain checkpoints.

params :- a. url string URL to subscribe to b. ch chan<- Checkpoint Channel to send new checkpoints to

returns :- none

type SubscribeOpts

type SubscribeOpts struct {
	// Endpoints exposing beacon chain API
	Endpoints []string
	// URL and topic to subscribe to within an endpoint
	StreamURL string
	// Interface with Listen implementation to subscribe to beacon chain events
	Subscriber Subscriber
}

SubscribeOpts : Struct Represent subscription data and handlers

type Subscriber

type Subscriber interface {
	Listen(url string, ch chan<- Checkpoint)
}

Subscriber : Interface Represents a subscriber for a given topic

type ValidatorBalance

type ValidatorBalance struct {
	Index   string `json:"index"`
	Balance string `json:"balance"`
}

ValidatorBalance : Struct Represent a single entry of response data from 'http://<endpoint>/eth/v1/beacon/states/<stateID>/validator_balances' API call

type ValidatorBalanceList

type ValidatorBalanceList struct {
	Data []ValidatorBalance `json:"data"`
}

ValidatorBalanceList : Struct Represent response data from 'http://<endpoint>/eth/v1/beacon/states/<stateID>/validator_balances' API call

Jump to

Keyboard shortcuts

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