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:
parent
7c22e47629
commit
64879c1e6a
|
@ -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.
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ...
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue