Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare dappmanager for multi-service nimbus client #2014

Merged
merged 17 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions packages/installer/src/ethClient/apiUrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildNetworkAlias, getBeaconServiceName } from "@dappnode/utils";
import { buildNetworkAlias } from "@dappnode/utils";
import { listPackageNoThrow } from "@dappnode/dockerapi";

/**
Expand Down Expand Up @@ -27,27 +27,28 @@ export function getEthExecClientApiUrl(dnpName: string, port = 8545): string {
* @param dnpName
*/
export async function getEthConsClientApiUrl(dnpName: string): Promise<string> {
let port = 3500;
let domain = "";
const defaultPort = 3500;
const defaultServiceName = "beacon-chain";

const dnp = await listPackageNoThrow({ dnpName });
if (dnp && typeof dnp.chain === "object" && dnp.chain.portNumber && dnp.chain.serviceName) {
port = dnp.chain.portNumber;
domain = buildNetworkAlias({
dnpName: dnpName,
serviceName: dnp.chain.serviceName,
isMainOrMonoservice: false
});
} else {
// Lighthouse, Teku and Prysm use 3500
// Nimbus uses 4500 because it is a monoservice and the validator API is using that port
if (dnpName.includes("nimbus")) {
port = 4500;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All production Nimbus clients have their driver defined like this:

  "chain": {
    "driver": "ethereum-beacon-chain",
    "serviceName": "beacon-validator",
    "portNumber": 4500
  },

So it is not necessary to consider this condition. Also, once nimbus package is published from https://github.com/dappnode/DAppNodePackage-nimbus-generic , it will have 2 services that will behave the same as the rest of the clients

}
domain = buildNetworkAlias({
dnpName: dnpName,
serviceName: getBeaconServiceName(dnpName),

if (!dnp || typeof dnp.chain !== "object") {
const domain = buildNetworkAlias({
dnpName,
serviceName: defaultServiceName,
isMainOrMonoservice: false
});

return `http://${domain}:${defaultPort}`;
}
return `http://${domain}:${port}`;

const { chain: { portNumber = defaultPort, serviceName = defaultServiceName } = {} } = dnp;

const domain = buildNetworkAlias({
dnpName,
serviceName,
isMainOrMonoservice: false
});

return `http://${domain}:${portNumber}`;
}
117 changes: 36 additions & 81 deletions packages/stakers/src/consensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Consensus extends StakerComponent {
}
await this.persistSelectedIfInstalled({
dnpName: currentConsensusDnpName,
userSettings: this.getUserSettings(currentConsensusDnpName, isInstalled, network)
userSettings: this.getUserSettings(isInstalled, network)
});
await this.DbHandlers[network].set(currentConsensusDnpName);
}
Expand All @@ -108,51 +108,36 @@ export class Consensus extends StakerComponent {
dockerNetworkName: params.DOCKER_STAKER_NETWORKS[network],
compatibleClients: Consensus.CompatibleConsensus[network],
userSettings: newConsensusDnpName
? this.getUserSettings(
newConsensusDnpName,
!(await listPackageNoThrow({ dnpName: newConsensusDnpName })),
network
)
? this.getUserSettings(!(await listPackageNoThrow({ dnpName: newConsensusDnpName })), network)
: {},
prevClient: prevConsClientDnpName
});
// persist on db
if (newConsensusDnpName !== prevConsClientDnpName) await this.DbHandlers[network].set(newConsensusDnpName);
}

