backend

package
v0.36.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: AGPL-3.0 Imports: 43 Imported by: 4

Documentation

Index

Constants

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 = 500

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

Variables

View Source
var ErrTransactionNotInBlock = errors.New("transaction not in block")

ErrTransactionNotInBlock represents an error indicating that the transaction is not found in the block.

Functions

func IsInsufficientExecutionReceipts added in v0.30.0

func IsInsufficientExecutionReceipts(err error) bool

func NewNetworkAPI added in v0.28.0

func NewNetworkAPI(
	state protocol.State,
	chainID flow.ChainID,
	headers storage.Headers,
	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

Types

type Backend

type Backend struct {
	BlockTracker subscription.BlockTracker
	// 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(params Params) (*Backend, error)

New creates backend instance

func (*Backend) ExecuteScriptAtBlockHeight

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

ExecuteScriptAtBlockHeight executes provided script at the provided block height.

func (*Backend) ExecuteScriptAtBlockID

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

ExecuteScriptAtBlockID executes provided script at the provided block ID.

func (*Backend) ExecuteScriptAtLatestBlock

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

ExecuteScriptAtLatestBlock executes provided script at the latest sealed block.

func (*Backend) GetAccount

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

GetAccount returns the account details at the latest sealed block. Alias for GetAccountAtLatestBlock

func (*Backend) GetAccountAtBlockHeight

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

GetAccountAtBlockHeight returns the account details at the given block height.

func (*Backend) GetAccountAtLatestBlock

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

GetAccountAtLatestBlock returns the account details at the latest sealed block.

func (*Backend) GetAccountBalanceAtBlockHeight added in v0.36.1

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

GetAccountBalanceAtBlockHeight returns the account balance at the given block height.

func (*Backend) GetAccountBalanceAtLatestBlock added in v0.36.1

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

GetAccountBalanceAtLatestBlock returns the account balance at the latest sealed block.

func (*Backend) GetAccountKeyAtBlockHeight added in v0.36.1

func (b *Backend) GetAccountKeyAtBlockHeight(
	ctx context.Context,
	address flow.Address,
	keyIndex uint32,
	height uint64,
) (*flow.AccountPublicKey, error)

GetAccountKeyAtBlockHeight returns the account public key by key index at the given block height.

func (*Backend) GetAccountKeyAtLatestBlock added in v0.36.1

func (b *Backend) GetAccountKeyAtLatestBlock(
	ctx context.Context,
	address flow.Address,
	keyIndex uint32,
) (*flow.AccountPublicKey, error)

GetAccountKeyAtLatestBlock returns the account public key at the latest sealed block.

func (*Backend) GetAccountKeysAtBlockHeight added in v0.36.1

func (b *Backend) GetAccountKeysAtBlockHeight(
	ctx context.Context,
	address flow.Address,
	height uint64,
) ([]flow.AccountPublicKey, error)

GetAccountKeysAtBlockHeight returns the account public keys at the given block height.

func (*Backend) GetAccountKeysAtLatestBlock added in v0.36.1

func (b *Backend) GetAccountKeysAtLatestBlock(
	ctx context.Context,
	address flow.Address,
) ([]flow.AccountPublicKey, error)

GetAccountKeysAtLatestBlock returns the account public keys at the latest sealed block.

func (*Backend) GetBlockByHeight

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

func (*Backend) GetBlockByID

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

func (*Backend) GetBlockHeaderByHeight

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

func (*Backend) GetBlockHeaderByID

func (b *Backend) GetBlockHeaderByID(ctx 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,
	requiredEventEncodingVersion entities.EventEncodingVersion,
) ([]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,
	requiredEventEncodingVersion entities.EventEncodingVersion,
) ([]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 added in v0.23.5

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

GetExecutionResultByID gets an execution result by its ID.

func (*Backend) GetExecutionResultForBlockID added in v0.21.0

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

func (*Backend) GetFullCollectionByID added in v0.33.26

func (b *Backend) GetFullCollectionByID(_ context.Context, colID flow.Identifier) (*flow.Collection, error)

func (*Backend) GetLatestBlock

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

func (*Backend) GetLatestBlockHeader

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

func (*Backend) GetLatestProtocolStateSnapshot added in v0.15.0

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) GetNodeVersionInfo added in v0.31.0

func (b *Backend) GetNodeVersionInfo(_ context.Context) (*access.NodeVersionInfo, error)

GetNodeVersionInfo returns node version information such as semver, commit, sporkID, protocolVersion, etc

func (*Backend) GetProtocolStateSnapshotByBlockID added in v0.33.1

func (b *Backend) GetProtocolStateSnapshotByBlockID(_ context.Context, blockID flow.Identifier) ([]byte, error)

GetProtocolStateSnapshotByBlockID returns serializable Snapshot for a block, by blockID. The requested block must be finalized, otherwise an error is returned. Expected errors during normal operation:

  • status.Error[codes.NotFound] - No block with the given ID was found
  • status.Error[codes.InvalidArgument] - Block ID is for an orphaned block and will never have a valid snapshot
  • status.Error[codes.FailedPrecondition] - A block was found, but it is not finalized and is above the finalized height. The block may or may not be finalized in the future; the client can retry later.

func (*Backend) GetProtocolStateSnapshotByHeight added in v0.33.1

func (b *Backend) GetProtocolStateSnapshotByHeight(_ context.Context, blockHeight uint64) ([]byte, error)

GetProtocolStateSnapshotByHeight returns serializable Snapshot by block height. The block must be finalized (otherwise the by-height query is ambiguous). Expected errors during normal operation:

  • status.Error[codes.NotFound] - No block with the given height was found. The block height may or may not be finalized in the future; the client can retry later.

func (*Backend) GetSystemTransaction added in v0.33.1

func (b *Backend) GetSystemTransaction(ctx context.Context, _ flow.Identifier) (*flow.TransactionBody, error)

GetSystemTransaction returns system transaction

func (*Backend) GetSystemTransactionResult added in v0.33.1

func (b *Backend) GetSystemTransactionResult(ctx context.Context, blockID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) (*access.TransactionResult, error)

GetSystemTransactionResult returns system transaction result

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,
	blockID flow.Identifier,
	collectionID flow.Identifier,
	requiredEventEncodingVersion entities.EventEncodingVersion,
) (*access.TransactionResult, error)

func (*Backend) GetTransactionResultByIndex added in v0.24.8

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

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

func (*Backend) GetTransactionResultsByBlockID added in v0.24.11

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

func (*Backend) GetTransactionsByBlockID added in v0.24.11

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

func (*Backend) LookupErrorMessageByIndex added in v0.33.13

func (b *Backend) LookupErrorMessageByIndex(
	ctx context.Context,
	blockID flow.Identifier,
	height uint64,
	index uint32,
) (string, error)

LookupErrorMessageByIndex returns transaction error message for specified transaction using its index. If an error message for transaction can be found in cache then it will be used to serve the request, otherwise an RPC call will be made to the EN to fetch that error message, fetched value will be cached in the LRU cache. Expected errors during normal operation:

  • status.Error[codes.NotFound] - transaction result for given block ID and tx index is not available.
  • InsufficientExecutionReceipts - found insufficient receipts for given block ID.
  • status.Error - remote GRPC call to EN has failed.

func (*Backend) LookupErrorMessageByTransactionID added in v0.33.13

func (b *Backend) LookupErrorMessageByTransactionID(
	ctx context.Context,
	blockID flow.Identifier,
	transactionID flow.Identifier,
) (string, error)

LookupErrorMessageByTransactionID returns transaction error message for specified transaction. If an error message for transaction can be found in the cache then it will be used to serve the request, otherwise an RPC call will be made to the EN to fetch that error message, fetched value will be cached in the LRU cache. Expected errors during normal operation:

  • InsufficientExecutionReceipts - found insufficient receipts for given block ID.
  • status.Error - remote GRPC call to EN has failed.

func (*Backend) LookupErrorMessagesByBlockID added in v0.33.13

func (b *Backend) LookupErrorMessagesByBlockID(
	ctx context.Context,
	blockID flow.Identifier,
	height uint64,
) (map[flow.Identifier]string, error)

LookupErrorMessagesByBlockID returns all error messages for failed transactions by blockID. An RPC call will be made to the EN to fetch missing errors messages, fetched value will be cached in the LRU cache. Expected errors during normal operation:

  • status.Error[codes.NotFound] - transaction results for given block ID are not available.
  • InsufficientExecutionReceipts - found insufficient receipts for given block ID.
  • status.Error - remote GRPC call to EN has failed.

func (*Backend) Ping

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

Ping responds to requests when the server is up.

func (*Backend) ProcessFinalizedBlockHeight added in v0.33.1

func (b *Backend) ProcessFinalizedBlockHeight(height uint64) error

ATTENTION: might be a source of problems in future. We run this code on finalization gorotuine, potentially lagging finalization events if operations take long time. We might need to move this logic on dedicated goroutine and provide a way to skip finalization events if they are delivered too often for this engine. An example of similar approach - https://github.com/onflow/flow-go/blob/10b0fcbf7e2031674c00f3cdd280f27bd1b16c47/engine/common/follower/compliance_engine.go#L201.. No errors expected during normal operations.

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

func (*Backend) SubscribeBlockDigestsFromLatest added in v0.33.30

func (b *Backend) SubscribeBlockDigestsFromLatest(ctx context.Context, blockStatus flow.BlockStatus) subscription.Subscription

SubscribeBlockDigestsFromLatest streams finalized or sealed lightweight block starting at the latest sealed block, up until the latest available block. Once the latest is reached, the stream will remain open and responses are sent for each new block as it becomes available.

Each lightweight block are filtered by the provided block status, and only those blocks that match the status are returned.

Parameters: - ctx: Context for the operation. - blockStatus: The status of the block, which could be only BlockStatusSealed or BlockStatusFinalized.

If invalid parameters will be supplied SubscribeBlockDigestsFromLatest will return a failed subscription.

func (*Backend) SubscribeBlockDigestsFromStartBlockID added in v0.33.30

func (b *Backend) SubscribeBlockDigestsFromStartBlockID(ctx context.Context, startBlockID flow.Identifier, blockStatus flow.BlockStatus) subscription.Subscription

SubscribeBlockDigestsFromStartBlockID streams finalized or sealed lightweight block starting at the requested start block id, up until the latest available block. Once the latest is reached, the stream will remain open and responses are sent for each new block as it becomes available.

Each lightweight block are filtered by the provided block status, and only those blocks that match the status are returned.

Parameters: - ctx: Context for the operation. - startBlockID: The identifier of the starting block. - blockStatus: The status of the block, which could be only BlockStatusSealed or BlockStatusFinalized.

If invalid parameters will be supplied SubscribeBlockDigestsFromStartBlockID will return a failed subscription.

func (*Backend) SubscribeBlockDigestsFromStartHeight added in v0.33.30

func (b *Backend) SubscribeBlockDigestsFromStartHeight(ctx context.Context, startHeight uint64, blockStatus flow.BlockStatus) subscription.Subscription

SubscribeBlockDigestsFromStartHeight streams finalized or sealed lightweight block starting at the requested start block height, up until the latest available block. Once the latest is reached, the stream will remain open and responses are sent for each new block as it becomes available.

Each lightweight block are filtered by the provided block status, and only those blocks that match the status are returned.

Parameters: - ctx: Context for the operation. - startHeight: The height of the starting block. - blockStatus: The status of the block, which could be only BlockStatusSealed or BlockStatusFinalized.

If invalid parameters will be supplied SubscribeBlockDigestsFromStartHeight will return a failed subscription.

func (*Backend) SubscribeBlockHeadersFromLatest added in v0.33.30

func (b *Backend) SubscribeBlockHeadersFromLatest(ctx context.Context, blockStatus flow.BlockStatus) subscription.Subscription

SubscribeBlockHeadersFromLatest streams finalized or sealed block headers starting at the latest sealed block, up until the latest available block header. Once the latest is reached, the stream will remain open and responses are sent for each new block header as it becomes available.

Each block header are filtered by the provided block status, and only those block headers that match the status are returned.

Parameters: - ctx: Context for the operation. - blockStatus: The status of the block, which could be only BlockStatusSealed or BlockStatusFinalized.

If invalid parameters will be supplied SubscribeBlockHeadersFromLatest will return a failed subscription.

func (*Backend) SubscribeBlockHeadersFromStartBlockID added in v0.33.30

func (b *Backend) SubscribeBlockHeadersFromStartBlockID(ctx context.Context, startBlockID flow.Identifier, blockStatus flow.BlockStatus) subscription.Subscription

SubscribeBlockHeadersFromStartBlockID streams finalized or sealed block headers starting at the requested start block id, up until the latest available block header. Once the latest is reached, the stream will remain open and responses are sent for each new block header as it becomes available.

Each block header are filtered by the provided block status, and only those block headers that match the status are returned.

Parameters: - ctx: Context for the operation. - startBlockID: The identifier of the starting block. - blockStatus: The status of the block, which could be only BlockStatusSealed or BlockStatusFinalized.

If invalid parameters will be supplied SubscribeBlockHeadersFromStartBlockID will return a failed subscription.

func (*Backend) SubscribeBlockHeadersFromStartHeight added in v0.33.30

func (b *Backend) SubscribeBlockHeadersFromStartHeight(ctx context.Context, startHeight uint64, blockStatus flow.BlockStatus) subscription.Subscription

SubscribeBlockHeadersFromStartHeight streams finalized or sealed block headers starting at the requested start block height, up until the latest available block header. Once the latest is reached, the stream will remain open and responses are sent for each new block header as it becomes available.

Each block header are filtered by the provided block status, and only those block headers that match the status are returned.

Parameters: - ctx: Context for the operation. - startHeight: The height of the starting block. - blockStatus: The status of the block, which could be only BlockStatusSealed or BlockStatusFinalized.

If invalid parameters will be supplied SubscribeBlockHeadersFromStartHeight will return a failed subscription.

func (*Backend) SubscribeBlocksFromLatest added in v0.33.30

func (b *Backend) SubscribeBlocksFromLatest(ctx context.Context, blockStatus flow.BlockStatus) subscription.Subscription

SubscribeBlocksFromLatest subscribes to the finalized or sealed blocks starting at the latest sealed block, up until the latest available block. Once the latest is reached, the stream will remain open and responses are sent for each new block as it becomes available.

Each block is filtered by the provided block status, and only those blocks that match the status are returned.

Parameters: - ctx: Context for the operation. - blockStatus: The status of the block, which could be only BlockStatusSealed or BlockStatusFinalized.

If invalid parameters will be supplied SubscribeBlocksFromLatest will return a failed subscription.

func (*Backend) SubscribeBlocksFromStartBlockID added in v0.33.30

func (b *Backend) SubscribeBlocksFromStartBlockID(ctx context.Context, startBlockID flow.Identifier, blockStatus flow.BlockStatus) subscription.Subscription

SubscribeBlocksFromStartBlockID subscribes to the finalized or sealed blocks starting at the requested start block id, up until the latest available block. Once the latest is reached, the stream will remain open and responses are sent for each new block as it becomes available.

Each block is filtered by the provided block status, and only those blocks that match the status are returned.

Parameters: - ctx: Context for the operation. - startBlockID: The identifier of the starting block. - blockStatus: The status of the block, which could be only BlockStatusSealed or BlockStatusFinalized.

If invalid parameters will be supplied SubscribeBlocksFromStartBlockID will return a failed subscription.

func (*Backend) SubscribeBlocksFromStartHeight added in v0.33.30

func (b *Backend) SubscribeBlocksFromStartHeight(ctx context.Context, startHeight uint64, blockStatus flow.BlockStatus) subscription.Subscription

SubscribeBlocksFromStartHeight subscribes to the finalized or sealed blocks starting at the requested start block height, up until the latest available block. Once the latest is reached, the stream will remain open and responses are sent for each new block as it becomes available.

Each block is filtered by the provided block status, and only those blocks that match the status are returned.

Parameters: - ctx: Context for the operation. - startHeight: The height of the starting block. - blockStatus: The status of the block, which could be only BlockStatusSealed or BlockStatusFinalized.

If invalid parameters will be supplied SubscribeBlocksFromStartHeight will return a failed subscription.

func (*Backend) SubscribeTransactionStatuses added in v0.33.30

func (b *Backend) SubscribeTransactionStatuses(
	ctx context.Context,
	tx *flow.TransactionBody,
	requiredEventEncodingVersion entities.EventEncodingVersion,
) subscription.Subscription

SubscribeTransactionStatuses subscribes to transaction status changes starting from the transaction reference block ID. If invalid tx parameters will be supplied SubscribeTransactionStatuses will return a failed subscription.

type Communicator added in v0.32.0

type Communicator interface {
	CallAvailableNode(

		nodes flow.IdentitySkeletonList,

		call func(node *flow.IdentitySkeleton) error,

		shouldTerminateOnError func(node *flow.IdentitySkeleton, err error) bool,
	) error
}

type Config added in v0.32.0

type Config struct {
	ExecutionClientTimeout    time.Duration                   // execution API GRPC client timeout
	CollectionClientTimeout   time.Duration                   // collection API GRPC client timeout
	ConnectionPoolSize        uint                            // size of the cache for storing collection and execution connections
	MaxHeightRange            uint                            // max size of height range requests
	PreferredExecutionNodeIDs []string                        // preferred list of upstream execution node IDs
	FixedExecutionNodeIDs     []string                        // fixed list of execution node IDs to choose from if no node ID can be chosen from the PreferredExecutionNodeIDs
	CircuitBreakerConfig      connection.CircuitBreakerConfig // the configuration for circuit breaker
	ScriptExecutionMode       string                          // the mode in which scripts are executed
	EventQueryMode            string                          // the mode in which events are queried
	TxResultQueryMode         string                          // the mode in which tx results are queried
}

Config defines the configurable options for creating Backend

type IndexQueryMode added in v0.33.1

type IndexQueryMode int
const (
	// IndexQueryModeLocalOnly executes scripts and gets accounts using only local storage
	IndexQueryModeLocalOnly IndexQueryMode = iota + 1

	// IndexQueryModeExecutionNodesOnly executes scripts and gets accounts using only
	// execution nodes
	IndexQueryModeExecutionNodesOnly

	// IndexQueryModeFailover executes scripts and gets accounts using local storage first,
	// then falls back to execution nodes if data is not available for the height or if request
	// failed due to a non-user error.
	IndexQueryModeFailover

	// IndexQueryModeCompare executes scripts and gets accounts using both local storage and
	// execution nodes and compares the results. The execution node result is always returned.
	IndexQueryModeCompare
)

func ParseIndexQueryMode added in v0.33.1

func ParseIndexQueryMode(s string) (IndexQueryMode, error)

func (IndexQueryMode) String added in v0.33.1

func (m IndexQueryMode) String() string

type InsufficientExecutionReceipts added in v0.17.0

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

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

func (InsufficientExecutionReceipts) Error added in v0.17.0

type MainNodeSelector added in v0.32.0

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

MainNodeSelector is a specific implementation of the node selector. Which performs in-order node selection using fixed list of pre-defined nodes.

func NewMainNodeSelector added in v0.32.0

func NewMainNodeSelector(nodes flow.IdentitySkeletonList) *MainNodeSelector

func (*MainNodeSelector) HasNext added in v0.32.0

func (e *MainNodeSelector) HasNext() bool

HasNext returns true if next node is available.

func (*MainNodeSelector) Next added in v0.32.0

Next returns the next node in the selector.

type NodeCommunicator added in v0.32.0

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

NodeCommunicator is responsible for calling available nodes in the backend.

func NewNodeCommunicator added in v0.32.0

func NewNodeCommunicator(circuitBreakerEnabled bool) *NodeCommunicator

NewNodeCommunicator creates a new instance of NodeCommunicator.

func (*NodeCommunicator) CallAvailableNode added in v0.32.0

func (b *NodeCommunicator) CallAvailableNode(

	nodes flow.IdentitySkeletonList,

	call func(id *flow.IdentitySkeleton) error,

	shouldTerminateOnError func(node *flow.IdentitySkeleton, err error) bool,
) error

CallAvailableNode calls the provided function on the available nodes. It iterates through the nodes and executes the function. If an error occurs, it applies the custom error terminator (if provided) and keeps track of the errors. If the error occurs in circuit breaker, it continues to the next node. If the maximum failed request count is reached, it returns the accumulated errors.

type NodeSelector added in v0.32.0

type NodeSelector interface {
	Next() *flow.IdentitySkeleton
	HasNext() bool
}

NodeSelector is an interface that represents the ability to select node identities that the access node is trying to reach. It encapsulates the internal logic of node selection and provides a way to change implementations for different types of nodes. Implementations of this interface should define the Next method, which returns the next node identity to be selected. HasNext checks if there is next node available.

type NodeSelectorFactory added in v0.32.0

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

NodeSelectorFactory is a factory for creating node selectors based on factory configuration and node type. Supported configurations: circuitBreakerEnabled = true - nodes will be pseudo-randomly sampled and picked in-order. circuitBreakerEnabled = false - nodes will be picked from proposed list in-order without any changes.

func (*NodeSelectorFactory) SelectNodes added in v0.32.0

SelectNodes selects the configured number of node identities from the provided list of nodes and returns the node selector to iterate through them.

type Params added in v0.32.0

type Params struct {
	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
	AccessMetrics             module.AccessMetrics
	ConnFactory               connection.ConnectionFactory
	RetryEnabled              bool
	MaxHeightRange            uint
	PreferredExecutionNodeIDs []string
	FixedExecutionNodeIDs     []string
	Log                       zerolog.Logger
	SnapshotHistoryLimit      int
	Communicator              Communicator
	TxResultCacheSize         uint
	TxErrorMessagesCacheSize  uint
	ScriptExecutor            execution.ScriptExecutor
	ScriptExecutionMode       IndexQueryMode
	CheckPayerBalance         bool
	EventQueryMode            IndexQueryMode
	BlockTracker              subscription.BlockTracker
	SubscriptionHandler       *subscription.SubscriptionHandler

	EventsIndex         *index.EventsIndex
	TxResultQueryMode   IndexQueryMode
	TxResultsIndex      *index.TransactionResultsIndex
	LastFullBlockHeight *counters.PersistentStrictMonotonicCounter
}

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) 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) error

