Skip to content

Commit a9fbfcf

Browse files
authored
IC-1112: move existing vote log INF -> DBG level (#12)
1 parent 3b39548 commit a9fbfcf

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

internal/consensus/state.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"runtime/debug"
1111
"sort"
1212
"strconv"
13+
"strings"
1314
"time"
1415

1516
injmetrics "github.com/InjectiveLabs/metrics/v2"
@@ -967,6 +968,21 @@ func (cs *State) handleMsg(mi msgInfo) {
967968
}
968969

969970
if err != nil {
971+
// no graceful way to match this error earlier in this codebase
972+
// we need to skip "existing vote" reports since they are false positives
973+
if strings.Contains(err.Error(), "error adding vote") {
974+
cs.Logger.Debug(
975+
"Failed to process message",
976+
"height", cs.Height,
977+
"round", cs.Round,
978+
"peer", peerID,
979+
"msg_type", fmt.Sprintf("%T", msg),
980+
"err", err,
981+
)
982+
983+
return
984+
}
985+
970986
cs.Logger.Info(
971987
"Failed to process message",
972988
"height", cs.Height,

internal/consensus/state_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,63 @@ x * TestHalt1 - if we see +2/3 precommits after timing out into new round, we sh
6969
7070
*/
7171

72+
type stateLogEntry struct {
73+
level string
74+
message string
75+
keyvals []any
76+
}
77+
78+
type stateLogRecorder struct {
79+
entries *[]stateLogEntry
80+
keyvals []any
81+
}
82+
83+
func newStateLogRecorder() *stateLogRecorder {
84+
entries := make([]stateLogEntry, 0)
85+
return &stateLogRecorder{entries: &entries}
86+
}
87+
88+
func (l *stateLogRecorder) Debug(msg string, keyvals ...any) {
89+
l.record("debug", msg, keyvals...)
90+
}
91+
92+
func (l *stateLogRecorder) Info(msg string, keyvals ...any) {
93+
l.record("info", msg, keyvals...)
94+
}
95+
96+
func (l *stateLogRecorder) Error(msg string, keyvals ...any) {
97+
l.record("error", msg, keyvals...)
98+
}
99+
100+
func (l *stateLogRecorder) With(keyvals ...any) log.Logger {
101+
nextKeyvals := append([]any{}, l.keyvals...)
102+
nextKeyvals = append(nextKeyvals, keyvals...)
103+
return &stateLogRecorder{
104+
entries: l.entries,
105+
keyvals: nextKeyvals,
106+
}
107+
}
108+
109+
func (l *stateLogRecorder) record(level string, msg string, keyvals ...any) {
110+
entryKeyvals := append([]any{}, l.keyvals...)
111+
entryKeyvals = append(entryKeyvals, keyvals...)
112+
*l.entries = append(*l.entries, stateLogEntry{
113+
level: level,
114+
message: msg,
115+
keyvals: entryKeyvals,
116+
})
117+
}
118+
119+
func (l *stateLogRecorder) count(level string, message string) int {
120+
count := 0
121+
for _, entry := range *l.entries {
122+
if entry.level == level && entry.message == message {
123+
count++
124+
}
125+
}
126+
return count
127+
}
128+
72129
// ----------------------------------------------------------------------------------------------------
73130
// ProposeSuite
74131

@@ -3117,6 +3174,31 @@ func TestStateOutputVoteStats(t *testing.T) {
31173174
}
31183175
}
31193176

3177+
func TestStateHandleMsgLogsAddingVoteErrorsAtDebug(t *testing.T) {
3178+
cs, vss := randState(2)
3179+
chainID := cs.state.ChainID
3180+
logger := newStateLogRecorder()
3181+
cs.SetLogger(logger)
3182+
3183+
peer := p2pmock.NewPeer(nil)
3184+
blockID := types.BlockID{
3185+
Hash: cmtrand.Bytes(tmhash.Size),
3186+
}
3187+
3188+
vote := signVote(vss[1], types.PrecommitType, chainID, blockID, true)
3189+
cs.handleMsg(msgInfo{&VoteMessage{vote}, peer.ID(), time.Time{}})
3190+
3191+
conflictingSignatureVote := vote.Copy()
3192+
conflictingSignatureVote.Signature = append([]byte(nil), vote.Signature...)
3193+
require.NotEmpty(t, conflictingSignatureVote.Signature)
3194+
conflictingSignatureVote.Signature[0] ^= 0x01
3195+
3196+
cs.handleMsg(msgInfo{&VoteMessage{conflictingSignatureVote}, peer.ID(), time.Time{}})
3197+
3198+
require.Equal(t, 1, logger.count("debug", "Failed to process message"))
3199+
require.Zero(t, logger.count("info", "Failed to process message"))
3200+
}
3201+
31203202
func TestSignSameVoteTwice(t *testing.T) {
31213203
cs, vss := randState(2)
31223204
chainID := cs.state.ChainID

0 commit comments

Comments
 (0)