diff --git a/.gitignore b/.gitignore index b031ce185..7b7b746fb 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ docs/tools scripts/wal2json/wal2json scripts/cutWALUntil/cutWALUntil + +.idea/ +*.iml diff --git a/docs/specification/rpc.rst b/docs/specification/rpc.rst index 7df394d77..386791aa7 100644 --- a/docs/specification/rpc.rst +++ b/docs/specification/rpc.rst @@ -97,6 +97,7 @@ An HTTP Get request to the root RPC endpoint (e.g. http://localhost:46657/genesis http://localhost:46657/net_info http://localhost:46657/num_unconfirmed_txs + http://localhost:46657/health http://localhost:46657/status http://localhost:46657/unconfirmed_txs http://localhost:46657/unsafe_flush_mempool diff --git a/rpc/core/doc.go b/rpc/core/doc.go index 5f3e2dced..b479482c4 100644 --- a/rpc/core/doc.go +++ b/rpc/core/doc.go @@ -81,6 +81,7 @@ Available endpoints: /net_info /num_unconfirmed_txs /status +/health /unconfirmed_txs /unsafe_flush_mempool /unsafe_stop_cpu_profiler diff --git a/rpc/core/health.go b/rpc/core/health.go new file mode 100644 index 000000000..dd71b4a91 --- /dev/null +++ b/rpc/core/health.go @@ -0,0 +1,30 @@ +package core + +import ( + ctypes "github.com/tendermint/tendermint/rpc/core/types" +) + +// Get node health. Checks whether new blocks are created. +// +// ```shell +// curl 'localhost:46657/health' +// ``` +// +// ```go +// client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket") +// result, err := client.Health() +// ``` +// +// > The above command returns JSON structured like this: +// +// ```json +// { +// "error": "", +// "result": {}, +// "id": "", +// "jsonrpc": "2.0" +// } +// ``` +func Health() (*ctypes.ResultHealth, error) { + return &ctypes.ResultHealth{}, nil +} diff --git a/rpc/core/pipe.go b/rpc/core/pipe.go index 2edb3f3d1..1eb00ceeb 100644 --- a/rpc/core/pipe.go +++ b/rpc/core/pipe.go @@ -3,10 +3,10 @@ package core import ( "time" - crypto "github.com/tendermint/go-crypto" + "github.com/tendermint/go-crypto" "github.com/tendermint/tendermint/consensus" cstypes "github.com/tendermint/tendermint/consensus/types" - p2p "github.com/tendermint/tendermint/p2p" + "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state/txindex" diff --git a/rpc/core/routes.go b/rpc/core/routes.go index 3ea7aa08c..0e10cefee 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -12,6 +12,7 @@ var Routes = map[string]*rpc.RPCFunc{ "unsubscribe_all": rpc.NewWSRPCFunc(UnsubscribeAll, ""), // info API + "health": rpc.NewRPCFunc(Health, ""), "status": rpc.NewRPCFunc(Status, ""), "net_info": rpc.NewRPCFunc(NetInfo, ""), "blockchain": rpc.NewRPCFunc(BlockchainInfo, "minHeight,maxHeight"), diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index e13edc843..7567fe650 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -155,3 +155,5 @@ type ResultEvent struct { Query string `json:"query"` Data types.TMEventData `json:"data"` } + +type ResultHealth struct{} diff --git a/types/heartbeat.go b/types/heartbeat.go index fc5f8ad7f..8b86a15ba 100644 --- a/types/heartbeat.go +++ b/types/heartbeat.go @@ -14,7 +14,7 @@ import ( // json field tags because we always want the JSON // representation to be in its canonical form. type Heartbeat struct { - ValidatorAddress Address `json:"validator_address"` + ValidatorAddress Address `json:"validator_address"` ValidatorIndex int `json:"validator_index"` Height int64 `json:"height"` Round int `json:"round"`