executionclient

package
v2.4.1-0...-73c2ea3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package executionclient implements functions for interacting with Ethereum execution clients.

Package executionclient is a generated GoMock package.

Index

Constants

View Source
const (
	DefaultReqTimeout    = 10 * time.Second
	DefaultReqRetryDelay = 10 * time.Second

	DefaultFollowDistance = 8

	DefaultHealthInvalidationInterval = 10 * time.Second

	DefaultSyncDistanceTolerance = 5
)

Variables

View Source
var (
	ErrClosed        = fmt.Errorf("closed")
	ErrBadInput      = fmt.Errorf("bad input")
	ErrNothingToSync = fmt.Errorf("nothing to sync")
	ErrSyncing       = fmt.Errorf("syncing")
)

Functions

This section is empty.

Types

type BlockLogs

type BlockLogs struct {
	BlockNumber uint64
	Logs        []ethtypes.Log
}

BlockLogs holds a block's number and it's logs.

func PackLogs

func PackLogs(logs []ethtypes.Log) []BlockLogs

PackLogs packs logs into []BlockLogs by their block number.

type ExecutionClient

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

ExecutionClient represents a client for interacting with Ethereum execution client.

func New

func New(ctx context.Context, nodeAddr string, contractAddr ethcommon.Address, opts ...Option) (*ExecutionClient, error)

New creates a new instance of ExecutionClient.

func (*ExecutionClient) Address

func (ec *ExecutionClient) Address() string

func (*ExecutionClient) ChainID

func (ec *ExecutionClient) ChainID(ctx context.Context) (*big.Int, error)

func (*ExecutionClient) Close

func (ec *ExecutionClient) Close() error

Close shuts down ExecutionClient.

func (*ExecutionClient) FetchHistoricalLogs

func (ec *ExecutionClient) FetchHistoricalLogs(ctx context.Context, fromBlock uint64) (
	logsCh <-chan BlockLogs,
	errsCh <-chan error,
	err error,
)

FetchHistoricalLogs retrieves historical logs emitted by the contract starting from fromBlock.

func (*ExecutionClient) FilterLogs

func (ec *ExecutionClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethtypes.Log, error)

func (*ExecutionClient) Filterer

func (ec *ExecutionClient) Filterer() (*contract.ContractFilterer, error)

func (*ExecutionClient) HeaderByNumber

func (ec *ExecutionClient) HeaderByNumber(ctx context.Context, blockNumber *big.Int) (*ethtypes.Header, error)

func (*ExecutionClient) Healthy

func (ec *ExecutionClient) Healthy(ctx context.Context) error

Healthy returns if execution client is currently healthy: responds to requests and not in the syncing state.

func (*ExecutionClient) StreamLogs

func (ec *ExecutionClient) StreamLogs(ctx context.Context, fromBlock uint64) (logsCh chan BlockLogs)

StreamLogs subscribes to events emitted by the Ethereum SSV contract(s) starting at fromBlock. It spawns a go-routine that spins in a perpetual retry loop, terminating only on unrecoverable interruptions (such as context cancels, client closure, etc.) as defined by isSingleClientInterruptedError func. The logsCh is closed once the streaming go-routine terminates. Any errors encountered during streaming are logged.

func (*ExecutionClient) SubscribeFilterLogs

func (ec *ExecutionClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- ethtypes.Log) (ethereum.Subscription, error)

func (*ExecutionClient) SyncProgress

func (ec *ExecutionClient) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)

type MockProvider

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

MockProvider is a mock of Provider interface.

func NewMockProvider

func NewMockProvider(ctrl *gomock.Controller) *MockProvider

NewMockProvider creates a new mock instance.

func (*MockProvider) ChainID

func (m *MockProvider) ChainID(ctx context.Context) (*big.Int, error)

ChainID mocks base method.

func (*MockProvider) Close

func (m *MockProvider) Close() error

Close mocks base method.

func (*MockProvider) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockProvider) FetchHistoricalLogs

func (m *MockProvider) FetchHistoricalLogs(ctx context.Context, fromBlock uint64) (<-chan BlockLogs, <-chan error, error)

FetchHistoricalLogs mocks base method.

func (*MockProvider) FilterLogs

func (m *MockProvider) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)

FilterLogs mocks base method.

func (*MockProvider) Filterer

