You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.6 KiB

7 years ago
  1. package core
  2. import (
  3. cm "github.com/tendermint/tendermint/consensus"
  4. cstypes "github.com/tendermint/tendermint/consensus/types"
  5. p2p "github.com/tendermint/tendermint/p2p"
  6. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  7. sm "github.com/tendermint/tendermint/state"
  8. "github.com/tendermint/tendermint/types"
  9. )
  10. // Get the validator set at the given block height.
  11. // If no height is provided, it will fetch the current validator set.
  12. //
  13. // ```shell
  14. // curl 'localhost:46657/validators'
  15. // ```
  16. //
  17. // ```go
  18. // client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
  19. // state, err := client.Validators()
  20. // ```
  21. //
  22. // > The above command returns JSON structured like this:
  23. //
  24. // ```json
  25. // {
  26. // "error": "",
  27. // "result": {
  28. // "validators": [
  29. // {
  30. // "accum": 0,
  31. // "voting_power": 10,
  32. // "pub_key": {
  33. // "data": "68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D",
  34. // "type": "ed25519"
  35. // },
  36. // "address": "E89A51D60F68385E09E716D353373B11F8FACD62"
  37. // }
  38. // ],
  39. // "block_height": 5241
  40. // },
  41. // "id": "",
  42. // "jsonrpc": "2.0"
  43. // }
  44. // ```
  45. func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
  46. storeHeight := blockStore.Height()
  47. height, err := getHeight(storeHeight, heightPtr)
  48. if err != nil {
  49. return nil, err
  50. }
  51. validators, err := sm.LoadValidators(stateDB, height)
  52. if err != nil {
  53. return nil, err
  54. }
  55. return &ctypes.ResultValidators{height, validators.Validators}, nil
  56. }
  57. // Dump consensus state.
  58. //
  59. // ```shell
  60. // curl 'localhost:46657/dump_consensus_state'
  61. // ```
  62. //
  63. // ```go
  64. // client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
  65. // state, err := client.DumpConsensusState()
  66. // ```
  67. //
  68. // > The above command returns JSON structured like this:
  69. //
  70. // ```json
  71. // {
  72. // "error": "",
  73. // "result": {
  74. // "peer_round_states": [],
  75. // "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}"
  76. // },
  77. // "id": "",
  78. // "jsonrpc": "2.0"
  79. // }
  80. // ```
  81. func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
  82. peerRoundStates := make(map[p2p.ID]*cstypes.PeerRoundState)
  83. for _, peer := range p2pSwitch.Peers().List() {
  84. peerState := peer.Get(types.PeerStateKey).(*cm.PeerState)
  85. peerRoundState := peerState.GetRoundState()
  86. peerRoundStates[peer.ID()] = peerRoundState
  87. }
  88. return &ctypes.ResultDumpConsensusState{consensusState.GetRoundState(), peerRoundStates}, nil
  89. }