backend

package
v0.29.6 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultClientTimeout = 3 * time.Second

DefaultClientTimeout is used when making a GRPC request to a collection node or an execution node

View Source
const DefaultConnectionPoolSize = 250

DefaultConnectionPoolSize is the default size for the connection pool to collection and execution nodes

View Source
const DefaultLoggedScriptsCacheSize = 1_000_000

DefaultLoggedScriptsCacheSize is the default size of the lookup cache used to dedupe logs of scripts sent to ENs limiting cache size to 16MB and does not affect script execution, only for keeping logs tidy

View Source
const DefaultMaxHeightRange = 250

DefaultMaxHeightRange is the default maximum size of range requests.

View Source
const DefaultSnapshotHistoryLimit = 50

DefaultSnapshotHistoryLimit the amount of blocks to look back in state when recursively searching for a valid snapshot

Variables

View Source
var SnapshotHistoryLimitErr = fmt.Errorf("reached the snapshot history limit")

Functions

func NewNetworkAPI

func NewNetworkAPI(state protocol.State, chainID flow.ChainID, snapshotHistoryLimit int) *backendNetwork

NetworkAPI func

The observer and access nodes need to be able to handle GetNetworkParameters and GetLatestProtocolStateSnapshot RPCs so this logic was split into the backendNetwork so that we can ignore the rest of the backend logic

func WithClientUnaryInterceptor

func WithClientUnaryInterceptor(timeout time.Duration) grpc.DialOption

Types

type Backend

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

Backend implements the Access API.

It is composed of several sub-backends that implement part of the Access API.

Script related calls are handled by backendScripts. Transaction related calls are handled by backendTransactions. Block Header related calls are handled by backendBlockHeaders. Block details related calls are handled by backendBlockDetails. Event related calls are handled by backendEvents. Account related calls are handled by backendAccounts.

All remaining calls are handled by the base Backend in this file.

func New

func New(
	state protocol.State,
	collectionRPC accessproto.AccessAPIClient,
	historicalAccessNodes []accessproto.AccessAPIClient,
	blocks storage.Blocks,
	headers storage.Headers,
	collections storage.Collections,
	transactions storage.Transactions,
	executionReceipts storage.ExecutionReceipts,
	executionResults storage.ExecutionResults,
	chainID flow.ChainID,
	transactionMetrics module.TransactionMetrics,
	connFactory ConnectionFactory,
	retryEnabled bool,
	maxHeightRange uint,
	preferredExecutionNodeIDs []string,
	fixedExecutionNodeIDs []string,
	log zerolog.Logger,
	snapshotHistoryLimit int,
) *Backend

func (*Backend) ExecuteScriptAtBlockHeight

func (b *Backend) ExecuteScriptAtBlockHeight(
	ctx context.Context,
	blockHeight uint64,
	script []byte,
	arguments [][]byte,
) ([]byte, error)

func (*Backend) ExecuteScriptAtBlockID

func (b *Backend) ExecuteScriptAtBlockID(
	ctx context.Context,
	blockID flow.Identifier,
	script []byte,
	arguments [][]byte,
) ([]byte, error)

func (*Backend) ExecuteScriptAtLatestBlock

func (b *Backend) ExecuteScriptAtLatestBlock(
	ctx context.Context,
	script []byte,
	arguments [][]byte,
) ([]byte, error)

func (*Backend) GetAccount

func (b *Backend) GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error)

func (*Backend) GetAccountAtBlockHeight

func (b *Backend) GetAccountAtBlockHeight(
	ctx context.Context,
	address flow.Address,
	height uint64,
) (*flow.Account, error)

func (*Backend) GetAccountAtLatestBlock

func (b *Backend) GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error)

func (*Backend) GetBlockByHeight

func (b *Backend) GetBlockByHeight(_ context.Context, height uint64) (*flow.Block, flow.BlockStatus, error)

func (*Backend) GetBlockByID

func (b *Backend) GetBlockByID(_ context.Context, id flow.Identifier) (*flow.Block, flow.BlockStatus, error)

func (*Backend) GetBlockHeaderByHeight

func (b *Backend) GetBlockHeaderByHeight(_ context.Context, height uint64) (*flow.Header, flow.BlockStatus, error)

func (*Backend) GetBlockHeaderByID

func (b *Backend) GetBlockHeaderByID(_ context.Context, id flow.Identifier) (*flow.Header, flow.BlockStatus, error)

func (*Backend) GetCollectionByID

func (b *Backend) GetCollectionByID(_ context.Context, colID flow.Identifier) (*flow.LightCollection, error)

func (*Backend) GetEventsForBlockIDs

func (b *Backend) GetEventsForBlockIDs(
	ctx context.Context,
	eventType string,
	blockIDs []flow.Identifier,
) ([]flow.BlockEvents, error)

GetEventsForBlockIDs retrieves events for all the specified block IDs that have the given type

func (*Backend) GetEventsForHeightRange

func (b *Backend) GetEventsForHeightRange(
	ctx context.Context,
	eventType string,
	startHeight, endHeight uint64,
) ([]flow.BlockEvents, error)

GetEventsForHeightRange retrieves events for all sealed blocks between the start block height and the end block height (inclusive) that have the given type.

func (*Backend) GetExecutionResultByID

func (b *Backend) GetExecutionResultByID(ctx context.Context, id flow.Identifier) (*flow.ExecutionResult, error)

GetExecutionResultByID gets an execution result by its ID.

func (*Backend) GetExecutionResultForBlockID

func (b *Backend) GetExecutionResultForBlockID(ctx context.Context, blockID flow.Identifier) (*flow.ExecutionResult, error)

