Skip to content

Commit

Permalink
fix(taiko-client): check inner iterator errors in `BlockProposedItera…
Browse files Browse the repository at this point in the history
…tor` (#18757)
  • Loading branch information
davidtaikocha authored Jan 13, 2025
1 parent b01eec1 commit 404efcc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
4 changes: 4 additions & 0 deletions packages/taiko-client/driver/txlist_fetcher/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ func (d *CalldataFetcher) Fetch(
return iter.Event.TxList, nil
}

if iter.Error() != nil {
return nil, fmt.Errorf("failed to fetch calldata for block %d: %w", meta.GetBlockID(), iter.Error())
}

return nil, fmt.Errorf("calldata for block %d not found", meta.GetBlockID())
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ func assembleBlockProposedIteratorCallback(
) error {
endHeight := end.Number.Uint64()

iter, err := taikoL1.FilterBlockProposed(
&bind.FilterOpts{Start: start.Number.Uint64(), End: &endHeight, Context: ctx},
filterQuery,
nil,
)
if err != nil {
return err
}
defer iter.Close()

iterOntake, err := taikoL1.FilterBlockProposedV2(
&bind.FilterOpts{Start: start.Number.Uint64(), End: &endHeight, Context: ctx},
filterQuery,
Expand All @@ -130,26 +120,6 @@ func assembleBlockProposedIteratorCallback(
}
defer iterOntake.Close()

for iter.Next() {
event := iter.Event

if err := callback(ctx, metadata.NewTaikoDataBlockMetadataLegacy(event), eventIter.end); err != nil {
return err
}

if eventIter.isEnd {
endFunc()
return nil
}

current, err := client.HeaderByHash(ctx, event.Raw.BlockHash)
if err != nil {
return err
}

updateCurrentFunc(current)
}

for iterOntake.Next() {
event := iterOntake.Event

Expand All @@ -170,6 +140,6 @@ func assembleBlockProposedIteratorCallback(
updateCurrentFunc(current)
}

return nil
return iterOntake.Error()
}
}
9 changes: 9 additions & 0 deletions packages/taiko-client/pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func (c *Client) ensureGenesisMatched(ctx context.Context) error {
if iter.Next() {
l2GenesisHash = iter.Event.BlockHash
}
if iter.Error() != nil {
return iter.Error()
}
} else {
// Fetch the genesis `BlockVerified` event.
iter, err := c.TaikoL1.FilterBlockVerified(filterOpts, []*big.Int{common.Big0}, nil)
Expand All @@ -84,6 +87,9 @@ func (c *Client) ensureGenesisMatched(ctx context.Context) error {
if iter.Next() {
l2GenesisHash = iter.Event.BlockHash
}
if iter.Error() != nil {
return iter.Error()
}
}

log.Debug("Genesis hash", "node", nodeGenesis.Hash(), "TaikoL1", common.BytesToHash(l2GenesisHash[:]))
Expand Down Expand Up @@ -836,6 +842,9 @@ func (c *Client) GetTaikoDataSlotBByNumber(ctx context.Context, number uint64) (
for iter.Next() {
return &iter.Event.SlotB, nil
}
if iter.Error() != nil {
return nil, fmt.Errorf("failed to get state variables by block number %d: %w", number, iter.Error())
}

return nil, fmt.Errorf("failed to get state variables by block number %d", number)
}
Expand Down

0 comments on commit 404efcc

Please sign in to comment.