2015-03-26 21:30:42 -07:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2015-11-01 11:34:08 -08:00
|
|
|
"github.com/tendermint/go-wire"
|
2015-04-25 11:49:26 -07:00
|
|
|
cm "github.com/tendermint/tendermint/consensus"
|
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
|
|
|
)
|
|
|
|
|
2016-02-08 00:48:58 -08:00
|
|
|
func Validators() (*ctypes.ResultValidators, error) {
|
2015-06-25 20:28:34 -07:00
|
|
|
var blockHeight int
|
2015-11-01 11:34:08 -08:00
|
|
|
var validators []*types.Validator
|
2015-03-26 21:30:42 -07:00
|
|
|
|
2016-08-09 20:06:19 -04:00
|
|
|
// XXX: this is racy.
|
|
|
|
// Either use state.LoadState(db) or make state atomic (see #165)
|
2015-03-26 21:30:42 -07:00
|
|
|
state := consensusState.GetState()
|
|
|
|
blockHeight = state.LastBlockHeight
|
2015-11-01 11:34:08 -08:00
|
|
|
state.Validators.Iterate(func(index int, val *types.Validator) bool {
|
|
|
|
validators = append(validators, val)
|
2015-03-26 21:30:42 -07:00
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
2016-02-08 00:48:58 -08:00
|
|
|
return &ctypes.ResultValidators{blockHeight, validators}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
2015-04-20 20:39:42 -07:00
|
|
|
|
2015-08-10 20:38:45 -07:00
|
|
|
func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
|
2015-04-25 11:49:26 -07:00
|
|
|
roundState := consensusState.GetRoundState()
|
|
|
|
peerRoundStates := []string{}
|
|
|
|
for _, peer := range p2pSwitch.Peers().List() {
|
|
|
|
// TODO: clean this up?
|
2015-09-25 12:55:59 -04:00
|
|
|
peerState := peer.Data.Get(types.PeerStateKey).(*cm.PeerState)
|
2015-04-25 11:49:26 -07:00
|
|
|
peerRoundState := peerState.GetRoundState()
|
2015-07-25 15:45:45 -07:00
|
|
|
peerRoundStateStr := peer.Key + ":" + string(wire.JSONBytes(peerRoundState))
|
2015-04-25 11:49:26 -07:00
|
|
|
peerRoundStates = append(peerRoundStates, peerRoundStateStr)
|
|
|
|
}
|
2015-08-10 20:38:45 -07:00
|
|
|
return &ctypes.ResultDumpConsensusState{roundState.String(), peerRoundStates}, nil
|
2015-04-20 20:39:42 -07:00
|
|
|
}
|