Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(taiko-client): ensure event block IDs are continuous #18775

Merged
merged 4 commits into from
Jan 15, 2025
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
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
Loading