From 7aa620d6755baf40bdc55428a671f56804bf93fb Mon Sep 17 00:00:00 2001 From: David Date: Mon, 13 Jan 2025 14:00:38 +0800 Subject: [PATCH 1/3] fix(taiko-client): check inner iterator errors in `BlockProposedIterator` --- .../event_iterator/block_proposed_iterator.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go b/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go index 67fc0fea23d..e33fc4a5af9 100644 --- a/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go +++ b/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go @@ -170,6 +170,14 @@ func assembleBlockProposedIteratorCallback( updateCurrentFunc(current) } + // Check iterator errors. + if iter.Error() != nil { + return iter.Error() + } + if iterOntake.Error() != nil { + return iter.Error() + } + return nil } } From 3e63d01d1f2a02cdd9dbdf68251e1a9216a31eec Mon Sep 17 00:00:00 2001 From: David Date: Mon, 13 Jan 2025 14:07:45 +0800 Subject: [PATCH 2/3] feat: remove unused iter --- .../event_iterator/block_proposed_iterator.go | 35 +------------------ 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go b/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go index e33fc4a5af9..3a319cfd520 100644 --- a/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go +++ b/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go @@ -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, @@ -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 @@ -171,11 +141,8 @@ func assembleBlockProposedIteratorCallback( } // Check iterator errors. - if iter.Error() != nil { - return iter.Error() - } if iterOntake.Error() != nil { - return iter.Error() + return iterOntake.Error() } return nil From 6f4668b22ee1642983db74b39e8917e43f67320b Mon Sep 17 00:00:00 2001 From: David Date: Mon, 13 Jan 2025 14:32:24 +0800 Subject: [PATCH 3/3] feat: more checks --- packages/taiko-client/driver/txlist_fetcher/calldata.go | 4 ++++ .../event_iterator/block_proposed_iterator.go | 7 +------ packages/taiko-client/pkg/rpc/methods.go | 9 +++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/taiko-client/driver/txlist_fetcher/calldata.go b/packages/taiko-client/driver/txlist_fetcher/calldata.go index 7beee95e99b..9f8de41548e 100644 --- a/packages/taiko-client/driver/txlist_fetcher/calldata.go +++ b/packages/taiko-client/driver/txlist_fetcher/calldata.go @@ -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()) } diff --git a/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go b/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go index 3a319cfd520..be350e5aeeb 100644 --- a/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go +++ b/packages/taiko-client/pkg/chain_iterator/event_iterator/block_proposed_iterator.go @@ -140,11 +140,6 @@ func assembleBlockProposedIteratorCallback( updateCurrentFunc(current) } - // Check iterator errors. - if iterOntake.Error() != nil { - return iterOntake.Error() - } - - return nil + return iterOntake.Error() } } diff --git a/packages/taiko-client/pkg/rpc/methods.go b/packages/taiko-client/pkg/rpc/methods.go index 824eaceaae6..6ce4278dd81 100644 --- a/packages/taiko-client/pkg/rpc/methods.go +++ b/packages/taiko-client/pkg/rpc/methods.go @@ -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) @@ -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[:])) @@ -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) }