github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rpc/backend/config.go (about)

     1  package backend
     2  
     3  import (
     4  	"errors"
     5  	"time"
     6  
     7  	"github.com/onflow/flow-go/engine/access/rpc/connection"
     8  )
     9  
    10  // Config defines the configurable options for creating Backend
    11  type Config struct {
    12  	ExecutionClientTimeout    time.Duration                   // execution API GRPC client timeout
    13  	CollectionClientTimeout   time.Duration                   // collection API GRPC client timeout
    14  	ConnectionPoolSize        uint                            // size of the cache for storing collection and execution connections
    15  	MaxHeightRange            uint                            // max size of height range requests
    16  	PreferredExecutionNodeIDs []string                        // preferred list of upstream execution node IDs
    17  	FixedExecutionNodeIDs     []string                        // fixed list of execution node IDs to choose from if no node ID can be chosen from the PreferredExecutionNodeIDs
    18  	CircuitBreakerConfig      connection.CircuitBreakerConfig // the configuration for circuit breaker
    19  	ScriptExecutionMode       string                          // the mode in which scripts are executed
    20  	EventQueryMode            string                          // the mode in which events are queried
    21  	TxResultQueryMode         string                          // the mode in which tx results are queried
    22  }
    23  
    24  type IndexQueryMode int
    25  
    26  const (
    27  	// IndexQueryModeLocalOnly executes scripts and gets accounts using only local storage
    28  	IndexQueryModeLocalOnly IndexQueryMode = iota + 1
    29  
    30  	// IndexQueryModeExecutionNodesOnly executes scripts and gets accounts using only
    31  	// execution nodes
    32  	IndexQueryModeExecutionNodesOnly
    33  
    34  	// IndexQueryModeFailover executes scripts and gets accounts using local storage first,
    35  	// then falls back to execution nodes if data is not available for the height or if request
    36  	// failed due to a non-user error.
    37  	IndexQueryModeFailover
    38  
    39  	// IndexQueryModeCompare executes scripts and gets accounts using both local storage and
    40  	// execution nodes and compares the results. The execution node result is always returned.
    41  	IndexQueryModeCompare
    42  )
    43  
    44  func ParseIndexQueryMode(s string) (IndexQueryMode, error) {
    45  	switch s {
    46  	case IndexQueryModeLocalOnly.String():
    47  		return IndexQueryModeLocalOnly, nil
    48  	case IndexQueryModeExecutionNodesOnly.String():
    49  		return IndexQueryModeExecutionNodesOnly, nil
    50  	case IndexQueryModeFailover.String():
    51  		return IndexQueryModeFailover, nil
    52  	case IndexQueryModeCompare.String():
    53  		return IndexQueryModeCompare, nil
    54  	default:
    55  		return 0, errors.New("invalid script execution mode")
    56  	}
    57  }
    58  
    59  func (m IndexQueryMode) String() string {
    60  	switch m {
    61  	case IndexQueryModeLocalOnly:
    62  		return "local-only"
    63  	case IndexQueryModeExecutionNodesOnly:
    64  		return "execution-nodes-only"
    65  	case IndexQueryModeFailover:
    66  		return "failover"
    67  	case IndexQueryModeCompare:
    68  		return "compare"
    69  	default:
    70  		return ""
    71  	}
    72  }