func (*Backend) GetLatestBlock

func (b *Backend) GetLatestBlock(_ context.Context, isSealed bool) (*flow.Block, flow.BlockStatus, error)

func (*Backend) GetLatestBlockHeader

func (b *Backend) GetLatestBlockHeader(_ context.Context, isSealed bool) (*flow.Header, flow.BlockStatus, error)

func (*Backend) GetLatestProtocolStateSnapshot

func (b *Backend) GetLatestProtocolStateSnapshot(_ context.Context) ([]byte, error)

GetLatestProtocolStateSnapshot returns the latest finalized snapshot

func (*Backend) GetNetworkParameters

func (b *Backend) GetNetworkParameters(_ context.Context) access.NetworkParameters

func (*Backend) GetTransaction

func (b *Backend) GetTransaction(ctx context.Context, txID flow.Identifier) (*flow.TransactionBody, error)

func (*Backend) GetTransactionResult

func (b *Backend) GetTransactionResult(
	ctx context.Context,
	txID flow.Identifier,
) (*access.TransactionResult, error)

func (*Backend) GetTransactionResultByIndex

func (b *Backend) GetTransactionResultByIndex(
	ctx context.Context,
	blockID flow.Identifier,
	index uint32,
) (*access.TransactionResult, error)

GetTransactionResultByIndex returns TransactionsResults for an index in a block that is executed, pending or finalized transactions return errors

func (*Backend) GetTransactionResultsByBlockID

func (b *Backend) GetTransactionResultsByBlockID(
	ctx context.Context,
	blockID flow.Identifier,
) ([]*access.TransactionResult, error)

func (*Backend) GetTransactionsByBlockID

func (b *Backend) GetTransactionsByBlockID(
	ctx context.Context,
	blockID flow.Identifier,
) ([]*flow.TransactionBody, error)

func (*Backend) NotifyFinalizedBlockHeight

func (b *Backend) NotifyFinalizedBlockHeight(height uint64)

func (*Backend) Ping

func (b *Backend) Ping(ctx context.Context) error

Ping responds to requests when the server is up.

func (*Backend) SendRawTransaction

func (b *Backend) SendRawTransaction(
	ctx context.Context,
	tx *flow.TransactionBody,
) error

SendRawTransaction sends a raw transaction to the collection node

func (*Backend) SendTransaction

func (b *Backend) SendTransaction(
	ctx context.Context,
	tx *flow.TransactionBody,
) error

SendTransaction forwards the transaction to the collection node

type CachedClient

type CachedClient struct {
	ClientConn *grpc.ClientConn
	Address    string
	// contains filtered or unexported fields
}

func (*CachedClient) Close

func (s *CachedClient) Close()

type ConnectionFactory

type ConnectionFactory interface {
	GetAccessAPIClient(address string) (access.AccessAPIClient, io.Closer, error)
	InvalidateAccessAPIClient(address string)
	GetExecutionAPIClient(address string) (execution.ExecutionAPIClient, io.Closer, error)
	InvalidateExecutionAPIClient(address string)
}

ConnectionFactory is used to create an access api client

type ConnectionFactoryImpl

type ConnectionFactoryImpl struct {
	CollectionGRPCPort        uint
	ExecutionGRPCPort         uint
	CollectionNodeGRPCTimeout time.Duration
	ExecutionNodeGRPCTimeout  time.Duration
	ConnectionsCache          *lru.Cache
	CacheSize                 uint
	AccessMetrics             module.AccessMetrics
	Log                       zerolog.Logger
	// contains filtered or unexported fields
}

func (*ConnectionFactoryImpl) GetAccessAPIClient

func (cf *ConnectionFactoryImpl) GetAccessAPIClient(address string) (access.AccessAPIClient, io.Closer, error)

func (*ConnectionFactoryImpl) GetExecutionAPIClient

func (cf *ConnectionFactoryImpl) GetExecutionAPIClient(address string) (execution.ExecutionAPIClient, io.Closer, error)

func (*ConnectionFactoryImpl) InvalidateAccessAPIClient

func (cf *ConnectionFactoryImpl) InvalidateAccessAPIClient(address string)

func (*ConnectionFactoryImpl) InvalidateExecutionAPIClient

func (cf *ConnectionFactoryImpl) InvalidateExecutionAPIClient(address string)

type InsufficientExecutionReceipts

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

InsufficientExecutionReceipts indicates that no execution receipt were found for a given block ID

func (InsufficientExecutionReceipts) Error

type ProxyConnectionFactory

type ProxyConnectionFactory struct {
	ConnectionFactory
	// contains filtered or unexported fields
}

func (*ProxyConnectionFactory) GetAccessAPIClient

func (p *ProxyConnectionFactory) GetAccessAPIClient(address string) (access.AccessAPIClient, io.Closer, error)

func (*ProxyConnectionFactory) GetExecutionAPIClient

func (p *ProxyConnectionFactory) GetExecutionAPIClient(address string) (execution.ExecutionAPIClient, io.Closer, error)

type Retry

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

Retry implements a simple retry mechanism for transaction submission.

func (*Retry) Activate

func (r *Retry) Activate() *Retry

func (*Retry) IsActive

func (r *Retry) IsActive() bool

func (*Retry) Notify

func (b *Retry) Notify(signal interface{}) bool

func (*Retry) RegisterTransaction

func (r *Retry) RegisterTransaction(height uint64, tx *flow.TransactionBody)

RegisterTransaction adds a transaction that could possibly be retried

func (*Retry) Retry

func (r *Retry) Retry(height uint64)

func (*Retry) SetBackend

func (r *Retry) SetBackend(b *Backend) *Retry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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