From 19c67b8394d78b6c15c98273aa41f367fe89111e Mon Sep 17 00:00:00 2001 From: Peter Siemens Date: Tue, 8 Dec 2020 22:01:29 -0800 Subject: [PATCH] Add scripts-enabled flag to execution node --- cmd/execution/main.go | 13 ++++++++++++- engine/execution/rpc/engine.go | 21 +++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/cmd/execution/main.go b/cmd/execution/main.go index 5e9e0adc752..9160e976e93 100644 --- a/cmd/execution/main.go +++ b/cmd/execution/main.go @@ -75,6 +75,7 @@ func main() { syncFast bool syncThreshold int extensiveLog bool + scriptsEnabled bool ) cmd.FlowNode(flow.RoleExecution.String()). @@ -93,6 +94,7 @@ func main() { flags.BoolVar(&syncFast, "sync-fast", false, "fast sync allows execution node to skip fetching collection during state syncing, and rely on state syncing to catch up") flags.IntVar(&syncThreshold, "sync-threshold", 100, "the maximum number of sealed and unexecuted blocks before triggering state syncing") flags.BoolVar(&extensiveLog, "extensive-logging", false, "extensive logging logs tx contents and block headers") + flags.BoolVar(&scriptsEnabled, "scripts-enabled", true, "whether to enable script executions") }). Module("computation manager", func(node *cmd.FlowNodeBuilder) error { rt := runtime.NewInterpreterRuntime() @@ -365,7 +367,16 @@ func main() { return syncEngine, nil }). Component("grpc server", func(node *cmd.FlowNodeBuilder) (module.ReadyDoneAware, error) { - rpcEng := rpc.New(node.Logger, rpcConf, ingestionEng, node.Storage.Blocks, events, results, txResults, node.RootChainID) + rpcEng := rpc.New( + node.Logger, + rpcConf, + ingestionEng, + node.Storage.Blocks, + events, + results, + txResults, + node.RootChainID, + ) return rpcEng, nil }).Run() } diff --git a/engine/execution/rpc/engine.go b/engine/execution/rpc/engine.go index 2f593a474e0..a0e65a3700c 100644 --- a/engine/execution/rpc/engine.go +++ b/engine/execution/rpc/engine.go @@ -44,7 +44,9 @@ func New( events storage.Events, exeResults storage.ExecutionResults, txResults storage.TransactionResults, - chainID flow.ChainID) *Engine { + chainID flow.ChainID, + scriptsEnabled bool, +) *Engine { log = log.With().Str("engine", "rpc").Logger() if config.MaxMsgSize == 0 { @@ -61,6 +63,7 @@ func New( events: events, exeResults: exeResults, transactionResults: txResults, + scriptsEnabled: scriptsEnabled, }, server: grpc.NewServer( grpc.MaxRecvMsgSize(config.MaxMsgSize), @@ -114,6 +117,7 @@ type handler struct { events storage.Events exeResults storage.ExecutionResults transactionResults storage.TransactionResults + scriptsEnabled bool } var _ execution.ExecutionAPIServer = &handler{} @@ -128,6 +132,10 @@ func (h *handler) ExecuteScriptAtBlockID( req *execution.ExecuteScriptAtBlockIDRequest, ) (*execution.ExecuteScriptAtBlockIDResponse, error) { + if !h.scriptsEnabled { + return nil, status.Error(codes.Unimplemented, "script executions are disabled") + } + blockID, err := convert.BlockID(req.GetBlockId()) if err != nil { return nil, err @@ -145,8 +153,10 @@ func (h *handler) ExecuteScriptAtBlockID( return res, nil } -func (h *handler) GetEventsForBlockIDs(_ context.Context, - req *execution.GetEventsForBlockIDsRequest) (*execution.GetEventsForBlockIDsResponse, error) { +func (h *handler) GetEventsForBlockIDs( + _ context.Context, + req *execution.GetEventsForBlockIDsRequest, +) (*execution.GetEventsForBlockIDsResponse, error) { // validate request blockIDs := req.GetBlockIds() @@ -266,6 +276,10 @@ func (h *handler) GetAccountAtBlockID( req *execution.GetAccountAtBlockIDRequest, ) (*execution.GetAccountAtBlockIDResponse, error) { + if !h.scriptsEnabled { + return nil, status.Error(codes.Unimplemented, "account queries are disabled") + } + blockID := req.GetBlockId() blockFlowID, err := convert.BlockID(blockID) if err != nil { @@ -296,5 +310,4 @@ func (h *handler) GetAccountAtBlockID( } return res, nil - }