Skip to content

Commit

Permalink
add mock servicer relay rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBigBoss committed May 5, 2023
1 parent d365853 commit f873e52
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ generate_rpc_openapi: go_oapi-codegen ## (Re)generates the RPC server and client
oapi-codegen --config ./rpc/client.gen.config.yml ./rpc/v1/openapi.yaml > ./rpc/client.gen.go
echo "OpenAPI client and server generated"

SWAGGER_PORT=8080
SWAGGER_PORT=127.0.0.1:8080
.PHONY: swagger-ui
swagger-ui: ## Starts a local Swagger UI instance for the RPC API
echo "Attempting to start Swagger UI at http://localhost:8080"
docker run --rm -p $(SWAGGER_PORT):8080 -e SWAGGER_JSON=/v1/openapi.yaml -v $(shell pwd)/rpc/v1:/v1 swaggerapi/swagger-ui
docker run --name pocket-swagger-ui --rm -p $(SWAGGER_PORT):8080 -e SWAGGER_JSON=/v1/openapi.yaml -v $(shell pwd)/rpc/v1:/v1 swaggerapi/swagger-ui

.PHONY: generate_cli_commands_docs
generate_cli_commands_docs: ## (Re)generates the CLI commands docs (this is meant to be called by CI)
Expand Down
27 changes: 27 additions & 0 deletions app/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,33 @@ func queryCommands() []*cobra.Command {
return rpcResponseCodeUnhealthy(statusCode, resp)
},
},
{
Use: "NodeRoles",
Short: "Get current the node roles",
Long: "Queries the node RPC to returns the type of utility actor(s) running on the node",
Aliases: []string{"noderoles"},
RunE: func(cmd *cobra.Command, args []string) error {
client, err := rpc.NewClientWithResponses(remoteCLIURL)
if err != nil {
return err
}
response, err := client.GetV1QueryNodeRoles(cmd.Context())
if err != nil {
return unableToConnectToRpc(err)
}
statusCode := response.StatusCode
body, err := io.ReadAll(response.Body)
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Error reading response body: %s\n", err.Error())
return err
}
if statusCode == http.StatusOK {
fmt.Println(string(body))
return nil
}
return rpcResponseCodeUnhealthy(statusCode, body)
},
},
}
return cmds
}
4 changes: 2 additions & 2 deletions build/localnet/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ for x in range(localnet_config["validators"]["count"]):
set=[
"global.postgresql.auth.postgresPassword=LocalNetPassword",
"image.repository=validator-image",
"privateKeySecretKeyRef.name=v1-localnet-validators-private-keys",
"privateKeySecretKeyRef.name=validators-private-keys",
"privateKeySecretKeyRef.key=%s" % formatted_number,
"genesis.preProvisionedGenesis.enabled=false",
"genesis.externalConfigMap.name=v1-localnet-genesis",
Expand All @@ -206,7 +206,7 @@ for x in range(localnet_config["servicers"]["count"]):
set=[
"global.postgresql.auth.postgresPassword=LocalNetPassword",
"image.repository=validator-image",
"privateKeySecretKeyRef.name=v1-localnet-validators-private-keys",
"privateKeySecretKeyRef.name=validators-private-keys",
"privateKeySecretKeyRef.key=%s" % formatted_number,
"genesis.preProvisionedGenesis.enabled=false",
"genesis.externalConfigMap.name=v1-localnet-genesis",
Expand Down
26 changes: 26 additions & 0 deletions rpc/handlers_servicer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package rpc

import (
"net/http"

"github.com/labstack/echo/v4"
)

func (s *rpcServer) PostV1ServicerRelay(ctx echo.Context) error {

// TODO: Move to the servicer module
servicerModuleName := "servicer"
found := false
for _, am := range s.GetBus().GetUtilityModule().GetActorModules() {
if am.GetModuleName() == servicerModuleName {
found = true
break
}
}

if !found {
return ctx.String(http.StatusInternalServerError, "node is unable to serve relays")
}

return nil
}

0 comments on commit f873e52

Please sign in to comment.