private getUserSettings(newConsensusDnpName: string, shouldSetEnvironment: boolean, network: Network): UserSettings {
const validatorServiceName = this.getValidatorServiceName(newConsensusDnpName);
const beaconServiceName = this.getBeaconServiceName(newConsensusDnpName);
private getUserSettings(shouldSetEnvironment: boolean, network: Network): UserSettings {
const validatorServiceName = "validator";
const beaconServiceName = "beacon-chain";
const defaultDappnodeGraffiti = "validating_from_DAppNode";
const defaultFeeRecipient = "0x0000000000000000000000000000000000000000";
return {
environment: shouldSetEnvironment
? beaconServiceName === validatorServiceName
? {
[validatorServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, // TODO: consider setting the MEV fee recipient as the default
// Graffiti is a mandatory value
["GRAFFITI"]: defaultDappnodeGraffiti,
// Checkpoint sync is an optional value
["CHECKPOINT_SYNC_URL"]: Consensus.DefaultCheckpointSync[network]
}
}
: {
[validatorServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient,
// Graffiti is a mandatory value
["GRAFFITI"]: defaultDappnodeGraffiti
},
? {
[validatorServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient,
// Graffiti is a mandatory value
["GRAFFITI"]: defaultDappnodeGraffiti
},

[beaconServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient,
// Checkpoint sync is an optional value
["CHECKPOINT_SYNC_URL"]: Consensus.DefaultCheckpointSync[network]
}
[beaconServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient,
// Checkpoint sync is an optional value
["CHECKPOINT_SYNC_URL"]: Consensus.DefaultCheckpointSync[network]
}
}
: {},
networks: {
rootNetworks: {
Expand All @@ -163,55 +148,25 @@ export class Consensus extends StakerComponent {
external: true
}
},
serviceNetworks:
beaconServiceName === validatorServiceName
? {
"beacon-validator": {
[params.DOCKER_STAKER_NETWORKS[network]]: {
aliases: [`beacon-chain.${network}.staker.dappnode`, `validator.${network}.staker.dappnode`]
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
aliases: [`beacon-chain.${network}.dncore.dappnode`, `validator.${network}.dncore.dappnode`]
}
}
}
: {
"beacon-chain": {
[params.DOCKER_STAKER_NETWORKS[network]]: {
aliases: [`beacon-chain.${network}.staker.dappnode`]
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
aliases: [`beacon-chain.${network}.dncore.dappnode`]
}
},
validator: {
[params.DOCKER_STAKER_NETWORKS[network]]: {
aliases: [`validator.${network}.staker.dappnode`]
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
aliases: [`validator.${network}.dncore.dappnode`]
}
}
}
serviceNetworks: {
"beacon-chain": {
[params.DOCKER_STAKER_NETWORKS[network]]: {
aliases: [`beacon-chain.${network}.staker.dappnode`]
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
aliases: [`beacon-chain.${network}.dncore.dappnode`]
}
},
validator: {
[params.DOCKER_STAKER_NETWORKS[network]]: {
aliases: [`validator.${network}.staker.dappnode`]
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
aliases: [`validator.${network}.dncore.dappnode`]
}
}
}
}
};
}

/**
* Get the validator service name.
* - Nimbus package is monoservice (beacon-validator)
* - Prysm, Teku, Lighthouse, and Lodestar are multiservice (beacon, validator)
*/
private getValidatorServiceName(newConsensusDnpName: string | null): string {
return newConsensusDnpName ? (newConsensusDnpName.includes("nimbus") ? "beacon-validator" : "validator") : "";
}

/**
* Get the beacon service name
* - Nimbus package is monoservice (beacon-validator)
* - Prysm, Teku, Lighthouse, and Lodestar are multiservice (beacon, validator)
*/
private getBeaconServiceName(newConsensusDnpName: string | null): string {
return newConsensusDnpName ? (newConsensusDnpName.includes("nimbus") ? "beacon-validator" : "beacon-chain") : "";
}
}
2 changes: 1 addition & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export * from "./asyncFlows.js";
export * from "./pid.js";
export { urlJoin } from "./urlJoin.js";
export { prettyDnpName } from "./prettyDnpName.js";
export { getBeaconServiceName, getConsensusUserSettings } from "./stakerUtils.js";
export { getConsensusUserSettings } from "./stakerUtils.js";
export * from "./ethers.js";
export { shellSafe } from "./shellSafe.js";
export { getIsInstalled } from "./getIsInstalled.js";
Expand Down
64 changes: 16 additions & 48 deletions packages/utils/src/stakerUtils.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
import { UserSettingsAllDnps, Network } from "@dappnode/types";

// TODO: remove these utils

/**
* Get the validator service name.
* - Nimbus package is monoservice (beacon-validator)
* - Prysm, Teku, Lighthouse, and Lodestar are multiservice (beacon, validator)
*/
function getValidatorServiceName(dnpName: string): string {
return dnpName.includes("nimbus") ? "beacon-validator" : "validator";
}

/**
* Get the beacon service name
* - Nimbus package is monoservice (beacon-validator)
* - Prysm, Teku, Lighthouse, and Lodestar are multiservice (beacon, validator)
*/
export function getBeaconServiceName(dnpName: string): string {
return dnpName.includes("nimbus") ? "beacon-validator" : "beacon-chain";
}

/**
* Get the user settings for the consensus client.
* It may be different depending if it is multiservice or monoservice and all the envs are
Expand All @@ -32,39 +12,27 @@ export function getConsensusUserSettings({
dnpName: string;
network: Network;
}): UserSettingsAllDnps {
const validatorServiceName = getValidatorServiceName(dnpName);
const beaconServiceName = getBeaconServiceName(dnpName);
const validatorServiceName = "validator";
const beaconServiceName = "beacon-chain";
const defaultDappnodeGraffiti = "validating_from_DAppNode";
const defaultFeeRecipient = "0x0000000000000000000000000000000000000000";
return {
[dnpName]: {
environment:
beaconServiceName === validatorServiceName
? {
[validatorServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, // TODO: consider setting the MEV fee recipient as the default
// Graffiti is a mandatory value
["GRAFFITI"]: defaultDappnodeGraffiti,
// Checkpoint sync is an optional value
["CHECKPOINT_SYNC_URL"]: getDefaultCheckpointSync(network)
}
}
: {
[validatorServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient,
// Graffiti is a mandatory value
["GRAFFITI"]: defaultDappnodeGraffiti
},
environment: {
[validatorServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient,
// Graffiti is a mandatory value
["GRAFFITI"]: defaultDappnodeGraffiti
},

[beaconServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient,
// Checkpoint sync is an optional value
["CHECKPOINT_SYNC_URL"]: getDefaultCheckpointSync(network)
}
}
[beaconServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient,
// Checkpoint sync is an optional value
["CHECKPOINT_SYNC_URL"]: getDefaultCheckpointSync(network)
}
}
}
};
}
Expand Down
Loading