Skip to content

Commit

Permalink
chore(taiko-client): ensure event block IDs are continuous (#18775)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jan 15, 2025
1 parent 3945f60 commit b359be0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
DefaultBlocksReadPerEpoch = 1000
DefaultRetryInterval = 12 * time.Second
DefaultBlockConfirmations = 0
BackOffMaxRetries = 5
)

var (
Expand Down Expand Up @@ -163,7 +164,13 @@ func (i *BlockBatchIterator) Iter() error {
return nil
}

if err := backoff.Retry(iterOp, backoff.WithContext(backoff.NewConstantBackOff(i.retryInterval), i.ctx)); err != nil {
if err := backoff.Retry(
iterOp,
backoff.WithMaxRetries(
backoff.WithContext(backoff.NewConstantBackOff(i.retryInterval), i.ctx),
BackOffMaxRetries,
),
); err != nil {
return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eventiterator
import (
"context"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -110,7 +111,10 @@ func assembleBlockProposedIteratorCallback(
updateCurrentFunc chainIterator.UpdateCurrentFunc,
endFunc chainIterator.EndIterFunc,
) error {
endHeight := end.Number.Uint64()
var (
endHeight = end.Number.Uint64()
lastBlockID uint64
)

log.Debug("Iterating BlockProposed events", "start", start.Number, "end", endHeight)

Expand All @@ -127,6 +131,20 @@ func assembleBlockProposedIteratorCallback(
event := iterOntake.Event
log.Debug("Processing BlockProposedV2 event", "block", event.BlockId, "l1BlockHeight", event.Raw.BlockNumber)

if lastBlockID != 0 && event.BlockId.Uint64() != lastBlockID+1 {
log.Warn(
"BlockProposedV2 event is not continuous, rescan the L1 chain",
"fromL1Block", start.Number,
"toL1Block", endHeight,
"lastScannedBlockID", lastBlockID,
"currentScannedBlockID", event.BlockId.Uint64(),
)
return fmt.Errorf(
"BlockProposedV2 event is not continuous, lastScannedBlockID: %d, currentScannedBlockID: %d",
lastBlockID, event.BlockId.Uint64(),
)
}

if err := callback(ctx, metadata.NewTaikoDataBlockMetadataOntake(event), eventIter.end); err != nil {
log.Warn("Error while processing BlockProposedV2 events, keep retrying", "error", err)
return err
Expand All @@ -145,6 +163,8 @@ func assembleBlockProposedIteratorCallback(

log.Debug("Updating current block cursor for processing BlockProposedV2 events", "block", current.Number)

lastBlockID = event.BlockId.Uint64()

updateCurrentFunc(current)
}

Expand Down

0 comments on commit b359be0

Please sign in to comment.