Skip to content

Commit

Permalink
rebase fixes
Browse files Browse the repository at this point in the history
chore: fix bls and blst versioning

fix: add ForkName.electra to ForkBlobsInfo

some api header lookup fixes

more api fixes

make the api data safe

Co-authored-by: matthewkeil <me@matthewkeil.com>
  • Loading branch information
g11tech and matthewkeil committed Jun 21, 2024
1 parent 4239f72 commit 4f800e5
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 16 deletions.
11 changes: 9 additions & 2 deletions packages/api/src/beacon/routes/beacon/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "../../../utils/codecs.js";
import {MetaHeader, VersionCodec, VersionMeta} from "../../../utils/metadata.js";
import {toForkName} from "../../../utils/fork.js";
import {fromHeaders} from "../../../utils/headers.js";

// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

Expand Down Expand Up @@ -247,7 +248,12 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
};
},
parseReqJson: ({body, headers}) => {
const fork = toForkName(headers[MetaHeader.Version]);
const versionHeader = fromHeaders(headers, MetaHeader.Version, false);
const fork =
versionHeader !== undefined
? toForkName(versionHeader)
: config.getForkName(Number((body as {data: {slot: string}}[])[0]?.data.slot ?? 0));

return {
signedAttestations:
ForkSeq[fork] >= ForkSeq.electra
Expand All @@ -266,7 +272,8 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
};
},
parseReqSsz: ({body, headers}) => {
const fork = toForkName(headers[MetaHeader.Version]);
const versionHeader = fromHeaders(headers, MetaHeader.Version, true);
const fork = toForkName(versionHeader);
return {
signedAttestations:
ForkSeq[fork] >= ForkSeq.electra
Expand Down
21 changes: 16 additions & 5 deletions packages/api/src/beacon/routes/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
VersionMeta,
VersionType,
} from "../../utils/metadata.js";
import {fromHeaders} from "../../utils/headers.js";

// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

Expand Down Expand Up @@ -856,7 +857,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
parseReq: ({query}) => ({
attestationDataRoot: fromHexString(query.attestation_data_root),
slot: query.slot,
committeeIndex: query.slot,
committeeIndex: query.committeeIndex,
}),
schema: {
query: {
Expand All @@ -878,7 +879,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
method: "POST",
req: {
writeReqJson: ({signedAggregateAndProofs}) => {
const fork = config.getForkName(signedAggregateAndProofs[0].message.aggregate.data.slot);
const fork = config.getForkName(signedAggregateAndProofs[0]?.message.aggregate.data.slot ?? 0);
return {
body:
ForkSeq[fork] >= ForkSeq.electra
Expand All @@ -892,7 +893,16 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
};
},
parseReqJson: ({body, headers}) => {
const fork = toForkName(headers[MetaHeader.Version]);
const versionHeader = fromHeaders(headers, MetaHeader.Version, false);
const fork =
versionHeader !== undefined
? toForkName(versionHeader)
: config.getForkName(
Number(
(body as {message: {aggregate: {data: {slot: string}}}}[])[0]?.message.aggregate.data.slot ?? 0
)
);

return {
signedAggregateAndProofs:
ForkSeq[fork] >= ForkSeq.electra
Expand All @@ -901,7 +911,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
};
},
writeReqSsz: ({signedAggregateAndProofs}) => {
const fork = config.getForkName(signedAggregateAndProofs[0].message.aggregate.data.slot);
const fork = config.getForkName(signedAggregateAndProofs[0]?.message.aggregate.data.slot ?? 0);
return {
body:
ForkSeq[fork] >= ForkSeq.electra
Expand All @@ -915,7 +925,8 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
};
},
parseReqSsz: ({body, headers}) => {
const fork = toForkName(headers[MetaHeader.Version]);
const versionHeader = fromHeaders(headers, MetaHeader.Version, true);
const fork = toForkName(versionHeader);
return {
signedAggregateAndProofs:
ForkSeq[fork] >= ForkSeq.electra
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 @@ -89,7 +89,7 @@ export const testData: GenericServerTestCases<Endpoints> = {

getPoolAttestations: {
args: {slot: 1, committeeIndex: 2},
res: {data: [ssz.phase0.Attestation.defaultValue()]},
res: {data: [ssz.phase0.Attestation.defaultValue()], meta: {version: ForkName.deneb}},
},
getPoolAttesterSlashings: {
args: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/beacon/testData/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const testData: GenericServerTestCases<Endpoints> = {
res: {data: ssz.altair.SyncCommitteeContribution.defaultValue()},
},
getAggregatedAttestation: {
args: {attestationDataRoot: ZERO_HASH, slot: 32000, index: 2},
args: {attestationDataRoot: ZERO_HASH, slot: 32000, committeeIndex: 2},
res: {data: ssz.phase0.Attestation.defaultValue(), meta: {version: ForkName.phase0}},
},
publishAggregateAndProofs: {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/blocks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export enum GossipedInputType {

type BlobsCacheMap = Map<number, {blobSidecar: deneb.BlobSidecar; blobBytes: Uint8Array | null}>;

type ForkBlobsInfo = {fork: ForkName.deneb};
type ForkBlobsInfo = {fork: ForkName.deneb | ForkName.electra};
type BlobsData = {blobs: deneb.BlobSidecars; blobsBytes: (Uint8Array | null)[]; blobsSource: BlobsSource};
export type BlockInputDataBlobs = ForkBlobsInfo & BlobsData;
export type BlockInputData = BlockInputDataBlobs;
Expand Down
4 changes: 2 additions & 2 deletions packages/light-client/test/unit/webEsmBundle.browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access */
import {expect, describe, it, vi, beforeAll} from "vitest";
import {sleep} from "@lodestar/utils";
import {Lightclient, LightclientEvent, utils, transport} from "../../dist/lightclient.min.mjs";
import {Lightclient, LightclientEvent, utils, transport} from "../../src/index.js";

describe("web bundle for lightclient", () => {
vi.setConfig({testTimeout: 20_000});
Expand Down
4 changes: 2 additions & 2 deletions packages/state-transition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"types": "lib/index.d.ts",
"dependencies": {
"@chainsafe/as-sha256": "^0.4.1",
"@chainsafe/bls": "^8.1.0",
"@chainsafe/blst": "^1.0.0",
"@chainsafe/bls": "7.1.3",
"@chainsafe/blst": "^0.2.11",
"@chainsafe/persistent-merkle-tree": "^0.7.1",
"@chainsafe/ssz": "^0.16.0",
"@lodestar/config": "^1.19.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"blockchain"
],
"dependencies": {
"@chainsafe/bls": "^8.1.0",
"@chainsafe/bls": "7.1.3",
"@chainsafe/ssz": "^0.16.0",
"@lodestar/api": "^1.19.0",
"@lodestar/config": "^1.19.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/validator/test/unit/services/attestation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ssz} from "@lodestar/types";
import {routes} from "@lodestar/api";
import {createChainForkConfig} from "@lodestar/config";
import {config} from "@lodestar/config/default";
import {ForkName} from "@lodestar/params";
import {AttestationService, AttestationServiceOpts} from "../../../src/services/attestation.js";
import {AttDutyAndProof} from "../../../src/services/attestationDuties.js";
import {ValidatorStore} from "../../../src/services/validatorStore.js";
Expand Down Expand Up @@ -100,7 +101,9 @@ describe("AttestationService", function () {

// Mock beacon's attestation and aggregates endpoints
api.validator.produceAttestationData.mockResolvedValue(mockApiResponse({data: attestation.data}));
api.validator.getAggregatedAttestation.mockResolvedValue(mockApiResponse({data: attestation}));
api.validator.getAggregatedAttestation.mockResolvedValue(
mockApiResponse({data: attestation, meta: {version: ForkName.phase0}})
);

api.beacon.submitPoolAttestations.mockResolvedValue(mockApiResponse({}));
api.validator.publishAggregateAndProofs.mockResolvedValue(mockApiResponse({}));
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,13 @@
resolved "https://registry.yarnpkg.com/@types/argparse/-/argparse-1.0.38.tgz#a81fd8606d481f873a3800c6ebae4f1d768a56a9"
integrity sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==

"@types/buffer-xor@^2.0.0":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@types/buffer-xor/-/buffer-xor-2.0.2.tgz#d8c463583b8fbb322ea824562dc78a0c3cea2ca6"
integrity sha512-OqdCua7QCTupPnJgmyGJUpxWgbuOi0IMIVslXTSePS2o+qDrDB6f2Pg44zRyqhUA5GbFAf39U8z0+mH4WG0fLQ==
dependencies:
"@types/node" "*"

"@types/cacheable-request@^6.0.1":
version "6.0.3"
resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.3.tgz#a430b3260466ca7b5ca5bfd735693b36e7a9d183"
Expand Down Expand Up @@ -4435,6 +4442,13 @@ buffer-xor@^1.0.3:
resolved "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz"
integrity sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=

buffer-xor@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-2.0.2.tgz#34f7c64f04c777a1f8aac5e661273bb9dd320289"
integrity sha512-eHslX0bin3GB+Lx2p7lEYRShRewuNZL3fUl4qlVJGGiwoPGftmt8JQgk2Y9Ji5/01TnVDo33E5b5O3vUB1HdqQ==
dependencies:
safe-buffer "^5.1.1"

buffer@4.9.2, buffer@^4.3.0:
version "4.9.2"
resolved "https://registry.npmjs.org/buffer/-/buffer-4.9.2.tgz"
Expand Down

0 comments on commit 4f800e5

Please sign in to comment.