Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: blob sidecars can be filtered by indices #6337

Merged
merged 8 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/api/src/beacon/routes/beacon/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,12 @@ export type Api = {
* Retrieves BlobSidecar included in requested block.
* @param blockId Block identifier.
* Can be one of: "head" (canonical head in node's view), "genesis", "finalized", \<slot\>, \<hex encoded blockRoot with 0x prefix\>.
* @param indices Array of indices for blob sidecars to request for in the specified block. Returns all blob sidecars in the block if not specified.
*/
getBlobSidecars(blockId: BlockId): Promise<
getBlobSidecars(
blockId: BlockId,
indices?: string[]
jeluard marked this conversation as resolved.
Show resolved Hide resolved
): Promise<
ApiClientResponse<{
[HttpStatusCode.OK]: {executionOptimistic: ExecutionOptimistic; data: deneb.BlobSidecars};
}>
Expand Down Expand Up @@ -270,7 +274,7 @@ export type ReqTypes = {
publishBlockV2: {body: unknown; query: {broadcast_validation?: string}};
publishBlindedBlock: {body: unknown};
publishBlindedBlockV2: {body: unknown; query: {broadcast_validation?: string}};
getBlobSidecars: BlockIdOnlyReq;
getBlobSidecars: {params: {block_id: string}; query: {indices?: string[]}};
jeluard marked this conversation as resolved.
Show resolved Hide resolved
};

export function getReqSerializers(config: ChainForkConfig): ReqSerializers<Api, ReqTypes> {
Expand Down Expand Up @@ -356,7 +360,16 @@ export function getReqSerializers(config: ChainForkConfig): ReqSerializers<Api,
query: {broadcast_validation: Schema.String},
},
},
getBlobSidecars: blockIdOnlyReq,
getBlobSidecars: {
writeReq: (block_id, indices = []) => ({
params: {block_id: String(block_id)},
query: {indices},
}),
parseReq: ({params, query}) => [params.block_id, query.indices],
schema: {
query: {indices: Schema.StringArray},
jeluard marked this conversation as resolved.
Show resolved Hide resolved
},
},
};
}

Expand Down
6 changes: 0 additions & 6 deletions packages/api/test/unit/beacon/oapiSpec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ const ignoredProperties: Record<string, IgnoredProperty> = {
*/
getHealth: {request: ["query.syncing_status"]},

/**
* https://github.com/ChainSafe/lodestar/issues/6185
* - must have required property 'query'
*/
getBlobSidecars: {request: ["query"]},

/*
https://github.com/ChainSafe/lodestar/issues/4638
/query - must have required property 'skip_randao_verification'
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/beacon/testData/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const testData: GenericServerTestCases<Api> = {
res: undefined,
},
getBlobSidecars: {
args: ["head"],
args: ["head", ["0"]],
res: {executionOptimistic: true, data: ssz.deneb.BlobSidecars.defaultValue()},
},

Expand Down
7 changes: 5 additions & 2 deletions packages/beacon-node/src/api/impl/beacon/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export function getBeaconBlockApi({
await publishBlock(signedBlockOrContents, opts);
},

async getBlobSidecars(blockId) {
async getBlobSidecars(blockId, indices = []) {
jeluard marked this conversation as resolved.
Show resolved Hide resolved
const {block, executionOptimistic} = await resolveBlockId(chain, blockId);
const blockRoot = config.getForkTypes(block.message.slot).BeaconBlock.hashTreeRoot(block.message);

Expand All @@ -418,9 +418,12 @@ export function getBeaconBlockApi({
if (!blobSidecars) {
throw Error(`blobSidecars not found in db for slot=${block.message.slot} root=${toHexString(blockRoot)}`);
}

const indicesSet = new Set(indices?.map((index) => parseInt(index)));
jeluard marked this conversation as resolved.
Show resolved Hide resolved
jeluard marked this conversation as resolved.
Show resolved Hide resolved
return {
executionOptimistic,
data: blobSidecars,
// Returnonly all sidecars if no indices are specified, only the requested ones (identified by `indices`) otherwise
data: indicesSet.size == 0 ? blobSidecars : blobSidecars.filter(({index}) => indicesSet.has(index)),
};
},
};
Expand Down