@@ -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+
31203202func TestSignSameVoteTwice (t * testing.T ) {
31213203 cs , vss := randState (2 )
31223204 chainID := cs .state .ChainID
0 commit comments