From 070d21448b3a76c5ffb08a06df16526d6b360eaf Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Thu, 16 Feb 2023 15:16:44 -0800 Subject: [PATCH 1/2] relayer should save latest block on processing whem subscribing, so upon reboot, it knows where to pick u pfrom. --- packages/relayer/indexer/subscribe.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/relayer/indexer/subscribe.go b/packages/relayer/indexer/subscribe.go index e4c02698a16..02ea554e6fc 100644 --- a/packages/relayer/indexer/subscribe.go +++ b/packages/relayer/indexer/subscribe.go @@ -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" ) @@ -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) + } + } }() } } From d771a2063ca703c7b47073fb23c70357a1be842f Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Thu, 16 Feb 2023 15:53:41 -0800 Subject: [PATCH 2/2] test --- packages/relayer/indexer/subscribe_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/relayer/indexer/subscribe_test.go b/packages/relayer/indexer/subscribe_test.go index c68811b1e32..f899386d352 100644 --- a/packages/relayer/indexer/subscribe_test.go +++ b/packages/relayer/indexer/subscribe_test.go @@ -2,7 +2,6 @@ package indexer import ( "context" - "math/big" "testing" "time" @@ -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)