Expose peer stats for dump_consensus_state

This commit is contained in:
Jae Kwon 2018-05-10 22:43:21 -07:00
parent c0a1a8d3c0
commit edbec10f9e
7 changed files with 67 additions and 169 deletions

12
Gopkg.lock generated
View File

@ -254,8 +254,8 @@
[[projects]]
name = "github.com/tendermint/go-amino"
packages = ["."]
revision = "3668c02a8feace009f80754a5e5a8541e5d7b996"
version = "0.9.8"
revision = "ed62928576cfcaf887209dc96142cd79cdfff389"
version = "0.9.9"
[[projects]]
name = "github.com/tendermint/go-crypto"
@ -285,8 +285,8 @@
"pubsub/query",
"test"
]
revision = "d94e312673e16a11ea55d742cefb3e331228f898"
version = "v0.8.2"
revision = "cc5f287c4798ffe88c04d02df219ecb6932080fd"
version = "v0.8.3-rc0"
[[projects]]
branch = "master"
@ -301,7 +301,7 @@
"ripemd160",
"salsa20/salsa"
]
revision = "b49d69b5da943f7ef3c9cf91c8777c1f78a0cc3c"
revision = "b0697eccbea9adec5b7ba8008f4c33d98d733388"
[[projects]]
branch = "master"
@ -384,6 +384,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "94cb2543199b0f4b6e9ac0e5b6469bdb77391da1c9f79f5b9792d7af936008ff"
inputs-digest = "52a0dcbebdf8714612444914cfce59a3af8c47c4453a2d43c4ccc5ff1a91d8ea"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -79,11 +79,11 @@
[[constraint]]
name = "github.com/tendermint/go-amino"
version = "~0.9.7"
version = "0.9.9"
[[constraint]]
[[override]]
name = "github.com/tendermint/tmlibs"
version = "~0.8.2-rc0"
version = "~0.8.3-rc0"
[[constraint]]
name = "google.golang.org/grpc"

View File

