Documentation ¶
Index ¶
- Constants
- Variables
- func IsInsufficientExecutionReceipts(err error) bool
- func NewCache(log zerolog.Logger, metrics module.AccessMetrics, connectionPoolSize int) (*lru.Cache[string, *connection.CachedClient], error)
- func NewNetworkAPI(state protocol.State, chainID flow.ChainID, snapshotHistoryLimit int) *backendNetwork
- type Backend
- func (b *Backend) ExecuteScriptAtBlockHeight(ctx context.Context, blockHeight uint64, script []byte, arguments [][]byte) ([]byte, error)
- func (b *Backend) ExecuteScriptAtBlockID(ctx context.Context, blockID flow.Identifier, script []byte, ...) ([]byte, error)
- func (b *Backend) ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments [][]byte) ([]byte, error)
- func (b *Backend) GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error)
- func (b *Backend) GetAccountAtBlockHeight(ctx context.Context, address flow.Address, height uint64) (*flow.Account, error)
- func (b *Backend) GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error)
- func (b *Backend) GetBlockByHeight(_ context.Context, height uint64) (*flow.Block, flow.BlockStatus, error)
- func (b *Backend) GetBlockByID(_ context.Context, id flow.Identifier) (*flow.Block, flow.BlockStatus, error)
- func (b *Backend) GetBlockHeaderByHeight(_ context.Context, height uint64) (*flow.Header, flow.BlockStatus, error)
- func (b *Backend) GetBlockHeaderByID(_ context.Context, id flow.Identifier) (*flow.Header, flow.BlockStatus, error)
- func (b *Backend) GetCollectionByID(_ context.Context, colID flow.Identifier) (*flow.LightCollection, error)
- func (b *Backend) GetEventsForBlockIDs(ctx context.Context, eventType string, blockIDs []flow.Identifier, ...) ([]flow.BlockEvents, error)
- func (b *Backend) GetEventsForHeightRange(ctx context.Context, eventType string, startHeight, endHeight uint64, ...) ([]flow.BlockEvents, error)
- func (b *Backend) GetExecutionResultByID(ctx context.Context, id flow.Identifier) (*flow.ExecutionResult, error)
- func (b *Backend) GetExecutionResultForBlockID(ctx context.Context, blockID flow.Identifier) (*flow.ExecutionResult, error)
- func (b *Backend) GetLatestBlock(_ context.Context, isSealed bool) (*flow.Block, flow.BlockStatus, error)
- func (b *Backend) GetLatestBlockHeader(_ context.Context, isSealed bool) (*flow.Header, flow.BlockStatus, error)
- func (b *Backend) GetLatestProtocolStateSnapshot(_ context.Context) ([]byte, error)
- func (b *Backend) GetNetworkParameters(_ context.Context) access.NetworkParameters
- func (b *Backend) GetNodeVersionInfo(_ context.Context) (*access.NodeVersionInfo, error)
- func (b *Backend) GetTransaction(ctx context.Context, txID flow.Identifier) (*flow.TransactionBody, error)
- func (b *Backend) GetTransactionResult(ctx context.Context, txID flow.Identifier, blockID flow.Identifier, ...) (*access.TransactionResult, error)
- func (b *Backend) GetTransactionResultByIndex(ctx context.Context, blockID flow.Identifier, index uint32, ...) (*access.TransactionResult, error)
- func (b *Backend) GetTransactionResultsByBlockID(ctx context.Context, blockID flow.Identifier, ...) ([]*access.TransactionResult, error)
- func (b *Backend) GetTransactionsByBlockID(ctx context.Context, blockID flow.Identifier) ([]*flow.TransactionBody, error)
- func (b *Backend) NotifyFinalizedBlockHeight(height uint64)
- func (b *Backend) Ping(ctx context.Context) error
- func (b *Backend) SendRawTransaction(ctx context.Context, tx *flow.TransactionBody) error
- func (b *Backend) SendTransaction(ctx context.Context, tx *flow.TransactionBody) error
- type Communicator
- type Config
- type InsufficientExecutionReceipts
- type MainNodeSelector
- type NodeCommunicator
- type NodeSelector
- type NodeSelectorFactory
- type Params
- type Retry
- type ScriptExecutionMode
- type ScriptExecutor
- func (s *ScriptExecutor) ExecuteAtBlockHeight(ctx context.Context, script []byte, arguments [][]byte, height uint64) ([]byte, error)
- func (s *ScriptExecutor) GetAccountAtBlockHeight(ctx context.Context, address flow.Address, height uint64) (*flow.Account, error)
- func (s *ScriptExecutor) InitReporter(indexReporter state_synchronization.IndexReporter, ...)
Constants ¶
const DefaultConnectionPoolSize = 250
DefaultConnectionPoolSize is the default size for the connection pool to collection and execution nodes
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
const DefaultMaxHeightRange = 250
DefaultMaxHeightRange is the default maximum size of range requests.
const DefaultSnapshotHistoryLimit = 50
DefaultSnapshotHistoryLimit the amount of blocks to look back in state when recursively searching for a valid snapshot
Variables ¶
var SnapshotHistoryLimitErr = fmt.Errorf("reached the snapshot history limit")
Functions ¶
func IsInsufficientExecutionReceipts ¶ added in v0.30.0
func NewCache ¶ added in v0.32.0
func NewCache( log zerolog.Logger, metrics module.AccessMetrics, connectionPoolSize int, ) (*lru.Cache[string, *connection.CachedClient], error)
NewCache constructs cache for storing connections to other nodes. No errors are expected during normal operations.
func NewNetworkAPI ¶ added in v0.28.0
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
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 (*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 ¶
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) GetBlockByHeight ¶
func (*Backend) GetBlockByID ¶
func (b *Backend) GetBlockByID(_ context.Context, id flow.Identifier) (*flow.Block, flow.BlockStatus, error)
func (*Backend) GetBlockHeaderByHeight ¶
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, 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) GetLatestBlock ¶
func (*Backend) GetLatestBlockHeader ¶
func (*Backend) GetLatestProtocolStateSnapshot ¶ added in v0.15.0
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
GetNodeVersionInfo returns node version information such as semver, commit, sporkID, protocolVersion, etc
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( ctx context.Context, blockID flow.Identifier, ) ([]*flow.TransactionBody, error)
func (*Backend) NotifyFinalizedBlockHeight ¶
func (b *Backend) NotifyFinalizedBlockHeight(height uint64)
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 Communicator ¶ added in v0.32.0
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 }
Config defines the configurable options for creating Backend
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
func (e InsufficientExecutionReceipts) Error() string
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.IdentityList) *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
func (e *MainNodeSelector) Next() *flow.Identity
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.IdentityList, call func(id *flow.Identity) error, shouldTerminateOnError func(node *flow.Identity, 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
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
func (n *NodeSelectorFactory) SelectNodes(nodes flow.IdentityList) (NodeSelector, error)
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 ScriptExecutor execution.ScriptExecutor ScriptExecutionMode ScriptExecutionMode }
type Retry ¶
type Retry struct {
// contains filtered or unexported fields
}
Retry implements a simple retry mechanism for transaction submission.
func (*Retry) RegisterTransaction ¶
func (r *Retry) RegisterTransaction(height uint64, tx *flow.TransactionBody)
RegisterTransaction adds a transaction that could possibly be retried
func (*Retry) SetBackend ¶
type ScriptExecutionMode ¶ added in v0.32.2
type ScriptExecutionMode int
const ( // ScriptExecutionModeLocalOnly executes scripts and gets accounts using only local storage ScriptExecutionModeLocalOnly ScriptExecutionMode = iota + 1 // ScriptExecutionModeExecutionNodesOnly executes scripts and gets accounts using only // execution nodes ScriptExecutionModeExecutionNodesOnly // ScriptExecutionModeFailover 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. ScriptExecutionModeFailover // ScriptExecutionModeCompare executes scripts and gets accounts using both local storage and // execution nodes and compares the results. The execution node result is always returned. ScriptExecutionModeCompare )
func ParseScriptExecutionMode ¶ added in v0.32.2
func ParseScriptExecutionMode(s string) (ScriptExecutionMode, error)
func (ScriptExecutionMode) String ¶ added in v0.32.2
func (m ScriptExecutionMode) String() string
type ScriptExecutor ¶ added in v0.32.2
type ScriptExecutor struct {
// contains filtered or unexported fields
}
func NewScriptExecutor ¶ added in v0.32.2
func NewScriptExecutor() *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
- execution.ErrDataNotAvailable 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
- execution.ErrDataNotAvailable 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) InitReporter ¶ added in v0.32.2
func (s *ScriptExecutor) InitReporter(indexReporter state_synchronization.IndexReporter, scriptExecutor *execution.Scripts)
InitReporter 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 execution.ErrDataNotAvailable until this method is called.