Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Jan 3, 2025
1 parent b79116c commit 3a4ac5f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions yarn-project/blob-sink/src/client/blob-sink-client-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
1 change: 0 additions & 1 deletion yarn-project/blob-sink/src/client/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/blob-sink/src/client/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { HttpBlobSinkClient } from './http.js';
describe('HttpBlobSinkClient', () => {
runBlobSinkClientTests(async () => {
const server = new BlobSinkServer({
port: 8888,
port: 33333,
});
await server.start();

Expand Down
9 changes: 7 additions & 2 deletions yarn-project/blob-sink/src/client/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ export class HttpBlobSinkClient implements BlobSinkClientInterface {
}
}

public async getBlobSidecar(blockHash: string): Promise<Blob[]> {
public async getBlobSidecar(blockHash: string, indices?: number[]): Promise<Blob[]> {
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();
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/blob-sink/src/client/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Blob } from '@aztec/foundation/blob';

export interface BlobSinkClientInterface {
sendBlobsToBlobSink(blockHash: string, blobs: Blob[]): Promise<boolean>;
getBlobSidecar(blockHash: string): Promise<Blob[]>;
sendBlobsToBlobSink(blockId: string, blobs: Blob[]): Promise<boolean>;
getBlobSidecar(blockId: string, indices?: number[]): Promise<Blob[]>;
}
4 changes: 2 additions & 2 deletions yarn-project/blob-sink/src/client/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class LocalBlobSinkClient implements BlobSinkClientInterface {
return true;
}

public async getBlobSidecar(blockId: string): Promise<Blob[]> {
const blobSidecars = await this.blobStore.getBlobSidecars(blockId);
public async getBlobSidecar(blockId: string, indices?: number[]): Promise<Blob[]> {
const blobSidecars = await this.blobStore.getBlobSidecars(blockId, indices);
if (!blobSidecars) {
return [];
}
Expand Down
4 changes: 1 addition & 3 deletions yarn-project/blob-sink/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3a4ac5f

Please sign in to comment.