Skip to content

Commit

Permalink
Add queries-enabled flag to EN
Browse files Browse the repository at this point in the history
  • Loading branch information
psiemens committed Dec 9, 2020
1 parent 6f00d8c commit dc78e01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/execution/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func main() {
syncThreshold int
extensiveLog bool
scriptsEnabled bool
queriesEnabled bool
)

cmd.FlowNode(flow.RoleExecution.String()).
Expand All @@ -94,7 +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")
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 @@ -377,6 +379,7 @@ func main() {
txResults,
node.RootChainID,
scriptsEnabled,
queriesEnabled,
)
return rpcEng, nil
}).Run()
Expand Down
11 changes: 11 additions & 0 deletions engine/execution/rpc/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func New(
txResults storage.TransactionResults,
chainID flow.ChainID,
scriptsEnabled bool,
queriesEnabled bool,
) *Engine {
log = log.With().Str("engine", "rpc").Logger()

Expand All @@ -64,6 +65,7 @@ func New(
exeResults: exeResults,
transactionResults: txResults,
scriptsEnabled: scriptsEnabled,
queriesEnabled: queriesEnabled,
},
server: grpc.NewServer(
grpc.MaxRecvMsgSize(config.MaxMsgSize),
Expand Down Expand Up @@ -118,6 +120,7 @@ type handler struct {
exeResults storage.ExecutionResults
transactionResults storage.TransactionResults
scriptsEnabled bool
queriesEnabled bool
}

var _ execution.ExecutionAPIServer = &handler{}
Expand Down Expand Up @@ -158,6 +161,10 @@ func (h *handler) GetEventsForBlockIDs(
req *execution.GetEventsForBlockIDsRequest,
) (*execution.GetEventsForBlockIDsResponse, error) {

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

// validate request
blockIDs := req.GetBlockIds()
flowBlockIDs, err := convert.BlockIDs(blockIDs)
Expand Down Expand Up @@ -206,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

0 comments on commit dc78e01

Please sign in to comment.