Skip to content

Commit

Permalink
check signer api upcheck endpoint (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo authored Dec 11, 2024
1 parent 79cbeec commit cbc5d54
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
22 changes: 22 additions & 0 deletions packages/brain/src/modules/apiClients/signer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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<void> {
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}`);
}
}
}
16 changes: 3 additions & 13 deletions packages/brain/src/modules/cron/reloadValidators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}

0 comments on commit cbc5d54

Please sign in to comment.