rpc: lower_case peer_round_states, use a list, add the node_address

This commit is contained in:
Ethan Buchman
2018-04-27 23:00:09 -04:00
parent ffe81a0206
commit f33da8817a
4 changed files with 31 additions and 23 deletions

View File

@ -990,6 +990,7 @@ func (cs *ConsensusState) enterPrecommit(height int64, round int) {
cs.newStep() cs.newStep()
}() }()
// check for a polka
blockID, ok := cs.Votes.Prevotes(round).TwoThirdsMajority() blockID, ok := cs.Votes.Prevotes(round).TwoThirdsMajority()
// If we don't have a polka, we must precommit nil // If we don't have a polka, we must precommit nil

View File

@ -13,21 +13,21 @@ import (
// PeerRoundState contains the known state of a peer. // PeerRoundState contains the known state of a peer.
// NOTE: Read-only when returned by PeerState.GetRoundState(). // NOTE: Read-only when returned by PeerState.GetRoundState().
type PeerRoundState struct { type PeerRoundState struct {
Height int64 // Height peer is at Height int64 `json:"height"` // Height peer is at
Round int // Round peer is at, -1 if unknown. Round int `json:"round"` // Round peer is at, -1 if unknown.
Step RoundStepType // Step peer is at Step RoundStepType `json:"step"` // Step peer is at
StartTime time.Time // Estimated start of round 0 at this height StartTime time.Time `json:"start_time"` // Estimated start of round 0 at this height
Proposal bool // True if peer has proposal for this round Proposal bool `json:"proposal"` // True if peer has proposal for this round
ProposalBlockPartsHeader types.PartSetHeader // ProposalBlockPartsHeader types.PartSetHeader `json:"proposal_block_parts_header"` //
ProposalBlockParts *cmn.BitArray // ProposalBlockParts *cmn.BitArray `json:"proposal_block_parts"` //
ProposalPOLRound int // Proposal's POL round. -1 if none. ProposalPOLRound int `json:"proposal_pol_round"` // Proposal's POL round. -1 if none.
ProposalPOL *cmn.BitArray // nil until ProposalPOLMessage received. ProposalPOL *cmn.BitArray `json:"proposal_pol"` // nil until ProposalPOLMessage received.
Prevotes *cmn.BitArray // All votes peer has for this round Prevotes *cmn.BitArray `json:"prevotes"` // All votes peer has for this round
Precommits *cmn.BitArray // All precommits peer has for this round Precommits *cmn.BitArray `json:"precommits"` // All precommits peer has for this round
LastCommitRound int // Round of commit for last height. -1 if none. LastCommitRound int `json:"last_commit_round"` // Round of commit for last height. -1 if none.
LastCommit *cmn.BitArray // All commit precommits of commit for last height. LastCommit *cmn.BitArray `json:"last_commit"` // All commit precommits of commit for last height.
CatchupCommitRound int // Round that we have commit for. Not necessarily unique. -1 if none. CatchupCommitRound int `json:"catchup_commit_round"` // Round that we have commit for. Not necessarily unique. -1 if none.
CatchupCommit *cmn.BitArray // All commit precommits peer has for this height & CatchupCommitRound CatchupCommit *cmn.BitArray `json:"catchup_commit"` // All commit precommits peer has for this height & CatchupCommitRound
} }
// String returns a string representation of the PeerRoundState // String returns a string representation of the PeerRoundState

View File

@ -1,10 +1,8 @@
package core package core
import ( import (
"encoding/json"
cm "github.com/tendermint/tendermint/consensus" cm "github.com/tendermint/tendermint/consensus"
p2p "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -84,14 +82,18 @@ func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
// } // }
// ``` // ```
func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) { func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
peerRoundStates := make(map[p2p.ID]json.RawMessage) peers := p2pSwitch.Peers().List()
for _, peer := range p2pSwitch.Peers().List() { peerRoundStates := make([]ctypes.PeerRoundState, len(peers))
for i, peer := range peers {
peerState := peer.Get(types.PeerStateKey).(*cm.PeerState) peerState := peer.Get(types.PeerStateKey).(*cm.PeerState)
peerRoundState, err := peerState.GetRoundStateJSON() peerRoundState, err := peerState.GetRoundStateJSON()
if err != nil { if err != nil {
return nil, err return nil, err
} }
peerRoundStates[peer.ID()] = peerRoundState peerRoundStates[i] = ctypes.PeerRoundState{
NodeAddress: p2p.IDAddressString(peer.ID(), peer.NodeInfo().ListenAddr),
PeerRoundState: peerRoundState,
}
} }
roundState, err := consensusState.GetRoundStateJSON() roundState, err := consensusState.GetRoundStateJSON()
if err != nil { if err != nil {

View File

@ -113,8 +113,13 @@ type ResultValidators struct {
} }
type ResultDumpConsensusState struct { type ResultDumpConsensusState struct {
RoundState json.RawMessage `json:"round_state"` RoundState json.RawMessage `json:"round_state"`
PeerRoundStates map[p2p.ID]json.RawMessage `json:"peer_round_states"` PeerRoundStates []PeerRoundState `json:"peer_round_states"`
}
type PeerRoundState struct {
NodeAddress string `json:"node_address"`
PeerRoundState json.RawMessage `json:"peer_round_state"`
} }
type ResultBroadcastTx struct { type ResultBroadcastTx struct {