From b848f1939caa5a03846ec288f3e08a7d32efb176 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sat, 23 Sep 2023 13:06:03 +0200 Subject: [PATCH] refactor: add type guard to builder pubkey filter --- packages/validator/src/services/prepareBeaconProposer.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/validator/src/services/prepareBeaconProposer.ts b/packages/validator/src/services/prepareBeaconProposer.ts index 65c34e478efd..f7662c17b56e 100644 --- a/packages/validator/src/services/prepareBeaconProposer.ts +++ b/packages/validator/src/services/prepareBeaconProposer.ts @@ -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}); @@ -95,11 +97,6 @@ export function pollBuilderValidatorRegistration( try { const registrations = await Promise.all( pubkeyHexes.map((pubkeyHex): Promise => { - // 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);