Skip to content

Commit 868328b

Browse files
committed
Merge PR #4837: Cleanup node_info Endpoint
1 parent 78f302d commit 868328b

File tree

10 files changed

+134
-116
lines changed

10 files changed

+134
-116
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[\#4837](https://github.com/cosmos/cosmos-sdk/pull/4837) Remove /version and /node_version
2+
endpoints in favor of refactoring /node_info to also include application version info.

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ build: go.sum
2525

2626
update-swagger-docs: statik
2727
$(BINDIR)/statik -src=client/lcd/swagger-ui -dest=client/lcd -f -m
28-
if [ -n "$(git status --porcelain)" ]; then \
29-
echo "swagger docs out of sync";\
28+
@if [ -n "$(git status --porcelain)" ]; then \
29+
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
3030
exit 1;\
3131
else \
32-
echo "swagger docs are in sync";\
32+
echo "\033[92mSwagger docs are in sync\033[0m";\
3333
fi
3434
.PHONY: update-swagger-docs
3535

client/alias.go

-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ var (
9494
BlockRequestHandlerFn = rpc.BlockRequestHandlerFn
9595
LatestBlockRequestHandlerFn = rpc.LatestBlockRequestHandlerFn
9696
RegisterRPCRoutes = rpc.RegisterRPCRoutes
97-
CLIVersionRequestHandler = rpc.CLIVersionRequestHandler
98-
NodeVersionRequestHandler = rpc.NodeVersionRequestHandler
9997
StatusCommand = rpc.StatusCommand
10098
NodeInfoRequestHandlerFn = rpc.NodeInfoRequestHandlerFn
10199
NodeSyncingRequestHandlerFn = rpc.NodeSyncingRequestHandlerFn

client/lcd/statik/statik.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/lcd/swagger-ui/swagger.yaml

+58-42
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ securityDefinitions:
3535
kms:
3636
type: basic
3737
paths:
38-
/version:
39-
get:
40-
summary: Version of Gaia-lite
41-
tags:
42-
- Misc
43-
description: Get the version of gaia-lite running locally to compare against expected
44-
responses:
45-
200:
46-
description: Plaintext version i.e. "v0.25.0"
4738
/node_info:
4839
get:
4940
description: Information about the connected node
@@ -58,44 +49,62 @@ paths:
5849
schema:
5950
type: object
6051
properties:
61-
id:
62-
type: string
63-
moniker:
64-
type: string
65-
example: validator-name
66-
protocol_version:
52+
application_version:
6753
properties:
68-
p2p:
54+
build_tags:
6955
type: string
70-
example: 7
71-
block:
56+
client_name:
7257
type: string
73-
example: 10
74-
app:
58+
commit:
7559
type: string
76-
example: 0
77-
network:
78-
type: string
79-
example: gaia-2
80-
channels:
81-
type: string
82-
listen_addr:
83-
type: string
84-
example: 192.168.56.1:26656
85-
version:
86-
description: Tendermint version
87-
type: string
88-
example: 0.15.0
89-
other:
90-
description: more information on versions
91-
type: object
60+
go:
61+
type: string
62+
name:
63+
type: string
64+
server_name:
65+
type: string
66+
version:
67+
type: string
68+
node_info:
9269
properties:
93-
tx_index:
70+
id:
71+
type: string
72+
moniker:
73+
type: string
74+
example: validator-name
75+
protocol_version:
76+
properties:
77+
p2p:
78+
type: string
79+
example: 7
80+
block:
81+
type: string
82+
example: 10
83+
app:
84+
type: string
85+
example: 0
86+
network:
87+
type: string
88+
example: gaia-2
89+
channels:
90+
type: string
91+
listen_addr:
9492
type: string
95-
example: on
96-
rpc_address:
93+
example: 192.168.56.1:26656
94+
version:
95+
description: Tendermint version
9796
type: string
98-
example: tcp://0.0.0.0:26657
97+
example: 0.15.0
98+
other:
99+
description: more information on versions
100+
type: object
101+
properties:
102+
tx_index:
103+
type: string
104+
example: on
105+
rpc_address:
106+
type: string
107+
example: tcp://0.0.0.0:26657
99108
500:
100109
description: Failed to query node status
101110
/syncing:
@@ -104,9 +113,16 @@ paths:
104113
tags:
105114
- Tendermint RPC
106115
description: Get if the node is currently syning with other nodes
116+
produces:
117+
- application/json
107118
responses:
108119
200:
109-
description: '"true" or "false"'
120+
description: Node syncing status
121+
schema:
122+
type: object
123+
properties:
124+
syncing:
125+
type: boolean
110126
500:
111127
description: Server internal error
112128
/blocks/latest:
@@ -2481,4 +2497,4 @@ definitions:
24812497
total:
24822498
type: array
24832499
items:
2484-
$ref: "#/definitions/Coin"
2500+
$ref: "#/definitions/Coin"

client/rpc/root.go

-32
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,17 @@
11
package rpc
22

33
import (
4-
"fmt"
5-
"log"
6-
"net/http"
7-
84
"github.com/gorilla/mux"
95

106
"github.com/cosmos/cosmos-sdk/client/context"
11-
"github.com/cosmos/cosmos-sdk/types/rest"
12-
"github.com/cosmos/cosmos-sdk/version"
137
)
148

159
// Register REST endpoints
1610
func RegisterRPCRoutes(cliCtx context.CLIContext, r *mux.Router) {
17-
r.HandleFunc("/version", CLIVersionRequestHandler).Methods("GET")
18-
r.HandleFunc("/node_version", NodeVersionRequestHandler(cliCtx)).Methods("GET")
1911
r.HandleFunc("/node_info", NodeInfoRequestHandlerFn(cliCtx)).Methods("GET")
2012
r.HandleFunc("/syncing", NodeSyncingRequestHandlerFn(cliCtx)).Methods("GET")
2113
r.HandleFunc("/blocks/latest", LatestBlockRequestHandlerFn(cliCtx)).Methods("GET")
2214
r.HandleFunc("/blocks/{height}", BlockRequestHandlerFn(cliCtx)).Methods("GET")
2315
r.HandleFunc("/validatorsets/latest", LatestValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
2416
r.HandleFunc("/validatorsets/{height}", ValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
2517
}
26-
27-
// cli version REST handler endpoint
28-
func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) {
29-
w.Header().Set("Content-Type", "application/json")
30-
if _, err := w.Write([]byte(fmt.Sprintf("{\"version\": \"%s\"}", version.Version))); err != nil {
31-
log.Printf("could not write response: %v", err)
32-
}
33-
}
34-
35-
// connected node version REST handler endpoint
36-
func NodeVersionRequestHandler(cliCtx context.CLIContext) http.HandlerFunc {
37-
return func(w http.ResponseWriter, r *http.Request) {
38-
res, _, err := cliCtx.Query("/app/version")
39-
if err != nil {
40-
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
41-
return
42-
}
43-
44-
w.Header().Set("Content-Type", "application/json")
45-
if _, err := w.Write(res); err != nil {
46-
log.Printf("could not write response: %v", err)
47-
}
48-
}
49-
}

client/rpc/status.go

+20-14
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package rpc
22

33
import (
44
"fmt"
5-
"log"
65
"net/http"
7-
"strconv"
86

97
"github.com/spf13/cobra"
108
"github.com/spf13/viper"
@@ -15,9 +13,12 @@ import (
1513
"github.com/cosmos/cosmos-sdk/client/flags"
1614
"github.com/cosmos/cosmos-sdk/codec"
1715
"github.com/cosmos/cosmos-sdk/types/rest"
16+
"github.com/cosmos/cosmos-sdk/version"
17+
18+
"github.com/tendermint/tendermint/p2p"
1819
)
1920

20-
// StatusCommand returns the status of the network
21+
// StatusCommand returns the command to return the status of the network.
2122
func StatusCommand() *cobra.Command {
2223
cmd := &cobra.Command{
2324
Use: "status",
@@ -32,7 +33,6 @@ func StatusCommand() *cobra.Command {
3233
}
3334

3435
func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
35-
// get the node
3636
node, err := cliCtx.GetNode()
3737
if err != nil {
3838
return &ctypes.ResultStatus{}, err
@@ -41,9 +41,7 @@ func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
4141
return node.Status()
4242
}
4343

44-
// CMD
45-
46-
func printNodeStatus(cmd *cobra.Command, args []string) error {
44+
func printNodeStatus(_ *cobra.Command, _ []string) error {
4745
// No need to verify proof in getting node status
4846
viper.Set(flags.FlagTrustNode, true)
4947
cliCtx := context.NewCLIContext()
@@ -66,7 +64,11 @@ func printNodeStatus(cmd *cobra.Command, args []string) error {
6664
return nil
6765
}
6866

69-
// REST
67+
type nodeInfoResponse struct {
68+
p2p.DefaultNodeInfo `json:"node_info"`
69+
70+
ApplicationVersion version.Info `json:"application_version"`
71+
}
7072

7173
// REST handler for node info
7274
func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
@@ -77,11 +79,18 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
7779
return
7880
}
7981

80-
nodeInfo := status.NodeInfo
81-
rest.PostProcessResponse(w, cliCtx, nodeInfo)
82+
resp := nodeInfoResponse{
83+
DefaultNodeInfo: status.NodeInfo,
84+
ApplicationVersion: version.NewInfo(),
85+
}
86+
rest.PostProcessResponseBare(w, cliCtx, resp)
8287
}
8388
}
8489

90+
type syncingResponse struct {
91+
Syncing bool `json:"syncing"`
92+
}
93+
8594
// REST handler for node syncing
8695
func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
8796
return func(w http.ResponseWriter, r *http.Request) {
@@ -91,9 +100,6 @@ func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
91100
return
92101
}
93102

94-
syncing := status.SyncInfo.CatchingUp
95-
if _, err := w.Write([]byte(strconv.FormatBool(syncing))); err != nil {
96-
log.Printf("could not write response: %v", err)
97-
}
103+
rest.PostProcessResponseBare(w, cliCtx, syncingResponse{Syncing: status.SyncInfo.CatchingUp})
98104
}
99105
}

types/rest/rest.go

+29
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,35 @@ func ParseQueryHeightOrReturnBadRequest(w http.ResponseWriter, cliCtx context.CL
237237
return cliCtx, true
238238
}
239239

240+
// PostProcessResponseBare post processes a body similar to PostProcessResponse
241+
// except it does not wrap the body and inject the height.
242+
func PostProcessResponseBare(w http.ResponseWriter, cliCtx context.CLIContext, body interface{}) {
243+
var (
244+
resp []byte
245+
err error
246+
)
247+
248+
switch body.(type) {
249+
case []byte:
250+
resp = body.([]byte)
251+
252+
default:
253+
if cliCtx.Indent {
254+
resp, err = cliCtx.Codec.MarshalJSONIndent(body, "", " ")
255+
} else {
256+
resp, err = cliCtx.Codec.MarshalJSON(body)
257+
}
258+
259+
if err != nil {
260+
WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
261+
return
262+
}
263+
}
264+
265+
w.Header().Set("Content-Type", "application/json")
266+
_, _ = w.Write(resp)
267+
}
268+
240269
// PostProcessResponse performs post processing for a REST response. The result
241270
// returned to clients will contain two fields, the height at which the resource
242271
// was queried at and the original result.

version/command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var Cmd = &cobra.Command{
2222
Use: "version",
2323
Short: "Print the app version",
2424
RunE: func(_ *cobra.Command, _ []string) error {
25-
verInfo := newVersionInfo()
25+
verInfo := NewInfo()
2626

2727
if !viper.GetBool(flagLong) {
2828
fmt.Println(verInfo.Version)

0 commit comments

Comments
 (0)