Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add type guard to builder pubkey filter #5985

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nifty :)

);

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
Loading