mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 04:41:22 +00:00
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:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user