Skip to content

Commit

Permalink
ethmonitor: quiet down debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Oct 30, 2024
1 parent 0d909e5 commit 678f71b
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions ethmonitor/ethmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,10 @@ func (m *Monitor) buildCanonicalChain(ctx context.Context, nextBlock *types.Bloc

headBlock := m.chain.Head()

m.log.Debugf("ethmonitor: new block #%d hash:%s prevHash:%s numTxns:%d",
nextBlock.NumberU64(), nextBlock.Hash().String(), nextBlock.ParentHash().String(), len(nextBlock.Transactions()))
if m.options.DebugLogging {
m.log.Debugf("ethmonitor: new block #%d hash:%s prevHash:%s numTxns:%d",
nextBlock.NumberU64(), nextBlock.Hash().String(), nextBlock.ParentHash().String(), len(nextBlock.Transactions()))
}

if headBlock == nil || nextBlock.ParentHash() == headBlock.Hash() {
// block-chaining it up
Expand All @@ -586,7 +588,9 @@ func (m *Monitor) buildCanonicalChain(ctx context.Context, nextBlock *types.Bloc
}
}

m.log.Debugf("ethmonitor: block reorg, reverting block #%d hash:%s prevHash:%s", poppedBlock.NumberU64(), poppedBlock.Hash().Hex(), poppedBlock.ParentHash().Hex())
if m.options.DebugLogging {
m.log.Debugf("ethmonitor: block reorg, reverting block #%d hash:%s prevHash:%s", poppedBlock.NumberU64(), poppedBlock.Hash().Hex(), poppedBlock.ParentHash().Hex())
}
events = append(events, &poppedBlock)

// let's always take a pause between any reorg for the polling interval time
Expand Down Expand Up @@ -677,7 +681,9 @@ func (m *Monitor) addLogs(ctx context.Context, blocks Blocks) {

func (m *Monitor) filterLogs(ctx context.Context, blockHash common.Hash, topics [][]common.Hash) ([]types.Log, []byte, error) {
getter := func(ctx context.Context, _ string) ([]byte, error) {
m.log.Debugf("ethmonitor: filterLogs is calling origin for block hash %s", blockHash)
if m.options.DebugLogging {
m.log.Debugf("ethmonitor: filterLogs is calling origin for block hash %s", blockHash)
}

tctx, cancel := context.WithTimeout(ctx, 4*time.Second)
defer cancel()
Expand Down Expand Up @@ -758,7 +764,9 @@ func (m *Monitor) fetchNextBlock(ctx context.Context) (*types.Block, []byte, boo
miss := false

getter := func(ctx context.Context, _ string) ([]byte, error) {
m.log.Debugf("ethmonitor: fetchNextBlock is calling origin for number %s", m.nextBlockNumber)
if m.options.DebugLogging {
m.log.Debugf("ethmonitor: fetchNextBlock is calling origin for number %s", m.nextBlockNumber)
}
for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -820,7 +828,9 @@ func cacheKeyBlockNum(chainID *big.Int, num *big.Int) string {
}

func (m *Monitor) fetchRawBlockByNumber(ctx context.Context, num *big.Int) ([]byte, error) {
m.log.Debugf("ethmonitor: fetchRawBlockByNumber is calling origin for number %s", num)
if m.options.DebugLogging {
m.log.Debugf("ethmonitor: fetchRawBlockByNumber is calling origin for number %s", num)
}
maxErrAttempts, errAttempts := 3, 0 // quick retry in case of short-term node connection failures

var blockPayload []byte
Expand Down Expand Up @@ -858,8 +868,9 @@ func (m *Monitor) fetchRawBlockByNumber(ctx context.Context, num *big.Int) ([]by

func (m *Monitor) fetchBlockByHash(ctx context.Context, hash common.Hash) (*types.Block, []byte, error) {
getter := func(ctx context.Context, _ string) ([]byte, error) {
m.log.Debugf("ethmonitor: fetchBlockByHash is calling origin for hash %s", hash)

if m.options.DebugLogging {
m.log.Debugf("ethmonitor: fetchBlockByHash is calling origin for hash %s", hash)
}
maxNotFoundAttempts, notFoundAttempts := 2, 0 // waiting for node to sync
maxErrAttempts, errAttempts := 2, 0 // quick retry in case of short-term node connection failures

Expand Down

0 comments on commit 678f71b

Please sign in to comment.