Skip to content

Commit

Permalink
fix(relayer): fix scanning blocks twice (#14047)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed Jun 23, 2023
1 parent fccc0a7 commit 9ee6723
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion packages/relayer/indexer/detect_and_handle_reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (svc *Service) detectAndHandleReorg(ctx context.Context, eventType string,
}

// reorg detected

log.Infof("reorg detected for msgHash %v and eventType %v", msgHash, eventType)

err = svc.eventRepo.Delete(ctx, e.ID)
Expand Down
13 changes: 12 additions & 1 deletion packages/relayer/indexer/filter_then_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package indexer

import (
"context"
"fmt"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/pkg/errors"
Expand Down Expand Up @@ -63,9 +64,17 @@ func (svc *Service) FilterThenSubscribe(
end = header.Number.Uint64()
}

// filter exclusive of the end block.
// we use "end" as the next starting point of the batch, and
// process up to end - 1 for this batch.
filterEnd := end - 1

fmt.Printf("block batch from %v to %v", i, filterEnd)
fmt.Println()

filterOpts := &bind.FilterOpts{
Start: svc.processingBlockHeight,
End: &end,
End: &filterEnd,
Context: ctx,
}

Expand All @@ -88,6 +97,8 @@ func (svc *Service) FilterThenSubscribe(
}

if !messageSentEvents.Next() || messageSentEvents.Event == nil {
// use "end" not "filterEnd" here, because it will be used as the start
// of the next batch.
if err := svc.handleNoEventsInBatch(ctx, chainID, int64(end)); err != nil {
return errors.Wrap(err, "svc.handleNoEventsInBatch")
}
Expand Down

0 comments on commit 9ee6723

Please sign in to comment.