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"
|
2017-10-10 01:39:21 -07:00
|
|
|
cstypes "github.com/tendermint/tendermint/consensus/types"
|
2015-04-07 11:44:25 -07:00
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2015-08-10 20:38:45 -07:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2015-03-26 21:30:42 -07:00
|
|
|
)
|
|
|
|
|
2017-09-04 15:27:04 -07:00
|
|
|
// Get the validator set at the given block height.
|
2017-08-21 15:11:16 -07:00
|
|
|
// If no height is provided, it will fetch the current validator set.
|
2017-06-01 06:09:30 -07: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-08-22 14:42:23 -07:00
|
|
|
func Validators(heightPtr *int) (*ctypes.ResultValidators, error) {
|
|
|
|
if heightPtr == nil {
|
2017-08-21 15:11:16 -07:00
|
|
|
blockHeight, validators := consensusState.GetValidators()
|
|
|
|
return &ctypes.ResultValidators{blockHeight, validators}, nil
|
|
|
|
}
|
2017-08-22 14:42:23 -07:00
|
|
|
|
|
|
|
height := *heightPtr
|
2017-08-21 15:11:16 -07:00
|
|
|
state := consensusState.GetState()
|
2017-08-22 14:42:23 -07:00
|
|
|
validators, err := state.LoadValidators(height)
|
2017-08-21 15:11:16 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-08-22 14:42:23 -07:00
|
|
|
return &ctypes.ResultValidators{height, validators.Validators}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
2015-04-20 20:39:42 -07:00
|
|
|
|
2017-06-01 06:09:30 -07:00
|
|
|
// Dump consensus state.
|
|
|
|
//
|
|
|
|
// ```shell
|
|
|
|
// curl 'localhost:46657/dump_consensus_state'
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// ```go
|
|
|
|
// client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
|
|
|
|
// state, err := client.DumpConsensusState()
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// > The above command returns JSON structured like this:
|
|
|
|
//
|
|
|
|
// ```json
|
|
|
|
// {
|
|
|
|
// "error": "",
|
|
|
|
// "result": {
|
|
|
|
// "peer_round_states": [],
|
|
|
|
// "round_state": "RoundState{\n H:3537 R:0 S:RoundStepNewHeight\n StartTime: 2017-05-31 12:32:31.178653883 +0000 UTC\n CommitTime: 2017-05-31 12:32:30.178653883 +0000 UTC\n Validators: ValidatorSet{\n Proposer: Validator{E89A51D60F68385E09E716D353373B11F8FACD62 {PubKeyEd25519{68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D}} VP:10 A:0}\n Validators:\n Validator{E89A51D60F68385E09E716D353373B11F8FACD62 {PubKeyEd25519{68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D}} VP:10 A:0}\n }\n Proposal: <nil>\n ProposalBlock: nil-PartSet nil-Block\n LockedRound: 0\n LockedBlock: nil-PartSet nil-Block\n Votes: HeightVoteSet{H:3537 R:0~0\n VoteSet{H:3537 R:0 T:1 +2/3:<nil> BA{1:_} map[]}\n VoteSet{H:3537 R:0 T:2 +2/3:<nil> BA{1:_} map[]}\n }\n LastCommit: VoteSet{H:3536 R:0 T:2 +2/3:B7F988FBCDC68F9320E346EECAA76E32F6054654:1:673BE7C01F74 BA{1:X} map[]}\n LastValidators: ValidatorSet{\n Proposer: Validator{E89A51D60F68385E09E716D353373B11F8FACD62 {PubKeyEd25519{68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D}} VP:10 A:0}\n Validators:\n Validator{E89A51D60F68385E09E716D353373B11F8FACD62 {PubKeyEd25519{68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D}} VP:10 A:0}\n }\n}"
|
|
|
|
// },
|
|
|
|
// "id": "",
|
|
|
|
// "jsonrpc": "2.0"
|
|
|
|
// }
|
|
|
|
// ```
|
2015-08-10 20:38:45 -07:00
|
|
|
func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
|
2017-10-10 01:39:21 -07:00
|
|
|
peerRoundStates := make(map[string]*cstypes.PeerRoundState)
|
|
|
|
for _, peer := range p2pSwitch.Peers().List() {
|
2017-09-12 17:49:22 -07:00
|
|
|
peerState := peer.Get(types.PeerStateKey).(*cm.PeerState)
|
2015-04-25 11:49:26 -07:00
|
|
|
peerRoundState := peerState.GetRoundState()
|
2017-10-10 01:39:21 -07:00
|
|
|
peerRoundStates[peer.Key()] = peerRoundState
|
2015-04-25 11:49:26 -07:00
|
|
|
}
|
2017-10-10 01:39:21 -07:00
|
|
|
return &ctypes.ResultDumpConsensusState{consensusState.GetRoundState(), peerRoundStates}, nil
|
2015-04-20 20:39:42 -07:00
|
|
|
}
|