diff --git a/packages/brain/src/modules/cron/reloadValidators/getValidatorsFeeRecipients.ts b/packages/brain/src/modules/cron/reloadValidators/getValidatorsFeeRecipients.ts deleted file mode 100644 index 8c1a17f1..00000000 --- a/packages/brain/src/modules/cron/reloadValidators/getValidatorsFeeRecipients.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ValidatorApi } from "../../apiClients/index.js"; - -/** - * Get the validators fee recipients from the validator API for the given pubkeys - */ -export async function getValidatorsFeeRecipients({ - validatorApi, - validatorPubkeys -}: { - validatorApi: ValidatorApi; - validatorPubkeys: string[]; -}): Promise<{ pubkey: string; feeRecipient: string }[]> { - const validatorData = []; - - for (const pubkey of validatorPubkeys) { - validatorData.push({ - pubkey, - feeRecipient: (await validatorApi.getFeeRecipient(pubkey)).data.ethaddress - }); - } - - return validatorData; -} diff --git a/packages/brain/src/modules/cron/reloadValidators/index.ts b/packages/brain/src/modules/cron/reloadValidators/index.ts index 4a63937b..8519a9a7 100644 --- a/packages/brain/src/modules/cron/reloadValidators/index.ts +++ b/packages/brain/src/modules/cron/reloadValidators/index.ts @@ -4,7 +4,6 @@ import logger from "../../logger/index.js"; import { deleteDbPubkeysNotInSigner } from "./deleteDbPubkeysNotInSigner.js"; import { deleteSignerPubkeysNotInDb } from "./deleteSignerPubkeysNotInDb.js"; import { deleteValidatorPubkeysNotInDB } from "./deleteValidatorPubkeysNotInDb.js"; -import { getValidatorsFeeRecipients } from "./getValidatorsFeeRecipients.js"; import { logPrefix } from "./logPrefix.js"; import { postValidatorPubkeysFromDb } from "./postValidatorPubkeysFromDb.js"; import { postValidatorsFeeRecipientsFromDb } from "./postValidatorsFeeRecipientsFromDb.js"; @@ -58,14 +57,10 @@ export async function reloadValidators( validatorPubkeysToRemove: validatorPubkeys.filter((pubkey) => !dbPubkeys.includes(pubkey)) }); - // 6. POST to validator API fee recipients that are in DB and not in validator API + // 6. POST to validator API fee recipients that are in DB in validator API await postValidatorsFeeRecipientsFromDb({ validatorApi, - dbData: brainDb.getData(), - validatorPubkeysFeeRecipients: await getValidatorsFeeRecipients({ - validatorApi, - validatorPubkeys - }) + dbData: brainDb.getData() }); logger.debug(`${logPrefix}Finished reloading data`); diff --git a/packages/brain/src/modules/cron/reloadValidators/postValidatorsFeeRecipientsFromDb.ts b/packages/brain/src/modules/cron/reloadValidators/postValidatorsFeeRecipientsFromDb.ts index ad0f38b7..6fc9c7f5 100644 --- a/packages/brain/src/modules/cron/reloadValidators/postValidatorsFeeRecipientsFromDb.ts +++ b/packages/brain/src/modules/cron/reloadValidators/postValidatorsFeeRecipientsFromDb.ts @@ -4,37 +4,22 @@ import logger from "../../logger/index.js"; import { logPrefix } from "./logPrefix.js"; /** - * Post in the validator API fee recipients that are in the DB and not in the validator API + * Post in the validator API fee recipients that are in the DB in the validator API */ export async function postValidatorsFeeRecipientsFromDb({ validatorApi, - dbData, - validatorPubkeysFeeRecipients + dbData }: { validatorApi: ValidatorApi; dbData: StakingBrainDb; - validatorPubkeysFeeRecipients: { pubkey: string; feeRecipient: string }[]; }): Promise { - const feeRecipientsToPost = validatorPubkeysFeeRecipients - .filter( - (validator) => - validator.feeRecipient.toLocaleLowerCase() !== dbData[validator.pubkey].feeRecipient.toLocaleLowerCase() - ) - .map((validator) => ({ - pubkey: validator.pubkey, - feeRecipient: dbData[validator.pubkey].feeRecipient - })); - - if (feeRecipientsToPost.length > 0) { - logger.debug(`${logPrefix}Found ${feeRecipientsToPost.length} fee recipients to add/update to validator API`); - for (const { pubkey, feeRecipient } of feeRecipientsToPost) - await validatorApi - .setFeeRecipient(feeRecipient, pubkey) - .catch((e) => - logger.error( - `${logPrefix}Error adding fee recipient ${feeRecipient} to validator API for pubkey ${pubkey}`, - e - ) - ); + for (const [pubkey, { feeRecipient }] of Object.entries(dbData)) { + await validatorApi + .setFeeRecipient(feeRecipient, pubkey) + .catch((e) => + logger.error( + `${logPrefix}Error posting fee recipient ${feeRecipient} for pubkey ${pubkey} to validator API: ${e}` + ) + ); } }