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.

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