Skip to content

Commit

Permalink
Merge pull request #2193 from OffchainLabs/improve-errorlogging-blobr…
Browse files Browse the repository at this point in the history
…eader

Improve error logging when blob client fails to read blobs from beacon-URL [NIT-2318]
  • Loading branch information
ganeshvanahalli authored Mar 18, 2024
2 parents f8a598c + fd1eef6 commit ad9ab00
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions util/headerreader/blob_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/log"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/util/blobs"
"github.com/offchainlabs/nitro/util/jsonapi"
Expand Down Expand Up @@ -133,7 +134,11 @@ func (b *BlobClient) GetBlobs(ctx context.Context, blockHash common.Hash, versio
return nil, errors.New("BlobClient hasn't been initialized")
}
slot := (header.Time - b.genesisTime) / b.secondsPerSlot
return b.blobSidecars(ctx, slot, versionedHashes)
blobs, err := b.blobSidecars(ctx, slot, versionedHashes)
if err != nil {
return nil, fmt.Errorf("error fetching blobs in %d l1 block: %w", header.Number, err)
}
return blobs, nil
}

type blobResponseItem struct {
Expand All @@ -147,14 +152,22 @@ type blobResponseItem struct {
KzgProof hexutil.Bytes `json:"kzg_proof"`
}

const trailingCharsOfResponse = 25

func (b *BlobClient) blobSidecars(ctx context.Context, slot uint64, versionedHashes []common.Hash) ([]kzg4844.Blob, error) {
rawData, err := beaconRequest[json.RawMessage](b, ctx, fmt.Sprintf("/eth/v1/beacon/blob_sidecars/%d", slot))
if err != nil {
return nil, fmt.Errorf("error calling beacon client in blobSidecars: %w", err)
}
var response []blobResponseItem
if err := json.Unmarshal(rawData, &response); err != nil {
return nil, fmt.Errorf("error unmarshalling raw data into array of blobResponseItem in blobSidecars: %w", err)
rawDataStr := string(rawData)
log.Debug("response from beacon URL cannot be unmarshalled into array of blobResponseItem in blobSidecars", "slot", slot, "responseLength", len(rawDataStr), "response", rawDataStr)
if len(rawDataStr) > 100 {
return nil, fmt.Errorf("error unmarshalling response from beacon URL into array of blobResponseItem in blobSidecars: %w. Trailing %d characters of the response: %s", err, trailingCharsOfResponse, rawDataStr[len(rawDataStr)-trailingCharsOfResponse:])
} else {
return nil, fmt.Errorf("error unmarshalling response from beacon URL into array of blobResponseItem in blobSidecars: %w. Response: %s", err, rawDataStr)
}
}

if len(response) < len(versionedHashes) {
Expand Down

0 comments on commit ad9ab00

Please sign in to comment.