Browse Source

include validator's voting power in /status

Refs #581
pull/1391/head
Anton Kaliaev 7 years ago
parent
commit
ed782e7508
No known key found for this signature in database GPG Key ID: 7B6881D965918214
4 changed files with 60 additions and 12 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +46
    -3
      rpc/core/status.go
  3. +12
    -7
      rpc/core/types/responses.go
  4. +1
    -2
      types/validator_set.go

+ 1
- 0
CHANGELOG.md View File

@ -32,6 +32,7 @@ BUG FIXES:
IMPROVEMENTS:
- [rpc] `/tx` and `/tx_search` responses now include the transaction hash
- [rpc] include validator power in `/status`
## 0.17.1 (March 27th, 2018)


+ 46
- 3
rpc/core/status.go View File

@ -1,9 +1,11 @@
package core
import (
"bytes"
"time"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
)
@ -48,7 +50,10 @@ import (
// "remote_addr": "",
// "network": "test-chain-qhVCa2",
// "moniker": "vagrant-ubuntu-trusty-64",
// "pub_key": "844981FE99ABB19F7816F2D5E94E8A74276AB1153760A7799E925C75401856C6"
// "pub_key": "844981FE99ABB19F7816F2D5E94E8A74276AB1153760A7799E925C75401856C6",
// "validator_status": {
// "voting_power": 10
// }
// }
// },
// "id": "",
@ -72,12 +77,50 @@ func Status() (*ctypes.ResultStatus, error) {
latestBlockTime := time.Unix(0, latestBlockTimeNano)
return &ctypes.ResultStatus{
result := &ctypes.ResultStatus{
NodeInfo: p2pSwitch.NodeInfo(),
PubKey: pubKey,
LatestBlockHash: latestBlockHash,
LatestAppHash: latestAppHash,
LatestBlockHeight: latestHeight,
LatestBlockTime: latestBlockTime,
Syncing: consensusReactor.FastSync()}, nil
Syncing: consensusReactor.FastSync(),
}
// add ValidatorStatus if node is a validator
if val := validatorAtHeight(latestHeight); val != nil {
result.ValidatorStatus = ctypes.ValidatorStatus{
VotingPower: val.VotingPower,
}
}
return result, nil
}
func validatorAtHeight(h int64) *types.Validator {
lastBlockHeight, vals := consensusState.GetValidators()
privValAddress := pubKey.Address()
// if we're still at height h, search in the current validator set
if lastBlockHeight == h {
for _, val := range vals {
if bytes.Equal(val.Address, privValAddress) {
return val
}
}
}
// if we've moved to the next height, retrieve the validator set from DB
if lastBlockHeight > h {
vals, err := sm.LoadValidators(stateDB, h)
if err != nil {
// should not happen
return nil
}
_, val := vals.GetByAddress(privValAddress)
return val
}
return nil
}

+ 12
- 7
rpc/core/types/responses.go View File

@ -54,14 +54,19 @@ func NewResultCommit(header *types.Header, commit *types.Commit,
}
}
type ValidatorStatus struct {
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"`
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"`
}
func (s *ResultStatus) TxIndexEnabled() bool {


+ 1
- 2
types/validator_set.go View File

@ -100,9 +100,8 @@ func (valSet *ValidatorSet) GetByAddress(address []byte) (index int, val *Valida
})
if idx < len(valSet.Validators) && bytes.Equal(valSet.Validators[idx].Address, address) {
return idx, valSet.Validators[idx].Copy()
} else {
return -1, nil
}
return -1, nil
}
// GetByIndex returns the validator's address and validator itself by index.


Loading…
Cancel
Save