Retry attempts to resend transactions for a specified block height. It performs cleanup operations, including pruning old transactions, and retries sending transactions that are still pending. The method takes a block height as input. If the provided height is lower than flow.DefaultTransactionExpiry, no retries are performed, and the method returns nil. No errors expected during normal operations.

func (*Retry) SetBackend

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

type ScriptExecutor added in v0.32.2

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

func NewScriptExecutor added in v0.32.2

func NewScriptExecutor(log zerolog.Logger, minHeight, maxHeight uint64) *ScriptExecutor

func (*ScriptExecutor) ExecuteAtBlockHeight added in v0.32.2

func (s *ScriptExecutor) ExecuteAtBlockHeight(ctx context.Context, script []byte, arguments [][]byte, height uint64) ([]byte, error)

ExecuteAtBlockHeight executes provided script at the provided block height against a local execution state.

Expected errors:

  • storage.ErrNotFound if the register or block height is not found
  • storage.ErrHeightNotIndexed if the data for the block height is not available. this could be because the height is not within the index block range, or the index is not ready.

func (*ScriptExecutor) GetAccountAtBlockHeight added in v0.32.2

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

GetAccountAtBlockHeight returns the account at the provided block height from a local execution state.

Expected errors:

  • storage.ErrNotFound if the account or block height is not found
  • storage.ErrHeightNotIndexed if the data for the block height is not available. this could be because the height is not within the index block range, or the index is not ready.

func (*ScriptExecutor) GetAccountAvailableBalance added in v0.36.1

func (s *ScriptExecutor) GetAccountAvailableBalance(ctx context.Context, address flow.Address, height uint64) (uint64, error)

GetAccountAvailableBalance returns an available balance of Flow account by the provided address and block height. Expected errors: - Script execution related errors - storage.ErrHeightNotIndexed if the data for the block height is not available

func (*ScriptExecutor) GetAccountBalance added in v0.35.17

func (s *ScriptExecutor) GetAccountBalance(ctx context.Context, address flow.Address, height uint64) (uint64, error)

GetAccountBalance returns a balance of Flow account by the provided address and block height. Expected errors: - Script execution related errors - storage.ErrHeightNotIndexed if the data for the block height is not available

func (*ScriptExecutor) GetAccountKey added in v0.36.1

func (s *ScriptExecutor) GetAccountKey(ctx context.Context, address flow.Address, keyIndex uint32, height uint64) (*flow.AccountPublicKey, error)

GetAccountKey returns Expected errors: - Script execution related errors - storage.ErrHeightNotIndexed if the data for the block height is not available

func (*ScriptExecutor) GetAccountKeys added in v0.35.17

func (s *ScriptExecutor) GetAccountKeys(ctx context.Context, address flow.Address, height uint64) ([]flow.AccountPublicKey, error)

