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
This commit is contained in:
Bric3d
2018-04-11 10:38:34 +02:00
committed by Anton Kaliaev
parent 7c22e47629
commit 64879c1e6a
16 changed files with 91 additions and 77 deletions

View File

@ -28,6 +28,8 @@ BUG FIXES:
BREAKING: 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 Upgrade from go-wire to go-amino. This is a sweeping change that breaks everything that is
serialized to disk or over the network. serialized to disk or over the network.

View File

@ -26,10 +26,14 @@ func BenchmarkEncodeStatusWire(b *testing.B) {
Version: "SOMEVER", Version: "SOMEVER",
Other: []string{"SOMESTRING", "OTHERSTRING"}, Other: []string{"SOMESTRING", "OTHERSTRING"},
}, },
PubKey: nodeKey.PubKey(), SyncInfo: ctypes.SyncInfo{
LatestBlockHash: []byte("SOMEBYTES"), LatestBlockHash: []byte("SOMEBYTES"),
LatestBlockHeight: 123, LatestBlockHeight: 123,
LatestBlockTime: time.Unix(0, 1234), LatestBlockTime: time.Unix(0, 1234),
},
ValidatorInfo: ctypes.ValidatorInfo{
PubKey: nodeKey.PubKey(),
},
} }
b.StartTimer() b.StartTimer()

View File

@ -83,11 +83,11 @@ We can see the chain's status at the ``/status`` end-point:
curl http://localhost:46657/status | jsonpp 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 Visit http://localhost:46657 in your browser to see the list of other
endpoints. Some take no arguments (like ``/status``), while others endpoints. Some take no arguments (like ``/status``), while others

View File

@ -93,7 +93,7 @@ func (p *provider) GetLatestCommit() (*ctypes.ResultCommit, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return p.node.Commit(&status.LatestBlockHeight) return p.node.Commit(&status.SyncInfo.LatestBlockHeight)
} }
// CommitFromResult ... // CommitFromResult ...

View File

