github.com/onflow/flow-go@v0.33.17/cmd/execution_config.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "strings" 7 "time" 8 9 "github.com/spf13/pflag" 10 11 "github.com/onflow/flow-go/engine/common/provider" 12 "github.com/onflow/flow-go/engine/execution/computation/query" 13 exeprovider "github.com/onflow/flow-go/engine/execution/provider" 14 "github.com/onflow/flow-go/fvm" 15 "github.com/onflow/flow-go/model/flow" 16 "github.com/onflow/flow-go/module/mempool" 17 "github.com/onflow/flow-go/utils/grpcutils" 18 19 "github.com/onflow/flow-go/engine/execution/computation" 20 "github.com/onflow/flow-go/engine/execution/ingestion/stop" 21 "github.com/onflow/flow-go/engine/execution/rpc" 22 "github.com/onflow/flow-go/fvm/storage/derived" 23 storage "github.com/onflow/flow-go/storage/badger" 24 ) 25 26 // ExecutionConfig contains the configs for starting up execution nodes 27 type ExecutionConfig struct { 28 rpcConf rpc.Config 29 triedir string 30 executionDataDir string 31 registerDir string 32 mTrieCacheSize uint32 33 transactionResultsCacheSize uint 34 checkpointDistance uint 35 checkpointsToKeep uint 36 chunkDataPackDir string 37 chunkDataPackCacheSize uint 38 chunkDataPackRequestsCacheSize uint32 39 requestInterval time.Duration 40 extensiveLog bool 41 pauseExecution bool 42 chunkDataPackQueryTimeout time.Duration 43 chunkDataPackDeliveryTimeout time.Duration 44 enableBlockDataUpload bool 45 gcpBucketName string 46 s3BucketName string 47 apiRatelimits map[string]int 48 apiBurstlimits map[string]int 49 executionDataAllowedPeers string 50 executionDataPrunerHeightRangeTarget uint64 51 executionDataPrunerThreshold uint64 52 blobstoreRateLimit int 53 blobstoreBurstLimit int 54 chunkDataPackRequestWorkers uint 55 maxGracefulStopDuration time.Duration 56 importCheckpointWorkerCount int 57 58 computationConfig computation.ComputationConfig 59 receiptRequestWorkers uint // common provider engine workers 60 receiptRequestsCacheSize uint32 // common provider engine cache size 61 62 // This is included to temporarily work around an issue observed on a small number of ENs. 63 // It works around an issue where some collection nodes are not configured with enough 64 // this works around an issue where some collection nodes are not configured with enough 65 // file descriptors causing connection failures. 66 onflowOnlyLNs bool 67 enableStorehouse bool 68 enableChecker bool 69 } 70 71 func (exeConf *ExecutionConfig) SetupFlags(flags *pflag.FlagSet) { 72 datadir := "/data" 73 74 flags.StringVarP(&exeConf.rpcConf.ListenAddr, "rpc-addr", "i", "localhost:9000", "the address the gRPC server listens on") 75 flags.UintVar(&exeConf.rpcConf.MaxMsgSize, "rpc-max-message-size", grpcutils.DefaultMaxMsgSize, "the maximum message size in bytes for messages sent or received over grpc") 76 flags.BoolVar(&exeConf.rpcConf.RpcMetricsEnabled, "rpc-metrics-enabled", false, "whether to enable the rpc metrics") 77 flags.StringVar(&exeConf.triedir, "triedir", filepath.Join(datadir, "trie"), "directory to store the execution State") 78 flags.StringVar(&exeConf.executionDataDir, "execution-data-dir", filepath.Join(datadir, "execution_data"), "directory to use for storing Execution Data") 79 flags.StringVar(&exeConf.registerDir, "register-dir", filepath.Join(datadir, "register"), "directory to use for storing registers Data") 80 flags.Uint32Var(&exeConf.mTrieCacheSize, "mtrie-cache-size", 500, "cache size for MTrie") 81 flags.UintVar(&exeConf.checkpointDistance, "checkpoint-distance", 20, "number of WAL segments between checkpoints") 82 flags.UintVar(&exeConf.checkpointsToKeep, "checkpoints-to-keep", 5, "number of recent checkpoints to keep (0 to keep all)") 83 flags.UintVar(&exeConf.computationConfig.DerivedDataCacheSize, "cadence-execution-cache", derived.DefaultDerivedDataCacheSize, 84 "cache size for Cadence execution") 85 flags.BoolVar(&exeConf.computationConfig.ExtensiveTracing, "extensive-tracing", false, "adds high-overhead tracing to execution") 86 flags.BoolVar(&exeConf.computationConfig.CadenceTracing, "cadence-tracing", false, "enables cadence runtime level tracing") 87 flags.IntVar(&exeConf.computationConfig.MaxConcurrency, "computer-max-concurrency", 1, "set to greater than 1 to enable concurrent transaction execution") 88 flags.StringVar(&exeConf.chunkDataPackDir, "chunk-data-pack-dir", filepath.Join(datadir, "chunk_data_packs"), "directory to use for storing chunk data packs") 89 flags.UintVar(&exeConf.chunkDataPackCacheSize, "chdp-cache", storage.DefaultCacheSize, "cache size for chunk data packs") 90 flags.Uint32Var(&exeConf.chunkDataPackRequestsCacheSize, "chdp-request-queue", mempool.DefaultChunkDataPackRequestQueueSize, "queue size for chunk data pack requests") 91 flags.DurationVar(&exeConf.requestInterval, "request-interval", 60*time.Second, "the interval between requests for the requester engine") 92 flags.Uint32Var(&exeConf.receiptRequestsCacheSize, "receipt-request-cache", provider.DefaultEntityRequestCacheSize, "queue size for entity requests at common provider engine") 93 flags.UintVar(&exeConf.receiptRequestWorkers, "receipt-request-workers", provider.DefaultRequestProviderWorkers, "number of workers for entity requests at common provider engine") 94 flags.DurationVar(&exeConf.computationConfig.QueryConfig.LogTimeThreshold, "script-log-threshold", query.DefaultLogTimeThreshold, 95 "threshold for logging script execution") 96 flags.DurationVar(&exeConf.computationConfig.QueryConfig.ExecutionTimeLimit, "script-execution-time-limit", query.DefaultExecutionTimeLimit, 97 "script execution time limit") 98 flags.Uint64Var(&exeConf.computationConfig.QueryConfig.ComputationLimit, "script-execution-computation-limit", fvm.DefaultComputationLimit, 99 "script execution computation limit") 100 flags.UintVar(&exeConf.transactionResultsCacheSize, "transaction-results-cache-size", 10000, "number of transaction results to be cached") 101 flags.BoolVar(&exeConf.extensiveLog, "extensive-logging", false, "extensive logging logs tx contents and block headers") 102 flags.DurationVar(&exeConf.chunkDataPackQueryTimeout, "chunk-data-pack-query-timeout", exeprovider.DefaultChunkDataPackQueryTimeout, "timeout duration to determine a chunk data pack query being slow") 103 flags.DurationVar(&exeConf.chunkDataPackDeliveryTimeout, "chunk-data-pack-delivery-timeout", exeprovider.DefaultChunkDataPackDeliveryTimeout, "timeout duration to determine a chunk data pack response delivery being slow") 104 flags.UintVar(&exeConf.chunkDataPackRequestWorkers, "chunk-data-pack-workers", exeprovider.DefaultChunkDataPackRequestWorker, "number of workers to process chunk data pack requests") 105 flags.BoolVar(&exeConf.pauseExecution, "pause-execution", false, "pause the execution. when set to true, no block will be executed, "+ 106 "but still be able to serve queries") 107 flags.BoolVar(&exeConf.enableBlockDataUpload, "enable-blockdata-upload", false, "enable uploading block data to Cloud Bucket") 108 flags.StringVar(&exeConf.gcpBucketName, "gcp-bucket-name", "", "GCP Bucket name for block data uploader") 109 flags.StringVar(&exeConf.s3BucketName, "s3-bucket-name", "", "S3 Bucket name for block data uploader") 110 flags.StringVar(&exeConf.executionDataAllowedPeers, "execution-data-allowed-requesters", "", "comma separated list of Access node IDs that are allowed to request Execution Data. an empty list allows all peers") 111 flags.Uint64Var(&exeConf.executionDataPrunerHeightRangeTarget, "execution-data-height-range-target", 0, "target height range size used to limit the amount of Execution Data kept on disk") 112 flags.Uint64Var(&exeConf.executionDataPrunerThreshold, "execution-data-height-range-threshold", 100_000, "height threshold used to trigger Execution Data pruning") 113 flags.StringToIntVar(&exeConf.apiRatelimits, "api-rate-limits", map[string]int{}, "per second rate limits for GRPC API methods e.g. Ping=300,ExecuteScriptAtBlockID=500 etc. note limits apply globally to all clients.") 114 flags.StringToIntVar(&exeConf.apiBurstlimits, "api-burst-limits", map[string]int{}, "burst limits for gRPC API methods e.g. Ping=100,ExecuteScriptAtBlockID=100 etc. note limits apply globally to all clients.") 115 flags.IntVar(&exeConf.blobstoreRateLimit, "blobstore-rate-limit", 0, "per second outgoing rate limit for Execution Data blobstore") 116 flags.IntVar(&exeConf.blobstoreBurstLimit, "blobstore-burst-limit", 0, "outgoing burst limit for Execution Data blobstore") 117 flags.DurationVar(&exeConf.maxGracefulStopDuration, "max-graceful-stop-duration", stop.DefaultMaxGracefulStopDuration, "the maximum amount of time stop control will wait for ingestion engine to gracefully shutdown before crashing") 118 flags.IntVar(&exeConf.importCheckpointWorkerCount, "import-checkpoint-worker-count", 10, "number of workers to import checkpoint file during bootstrap") 119 120 flags.BoolVar(&exeConf.onflowOnlyLNs, "temp-onflow-only-lns", false, "do not use unless required. forces node to only request collections from onflow collection nodes") 121 flags.BoolVar(&exeConf.enableStorehouse, "enable-storehouse", false, "enable storehouse to store registers on disk, default is false") 122 flags.BoolVar(&exeConf.enableChecker, "enable-checker", true, "enable checker to check the correctness of the execution result, default is true") 123 124 } 125 126 func (exeConf *ExecutionConfig) ValidateFlags() error { 127 if exeConf.enableBlockDataUpload { 128 if exeConf.gcpBucketName == "" && exeConf.s3BucketName == "" { 129 return fmt.Errorf("invalid flag. gcp-bucket-name or s3-bucket-name required when blockdata-uploader is enabled") 130 } 131 } 132 if exeConf.executionDataAllowedPeers != "" { 133 ids := strings.Split(exeConf.executionDataAllowedPeers, ",") 134 for _, id := range ids { 135 if _, err := flow.HexStringToIdentifier(id); err != nil { 136 return fmt.Errorf("invalid node ID in execution-data-allowed-requesters %s: %w", id, err) 137 } 138 } 139 } 140 return nil 141 }