provider

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package provider is the implementation of the Provider interface. it abstracts connecting to different rollup chains and collecting XMsgs and XReceipts to construct XBlock and deliver them to the calling module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mock

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

Mock is a mock implementation of the xchain.Provider interface. It generates deterministic blocks and messages for any chain that is queried. Except for omni consensus chain, we use the real cprovider to fetch blocks.

func NewMock

func NewMock(period time.Duration, cChainID uint64, cProvider cchain.Provider) *Mock

func (*Mock) GetBlock

func (m *Mock) GetBlock(_ context.Context, chainID uint64, height uint64, offset uint64) (xchain.Block, bool, error)

func (*Mock) GetEmittedCursor

func (*Mock) GetEmittedCursor(_ context.Context, _ xchain.EmitRef, stream xchain.StreamID,
) (xchain.StreamCursor, bool, error)

func (*Mock) GetSubmittedCursor

func (*Mock) GetSubmittedCursor(_ context.Context, stream xchain.StreamID,
) (xchain.StreamCursor, bool, error)

func (*Mock) StreamAsync

func (m *Mock) StreamAsync(ctx context.Context, chainID uint64, fromHeight uint64, fromOffset uint64, callback xchain.ProviderCallback) error

func (*Mock) StreamAsyncNoOffset added in v0.1.6

func (*Mock) StreamAsyncNoOffset(context.Context, uint64, uint64, xchain.ProviderCallback) error

func (*Mock) StreamBlocks

func (m *Mock) StreamBlocks(ctx context.Context, chainID uint64, fromHeight uint64, fromOffset uint64, callback xchain.ProviderCallback) error

func (*Mock) StreamBlocksNoOffset added in v0.1.6

func (*Mock) StreamBlocksNoOffset(context.Context, uint64, uint64, xchain.ProviderCallback) error

type Provider

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

Provider stores the source chain configuration and the global quit channel.

func New

func New(network netconf.Network, rpcClients map[uint64]ethclient.Client, cProvider cchain.Provider) *Provider

New instantiates the provider instance which will be ready to accept subscriptions for respective destination XBlocks.

func (*Provider) GetBlock

func (p *Provider) GetBlock(ctx context.Context, chainID uint64, height uint64, xOffset uint64) (xchain.Block, bool, error)

GetBlock returns the XBlock for the provided chain and height, or false if not available yet (not finalized), or an error.

func (*Provider) GetEmittedCursor

func (p *Provider) GetEmittedCursor(ctx context.Context, ref xchain.EmitRef, stream xchain.StreamID,
) (xchain.StreamCursor, bool, error)

GetEmittedCursor returns the emitted cursor for the destination chain on the source chain, or false if not available, or an error. Calls the source chain portal OutXStreamOffset method.

Note that the BlockOffset field is not populated for emit cursors, since it isn't stored on-chain but tracked off-chain.

func (*Provider) GetSubmittedCursor

func (p *Provider) GetSubmittedCursor(ctx context.Context, stream xchain.StreamID,
) (xchain.StreamCursor, bool, error)

GetSubmittedCursor returns the submitted cursor for the source chain on the destination chain, or false if not available, or an error. Calls the destination chain portal InXStreamOffset method.

func (*Provider) StreamAsync

func (p *Provider) StreamAsync(
	ctx context.Context,
	chainID uint64,
	fromHeight uint64,
	fromOffset uint64,
	callback xchain.ProviderCallback,
) error

StreamAsync starts a goroutine that streams xblocks asynchronously forever. It returns immediately. It only returns an error if the chainID in invalid. This is the async version of StreamBlocks. It retries forever (with backoff) on all fetch and callback errors.

func (*Provider) StreamAsyncNoOffset added in v0.1.6

func (p *Provider) StreamAsyncNoOffset(
	ctx context.Context,
	chainID uint64,
	fromHeight uint64,
	callback xchain.ProviderCallback,
) error

StreamAsyncNoOffset is the same as StreamAsync except that XBlockOffset is not populated in the returned XBlocks.

func (*Provider) StreamBlocks

func (p *Provider) StreamBlocks(
	ctx context.Context,
	chainID uint64,
	fromHeight uint64,
	fromOffset uint64,
	callback xchain.ProviderCallback,
) error

StreamBlocks blocks, streaming all xblocks from the chain as they become available (finalized). It retries forever (with backoff) on all fetch errors. It however returns the first callback error. It returns nil when the context is canceled.

func (*Provider) StreamBlocksNoOffset added in v0.1.6

func (p *Provider) StreamBlocksNoOffset(
	ctx context.Context,
	chainID uint64,
	fromHeight uint64,
	callback xchain.ProviderCallback,
) error

StreamBlocksNoOffset is the same as StreamBlocks except that XBlockOffset is not populated in the returned XBlocks.

Jump to

Keyboard shortcuts

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