Browse Source

logging: shorten precommit log message (#6270)

This is an attempt to clean up the logging message as requested in #6269.
pull/6275/head
Sam Kleinman 4 years ago
committed by GitHub
parent
commit
3f9066b290
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions
  1. +6
    -1
      consensus/state.go
  2. +1
    -1
      types/block.go
  3. +17
    -2
      types/vote_set.go

+ 6
- 1
consensus/state.go View File

@ -2128,7 +2128,12 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.NodeID) (added bool, err e
case tmproto.PrecommitType: case tmproto.PrecommitType:
precommits := cs.Votes.Precommits(vote.Round) precommits := cs.Votes.Precommits(vote.Round)
cs.Logger.Debug("added vote to precommit", "vote", vote, "precommits", precommits.StringShort())
cs.Logger.Debug("added vote to precommit",
"height", vote.Height,
"round", vote.Round,
"validator", vote.ValidatorAddress.String(),
"vote_timestamp", vote.Timestamp,
"data", precommits.LogString())
blockID, ok := precommits.TwoThirdsMajority() blockID, ok := precommits.TwoThirdsMajority()
if ok { if ok {


+ 1
- 1
types/block.go View File

@ -1189,7 +1189,7 @@ func (blockID BlockID) Key() string {
panic(err) panic(err)
} }
return string(blockID.Hash) + string(bz)
return fmt.Sprint(string(blockID.Hash), string(bz))
} }
// ValidateBasic performs basic validation. // ValidateBasic performs basic validation.


+ 17
- 2
types/vote_set.go View File

@ -442,12 +442,14 @@ func (voteSet *VoteSet) TwoThirdsMajority() (blockID BlockID, ok bool) {
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Strings and JSON // Strings and JSON
const nilVoteSetString = "nil-VoteSet"
// String returns a string representation of VoteSet. // String returns a string representation of VoteSet.
// //
// See StringIndented. // See StringIndented.
func (voteSet *VoteSet) String() string { func (voteSet *VoteSet) String() string {
if voteSet == nil { if voteSet == nil {
return "nil-VoteSet"
return nilVoteSetString
} }
return voteSet.StringIndented("") return voteSet.StringIndented("")
} }
@ -551,7 +553,7 @@ func (voteSet *VoteSet) voteStrings() []string {
// 7. 2/3+ majority for each peer // 7. 2/3+ majority for each peer
func (voteSet *VoteSet) StringShort() string { func (voteSet *VoteSet) StringShort() string {
if voteSet == nil { if voteSet == nil {
return "nil-VoteSet"
return nilVoteSetString
} }
voteSet.mtx.Lock() voteSet.mtx.Lock()
defer voteSet.mtx.Unlock() defer voteSet.mtx.Unlock()
@ -560,6 +562,19 @@ func (voteSet *VoteSet) StringShort() string {
voteSet.height, voteSet.round, voteSet.signedMsgType, voteSet.maj23, frac, voteSet.votesBitArray, voteSet.peerMaj23s) voteSet.height, voteSet.round, voteSet.signedMsgType, voteSet.maj23, frac, voteSet.votesBitArray, voteSet.peerMaj23s)
} }
// LogString produces a logging suitable string representation of the
// vote set.
func (voteSet *VoteSet) LogString() string {
if voteSet == nil {
return nilVoteSetString
}
voteSet.mtx.Lock()
defer voteSet.mtx.Unlock()
voted, total, frac := voteSet.sumTotalFrac()
return fmt.Sprintf("Votes:%d/%d(%.3f)", voted, total, frac)
}
// return the power voted, the total, and the fraction // return the power voted, the total, and the fraction
func (voteSet *VoteSet) sumTotalFrac() (int64, int64, float64) { func (voteSet *VoteSet) sumTotalFrac() (int64, int64, float64) {
voted, total := voteSet.sum, voteSet.valSet.TotalVotingPower() voted, total := voteSet.sum, voteSet.valSet.TotalVotingPower()


Loading…
Cancel
Save