parent
0732526465
commit
ed782e7508
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -54,6 +54,10 @@ 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"`
|
||||
|
@ -62,6 +66,7 @@ type ResultStatus struct {
|
|||
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 {
|
||||
|
|
|
@ -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…
Reference in New Issue