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

Commit

Permalink
fix: retry indexing the same block range on handler failure (#353)
Browse files Browse the repository at this point in the history
* Add listener tests

* Fix mocks

* Regenerate mocks with correct mockgen version

* Change unable to handle events to warn as it is not actionable in most cases
  • Loading branch information
mpetrun5 committed Oct 16, 2023
1 parent e55b5ce commit c06ed31
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 226 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ genmocks:
mockgen -destination=./chains/evm/calls/transactor/itx/mock/itx.go -source=./chains/evm/calls/transactor/itx/itx.go
mockgen -destination=./chains/evm/calls/transactor/itx//mock/minimalForwarder.go -source=./chains/evm/calls/transactor/itx/minimalForwarder.go
mockgen -destination=chains/evm/cli/bridge/mock/vote-proposal.go -source=./chains/evm/cli/bridge/vote-proposal.go
mockgen -destination=chains/evm/listener/mock/listener.go -source=./chains/evm/listener/event-handler.go
mockgen -destination=chains/evm/listener/mock/handler.go -source=./chains/evm/listener/event-handler.go
mockgen -destination=chains/evm/listener/mock/listener.go -source=./chains/evm/listener/listener.go

15 changes: 10 additions & 5 deletions chains/evm/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/ChainSafe/chainbridge-core/relayer/message"
"github.com/ChainSafe/chainbridge-core/store"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand All @@ -27,13 +26,17 @@ type BlockDeltaMeter interface {
TrackBlockDelta(domainID uint8, head *big.Int, current *big.Int)
}

type BlockStorer interface {
StoreBlock(block *big.Int, domainID uint8) error
}

type EVMListener struct {
client ChainClient
eventHandlers []EventHandler
metrics BlockDeltaMeter

domainID uint8
blockstore *store.BlockStore
blockstore BlockStorer
blockRetryInterval time.Duration
blockConfirmations *big.Int
blockInterval *big.Int
Expand All @@ -46,7 +49,7 @@ type EVMListener struct {
func NewEVMListener(
client ChainClient,
eventHandlers []EventHandler,
blockstore *store.BlockStore,
blockstore BlockStorer,
metrics BlockDeltaMeter,
domainID uint8,
blockRetryInterval time.Duration,
Expand All @@ -70,6 +73,7 @@ func NewEVMListener(
// configured for the listener.
func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int, msgChan chan []*message.Message, errChn chan<- error) {
endBlock := big.NewInt(0)
loop:
for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -98,9 +102,10 @@ func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int, m
for _, handler := range l.eventHandlers {
err := handler.HandleEvent(startBlock, new(big.Int).Sub(endBlock, big.NewInt(1)), msgChan)
if err != nil {
l.log.Error().Err(err).Msgf("Unable to handle events")
continue
l.log.Warn().Err(err).Msgf("Unable to handle events")
continue loop
}

}

//Write to block store. Not a critical operation, no need to retry
Expand Down
Loading

0 comments on commit c06ed31

Please sign in to comment.