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

Commit

Permalink
chore: improve evm listener logging (#335)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mpetrun5 and MakMuftic authored Mar 20, 2023
1 parent 76d0d57 commit ba947a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion chains/evm/executor/message-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (mh *EVMMessageHandler) RegisterMessageHandler(address string, handler Mess
mh.handlers = make(map[common.Address]MessageHandlerFunc)
}

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

mh.handlers[common.HexToAddress(address)] = handler
}
Expand Down
2 changes: 1 addition & 1 deletion chains/evm/listener/deposit-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (e *ETHDepositHandler) RegisterDepositHandler(handlerAddress string, handle
return
}

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

Expand Down
13 changes: 10 additions & 3 deletions chains/evm/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ChainSafe/chainbridge-core/relayer/message"
"github.com/ChainSafe/chainbridge-core/store"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

Expand All @@ -31,6 +32,8 @@ type EVMListener struct {
blockRetryInterval time.Duration
blockConfirmations *big.Int
blockInterval *big.Int

log zerolog.Logger
}

// NewEVMListener creates an EVMListener that listens to deposit events on chain
Expand All @@ -43,7 +46,9 @@ func NewEVMListener(
blockRetryInterval time.Duration,
blockConfirmations *big.Int,
blockInterval *big.Int) *EVMListener {
logger := log.With().Uint8("domainID", domainID).Logger()
return &EVMListener{
log: logger,
client: client,
eventHandlers: eventHandlers,
blockstore: blockstore,
Expand All @@ -65,7 +70,7 @@ func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int, m
default:
head, err := l.client.LatestBlock()
if err != nil {
log.Error().Err(err).Msg("Unable to get latest block")
l.log.Error().Err(err).Msg("Unable to get latest block")
time.Sleep(l.blockRetryInterval)
continue
}
Expand All @@ -80,18 +85,20 @@ func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int, m
continue
}

l.log.Debug().Msgf("Fetching evm events for block range %s-%s", startBlock, endBlock)

for _, handler := range l.eventHandlers {
err := handler.HandleEvent(startBlock, new(big.Int).Sub(endBlock, big.NewInt(1)), msgChan)
if err != nil {
log.Error().Err(err).Str("DomainID", string(l.domainID)).Msgf("Unable to handle events")
l.log.Error().Err(err).Msgf("Unable to handle events")
continue
}
}

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

startBlock.Add(startBlock, l.blockInterval)
Expand Down

0 comments on commit ba947a1

Please sign in to comment.