From 3f5102bc340275fcc750985f1961054d17352962 Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 10 May 2024 10:20:49 +0200 Subject: [PATCH] add envs --- packages/brain/src/index.ts | 14 ++++-- .../apiClients/dappnodeSignerProover.ts | 8 ++-- .../src/modules/cron/proofOfAttestation.ts | 3 +- packages/brain/src/modules/envs/index.ts | 45 ++++++++++++++++--- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/packages/brain/src/index.ts b/packages/brain/src/index.ts index b543d26f..6f5421af 100644 --- a/packages/brain/src/index.ts +++ b/packages/brain/src/index.ts @@ -43,6 +43,9 @@ export const { signerUrl, token, host, + shareDataWithDappnode, + validatorsMonitorUrl, + shareCronInterval, tlsCert, } = loadStakerConfig(); logger.debug( @@ -74,7 +77,10 @@ export const beaconchainApi = new Beaconchain( { baseUrl: beaconchainUrl }, network ); -export const dappnodeSignerProoverApi = new DappnodeSigningProover(network); +export const dappnodeSignerProoverApi = new DappnodeSigningProover( + network, + validatorsMonitorUrl +); // Create DB instance export const brainDb = new BrainDataBase( @@ -104,15 +110,15 @@ export const reloadValidatorsCron = new CronJob( ).reloadValidators ); reloadValidatorsCron.start(); -export const proofOfAttestationCron = new CronJob( - 60 * 60 * 1000, +const proofOfAttestationCron = new CronJob( + shareCronInterval, new ProofOfAttestation( signerApi, brainDb, dappnodeSignerProoverApi ).sendProofOfAttestation ); -proofOfAttestationCron.start(); +if (shareDataWithDappnode) proofOfAttestationCron.start(); // Graceful shutdown function handle(signal: string): void { diff --git a/packages/brain/src/modules/apiClients/dappnodeSignerProover.ts b/packages/brain/src/modules/apiClients/dappnodeSignerProover.ts index 167ca0af..cf8971d6 100644 --- a/packages/brain/src/modules/apiClients/dappnodeSignerProover.ts +++ b/packages/brain/src/modules/apiClients/dappnodeSignerProover.ts @@ -5,15 +5,13 @@ import { Web3signerPostSignDappnodeResponse, } from "@stakingbrain/common"; -const dappnodeSignDomain = "https://dappnode-signatures.io"; - export class DappnodeSigningProover extends StandardApi { - private dappnodeSignEndpoint = "/dappnode/proof-of-attestation"; + private dappnodeSignEndpoint = "/newSignature"; - constructor(network: Network) { + constructor(network: Network, validatorsMonitorUrl?: string) { super( { - baseUrl: dappnodeSignDomain, + baseUrl: validatorsMonitorUrl || "https://dappnode-signatures.io", }, network ); diff --git a/packages/brain/src/modules/cron/proofOfAttestation.ts b/packages/brain/src/modules/cron/proofOfAttestation.ts index 0ba83331..5d05a9fa 100644 --- a/packages/brain/src/modules/cron/proofOfAttestation.ts +++ b/packages/brain/src/modules/cron/proofOfAttestation.ts @@ -1,8 +1,7 @@ import { Web3signerPostSignDappnodeResponse } from "@stakingbrain/common"; -import { Web3SignerApi } from "../apiClients/index.js"; +import { Web3SignerApi, DappnodeSigningProover } from "../apiClients/index.js"; import { BrainDataBase } from "../db/index.js"; import logger from "../logger/index.js"; -import { DappnodeSigningProover } from "../apiClients/dappnodeSignerProover.js"; export class ProofOfAttestation { private signerApi: Web3SignerApi; diff --git a/packages/brain/src/modules/envs/index.ts b/packages/brain/src/modules/envs/index.ts index ebbdfed4..139a389b 100644 --- a/packages/brain/src/modules/envs/index.ts +++ b/packages/brain/src/modules/envs/index.ts @@ -58,6 +58,9 @@ export function loadStakerConfig(): { signerUrl: string; token: string; host: string; + shareDataWithDappnode: boolean; + validatorsMonitorUrl: string; + shareCronInterval: number; tlsCert?: Buffer; } { const network = process.env.NETWORK as Network; @@ -69,6 +72,15 @@ export function loadStakerConfig(): { )}` ); + const shareDataWithDappnode = process.env.SHARE_DATA_WITH_DAPPNODE === "true"; + const validatorsMonitorUrl = process.env.VALIDATORS_MONITOR_URL || ""; + const shareCronInterval = parseInt(process.env.SHARE_CRON_INTERVAL || ""); + if (shareDataWithDappnode && (!validatorsMonitorUrl || !shareCronInterval)) { + throw Error( + "SHARE_DATA_WITH_DAPPNODE is true, but VALIDATORS_MONITOR_URL or SHARE_CRON_INTERVAL are not set" + ); + } + const certDir = path.join(__dirname, params.certDirName); let executionClientUrl: string, @@ -78,7 +90,8 @@ export function loadStakerConfig(): { tlsCert: Buffer | undefined; if (network === "mainnet") { - const { executionClient, consensusClient, isMevBoostSet } = loadEnvs("mainnet"); + const { executionClient, consensusClient, isMevBoostSet } = + loadEnvs("mainnet"); switch (executionClient) { case "geth.dnp.dappnode.eth": executionClientUrl = `http://geth.dappnode:8545`; @@ -143,10 +156,14 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer.dappnode:9000`, token, host: `brain.web3signer.dappnode`, + shareDataWithDappnode, + validatorsMonitorUrl, + shareCronInterval, tlsCert, }; } else if (network === "gnosis") { - const { executionClient, consensusClient, isMevBoostSet } = loadEnvs("gnosis"); + const { executionClient, consensusClient, isMevBoostSet } = + loadEnvs("gnosis"); switch (executionClient) { case "nethermind-xdai.dnp.dappnode.eth": executionClientUrl = `http://nethermind-xdai.dappnode:8545`; @@ -205,10 +222,14 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer-gnosis.dappnode:9000`, token, host: `brain.web3signer-gnosis.dappnode`, + shareDataWithDappnode, + validatorsMonitorUrl, + shareCronInterval, tlsCert, }; } else if (network === "prater") { - const { executionClient, consensusClient, isMevBoostSet } = loadEnvs("prater"); + const { executionClient, consensusClient, isMevBoostSet } = + loadEnvs("prater"); switch (executionClient) { case "goerli-nethermind.dnp.dappnode.eth": executionClientUrl = `http://goerli-nethermind.dappnode:8545`; @@ -273,10 +294,14 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer-prater.dappnode:9000`, token, host: `web3signer.web3signer-prater.dappnode`, + shareDataWithDappnode, + validatorsMonitorUrl, + shareCronInterval, tlsCert, }; } else if (network === "lukso") { - const { executionClient, consensusClient, isMevBoostSet } = loadEnvs("lukso"); + const { executionClient, consensusClient, isMevBoostSet } = + loadEnvs("lukso"); switch (executionClient) { case "lukso-erigon.dnp.dappnode.eth": executionClientUrl = `http://lukso-erigon.dappnode:8545`; @@ -335,10 +360,14 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer-lukso.dappnode:9000`, token, host: `web3signer.web3signer-lukso.dappnode`, + shareDataWithDappnode, + validatorsMonitorUrl, + shareCronInterval, tlsCert, }; } else if (network === "holesky") { - const { executionClient, consensusClient, isMevBoostSet } = loadEnvs("holesky"); + const { executionClient, consensusClient, isMevBoostSet } = + loadEnvs("holesky"); switch (executionClient) { case "holesky-nethermind.dnp.dappnode.eth": executionClientUrl = `http://holesky-nethermind.dappnode:8545`; @@ -403,6 +432,9 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer-holesky.dappnode:9000`, token, host: `web3signer.web3signer-holesky.dappnode`, + shareDataWithDappnode, + validatorsMonitorUrl, + shareCronInterval, tlsCert, }; } else { @@ -428,7 +460,8 @@ function loadEnvs( const consensusClient = process.env[`_DAPPNODE_GLOBAL_CONSENSUS_CLIENT_${network.toUpperCase()}`]; const isMevBoostSet = - process.env[`_DAPPNODE_GLOBAL_MEVBOOST_${network.toUpperCase()}`] === "true"; + process.env[`_DAPPNODE_GLOBAL_MEVBOOST_${network.toUpperCase()}`] === + "true"; switch (network) { case "mainnet":