From 64879c1e6af87c447d79f963f0f9891677ac9019 Mon Sep 17 00:00:00 2001 From: Bric3d Date: Wed, 11 Apr 2018 10:38:34 +0200 Subject: [PATCH] 1417 status response format (#1424) * Reformated the ResultStatus * fix misuse of ResultStatus. * updated changelog * Fixed tests * fixed rpc helper tests * fixed rpc_tests * fixed mock/status_test * fixed typo * fixed ommitempty on validatorstatus and the changelog * fixed extra line in changelog * Updated usage of the /status json response in tests after breaking changes * Updated remaining tests with changes after searching the codebase for usage * Reformated the ResultStatus * fix misuse of ResultStatus. * updated changelog * Fixed tests * fixed rpc helper tests * fixed rpc_tests * fixed mock/status_test * fixed typo * fixed ommitempty on validatorstatus and the changelog * Updated usage of the /status json response in tests after breaking changes * Updated remaining tests with changes after searching the codebase for usage * rebased against develop --- CHANGELOG.md | 2 ++ benchmarks/codec_test.go | 12 +++++--- docs/using-tendermint.rst | 4 +-- lite/client/provider.go | 2 +- rpc/client/helpers.go | 2 +- rpc/client/helpers_test.go | 8 ++--- rpc/client/mock/status_test.go | 16 +++++----- rpc/client/rpc_test.go | 4 +-- rpc/core/status.go | 46 +++++++++++++++------------- rpc/core/types/responses.go | 24 +++++++++------ test/p2p/atomic_broadcast/test.sh | 14 ++++----- test/p2p/basic/test.sh | 4 +-- test/p2p/fast_sync/check_peer.sh | 8 ++--- test/p2p/kill_all/check_peers.sh | 4 +-- test/persist/test_failure_indices.sh | 12 ++++---- test/persist/test_simple.sh | 6 ++-- 16 files changed, 91 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f54c9805d..9a462a993 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ BUG FIXES: BREAKING: +- [rpc]: Changed the output format for the `/status` endpoint + Upgrade from go-wire to go-amino. This is a sweeping change that breaks everything that is serialized to disk or over the network. diff --git a/benchmarks/codec_test.go b/benchmarks/codec_test.go index 2f24b776d..d8e4bc82c 100644 --- a/benchmarks/codec_test.go +++ b/benchmarks/codec_test.go @@ -26,10 +26,14 @@ func BenchmarkEncodeStatusWire(b *testing.B) { Version: "SOMEVER", Other: []string{"SOMESTRING", "OTHERSTRING"}, }, - PubKey: nodeKey.PubKey(), - LatestBlockHash: []byte("SOMEBYTES"), - LatestBlockHeight: 123, - LatestBlockTime: time.Unix(0, 1234), + SyncInfo: ctypes.SyncInfo{ + LatestBlockHash: []byte("SOMEBYTES"), + LatestBlockHeight: 123, + LatestBlockTime: time.Unix(0, 1234), + }, + ValidatorInfo: ctypes.ValidatorInfo{ + PubKey: nodeKey.PubKey(), + }, } b.StartTimer() diff --git a/docs/using-tendermint.rst b/docs/using-tendermint.rst index 13c2d882f..1d8e1aaaa 100644 --- a/docs/using-tendermint.rst +++ b/docs/using-tendermint.rst @@ -83,11 +83,11 @@ We can see the chain's status at the ``/status`` end-point: curl http://localhost:46657/status | jsonpp -and the ``latest_app_hash`` in particular: +and the ``sync_info.latest_app_hash`` in particular: :: - curl http://localhost:46657/status | jsonpp | grep app_hash + curl http://localhost:46657/status | jsonpp | grep sync_info.latest_app_hash Visit http://localhost:46657 in your browser to see the list of other endpoints. Some take no arguments (like ``/status``), while others diff --git a/lite/client/provider.go b/lite/client/provider.go index c98297dec..5f3d72450 100644 --- a/lite/client/provider.go +++ b/lite/client/provider.go @@ -93,7 +93,7 @@ func (p *provider) GetLatestCommit() (*ctypes.ResultCommit, error) { if err != nil { return nil, err } - return p.node.Commit(&status.LatestBlockHeight) + return p.node.Commit(&status.SyncInfo.LatestBlockHeight) } // CommitFromResult ... diff --git a/rpc/client/helpers.go b/rpc/client/helpers.go index 86c65919d..7e64d1164 100644 --- a/rpc/client/helpers.go +++ b/rpc/client/helpers.go @@ -41,7 +41,7 @@ func WaitForHeight(c StatusClient, h int64, waiter Waiter) error { if err != nil { return err } - delta = h - s.LatestBlockHeight + delta = h - s.SyncInfo.LatestBlockHeight // wait for the time, or abort early if err := waiter(delta); err != nil { return err diff --git a/rpc/client/helpers_test.go b/rpc/client/helpers_test.go index cef462475..d5c31ddaf 100644 --- a/rpc/client/helpers_test.go +++ b/rpc/client/helpers_test.go @@ -32,7 +32,7 @@ func TestWaitForHeight(t *testing.T) { // now set current block height to 10 m.Call = mock.Call{ - Response: &ctypes.ResultStatus{LatestBlockHeight: 10}, + Response: &ctypes.ResultStatus{SyncInfo: ctypes.SyncInfo{LatestBlockHeight: 10} }, } // we will not wait for more than 10 blocks @@ -52,7 +52,7 @@ func TestWaitForHeight(t *testing.T) { // we use the callback to update the status height myWaiter := func(delta int64) error { // update the height for the next call - m.Call.Response = &ctypes.ResultStatus{LatestBlockHeight: 15} + m.Call.Response = &ctypes.ResultStatus{SyncInfo: ctypes.SyncInfo{LatestBlockHeight: 15}} return client.DefaultWaitStrategy(delta) } @@ -66,11 +66,11 @@ func TestWaitForHeight(t *testing.T) { require.Nil(pre.Error) prer, ok := pre.Response.(*ctypes.ResultStatus) require.True(ok) - assert.Equal(int64(10), prer.LatestBlockHeight) + assert.Equal(int64(10), prer.SyncInfo.LatestBlockHeight) post := r.Calls[4] require.Nil(post.Error) postr, ok := post.Response.(*ctypes.ResultStatus) require.True(ok) - assert.Equal(int64(15), postr.LatestBlockHeight) + assert.Equal(int64(15), postr.SyncInfo.LatestBlockHeight) } diff --git a/rpc/client/mock/status_test.go b/rpc/client/mock/status_test.go index b3827fb13..dafd35080 100644 --- a/rpc/client/mock/status_test.go +++ b/rpc/client/mock/status_test.go @@ -17,9 +17,11 @@ func TestStatus(t *testing.T) { m := &mock.StatusMock{ Call: mock.Call{ Response: &ctypes.ResultStatus{ - LatestBlockHash: cmn.HexBytes("block"), - LatestAppHash: cmn.HexBytes("app"), - LatestBlockHeight: 10, + SyncInfo: ctypes.SyncInfo{ + LatestBlockHash: cmn.HexBytes("block"), + LatestAppHash: cmn.HexBytes("app"), + LatestBlockHeight: 10, + }, }}, } @@ -29,8 +31,8 @@ func TestStatus(t *testing.T) { // make sure response works proper status, err := r.Status() require.Nil(err, "%+v", err) - assert.EqualValues("block", status.LatestBlockHash) - assert.EqualValues(10, status.LatestBlockHeight) + assert.EqualValues("block", status.SyncInfo.LatestBlockHash) + assert.EqualValues(10, status.SyncInfo.LatestBlockHeight) // make sure recorder works properly require.Equal(1, len(r.Calls)) @@ -41,6 +43,6 @@ func TestStatus(t *testing.T) { require.NotNil(rs.Response) st, ok := rs.Response.(*ctypes.ResultStatus) require.True(ok) - assert.EqualValues("block", st.LatestBlockHash) - assert.EqualValues(10, st.LatestBlockHeight) + assert.EqualValues("block", st.SyncInfo.LatestBlockHash) + assert.EqualValues(10, st.SyncInfo.LatestBlockHeight) } diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index c5c5822f9..bfdc707f4 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -50,7 +50,7 @@ func TestInfo(t *testing.T) { info, err := c.ABCIInfo() require.Nil(t, err, "%d: %+v", i, err) // TODO: this is not correct - fix merkleeyes! - // assert.EqualValues(t, status.LatestBlockHeight, info.Response.LastBlockHeight) + // assert.EqualValues(t, status.SyncInfo.LatestBlockHeight, info.Response.LastBlockHeight) assert.True(t, strings.Contains(info.Response.Data, "size")) } } @@ -136,7 +136,7 @@ func TestAppCalls(t *testing.T) { s, err := c.Status() require.Nil(err, "%d: %+v", i, err) // sh is start height or status height - sh := s.LatestBlockHeight + sh := s.SyncInfo.LatestBlockHeight // look for the future h := sh + 2 diff --git a/rpc/core/status.go b/rpc/core/status.go index b4543a61c..9bdf9dd64 100644 --- a/rpc/core/status.go +++ b/rpc/core/status.go @@ -27,15 +27,20 @@ import ( // ```json // { // "result": { -// "syncing": false, -// "latest_block_time": "2017-12-07T18:19:47.617Z", -// "latest_block_height": 6, -// "latest_app_hash": "", -// "latest_block_hash": "A63D0C3307DEDCCFCC82ED411AE9108B70B29E02", -// "pub_key": { -// "data": "8C9A68070CBE33F9C445862BA1E9D96A75CEB68C0CF6ADD3652D07DCAC5D0380", -// "type": "ed25519" -// }, +// "sync_info": { +// "syncing": false, +// "latest_block_time": "2017-12-07T18:19:47.617Z", +// "latest_block_height": 6, +// "latest_app_hash": "", +// "latest_block_hash": "A63D0C3307DEDCCFCC82ED411AE9108B70B29E02", +// } +// "validator_info": { +// "pub_key": { +// "data": "8C9A68070CBE33F9C445862BA1E9D96A75CEB68C0CF6ADD3652D07DCAC5D0380", +// "type": "ed25519" +// }, +// "voting_power": 10 +// } // "node_info": { // "other": [ // "wire_version=0.7.2", @@ -51,9 +56,6 @@ import ( // "network": "test-chain-qhVCa2", // "moniker": "vagrant-ubuntu-trusty-64", // "pub_key": "844981FE99ABB19F7816F2D5E94E8A74276AB1153760A7799E925C75401856C6", -// "validator_status": { -// "voting_power": 10 -// } // } // }, // "id": "", @@ -78,20 +80,20 @@ func Status() (*ctypes.ResultStatus, error) { latestBlockTime := time.Unix(0, latestBlockTimeNano) result := &ctypes.ResultStatus{ - NodeInfo: p2pSwitch.NodeInfo(), - PubKey: pubKey, - LatestBlockHash: latestBlockHash, - LatestAppHash: latestAppHash, - LatestBlockHeight: latestHeight, - LatestBlockTime: latestBlockTime, - Syncing: consensusReactor.FastSync(), + NodeInfo: p2pSwitch.NodeInfo(), + SyncInfo: ctypes.SyncInfo{ + LatestBlockHash: latestBlockHash, + LatestAppHash: latestAppHash, + LatestBlockHeight: latestHeight, + LatestBlockTime: latestBlockTime, + Syncing: consensusReactor.FastSync(), + }, + ValidatorInfo: ctypes.ValidatorInfo{PubKey: pubKey}, } // add ValidatorStatus if node is a validator if val := validatorAtHeight(latestHeight); val != nil { - result.ValidatorStatus = ctypes.ValidatorStatus{ - VotingPower: val.VotingPower, - } + result.ValidatorInfo.VotingPower = val.VotingPower } return result, nil diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 729f64c06..82bfceaa7 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -54,19 +54,23 @@ func NewResultCommit(header *types.Header, commit *types.Commit, } } -type ValidatorStatus struct { - VotingPower int64 `json:"voting_power"` +type SyncInfo struct { + LatestBlockHash cmn.HexBytes `json:"latest_block_hash"` + LatestAppHash cmn.HexBytes `json:"latest_app_hash"` + LatestBlockHeight int64 `json:"latest_block_height"` + LatestBlockTime time.Time `json:"latest_block_time"` + Syncing bool `json:"syncing"` +} + +type ValidatorInfo struct { + PubKey crypto.PubKey `json:"pub_key"` + VotingPower int64 `json:"voting_power"` } type ResultStatus struct { - NodeInfo p2p.NodeInfo `json:"node_info"` - PubKey crypto.PubKey `json:"pub_key"` - LatestBlockHash cmn.HexBytes `json:"latest_block_hash"` - LatestAppHash cmn.HexBytes `json:"latest_app_hash"` - LatestBlockHeight int64 `json:"latest_block_height"` - LatestBlockTime time.Time `json:"latest_block_time"` - Syncing bool `json:"syncing"` - ValidatorStatus ValidatorStatus `json:"validator_status,omitempty"` + NodeInfo p2p.NodeInfo `json:"node_info"` + SyncInfo SyncInfo `json:"sync_info"` + ValidatorInfo ValidatorInfo `json:"validator_info"` } func (s *ResultStatus) TxIndexEnabled() bool { diff --git a/test/p2p/atomic_broadcast/test.sh b/test/p2p/atomic_broadcast/test.sh index 3224c0427..267330729 100644 --- a/test/p2p/atomic_broadcast/test.sh +++ b/test/p2p/atomic_broadcast/test.sh @@ -17,7 +17,7 @@ for i in $(seq 1 "$N"); do addr=$(test/p2p/ip.sh "$i"):46657 # current state - HASH1=$(curl -s "$addr/status" | jq .result.latest_app_hash) + HASH1=$(curl -s "$addr/status" | jq .result.sync_info.latest_app_hash) # - send a tx TX=aadeadbeefbeefbeef0$i @@ -26,11 +26,11 @@ for i in $(seq 1 "$N"); do echo "" # we need to wait another block to get the new app_hash - h1=$(curl -s "$addr/status" | jq .result.latest_block_height) + h1=$(curl -s "$addr/status" | jq .result.sync_info.latest_block_height) h2=$h1 while [ "$h2" == "$h1" ]; do sleep 1 - h2=$(curl -s "$addr/status" | jq .result.latest_block_height) + h2=$(curl -s "$addr/status" | jq .result.sync_info.latest_block_height) done # wait for all other peers to get to this height @@ -39,16 +39,16 @@ for i in $(seq 1 "$N"); do if [[ "$i" != "$j" ]]; then addrJ=$(test/p2p/ip.sh "$j"):46657 - h=$(curl -s "$addrJ/status" | jq .result.latest_block_height) + h=$(curl -s "$addrJ/status" | jq .result.sync_info.latest_block_height) while [ "$h" -lt "$minHeight" ]; do sleep 1 - h=$(curl -s "$addrJ/status" | jq .result.latest_block_height) + h=$(curl -s "$addrJ/status" | jq .result.sync_info.latest_block_height) done fi done # check that hash was updated - HASH2=$(curl -s "$addr/status" | jq .result.latest_app_hash) + HASH2=$(curl -s "$addr/status" | jq .result.sync_info.latest_app_hash) if [[ "$HASH1" == "$HASH2" ]]; then echo "Expected state hash to update from $HASH1. Got $HASH2" exit 1 @@ -58,7 +58,7 @@ for i in $(seq 1 "$N"); do for j in $(seq 1 "$N"); do if [[ "$i" != "$j" ]]; then addrJ=$(test/p2p/ip.sh "$j"):46657 - HASH3=$(curl -s "$addrJ/status" | jq .result.latest_app_hash) + HASH3=$(curl -s "$addrJ/status" | jq .result.sync_info.latest_app_hash) if [[ "$HASH2" != "$HASH3" ]]; then echo "App hash for node $j doesn't match. Got $HASH3, expected $HASH2" diff --git a/test/p2p/basic/test.sh b/test/p2p/basic/test.sh index 63df62be2..4876c8c54 100755 --- a/test/p2p/basic/test.sh +++ b/test/p2p/basic/test.sh @@ -54,12 +54,12 @@ for i in `seq 1 $N`; do done # - assert block height is greater than 1 - BLOCK_HEIGHT=`curl -s $addr/status | jq .result.latest_block_height` + BLOCK_HEIGHT=`curl -s $addr/status | jq .result.sync_info.latest_block_height` COUNT=0 while [ "$BLOCK_HEIGHT" -le 1 ]; do echo "Waiting for node $i to commit a block ..." sleep 1 - BLOCK_HEIGHT=`curl -s $addr/status | jq .result.latest_block_height` + BLOCK_HEIGHT=`curl -s $addr/status | jq .result.sync_info.latest_block_height` COUNT=$((COUNT+1)) if [ "$COUNT" -gt "$MAX_SLEEP" ]; then echo "Waited too long for node $i to commit a block" diff --git a/test/p2p/fast_sync/check_peer.sh b/test/p2p/fast_sync/check_peer.sh index b10c3efc5..537a5cfe9 100644 --- a/test/p2p/fast_sync/check_peer.sh +++ b/test/p2p/fast_sync/check_peer.sh @@ -15,10 +15,10 @@ peerID=$(( $(($ID % 4)) + 1 )) # 1->2 ... 3->4 ... 4->1 peer_addr=$(test/p2p/ip.sh $peerID):46657 # get another peer's height -h1=`curl -s $peer_addr/status | jq .result.latest_block_height` +h1=`curl -s $peer_addr/status | jq .result.sync_info.latest_block_height` # get another peer's state -root1=`curl -s $peer_addr/status | jq .result.latest_app_hash` +root1=`curl -s $peer_addr/status | jq .result.sync_info.latest_app_hash` echo "Other peer is on height $h1 with state $root1" echo "Waiting for peer $ID to catch up" @@ -29,12 +29,12 @@ set +o pipefail h2="0" while [[ "$h2" -lt "$(($h1+3))" ]]; do sleep 1 - h2=`curl -s $addr/status | jq .result.latest_block_height` + h2=`curl -s $addr/status | jq .result.sync_info.latest_block_height` echo "... $h2" done # check the app hash -root2=`curl -s $addr/status | jq .result.latest_app_hash` +root2=`curl -s $addr/status | jq .result.sync_info.latest_app_hash` if [[ "$root1" != "$root2" ]]; then echo "App hash after fast sync does not match. Got $root2; expected $root1" diff --git a/test/p2p/kill_all/check_peers.sh b/test/p2p/kill_all/check_peers.sh index 37cd13a42..40d9813bf 100644 --- a/test/p2p/kill_all/check_peers.sh +++ b/test/p2p/kill_all/check_peers.sh @@ -23,7 +23,7 @@ set -e # get the first peer's height addr=$(test/p2p/ip.sh 1):46657 -h1=$(curl -s "$addr/status" | jq .result.latest_block_height) +h1=$(curl -s "$addr/status" | jq .result.sync_info.latest_block_height) echo "1st peer is on height $h1" echo "Waiting until other peers reporting a height higher than the 1st one" @@ -33,7 +33,7 @@ for i in $(seq 2 "$NUM_OF_PEERS"); do while [[ $hi -le $h1 ]] ; do addr=$(test/p2p/ip.sh "$i"):46657 - hi=$(curl -s "$addr/status" | jq .result.latest_block_height) + hi=$(curl -s "$addr/status" | jq .result.sync_info.latest_block_height) echo "... peer $i is on height $hi" diff --git a/test/persist/test_failure_indices.sh b/test/persist/test_failure_indices.sh index 42739107f..dd630e1b7 100644 --- a/test/persist/test_failure_indices.sh +++ b/test/persist/test_failure_indices.sh @@ -31,7 +31,7 @@ function start_procs(){ if [[ "$CIRCLECI" == true ]]; then $TM_CMD & else - $TM_CMD &> "tendermint_${name}.log" & + $TM_CMD &> "tendermint_${name}.log" & fi PID_TENDERMINT=$! else @@ -60,8 +60,8 @@ function wait_for_port() { i=0 while [ "$ERR" == 0 ]; do echo "... port $port is still bound. waiting ..." - sleep 1 - nc -z 127.0.0.1 $port + sleep 1 + nc -z 127.0.0.1 $port ERR=$? i=$((i + 1)) if [[ $i == 10 ]]; then @@ -97,7 +97,7 @@ for failIndex in $(seq $failsStart $failsEnd); do ERR=$? i=0 while [ "$ERR" != 0 ]; do - sleep 1 + sleep 1 curl -s --unix-socket "$RPC_ADDR" http://localhost/status > /dev/null ERR=$? i=$((i + 1)) @@ -108,11 +108,11 @@ for failIndex in $(seq $failsStart $failsEnd); do done # wait for a new block - h1=$(curl -s --unix-socket "$RPC_ADDR" http://localhost/status | jq .result.latest_block_height) + h1=$(curl -s --unix-socket "$RPC_ADDR" http://localhost/status | jq .result.sync_info.latest_block_height) h2=$h1 while [ "$h2" == "$h1" ]; do sleep 1 - h2=$(curl -s --unix-socket "$RPC_ADDR" http://localhost/status | jq .result.latest_block_height) + h2=$(curl -s --unix-socket "$RPC_ADDR" http://localhost/status | jq .result.sync_info.latest_block_height) done kill_procs diff --git a/test/persist/test_simple.sh b/test/persist/test_simple.sh index be7852598..171ab747d 100644 --- a/test/persist/test_simple.sh +++ b/test/persist/test_simple.sh @@ -46,7 +46,7 @@ curl -s $addr/status > /dev/null ERR=$? i=0 while [ "$ERR" != 0 ]; do - sleep 1 + sleep 1 curl -s $addr/status > /dev/null ERR=$? i=$(($i + 1)) @@ -57,11 +57,11 @@ while [ "$ERR" != 0 ]; do done # wait for a new block -h1=`curl -s $addr/status | jq .result.latest_block_height` +h1=`curl -s $addr/status | jq .result.sync_info.latest_block_height` h2=$h1 while [ "$h2" == "$h1" ]; do sleep 1 - h2=`curl -s $addr/status | jq .result.latest_block_height` + h2=`curl -s $addr/status | jq .result.sync_info.latest_block_height` done kill_procs