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

Commit c06ed31

Browse files
authored
fix: retry indexing the same block range on handler failure (#353)
* 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
1 parent e55b5ce commit c06ed31

File tree

5 files changed

+350
-226
lines changed

5 files changed

+350
-226
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ genmocks:
4141
mockgen -destination=./chains/evm/calls/transactor/itx/mock/itx.go -source=./chains/evm/calls/transactor/itx/itx.go
4242
mockgen -destination=./chains/evm/calls/transactor/itx//mock/minimalForwarder.go -source=./chains/evm/calls/transactor/itx/minimalForwarder.go
4343
mockgen -destination=chains/evm/cli/bridge/mock/vote-proposal.go -source=./chains/evm/cli/bridge/vote-proposal.go
44-
mockgen -destination=chains/evm/listener/mock/listener.go -source=./chains/evm/listener/event-handler.go
44+
mockgen -destination=chains/evm/listener/mock/handler.go -source=./chains/evm/listener/event-handler.go
45+
mockgen -destination=chains/evm/listener/mock/listener.go -source=./chains/evm/listener/listener.go
46+

chains/evm/listener/listener.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"time"
1010

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

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

29+
type BlockStorer interface {
30+
StoreBlock(block *big.Int, domainID uint8) error
31+
}
32+
3033
type EVMListener struct {
3134
client ChainClient
3235
eventHandlers []EventHandler
3336
metrics BlockDeltaMeter
3437

3538
domainID uint8
36-
blockstore *store.BlockStore
39+
blockstore BlockStorer
3740
blockRetryInterval time.Duration
3841
blockConfirmations *big.Int
3942
blockInterval *big.Int
@@ -46,7 +49,7 @@ type EVMListener struct {
4649
func NewEVMListener(
4750
client ChainClient,
4851
eventHandlers []EventHandler,
49-
blockstore *store.BlockStore,
52+
blockstore BlockStorer,
5053
metrics BlockDeltaMeter,
5154
domainID uint8,
5255
blockRetryInterval time.Duration,
@@ -70,6 +73,7 @@ func NewEVMListener(
7073
// configured for the listener.
7174
func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int, msgChan chan []*message.Message, errChn chan<- error) {
7275
endBlock := big.NewInt(0)
76+
loop:
7377
for {
7478
select {
7579
case <-ctx.Done():
@@ -98,9 +102,10 @@ func (l *EVMListener) ListenToEvents(ctx context.Context, startBlock *big.Int, m
98102
for _, handler := range l.eventHandlers {
99103
err := handler.HandleEvent(startBlock, new(big.Int).Sub(endBlock, big.NewInt(1)), msgChan)
100104
if err != nil {
101-
l.log.Error().Err(err).Msgf("Unable to handle events")
102-
continue
105+
l.log.Warn().Err(err).Msgf("Unable to handle events")
106+
continue loop
103107
}
108+
104109
}
105110

106111
//Write to block store. Not a critical operation, no need to retry

0 commit comments

Comments
 (0)