Skip to content

Commit

Permalink
refactor: getDataColumnSidecars for PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkeil committed Sep 9, 2024
1 parent dc44577 commit 1f88c54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
36 changes: 17 additions & 19 deletions packages/beacon-node/src/util/blobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export function getDataColumnSidecars(
contents: deneb.Contents & {kzgCommitmentsInclusionProof?: peerdas.KzgCommitmentsInclusionProof}
): peerdas.DataColumnSidecars {
const blobKzgCommitments = (signedBlock as deneb.SignedBeaconBlock).message.body.blobKzgCommitments;
const {blobs} = contents;
if (!Array.isArray(blobs)) {
throw Error("Invalid block with missing blobs for computeBlobSidecars");
}
if (blobKzgCommitments === undefined) {
throw Error("Invalid block with missing blobKzgCommitments for computeBlobSidecars");
}
Expand All @@ -86,25 +90,19 @@ export function getDataColumnSidecars(
const signedBlockHeader = signedBlockToSignedHeader(config, signedBlock);
const kzgCommitmentsInclusionProof =
contents.kzgCommitmentsInclusionProof ?? computeKzgCommitmentsInclusionProof(fork, signedBlock.message.body);
const cellsAndProofs = blobs.map((blob) => ckzg.computeCellsAndKzgProofs(blob));

const dataColumnSidecar = {
index: j,
column,
kzgCommitments: blobKzgCommitments,
kzgProofs,
signedBlockHeader,
kzgCommitmentsInclusionProof,
} as peerdas.DataColumnSidecar;

contents.blobs.map(ckzg.computeCellsAndKzgProofs).forEach(([cells, proofs], rowNumber) => {
cells.map((cell, columnNumber) => {
if (rowNumber === 0) {
sidecars[columnNumber].index = columnNumber;
}
sidecars[columnNumber].column[rowNumber] = cell;
sidecars[columnNumber].kzgProofs[rowNumber] = proofs[columnNumber];
});
return Array.from({length: NUMBER_OF_COLUMNS}, (_, columnIndex) => {
// columnIndex'th column
const column = Array.from({length: blobs.length}, (_, rowNumber) => cellsAndProofs[rowNumber][0][columnIndex]);
const kzgProofs = Array.from({length: blobs.length}, (_, rowNumber) => cellsAndProofs[rowNumber][1][columnIndex]);
return {
index: columnIndex,
column,
kzgCommitments: blobKzgCommitments,
kzgProofs,
signedBlockHeader,
kzgCommitmentsInclusionProof,
};
});

return sidecars;
}
1 change: 0 additions & 1 deletion packages/beacon-node/test/unit/util/kzg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {computeBlobSidecars, getDataColumnSidecars, kzgCommitmentToVersionedHash
import {loadEthereumTrustedSetup, initCKZG, ckzg, FIELD_ELEMENTS_PER_BLOB_MAINNET} from "../../../src/util/kzg.js";
import {validateBlobSidecars, validateGossipBlobSidecar} from "../../../src/chain/validation/blobSidecar.js";
import {getBlobCellAndProofs} from "../../utils/getBlobCellAndProofs.js";
import {linspace} from "../../../src/util/numpy.js";

describe("C-KZG", () => {
const afterEachCallbacks: (() => Promise<unknown> | void)[] = [];
Expand Down

0 comments on commit 1f88c54

Please sign in to comment.