Skip to content

Commit a54fbce

Browse files
codchenudpatil
authored andcommitted
Fix debug log (#205)
1 parent 693d289 commit a54fbce

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

internal/consensus/reactor.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"sync"
99
"time"
1010

11+
"github.com/tendermint/tendermint/config"
1112
cstypes "github.com/tendermint/tendermint/internal/consensus/types"
1213
"github.com/tendermint/tendermint/internal/eventbus"
1314
"github.com/tendermint/tendermint/internal/p2p"
@@ -121,6 +122,7 @@ type ConsSyncReactor interface {
121122
type Reactor struct {
122123
service.BaseService
123124
logger log.Logger
125+
cfg *config.Config
124126

125127
state *State
126128
eventBus *eventbus.EventBus
@@ -148,6 +150,7 @@ func NewReactor(
148150
eventBus *eventbus.EventBus,
149151
waitSync bool,
150152
metrics *Metrics,
153+
cfg *config.Config,
151154
) *Reactor {
152155
r := &Reactor{
153156
logger: logger,
@@ -160,6 +163,7 @@ func NewReactor(
160163
peerEvents: peerEvents,
161164
readySignal: make(chan struct{}),
162165
channels: &channelBundle{},
166+
cfg: cfg,
163167
}
164168
r.BaseService = *service.NewBaseService(logger, "Consensus", r)
165169

@@ -646,7 +650,12 @@ func (r *Reactor) pickSendVote(ctx context.Context, ps *PeerState, votes types.V
646650
return false, nil
647651
}
648652

649-
r.logger.Debug("sending vote message", "ps", ps, "vote", vote)
653+
if r.cfg.BaseConfig.LogLevel == log.LogLevelDebug {
654+
psJson, err := ps.ToJSON() // expensive, so we only want to call if debug is on
655+
if err != nil {
656+
r.logger.Debug("sending vote message", "ps", string(psJson), "vote", vote)
657+
}
658+
}
650659
if err := voteCh.Send(ctx, p2p.Envelope{
651660
To: ps.peerID,
652661
Message: &tmcons.Vote{

internal/consensus/reactor_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func setup(
9797
state.eventBus,
9898
true,
9999
NopMetrics(),
100+
config.DefaultConfig(),
100101
)
101102

102103
reactor.SetStateChannel(rts.stateChannels[nodeID])
@@ -697,6 +698,7 @@ func TestSwitchToConsensusVoteExtensions(t *testing.T) {
697698
cs.eventBus,
698699
true,
699700
NopMetrics(),
701+
config.DefaultConfig(),
700702
)
701703

702704
if testCase.shouldPanic {

node/node.go

+1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ func makeNode(
349349
eventBus,
350350
waitSync,
351351
nodeMetrics.consensus,
352+
cfg,
352353
)
353354

354355
node.router.AddChDescToBeAdded(consensus.GetStateChannelDescriptor(), csReactor.SetStateChannel)

0 commit comments

Comments
 (0)