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 Aug 9, 2024
1 parent 2aea1c6 commit 7ade322
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 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 @@ -41,6 +41,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 @@ -811,7 +812,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 @@ -833,7 +834,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 @@ -847,7 +848,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 @@ -856,7 +866,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 @@ -870,7 +880,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 @@ -92,7 +92,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 @@ -99,7 +99,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
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
1 change: 1 addition & 0 deletions packages/state-transition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"types": "lib/index.d.ts",
"dependencies": {
"@chainsafe/as-sha256": "^0.5.0",
"@chainsafe/bls": "7.1.3",
"@chainsafe/blst": "^2.0.3",
"@chainsafe/persistent-merkle-tree": "^0.8.0",
"@chainsafe/persistent-ts": "^0.19.1",
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 @@ -105,7 +106,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

0 comments on commit 7ade322

Please sign in to comment.