2015-03-26 21:30:42 -07:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2015-04-25 11:49:26 -07:00
|
|
|
cm "github.com/tendermint/tendermint/consensus"
|
2018-04-27 23:00:09 -04:00
|
|
|
"github.com/tendermint/tendermint/p2p"
|
2015-04-07 11:44:25 -07:00
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2017-12-27 14:27:37 -05:00
|
|
|
sm "github.com/tendermint/tendermint/state"
|
2015-08-10 20:38:45 -07:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2015-03-26 21:30:42 -07:00
|
|
|
)
|
|
|
|
|
2017-09-04 18:27:04 -04:00
|
|
|
// Get the validator set at the given block height.
|
2017-08-21 18:11:16 -04:00
|
|
|
// If no height is provided, it will fetch the current validator set.
|
2017-06-01 16:09:30 +03:00
|
|
|
//
|
|
|
|
// ```shell
|
|
|
|
// curl 'localhost:46657/validators'
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// ```go
|
|
|
|
// client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
|
|
|
|
// state, err := client.Validators()
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// > The above command returns JSON structured like this:
|
|
|
|
//
|
|
|
|
// ```json
|
|
|
|
// {
|
|
|
|
// "error": "",
|
|
|
|
// "result": {
|
|
|
|
// "validators": [
|
|
|
|
// {
|
|
|
|
// "accum": 0,
|
|
|
|
// "voting_power": 10,
|
|
|
|
// "pub_key": {
|
|
|
|
// "data": "68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D",
|
|
|
|
// "type": "ed25519"
|
|
|
|
// },
|
|
|
|
// "address": "E89A51D60F68385E09E716D353373B11F8FACD62"
|
|
|
|
// }
|
|
|
|
// ],
|
|
|
|
// "block_height": 5241
|
|
|
|
// },
|
|
|
|
// "id": "",
|
|
|
|
// "jsonrpc": "2.0"
|
|
|
|
// }
|
|
|
|
// ```
|
2017-12-01 19:04:53 -06:00
|
|
|
func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
|
2017-12-26 20:08:25 -05:00
|
|
|
storeHeight := blockStore.Height()
|
|
|
|
height, err := getHeight(storeHeight, heightPtr)
|
2017-12-26 19:37:42 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-08-21 18:11:16 -04:00
|
|
|
}
|
2017-08-22 17:42:23 -04:00
|
|
|
|
2017-12-27 22:09:48 -05:00
|
|
|
validators, err := sm.LoadValidators(stateDB, height)
|
2017-08-21 18:11:16 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-08-22 17:42:23 -04:00
|
|
|
return &ctypes.ResultValidators{height, validators.Validators}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
2015-04-20 20:39:42 -07:00
|
|
|
|
2018-04-10 11:15:16 +02:00
|
|
|
// DumpConsensusState dumps consensus state.
|
2018-04-27 23:19:40 -04:00
|
|
|
// UNSTABLE
|
2015-08-10 20:38:45 -07:00
|
|
|
func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
|
2018-04-27 23:00:09 -04:00
|
|
|
peers := p2pSwitch.Peers().List()
|
2018-05-10 22:43:21 -07:00
|
|
|
peerRoundStates := make([]ctypes.PeerRoundStateInfo, len(peers))
|
2018-04-27 23:00:09 -04:00
|
|
|
for i, peer := range peers {
|
2017-09-12 20:49:22 -04:00
|
|
|
peerState := peer.Get(types.PeerStateKey).(*cm.PeerState)
|
2018-04-10 11:15:16 +02:00
|
|
|
peerRoundState, err := peerState.GetRoundStateJSON()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-05-10 22:43:21 -07:00
|
|
|
peerRoundStates[i] = ctypes.PeerRoundStateInfo{
|
2018-04-27 23:00:09 -04:00
|
|
|
NodeAddress: p2p.IDAddressString(peer.ID(), peer.NodeInfo().ListenAddr),
|
|
|
|
PeerRoundState: peerRoundState,
|
|
|
|
}
|
2015-04-25 11:49:26 -07:00
|
|
|
}
|
2018-04-10 11:15:16 +02:00
|
|
|
roundState, err := consensusState.GetRoundStateJSON()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &ctypes.ResultDumpConsensusState{roundState, peerRoundStates}, nil
|
2015-04-20 20:39:42 -07:00
|
|
|
}
|