Skip to content

Commit

Permalink
fix: publish electra attestations / aggregates through api (#6759)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored May 13, 2024
1 parent 9c1a4ca commit a5ee6ef
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/beacon/client/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {IHttpClient, generateGenericJsonClient} from "../../utils/client/index.j
/**
* REST HTTP client for validator routes
*/
export function getClient(_config: ChainForkConfig, httpClient: IHttpClient): Api {
const reqSerializers = getReqSerializers();
export function getClient(config: ChainForkConfig, httpClient: IHttpClient): Api {
const reqSerializers = getReqSerializers(config);
const returnTypes = getReturnTypes();
// All routes return JSON, use a client auto-generator
return generateGenericJsonClient<Api, ReqTypes>(routesData, reqSerializers, returnTypes, httpClient);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/beacon/routes/beacon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function getReqSerializers(config: ChainForkConfig) {
return {
getGenesis: reqEmpty,
...block.getReqSerializers(config),
...pool.getReqSerializers(),
...pool.getReqSerializers(config),
...state.getReqSerializers(),
...rewards.getReqSerializers(),
};
Expand Down
20 changes: 17 additions & 3 deletions packages/api/src/beacon/routes/beacon/pool.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {ChainForkConfig} from "@lodestar/config";
import {ForkName} from "@lodestar/params";
import {phase0, altair, capella, CommitteeIndex, Slot, ssz, allForks} from "@lodestar/types";
import {ApiClientResponse} from "../../../interfaces.js";
import {HttpStatusCode} from "../../../utils/client/httpStatusCode.js";
Expand Down Expand Up @@ -159,15 +161,15 @@ export type ReqTypes = {
getPoolProposerSlashings: ReqEmpty;
getPoolVoluntaryExits: ReqEmpty;
getPoolBlsToExecutionChanges: ReqEmpty;
submitPoolAttestations: {body: unknown};
submitPoolAttestations: {body: unknown; headers: {"eth-consensus-version": ForkName}};
submitPoolAttesterSlashings: {body: unknown};
submitPoolProposerSlashings: {body: unknown};
submitPoolVoluntaryExit: {body: unknown};
submitPoolBlsToExecutionChange: {body: unknown};
submitPoolSyncCommitteeSignatures: {body: unknown};
};

export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
export function getReqSerializers(config: ChainForkConfig): ReqSerializers<Api, ReqTypes> {
return {
getPoolAttestations: {
writeReq: (filters) => ({query: {slot: filters?.slot, committee_index: filters?.committeeIndex}}),
Expand All @@ -178,7 +180,19 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
getPoolProposerSlashings: reqEmpty,
getPoolVoluntaryExits: reqEmpty,
getPoolBlsToExecutionChanges: reqEmpty,
submitPoolAttestations: reqOnlyBody(ArrayOf(ssz.phase0.Attestation), Schema.ObjectArray),
submitPoolAttestations: {
writeReq: (attestations) => {
const fork = config.getForkName(attestations[0].data.slot);
return {
body: ArrayOf(ssz.allForks[fork].Attestation).toJson(attestations),
headers: {"eth-consensus-version": fork},
};
},
parseReq: ({body, headers}) => [
ArrayOf(ssz.allForks[headers["eth-consensus-version"]].Attestation).fromJson(body),
],
schema: {body: Schema.ObjectArray},
},
submitPoolAttesterSlashings: reqOnlyBody(ssz.phase0.AttesterSlashing, Schema.Object),
submitPoolProposerSlashings: reqOnlyBody(ssz.phase0.ProposerSlashing, Schema.Object),
submitPoolVoluntaryExit: reqOnlyBody(ssz.phase0.SignedVoluntaryExit, Schema.Object),
Expand Down
19 changes: 16 additions & 3 deletions packages/api/src/beacon/routes/validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ContainerType, fromHexString, toHexString, Type} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {ForkName, ForkBlobs, isForkBlobs, isForkExecution, ForkPreBlobs, ForkExecution} from "@lodestar/params";
import {
allForks,
Expand Down Expand Up @@ -500,7 +501,7 @@ export type ReqTypes = {
produceAttestationData: {query: {slot: number; committee_index: number}};
produceSyncCommitteeContribution: {query: {slot: number; subcommittee_index: number; beacon_block_root: string}};
getAggregatedAttestation: {query: {attestation_data_root: string; slot: number; index: number}};
publishAggregateAndProofs: {body: unknown};
publishAggregateAndProofs: {body: unknown; headers: {"eth-consensus-version": ForkName}};
publishContributionAndProofs: {body: unknown};
prepareBeaconCommitteeSubnet: {body: unknown};
prepareSyncCommitteeSubnets: {body: unknown};
Expand Down Expand Up @@ -530,7 +531,7 @@ const SyncCommitteeSelection = new ContainerType(
{jsonCase: "eth2"}
);

export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
export function getReqSerializers(config: ChainForkConfig): ReqSerializers<Api, ReqTypes> {
const BeaconCommitteeSubscription = new ContainerType(
{
validatorIndex: ssz.ValidatorIndex,
Expand Down Expand Up @@ -655,7 +656,19 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
},
},

publishAggregateAndProofs: reqOnlyBody(ArrayOf(ssz.phase0.SignedAggregateAndProof), Schema.ObjectArray),
publishAggregateAndProofs: {
writeReq: (signedAggregateAndProofs) => {
const fork = config.getForkName(signedAggregateAndProofs[0].message.aggregate.data.slot);
return {
body: ArrayOf(ssz.allForks[fork].SignedAggregateAndProof).toJson(signedAggregateAndProofs),
headers: {"eth-consensus-version": fork},
};
},
parseReq: ({body, headers}) => [
ArrayOf(ssz.allForks[headers["eth-consensus-version"]].SignedAggregateAndProof).fromJson(body),
],
schema: {body: Schema.ObjectArray},
},
publishContributionAndProofs: reqOnlyBody(ArrayOf(ssz.altair.SignedContributionAndProof), Schema.ObjectArray),
prepareBeaconCommitteeSubnet: reqOnlyBody(ArrayOf(BeaconCommitteeSubscription), Schema.ObjectArray),
prepareSyncCommitteeSubnets: reqOnlyBody(ArrayOf(SyncCommitteeSubscription), Schema.ObjectArray),
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/beacon/server/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {ServerRoutes, getGenericJsonServer} from "../../utils/server/index.js";
import {ServerApi} from "../../interfaces.js";

export function getRoutes(config: ChainForkConfig, api: ServerApi<Api>): ServerRoutes<Api, ReqTypes> {
const reqSerializers = getReqSerializers();
const reqSerializers = getReqSerializers(config);
const returnTypes = getReturnTypes();

// Most of routes return JSON, use a server auto-generator
Expand Down

0 comments on commit a5ee6ef

Please sign in to comment.