Skip to content

Commit

Permalink
Add scripts-enabled flag to execution node
Browse files Browse the repository at this point in the history
  • Loading branch information
psiemens committed Dec 9, 2020
1 parent ed87689 commit 19c67b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
13 changes: 12 additions & 1 deletion cmd/execution/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func main() {
syncFast bool
syncThreshold int
extensiveLog bool
scriptsEnabled bool
)

cmd.FlowNode(flow.RoleExecution.String()).
Expand All @@ -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()
Expand Down Expand Up @@ -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()
}
Expand Down
21 changes: 17 additions & 4 deletions engine/execution/rpc/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -61,6 +63,7 @@ func New(
events: events,
exeResults: exeResults,
transactionResults: txResults,
scriptsEnabled: scriptsEnabled,
},
server: grpc.NewServer(
grpc.MaxRecvMsgSize(config.MaxMsgSize),
Expand Down Expand Up @@ -114,6 +117,7 @@ type handler struct {
events storage.Events
exeResults storage.ExecutionResults
transactionResults storage.TransactionResults
scriptsEnabled bool
}

var _ execution.ExecutionAPIServer = &handler{}
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -296,5 +310,4 @@ func (h *handler) GetAccountAtBlockID(
}

return res, nil

}

0 comments on commit 19c67b8

Please sign in to comment.