GetAccountKeys returns a public key of Flow account by the provided address, block height and index. Expected errors: - Script execution related errors - storage.ErrHeightNotIndexed if the data for the block height is not available

func (*ScriptExecutor) Initialize added in v0.33.9

func (s *ScriptExecutor) Initialize(indexReporter state_synchronization.IndexReporter, scriptExecutor *execution.Scripts) error

Initialize initializes the indexReporter and script executor This method can be called at any time after the ScriptExecutor object is created. Any requests made to the other methods will return storage.ErrHeightNotIndexed until this method is called.

func (*ScriptExecutor) SetMaxCompatibleHeight added in v0.32.10

func (s *ScriptExecutor) SetMaxCompatibleHeight(height uint64)

SetMaxCompatibleHeight sets the highest block height (inclusive) that can be queried using local execution Use this to limit the executable block range supported by the node's current software version.

func (*ScriptExecutor) SetMinCompatibleHeight added in v0.32.10

func (s *ScriptExecutor) SetMinCompatibleHeight(height uint64)

SetMinCompatibleHeight sets the lowest block height (inclusive) that can be queried using local execution Use this to limit the executable block range supported by the node's current software version.

type TransactionErrorMessage added in v0.33.13

type TransactionErrorMessage interface {
	// LookupErrorMessageByTransactionID is a function type for getting transaction error message by block ID and transaction ID.
	// Expected errors during normal operation:
	//   - InsufficientExecutionReceipts - found insufficient receipts for given block ID.
	//   - status.Error - remote GRPC call to EN has failed.
	LookupErrorMessageByTransactionID(ctx context.Context, blockID flow.Identifier, transactionID flow.Identifier) (string, error)

	// LookupErrorMessageByIndex is a function type for getting transaction error message by index.
	// Expected errors during normal operation:
	//   - status.Error[codes.NotFound] - transaction result for given block ID and tx index is not available.
	//   - InsufficientExecutionReceipts - found insufficient receipts for given block ID.
	//   - status.Error - remote GRPC call to EN has failed.
	LookupErrorMessageByIndex(ctx context.Context, blockID flow.Identifier, height uint64, index uint32) (string, error)

	// LookupErrorMessagesByBlockID is a function type for getting transaction error messages by block ID.
	// Expected errors during normal operation:
	//   - status.Error[codes.NotFound] - transaction results for given block ID are not available.
	//   - InsufficientExecutionReceipts - found insufficient receipts for given block ID.
	//   - status.Error - remote GRPC call to EN has failed.
	LookupErrorMessagesByBlockID(ctx context.Context, blockID flow.Identifier, height uint64) (map[flow.Identifier]string, error)
}

