From f33da8817a20bcdb29115fb989f476d9f80e54f2 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Fri, 27 Apr 2018 23:00:09 -0400 Subject: [PATCH] rpc: lower_case peer_round_states, use a list, add the node_address --- consensus/state.go | 1 + consensus/types/peer_round_state.go | 30 ++++++++++++++--------------- rpc/core/consensus.go | 14 ++++++++------ rpc/core/types/responses.go | 9 +++++++-- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index bd069f70c..40b8f16d5 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -990,6 +990,7 @@ func (cs *ConsensusState) enterPrecommit(height int64, round int) { cs.newStep() }() + // check for a polka blockID, ok := cs.Votes.Prevotes(round).TwoThirdsMajority() // If we don't have a polka, we must precommit nil diff --git a/consensus/types/peer_round_state.go b/consensus/types/peer_round_state.go index 7dfeed923..dcb6c8e02 100644 --- a/consensus/types/peer_round_state.go +++ b/consensus/types/peer_round_state.go @@ -13,21 +13,21 @@ import ( // PeerRoundState contains the known state of a peer. // NOTE: Read-only when returned by PeerState.GetRoundState(). type PeerRoundState struct { - Height int64 // Height peer is at - Round int // Round peer is at, -1 if unknown. - Step RoundStepType // Step peer is at - StartTime time.Time // Estimated start of round 0 at this height - Proposal bool // True if peer has proposal for this round - ProposalBlockPartsHeader types.PartSetHeader // - ProposalBlockParts *cmn.BitArray // - ProposalPOLRound int // Proposal's POL round. -1 if none. - ProposalPOL *cmn.BitArray // nil until ProposalPOLMessage received. - Prevotes *cmn.BitArray // All votes peer has for this round - Precommits *cmn.BitArray // All precommits peer has for this round - LastCommitRound int // Round of commit for last height. -1 if none. - LastCommit *cmn.BitArray // All commit precommits of commit for last height. - CatchupCommitRound int // Round that we have commit for. Not necessarily unique. -1 if none. - CatchupCommit *cmn.BitArray // All commit precommits peer has for this height & CatchupCommitRound + Height int64 `json:"height"` // Height peer is at + Round int `json:"round"` // Round peer is at, -1 if unknown. + Step RoundStepType `json:"step"` // Step peer is at + StartTime time.Time `json:"start_time"` // Estimated start of round 0 at this height + Proposal bool `json:"proposal"` // True if peer has proposal for this round + ProposalBlockPartsHeader types.PartSetHeader `json:"proposal_block_parts_header"` // + ProposalBlockParts *cmn.BitArray `json:"proposal_block_parts"` // + ProposalPOLRound int `json:"proposal_pol_round"` // Proposal's POL round. -1 if none. + ProposalPOL *cmn.BitArray `json:"proposal_pol"` // nil until ProposalPOLMessage received. + Prevotes *cmn.BitArray `json:"prevotes"` // All votes peer has for this round + Precommits *cmn.BitArray `json:"precommits"` // All precommits peer has for this round + LastCommitRound int `json:"last_commit_round"` // Round of commit for last height. -1 if none. + LastCommit *cmn.BitArray `json:"last_commit"` // All commit precommits of commit for last height. + CatchupCommitRound int `json:"catchup_commit_round"` // Round that we have commit for. Not necessarily unique. -1 if none. + CatchupCommit *cmn.BitArray `json:"catchup_commit"` // All commit precommits peer has for this height & CatchupCommitRound } // String returns a string representation of the PeerRoundState diff --git a/rpc/core/consensus.go b/rpc/core/consensus.go index 7647aef7d..191b658f0 100644 --- a/rpc/core/consensus.go +++ b/rpc/core/consensus.go @@ -1,10 +1,8 @@ package core import ( - "encoding/json" - 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" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" @@ -84,14 +82,18 @@ func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) { // } // ``` func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) { - peerRoundStates := make(map[p2p.ID]json.RawMessage) - for _, peer := range p2pSwitch.Peers().List() { + peers := p2pSwitch.Peers().List() + peerRoundStates := make([]ctypes.PeerRoundState, len(peers)) + for i, peer := range peers { peerState := peer.Get(types.PeerStateKey).(*cm.PeerState) peerRoundState, err := peerState.GetRoundStateJSON() if err != nil { 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() if err != nil { diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index ef4d72614..3a60be827 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -113,8 +113,13 @@ type ResultValidators struct { } type ResultDumpConsensusState struct { - RoundState json.RawMessage `json:"round_state"` - PeerRoundStates map[p2p.ID]json.RawMessage `json:"peer_round_states"` + RoundState json.RawMessage `json:"round_state"` + PeerRoundStates []PeerRoundState `json:"peer_round_states"` +} + +type PeerRoundState struct { + NodeAddress string `json:"node_address"` + PeerRoundState json.RawMessage `json:"peer_round_state"` } type ResultBroadcastTx struct {