Skip to content

Commit

Permalink
Merge pull request #5037 from onflow/petera/4776-make-script-exec-con…
Browse files Browse the repository at this point in the history
…figurable

[Access] Make script exec configurable
  • Loading branch information
peterargue authored Nov 20, 2023
2 parents 6948717 + bb6f2b8 commit 2608c0f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ type AccessNodeConfig struct {
executionDataIndexingEnabled bool
registersDBPath string
checkpointFile string
scriptExecutorConfig query.QueryConfig
}

type PublicNetworkConfig struct {
Expand Down Expand Up @@ -232,6 +233,7 @@ func DefaultAccessNodeConfig() *AccessNodeConfig {
executionDataIndexingEnabled: false,
registersDBPath: filepath.Join(homedir, ".flow", "execution_state"),
checkpointFile: cmd.NotSet,
scriptExecutorConfig: query.NewDefaultConfig(),
}
}

Expand Down Expand Up @@ -771,6 +773,7 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
query.NewProtocolStateWrapper(builder.State),
builder.Storage.Headers,
builder.ExecutionIndexerCore.RegisterValue,
builder.scriptExecutorConfig,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -929,6 +932,11 @@ func (builder *FlowAccessNodeBuilder) extraFlags() {

// Script Execution
flags.StringVar(&builder.rpcConf.BackendConfig.ScriptExecutionMode, "script-execution-mode", defaultConfig.rpcConf.BackendConfig.ScriptExecutionMode, "mode to use when executing scripts. one of (local-only, execution-nodes-only, failover, compare)")
flags.Uint64Var(&builder.scriptExecutorConfig.ComputationLimit, "script-execution-computation-limit", defaultConfig.scriptExecutorConfig.ComputationLimit, "maximum number of computation units a locally executed script can use. default: 100000")
flags.IntVar(&builder.scriptExecutorConfig.MaxErrorMessageSize, "script-execution-max-error-length", defaultConfig.scriptExecutorConfig.MaxErrorMessageSize, "maximum number characters to include in error message strings. additional characters are truncated. default: 1000")
flags.DurationVar(&builder.scriptExecutorConfig.LogTimeThreshold, "script-execution-log-time-threshold", defaultConfig.scriptExecutorConfig.LogTimeThreshold, "emit a log for any scripts that take over this threshold. default: 1s")
flags.DurationVar(&builder.scriptExecutorConfig.ExecutionTimeLimit, "script-execution-timeout", defaultConfig.scriptExecutorConfig.ExecutionTimeLimit, "timeout value for locally executed scripts. default: 10s")

}).ValidateFlags(func() error {
if builder.supportsObserver && (builder.PublicNetworkConfig.BindAddress == cmd.NotSet || builder.PublicNetworkConfig.BindAddress == "") {
return errors.New("public-network-address must be set if supports-observer is true")
Expand Down
3 changes: 3 additions & 0 deletions cmd/execution_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/onflow/flow-go/engine/common/provider"
"github.com/onflow/flow-go/engine/execution/computation/query"
exeprovider "github.com/onflow/flow-go/engine/execution/provider"
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/mempool"
"github.com/onflow/flow-go/utils/grpcutils"
Expand Down Expand Up @@ -89,6 +90,8 @@ func (exeConf *ExecutionConfig) SetupFlags(flags *pflag.FlagSet) {
"threshold for logging script execution")
flags.DurationVar(&exeConf.computationConfig.QueryConfig.ExecutionTimeLimit, "script-execution-time-limit", query.DefaultExecutionTimeLimit,
"script execution time limit")
flags.Uint64Var(&exeConf.computationConfig.QueryConfig.ComputationLimit, "script-execution-computation-limit", fvm.DefaultComputationLimit,
"script execution computation limit")
flags.UintVar(&exeConf.transactionResultsCacheSize, "transaction-results-cache-size", 10000, "number of transaction results to be cached")
flags.BoolVar(&exeConf.extensiveLog, "extensive-logging", false, "extensive logging logs tx contents and block headers")
flags.DurationVar(&exeConf.chunkDataPackQueryTimeout, "chunk-data-pack-query-timeout", exeprovider.DefaultChunkDataPackQueryTimeout, "timeout duration to determine a chunk data pack query being slow")
Expand Down
5 changes: 5 additions & 0 deletions engine/execution/computation/query/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ type Executor interface {
type QueryConfig struct {
LogTimeThreshold time.Duration
ExecutionTimeLimit time.Duration
ComputationLimit uint64
MaxErrorMessageSize int
}

func NewDefaultConfig() QueryConfig {
return QueryConfig{
LogTimeThreshold: DefaultLogTimeThreshold,
ExecutionTimeLimit: DefaultExecutionTimeLimit,
ComputationLimit: fvm.DefaultComputationLimit,
MaxErrorMessageSize: DefaultMaxErrorMessageSize,
}
}
Expand All @@ -87,6 +89,9 @@ func NewQueryExecutor(
derivedChainData *derived.DerivedChainData,
entropyPerBlock EntropyProviderPerBlock,
) *QueryExecutor {
if config.ComputationLimit > 0 {
vmCtx = fvm.NewContextFromParent(vmCtx, fvm.WithComputationLimit(config.ComputationLimit))
}
return &QueryExecutor{
config: config,
logger: logger,
Expand Down
3 changes: 2 additions & 1 deletion module/execution/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func NewScripts(
entropy query.EntropyProviderPerBlock,
header storage.Headers,
registerAtHeight RegisterAtHeight,
queryConf query.QueryConfig,
) (*Scripts, error) {
vm := fvm.NewVirtualMachine()

Expand All @@ -80,7 +81,7 @@ func NewScripts(
}

queryExecutor := query.NewQueryExecutor(
query.NewDefaultConfig(),
queryConf,
log,
metrics,
vm,
Expand Down
2 changes: 2 additions & 0 deletions module/execution/scripts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
mocks "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"

"github.com/onflow/flow-go/engine/execution/computation/query"
"github.com/onflow/flow-go/engine/execution/computation/query/mock"
"github.com/onflow/flow-go/engine/execution/testutil"
"github.com/onflow/flow-go/fvm"
Expand Down Expand Up @@ -165,6 +166,7 @@ func (s *scriptTestSuite) SetupTest() {
entropyBlock,
headers,
index.RegisterValue,
query.NewDefaultConfig(),
)
s.Require().NoError(err)
s.scripts = scripts
Expand Down

0 comments on commit 2608c0f

Please sign in to comment.