func (m *MockProvider) Filterer() (*contract.ContractFilterer, error)

Filterer mocks base method.

func (*MockProvider) HeaderByNumber

func (m *MockProvider) HeaderByNumber(ctx context.Context, blockNumber *big.Int) (*types.Header, error)

HeaderByNumber mocks base method.

func (*MockProvider) Healthy

func (m *MockProvider) Healthy(ctx context.Context) error

Healthy mocks base method.

func (*MockProvider) StreamLogs

func (m *MockProvider) StreamLogs(ctx context.Context, fromBlock uint64) chan BlockLogs

StreamLogs mocks base method.

func (*MockProvider) SubscribeFilterLogs

func (m *MockProvider) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs mocks base method.

type MockProviderMockRecorder

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

MockProviderMockRecorder is the mock recorder for MockProvider.

func (*MockProviderMockRecorder) ChainID

func (mr *MockProviderMockRecorder) ChainID(ctx any) *gomock.Call

ChainID indicates an expected call of ChainID.

func (*MockProviderMockRecorder) Close

func (mr *MockProviderMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockProviderMockRecorder) FetchHistoricalLogs

func (mr *MockProviderMockRecorder) FetchHistoricalLogs(ctx, fromBlock any) *gomock.Call

FetchHistoricalLogs indicates an expected call of FetchHistoricalLogs.

func (*MockProviderMockRecorder) FilterLogs

func (mr *MockProviderMockRecorder) FilterLogs(ctx, q any) *gomock.Call

FilterLogs indicates an expected call of FilterLogs.

func (*MockProviderMockRecorder) Filterer

func (mr *MockProviderMockRecorder) Filterer() *gomock.Call

Filterer indicates an expected call of Filterer.

func (*MockProviderMockRecorder) HeaderByNumber

func (mr *MockProviderMockRecorder) HeaderByNumber(ctx, blockNumber any) *gomock.Call

HeaderByNumber indicates an expected call of HeaderByNumber.

func (*MockProviderMockRecorder) Healthy

func (mr *MockProviderMockRecorder) Healthy(ctx any) *gomock.Call

Healthy indicates an expected call of Healthy.

func (*MockProviderMockRecorder) StreamLogs

func (mr *MockProviderMockRecorder) StreamLogs(ctx, fromBlock any) *gomock.Call

StreamLogs indicates an expected call of StreamLogs.

func (*MockProviderMockRecorder) SubscribeFilterLogs

func (mr *MockProviderMockRecorder) SubscribeFilterLogs(ctx, q, ch any) *gomock.Call

SubscribeFilterLogs indicates an expected call of SubscribeFilterLogs.

type MockSingleClientProvider

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

MockSingleClientProvider is a mock of SingleClientProvider interface.

func NewMockSingleClientProvider

func NewMockSingleClientProvider(ctrl *gomock.Controller) *MockSingleClientProvider

NewMockSingleClientProvider creates a new mock instance.

func (*MockSingleClientProvider) ChainID

func (m *MockSingleClientProvider) ChainID(ctx context.Context) (*big.Int, error)

ChainID mocks base method.

func (*MockSingleClientProvider) Close

func (m *MockSingleClientProvider) Close() error

Close mocks base method.

func (*MockSingleClientProvider) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSingleClientProvider) FetchHistoricalLogs

func (m *MockSingleClientProvider) FetchHistoricalLogs(ctx context.Context, fromBlock uint64) (<-chan BlockLogs, <-chan error, error)

FetchHistoricalLogs mocks base method.

func (*MockSingleClientProvider) FilterLogs

FilterLogs mocks base method.

func (*MockSingleClientProvider) Filterer

Filterer mocks base method.

func (*MockSingleClientProvider) HeaderByNumber

func (m *MockSingleClientProvider) HeaderByNumber(ctx context.Context, blockNumber *big.Int) (*types.Header, error)

HeaderByNumber mocks base method.

func (*MockSingleClientProvider) Healthy

Healthy mocks base method.

func (*MockSingleClientProvider) StreamLogs

func (m *MockSingleClientProvider) StreamLogs(ctx context.Context, fromBlock uint64) chan BlockLogs

StreamLogs mocks base method.

func (*MockSingleClientProvider) SubscribeFilterLogs

func (m *MockSingleClientProvider) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs mocks base method.