@ -41,7 +41,7 @@ func WaitForHeight(c StatusClient, h int64, waiter Waiter) error {
if err != nil { if err != nil {
return err return err
} }
delta = h - s.LatestBlockHeight delta = h - s.SyncInfo.LatestBlockHeight
// wait for the time, or abort early // wait for the time, or abort early
if err := waiter(delta); err != nil { if err := waiter(delta); err != nil {
return err return err

View File

@ -32,7 +32,7 @@ func TestWaitForHeight(t *testing.T) {
// now set current block height to 10 // now set current block height to 10
m.Call = mock.Call{ 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 // 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 // we use the callback to update the status height
myWaiter := func(delta int64) error { myWaiter := func(delta int64) error {
// update the height for the next call // 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) return client.DefaultWaitStrategy(delta)
} }
@ -66,11 +66,11 @@ func TestWaitForHeight(t *testing.T) {
require.Nil(pre.Error) require.Nil(pre.Error)
prer, ok := pre.Response.(*ctypes.ResultStatus) prer, ok := pre.Response.(*ctypes.ResultStatus)
require.True(ok) require.True(ok)
assert.Equal(int64(10), prer.LatestBlockHeight) assert.Equal(int64(10), prer.SyncInfo.LatestBlockHeight)
post := r.Calls[4] post := r.Calls[4]
require.Nil(post.Error) require.Nil(post.Error)
postr, ok := post.Response.(*ctypes.ResultStatus) postr, ok := post.Response.(*ctypes.ResultStatus)
require.True(ok) require.True(ok)
assert.Equal(int64(15), postr.LatestBlockHeight) assert.Equal(int64(15), postr.SyncInfo.LatestBlockHeight)
} }

View File

@ -17,9 +17,11 @@ func TestStatus(t *testing.T) {
m := &mock.StatusMock{ m := &mock.StatusMock{
Call: mock.Call{ Call: mock.Call{
Response: &ctypes.ResultStatus{ Response: &ctypes.ResultStatus{
LatestBlockHash: cmn.HexBytes("block"), SyncInfo: ctypes.SyncInfo{
LatestAppHash: cmn.HexBytes("app"), LatestBlockHash: cmn.HexBytes("block"),
LatestBlockHeight: 10, LatestAppHash: cmn.HexBytes("app"),
LatestBlockHeight: 10,
},
}}, }},
} }
@ -29,8 +31,8 @@ func TestStatus(t *testing.T) {
// make sure response works proper // make sure response works proper
status, err := r.Status() status, err := r.Status()
require.Nil(err, "%+v", err) require.Nil(err, "%+v", err)
assert.EqualValues("block", status.LatestBlockHash) assert.EqualValues("block", status.SyncInfo.LatestBlockHash)
assert.EqualValues(10, status.LatestBlockHeight) assert.EqualValues(10, status.SyncInfo.LatestBlockHeight)
// make sure recorder works properly // make sure recorder works properly
require.Equal(1, len(r.Calls)) require.Equal(1, len(r.Calls))
@ -41,6 +43,6 @@ func TestStatus(t *testing.T) {
require.NotNil(rs.Response) require.NotNil(rs.Response)
st, ok := rs.Response.(*ctypes.ResultStatus) st, ok := rs.Response.(*ctypes.ResultStatus)
require.True(ok) require.True(ok)
assert.EqualValues("block", st.LatestBlockHash) assert.EqualValues("block", st.SyncInfo.LatestBlockHash)
assert.EqualValues(10, st.LatestBlockHeight) assert.EqualValues(10, st.SyncInfo.LatestBlockHeight)
} }

View File

@ -50,7 +50,7 @@ func TestInfo(t *testing.T) {
info, err := c.ABCIInfo() info, err := c.ABCIInfo()
require.Nil(t, err, "%d: %+v", i, err) require.Nil(t, err, "%d: %+v", i, err)
// TODO: this is not correct - fix merkleeyes! // 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")) assert.True(t, strings.Contains(info.Response.Data, "size"))
} }
} }
@ -136,7 +136,7 @@ func TestAppCalls(t *testing.T) {
s, err := c.Status() s, err := c.Status()
require.Nil(err, "%d: %+v", i, err) require.Nil(err, "%d: %+v", i, err)
// sh is start height or status height // sh is start height or status height
sh := s.LatestBlockHeight sh := s.SyncInfo.LatestBlockHeight
// look for the future // look for the future
h := sh + 2 h := sh + 2

View File

@ -27,15 +27,20 @@ import (
// ```json // ```json
// { // {
// "result": { // "result": {
// "syncing": false, // "sync_info": {
// "latest_block_time": "2017-12-07T18:19:47.617Z", // "syncing": false,
// "latest_block_height": 6, // "latest_block_time": "2017-12-07T18:19:47.617Z",
// "latest_app_hash": "", // "latest_block_height": 6,
// "latest_block_hash": "A63D0C3307DEDCCFCC82ED411AE9108B70B29E02", // "latest_app_hash": "",
// "pub_key": { // "latest_block_hash": "A63D0C3307DEDCCFCC82ED411AE9108B70B29E02",
// "data": "8C9A68070CBE33F9C445862BA1E9D96A75CEB68C0CF6ADD3652D07DCAC5D0380", // }
// "type": "ed25519" // "validator_info": {
// }, // "pub_key": {
// "data": "8C9A68070CBE33F9C445862BA1E9D96A75CEB68C0CF6ADD3652D07DCAC5D0380",
// "type": "ed25519"
// },
// "voting_power": 10
// }
// "node_info": { // "node_info": {
// "other": [ // "other": [
// "wire_version=0.7.2", // "wire_version=0.7.2",
@ -51,9 +56,6 @@ import (
// "network": "test-chain-qhVCa2", // "network": "test-chain-qhVCa2",
// "moniker": "vagrant-ubuntu-trusty-64", // "moniker": "vagrant-ubuntu-trusty-64",
// "pub_key": "844981FE99ABB19F7816F2D5E94E8A74276AB1153760A7799E925C75401856C6", // "pub_key": "844981FE99ABB19F7816F2D5E94E8A74276AB1153760A7799E925C75401856C6",
// "validator_status": {
// "voting_power": 10
// }
// } // }
// }, // },
// "id": "", // "id": "",
@ -78,20 +80,20 @@ func Status() (*ctypes.ResultStatus, error) {
latestBlockTime := time.Unix(0, latestBlockTimeNano) latestBlockTime := time.Unix(0, latestBlockTimeNano)
result := &ctypes.ResultStatus{ result := &ctypes.ResultStatus{
NodeInfo: p2pSwitch.NodeInfo(), NodeInfo: p2pSwitch.NodeInfo(),
PubKey: pubKey, SyncInfo: ctypes.SyncInfo{
LatestBlockHash: latestBlockHash, LatestBlockHash: latestBlockHash,
LatestAppHash: latestAppHash, LatestAppHash: latestAppHash,
LatestBlockHeight: latestHeight, LatestBlockHeight: latestHeight,
LatestBlockTime: latestBlockTime, LatestBlockTime: latestBlockTime,
Syncing: consensusReactor.FastSync(), Syncing: consensusReactor.FastSync(),
},
ValidatorInfo: ctypes.ValidatorInfo{PubKey: pubKey},
} }
// add ValidatorStatus if node is a validator // add ValidatorStatus if node is a validator
if val := validatorAtHeight(latestHeight); val != nil { if val := validatorAtHeight(latestHeight); val != nil {
result.ValidatorStatus = ctypes.ValidatorStatus{ result.ValidatorInfo.VotingPower = val.VotingPower
VotingPower: val.VotingPower,
}
} }
return result, nil return result, nil

View File

@ -54,19 +54,23 @@ func NewResultCommit(header *types.Header, commit *types.Commit,
} }
} }
type ValidatorStatus struct { type SyncInfo struct {
VotingPower int64 `json:"voting_power"` 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 { type ResultStatus struct {
NodeInfo p2p.NodeInfo `json:"node_info"` NodeInfo p2p.NodeInfo `json:"node_info"`
PubKey crypto.PubKey `json:"pub_key"` SyncInfo SyncInfo `json:"sync_info"`
LatestBlockHash cmn.HexBytes `json:"latest_block_hash"` ValidatorInfo ValidatorInfo `json:"validator_info"`
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"`
} }
func (s *ResultStatus) TxIndexEnabled() bool { func (s *ResultStatus) TxIndexEnabled() bool {

View File

@ -17,7 +17,7 @@ for i in $(seq 1 "$N"); do
addr=$(test/p2p/ip.sh "$i"):46657 addr=$(test/p2p/ip.sh "$i"):46657
# current state # 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 # - send a tx
TX=aadeadbeefbeefbeef0$i TX=aadeadbeefbeefbeef0$i
@ -26,11 +26,11 @@ for i in $(seq 1 "$N"); do
echo "" echo ""
# we need to wait another block to get the new app_hash # 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 h2=$h1
while [ "$h2" == "$h1" ]; do while [ "$h2" == "$h1" ]; do
sleep 1 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 done
# wait for all other peers to get to this height # 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 if [[ "$i" != "$j" ]]; then
addrJ=$(test/p2p/ip.sh "$j"):46657 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 while [ "$h" -lt "$minHeight" ]; do
sleep 1 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 done
fi fi
done done
# check that hash was updated # 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 if [[ "$HASH1" == "$HASH2" ]]; then
echo "Expected state hash to update from $HASH1. Got $HASH2" echo "Expected state hash to update from $HASH1. Got $HASH2"
exit 1 exit 1
@ -58,7 +58,7 @@ for i in $(seq 1 "$N"); do
for j in $(seq 1 "$N"); do for j in $(seq 1 "$N"); do
if [[ "$i" != "$j" ]]; then if [[ "$i" != "$j" ]]; then
addrJ=$(test/p2p/ip.sh "$j"):46657 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 if [[ "$HASH2" != "$HASH3" ]]; then
echo "App hash for node $j doesn't match. Got $HASH3, expected $HASH2" echo "App hash for node $j doesn't match. Got $HASH3, expected $HASH2"

View File

@ -54,12 +54,12 @@ for i in `seq 1 $N`; do
done done
# - assert block height is greater than 1 # - 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 COUNT=0
while [ "$BLOCK_HEIGHT" -le 1 ]; do while [ "$BLOCK_HEIGHT" -le 1 ]; do
echo "Waiting for node $i to commit a block ..." echo "Waiting for node $i to commit a block ..."
sleep 1 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)) COUNT=$((COUNT+1))
if [ "$COUNT" -gt "$MAX_SLEEP" ]; then if [ "$COUNT" -gt "$MAX_SLEEP" ]; then
echo "Waited too long for node $i to commit a block" echo "Waited too long for node $i to commit a block"

View File

@ -15,10 +15,10 @@ peerID=$(( $(($ID % 4)) + 1 )) # 1->2 ... 3->4 ... 4->1
peer_addr=$(test/p2p/ip.sh $peerID):46657 peer_addr=$(test/p2p/ip.sh $peerID):46657
# get another peer's height # 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 # 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 "Other peer is on height $h1 with state $root1"
echo "Waiting for peer $ID to catch up" echo "Waiting for peer $ID to catch up"
@ -29,12 +29,12 @@ set +o pipefail
h2="0" h2="0"
while [[ "$h2" -lt "$(($h1+3))" ]]; do while [[ "$h2" -lt "$(($h1+3))" ]]; do
sleep 1 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" echo "... $h2"
done done
# check the app hash # 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 if [[ "$root1" != "$root2" ]]; then
echo "App hash after fast sync does not match. Got $root2; expected $root1" echo "App hash after fast sync does not match. Got $root2; expected $root1"

View File

@ -23,7 +23,7 @@ set -e
# get the first peer's height # get the first peer's height
addr=$(test/p2p/ip.sh 1):46657 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 "1st peer is on height $h1"
echo "Waiting until other peers reporting a height higher than the 1st one" 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 while [[ $hi -le $h1 ]] ; do
addr=$(test/p2p/ip.sh "$i"):46657 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" echo "... peer $i is on height $hi"

View File

@ -31,7 +31,7 @@ function start_procs(){
if [[ "$CIRCLECI" == true ]]; then if [[ "$CIRCLECI" == true ]]; then
$TM_CMD & $TM_CMD &
else else
$TM_CMD &> "tendermint_${name}.log" & $TM_CMD &> "tendermint_${name}.log" &
fi fi
PID_TENDERMINT=$! PID_TENDERMINT=$!
else else
@ -60,8 +60,8 @@ function wait_for_port() {
i=0 i=0
while [ "$ERR" == 0 ]; do while [ "$ERR" == 0 ]; do
echo "... port $port is still bound. waiting ..." echo "... port $port is still bound. waiting ..."
sleep 1 sleep 1
nc -z 127.0.0.1 $port nc -z 127.0.0.1 $port
ERR=$? ERR=$?
i=$((i + 1)) i=$((i + 1))
if [[ $i == 10 ]]; then if [[ $i == 10 ]]; then
@ -97,7 +97,7 @@ for failIndex in $(seq $failsStart $failsEnd); do
ERR=$? ERR=$?
i=0 i=0
while [ "$ERR" != 0 ]; do while [ "$ERR" != 0 ]; do
sleep 1 sleep 1
curl -s --unix-socket "$RPC_ADDR" http://localhost/status > /dev/null curl -s --unix-socket "$RPC_ADDR" http://localhost/status > /dev/null
ERR=$? ERR=$?
i=$((i + 1)) i=$((i + 1))
@ -108,11 +108,11 @@ for failIndex in $(seq $failsStart $failsEnd); do
done done
# wait for a new block # 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 h2=$h1
while [ "$h2" == "$h1" ]; do while [ "$h2" == "$h1" ]; do
sleep 1 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 done
kill_procs kill_procs

View File

@ -46,7 +46,7 @@ curl -s $addr/status > /dev/null
ERR=$? ERR=$?
i=0 i=0
while [ "$ERR" != 0 ]; do while [ "$ERR" != 0 ]; do
sleep 1 sleep 1
curl -s $addr/status > /dev/null curl -s $addr/status > /dev/null
ERR=$? ERR=$?
i=$(($i + 1)) i=$(($i + 1))
@ -57,11 +57,11 @@ while [ "$ERR" != 0 ]; do
done done
# wait for a new block # 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 h2=$h1
while [ "$h2" == "$h1" ]; do while [ "$h2" == "$h1" ]; do
sleep 1 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 done
kill_procs kill_procs