@ -210,7 +210,7 @@ func (conR *ConsensusReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
return
}
// Peer claims to have a maj23 for some BlockID at H,R,S,
err := votes.SetPeerMaj23(msg.Round, msg.Type, ps.Peer.ID(), msg.BlockID)
err := votes.SetPeerMaj23(msg.Round, msg.Type, ps.peer.ID(), msg.BlockID)
if err != nil {
conR.Switch.StopPeerForError(src, err)
return
@ -840,33 +840,34 @@ var (
// PeerState contains the known state of a peer, including its connection and
// threadsafe access to its PeerRoundState.
// NOTE: THIS GETS DUMPED WITH rpc/core/consensus.go.
// Be mindful of what you Expose.
type PeerState struct {
Peer p2p.Peer
peer p2p.Peer
logger log.Logger
mtx sync.Mutex
cstypes.PeerRoundState
stats *peerStateStats
mtx sync.Mutex //
cstypes.PeerRoundState // Exposed.
Stats *peerStateStats //
}
// peerStateStats holds internal statistics for a peer.
type peerStateStats struct {
lastVoteHeight int64
votes int
lastBlockPartHeight int64
blockParts int
LastVoteHeight int64
Votes int
LastBlockPartHeight int64
BlockParts int
}
func (pss peerStateStats) String() string {
return fmt.Sprintf("peerStateStats{votes: %d, blockParts: %d}", pss.votes, pss.blockParts)
return fmt.Sprintf("peerStateStats{lvh: %d, votes: %d, lbph: %d, blockParts: %d}",
pss.LastVoteHeight, pss.Votes, pss.LastBlockPartHeight, pss.BlockParts)
}
// NewPeerState returns a new PeerState for the given Peer
func NewPeerState(peer p2p.Peer) *PeerState {
return &PeerState{
Peer: peer,
peer: peer,
logger: log.NewNopLogger(),
PeerRoundState: cstypes.PeerRoundState{
Round: -1,
@ -874,7 +875,7 @@ func NewPeerState(peer p2p.Peer) *PeerState {
LastCommitRound: -1,
CatchupCommitRound: -1,
},
stats: &peerStateStats{},
Stats: &peerStateStats{},
}
}
@ -961,7 +962,7 @@ func (ps *PeerState) PickSendVote(votes types.VoteSetReader) bool {
if vote, ok := ps.PickVoteToSend(votes); ok {
msg := &VoteMessage{vote}
ps.logger.Debug("Sending vote message", "ps", ps, "vote", vote)
return ps.Peer.Send(VoteChannel, cdc.MustMarshalBinaryBare(msg))
return ps.peer.Send(VoteChannel, cdc.MustMarshalBinaryBare(msg))
}
return false
}
@ -1103,12 +1104,12 @@ func (ps *PeerState) RecordVote(vote *types.Vote) int {
ps.mtx.Lock()
defer ps.mtx.Unlock()
if ps.stats.lastVoteHeight >= vote.Height {
return ps.stats.votes
if ps.Stats.LastVoteHeight >= vote.Height {
return ps.Stats.Votes
}
ps.stats.lastVoteHeight = vote.Height
ps.stats.votes++
return ps.stats.votes
ps.Stats.LastVoteHeight = vote.Height
ps.Stats.Votes++
return ps.Stats.Votes
}
// VotesSent returns the number of blocks for which peer has been sending us
@ -1117,7 +1118,7 @@ func (ps *PeerState) VotesSent() int {
ps.mtx.Lock()
defer ps.mtx.Unlock()
return ps.stats.votes
return ps.Stats.Votes
}
// RecordBlockPart updates internal statistics for this peer by recording the
@ -1128,13 +1129,13 @@ func (ps *PeerState) RecordBlockPart(bp *BlockPartMessage) int {
ps.mtx.Lock()
defer ps.mtx.Unlock()
if ps.stats.lastBlockPartHeight >= bp.Height {
return ps.stats.blockParts
if ps.Stats.LastBlockPartHeight >= bp.Height {
return ps.Stats.BlockParts
}
ps.stats.lastBlockPartHeight = bp.Height
ps.stats.blockParts++
return ps.stats.blockParts
ps.Stats.LastBlockPartHeight = bp.Height
ps.Stats.BlockParts++
return ps.Stats.BlockParts
}
// BlockPartsSent returns the number of blocks for which peer has been sending
@ -1143,7 +1144,7 @@ func (ps *PeerState) BlockPartsSent() int {
ps.mtx.Lock()
defer ps.mtx.Unlock()
return ps.stats.blockParts
return ps.Stats.BlockParts
}
// SetHasVote sets the given vote as known by the peer
@ -1292,13 +1293,13 @@ func (ps *PeerState) StringIndented(indent string) string {
ps.mtx.Lock()
defer ps.mtx.Unlock()
return fmt.Sprintf(`PeerState{
%s Key %v
%s PRS %v
%s Stats %v
%s Key %v
%s RoundState %v
%s Stats %v
%s}`,
indent, ps.Peer.ID(),
indent, ps.peer.ID(),
indent, ps.PeerRoundState.StringIndented(indent+" "),
indent, ps.stats,
indent, ps.Stats,
indent)
}

View File

@ -2,9 +2,8 @@ package p2p
import (
"fmt"
"strings"
cmn "github.com/tendermint/tmlibs/common"
"strings"
)
const (
@ -31,7 +30,7 @@ type NodeInfo struct {
Version string `json:"version"` // major.minor.revision
Channels cmn.HexBytes `json:"channels"` // channels this node knows about
// Sanitize
// ASCIIText fields
Moniker string `json:"moniker"` // arbitrary moniker
Other []string `json:"other"` // other application specific data
}
@ -42,11 +41,28 @@ type NodeInfo struct {
// if the ListenAddr is malformed, or if the ListenAddr is a host name
// that can not be resolved to some IP.
// TODO: constraints for Moniker/Other? Or is that for the UI ?
// JAE: It needs to be done on the client, but to prevent ambiguous
// unicode characters, maybe it's worth sanitizing it here.
// In the future we might want to validate these, once we have a
// name-resolution system up.
// International clients could then use punycode (or we could use
// url-encoding), and we just need to be careful with how we handle that in our
// clients. (e.g. off by default).
func (info NodeInfo) Validate() error {
if len(info.Channels) > maxNumChannels {
return fmt.Errorf("info.Channels is too long (%v). Max is %v", len(info.Channels), maxNumChannels)
}
// Sanitize ASCII text fields.
if !cmn.IsASCIIText(info.Moniker) || cmn.ASCIITrim(info.Moniker) == "" {
return fmt.Errorf("info.Moniker must be valid non-empty ASCII text without tabs, but got %v.", info.Moniker)
}
for i, s := range info.Other {
if !cmn.IsASCIIText(s) || cmn.ASCIITrim(s) == "" {
return fmt.Errorf("info.Other[%v] must be valid non-empty ASCII text without tabs, but got %v.", i, s)
}
}
channels := make(map[byte]struct{})
for _, ch := range info.Channels {
_, ok := channels[ch]

View File

@ -74,7 +74,7 @@ func TestDumpConsensusState(t *testing.T) {
cons, err := nc.DumpConsensusState()
require.Nil(t, err, "%d: %+v", i, err)
assert.NotEmpty(t, cons.RoundState)
assert.Empty(t, cons.PeerRoundStates)
assert.Empty(t, cons.Peers)
}
}

View File

@ -58,134 +58,17 @@ func Validators(heightPtr *int64) (*ctypes.ResultValidators, error) {
}
// DumpConsensusState dumps consensus state.
//
// ```shell
// curl 'localhost:46657/dump_consensus_state'
// ```
//
// ```go
// client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
// state, err := client.DumpConsensusState()
// ```
//
// > The above command returns JSON structured like this:
//
// ```json
//{
// "jsonrpc": "2.0",
// "id": "",
// "result": {
// "round_state": {
// "height": 138,
// "round": 0,
// "step": 1,
// "start_time": "2018-04-27T23:16:34.472087096-04:00",
// "commit_time": "2018-04-27T23:16:33.472087096-04:00",
// "validators": {
// "validators": [
// {
// "address": "5875562FF0FFDECC895C20E32FC14988952E99E7",
// "pub_key": {
// "type": "AC26791624DE60",
// "value": "PpDJRUrLG2RgFqYYjawfn/AcAgacSXpLFrmfYYQnuzE="
// },
// "voting_power": 10,
// "accum": 0
// }
// ],
// "proposer": {
// "address": "5875562FF0FFDECC895C20E32FC14988952E99E7",
// "pub_key": {
// "type": "AC26791624DE60",
// "value": "PpDJRUrLG2RgFqYYjawfn/AcAgacSXpLFrmfYYQnuzE="
// },
// "voting_power": 10,
// "accum": 0
// }
// },
// "proposal": null,
// "proposal_block": null,
// "proposal_block_parts": null,
// "locked_round": 0,
// "locked_block": null,
// "locked_block_parts": null,
// "valid_round": 0,
// "valid_block": null,
// "valid_block_parts": null,
// "votes": [
// {
// "round": 0,
// "prevotes": "_",
// "precommits": "_"
// }
// ],
// "commit_round": -1,
// "last_commit": {
// "votes": [
// "Vote{0:5875562FF0FF 137/00/2(Precommit) 5701C93659EA /ED3588D7AF29.../ @ 2018-04-28T03:16:33.469Z}"
// ],
// "votes_bit_array": "x",
// "peer_maj_23s": {}
// },
// "last_validators": {
// "validators": [
// {
// "address": "5875562FF0FFDECC895C20E32FC14988952E99E7",
// "pub_key": {
// "type": "AC26791624DE60",
// "value": "PpDJRUrLG2RgFqYYjawfn/AcAgacSXpLFrmfYYQnuzE="
// },
// "voting_power": 10,
// "accum": 0
// }
// ],
// "proposer": {
// "address": "5875562FF0FFDECC895C20E32FC14988952E99E7",
// "pub_key": {
// "type": "AC26791624DE60",
// "value": "PpDJRUrLG2RgFqYYjawfn/AcAgacSXpLFrmfYYQnuzE="
// },
// "voting_power": 10,
// "accum": 0
// }
// }
// },
// "peer_round_states": {
// "d4bf26bfa5e390b94d98106ab858abf64db26d48": {
// "Height": 136,
// "Round": 0,
// "Step": 1,
// "StartTime": "2018-04-27T23:16:33.841163812-04:00",
// "Proposal": false,
// "ProposalBlockPartsHeader": {
// "total": 1,
// "hash": "E27F2D13298F7CB14090EE60CD9AB214D2F5161F"
// },
// "ProposalBlockParts": "x",
// "ProposalPOLRound": -1,
// "ProposalPOL": "_",
// "Prevotes": "_",
// "Precommits": "x",
// "LastCommitRound": 0,
// "LastCommit": null,
// "CatchupCommitRound": 0,
// "CatchupCommit": "_"
// }
// }
// }
//}
// ```
// UNSTABLE
func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
peers := p2pSwitch.Peers().List()
peerRoundStates := make([]ctypes.PeerRoundState, len(peers))
peerRoundStates := make([]ctypes.PeerRoundStateInfo, 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[i] = ctypes.PeerRoundState{
peerRoundStates[i] = ctypes.PeerRoundStateInfo{
NodeAddress: p2p.IDAddressString(peer.ID(), peer.NodeInfo().ListenAddr),
PeerRoundState: peerRoundState,
}

View File

@ -130,13 +130,11 @@ type ResultValidators struct {
// Info about the consensus state.
// Unstable
type ResultDumpConsensusState struct {
RoundState json.RawMessage `json:"round_state"`
PeerRoundStates []PeerRoundState `json:"peer_round_states"`
RoundState json.RawMessage `json:"round_state"`
Peers []PeerRoundStateInfo `json:"peers"`
}
// Raw JSON for the PeerRoundState
// Unstable
type PeerRoundState struct {
type PeerRoundStateInfo struct {
NodeAddress string `json:"node_address"`
PeerRoundState json.RawMessage `json:"peer_round_state"`
}