Skip to content

Commit

Permalink
Post FR always in validator client (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo authored Feb 6, 2025
1 parent 43447c4 commit 50f0691
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 55 deletions.

This file was deleted.

9 changes: 2 additions & 7 deletions packages/brain/src/modules/cron/reloadValidators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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}`
)
);
}
}

0 comments on commit 50f0691

Please sign in to comment.