github.com/koko1123/flow-go-1@v0.29.6/cmd/execution_config.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strings" 8 "time" 9 10 "github.com/spf13/pflag" 11 12 "github.com/koko1123/flow-go-1/engine/common/provider" 13 exeprovider "github.com/koko1123/flow-go-1/engine/execution/provider" 14 "github.com/koko1123/flow-go-1/model/flow" 15 "github.com/koko1123/flow-go-1/module/mempool" 16 17 "github.com/koko1123/flow-go-1/engine/execution/computation" 18 "github.com/koko1123/flow-go-1/engine/execution/rpc" 19 "github.com/koko1123/flow-go-1/fvm/derived" 20 storage "github.com/koko1123/flow-go-1/storage/badger" 21 ) 22 23 // ExecutionConfig contains the configs for starting up execution nodes 24 type ExecutionConfig struct { 25 rpcConf rpc.Config 26 triedir string 27 executionDataDir string 28 mTrieCacheSize uint32 29 transactionResultsCacheSize uint 30 checkpointDistance uint 31 checkpointsToKeep uint 32 stateDeltasLimit uint 33 chunkDataPackCacheSize uint 34 chunkDataPackRequestsCacheSize uint32 35 requestInterval time.Duration 36 preferredExeNodeIDStr string 37 syncByBlocks bool 38 syncFast bool 39 syncThreshold int 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 56 computationConfig computation.ComputationConfig 57 receiptRequestWorkers uint // common provider engine workers 58 receiptRequestsCacheSize uint32 // common provider engine cache size 59 } 60 61 func (exeConf *ExecutionConfig) SetupFlags(flags *pflag.FlagSet) { 62 homedir, _ := os.UserHomeDir() 63 datadir := filepath.Join(homedir, ".flow", "execution") 64 65 flags.StringVarP(&exeConf.rpcConf.ListenAddr, "rpc-addr", "i", "localhost:9000", "the address the gRPC server listens on") 66 flags.BoolVar(&exeConf.rpcConf.RpcMetricsEnabled, "rpc-metrics-enabled", false, "whether to enable the rpc metrics") 67 flags.StringVar(&exeConf.triedir, "triedir", datadir, "directory to store the execution State") 68 flags.StringVar(&exeConf.executionDataDir, "execution-data-dir", filepath.Join(homedir, ".flow", "execution_data"), "directory to use for storing Execution Data") 69 flags.Uint32Var(&exeConf.mTrieCacheSize, "mtrie-cache-size", 500, "cache size for MTrie") 70 flags.UintVar(&exeConf.checkpointDistance, "checkpoint-distance", 20, "number of WAL segments between checkpoints") 71 flags.UintVar(&exeConf.checkpointsToKeep, "checkpoints-to-keep", 5, "number of recent checkpoints to keep (0 to keep all)") 72 flags.UintVar(&exeConf.stateDeltasLimit, "state-deltas-limit", 100, "maximum number of state deltas in the memory pool") 73 flags.UintVar(&exeConf.computationConfig.DerivedDataCacheSize, "cadence-execution-cache", derived.DefaultDerivedDataCacheSize, 74 "cache size for Cadence execution") 75 flags.BoolVar(&exeConf.computationConfig.ExtensiveTracing, "extensive-tracing", false, "adds high-overhead tracing to execution") 76 flags.BoolVar(&exeConf.computationConfig.CadenceTracing, "cadence-tracing", false, "enables cadence runtime level tracing") 77 flags.UintVar(&exeConf.chunkDataPackCacheSize, "chdp-cache", storage.DefaultCacheSize, "cache size for chunk data packs") 78 flags.Uint32Var(&exeConf.chunkDataPackRequestsCacheSize, "chdp-request-queue", mempool.DefaultChunkDataPackRequestQueueSize, "queue size for chunk data pack requests") 79 flags.DurationVar(&exeConf.requestInterval, "request-interval", 60*time.Second, "the interval between requests for the requester engine") 80 flags.Uint32Var(&exeConf.receiptRequestsCacheSize, "receipt-request-cache", provider.DefaultEntityRequestCacheSize, "queue size for entity requests at common provider engine") 81 flags.UintVar(&exeConf.receiptRequestWorkers, "receipt-request-workers", provider.DefaultRequestProviderWorkers, "number of workers for entity requests at common provider engine") 82 flags.DurationVar(&exeConf.computationConfig.ScriptLogThreshold, "script-log-threshold", computation.DefaultScriptLogThreshold, 83 "threshold for logging script execution") 84 flags.DurationVar(&exeConf.computationConfig.ScriptExecutionTimeLimit, "script-execution-time-limit", computation.DefaultScriptExecutionTimeLimit, 85 "script execution time limit") 86 flags.StringVar(&exeConf.preferredExeNodeIDStr, "preferred-exe-node-id", "", "node ID for preferred execution node used for state sync") 87 flags.UintVar(&exeConf.transactionResultsCacheSize, "transaction-results-cache-size", 10000, "number of transaction results to be cached") 88 flags.BoolVar(&exeConf.syncByBlocks, "sync-by-blocks", true, "deprecated, sync by blocks instead of execution state deltas") 89 flags.BoolVar(&exeConf.syncFast, "sync-fast", false, "fast sync allows execution node to skip fetching collection during state syncing,"+ 90 " and rely on state syncing to catch up") 91 flags.IntVar(&exeConf.syncThreshold, "sync-threshold", 100, 92 "the maximum number of sealed and unexecuted blocks before triggering state syncing") 93 flags.BoolVar(&exeConf.extensiveLog, "extensive-logging", false, "extensive logging logs tx contents and block headers") 94 flags.DurationVar(&exeConf.chunkDataPackQueryTimeout, "chunk-data-pack-query-timeout", exeprovider.DefaultChunkDataPackQueryTimeout, "timeout duration to determine a chunk data pack query being slow") 95 flags.DurationVar(&exeConf.chunkDataPackDeliveryTimeout, "chunk-data-pack-delivery-timeout", exeprovider.DefaultChunkDataPackDeliveryTimeout, "timeout duration to determine a chunk data pack response delivery being slow") 96 flags.UintVar(&exeConf.chunkDataPackRequestWorkers, "chunk-data-pack-workers", exeprovider.DefaultChunkDataPackRequestWorker, "number of workers to process chunk data pack requests") 97 flags.BoolVar(&exeConf.pauseExecution, "pause-execution", false, "pause the execution. when set to true, no block will be executed, "+ 98 "but still be able to serve queries") 99 flags.BoolVar(&exeConf.enableBlockDataUpload, "enable-blockdata-upload", false, "enable uploading block data to Cloud Bucket") 100 flags.StringVar(&exeConf.gcpBucketName, "gcp-bucket-name", "", "GCP Bucket name for block data uploader") 101 flags.StringVar(&exeConf.s3BucketName, "s3-bucket-name", "", "S3 Bucket name for block data uploader") 102 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") 103 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") 104 flags.Uint64Var(&exeConf.executionDataPrunerThreshold, "execution-data-height-range-threshold", 100_000, "height threshold used to trigger Execution Data pruning") 105 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.") 106 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.") 107 flags.IntVar(&exeConf.blobstoreRateLimit, "blobstore-rate-limit", 0, "per second outgoing rate limit for Execution Data blobstore") 108 flags.IntVar(&exeConf.blobstoreBurstLimit, "blobstore-burst-limit", 0, "outgoing burst limit for Execution Data blobstore") 109 } 110 111 func (exeConf *ExecutionConfig) ValidateFlags() error { 112 if exeConf.enableBlockDataUpload { 113 if exeConf.gcpBucketName == "" && exeConf.s3BucketName == "" { 114 return fmt.Errorf("invalid flag. gcp-bucket-name or s3-bucket-name required when blockdata-uploader is enabled") 115 } 116 } 117 if exeConf.executionDataAllowedPeers != "" { 118 ids := strings.Split(exeConf.executionDataAllowedPeers, ",") 119 for _, id := range ids { 120 if _, err := flow.HexStringToIdentifier(id); err != nil { 121 return fmt.Errorf("invalid node ID in execution-data-allowed-requesters %s: %w", id, err) 122 } 123 } 124 } 125 return nil 126 }