Skip to content

Commit

Permalink
fix(relayer): Save block progress when caught up and subscribing to n…
Browse files Browse the repository at this point in the history
…ew events (#13177)
  • Loading branch information
cyberhorsey committed Feb 17, 2023
1 parent 3aaf5dd commit 5ef2c0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/relayer/indexer/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/taikoxyz/taiko-mono/packages/relayer"
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/bridge"
)

Expand Down Expand Up @@ -39,6 +40,23 @@ func (svc *Service) subscribe(ctx context.Context, chainID *big.Int) error {
if err != nil {
log.Errorf("svc.subscribe, svc.handleEvent: %v", err)
}

block, err := svc.blockRepo.GetLatestBlockProcessedForEvent(relayer.EventNameMessageSent, chainID)
if err != nil {
log.Errorf("svc.subscribe, blockRepo.GetLatestBlockProcessedForEvent: %v", err)
}

if block.Height < event.Raw.BlockNumber {
err = svc.blockRepo.Save(relayer.SaveBlockOpts{
Height: event.Raw.BlockNumber,
Hash: event.Raw.BlockHash,
ChainID: chainID,
EventName: relayer.EventNameMessageSent,
})
if err != nil {
log.Errorf("svc.subscribe, svc.blockRepo.Save: %v", err)
}
}
}()
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/relayer/indexer/subscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package indexer

import (
"context"
"math/big"
"testing"
"time"

Expand All @@ -14,7 +13,7 @@ func Test_subscribe(t *testing.T) {
svc, bridge := newTestService()

go func() {
_ = svc.subscribe(context.Background(), big.NewInt(1))
_ = svc.subscribe(context.Background(), mock.MockChainID)
}()

<-time.After(6 * time.Second)
Expand Down

0 comments on commit 5ef2c0f

Please sign in to comment.