Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit ba947a1

Browse files
mpetrun5MakMuftic
andauthored
chore: improve evm listener logging (#335)
* chore: improve evm listener logging * Set registration of deposit and message handlers to debug * Update chains/evm/listener/listener.go Co-authored-by: mace <[email protected]> --------- Co-authored-by: mace <[email protected]>
1 parent 76d0d57 commit ba947a1

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

chains/evm/executor/message-handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (mh *EVMMessageHandler) RegisterMessageHandler(address string, handler Mess
7070
mh.handlers = make(map[common.Address]MessageHandlerFunc)
7171
}
7272

73-
log.Info().Msgf("Registered message handler for address %s", address)
73+
log.Debug().Msgf("Registered message handler for address %s", address)
7474

7575
mh.handlers[common.HexToAddress(address)] = handler
7676
}

chains/evm/listener/deposit-handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (e *ETHDepositHandler) RegisterDepositHandler(handlerAddress string, handle
6161
return
6262
}
6363

64-
log.Info().Msgf("Registered deposit handler for address %s", handlerAddress)
64+
log.Debug().Msgf("Registered deposit handler for address %s", handlerAddress)
6565
e.depositHandlers[common.HexToAddress(handlerAddress)] = handler
6666
}
6767

chains/evm/listener/listener.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/ChainSafe/chainbridge-core/relayer/message"
1212
"github.com/ChainSafe/chainbridge-core/store"
1313

14+
"github.com/rs/zerolog"
1415
"github.com/rs/zerolog/log"
1516
)
1617

@@ -31,6 +32,8 @@ type EVMListener struct {
3132
blockRetryInterval time.Duration
3233
blockConfirmations *big.Int
3334
blockInterval *big.Int
35+
36+
log zerolog.Logger
3437
}
3538

3639
// NewEVMListener creates an EVMListener that listens to deposit events on chain
@@ -43,7 +46,9 @@ func NewEVMListener(
4346
blockRetryInterval time.Duration,
4447
blockConfirmations *big.Int,
4548
blockInterval *big.Int) *EVMListener {
49+
logger := log.With().Uint8("domainID", domainID).Logger()
4650
return &EVMListener{
51+
log: logger,
4752
client: client,
4853
eventHandlers: eventHandlers,
4954
blockstore: blockstore,
@@ -65,7 +70,7 @@ func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int, m
6570
default:
6671
head, err := l.client.LatestBlock()
6772
if err != nil {
68-
log.Error().Err(err).Msg("Unable to get latest block")
73+
l.log.Error().Err(err).Msg("Unable to get latest block")
6974
time.Sleep(l.blockRetryInterval)
7075
continue
7176
}
@@ -80,18 +85,20 @@ func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int, m
8085
continue
8186
}
8287

88+
l.log.Debug().Msgf("Fetching evm events for block range %s-%s", startBlock, endBlock)
89+
8390
for _, handler := range l.eventHandlers {
8491
err := handler.HandleEvent(startBlock, new(big.Int).Sub(endBlock, big.NewInt(1)), msgChan)
8592
if err != nil {
86-
log.Error().Err(err).Str("DomainID", string(l.domainID)).Msgf("Unable to handle events")
93+
l.log.Error().Err(err).Msgf("Unable to handle events")
8794
continue
8895
}
8996
}
9097

9198
//Write to block store. Not a critical operation, no need to retry
9299
err = l.blockstore.StoreBlock(endBlock, l.domainID)
93100
if err != nil {
94-
log.Error().Str("block", endBlock.String()).Err(err).Msg("Failed to write latest block to blockstore")
101+
l.log.Error().Str("block", endBlock.String()).Err(err).Msg("Failed to write latest block to blockstore")
95102
}
96103

97104
startBlock.Add(startBlock, l.blockInterval)

0 commit comments

Comments
 (0)