extract some of the consensus types into ./types

so they can be used in rpc/core/types/responses.go.

```
So, it seems like we could use the actual structs here, but we don't want to have to import consensus to get them, as then clients are importing too much crap. So probably we should move some types from consensus into consensus/types so we can import.

Will these raw messages be identical to:

type ResultDumpConsensusState struct {
  RoundState cstypes.RoundState
  PeerRoundStates map[string]cstypes.PeerRoundState
}
```
https://github.com/tendermint/tendermint/pull/724#discussion_r143598193
This commit is contained in:
Anton Kaliaev
2017-10-10 12:39:21 +04:00
parent d6a87d3c43
commit dc0e8de9b0
11 changed files with 283 additions and 271 deletions

View File

@ -1,13 +1,10 @@
package core
import (
"encoding/json"
cm "github.com/tendermint/tendermint/consensus"
cstypes "github.com/tendermint/tendermint/consensus/types"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
"github.com/pkg/errors"
)
// Get the validator set at the given block height.
@ -85,22 +82,12 @@ func Validators(heightPtr *int) (*ctypes.ResultValidators, error) {
// }
// ```
func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
roundStateBytes, err := json.Marshal(consensusState.GetRoundState())
if err != nil {
return nil, errors.Wrap(err, "failed to marshal round state")
}
peerRoundStates := make(map[string]json.RawMessage)
for i, peer := range p2pSwitch.Peers().List() {
peerRoundStates := make(map[string]*cstypes.PeerRoundState)
for _, peer := range p2pSwitch.Peers().List() {
// TODO: clean this up?
peerState := peer.Get(types.PeerStateKey).(*cm.PeerState)
peerRoundState := peerState.GetRoundState()
peerRoundStateBytes, err := json.Marshal(peerRoundState)
if err != nil {
return nil, errors.Wrapf(err, "failed to marshal peer#%d round state", i)
}
peerRoundStates[peer.Key()] = json.RawMessage(peerRoundStateBytes)
peerRoundStates[peer.Key()] = peerRoundState
}
return &ctypes.ResultDumpConsensusState{json.RawMessage(roundStateBytes), peerRoundStates}, nil
return &ctypes.ResultDumpConsensusState{consensusState.GetRoundState(), peerRoundStates}, nil
}