-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: blob sink in sandbox without extra process (#11032)
- Loading branch information
Showing
42 changed files
with
390 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
{ | ||
"path": "../bb-prover" | ||
}, | ||
{ | ||
"path": "../blob-sink" | ||
}, | ||
{ | ||
"path": "../circuit-types" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ | |
{ | ||
"path": "../bb-prover" | ||
}, | ||
{ | ||
"path": "../blob-sink" | ||
}, | ||
{ | ||
"path": "../bot" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
yarn-project/blob-sink/src/client/blob-sink-client-tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Blob } from '@aztec/foundation/blob'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
|
||
import { type BlobSinkClientInterface } from './interface.js'; | ||
|
||
/** | ||
* Shared test suite for blob sink clients | ||
* @param createClient - Function that creates a client instance for testing | ||
* @param cleanup - Optional cleanup function to run after each test | ||
*/ | ||
export function runBlobSinkClientTests( | ||
createClient: () => Promise<{ client: BlobSinkClientInterface; cleanup: () => Promise<void> }>, | ||
) { | ||
let client: BlobSinkClientInterface; | ||
let cleanup: () => Promise<void>; | ||
|
||
beforeEach(async () => { | ||
const setup = await createClient(); | ||
client = setup.client; | ||
cleanup = setup.cleanup; | ||
}); | ||
|
||
afterEach(async () => { | ||
await cleanup(); | ||
}); | ||
|
||
it('should send and retrieve blobs', async () => { | ||
const testFields = [Fr.random(), Fr.random(), Fr.random()]; | ||
const blob = Blob.fromFields(testFields); | ||
const blockId = '0x1234'; | ||
|
||
const success = await client.sendBlobsToBlobSink(blockId, [blob]); | ||
expect(success).toBe(true); | ||
|
||
const retrievedBlobs = await client.getBlobSidecar(blockId); | ||
expect(retrievedBlobs).toHaveLength(1); | ||
expect(retrievedBlobs[0].fieldsHash.toString()).toBe(blob.fieldsHash.toString()); | ||
expect(retrievedBlobs[0].commitment.toString('hex')).toBe(blob.commitment.toString('hex')); | ||
}); | ||
|
||
it('should handle multiple blobs', async () => { | ||
const blobs = [ | ||
Blob.fromFields([Fr.random(), Fr.random()]), | ||
Blob.fromFields([Fr.random(), Fr.random()]), | ||
Blob.fromFields([Fr.random(), Fr.random()]), | ||
]; | ||
const blockId = '0x5678'; | ||
|
||
const success = await client.sendBlobsToBlobSink(blockId, blobs); | ||
expect(success).toBe(true); | ||
|
||
const retrievedBlobs = await client.getBlobSidecar(blockId); | ||
expect(retrievedBlobs).toHaveLength(3); | ||
|
||
for (let i = 0; i < blobs.length; i++) { | ||
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 () => { | ||
const blockId = '0xnonexistent'; | ||
const retrievedBlobs = await client.getBlobSidecar(blockId); | ||
expect(retrievedBlobs).toEqual([]); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MemoryBlobStore } from '../blobstore/memory_blob_store.js'; | ||
import { HttpBlobSinkClient } from './http.js'; | ||
import { type BlobSinkClientInterface } from './interface.js'; | ||
import { LocalBlobSinkClient } from './local.js'; | ||
|
||
export function createBlobSinkClient(blobSinkUrl?: string): BlobSinkClientInterface { | ||
if (!blobSinkUrl) { | ||
const blobStore = new MemoryBlobStore(); | ||
return new LocalBlobSinkClient(blobStore); | ||
} | ||
|
||
return new HttpBlobSinkClient(blobSinkUrl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Blob } from '@aztec/foundation/blob'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
|
||
import { BlobSinkServer } from '../server/server.js'; | ||
import { runBlobSinkClientTests } from './blob-sink-client-tests.js'; | ||
import { HttpBlobSinkClient } from './http.js'; | ||
|
||
describe('HttpBlobSinkClient', () => { | ||
runBlobSinkClientTests(async () => { | ||
const server = new BlobSinkServer({ | ||
port: 0, | ||
}); | ||
await server.start(); | ||
|
||
const client = new HttpBlobSinkClient(`http://localhost:${server.port}`); | ||
|
||
return { | ||
client, | ||
cleanup: async () => { | ||
await server.stop(); | ||
}, | ||
}; | ||
}); | ||
|
||
it('should handle server connection errors gracefully', async () => { | ||
const client = new HttpBlobSinkClient('http://localhost:12345'); // Invalid port | ||
const blob = Blob.fromFields([Fr.random()]); | ||
|
||
const success = await client.sendBlobsToBlobSink('0x1234', [blob]); | ||
expect(success).toBe(false); | ||
|
||
const retrievedBlobs = await client.getBlobSidecar('0x1234'); | ||
expect(retrievedBlobs).toEqual([]); | ||
}); | ||
}); |
Oops, something went wrong.