Skip to content

Commit

Permalink
Merge pull request #228 from onflow/exe-scripts-enabled-flag
Browse files Browse the repository at this point in the history
Add flag to disable script executions on EN
  • Loading branch information
Kay-Zee authored Dec 9, 2020
2 parents ed87689 + dc78e01 commit b48d87b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
17 changes: 16 additions & 1 deletion cmd/execution/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func main() {
syncFast bool
syncThreshold int
extensiveLog bool
scriptsEnabled bool
queriesEnabled bool
)

cmd.FlowNode(flow.RoleExecution.String()).
Expand All @@ -93,6 +95,8 @@ 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 and account queries")
flags.BoolVar(&queriesEnabled, "queries-enabled", true, "whether to enable event and transaction queries")
}).
Module("computation manager", func(node *cmd.FlowNodeBuilder) error {
rt := runtime.NewInterpreterRuntime()
Expand Down Expand Up @@ -365,7 +369,18 @@ 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,
scriptsEnabled,
queriesEnabled,
)
return rpcEng, nil
}).Run()
}
Expand Down
32 changes: 28 additions & 4 deletions engine/execution/rpc/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func New(
events storage.Events,
exeResults storage.ExecutionResults,
txResults storage.TransactionResults,
chainID flow.ChainID) *Engine {
chainID flow.ChainID,
scriptsEnabled bool,
queriesEnabled bool,
) *Engine {
log = log.With().Str("engine", "rpc").Logger()

if config.MaxMsgSize == 0 {
Expand All @@ -61,6 +64,8 @@ func New(
events: events,
exeResults: exeResults,
transactionResults: txResults,
scriptsEnabled: scriptsEnabled,
queriesEnabled: queriesEnabled,
},
server: grpc.NewServer(
grpc.MaxRecvMsgSize(config.MaxMsgSize),
Expand Down Expand Up @@ -114,6 +119,8 @@ type handler struct {
events storage.Events
exeResults storage.ExecutionResults
transactionResults storage.TransactionResults
scriptsEnabled bool
queriesEnabled bool
}

var _ execution.ExecutionAPIServer = &handler{}
Expand All @@ -128,6 +135,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 +156,14 @@ 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) {

if !h.queriesEnabled {
return nil, status.Error(codes.Unimplemented, "event queries are disabled")
}

// validate request
blockIDs := req.GetBlockIds()
Expand Down Expand Up @@ -196,6 +213,10 @@ func (h *handler) GetTransactionResult(
req *execution.GetTransactionResultRequest,
) (*execution.GetTransactionResultResponse, error) {

if !h.queriesEnabled {
return nil, status.Error(codes.Unimplemented, "transaction result queries are disabled")
}

reqBlockID := req.GetBlockId()
blockID, err := convert.BlockID(reqBlockID)
if err != nil {
Expand Down Expand Up @@ -266,6 +287,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 +321,4 @@ func (h *handler) GetAccountAtBlockID(
}

return res, nil

}

0 comments on commit b48d87b

Please sign in to comment.