eth

package
v0.0.0-...-d4adcb1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EthSlotInterval  = 12 * time.Second
	EthEpochInterval = 6*time.Minute + 24*time.Second
)

TODO: move to config

Variables

View Source
var DefaultRetryOpts = []retry.Option{
	retry.Attempts(defaultRetryAttempts),
	retry.Delay(defaultRetryDelay),
	retry.LastErrorOnly(true),
	retry.OnRetry(func(n uint, err error) {
		log.Errorf("Failed attempt: %w", err, "attempt", n)
	}),
}

Functions

func SubscribeNewHeadByPolling

func SubscribeNewHeadByPolling(
	ctx context.Context,
	client ethClient,
	headCh chan<- *types.Header,
	tag BlockTag,
	interval time.Duration,
	requestTimeout time.Duration,
) event.Subscription

Types

type BlockTag

type BlockTag string
const (
	// - L1: The most recent block in the canonical chain observed by the client,
	// 	     this block may be re-orged out of the canonical chain even under healthy/normal conditions
	// - L2: Local chain head (unconfirmed on L1)
	Latest BlockTag = "latest"
	// - L1: The most recent block that is safe from re-orgs under honest majority and certain synchronicity assumptions
	// - L2: Derived chain tip from (not-necessarily safe) L1 data
	Safe BlockTag = "safe"
	// - L1: The most recent crypto-economically secure block,
	//       cannot be re-orged outside of manual intervention driven by community coordination
	// - L2: Derived chain tip from finalized L1 data
	Finalized BlockTag = "finalized"
)

Block tags (used both for L1 and L2) https://ethereum.github.io/execution-apis/api-documentation/

type EthClient

type EthClient struct {
	*ethclient.Client
	C *rpc.Client
}

func DialWithRetry

func DialWithRetry(ctx context.Context, endpoint string, retryOpts ...retry.Option) (*EthClient, error)

func NewEthClient

func NewEthClient(c *rpc.Client) *EthClient

func (*EthClient) HeaderByTag

func (c *EthClient) HeaderByTag(ctx context.Context, tag BlockTag) (*types.Header, error)

func (*EthClient) SuggestGasTipCap

func (c *EthClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

func (*EthClient) TxPoolStatus

func (c *EthClient) TxPoolStatus(ctx context.Context) (map[string]hexutil.Uint, error)

type EthState

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

Thread-safe. Tracks the latest, last safe and last finalized L1 headers received.

func NewEthState

func NewEthState() *EthState

func (*EthState) Finalized

func (s *EthState) Finalized() types.BlockID

func (*EthState) Head

func (s *EthState) Head() types.BlockID

func (*EthState) OnFinalized

func (s *EthState) OnFinalized(_ context.Context, header *ethTypes.Header) error

func (*EthState) OnLatest

func (s *EthState) OnLatest(_ context.Context, header *ethTypes.Header) error

func (*EthState) OnSafe

func (s *EthState) OnSafe(_ context.Context, header *ethTypes.Header) error

func (*EthState) Safe

func (s *EthState) Safe() types.BlockID

func (*EthState) Tips

type EthSyncer

type EthSyncer struct {
	OnNewHandler
	LatestHeaderBroker    *utils.Broker[*types.Header]
	SafeHeaderBroker      *utils.Broker[*types.Header]
	FinalizedHeaderBroker *utils.Broker[*types.Header]
	// contains filtered or unexported fields
}

func NewEthSyncer

func NewEthSyncer(handler OnNewHandler) *EthSyncer

func (*EthSyncer) Start

func (s *EthSyncer) Start(ctx context.Context, client syncerEthClient)

Starts a subscription in a separate goroutine for each commitment level.

func (*EthSyncer) Stop

func (s *EthSyncer) Stop(ctx context.Context)

type LazyEthClient

type LazyEthClient struct {
	*EthClient
	// contains filtered or unexported fields
}

func NewLazilyDialedEthClient

func NewLazilyDialedEthClient(endpoint string, retryOpts ...retry.Option) *LazyEthClient

func (*LazyEthClient) EnsureDialed

func (c *LazyEthClient) EnsureDialed(ctx context.Context) error

type OnNewHandler

type OnNewHandler interface {
	OnLatest(ctx context.Context, header *types.Header) error
	OnSafe(ctx context.Context, header *types.Header) error
	OnFinalized(ctx context.Context, header *types.Header) error
}

Directories

Path Synopsis
We use Optimism's `SimpleTransactionManager` below (as of commit: 02c570c4c05603e1261f664ee8f92502814bfca2).
We use Optimism's `SimpleTransactionManager` below (as of commit: 02c570c4c05603e1261f664ee8f92502814bfca2).

Jump to

Keyboard shortcuts

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