Skip to content

Commit

Permalink
Fix operationId of bls_to_execution_changes routes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluard committed Dec 8, 2023
1 parent 91cd2af commit ad53c2d
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 105 deletions.
18 changes: 9 additions & 9 deletions packages/api/src/beacon/routes/beacon/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type Api = {
* @returns any Successful response
* @throws ApiError
*/
getPoolBlsToExecutionChanges(): Promise<
getPoolBLSToExecutionChanges(): Promise<
ApiClientResponse<{[HttpStatusCode.OK]: {data: capella.SignedBLSToExecutionChange[]}}>
>;

Expand Down Expand Up @@ -123,7 +123,7 @@ export type Api = {
* @returns any BLSToExecutionChange is stored in node and broadcasted to network
* @throws ApiError
*/
submitPoolBlsToExecutionChange(
submitPoolBLSToExecutionChange(
blsToExecutionChange: capella.SignedBLSToExecutionChange[]
): Promise<ApiClientResponse<{[HttpStatusCode.OK]: void}, HttpStatusCode.BAD_REQUEST>>;

Expand All @@ -143,12 +143,12 @@ export const routesData: RoutesData<Api> = {
getPoolAttesterSlashings: {url: "/eth/v1/beacon/pool/attester_slashings", method: "GET"},
getPoolProposerSlashings: {url: "/eth/v1/beacon/pool/proposer_slashings", method: "GET"},
getPoolVoluntaryExits: {url: "/eth/v1/beacon/pool/voluntary_exits", method: "GET"},
getPoolBlsToExecutionChanges: {url: "/eth/v1/beacon/pool/bls_to_execution_changes", method: "GET"},
getPoolBLSToExecutionChanges: {url: "/eth/v1/beacon/pool/bls_to_execution_changes", method: "GET"},
submitPoolAttestations: {url: "/eth/v1/beacon/pool/attestations", method: "POST"},
submitPoolAttesterSlashings: {url: "/eth/v1/beacon/pool/attester_slashings", method: "POST"},
submitPoolProposerSlashings: {url: "/eth/v1/beacon/pool/proposer_slashings", method: "POST"},
submitPoolVoluntaryExit: {url: "/eth/v1/beacon/pool/voluntary_exits", method: "POST"},
submitPoolBlsToExecutionChange: {url: "/eth/v1/beacon/pool/bls_to_execution_changes", method: "POST"},
submitPoolBLSToExecutionChange: {url: "/eth/v1/beacon/pool/bls_to_execution_changes", method: "POST"},
submitPoolSyncCommitteeSignatures: {url: "/eth/v1/beacon/pool/sync_committees", method: "POST"},
};

Expand All @@ -158,12 +158,12 @@ export type ReqTypes = {
getPoolAttesterSlashings: ReqEmpty;
getPoolProposerSlashings: ReqEmpty;
getPoolVoluntaryExits: ReqEmpty;
getPoolBlsToExecutionChanges: ReqEmpty;
getPoolBLSToExecutionChanges: ReqEmpty;
submitPoolAttestations: {body: unknown};
submitPoolAttesterSlashings: {body: unknown};
submitPoolProposerSlashings: {body: unknown};
submitPoolVoluntaryExit: {body: unknown};
submitPoolBlsToExecutionChange: {body: unknown};
submitPoolBLSToExecutionChange: {body: unknown};
submitPoolSyncCommitteeSignatures: {body: unknown};
};

Expand All @@ -177,12 +177,12 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
getPoolAttesterSlashings: reqEmpty,
getPoolProposerSlashings: reqEmpty,
getPoolVoluntaryExits: reqEmpty,
getPoolBlsToExecutionChanges: reqEmpty,
getPoolBLSToExecutionChanges: reqEmpty,
submitPoolAttestations: reqOnlyBody(ArrayOf(ssz.phase0.Attestation), Schema.ObjectArray),
submitPoolAttesterSlashings: reqOnlyBody(ssz.phase0.AttesterSlashing, Schema.Object),
submitPoolProposerSlashings: reqOnlyBody(ssz.phase0.ProposerSlashing, Schema.Object),
submitPoolVoluntaryExit: reqOnlyBody(ssz.phase0.SignedVoluntaryExit, Schema.Object),
submitPoolBlsToExecutionChange: reqOnlyBody(ArrayOf(ssz.capella.SignedBLSToExecutionChange), Schema.ObjectArray),
submitPoolBLSToExecutionChange: reqOnlyBody(ArrayOf(ssz.capella.SignedBLSToExecutionChange), Schema.ObjectArray),
submitPoolSyncCommitteeSignatures: reqOnlyBody(ArrayOf(ssz.altair.SyncCommitteeMessage), Schema.ObjectArray),
};
}
Expand All @@ -193,6 +193,6 @@ export function getReturnTypes(): ReturnTypes<Api> {
getPoolAttesterSlashings: ContainerData(ArrayOf(ssz.phase0.AttesterSlashing)),
getPoolProposerSlashings: ContainerData(ArrayOf(ssz.phase0.ProposerSlashing)),
getPoolVoluntaryExits: ContainerData(ArrayOf(ssz.phase0.SignedVoluntaryExit)),
getPoolBlsToExecutionChanges: ContainerData(ArrayOf(ssz.capella.SignedBLSToExecutionChange)),
getPoolBLSToExecutionChanges: ContainerData(ArrayOf(ssz.capella.SignedBLSToExecutionChange)),
};
}
4 changes: 2 additions & 2 deletions packages/api/test/unit/beacon/testData/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const testData: GenericServerTestCases<Api> = {
args: [],
res: {data: [ssz.phase0.SignedVoluntaryExit.defaultValue()]},
},
getPoolBlsToExecutionChanges: {
getPoolBLSToExecutionChanges: {
args: [],
res: {data: [ssz.capella.SignedBLSToExecutionChange.defaultValue()]},
},
Expand All @@ -113,7 +113,7 @@ export const testData: GenericServerTestCases<Api> = {
args: [ssz.phase0.SignedVoluntaryExit.defaultValue()],
res: undefined,
},
submitPoolBlsToExecutionChange: {
submitPoolBLSToExecutionChange: {
args: [[ssz.capella.SignedBLSToExecutionChange.defaultValue()]],
res: undefined,
},
Expand Down
18 changes: 9 additions & 9 deletions packages/beacon-node/src/api/impl/beacon/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {validateApiAttestation} from "../../../../chain/validation/index.js";
import {validateApiAttesterSlashing} from "../../../../chain/validation/attesterSlashing.js";
import {validateApiProposerSlashing} from "../../../../chain/validation/proposerSlashing.js";
import {validateApiVoluntaryExit} from "../../../../chain/validation/voluntaryExit.js";
import {validateApiBlsToExecutionChange} from "../../../../chain/validation/blsToExecutionChange.js";
import {validateApiBLSToExecutionChange} from "../../../../chain/validation/blsToExecutionChange.js";
import {validateApiSyncCommittee} from "../../../../chain/validation/syncCommittee.js";
import {ApiModules} from "../../types.js";
import {AttestationError, GossipAction, SyncCommitteeError} from "../../../../chain/errors/index.js";
Expand Down Expand Up @@ -41,8 +41,8 @@ export function getBeaconPoolApi({
return {data: chain.opPool.getAllVoluntaryExits()};
},

async getPoolBlsToExecutionChanges() {
return {data: chain.opPool.getAllBlsToExecutionChanges().map(({data}) => data)};
async getPoolBLSToExecutionChanges() {
return {data: chain.opPool.getAllBLSToExecutionChanges().map(({data}) => data)};
},

async submitPoolAttestations(attestations) {
Expand Down Expand Up @@ -116,26 +116,26 @@ export function getBeaconPoolApi({
await network.publishVoluntaryExit(voluntaryExit);
},

async submitPoolBlsToExecutionChange(blsToExecutionChanges) {
async submitPoolBLSToExecutionChange(blsToExecutionChanges) {
const errors: Error[] = [];

await Promise.all(
blsToExecutionChanges.map(async (blsToExecutionChange, i) => {
try {
// Ignore even if the change exists and reprocess
await validateApiBlsToExecutionChange(chain, blsToExecutionChange);
await validateApiBLSToExecutionChange(chain, blsToExecutionChange);
const preCapella = chain.clock.currentEpoch < chain.config.CAPELLA_FORK_EPOCH;
chain.opPool.insertBlsToExecutionChange(blsToExecutionChange, preCapella);
chain.opPool.insertBLSToExecutionChange(blsToExecutionChange, preCapella);

chain.emitter.emit(routes.events.EventType.blsToExecutionChange, blsToExecutionChange);

if (!preCapella) {
await network.publishBlsToExecutionChange(blsToExecutionChange);
await network.publishBLSToExecutionChange(blsToExecutionChange);
}
} catch (e) {
errors.push(e as Error);
logger.error(
`Error on submitPoolBlsToExecutionChange [${i}]`,
`Error on submitPoolBLSToExecutionChange [${i}]`,
{validatorIndex: blsToExecutionChange.message.validatorIndex},
e as Error
);
Expand All @@ -144,7 +144,7 @@ export function getBeaconPoolApi({
);

if (errors.length > 1) {
throw Error("Multiple errors on submitPoolBlsToExecutionChange\n" + errors.map((e) => e.message).join("\n"));
throw Error("Multiple errors on submitPoolBLSToExecutionChange\n" + errors.map((e) => e.message).join("\n"));
} else if (errors.length === 1) {
throw errors[0];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {GossipActionError} from "./gossipValidation.js";

export enum BlsToExecutionChangeErrorCode {
export enum BLSToExecutionChangeErrorCode {
ALREADY_EXISTS = "BLS_TO_EXECUTION_CHANGE_ERROR_ALREADY_EXISTS",
INVALID = "BLS_TO_EXECUTION_CHANGE_ERROR_INVALID",
INVALID_SIGNATURE = "BLS_TO_EXECUTION_CHANGE_ERROR_INVALID_SIGNATURE",
}
export type BlsToExecutionChangeErrorType =
| {code: BlsToExecutionChangeErrorCode.ALREADY_EXISTS}
| {code: BlsToExecutionChangeErrorCode.INVALID}
| {code: BlsToExecutionChangeErrorCode.INVALID_SIGNATURE};
export type BLSToExecutionChangeErrorType =
| {code: BLSToExecutionChangeErrorCode.ALREADY_EXISTS}
| {code: BLSToExecutionChangeErrorCode.INVALID}
| {code: BLSToExecutionChangeErrorCode.INVALID_SIGNATURE};

export class BlsToExecutionChangeError extends GossipActionError<BlsToExecutionChangeErrorType> {}
export class BLSToExecutionChangeError extends GossipActionError<BLSToExecutionChangeErrorType> {}
18 changes: 9 additions & 9 deletions packages/beacon-node/src/chain/opPools/opPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {IBeaconDb} from "../../db/index.js";
import {SignedBLSToExecutionChangeVersioned} from "../../util/types.js";
import {BlockType} from "../interface.js";
import {Metrics} from "../../metrics/metrics.js";
import {isValidBlsToExecutionChangeForBlockInclusion} from "./utils.js";
import {isValidBLSToExecutionChangeForBlockInclusion} from "./utils.js";

type HexRoot = string;
type AttesterSlashingCached = {
Expand Down Expand Up @@ -72,7 +72,7 @@ export class OpPool {
this.insertVoluntaryExit(voluntaryExit);
}
for (const item of blsToExecutionChanges) {
this.insertBlsToExecutionChange(item.data, item.preCapella);
this.insertBLSToExecutionChange(item.data, item.preCapella);
}
}

Expand Down Expand Up @@ -120,7 +120,7 @@ export class OpPool {
return this.voluntaryExits.has(validatorIndex);
}

hasSeenBlsToExecutionChange(validatorIndex: ValidatorIndex): boolean {
hasSeenBLSToExecutionChange(validatorIndex: ValidatorIndex): boolean {
return this.blsToExecutionChanges.has(validatorIndex);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ export class OpPool {
}

/** Must be validated beforehand */
insertBlsToExecutionChange(blsToExecutionChange: capella.SignedBLSToExecutionChange, preCapella = false): void {
insertBLSToExecutionChange(blsToExecutionChange: capella.SignedBLSToExecutionChange, preCapella = false): void {
this.blsToExecutionChanges.set(blsToExecutionChange.message.validatorIndex, {
data: blsToExecutionChange,
preCapella,
Expand Down Expand Up @@ -262,7 +262,7 @@ export class OpPool {
const endBlsToExecutionChanges = stepsMetrics?.startTimer();
const blsToExecutionChanges: capella.SignedBLSToExecutionChange[] = [];
for (const blsToExecutionChange of this.blsToExecutionChanges.values()) {
if (isValidBlsToExecutionChangeForBlockInclusion(state, blsToExecutionChange.data)) {
if (isValidBLSToExecutionChangeForBlockInclusion(state, blsToExecutionChange.data)) {
blsToExecutionChanges.push(blsToExecutionChange.data);
if (blsToExecutionChanges.length >= MAX_BLS_TO_EXECUTION_CHANGES) {
break;
Expand Down Expand Up @@ -292,7 +292,7 @@ export class OpPool {
}

/** For beacon pool API */
getAllBlsToExecutionChanges(): SignedBLSToExecutionChangeVersioned[] {
getAllBLSToExecutionChanges(): SignedBLSToExecutionChangeVersioned[] {
return Array.from(this.blsToExecutionChanges.values());
}

Expand All @@ -303,7 +303,7 @@ export class OpPool {
this.pruneAttesterSlashings(headState);
this.pruneProposerSlashings(headState);
this.pruneVoluntaryExits(headState);
this.pruneBlsToExecutionChanges(headState, finalizedState);
this.pruneBLSToExecutionChanges(headState, finalizedState);
}

/**
Expand Down Expand Up @@ -372,12 +372,12 @@ export class OpPool {
* Prune blsToExecutionChanges for validators which have been set with withdrawal
* credentials
*/
private pruneBlsToExecutionChanges(
private pruneBLSToExecutionChanges(
headState: CachedBeaconStateAllForks,
finalizedState: CachedBeaconStateAllForks | null
): void {
for (const [key, blsToExecutionChange] of this.blsToExecutionChanges.entries()) {
// TODO CAPELLA: We need the finalizedState to safely prune BlsToExecutionChanges. Finalized state may not be
// TODO CAPELLA: We need the finalizedState to safely prune BLSToExecutionChanges. Finalized state may not be
// available in the cache, so it can be null. Once there's a head only prunning strategy, change
if (finalizedState !== null) {
const validator = finalizedState.validators.getReadonly(blsToExecutionChange.data.message.validatorIndex);
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/opPools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function signatureFromBytesNoCheck(signature: Uint8Array): Signature {
* Ensures that a SignedBLSToExecutionChange object is _still_ valid for block inclusion. An object valid for the pool,
* can become invalid for certain forks.
*/
export function isValidBlsToExecutionChangeForBlockInclusion(
export function isValidBLSToExecutionChangeForBlockInclusion(
state: CachedBeaconStateAllForks,
signedBLSToExecutionChange: capella.SignedBLSToExecutionChange
): boolean {
Expand Down
34 changes: 17 additions & 17 deletions packages/beacon-node/src/chain/validation/blsToExecutionChange.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import {capella} from "@lodestar/types";
import {
isValidBlsToExecutionChange,
getBlsToExecutionChangeSignatureSet,
isValidBLSToExecutionChange,
getBLSToExecutionChangeSignatureSet,
CachedBeaconStateCapella,
} from "@lodestar/state-transition";
import {IBeaconChain} from "..";
import {BlsToExecutionChangeError, BlsToExecutionChangeErrorCode, GossipAction} from "../errors/index.js";
import {BLSToExecutionChangeError, BLSToExecutionChangeErrorCode, GossipAction} from "../errors/index.js";

export async function validateApiBlsToExecutionChange(
export async function validateApiBLSToExecutionChange(
chain: IBeaconChain,
blsToExecutionChange: capella.SignedBLSToExecutionChange
): Promise<void> {
const ignoreExists = true;
const prioritizeBls = true;
return validateBlsToExecutionChange(chain, blsToExecutionChange, {ignoreExists, prioritizeBls});
return validateBLSToExecutionChange(chain, blsToExecutionChange, {ignoreExists, prioritizeBls});
}

export async function validateGossipBlsToExecutionChange(
export async function validateGossipBLSToExecutionChange(
chain: IBeaconChain,
blsToExecutionChange: capella.SignedBLSToExecutionChange
): Promise<void> {
return validateBlsToExecutionChange(chain, blsToExecutionChange);
return validateBLSToExecutionChange(chain, blsToExecutionChange);
}

async function validateBlsToExecutionChange(
async function validateBLSToExecutionChange(
chain: IBeaconChain,
blsToExecutionChange: capella.SignedBLSToExecutionChange,
opts: {ignoreExists?: boolean; prioritizeBls?: boolean} = {ignoreExists: false, prioritizeBls: false}
): Promise<void> {
const {ignoreExists, prioritizeBls} = opts;
// [IGNORE] The blsToExecutionChange is the first valid blsToExecutionChange received for the validator with index
// signedBLSToExecutionChange.message.validatorIndex.
if (!ignoreExists && chain.opPool.hasSeenBlsToExecutionChange(blsToExecutionChange.message.validatorIndex)) {
throw new BlsToExecutionChangeError(GossipAction.IGNORE, {
code: BlsToExecutionChangeErrorCode.ALREADY_EXISTS,
if (!ignoreExists && chain.opPool.hasSeenBLSToExecutionChange(blsToExecutionChange.message.validatorIndex)) {
throw new BLSToExecutionChangeError(GossipAction.IGNORE, {
code: BLSToExecutionChangeErrorCode.ALREADY_EXISTS,
});
}

Expand All @@ -45,17 +45,17 @@ async function validateBlsToExecutionChange(

// [REJECT] All of the conditions within process_bls_to_execution_change pass validation.
// verifySignature = false, verified in batch below
const {valid} = isValidBlsToExecutionChange(state as CachedBeaconStateCapella, blsToExecutionChange, false);
const {valid} = isValidBLSToExecutionChange(state as CachedBeaconStateCapella, blsToExecutionChange, false);
if (!valid) {
throw new BlsToExecutionChangeError(GossipAction.REJECT, {
code: BlsToExecutionChangeErrorCode.INVALID,
throw new BLSToExecutionChangeError(GossipAction.REJECT, {
code: BLSToExecutionChangeErrorCode.INVALID,
});
}

const signatureSet = getBlsToExecutionChangeSignatureSet(config, blsToExecutionChange);
const signatureSet = getBLSToExecutionChangeSignatureSet(config, blsToExecutionChange);
if (!(await chain.bls.verifySignatureSets([signatureSet], {batchable: true, priority: prioritizeBls}))) {
throw new BlsToExecutionChangeError(GossipAction.REJECT, {
code: BlsToExecutionChangeErrorCode.INVALID_SIGNATURE,
throw new BLSToExecutionChangeError(GossipAction.REJECT, {
code: BLSToExecutionChangeErrorCode.INVALID_SIGNATURE,
});
}
}
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface INetwork extends INetworkCorePublic {
publishBeaconAggregateAndProof(aggregateAndProof: phase0.SignedAggregateAndProof): Promise<number>;
publishBeaconAttestation(attestation: phase0.Attestation, subnet: number): Promise<number>;
publishVoluntaryExit(voluntaryExit: phase0.SignedVoluntaryExit): Promise<number>;
publishBlsToExecutionChange(blsToExecutionChange: capella.SignedBLSToExecutionChange): Promise<number>;
publishBLSToExecutionChange(blsToExecutionChange: capella.SignedBLSToExecutionChange): Promise<number>;
publishProposerSlashing(proposerSlashing: phase0.ProposerSlashing): Promise<number>;
publishAttesterSlashing(attesterSlashing: phase0.AttesterSlashing): Promise<number>;
publishSyncCommitteeSignature(signature: altair.SyncCommitteeMessage, subnet: number): Promise<number>;
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class Network implements INetwork {
});
}

async publishBlsToExecutionChange(blsToExecutionChange: capella.SignedBLSToExecutionChange): Promise<number> {
async publishBLSToExecutionChange(blsToExecutionChange: capella.SignedBLSToExecutionChange): Promise<number> {
const publishChanges = [];
for (const fork of getActiveForks(this.config, this.clock.currentEpoch)) {
if (ForkSeq[fork] >= ForkSeq.capella) {
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/src/network/processor/gossipHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
validateGossipSyncCommittee,
validateSyncCommitteeGossipContributionAndProof,
validateGossipVoluntaryExit,
validateGossipBlsToExecutionChange,
validateGossipBLSToExecutionChange,
AggregateAndProofValidationResult,
validateGossipAttestationsSameAttData,
validateGossipAttestation,
Expand Down Expand Up @@ -548,11 +548,11 @@ function getDefaultHandlers(modules: ValidatorFnsModules, options: GossipHandler
}: GossipHandlerParamGeneric<GossipType.bls_to_execution_change>) => {
const {serializedData} = gossipData;
const blsToExecutionChange = sszDeserialize(topic, serializedData);
await validateGossipBlsToExecutionChange(chain, blsToExecutionChange);
await validateGossipBLSToExecutionChange(chain, blsToExecutionChange);

// Handler
try {
chain.opPool.insertBlsToExecutionChange(blsToExecutionChange);
chain.opPool.insertBLSToExecutionChange(blsToExecutionChange);
} catch (e) {
logger.error("Error adding blsToExecutionChange to pool", {}, e as Error);
}
Expand Down
Loading

0 comments on commit ad53c2d

Please sign in to comment.