TransactionErrorMessage declares the lookup transaction error methods by different input parameters.

type TransactionSubscriptionMetadata added in v0.33.30

type TransactionSubscriptionMetadata struct {
	*access.TransactionResult
	// contains filtered or unexported fields
}

TransactionSubscriptionMetadata holds data representing the status state for each transaction subscription.

type TransactionsLocalDataProvider added in v0.33.13

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

TransactionsLocalDataProvider provides functionality for retrieving transaction results and error messages from local storages

func (*TransactionsLocalDataProvider) DeriveTransactionStatus added in v0.33.30

func (t *TransactionsLocalDataProvider) DeriveTransactionStatus(blockHeight uint64, executed bool) (flow.TransactionStatus, error)

DeriveTransactionStatus is used to determine the status of a transaction based on the provided block height, and execution status. No errors expected during normal operations.

func (*TransactionsLocalDataProvider) DeriveUnknownTransactionStatus added in v0.33.30

func (t *TransactionsLocalDataProvider) DeriveUnknownTransactionStatus(refBlockID flow.Identifier) (flow.TransactionStatus, error)

DeriveUnknownTransactionStatus is used to determine the status of transaction that are not in a block yet based on the provided reference block ID.

func (*TransactionsLocalDataProvider) GetTransactionResultByIndexFromStorage added in v0.33.13

