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

fix(taiko-client): blob fetching using wrong timestamp #17754

Merged
merged 10 commits into from
Jul 5, 2024
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
4 changes: 3 additions & 1 deletion packages/taiko-client/driver/txlist_fetcher/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ type CalldataFetcher struct{}

// NewCalldataTxListFetcher creates a new CalldataFetcher instance.
func (d *CalldataFetcher) Fetch(
_ context.Context,
ctx context.Context,
tx *types.Transaction,
meta *bindings.TaikoDataBlockMetadata,
emittedInBlockID uint64,
blockProposedEventEmittedInTimestamp 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
Loading