From be09094fee6a97722bbe325cd81ee3c35e5cfffd Mon Sep 17 00:00:00 2001 From: antho1404 Date: Mon, 18 May 2020 23:52:00 +0700 Subject: [PATCH 01/18] add filter for execution list --- x/execution/client/rest/query.go | 53 +++++++++++++++++++++++++- x/execution/internal/keeper/keeper.go | 6 ++- x/execution/internal/keeper/querier.go | 10 +++-- x/execution/internal/types/querier.go | 24 ++++++++++++ 4 files changed, 87 insertions(+), 6 deletions(-) diff --git a/x/execution/client/rest/query.go b/x/execution/client/rest/query.go index 38afb940e..72abdc2af 100644 --- a/x/execution/client/rest/query.go +++ b/x/execution/client/rest/query.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/rest" "github.com/gorilla/mux" "github.com/mesg-foundation/engine/execution" + "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/x/execution/internal/types" ) @@ -62,7 +63,57 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryList) - res, height, err := cliCtx.QueryWithData(route, nil) + filter := types.ListFilter{} + if param := r.FormValue("parentHash"); param != "" { + h, err := hash.Decode(param) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + filter.ParentHash = h + } + + if param := r.FormValue("eventHash"); param != "" { + h, err := hash.Decode(param) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + filter.EventHash = h + } + + if param := r.FormValue("instanceHash"); param != "" { + h, err := hash.Decode(param) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + filter.InstanceHash = h + } + + if param := r.FormValue("processHash"); param != "" { + h, err := hash.Decode(param) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + filter.ProcessHash = h + } + + if param := r.FormValue("status"); param != "" { + status, ok := execution.Status_value[param] + if !ok { + rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("%q is invalid", param)) + return + } + filter.Status = execution.Status(status) + } + + data, err := cliCtx.Codec.MarshalJSON(filter) + if err != nil { + return + } + res, height, err := cliCtx.QueryWithData(route, data) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return diff --git a/x/execution/internal/keeper/keeper.go b/x/execution/internal/keeper/keeper.go index 5a17787bb..c518fb229 100644 --- a/x/execution/internal/keeper/keeper.go +++ b/x/execution/internal/keeper/keeper.go @@ -348,7 +348,7 @@ func (k *Keeper) Get(ctx sdk.Context, hash hash.Hash) (*executionpb.Execution, e } // List returns all executions. -func (k *Keeper) List(ctx sdk.Context) ([]*executionpb.Execution, error) { +func (k *Keeper) List(ctx sdk.Context, filter types.ListFilter) ([]*executionpb.Execution, error) { var ( execs []*executionpb.Execution iter = ctx.KVStore(k.storeKey).Iterator(nil, nil) @@ -359,7 +359,9 @@ func (k *Keeper) List(ctx sdk.Context) ([]*executionpb.Execution, error) { if err := k.cdc.UnmarshalBinaryLengthPrefixed(value, &exec); err != nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrJSONUnmarshal, err.Error()) } - execs = append(execs, exec) + if filter.Match(exec) { + execs = append(execs, exec) + } iter.Next() } iter.Close() diff --git a/x/execution/internal/keeper/querier.go b/x/execution/internal/keeper/querier.go index 1f7b3ee7e..a8caf433d 100644 --- a/x/execution/internal/keeper/querier.go +++ b/x/execution/internal/keeper/querier.go @@ -15,7 +15,7 @@ func NewQuerier(k Keeper) sdk.Querier { case types.QueryGet: return get(ctx, k, path[1:]) case types.QueryList: - return list(ctx, k) + return list(ctx, k, req.Data) default: return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown execution query endpoint") } @@ -43,8 +43,12 @@ func get(ctx sdk.Context, k Keeper, path []string) ([]byte, error) { return res, nil } -func list(ctx sdk.Context, k Keeper) ([]byte, error) { - es, err := k.List(ctx) +func list(ctx sdk.Context, k Keeper, data []byte) ([]byte, error) { + var filter types.ListFilter + if err := types.ModuleCdc.UnmarshalJSON(data, &filter); err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) + } + es, err := k.List(ctx, filter) if err != nil { return nil, err } diff --git a/x/execution/internal/types/querier.go b/x/execution/internal/types/querier.go index 24f2f46fe..8b57dc9ea 100644 --- a/x/execution/internal/types/querier.go +++ b/x/execution/internal/types/querier.go @@ -1,6 +1,30 @@ package types +import ( + "github.com/mesg-foundation/engine/execution" + "github.com/mesg-foundation/engine/hash" +) + +// Querier names const ( QueryGet = "get" QueryList = "list" ) + +// ListFilter available for the List +type ListFilter struct { + ParentHash hash.Hash `json:"parentHash"` + EventHash hash.Hash `json:"eventHash"` + InstanceHash hash.Hash `json:"instanceHash"` + ProcessHash hash.Hash `json:"processHash"` + Status execution.Status `json:"status"` +} + +// Match returns true if an execution matches a specific filter +func (f ListFilter) Match(exec *execution.Execution) bool { + return (f.Status == execution.Status_Unknown || f.Status == exec.Status) && + (f.ProcessHash.IsZero() || f.ProcessHash.Equal(exec.ProcessHash)) && + (f.InstanceHash.IsZero() || f.InstanceHash.Equal(exec.InstanceHash)) && + (f.ParentHash.IsZero() || f.ParentHash.Equal(exec.ParentHash)) && + (f.EventHash.IsZero() || f.EventHash.Equal(exec.EventHash)) +} From 6d2416e5982970d298c5b21290f1952f92abefac Mon Sep 17 00:00:00 2001 From: antho1404 Date: Tue, 19 May 2020 14:06:32 +0700 Subject: [PATCH 02/18] add node key filter --- x/execution/client/rest/query.go | 4 ++++ x/execution/internal/types/querier.go | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/x/execution/client/rest/query.go b/x/execution/client/rest/query.go index 72abdc2af..bc6a842cb 100644 --- a/x/execution/client/rest/query.go +++ b/x/execution/client/rest/query.go @@ -109,6 +109,10 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { filter.Status = execution.Status(status) } + if param := r.FormValue("nodeKey"); param != "" { + filter.NodeKey = param + } + data, err := cliCtx.Codec.MarshalJSON(filter) if err != nil { return diff --git a/x/execution/internal/types/querier.go b/x/execution/internal/types/querier.go index 8b57dc9ea..106481f54 100644 --- a/x/execution/internal/types/querier.go +++ b/x/execution/internal/types/querier.go @@ -18,13 +18,28 @@ type ListFilter struct { InstanceHash hash.Hash `json:"instanceHash"` ProcessHash hash.Hash `json:"processHash"` Status execution.Status `json:"status"` + NodeKey string `json:"nodeKey"` } // Match returns true if an execution matches a specific filter func (f ListFilter) Match(exec *execution.Execution) bool { - return (f.Status == execution.Status_Unknown || f.Status == exec.Status) && - (f.ProcessHash.IsZero() || f.ProcessHash.Equal(exec.ProcessHash)) && - (f.InstanceHash.IsZero() || f.InstanceHash.Equal(exec.InstanceHash)) && - (f.ParentHash.IsZero() || f.ParentHash.Equal(exec.ParentHash)) && - (f.EventHash.IsZero() || f.EventHash.Equal(exec.EventHash)) + if f.Status != execution.Status_Unknown && f.Status != exec.Status { + return false + } + if !f.ProcessHash.IsZero() && !f.ProcessHash.Equal(exec.ProcessHash) { + return false + } + if !f.InstanceHash.IsZero() && !f.InstanceHash.Equal(exec.InstanceHash) { + return false + } + if !f.ParentHash.IsZero() && !f.ParentHash.Equal(exec.ParentHash) { + return false + } + if !f.EventHash.IsZero() && !f.EventHash.Equal(exec.EventHash) { + return false + } + if f.NodeKey != "" && f.NodeKey != exec.NodeKey { + return false + } + return true } From f0ccf2d016e5ca84cbc2a8922b461e77c59310f1 Mon Sep 17 00:00:00 2001 From: antho1404 Date: Tue, 19 May 2020 14:06:39 +0700 Subject: [PATCH 03/18] update e2e polling --- e2e/api_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/e2e/api_test.go b/e2e/api_test.go index 2be3cd6b4..51d39a07d 100644 --- a/e2e/api_test.go +++ b/e2e/api_test.go @@ -145,13 +145,11 @@ func pollExecutionOfProcess(processHash hash.Hash, status execution.Status, node timeout := time.After(pollingTimeout) for { var execs []*execution.Execution - if err := lcd.Get("execution/list", &execs); err != nil { + if err := lcd.Get(fmt.Sprintf("execution/list?processHash=%s&status=%s&nodeKey=%s", processHash, status, nodeKey), &execs); err != nil { return nil, err } - for _, exec := range execs { - if exec.ProcessHash.Equal(processHash) && exec.Status == status && exec.NodeKey == nodeKey { - return exec, nil - } + if len(execs) > 0 { + return execs[0], nil } select { case <-time.After(pollingInterval): From 78b65969df9645f0b7ca0ac2f5dd7021836d6e3d Mon Sep 17 00:00:00 2001 From: antho1404 Date: Tue, 19 May 2020 15:07:19 +0700 Subject: [PATCH 04/18] add pagination headers --- x/execution/client/rest/query.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/execution/client/rest/query.go b/x/execution/client/rest/query.go index bc6a842cb..87787dee7 100644 --- a/x/execution/client/rest/query.go +++ b/x/execution/client/rest/query.go @@ -132,6 +132,9 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { sort.Sort(sort.Reverse(execution.ByBlockHeight(execs))) start, end := client.Paginate(len(execs), page, limit, limit) + w.Header().Set("X-Page", fmt.Sprintf("%d", page)) + w.Header().Set("X-Limit", fmt.Sprintf("%d", limit)) + w.Header().Set("X-Total-Count", fmt.Sprintf("%d", len(execs))) if start < 0 || end < 0 { execs = []*execution.Execution{} } else { From 56e1a95b4e25a27ad8e815163a0d4b20d93b3279 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Tue, 19 May 2020 15:44:58 +0700 Subject: [PATCH 05/18] update dev script to use container instead of service --- Makefile | 4 +++- scripts/dev.sh | 31 +++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index ec2d25e0a..145217c1c 100644 --- a/Makefile +++ b/Makefile @@ -84,4 +84,6 @@ changelog: clean: - rm -rf bin - - docker image rm $(docker images | grep 'mesg') + - docker volume rm engine + - docker image rm $(shell docker images -q mesg/engine) + - docker image rm $(shell docker images -q mesg/tools) diff --git a/scripts/dev.sh b/scripts/dev.sh index 4f37143fa..cbb9e2527 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -17,13 +17,10 @@ if [[ "$2" == "monitoring" ]]; then fi function onexit { - docker service rm $ENGINE_NAME - docker wait $(docker ps -f label=com.docker.swarm.service.name=$ENGINE_NAME -q) 2> /dev/null + docker stop $ENGINE_NAME - if $monitor; then - docker service rm engine-grafana engine-prometheus - docker wait $(docker ps -f label=com.docker.swarm.service.name=engine-grafana -q) 2> /dev/null - docker wait $(docker ps -f label=com.docker.swarm.service.name=engine-prometheus -q) 2> /dev/null + if $monitoring; then + docker stop engine-grafana engine-prometheus fi docker network remove $NETWORK_NAME @@ -32,35 +29,41 @@ function onexit { trap onexit EXIT if [[ -z $(docker network list -f name="$NETWORK_NAME" -q) ]]; then - docker network create --driver overlay $NETWORK_NAME + docker network create $NETWORK_NAME fi if $monitoring; then echo "start monitoring" - docker service create \ + docker run \ + -d \ + --rm \ + --name=engine-grafana \ -p 3001:3000 \ --network $NETWORK_NAME \ - --name=engine-grafana \ --mount type=bind,source=$(pwd)/scripts/monitoring/datasource.yml,destination=/etc/grafana/provisioning/datasources/datasource.yml \ --mount type=bind,source=$(pwd)/scripts/monitoring/dashboard.yml,destination=/etc/grafana/provisioning/dashboards/dashboard.yml \ --mount type=bind,source=$(pwd)/scripts/monitoring/dashboards,destination=/var/lib/grafana/dashboards \ grafana/grafana - docker service create \ + docker run \ + -d \ + --rm \ + --name=engine-prometheus \ -p 9090:9090 \ --network $NETWORK_NAME \ - --name=engine-prometheus \ --mount type=bind,source=$(pwd)/scripts/monitoring/prometheus.yml,destination=/etc/prometheus/prometheus.yml \ prom/prometheus fi -docker service create \ +docker run \ + -d \ + --rm \ --name $ENGINE_NAME \ -p 1317:1317 \ -p 50052:50052 \ -p 26657:26657 \ --network $NETWORK_NAME \ - --label com.docker.stack.namespace=$ENGINE_NAME \ + --volume engine:/root/ \ mesg/engine:$1-dev -docker service logs --tail 1000 --follow --raw $ENGINE_NAME +docker logs --tail 1000 --follow $ENGINE_NAME From ecd6c1a64373e3c45f25ac39e4436dd07c3dfc28 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Tue, 19 May 2020 16:35:11 +0700 Subject: [PATCH 06/18] =?UTF-8?q?add=20rest=20query=20parameters=20to=20mo?= =?UTF-8?q?dule=20execution=20remove=20params=20from=20modules=20that=20do?= =?UTF-8?q?esn=E2=80=99t=20use=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- x/execution/client/rest/query.go | 25 ++++++++++++++++++ x/ownership/alias.go | 10 +++----- x/ownership/client/rest/query.go | 25 ------------------ x/ownership/internal/types/params.go | 38 ---------------------------- x/process/alias.go | 10 +++----- x/process/client/rest/query.go | 25 ------------------ x/process/internal/types/params.go | 38 ---------------------------- x/runner/alias.go | 10 +++----- x/runner/client/rest/query.go | 25 ------------------ x/runner/internal/types/params.go | 38 ---------------------------- x/service/alias.go | 10 +++----- x/service/internal/types/params.go | 38 ---------------------------- 12 files changed, 41 insertions(+), 251 deletions(-) delete mode 100644 x/ownership/internal/types/params.go delete mode 100644 x/process/internal/types/params.go delete mode 100644 x/runner/internal/types/params.go delete mode 100644 x/service/internal/types/params.go diff --git a/x/execution/client/rest/query.go b/x/execution/client/rest/query.go index 38afb940e..b7bf65c31 100644 --- a/x/execution/client/rest/query.go +++ b/x/execution/client/rest/query.go @@ -23,6 +23,11 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { "/execution/list", queryListHandlerFn(cliCtx), ).Methods(http.MethodGet) + + r.HandleFunc( + "/execution/parameters", + queryParamsHandlerFn(cliCtx), + ).Methods("GET") } func queryGetHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { @@ -87,3 +92,23 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { rest.PostProcessResponse(w, cliCtx, execs) } } + +func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) + if !ok { + return + } + + route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute) + + res, height, err := cliCtx.QueryWithData(route, nil) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + + cliCtx = cliCtx.WithHeight(height) + rest.PostProcessResponse(w, cliCtx, res) + } +} diff --git a/x/ownership/alias.go b/x/ownership/alias.go index 3db12dd79..0adb52378 100644 --- a/x/ownership/alias.go +++ b/x/ownership/alias.go @@ -7,11 +7,10 @@ import ( // const aliases const ( - ModuleName = types.ModuleName - RouterKey = types.RouterKey - StoreKey = types.StoreKey - DefaultParamspace = types.DefaultParamspace - QuerierRoute = types.QuerierRoute + ModuleName = types.ModuleName + RouterKey = types.RouterKey + StoreKey = types.StoreKey + QuerierRoute = types.QuerierRoute ) // functions and variable aliases @@ -39,7 +38,6 @@ var ( type ( Keeper = keeper.Keeper GenesisState = types.GenesisState - Params = types.Params MsgWithdraw = types.MsgWithdraw ) diff --git a/x/ownership/client/rest/query.go b/x/ownership/client/rest/query.go index 1a9663f5f..f0580bd7d 100644 --- a/x/ownership/client/rest/query.go +++ b/x/ownership/client/rest/query.go @@ -15,11 +15,6 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { "/ownership/list", queryListHandlerFn(cliCtx), ).Methods(http.MethodGet) - - r.HandleFunc( - "/ownership/parameters", - queryParamsHandlerFn(cliCtx), - ).Methods(http.MethodGet) } func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { @@ -40,23 +35,3 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { rest.PostProcessResponse(w, cliCtx, res) } } - -func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute) - - res, height, err := cliCtx.QueryWithData(route, nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} diff --git a/x/ownership/internal/types/params.go b/x/ownership/internal/types/params.go deleted file mode 100644 index 4940992b5..000000000 --- a/x/ownership/internal/types/params.go +++ /dev/null @@ -1,38 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/x/params" -) - -// Default parameter namespace -const ( - DefaultParamspace = ModuleName -) - -// ParamKeyTable for instance module -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable().RegisterParamSet(&Params{}) -} - -// Params - used for initializing default parameter for instance at genesis -type Params struct{} - -// NewParams creates a new Params object -func NewParams() Params { - return Params{} -} - -// String implements the stringer interface for Params -func (p Params) String() string { - return "" -} - -// ParamSetPairs - Implements params.ParamSet -func (p *Params) ParamSetPairs() params.ParamSetPairs { - return params.ParamSetPairs{} -} - -// DefaultParams defines the parameters for this module -func DefaultParams() Params { - return NewParams() -} diff --git a/x/process/alias.go b/x/process/alias.go index a6fb21e75..b2d232844 100644 --- a/x/process/alias.go +++ b/x/process/alias.go @@ -7,11 +7,10 @@ import ( // const aliases const ( - ModuleName = types.ModuleName - RouterKey = types.RouterKey - StoreKey = types.StoreKey - DefaultParamspace = types.DefaultParamspace - QuerierRoute = types.QuerierRoute + ModuleName = types.ModuleName + RouterKey = types.RouterKey + StoreKey = types.StoreKey + QuerierRoute = types.QuerierRoute ) // functions and variable aliases @@ -40,7 +39,6 @@ var ( type ( Keeper = keeper.Keeper GenesisState = types.GenesisState - Params = types.Params MsgCreate = types.MsgCreate MsgDelete = types.MsgDelete diff --git a/x/process/client/rest/query.go b/x/process/client/rest/query.go index 2a9f1f648..3f615614f 100644 --- a/x/process/client/rest/query.go +++ b/x/process/client/rest/query.go @@ -28,11 +28,6 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { queryHashHandlerFn(cliCtx), ).Methods(http.MethodPost) - r.HandleFunc( - "/process/parameters", - queryParamsHandlerFn(cliCtx), - ).Methods(http.MethodGet) - r.HandleFunc( "/process/exist/{hash}", queryExistHandlerFn(cliCtx), @@ -81,26 +76,6 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } } -func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute) - - res, height, err := cliCtx.QueryWithData(route, nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - // HashRequest is the request of the hash endpoint. type HashRequest struct { Name string `json:"name,omitempty"` diff --git a/x/process/internal/types/params.go b/x/process/internal/types/params.go deleted file mode 100644 index 4940992b5..000000000 --- a/x/process/internal/types/params.go +++ /dev/null @@ -1,38 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/x/params" -) - -// Default parameter namespace -const ( - DefaultParamspace = ModuleName -) - -// ParamKeyTable for instance module -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable().RegisterParamSet(&Params{}) -} - -// Params - used for initializing default parameter for instance at genesis -type Params struct{} - -// NewParams creates a new Params object -func NewParams() Params { - return Params{} -} - -// String implements the stringer interface for Params -func (p Params) String() string { - return "" -} - -// ParamSetPairs - Implements params.ParamSet -func (p *Params) ParamSetPairs() params.ParamSetPairs { - return params.ParamSetPairs{} -} - -// DefaultParams defines the parameters for this module -func DefaultParams() Params { - return NewParams() -} diff --git a/x/runner/alias.go b/x/runner/alias.go index c73abefed..45e36264c 100644 --- a/x/runner/alias.go +++ b/x/runner/alias.go @@ -7,11 +7,10 @@ import ( // const aliases const ( - ModuleName = types.ModuleName - RouterKey = types.RouterKey - StoreKey = types.StoreKey - DefaultParamspace = types.DefaultParamspace - QuerierRoute = types.QuerierRoute + ModuleName = types.ModuleName + RouterKey = types.RouterKey + StoreKey = types.StoreKey + QuerierRoute = types.QuerierRoute ) // functions and variable aliases @@ -41,7 +40,6 @@ var ( type ( Keeper = keeper.Keeper GenesisState = types.GenesisState - Params = types.Params MsgCreate = types.MsgCreate MsgDelete = types.MsgDelete diff --git a/x/runner/client/rest/query.go b/x/runner/client/rest/query.go index 3f9c6e094..b32d70931 100644 --- a/x/runner/client/rest/query.go +++ b/x/runner/client/rest/query.go @@ -30,11 +30,6 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { queryHashHandlerFn(cliCtx), ).Methods(http.MethodPost) - r.HandleFunc( - "/runner/parameters", - queryParamsHandlerFn(cliCtx), - ).Methods(http.MethodGet) - r.HandleFunc( "/runner/exist/{hash}", queryExistHandlerFn(cliCtx), @@ -83,26 +78,6 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } } -func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute) - - res, height, err := cliCtx.QueryWithData(route, nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - // HashRequest is the request of the hash endpoint. type HashRequest struct { ServiceHash hash.Hash `json:"serviceHash"` diff --git a/x/runner/internal/types/params.go b/x/runner/internal/types/params.go deleted file mode 100644 index 4940992b5..000000000 --- a/x/runner/internal/types/params.go +++ /dev/null @@ -1,38 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/x/params" -) - -// Default parameter namespace -const ( - DefaultParamspace = ModuleName -) - -// ParamKeyTable for instance module -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable().RegisterParamSet(&Params{}) -} - -// Params - used for initializing default parameter for instance at genesis -type Params struct{} - -// NewParams creates a new Params object -func NewParams() Params { - return Params{} -} - -// String implements the stringer interface for Params -func (p Params) String() string { - return "" -} - -// ParamSetPairs - Implements params.ParamSet -func (p *Params) ParamSetPairs() params.ParamSetPairs { - return params.ParamSetPairs{} -} - -// DefaultParams defines the parameters for this module -func DefaultParams() Params { - return NewParams() -} diff --git a/x/service/alias.go b/x/service/alias.go index 7e51e6780..56b88edf7 100644 --- a/x/service/alias.go +++ b/x/service/alias.go @@ -7,11 +7,10 @@ import ( // const aliases const ( - ModuleName = types.ModuleName - RouterKey = types.RouterKey - StoreKey = types.StoreKey - DefaultParamspace = types.DefaultParamspace - QuerierRoute = types.QuerierRoute + ModuleName = types.ModuleName + RouterKey = types.RouterKey + StoreKey = types.StoreKey + QuerierRoute = types.QuerierRoute ) // functions and variable aliases @@ -39,7 +38,6 @@ var ( type ( Keeper = keeper.Keeper GenesisState = types.GenesisState - Params = types.Params MsgCreate = types.MsgCreate ) diff --git a/x/service/internal/types/params.go b/x/service/internal/types/params.go deleted file mode 100644 index 4940992b5..000000000 --- a/x/service/internal/types/params.go +++ /dev/null @@ -1,38 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/x/params" -) - -// Default parameter namespace -const ( - DefaultParamspace = ModuleName -) - -// ParamKeyTable for instance module -func ParamKeyTable() params.KeyTable { - return params.NewKeyTable().RegisterParamSet(&Params{}) -} - -// Params - used for initializing default parameter for instance at genesis -type Params struct{} - -// NewParams creates a new Params object -func NewParams() Params { - return Params{} -} - -// String implements the stringer interface for Params -func (p Params) String() string { - return "" -} - -// ParamSetPairs - Implements params.ParamSet -func (p *Params) ParamSetPairs() params.ParamSetPairs { - return params.ParamSetPairs{} -} - -// DefaultParams defines the parameters for this module -func DefaultParams() Params { - return NewParams() -} From a9e3e601aee0d4731555e429c6a11204e6327757 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Tue, 19 May 2020 17:16:23 +0700 Subject: [PATCH 07/18] improve cli commands description --- x/execution/client/cli/query.go | 9 ++++++--- x/execution/client/cli/tx.go | 4 ++-- x/instance/client/cli/query.go | 15 +++++++++------ x/ownership/client/cli/query.go | 5 +++-- x/ownership/client/cli/tx.go | 2 +- x/process/client/cli/query.go | 14 +++++++++----- x/process/client/cli/tx.go | 4 ++-- x/runner/client/cli/query.go | 14 +++++++++----- x/runner/client/cli/tx.go | 4 ++-- x/service/client/cli/query.go | 12 ++++++++---- x/service/client/cli/tx.go | 2 +- 11 files changed, 52 insertions(+), 33 deletions(-) diff --git a/x/execution/client/cli/query.go b/x/execution/client/cli/query.go index c264117d7..156b53095 100644 --- a/x/execution/client/cli/query.go +++ b/x/execution/client/cli/query.go @@ -17,7 +17,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { // Group execution queries under a subcommand executionQueryCmd := &cobra.Command{ Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Short: fmt.Sprintf("Query commands for the %s module", types.ModuleName), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -33,10 +33,11 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { return executionQueryCmd } +// GetCmdGet implements the get query command. func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "get [hash]", - Short: "get", + Short: "Fetch an execution by its hash", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -53,10 +54,12 @@ func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { } } +// GetCmdList implements the list query command. func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "list", - Short: "list", + Short: "Query all the executions", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryList), nil) diff --git a/x/execution/client/cli/tx.go b/x/execution/client/cli/tx.go index ec4fbe4c4..e873cabcc 100644 --- a/x/execution/client/cli/tx.go +++ b/x/execution/client/cli/tx.go @@ -37,7 +37,7 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command { func GetCmdCreate(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "create [definition]", - Short: "Creates a new execution", + Short: "Create a new execution", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) @@ -67,7 +67,7 @@ func GetCmdCreate(cdc *codec.Codec) *cobra.Command { func GetCmdUpdate(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "update [definition]", - Short: "Updates an execution", + Short: "Update an execution", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) diff --git a/x/instance/client/cli/query.go b/x/instance/client/cli/query.go index 4fc9fb3f6..3aedb4bc0 100644 --- a/x/instance/client/cli/query.go +++ b/x/instance/client/cli/query.go @@ -17,7 +17,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { // Group instance queries under a subcommand instanceQueryCmd := &cobra.Command{ Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Short: fmt.Sprintf("Query commands for the %s module", types.ModuleName), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -26,17 +26,18 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { instanceQueryCmd.AddCommand( flags.GetCommands( GetCmdGet(queryRoute, cdc), - GetCmdLists(queryRoute, cdc), + GetCmdList(queryRoute, cdc), )..., ) return instanceQueryCmd } +// GetCmdGet implements the get query command. func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ - Use: "get", - Short: "get", + Use: "get [hash]", + Short: "Fetch an instance by its hash", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -53,10 +54,12 @@ func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { } } -func GetCmdLists(queryRoute string, cdc *codec.Codec) *cobra.Command { +// GetCmdList implements the list query command. +func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "list", - Short: "list", + Short: "Query all the instances", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryList), nil) diff --git a/x/ownership/client/cli/query.go b/x/ownership/client/cli/query.go index 2818b1569..441191603 100644 --- a/x/ownership/client/cli/query.go +++ b/x/ownership/client/cli/query.go @@ -17,7 +17,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { // Group ownership queries under a subcommand ownershipQueryCmd := &cobra.Command{ Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Short: fmt.Sprintf("Query commands for the %s module", types.ModuleName), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -36,7 +36,8 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "list", - Short: "list", + Short: "Query all the ownership", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryList), nil) diff --git a/x/ownership/client/cli/tx.go b/x/ownership/client/cli/tx.go index 0ba3308cb..4676ad353 100644 --- a/x/ownership/client/cli/tx.go +++ b/x/ownership/client/cli/tx.go @@ -37,7 +37,7 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command { func GetCmdWithdraw(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "withdraw-coins [resourceHash] [amount]", - Short: "withdraw coins from a resource", + Short: "Withdraw coins from a resource", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) diff --git a/x/process/client/cli/query.go b/x/process/client/cli/query.go index 8a658b46e..ab7293a9d 100644 --- a/x/process/client/cli/query.go +++ b/x/process/client/cli/query.go @@ -17,7 +17,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { // Group process queries under a subcommand processQueryCmd := &cobra.Command{ Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Short: fmt.Sprintf("Query commands for the %s module", types.ModuleName), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -34,10 +34,11 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { return processQueryCmd } +// GetCmdGet implements the get query command. func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ - Use: "get", - Short: "get", + Use: "get [hash]", + Short: "Fetch a process by its hash", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -54,10 +55,12 @@ func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { } } +// GetCmdList implements the list query command. func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "list", - Short: "list", + Short: "Query all the processes", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryList), nil) @@ -73,10 +76,11 @@ func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { } } +// GetCmdExist implements the exist query command. func GetCmdExist(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "exist [hash]", - Short: "exist", + Short: "Check if the process exist", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) diff --git a/x/process/client/cli/tx.go b/x/process/client/cli/tx.go index e439a982d..f1428f50c 100644 --- a/x/process/client/cli/tx.go +++ b/x/process/client/cli/tx.go @@ -39,7 +39,7 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command { func GetCmdCreate(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "create [definition]", - Short: "Creates a new process", + Short: "Create a new process from its definition", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) @@ -69,7 +69,7 @@ func GetCmdCreate(cdc *codec.Codec) *cobra.Command { func GetCmdDelete(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "delete [processHash]", - Short: "Deletes a process", + Short: "Delete a process", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) diff --git a/x/runner/client/cli/query.go b/x/runner/client/cli/query.go index 4f96d95a8..3f2fa480e 100644 --- a/x/runner/client/cli/query.go +++ b/x/runner/client/cli/query.go @@ -17,7 +17,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { // Group runner queries under a subcommand runnerQueryCmd := &cobra.Command{ Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Short: fmt.Sprintf("Query commands for the %s module", types.ModuleName), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -34,10 +34,11 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { return runnerQueryCmd } +// GetCmdGet implements the get query command. func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ - Use: "get", - Short: "get", + Use: "get [hash]", + Short: "Fetch a runner by its hash", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -54,10 +55,12 @@ func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { } } +// GetCmdList implements the list query command. func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "list", - Short: "list", + Short: "Query all the runners", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryList), nil) @@ -73,10 +76,11 @@ func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { } } +// GetCmdExist implements the exist query command. func GetCmdExist(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "exist [hash]", - Short: "exist", + Short: "Check if the runner exist", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) diff --git a/x/runner/client/cli/tx.go b/x/runner/client/cli/tx.go index 0bc1a451c..0d26735e3 100644 --- a/x/runner/client/cli/tx.go +++ b/x/runner/client/cli/tx.go @@ -39,7 +39,7 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command { func GetCmdCreate(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "create [serviceHash] [envHash]", - Short: "Creates a new runner", + Short: "Create a new runner", Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) @@ -77,7 +77,7 @@ func GetCmdCreate(cdc *codec.Codec) *cobra.Command { func GetCmdDelete(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "delete [runnerHash]", - Short: "Deletes a runner", + Short: "Delete a runner", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) diff --git a/x/service/client/cli/query.go b/x/service/client/cli/query.go index 1fb5b95d2..665d8373f 100644 --- a/x/service/client/cli/query.go +++ b/x/service/client/cli/query.go @@ -17,7 +17,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { // Group service queries under a subcommand serviceQueryCmd := &cobra.Command{ Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Short: fmt.Sprintf("Query commands for the %s module", types.ModuleName), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -34,10 +34,11 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { return serviceQueryCmd } +// GetCmdGet implements the get query command. func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "get [hash]", - Short: "get", + Short: "Fetch a service by its hash", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -54,10 +55,12 @@ func GetCmdGet(queryRoute string, cdc *codec.Codec) *cobra.Command { } } +// GetCmdList implements the list query command. func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "list", - Short: "list", + Short: "Query all the services", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryList), nil) @@ -73,10 +76,11 @@ func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { } } +// GetCmdExist implements the exist query command. func GetCmdExist(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "exist [hash]", - Short: "exist", + Short: "Check if the service exist", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) diff --git a/x/service/client/cli/tx.go b/x/service/client/cli/tx.go index 76f05f773..121b3a34b 100644 --- a/x/service/client/cli/tx.go +++ b/x/service/client/cli/tx.go @@ -37,7 +37,7 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command { func GetCmdCreate(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "create [definition]", - Short: "create a service from its definition", + Short: "Create a service from its definition", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) From 15dbfc9187e3e6c79fe2addb8f6c274223506003 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Tue, 19 May 2020 17:17:07 +0700 Subject: [PATCH 08/18] add missing param query to module execution --- x/execution/alias.go | 5 +++-- x/execution/client/cli/query.go | 23 +++++++++++++++++++++++ x/execution/client/rest/query.go | 2 +- x/execution/internal/keeper/querier.go | 10 ++++++++++ x/execution/internal/types/querier.go | 5 +++-- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/x/execution/alias.go b/x/execution/alias.go index 304d72f01..2ba37e9a3 100644 --- a/x/execution/alias.go +++ b/x/execution/alias.go @@ -25,8 +25,9 @@ var ( ModuleCdc = types.ModuleCdc - QueryGet = types.QueryGet - QueryList = types.QueryList + QueryGet = types.QueryGet + QueryList = types.QueryList + QueryParameters = types.QueryParameters M = keeper.M diff --git a/x/execution/client/cli/query.go b/x/execution/client/cli/query.go index 156b53095..360567b4b 100644 --- a/x/execution/client/cli/query.go +++ b/x/execution/client/cli/query.go @@ -27,6 +27,7 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { flags.GetCommands( GetCmdGet(queryRoute, cdc), GetCmdList(queryRoute, cdc), + GetCmdQueryParams(queryRoute, cdc), )..., ) @@ -74,3 +75,25 @@ func GetCmdList(queryRoute string, cdc *codec.Codec) *cobra.Command { }, } } + +// GetCmdQueryParams implements the params query command. +func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { + return &cobra.Command{ + Use: "params", + Short: "Query the parameters", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + cliCtx := context.NewCLIContext().WithCodec(cdc) + + route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryParameters) + bz, _, err := cliCtx.QueryWithData(route, nil) + if err != nil { + return err + } + + var params types.Params + cdc.MustUnmarshalJSON(bz, ¶ms) + return cliCtx.PrintOutput(params) + }, + } +} diff --git a/x/execution/client/rest/query.go b/x/execution/client/rest/query.go index b7bf65c31..91962dd97 100644 --- a/x/execution/client/rest/query.go +++ b/x/execution/client/rest/query.go @@ -100,7 +100,7 @@ func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute) + route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters) res, height, err := cliCtx.QueryWithData(route, nil) if err != nil { diff --git a/x/execution/internal/keeper/querier.go b/x/execution/internal/keeper/querier.go index 1f7b3ee7e..ea26276ef 100644 --- a/x/execution/internal/keeper/querier.go +++ b/x/execution/internal/keeper/querier.go @@ -16,6 +16,8 @@ func NewQuerier(k Keeper) sdk.Querier { return get(ctx, k, path[1:]) case types.QueryList: return list(ctx, k) + case types.QueryParameters: + return queryParameters(ctx, k) default: return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown execution query endpoint") } @@ -55,3 +57,11 @@ func list(ctx sdk.Context, k Keeper) ([]byte, error) { } return res, nil } + +func queryParameters(ctx sdk.Context, k Keeper) ([]byte, error) { + res, err := types.ModuleCdc.MarshalJSON(k.GetParams(ctx)) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + } + return res, nil +} diff --git a/x/execution/internal/types/querier.go b/x/execution/internal/types/querier.go index 24f2f46fe..e37e1c2f2 100644 --- a/x/execution/internal/types/querier.go +++ b/x/execution/internal/types/querier.go @@ -1,6 +1,7 @@ package types const ( - QueryGet = "get" - QueryList = "list" + QueryGet = "get" + QueryList = "list" + QueryParameters = "parameters" ) From a965e43417402306288831903e16f4d4cf567393 Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 20 May 2020 11:23:05 +0700 Subject: [PATCH 09/18] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolas Mahé --- x/execution/client/rest/query.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/x/execution/client/rest/query.go b/x/execution/client/rest/query.go index bc6a842cb..d05a14768 100644 --- a/x/execution/client/rest/query.go +++ b/x/execution/client/rest/query.go @@ -67,7 +67,7 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { if param := r.FormValue("parentHash"); param != "" { h, err := hash.Decode(param) if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + rest.WriteErrorResponse(w, http.StatusBadRequest, "error on parameter parentHash: "+err.Error()) return } filter.ParentHash = h @@ -76,7 +76,7 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { if param := r.FormValue("eventHash"); param != "" { h, err := hash.Decode(param) if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + rest.WriteErrorResponse(w, http.StatusBadRequest, "error on parameter eventHash: "+err.Error()) return } filter.EventHash = h @@ -85,7 +85,7 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { if param := r.FormValue("instanceHash"); param != "" { h, err := hash.Decode(param) if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + rest.WriteErrorResponse(w, http.StatusBadRequest, "error on parameter instanceHash: "+err.Error()) return } filter.InstanceHash = h @@ -94,7 +94,7 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { if param := r.FormValue("processHash"); param != "" { h, err := hash.Decode(param) if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + rest.WriteErrorResponse(w, http.StatusBadRequest, "error on parameter processHash: "+err.Error()) return } filter.ProcessHash = h @@ -103,7 +103,7 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { if param := r.FormValue("status"); param != "" { status, ok := execution.Status_value[param] if !ok { - rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("%q is invalid", param)) + rest.WriteErrorResponse(w, http.StatusBadRequest, "error on parameter status: value is invalid") return } filter.Status = execution.Status(status) @@ -115,6 +115,7 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { data, err := cliCtx.Codec.MarshalJSON(filter) if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } res, height, err := cliCtx.QueryWithData(route, data) From 90e9c18c8477a0c83e8e0addfd2eca49c848706b Mon Sep 17 00:00:00 2001 From: antho1404 Date: Wed, 20 May 2020 12:59:48 +0700 Subject: [PATCH 10/18] convert using strconv --- x/execution/client/rest/query.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x/execution/client/rest/query.go b/x/execution/client/rest/query.go index 4446cba3f..262566d15 100644 --- a/x/execution/client/rest/query.go +++ b/x/execution/client/rest/query.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "sort" + "strconv" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" @@ -133,9 +134,9 @@ func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { sort.Sort(sort.Reverse(execution.ByBlockHeight(execs))) start, end := client.Paginate(len(execs), page, limit, limit) - w.Header().Set("X-Page", fmt.Sprintf("%d", page)) - w.Header().Set("X-Limit", fmt.Sprintf("%d", limit)) - w.Header().Set("X-Total-Count", fmt.Sprintf("%d", len(execs))) + w.Header().Set("X-Page", strconv.Itoa(page)) + w.Header().Set("X-Limit", strconv.Itoa(limit)) + w.Header().Set("X-Total-Count", strconv.Itoa(len(execs))) if start < 0 || end < 0 { execs = []*execution.Execution{} } else { From 1fabd3d7c9c56f7b91c39fb80118b6fb92148bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mah=C3=A9?= Date: Wed, 20 May 2020 17:17:38 +0700 Subject: [PATCH 11/18] Revert "Fix 2 issues with instance" --- app/app.go | 4 ++-- instance/instance.pb.go | 15 +++++++-------- protobuf/types/instance.proto | 2 +- x/instance/internal/keeper/keeper.go | 17 ++++++----------- x/instance/internal/types/expected_keepers.go | 7 ------- 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/app/app.go b/app/app.go index a828290b3..21622951f 100644 --- a/app/app.go +++ b/app/app.go @@ -241,9 +241,9 @@ func NewInitApp( // Engine's module keepers app.ownershipKeeper = ownership.NewKeeper(app.cdc, keys[ownership.StoreKey], app.bankKeeper) - app.serviceKeeper = service.NewKeeper(app.cdc, keys[service.StoreKey], app.ownershipKeeper) - app.instanceKeeper = instance.NewKeeper(app.cdc, keys[instance.StoreKey], app.serviceKeeper) + app.instanceKeeper = instance.NewKeeper(app.cdc, keys[instance.StoreKey]) app.processKeeper = process.NewKeeper(app.cdc, keys[process.StoreKey], app.instanceKeeper, app.ownershipKeeper, app.bankKeeper) + app.serviceKeeper = service.NewKeeper(app.cdc, keys[service.StoreKey], app.ownershipKeeper) app.runnerKeeper = runner.NewKeeper(app.cdc, keys[runner.StoreKey], app.instanceKeeper, app.ownershipKeeper) app.executionKeeper = execution.NewKeeper( app.cdc, diff --git a/instance/instance.pb.go b/instance/instance.pb.go index 4ac3926c3..d391fb778 100644 --- a/instance/instance.pb.go +++ b/instance/instance.pb.go @@ -27,7 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Instance struct { Hash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,1,opt,name=hash,proto3,casttype=github.com/mesg-foundation/engine/hash.Hash" json:"hash,omitempty" hash:"-" validate:"required,hash"` ServiceHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,2,opt,name=serviceHash,proto3,casttype=github.com/mesg-foundation/engine/hash.Hash" json:"serviceHash,omitempty" hash:"name:2" validate:"required,hash"` - EnvHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,3,opt,name=envHash,proto3,casttype=github.com/mesg-foundation/engine/hash.Hash" json:"envHash,omitempty" hash:"name:3" validate:"omitempty,hash"` + EnvHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,3,opt,name=envHash,proto3,casttype=github.com/mesg-foundation/engine/hash.Hash" json:"envHash,omitempty" hash:"name:3" validate:"required,hash"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -64,11 +64,11 @@ func init() { func init() { proto.RegisterFile("instance.proto", fileDescriptor_fd22322185b2070b) } var fileDescriptor_fd22322185b2070b = []byte{ - // 270 bytes of a gzipped FileDescriptorProto + // 252 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcb, 0xcc, 0x2b, 0x2e, 0x49, 0xcc, 0x4b, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xca, 0x4d, 0x2d, 0x4e, 0xd7, 0x2b, 0xa9, 0x2c, 0x48, 0x2d, 0x96, 0x52, 0x4a, 0xcf, 0x4f, 0xcf, 0xd7, 0x07, 0x8b, 0x27, - 0x95, 0xa6, 0xe9, 0x83, 0x78, 0x60, 0x0e, 0x98, 0x05, 0x51, 0xaf, 0xf4, 0x9c, 0x89, 0x8b, 0xc3, + 0x95, 0xa6, 0xe9, 0x83, 0x78, 0x60, 0x0e, 0x98, 0x05, 0x51, 0xaf, 0xf4, 0x8c, 0x89, 0x8b, 0xc3, 0x13, 0x6a, 0x84, 0x50, 0x06, 0x17, 0x4b, 0x46, 0x62, 0x71, 0x86, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8f, 0x53, 0xc8, 0xa7, 0x7b, 0xf2, 0x8a, 0x20, 0xbe, 0x95, 0x92, 0xae, 0x92, 0x42, 0x59, 0x62, 0x4e, 0x66, 0x4a, 0x62, 0x49, 0xaa, 0x95, 0x52, 0x51, 0x6a, 0x61, 0x69, 0x66, 0x51, 0x6a, 0x8a, @@ -77,11 +77,10 @@ var fileDescriptor_fd22322185b2070b = []byte{ 0xfa, 0xa9, 0x79, 0xe9, 0x99, 0x79, 0xa9, 0xfa, 0x20, 0xa5, 0x7a, 0x1e, 0x89, 0xc5, 0x19, 0x41, 0x60, 0x1b, 0x84, 0xaa, 0xb9, 0xb8, 0x8b, 0x53, 0x8b, 0xca, 0x32, 0x93, 0x53, 0x41, 0x82, 0x12, 0x4c, 0x60, 0x0b, 0x23, 0x3f, 0xdd, 0x93, 0x57, 0x83, 0x58, 0x98, 0x97, 0x98, 0x9b, 0x6a, 0x65, - 0x44, 0x3d, 0x5b, 0x91, 0x6d, 0x13, 0x2a, 0xe1, 0x62, 0x4f, 0xcd, 0x2b, 0x03, 0x5b, 0xcc, 0x0c, - 0xb6, 0x38, 0xea, 0xd3, 0x3d, 0x79, 0x75, 0x24, 0x8b, 0x8d, 0x91, 0x2d, 0xce, 0xcf, 0xcd, 0x2c, - 0x49, 0xcd, 0x2d, 0x28, 0xa9, 0x24, 0xcf, 0x66, 0x98, 0x55, 0x4e, 0x26, 0x27, 0x1e, 0xca, 0x31, - 0xac, 0x78, 0x24, 0xc7, 0x18, 0xa5, 0x45, 0x58, 0x3f, 0x2c, 0x56, 0x93, 0xd8, 0xc0, 0xd1, 0x64, - 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x8d, 0x84, 0x12, 0x40, 0xe8, 0x01, 0x00, 0x00, + 0x44, 0x3d, 0x5b, 0x91, 0x6d, 0x13, 0x2a, 0xe6, 0x62, 0x4f, 0xcd, 0x2b, 0x03, 0x5b, 0xcc, 0x8c, + 0xd5, 0x62, 0x63, 0xea, 0x59, 0x0c, 0xb3, 0xc9, 0xc9, 0xe4, 0xc4, 0x43, 0x39, 0x86, 0x15, 0x8f, + 0xe4, 0x18, 0xa3, 0xb4, 0x08, 0xeb, 0x87, 0x45, 0x6a, 0x12, 0x1b, 0x38, 0x96, 0x8c, 0x01, 0x01, + 0x00, 0x00, 0xff, 0xff, 0xc8, 0xf9, 0x30, 0x37, 0xe7, 0x01, 0x00, 0x00, } func (this *Instance) Equal(that interface{}) bool { diff --git a/protobuf/types/instance.proto b/protobuf/types/instance.proto index baf6734d0..34fc5b709 100644 --- a/protobuf/types/instance.proto +++ b/protobuf/types/instance.proto @@ -21,7 +21,7 @@ message Instance { ]; bytes envHash = 3 [ - (gogoproto.moretags) = 'hash:"name:3" validate:"omitempty,hash"', + (gogoproto.moretags) = 'hash:"name:3" validate:"required,hash"', (gogoproto.casttype) = "github.com/mesg-foundation/engine/hash.Hash" ]; } diff --git a/x/instance/internal/keeper/keeper.go b/x/instance/internal/keeper/keeper.go index 9a59e6851..0a7d10224 100644 --- a/x/instance/internal/keeper/keeper.go +++ b/x/instance/internal/keeper/keeper.go @@ -14,17 +14,15 @@ import ( // Keeper of the instance store type Keeper struct { - storeKey sdk.StoreKey - cdc *codec.Codec - serviceKeeper types.ServiceKeeper + storeKey sdk.StoreKey + cdc *codec.Codec } // NewKeeper creates a instance keeper -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, serviceKeeper types.ServiceKeeper) Keeper { +func NewKeeper(cdc *codec.Codec, key sdk.StoreKey) Keeper { keeper := Keeper{ - storeKey: key, - cdc: cdc, - serviceKeeper: serviceKeeper, + storeKey: key, + cdc: cdc, } return keeper } @@ -36,16 +34,13 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // FetchOrCreate creates a new instance if needed. func (k Keeper) FetchOrCreate(ctx sdk.Context, serviceHash hash.Hash, envHash hash.Hash) (*instance.Instance, error) { - if _, err := k.serviceKeeper.Get(ctx, serviceHash); err != nil { - return nil, err - } + store := ctx.KVStore(k.storeKey) inst, err := instance.New(serviceHash, envHash) if err != nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error()) } - store := ctx.KVStore(k.storeKey) if !store.Has(inst.Hash) { value, err := k.cdc.MarshalBinaryLengthPrefixed(inst) if err != nil { diff --git a/x/instance/internal/types/expected_keepers.go b/x/instance/internal/types/expected_keepers.go index 4b46cd058..23128499d 100644 --- a/x/instance/internal/types/expected_keepers.go +++ b/x/instance/internal/types/expected_keepers.go @@ -3,8 +3,6 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params" - "github.com/mesg-foundation/engine/hash" - servicepb "github.com/mesg-foundation/engine/service" ) // ParamSubspace defines the expected Subspace interfacace @@ -14,8 +12,3 @@ type ParamSubspace interface { GetParamSet(ctx sdk.Context, ps params.ParamSet) SetParamSet(ctx sdk.Context, ps params.ParamSet) } - -// ServiceKeeper module interface. -type ServiceKeeper interface { - Get(ctx sdk.Context, hash hash.Hash) (*servicepb.Service, error) -} From 5cdd58ee7aabc9e5993998de212bcacf2d9e5102 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Wed, 20 May 2020 18:31:28 +0700 Subject: [PATCH 12/18] Switch to json logger in orchestrator and daemon --- cmd/mesg-cli/orchestrator.go | 2 +- cmd/mesg-daemon/main.go | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cmd/mesg-cli/orchestrator.go b/cmd/mesg-cli/orchestrator.go index c6a138fbf..e2c3402c0 100644 --- a/cmd/mesg-cli/orchestrator.go +++ b/cmd/mesg-cli/orchestrator.go @@ -48,7 +48,7 @@ func startOrchestratorCmd(cdc *codec.Codec) *cobra.Command { return fmt.Errorf("chain-id is required. use flag --chain-id or config file") } - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + logger := log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)) client, err := cliCtx.GetNode() if err != nil { return err diff --git a/cmd/mesg-daemon/main.go b/cmd/mesg-daemon/main.go index 0e332b27e..857ef6f0d 100644 --- a/cmd/mesg-daemon/main.go +++ b/cmd/mesg-daemon/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "io" + "os" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/debug" @@ -19,7 +20,9 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" abci "github.com/tendermint/tendermint/abci/types" + cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/cli" + tmflags "github.com/tendermint/tendermint/libs/cli/flags" "github.com/tendermint/tendermint/libs/log" tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -35,12 +38,28 @@ func main() { // init the config of cosmos cosmos.InitConfig() - ctx := server.NewDefaultContext() + logger := log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)) + ctx := server.NewContext( + cfg.DefaultConfig(), + logger, + ) cobra.EnableCommandSorting = false rootCmd := &cobra.Command{ - Use: version.ServerName, - Short: "Engine Daemon (server)", - PersistentPreRunE: server.PersistentPreRunEFn(ctx), + Use: version.ServerName, + Short: "Engine Daemon (server)", + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + err := server.PersistentPreRunEFn(ctx)(cmd, args) + logger, err = tmflags.ParseLogLevel(ctx.Config.LogLevel, logger, cfg.DefaultLogLevel()) + if err != nil { + return err + } + if viper.GetBool(cli.TraceFlag) { + logger = log.NewTracingLogger(logger) + } + logger = logger.With("module", "main") + ctx.Logger = logger + return err + }, } rootCmd.AddCommand(genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome)) From bc2fe42e84c7e57b98fc35c8795ac3b34f0014d8 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Wed, 20 May 2020 19:16:09 +0700 Subject: [PATCH 13/18] improve logger creation in daemon cli --- cmd/mesg-daemon/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/mesg-daemon/main.go b/cmd/mesg-daemon/main.go index 857ef6f0d..2955d4d14 100644 --- a/cmd/mesg-daemon/main.go +++ b/cmd/mesg-daemon/main.go @@ -38,18 +38,19 @@ func main() { // init the config of cosmos cosmos.InitConfig() - logger := log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)) ctx := server.NewContext( cfg.DefaultConfig(), - logger, + log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)), ) cobra.EnableCommandSorting = false rootCmd := &cobra.Command{ Use: version.ServerName, Short: "Engine Daemon (server)", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - err := server.PersistentPreRunEFn(ctx)(cmd, args) - logger, err = tmflags.ParseLogLevel(ctx.Config.LogLevel, logger, cfg.DefaultLogLevel()) + if err := server.PersistentPreRunEFn(ctx)(cmd, args); err != nil { + return err + } + logger, err := tmflags.ParseLogLevel(ctx.Config.LogLevel, ctx.Logger, cfg.DefaultLogLevel()) if err != nil { return err } @@ -58,7 +59,7 @@ func main() { } logger = logger.With("module", "main") ctx.Logger = logger - return err + return nil }, } From 077b53caf665642477476ce98af567e9a670116e Mon Sep 17 00:00:00 2001 From: antho1404 Date: Wed, 20 May 2020 21:35:06 +0700 Subject: [PATCH 14/18] force json logs for daemon --- cmd/mesg-daemon/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/mesg-daemon/main.go b/cmd/mesg-daemon/main.go index 2955d4d14..d4fe165ca 100644 --- a/cmd/mesg-daemon/main.go +++ b/cmd/mesg-daemon/main.go @@ -50,7 +50,7 @@ func main() { if err := server.PersistentPreRunEFn(ctx)(cmd, args); err != nil { return err } - logger, err := tmflags.ParseLogLevel(ctx.Config.LogLevel, ctx.Logger, cfg.DefaultLogLevel()) + logger, err := tmflags.ParseLogLevel(ctx.Config.LogLevel, log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)), cfg.DefaultLogLevel()) if err != nil { return err } From b17a3f9e6c8aa9b4c910a7096f17530020e7bee2 Mon Sep 17 00:00:00 2001 From: antho1404 Date: Wed, 20 May 2020 21:35:31 +0700 Subject: [PATCH 15/18] custom lcd server with json log --- cmd/mesg-cli/main.go | 64 +++++++++++++++++++++++++++++++++++--------- go.mod | 1 + 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/cmd/mesg-cli/main.go b/cmd/mesg-cli/main.go index b9f23e06e..af1b32e40 100644 --- a/cmd/mesg-cli/main.go +++ b/cmd/mesg-cli/main.go @@ -2,26 +2,33 @@ package main import ( "fmt" + "net" "os" "path" + "time" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" - "github.com/cosmos/cosmos-sdk/client/lcd" "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" "github.com/cosmos/cosmos-sdk/x/bank" bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" + "github.com/gorilla/mux" "github.com/mesg-foundation/engine/app" "github.com/mesg-foundation/engine/cosmos" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/libs/cli" + "github.com/tendermint/tendermint/libs/log" + rpcserver "github.com/tendermint/tendermint/rpc/lib/server" ) func main() { @@ -54,7 +61,7 @@ func main() { flags.LineBreak, orchestratorCmd(cdc), flags.LineBreak, - lcd.ServeCommand(cdc, registerRoutes), + ServeCommand(cdc), flags.LineBreak, keys.Commands(), signCommand(), @@ -73,6 +80,49 @@ func main() { } } +// ServeCommand creates and starts the LCD server +func ServeCommand(cdc *codec.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "rest-server", + Short: "Start LCD (light-client daemon), a local REST server", + RunE: func(cmd *cobra.Command, args []string) (err error) { + r := mux.NewRouter() + cliCtx := context.NewCLIContext().WithCodec(cdc) + logger := log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)).With("module", "rest-server") + var listener net.Listener + server.TrapSignal(func() { + err := listener.Close() + logger.Error("error closing listener", "err", err) + }) + + client.RegisterRoutes(cliCtx, r) + authrest.RegisterTxRoutes(cliCtx, r) + app.ModuleBasics.RegisterRESTRoutes(cliCtx, r) + cosmos.RegisterSimulateRoute(cliCtx, r) + + cfg := rpcserver.DefaultConfig() + cfg.MaxOpenConnections = viper.GetInt(flags.FlagMaxOpenConnections) + cfg.ReadTimeout = time.Duration(uint(viper.GetInt(flags.FlagRPCReadTimeout))) * time.Second + cfg.WriteTimeout = time.Duration(uint(viper.GetInt(flags.FlagRPCWriteTimeout))) * time.Second + + listener, err = rpcserver.Listen(viper.GetString(flags.FlagListenAddr), cfg) + if err != nil { + return + } + logger.Info( + fmt.Sprintf( + "Starting application REST service (chain-id: %q)...", + viper.GetString(flags.FlagChainID), + ), + ) + + return rpcserver.StartHTTPServer(listener, r, logger, cfg) + }, + } + + return flags.RegisterRestServerFlags(cmd) +} + func queryCmd(cdc *amino.Codec) *cobra.Command { queryCmd := &cobra.Command{ Use: "query", @@ -131,16 +181,6 @@ func txCmd(cdc *amino.Codec) *cobra.Command { return txCmd } -// registerRoutes registers the routes from the different modules for the LCD. -// NOTE: details on the routes added for each module are in the module documentation -// NOTE: If making updates here you also need to update the test helper in client/lcd/test_helper.go -func registerRoutes(rs *lcd.RestServer) { - client.RegisterRoutes(rs.CliCtx, rs.Mux) - authrest.RegisterTxRoutes(rs.CliCtx, rs.Mux) - app.ModuleBasics.RegisterRESTRoutes(rs.CliCtx, rs.Mux) - cosmos.RegisterSimulateRoute(rs.CliCtx, rs.Mux) -} - func initConfig(cmd *cobra.Command) error { home, err := cmd.PersistentFlags().GetString(cli.HomeFlag) if err != nil { diff --git a/go.mod b/go.mod index 37347ee35..4063e85d2 100644 --- a/go.mod +++ b/go.mod @@ -42,6 +42,7 @@ require ( github.com/prometheus/client_golang v1.5.1 github.com/prometheus/procfs v0.0.11 // indirect github.com/pseudomuto/protoc-gen-doc v1.3.1 + github.com/rakyll/statik v0.1.6 github.com/rcrowley/go-metrics v0.0.0-20190706150252-9beb055b7962 // indirect github.com/sirupsen/logrus v1.5.0 // indirect github.com/spf13/afero v1.2.2 // indirect From 940fcc0c31daa111c56c379ce62cb2b3268be796 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Thu, 21 May 2020 09:51:40 +0700 Subject: [PATCH 16/18] move lcd serve command to a dedicated file --- cmd/mesg-cli/main.go | 52 -------------------------------- cmd/mesg-cli/serve.go | 70 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 52 deletions(-) create mode 100644 cmd/mesg-cli/serve.go diff --git a/cmd/mesg-cli/main.go b/cmd/mesg-cli/main.go index af1b32e40..8c88e5ab4 100644 --- a/cmd/mesg-cli/main.go +++ b/cmd/mesg-cli/main.go @@ -2,33 +2,24 @@ package main import ( "fmt" - "net" "os" "path" - "time" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/rpc" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" - authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" "github.com/cosmos/cosmos-sdk/x/bank" bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" - "github.com/gorilla/mux" "github.com/mesg-foundation/engine/app" "github.com/mesg-foundation/engine/cosmos" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/libs/cli" - "github.com/tendermint/tendermint/libs/log" - rpcserver "github.com/tendermint/tendermint/rpc/lib/server" ) func main() { @@ -80,49 +71,6 @@ func main() { } } -// ServeCommand creates and starts the LCD server -func ServeCommand(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "rest-server", - Short: "Start LCD (light-client daemon), a local REST server", - RunE: func(cmd *cobra.Command, args []string) (err error) { - r := mux.NewRouter() - cliCtx := context.NewCLIContext().WithCodec(cdc) - logger := log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)).With("module", "rest-server") - var listener net.Listener - server.TrapSignal(func() { - err := listener.Close() - logger.Error("error closing listener", "err", err) - }) - - client.RegisterRoutes(cliCtx, r) - authrest.RegisterTxRoutes(cliCtx, r) - app.ModuleBasics.RegisterRESTRoutes(cliCtx, r) - cosmos.RegisterSimulateRoute(cliCtx, r) - - cfg := rpcserver.DefaultConfig() - cfg.MaxOpenConnections = viper.GetInt(flags.FlagMaxOpenConnections) - cfg.ReadTimeout = time.Duration(uint(viper.GetInt(flags.FlagRPCReadTimeout))) * time.Second - cfg.WriteTimeout = time.Duration(uint(viper.GetInt(flags.FlagRPCWriteTimeout))) * time.Second - - listener, err = rpcserver.Listen(viper.GetString(flags.FlagListenAddr), cfg) - if err != nil { - return - } - logger.Info( - fmt.Sprintf( - "Starting application REST service (chain-id: %q)...", - viper.GetString(flags.FlagChainID), - ), - ) - - return rpcserver.StartHTTPServer(listener, r, logger, cfg) - }, - } - - return flags.RegisterRestServerFlags(cmd) -} - func queryCmd(cdc *amino.Codec) *cobra.Command { queryCmd := &cobra.Command{ Use: "query", diff --git a/cmd/mesg-cli/serve.go b/cmd/mesg-cli/serve.go new file mode 100644 index 000000000..8b71e5dd0 --- /dev/null +++ b/cmd/mesg-cli/serve.go @@ -0,0 +1,70 @@ +package main + +import ( + "fmt" + "net" + "os" + "time" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/server" + authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" + "github.com/gorilla/mux" + "github.com/mesg-foundation/engine/app" + "github.com/mesg-foundation/engine/cosmos" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/tendermint/tendermint/libs/log" + rpcserver "github.com/tendermint/tendermint/rpc/lib/server" +) + +// ServeCommand creates and starts the LCD server +// adapted version of function from https://github.com/cosmos/cosmos-sdk/blob/v0.38.3/client/lcd/root.go#L74-L100 +func ServeCommand(cdc *codec.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "rest-server", + Short: "Start LCD (light-client daemon), a local REST server", + RunE: func(cmd *cobra.Command, args []string) (err error) { + // new rest server + r := mux.NewRouter() + cliCtx := context.NewCLIContext().WithCodec(cdc) + logger := log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)).With("module", "rest-server") + + // register routes + client.RegisterRoutes(cliCtx, r) + authrest.RegisterTxRoutes(cliCtx, r) + app.ModuleBasics.RegisterRESTRoutes(cliCtx, r) + cosmos.RegisterSimulateRoute(cliCtx, r) + + // start + var listener net.Listener + server.TrapSignal(func() { + err := listener.Close() + logger.Error("error closing listener", "err", err) + }) + + cfg := rpcserver.DefaultConfig() + cfg.MaxOpenConnections = viper.GetInt(flags.FlagMaxOpenConnections) + cfg.ReadTimeout = time.Duration(uint(viper.GetInt(flags.FlagRPCReadTimeout))) * time.Second + cfg.WriteTimeout = time.Duration(uint(viper.GetInt(flags.FlagRPCWriteTimeout))) * time.Second + + listener, err = rpcserver.Listen(viper.GetString(flags.FlagListenAddr), cfg) + if err != nil { + return + } + logger.Info( + fmt.Sprintf( + "Starting application REST service (chain-id: %q)...", + viper.GetString(flags.FlagChainID), + ), + ) + + return rpcserver.StartHTTPServer(listener, r, logger, cfg) + }, + } + + return flags.RegisterRestServerFlags(cmd) +} From 28a2f36de18cf44162d52fd9fd6ba1ebd9b6bd54 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Thu, 21 May 2020 09:51:59 +0700 Subject: [PATCH 17/18] cleanup go mod dep and add link to original function --- cmd/mesg-daemon/main.go | 1 + go.mod | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/mesg-daemon/main.go b/cmd/mesg-daemon/main.go index d4fe165ca..146cf9178 100644 --- a/cmd/mesg-daemon/main.go +++ b/cmd/mesg-daemon/main.go @@ -47,6 +47,7 @@ func main() { Use: version.ServerName, Short: "Engine Daemon (server)", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + // adapted version of function from https://github.com/cosmos/cosmos-sdk/blob/v0.38.3/server/util.go#L49-L74 if err := server.PersistentPreRunEFn(ctx)(cmd, args); err != nil { return err } diff --git a/go.mod b/go.mod index 4063e85d2..37347ee35 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,6 @@ require ( github.com/prometheus/client_golang v1.5.1 github.com/prometheus/procfs v0.0.11 // indirect github.com/pseudomuto/protoc-gen-doc v1.3.1 - github.com/rakyll/statik v0.1.6 github.com/rcrowley/go-metrics v0.0.0-20190706150252-9beb055b7962 // indirect github.com/sirupsen/logrus v1.5.0 // indirect github.com/spf13/afero v1.2.2 // indirect From 70eaa421555415022aba4a1d80a1a1521cb09179 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Thu, 21 May 2020 10:18:07 +0700 Subject: [PATCH 18/18] add v0.25.0 to changelog --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47e0fb745..c7b29b1da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## [v0.25.0](https://github.com/mesg-foundation/engine/releases/tag/v0.25.0) + +#### Breaking Changes + +- ([#1830](https://github.com/mesg-foundation/engine/pull/1830)) Revert "Fix 2 issues with instance". + +#### Added + +- ([#1825](https://github.com/mesg-foundation/engine/pull/1825)) Add filter on execution list. + +#### Changed + +- ([#1827](https://github.com/mesg-foundation/engine/pull/1827)) Update dev script to use docker container instead of docker service. +- ([#1828](https://github.com/mesg-foundation/engine/pull/1828)) Improve CLI commands. +- ([#1831](https://github.com/mesg-foundation/engine/pull/1831)) Switch to json logger in orchestrator and daemon. + ## [v0.24.0](https://github.com/mesg-foundation/engine/releases/tag/v0.24.0) #### Breaking Changes