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

fix: retry indexing the same block range on handler failure #353

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mpetrun5 marked this conversation as resolved.
Show resolved Hide resolved
}

}

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