func (*MockSingleClientProvider) SyncProgress

SyncProgress mocks base method.

type MockSingleClientProviderMockRecorder

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

MockSingleClientProviderMockRecorder is the mock recorder for MockSingleClientProvider.

func (*MockSingleClientProviderMockRecorder) ChainID

ChainID indicates an expected call of ChainID.

func (*MockSingleClientProviderMockRecorder) Close

Close indicates an expected call of Close.

func (*MockSingleClientProviderMockRecorder) FetchHistoricalLogs

func (mr *MockSingleClientProviderMockRecorder) FetchHistoricalLogs(ctx, fromBlock any) *gomock.Call

FetchHistoricalLogs indicates an expected call of FetchHistoricalLogs.

func (*MockSingleClientProviderMockRecorder) FilterLogs

func (mr *MockSingleClientProviderMockRecorder) FilterLogs(ctx, q any) *gomock.Call

FilterLogs indicates an expected call of FilterLogs.

func (*MockSingleClientProviderMockRecorder) Filterer

Filterer indicates an expected call of Filterer.

func (*MockSingleClientProviderMockRecorder) HeaderByNumber

func (mr *MockSingleClientProviderMockRecorder) HeaderByNumber(ctx, blockNumber any) *gomock.Call

HeaderByNumber indicates an expected call of HeaderByNumber.

func (*MockSingleClientProviderMockRecorder) Healthy

Healthy indicates an expected call of Healthy.

func (*MockSingleClientProviderMockRecorder) StreamLogs

func (mr *MockSingleClientProviderMockRecorder) StreamLogs(ctx, fromBlock any) *gomock.Call

StreamLogs indicates an expected call of StreamLogs.

func (*MockSingleClientProviderMockRecorder) SubscribeFilterLogs

func (mr *MockSingleClientProviderMockRecorder) SubscribeFilterLogs(ctx, q, ch any) *gomock.Call

SubscribeFilterLogs indicates an expected call of SubscribeFilterLogs.

func (*MockSingleClientProviderMockRecorder) SyncProgress

func (mr *MockSingleClientProviderMockRecorder) SyncProgress(ctx any) *gomock.Call

SyncProgress indicates an expected call of SyncProgress.

type MultiClient

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

MultiClient wraps several execution clients and uses the current available one.

There are several scenarios of node outage:

1) SSV node uses EL1, EL2, CL1, CL2; CL1 uses only EL1, CL2 uses only EL2. EL1 becomes unavailable.

The execution client MultiClient switches to EL2, consensus multi client (another package) remains on CL1. CL1 remains available and responds to requests but its syncing distance increases until EL1 is up. The consensus multi client cannot determine that it's unhealthy until the sync distance reaches SyncDistanceTolerance, but when it does, it switches to CL2 and then SSV node uses EL2 and CL2. This case usually causes duty misses approximately for duration of SyncDistanceTolerance.

2) SSV node uses EL1, EL2, CL1, CL2; CL1 uses EL1 and other available ELs, CL2 uses any available EL. EL1 becomes unavailable.

The execution MultiClient switches to EL2, the consensus multi client remains on CL1, which should switch its execution client from EL1 to an available one. Possible duty misses up to SyncDistanceTolerance duration

3) SSV node uses EL1, EL2, CL1, CL2; CL1 uses any available EL, CL2 uses any available EL. EL1 becomes unavailable.

The execution MultiClient switches to EL2, the consensus multi client remains on CL1, which should remain working. This shouldn't cause significant duty misses.

4) SSV node uses EL1, EL2, CL1, CL2; CL1 uses only EL1, CL2 uses only EL2. EL1 and CL1 become unavailable.

The execution MultiClient switches to EL2, the consensus multi client switches to CL2, This shouldn't cause significant duty misses.

func NewMulti

func NewMulti(ctx context.Context, nodeAddrs []string, contractAddr ethcommon.Address, opts ...OptionMulti) (*MultiClient, error)

NewMulti creates a new instance of MultiClient.

func (*MultiClient) ChainID

func (mc *MultiClient) ChainID(_ context.Context) (*big.Int, error)

func (*MultiClient) Close

func (mc *MultiClient) Close() error

func (*MultiClient) FetchHistoricalLogs

