Skip to content

Commit

Permalink
refactor: add type guard to builder pubkey filter (#5985)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored Sep 23, 2023
1 parent 0f74435 commit f5e2c3a
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/validator/src/services/prepareBeaconProposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export function pollBuilderValidatorRegistration(
const pubkeyHexes = validatorStore
.getAllLocalIndices()
.map((index) => validatorStore.getPubkeyOfIndex(index))
.filter((pubkeyHex) => pubkeyHex !== undefined && validatorStore.isBuilderEnabled(pubkeyHex));
.filter(
(pubkeyHex): pubkeyHex is string => pubkeyHex !== undefined && validatorStore.isBuilderEnabled(pubkeyHex)
);

if (pubkeyHexes.length > 0) {
const pubkeyHexesChunks = batchItems(pubkeyHexes, {batchSize: REGISTRATION_CHUNK_SIZE});
Expand All @@ -95,11 +97,6 @@ export function pollBuilderValidatorRegistration(
try {
const registrations = await Promise.all(
pubkeyHexes.map((pubkeyHex): Promise<bellatrix.SignedValidatorRegistrationV1> => {
// Just to make typescript happy as it can't figure out we have filtered
// undefined pubkeys above
if (pubkeyHex === undefined) {
throw Error("All undefined pubkeys should have been filtered out");
}
const feeRecipient = validatorStore.getFeeRecipient(pubkeyHex);
const gasLimit = validatorStore.getGasLimit(pubkeyHex);
return validatorStore.getValidatorRegistration(pubkeyHex, {feeRecipient, gasLimit}, slot);
Expand Down

0 comments on commit f5e2c3a

Please sign in to comment.