Skip to content

Commit

Permalink
Merge pull request #267 from dappnode/marc/add_web3signerAPI_healthcheck
Browse files Browse the repository at this point in the history
Add signer api healthcheck on realoadValidators
  • Loading branch information
pablomendezroyo authored Nov 13, 2023
2 parents 958f210 + 3fa0f28 commit 0e26f2f
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/brain/src/modules/cron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,50 @@ export class Cron {
try {
logger.debug(`Reloading data...`);

// 0. GET data
// 0. GET status
const signerApiStatus = await this.signerApi.getStatus();

// If web3signer API is not UP, skip data reload and further steps.
// This is done to avoid unintended DB modifications when the API is down.
// Status can be "UP" | "DOWN" | "UNKNOWN" | "LOADING" | "ERROR";
if (signerApiStatus.status !== "UP") {
logger.warn(`Web3Signer is ${signerApiStatus.status}. Skipping data reload until Web3Signer is UP. Trying again in ${this.defaultInterval / 1000} seconds`);
return;
}

// 1. GET data
const dbPubkeys = Object.keys(this.brainDb.getData());
const signerPubkeys = (await this.signerApi.getKeystores()).data.map(
(keystore) => keystore.validating_pubkey
);

// 1. DELETE from signer API pubkeys that are not in DB
// 2. DELETE from signer API pubkeys that are not in DB
await this.deleteSignerPubkeysNotInDB({ signerPubkeys, dbPubkeys });

// 2. DELETE from DB pubkeys that are not in signer API
// 3. DELETE from DB pubkeys that are not in signer API
await this.deleteDbPubkeysNotInSigner({ dbPubkeys, signerPubkeys });

const validatorPubkeys = (
await this.validatorApi.getRemoteKeys()
).data.map((keystore) => keystore.pubkey);

// 3. POST to validator API pubkeys that are in DB and not in validator API
// 4. POST to validator API pubkeys that are in DB and not in validator API
await this.postValidatorPubkeysFromDb({
brainDbPubkeysToAdd: dbPubkeys.filter(
(pubkey) => !validatorPubkeys.includes(pubkey)
),
validatorPubkeys,
});

// 4. DELETE to validator API pubkeys that are in validator API and not in DB
// 5. DELETE to validator API pubkeys that are in validator API and not in DB
await this.deleteValidatorPubkeysNotInDB({
validatorPubkeys,
validatorPubkeysToRemove: validatorPubkeys.filter(
(pubkey) => !dbPubkeys.includes(pubkey)
),
});

// 5. 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 and not in validator API
await this.postValidatorsFeeRecipientsFromDb({
dbData: this.brainDb.getData(),
validatorPubkeysFeeRecipients: await this.getValidatorsFeeRecipients({
Expand Down Expand Up @@ -125,6 +136,8 @@ export class Cron {
}

logger.error(`Error reloading data`, e);
} else {
logger.error(`Unknown error reloading data`, e);
}
}
}
Expand Down

0 comments on commit 0e26f2f

Please sign in to comment.