From 3a4ac5fd7412dd4285826b434dc76d01de99635f Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:58:27 +0000 Subject: [PATCH] rebase --- .../blob-sink/src/client/blob-sink-client-tests.ts | 6 ++++++ yarn-project/blob-sink/src/client/factory.ts | 1 - yarn-project/blob-sink/src/client/http.test.ts | 2 +- yarn-project/blob-sink/src/client/http.ts | 9 +++++++-- yarn-project/blob-sink/src/client/interface.ts | 4 ++-- yarn-project/blob-sink/src/client/local.ts | 4 ++-- yarn-project/blob-sink/src/server/server.ts | 4 +--- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/yarn-project/blob-sink/src/client/blob-sink-client-tests.ts b/yarn-project/blob-sink/src/client/blob-sink-client-tests.ts index f367445555d7..3e77a5ffe6b8 100644 --- a/yarn-project/blob-sink/src/client/blob-sink-client-tests.ts +++ b/yarn-project/blob-sink/src/client/blob-sink-client-tests.ts @@ -56,6 +56,12 @@ export function runBlobSinkClientTests( expect(retrievedBlobs[i].fieldsHash.toString()).toBe(blobs[i].fieldsHash.toString()); expect(retrievedBlobs[i].commitment.toString('hex')).toBe(blobs[i].commitment.toString('hex')); } + + // Can request blobs by index + const retrievedBlobsByIndex = await client.getBlobSidecar(blockId, [0, 2]); + expect(retrievedBlobsByIndex).toHaveLength(2); + expect(retrievedBlobsByIndex[0].fieldsHash.toString()).toBe(blobs[0].fieldsHash.toString()); + expect(retrievedBlobsByIndex[1].fieldsHash.toString()).toBe(blobs[2].fieldsHash.toString()); }); it('should return empty array for non-existent block', async () => { diff --git a/yarn-project/blob-sink/src/client/factory.ts b/yarn-project/blob-sink/src/client/factory.ts index 48ed1757f283..796746a0ed89 100644 --- a/yarn-project/blob-sink/src/client/factory.ts +++ b/yarn-project/blob-sink/src/client/factory.ts @@ -5,7 +5,6 @@ import { LocalBlobSinkClient } from './local.js'; export function createBlobSinkClient(blobSinkUrl?: string): BlobSinkClientInterface { if (!blobSinkUrl) { - // TODO: persist to disk const blobStore = new MemoryBlobStore(); return new LocalBlobSinkClient(blobStore); } diff --git a/yarn-project/blob-sink/src/client/http.test.ts b/yarn-project/blob-sink/src/client/http.test.ts index 128853d7692d..10e117ea29f3 100644 --- a/yarn-project/blob-sink/src/client/http.test.ts +++ b/yarn-project/blob-sink/src/client/http.test.ts @@ -8,7 +8,7 @@ import { HttpBlobSinkClient } from './http.js'; describe('HttpBlobSinkClient', () => { runBlobSinkClientTests(async () => { const server = new BlobSinkServer({ - port: 8888, + port: 33333, }); await server.start(); diff --git a/yarn-project/blob-sink/src/client/http.ts b/yarn-project/blob-sink/src/client/http.ts index 316c8f6cee35..29539a05a28f 100644 --- a/yarn-project/blob-sink/src/client/http.ts +++ b/yarn-project/blob-sink/src/client/http.ts @@ -44,14 +44,19 @@ export class HttpBlobSinkClient implements BlobSinkClientInterface { } } - public async getBlobSidecar(blockHash: string): Promise { + public async getBlobSidecar(blockHash: string, indices?: number[]): Promise { if (!this.blobSinkUrl) { this.log.verbose('No blob sink url configured'); return []; } try { - const res = await fetch(`${this.blobSinkUrl}/eth/v1/beacon/blob_sidecars/${blockHash}`); + let url = `${this.blobSinkUrl}/eth/v1/beacon/blob_sidecars/${blockHash}`; + if (indices && indices.length > 0) { + url += `?indices=${indices.join(',')}`; + } + + const res = await fetch(url); if (res.ok) { const body = await res.json(); diff --git a/yarn-project/blob-sink/src/client/interface.ts b/yarn-project/blob-sink/src/client/interface.ts index 6f19b48213ea..c98e450a6bcb 100644 --- a/yarn-project/blob-sink/src/client/interface.ts +++ b/yarn-project/blob-sink/src/client/interface.ts @@ -1,6 +1,6 @@ import { type Blob } from '@aztec/foundation/blob'; export interface BlobSinkClientInterface { - sendBlobsToBlobSink(blockHash: string, blobs: Blob[]): Promise; - getBlobSidecar(blockHash: string): Promise; + sendBlobsToBlobSink(blockId: string, blobs: Blob[]): Promise; + getBlobSidecar(blockId: string, indices?: number[]): Promise; } diff --git a/yarn-project/blob-sink/src/client/local.ts b/yarn-project/blob-sink/src/client/local.ts index 70f7ead3681d..df18903a611f 100644 --- a/yarn-project/blob-sink/src/client/local.ts +++ b/yarn-project/blob-sink/src/client/local.ts @@ -19,8 +19,8 @@ export class LocalBlobSinkClient implements BlobSinkClientInterface { return true; } - public async getBlobSidecar(blockId: string): Promise { - const blobSidecars = await this.blobStore.getBlobSidecars(blockId); + public async getBlobSidecar(blockId: string, indices?: number[]): Promise { + const blobSidecars = await this.blobStore.getBlobSidecars(blockId, indices); if (!blobSidecars) { return []; } diff --git a/yarn-project/blob-sink/src/server/server.ts b/yarn-project/blob-sink/src/server/server.ts index e0fc195bc74c..030f58d147ad 100644 --- a/yarn-project/blob-sink/src/server/server.ts +++ b/yarn-project/blob-sink/src/server/server.ts @@ -10,12 +10,10 @@ import { z } from 'zod'; import { type BlobStore, DiskBlobStore } from '../blobstore/index.js'; import { MemoryBlobStore } from '../blobstore/memory_blob_store.js'; -import { type PostBlobSidecarRequest, blockIdSchema } from '../types/api.js'; +import { type PostBlobSidecarRequest, blockIdSchema, indicesSchema } from '../types/api.js'; import { BlobWithIndex } from '../types/index.js'; import { type BlobSinkConfig } from './config.js'; import { BlobSinkMetrics } from './metrics.js'; -import { type PostBlobSidecarRequest, blockIdSchema, indicesSchema } from './types/api.js'; -import { BlobWithIndex } from './types/index.js'; /** * Example usage: