Skip to content

Commit

Permalink
chore(taiko-client): improve BlobFetcher (#18786)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jan 17, 2025
1 parent 65f763b commit fc32df8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/taiko-client/driver/txlist_fetcher/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package txlistdecoder
import (
"context"
"crypto/sha256"
"fmt"
"math/big"

"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -62,11 +64,27 @@ func (d *BlobFetcher) Fetch(
}

if meta.GetBlobTxListLength() == 0 {
return bytes[meta.GetBlobTxListOffset():], nil
return bytes, nil
}
return bytes[meta.GetBlobTxListOffset() : meta.GetBlobTxListOffset()+meta.GetBlobTxListLength()], nil

b, err := sliceTxList(meta.GetBlockID(), bytes, meta.GetBlobTxListOffset(), meta.GetBlobTxListLength())
if err != nil {
log.Warn("Invalid txlist offset and size in metadata", "blockID", meta.GetBlockID(), "err", err)
return []byte{}, nil
}
return b, nil
}
}

return nil, pkg.ErrSidecarNotFound
}

// sliceTxList returns the sliced txList bytes from the given offset and length.
func sliceTxList(id *big.Int, b []byte, offset, length uint32) ([]byte, error) {
if offset+length > uint32(len(b)) {
return nil, fmt.Errorf(
"invalid txlist offset and size in metadata (%d): offset=%d, size=%d, blobSize=%d", id, offset, length, len(b),
)
}
return b[offset : offset+length], nil
}

0 comments on commit fc32df8

Please sign in to comment.