func (t *TransactionsLocalDataProvider) GetTransactionResultByIndexFromStorage(
	ctx context.Context,
	block *flow.Block,
	index uint32,
	requiredEventEncodingVersion entities.EventEncodingVersion,
) (*access.TransactionResult, error)

GetTransactionResultByIndexFromStorage retrieves a transaction result by index from storage. Expected errors during normal operation:

  • codes.NotFound if result cannot be provided by storage due to the absence of data.
  • codes.Internal when event payload conversion failed.
  • indexer.ErrIndexNotInitialized when txResultsIndex not initialized
  • storage.ErrHeightNotIndexed when data is unavailable

All other errors are considered as state corruption (fatal) or internal errors in the transaction error message getter or when deriving transaction status.

func (*TransactionsLocalDataProvider) GetTransactionResultFromStorage added in v0.33.13

func (t *TransactionsLocalDataProvider) GetTransactionResultFromStorage(
	ctx context.Context,
	block *flow.Block,
	transactionID flow.Identifier,
	requiredEventEncodingVersion entities.EventEncodingVersion,
) (*access.TransactionResult, error)

GetTransactionResultFromStorage retrieves a transaction result from storage by block ID and transaction ID. Expected errors during normal operation:

  • codes.NotFound when result cannot be provided by storage due to the absence of data.
  • codes.Internal if event payload conversion failed.
  • indexer.ErrIndexNotInitialized when txResultsIndex not initialized
  • storage.ErrHeightNotIndexed when data is unavailable

