Skip to content

Commit

Permalink
fix(taiko-client): blob fetching using wrong timestamp (#17754)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed Jul 5, 2024
1 parent 14b50c9 commit 25f4da7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
7 changes: 6 additions & 1 deletion packages/taiko-client/driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ func (s *Syncer) onBlockProposed(
txListFetcher = new(txlistFetcher.CalldataFetcher)
}

txListBytes, err = txListFetcher.Fetch(ctx, tx, &event.Meta)
header, err := s.rpc.L1.HeaderByNumber(ctx, new(big.Int).SetUint64(event.Raw.BlockNumber))
if err != nil {
return fmt.Errorf("failed to get header by number: %w", err)
}

txListBytes, err = txListFetcher.Fetch(ctx, tx, &event.Meta, event.Raw.BlockNumber, header.Time)
if err != nil {
return fmt.Errorf("failed to fetch tx list: %w", err)
}
Expand Down
6 changes: 4 additions & 2 deletions packages/taiko-client/driver/txlist_fetcher/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ func (d *BlobFetcher) Fetch(
ctx context.Context,
_ *types.Transaction,
meta *bindings.TaikoDataBlockMetadata,
emittedInBlockID uint64,
blockProposedEventEmittedInTimestamp uint64,
) ([]byte, error) {
if !meta.BlobUsed {
return nil, pkg.ErrBlobUsed
}

// Fetch the L1 block sidecars.
sidecars, err := d.ds.GetBlobs(ctx, meta)
sidecars, err := d.ds.GetBlobs(ctx, meta, blockProposedEventEmittedInTimestamp)
if err != nil {
return nil, err
}

log.Info("Fetch sidecars", "blockNumber", meta.L1Height+1, "sidecars", len(sidecars))
log.Info("Fetch sidecars", "blockNumber", emittedInBlockID, "sidecars", len(sidecars))

// Compare the blob hash with the sidecar's kzg commitment.
for i, sidecar := range sidecars {
Expand Down
2 changes: 2 additions & 0 deletions packages/taiko-client/driver/txlist_fetcher/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func (d *CalldataFetcher) Fetch(
_ context.Context,
tx *types.Transaction,
meta *bindings.TaikoDataBlockMetadata,
_ uint64,
_ uint64,
) ([]byte, error) {
if meta.BlobUsed {
return nil, pkg.ErrBlobUsed
Expand Down
8 changes: 7 additions & 1 deletion packages/taiko-client/driver/txlist_fetcher/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ import (

// TxListFetcher is responsible for fetching the L2 txList bytes from L1
type TxListFetcher interface {
Fetch(ctx context.Context, tx *types.Transaction, meta *bindings.TaikoDataBlockMetadata) ([]byte, error)
Fetch(
ctx context.Context,
_ *types.Transaction,
meta *bindings.TaikoDataBlockMetadata,
emittedInBlockID uint64,
blockProposedEventEmittedInTimestamp uint64,
) ([]byte, error)
}
3 changes: 2 additions & 1 deletion packages/taiko-client/pkg/rpc/blob_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (p *BlobServerResponse) UnmarshalJSON(data []byte) error {
func (ds *BlobDataSource) GetBlobs(
ctx context.Context,
meta *bindings.TaikoDataBlockMetadata,
emittedInTimestamp uint64,
) ([]*blob.Sidecar, error) {
if !meta.BlobUsed {
return nil, pkg.ErrBlobUnused
Expand All @@ -88,7 +89,7 @@ func (ds *BlobDataSource) GetBlobs(
if ds.client.L1Beacon == nil {
sidecars, err = nil, pkg.ErrBeaconNotFound
} else {
sidecars, err = ds.client.L1Beacon.GetBlobs(ctx, meta.Timestamp)
sidecars, err = ds.client.L1Beacon.GetBlobs(ctx, emittedInTimestamp)
}
if err != nil {
log.Info("Failed to get blobs from beacon, try to use blob server.", "error", err.Error())
Expand Down
1 change: 1 addition & 0 deletions packages/taiko-client/pkg/rpc/blob_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestGetBlobsFromBlobScan(t *testing.T) {
BlobHash: common.HexToHash("0x0145185449c57dee4e6c921b702e5d572fbeb026f96c220a6a17b79d157d921b"),
BlobUsed: true,
},
0,
)
require.Nil(t, err)
require.NotNil(t, sidecars)
Expand Down
10 changes: 0 additions & 10 deletions packages/taiko-client/pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,16 +562,6 @@ func (c *Client) checkSyncedL1SnippetFromAnchor(
return false, err
}

if l1HeightInAnchor+1 != l1Height {
log.Info(
"Reorg detected due to L1 height mismatch",
"blockID", blockID,
"l1HeightInAnchor", l1HeightInAnchor,
"l1Height", l1Height,
)
return true, nil
}

if parentGasUsed != uint32(parent.GasUsed()) {
log.Info(
"Reorg detected due to parent gas used mismatch",
Expand Down

0 comments on commit 25f4da7

Please sign in to comment.