From 8a646c360729102620dd869789e2db88ba412b28 Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 17 Nov 2023 09:55:05 +0100 Subject: [PATCH 1/6] remove fee recipient as global env --- packages/brain/src/index.ts | 5 ++-- packages/brain/src/modules/db/index.ts | 19 +++++--------- packages/brain/src/modules/envs/index.ts | 33 +++--------------------- 3 files changed, 12 insertions(+), 45 deletions(-) diff --git a/packages/brain/src/index.ts b/packages/brain/src/index.ts index cdbd90e3..d7daf70e 100644 --- a/packages/brain/src/index.ts +++ b/packages/brain/src/index.ts @@ -33,11 +33,10 @@ export const { signerUrl, token, host, - defaultFeeRecipient, tlsCert, } = loadStakerConfig(); logger.debug( - `Loaded staker config:\n - Network: ${network}\n - Execution client: ${executionClient}\n - Consensus client: ${consensusClient}\n - Execution client url: ${executionClientUrl}\n - Validator url: ${validatorUrl}\n - Beaconcha url: ${beaconchaUrl}\n - Beaconchain url: ${beaconchainUrl}\n - Signer url: ${signerUrl}\n - Token: ${token}\n - Host: ${host}\n - Default fee recipient: ${defaultFeeRecipient}` + `Loaded staker config:\n - Network: ${network}\n - Execution client: ${executionClient}\n - Consensus client: ${consensusClient}\n - Execution client url: ${executionClientUrl}\n - Validator url: ${validatorUrl}\n - Beaconcha url: ${beaconchaUrl}\n - Beaconchain url: ${beaconchainUrl}\n - Signer url: ${signerUrl}\n - Token: ${token}\n - Host: ${host}}` ); // Create API instances. Must preceed db initialization @@ -68,7 +67,7 @@ export const brainDb = new BrainDataBase( const uiServer = startUiServer(path.resolve(__dirname, params.uiBuildDirName)); const launchpadServer = startLaunchpadApi(); -await brainDb.initialize(signerApi, validatorApi, defaultFeeRecipient); +await brainDb.initialize(signerApi, validatorApi); logger.debug(brainDb.data); // CRON diff --git a/packages/brain/src/modules/db/index.ts b/packages/brain/src/modules/db/index.ts index e1b0531f..2e1f04d9 100644 --- a/packages/brain/src/modules/db/index.ts +++ b/packages/brain/src/modules/db/index.ts @@ -59,19 +59,14 @@ export class BrainDataBase extends LowSync { */ public async initialize( signerApi: Web3SignerApi, - validatorApi: ValidatorApi, - defaultFeeRecipient: string | undefined + validatorApi: ValidatorApi ): Promise { try { // Important! .read() method must be called before accessing brainDb.data otherwise it will be null this.read(); // If db.json doesn't exist, db.data will be null if (this.data === null) - await this.databaseMigration( - signerApi, - validatorApi, - defaultFeeRecipient - ); + await this.databaseMigration(signerApi, validatorApi); else this.setOwnerWriteRead(); } catch (e) { logger.error(`unable to initialize the db ${this.dbName}`, e); @@ -247,12 +242,10 @@ export class BrainDataBase extends LowSync { * * @param signerApi - The signer API * @param validatorApi - The validator API - * @param defaultFeeRecipient - The default fee recipient to use if the validator API is not available */ private async databaseMigration( signerApi: Web3SignerApi, - validatorApi: ValidatorApi, - defaultFeeRecipient?: string + validatorApi: ValidatorApi ): Promise { let retries = 0; while (retries < 10) { @@ -279,11 +272,11 @@ export class BrainDataBase extends LowSync { }) .catch((e) => { logger.error( - `Unable to fetch fee recipient for ${pubkeys[0]}. Setting default ${defaultFeeRecipient}}`, + `Unable to fetch fee recipient for ${pubkeys[0]}. Setting default ${params.burnAddress}}`, e ); - if (defaultFeeRecipient) feeRecipient = defaultFeeRecipient; - else feeRecipient = params.burnAddress; + // TODO: consider setting MEV fee recipient + feeRecipient = params.burnAddress; }); logger.info( diff --git a/packages/brain/src/modules/envs/index.ts b/packages/brain/src/modules/envs/index.ts index 77a5403e..652a190d 100644 --- a/packages/brain/src/modules/envs/index.ts +++ b/packages/brain/src/modules/envs/index.ts @@ -58,7 +58,6 @@ export function loadStakerConfig(): { signerUrl: string; token: string; host: string; - defaultFeeRecipient?: string; tlsCert?: Buffer; } { const network = process.env.NETWORK as Network; @@ -79,8 +78,7 @@ export function loadStakerConfig(): { tlsCert: Buffer | undefined; if (network === "mainnet") { - const { executionClient, consensusClient, defaultFeeRecipient } = - loadEnvs("mainnet"); + const { executionClient, consensusClient } = loadEnvs("mainnet"); switch (executionClient) { case "geth.dnp.dappnode.eth": executionClientUrl = `http://geth.dappnode:8545`; @@ -144,15 +142,10 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer.dappnode:9000`, token, host: `brain.web3signer.dappnode`, - defaultFeeRecipient: - defaultFeeRecipient && isValidEcdsaPubkey(defaultFeeRecipient) - ? defaultFeeRecipient - : undefined, tlsCert, }; } else if (network === "gnosis") { - const { executionClient, consensusClient, defaultFeeRecipient } = - loadEnvs("gnosis"); + const { executionClient, consensusClient } = loadEnvs("gnosis"); switch (executionClient) { case "nethermind-xdai.dnp.dappnode.eth": executionClientUrl = `http://nethermind-xdai.dappnode:8545`; @@ -202,15 +195,10 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer-gnosis.dappnode:9000`, token, host: `brain.web3signer-gnosis.dappnode`, - defaultFeeRecipient: - defaultFeeRecipient && isValidEcdsaPubkey(defaultFeeRecipient) - ? defaultFeeRecipient - : undefined, tlsCert, }; } else if (network === "prater") { - const { executionClient, consensusClient, defaultFeeRecipient } = - loadEnvs("prater"); + const { executionClient, consensusClient } = loadEnvs("prater"); switch (executionClient) { case "goerli-nethermind.dnp.dappnode.eth": executionClientUrl = `http://goerli-nethermind.dappnode:8545`; @@ -274,15 +262,10 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer-prater.dappnode:9000`, token, host: `web3signer.web3signer-prater.dappnode`, - defaultFeeRecipient: - defaultFeeRecipient && isValidEcdsaPubkey(defaultFeeRecipient) - ? defaultFeeRecipient - : undefined, tlsCert, }; } else if (network === "lukso") { - const { executionClient, consensusClient, defaultFeeRecipient } = - loadEnvs("lukso"); + const { executionClient, consensusClient } = loadEnvs("lukso"); switch (executionClient) { case "lukso-erigon.dnp.dappnode.eth": executionClientUrl = `http://lukso-erigon.dappnode:8545`; @@ -340,10 +323,6 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer-lukso.dappnode:9000`, token, host: `web3signer.web3signer-lukso.dappnode`, - defaultFeeRecipient: - defaultFeeRecipient && isValidEcdsaPubkey(defaultFeeRecipient) - ? defaultFeeRecipient - : undefined, tlsCert, }; } else if (network === "holesky") { @@ -432,12 +411,9 @@ function loadEnvs( ): { executionClient: ExecutionClient; consensusClient: ConsensusClient; - defaultFeeRecipient?: string; } { const errors = []; - const defaultFeeRecipient = - process.env[`_DAPPNODE_GLOBAL_FEE_RECIPIENT_${network.toUpperCase()}`]; const executionClient = process.env[`_DAPPNODE_GLOBAL_EXECUTION_CLIENT_${network.toUpperCase()}`]; const consensusClient = @@ -564,6 +540,5 @@ function loadEnvs( return { executionClient: executionClient as ExecutionClient, consensusClient: consensusClient as ConsensusClient, - defaultFeeRecipient, }; } From d07af09f7ded893a30bed8ced1ca45d974200ae8 Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 17 Nov 2023 09:59:58 +0100 Subject: [PATCH 2/6] remove default fee recipient from back-front call --- packages/brain/src/calls/getStakerConfig.ts | 2 -- packages/brain/src/modules/envs/index.ts | 2 +- packages/common/src/types/network/types.ts | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/brain/src/calls/getStakerConfig.ts b/packages/brain/src/calls/getStakerConfig.ts index f7208fd9..ceffa237 100644 --- a/packages/brain/src/calls/getStakerConfig.ts +++ b/packages/brain/src/calls/getStakerConfig.ts @@ -3,7 +3,6 @@ import { network, executionClient, consensusClient, - defaultFeeRecipient, executionClientUrl, validatorUrl, beaconchainUrl, @@ -19,6 +18,5 @@ export async function getStakerConfig(): Promise> { validatorUrl, beaconchainUrl, signerUrl, - defaultFeeRecipient, }; } diff --git a/packages/brain/src/modules/envs/index.ts b/packages/brain/src/modules/envs/index.ts index 652a190d..919c835d 100644 --- a/packages/brain/src/modules/envs/index.ts +++ b/packages/brain/src/modules/envs/index.ts @@ -45,7 +45,7 @@ import { isValidEcdsaPubkey } from "@stakingbrain/common"; * @throws consensus client is not valid for : . Valid consensus clients for : * This exception is thrown if the consensus client is not valid for the network * - * @returns executionClientUrl, validatorUrl, beaconchainUrl, beaconchaUrl, signerUrl, token, host, defaultFeeRecipient, tlsCert + * @returns executionClientUrl, validatorUrl, beaconchainUrl, beaconchaUrl, signerUrl, token, host, tlsCert */ export function loadStakerConfig(): { network: Network; diff --git a/packages/common/src/types/network/types.ts b/packages/common/src/types/network/types.ts index 3f28b70d..8f41678f 100644 --- a/packages/common/src/types/network/types.ts +++ b/packages/common/src/types/network/types.ts @@ -10,7 +10,6 @@ export interface StakerConfig { validatorUrl: string; beaconchainUrl: string; signerUrl: string; - defaultFeeRecipient?: string; } export type ExecutionClient = T extends "mainnet" From 6570b9ab86978e7d490baf3f0c786ce6b43a5771 Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 17 Nov 2023 10:03:45 +0100 Subject: [PATCH 3/6] remove unused import --- packages/brain/src/modules/envs/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/brain/src/modules/envs/index.ts b/packages/brain/src/modules/envs/index.ts index 919c835d..3802ebc3 100644 --- a/packages/brain/src/modules/envs/index.ts +++ b/packages/brain/src/modules/envs/index.ts @@ -28,7 +28,6 @@ import path from "path"; import fs from "fs"; import { params } from "../../params.js"; import { __dirname } from "../../index.js"; -import { isValidEcdsaPubkey } from "@stakingbrain/common"; /** * Loads the staker config needed to create the base urls for beacon, validator and signer APIs From 026eb5041bb25bc448b97bff771b4a0cfd4dd41e Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 17 Nov 2023 10:22:27 +0100 Subject: [PATCH 4/6] trigger gha --- packages/brain/src/modules/db/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/brain/src/modules/db/index.ts b/packages/brain/src/modules/db/index.ts index 2e1f04d9..31e063bd 100644 --- a/packages/brain/src/modules/db/index.ts +++ b/packages/brain/src/modules/db/index.ts @@ -275,7 +275,7 @@ export class BrainDataBase extends LowSync { `Unable to fetch fee recipient for ${pubkeys[0]}. Setting default ${params.burnAddress}}`, e ); - // TODO: consider setting MEV fee recipient + // TODO: consider setting MEV fee recipient. feeRecipient = params.burnAddress; }); From 0c7c38f75bd1523622c01cde66152af31c10da19 Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 17 Nov 2023 10:39:55 +0100 Subject: [PATCH 5/6] remove extra fee recipient --- packages/brain/src/modules/envs/index.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/brain/src/modules/envs/index.ts b/packages/brain/src/modules/envs/index.ts index 3802ebc3..3bcf36a1 100644 --- a/packages/brain/src/modules/envs/index.ts +++ b/packages/brain/src/modules/envs/index.ts @@ -325,8 +325,7 @@ export function loadStakerConfig(): { tlsCert, }; } else if (network === "holesky") { - const { executionClient, consensusClient, defaultFeeRecipient } = - loadEnvs("holesky"); + const { executionClient, consensusClient } = loadEnvs("holesky"); switch (executionClient) { case "holesky-nethermind.dnp.dappnode.eth": executionClientUrl = `http://holesky-nethermind.dappnode:8545`; @@ -390,10 +389,6 @@ export function loadStakerConfig(): { signerUrl: `http://web3signer.web3signer-holesky.dappnode:9000`, token, host: `web3signer.web3signer-holesky.dappnode`, - defaultFeeRecipient: - defaultFeeRecipient && isValidEcdsaPubkey(defaultFeeRecipient) - ? defaultFeeRecipient - : undefined, tlsCert, }; } else { From f7f56e85ff70f4bbdeb88fd4f931f77430b8b345 Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 17 Nov 2023 10:47:45 +0100 Subject: [PATCH 6/6] fix tests --- .../tests/unit/modules/db/index.unit.test.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/packages/brain/tests/unit/modules/db/index.unit.test.ts b/packages/brain/tests/unit/modules/db/index.unit.test.ts index 48f703b7..99a60597 100644 --- a/packages/brain/tests/unit/modules/db/index.unit.test.ts +++ b/packages/brain/tests/unit/modules/db/index.unit.test.ts @@ -98,11 +98,7 @@ describe("DataBase", () => { expect(db.data).to.be.null; // initialize - await db.initialize( - signerApi, - validatorApi, - "0x0000000000000000000000000000000000000000" - ); + await db.initialize(signerApi, validatorApi); // print contents of database console.log(db.data); // check database @@ -120,11 +116,7 @@ describe("DataBase", () => { const signerApi = sinon.createStubInstance(Web3SignerApi); const validatorApi = sinon.createStubInstance(ValidatorApi); sinon.stub(db, "databaseMigration").callsFake(databaseMigration); - await db.initialize( - signerApi, - validatorApi, - "0x0000000000000000000000000000000000000000" - ); + await db.initialize(signerApi, validatorApi); expect(fs.existsSync(testDbName)).to.be.true; db.read(); @@ -139,11 +131,7 @@ describe("DataBase", () => { fs.writeFileSync(testDbName, JSON.stringify({})); const signerApi = sinon.createStubInstance(Web3SignerApi); const validatorApi = sinon.createStubInstance(ValidatorApi); - db.initialize( - signerApi, - validatorApi, - "0x0000000000000000000000000000000000000000" - ); + db.initialize(signerApi, validatorApi); expect(fs.existsSync(testDbName)).to.be.true; db.read(); expect(db.data).to.be.empty;