All other errors are considered as state corruption (fatal) or internal errors in the transaction error message getter or when deriving transaction status.

func (*TransactionsLocalDataProvider) GetTransactionResultsByBlockIDFromStorage added in v0.33.13

func (t *TransactionsLocalDataProvider) GetTransactionResultsByBlockIDFromStorage(
	ctx context.Context,
	block *flow.Block,
	requiredEventEncodingVersion entities.EventEncodingVersion,
) ([]*access.TransactionResult, error)

GetTransactionResultsByBlockIDFromStorage retrieves transaction results by block ID from storage Expected errors during normal operation:

  • codes.NotFound if result cannot be provided by storage due to the absence of data.
  • codes.Internal when event payload conversion failed.
  • indexer.ErrIndexNotInitialized when txResultsIndex not initialized
  • storage.ErrHeightNotIndexed when data is unavailable

All other errors are considered as state corruption (fatal) or internal errors in the transaction error message getter or when deriving transaction status.

func (*TransactionsLocalDataProvider) LookupCollectionIDInBlock added in v0.33.30

func (t *TransactionsLocalDataProvider) LookupCollectionIDInBlock(
	block *flow.Block,
	txID flow.Identifier,
) (flow.Identifier, error)

LookupCollectionIDInBlock returns the collection ID based on the transaction ID. The lookup is performed in block collections.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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