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.

37 lines
1.2 KiB

8 years ago
  1. package core
  2. import (
  3. "github.com/tendermint/go-wire"
  4. cm "github.com/tendermint/tendermint/consensus"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. func Validators() (*ctypes.ResultValidators, error) {
  9. var blockHeight int
  10. var validators []*types.Validator
  11. // XXX: this is racy.
  12. // Either use state.LoadState(db) or make state atomic (see #165)
  13. state := consensusState.GetState()
  14. blockHeight = state.LastBlockHeight
  15. state.Validators.Iterate(func(index int, val *types.Validator) bool {
  16. validators = append(validators, val)
  17. return false
  18. })
  19. return &ctypes.ResultValidators{blockHeight, validators}, nil
  20. }
  21. func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
  22. roundState := consensusState.GetRoundState()
  23. peerRoundStates := []string{}
  24. for _, peer := range p2pSwitch.Peers().List() {
  25. // TODO: clean this up?
  26. peerState := peer.Data.Get(types.PeerStateKey).(*cm.PeerState)
  27. peerRoundState := peerState.GetRoundState()
  28. peerRoundStateStr := peer.Key + ":" + string(wire.JSONBytes(peerRoundState))
  29. peerRoundStates = append(peerRoundStates, peerRoundStateStr)
  30. }
  31. return &ctypes.ResultDumpConsensusState{roundState.String(), peerRoundStates}, nil
  32. }