From cbc5d54723d74727c330cac97a313ca118cbaf08 Mon Sep 17 00:00:00 2001 From: pablomendezroyo <41727368+pablomendezroyo@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:58:16 +0100 Subject: [PATCH] check signer api upcheck endpoint (#414) --- .../src/modules/apiClients/signer/index.ts | 22 +++++++++++++++++++ .../modules/cron/reloadValidators/index.ts | 16 +++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/brain/src/modules/apiClients/signer/index.ts b/packages/brain/src/modules/apiClients/signer/index.ts index 6401c0ab..12fcbe18 100644 --- a/packages/brain/src/modules/apiClients/signer/index.ts +++ b/packages/brain/src/modules/apiClients/signer/index.ts @@ -44,6 +44,12 @@ export class Web3SignerApi extends StandardApi { */ private serverStatusEndpoint = "/healthcheck"; + /** + * Server status endpoint + * @see https://consensys.github.io/web3signer/web3signer-eth2.html#tag/Server-Status/operation/UPCHECK + */ + private serverUpcheckEndpoint = "/upcheck"; + /** * Origine header required by web3signer */ @@ -175,4 +181,20 @@ export class Web3SignerApi extends StandardApi { throw new SignerApiError(`Error getting (GET) server status. Is Web3Signer running?: ${e.message}`); } } + + /** + * Checks the Web3Signer server status. Confirms if Web3Signer is connected and running. Not used by the validator client. + * @see https://consensys.github.io/web3signer/web3signer-eth2.html#tag/Server-Status/operation/UPCHECK + */ + public async upcheck(): Promise { + try { + await this.request({ + method: "GET", + endpoint: this.serverUpcheckEndpoint, + headers: this.originHeader + }); + } catch (e) { + throw new SignerApiError(`Error getting (GET) server upcheck. Is Web3Signer running?: ${e.message}`); + } + } } diff --git a/packages/brain/src/modules/cron/reloadValidators/index.ts b/packages/brain/src/modules/cron/reloadValidators/index.ts index e80961d6..4a63937b 100644 --- a/packages/brain/src/modules/cron/reloadValidators/index.ts +++ b/packages/brain/src/modules/cron/reloadValidators/index.ts @@ -28,18 +28,8 @@ export async function reloadValidators( try { logger.debug(`${logPrefix}Reloading data...`); - // 0. GET status - const signerApiStatus = await 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( - `${logPrefix}Web3Signer is ${signerApiStatus.status}. Skipping data reload until Web3Signer is UP. Trying again in next jobexecution` - ); - return; - } + // 0. Check signer API upcheck endpoint + await signerApi.upcheck(); // 1. GET data const dbPubkeys = Object.keys(brainDb.getData()); @@ -80,6 +70,6 @@ export async function reloadValidators( logger.debug(`${logPrefix}Finished reloading data`); } catch (e) { - logger.error(`${logPrefix}Unknown error reloading data`, e); + logger.error(`${logPrefix}Error reloading data`, e); } }