func (mc *MultiClient) FetchHistoricalLogs(ctx context.Context, fromBlock uint64) (<-chan BlockLogs, <-chan error, error)

FetchHistoricalLogs retrieves historical logs emitted by the Ethereum SSV contract(s) starting at fromBlock. It delegates the FetchHistoricalLogs call to clients MultiClient is configured with until one of them manages to serve it without an error.

func (*MultiClient) FilterLogs

func (mc *MultiClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethtypes.Log, error)

func (*MultiClient) Filterer

func (mc *MultiClient) Filterer() (*contract.ContractFilterer, error)

func (*MultiClient) HeaderByNumber

func (mc *MultiClient) HeaderByNumber(ctx context.Context, blockNumber *big.Int) (*ethtypes.Header, error)

HeaderByNumber retrieves a block header by its number.

func (*MultiClient) Healthy

func (mc *MultiClient) Healthy(ctx context.Context) error

Healthy returns whether MultiClient has at least 1 healthy EL client (a client that responds to requests and not is in the syncing state).

func (*MultiClient) StreamLogs

func (mc *MultiClient) StreamLogs(ctx context.Context, fromBlock uint64) (logsCh chan BlockLogs)

StreamLogs subscribes to events emitted by the Ethereum SSV contract(s) starting at fromBlock. It spawns a go-routine that spins in a perpetual retry loop, terminating only on unrecoverable interruptions (such as context cancels, client closure, etc.) as defined by isMultiClientInterruptedError func. The logsCh is closed once the streaming go-routine terminates. Any errors encountered during streaming are logged.

func (*MultiClient) SubscribeFilterLogs

func (mc *MultiClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- ethtypes.Log) (ethereum.Subscription, error)

type Option

type Option func(*ExecutionClient)

Option defines an ExecutionClient configuration option.

func WithFollowDistance

func WithFollowDistance(offset uint64) Option

WithFollowDistance sets finalization offset (a block at this offset into the past from the head block will be considered as very likely finalized).

func WithHealthInvalidationInterval

func WithHealthInvalidationInterval(interval time.Duration) Option

WithHealthInvalidationInterval sets health invalidation interval. 0 disables caching.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger enables logging.

func WithReqTimeout

func WithReqTimeout(timeout time.Duration) Option

WithReqTimeout sets timeout for RPC requests to eth1 node. The timeout must be positive, otherwise the default value will be used.

func WithSyncDistanceTolerance

func WithSyncDistanceTolerance(count uint64) Option

WithSyncDistanceTolerance sets the number of blocks that is acceptable to lag behind.

type OptionMulti

type OptionMulti func(client *MultiClient)

OptionMulti defines a MultiClient configuration option.

func WithLoggerMulti

func WithLoggerMulti(logger *zap.Logger) OptionMulti

WithLoggerMulti enables logging.

func WithReqTimeoutMulti

func WithReqTimeoutMulti(timeout time.Duration) OptionMulti

WithReqTimeoutMulti sets timeout for RPC requests to eth1 node. The timeout must be positive, otherwise the default value will be used.

func WithSyncDistanceToleranceMulti

func WithSyncDistanceToleranceMulti(count uint64) OptionMulti

WithSyncDistanceToleranceMulti sets the number of blocks that is acceptable to lag behind.

type Options

type Options struct {
	Addr                  string        `` /* 214-byte string literal not displayed */
	ConnectionTimeout     time.Duration `` /* 133-byte string literal not displayed */
	SyncDistanceTolerance uint64        `` /* 158-byte string literal not displayed */
}

Options contains config configurations related to Ethereum execution client.

type Provider

type Provider interface {
	FetchHistoricalLogs(ctx context.Context, fromBlock uint64) (logsCh <-chan BlockLogs, errsCh <-chan error, err error)
	StreamLogs(ctx context.Context, fromBlock uint64) (logsCh chan BlockLogs)
	Filterer() (*contract.ContractFilterer, error)
	HeaderByNumber(ctx context.Context, blockNumber *big.Int) (*ethtypes.Header, error)
	ChainID(ctx context.Context) (*big.Int, error)
	Healthy(ctx context.Context) error
	SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- ethtypes.Log) (ethereum.Subscription, error)
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethtypes.Log, error)
	Close() error
}

type SingleClientProvider

type SingleClientProvider interface {
	Provider
	SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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