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 6 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
9 changes: 5 additions & 4 deletions packages/daemons/src/ethMultiClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ export async function runEthClientInstaller(
if (isConsensusClientMainnet(target))
await packageInstall(dappnodeInstaller, {
name: target,
userSettings: getConsensusUserSettings({
dnpName: target,
network: Network.Mainnet
})
userSettings: {
[target]: getConsensusUserSettings({
network: Network.Mainnet
})
}
});
else await packageInstall(dappnodeInstaller, { name: target });
} catch (e) {
Expand Down
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}`;
}
10 changes: 6 additions & 4 deletions packages/installer/src/ethClient/ethereumClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,12 @@ export class EthereumClient {
});
if (!consClientPkg) {
// Get default cons client user settings and install cons client
const userSettings = getConsensusUserSettings({
dnpName: consClient,
network: Network.Mainnet
});
const userSettings = {
[consClient]: getConsensusUserSettings({
network: Network.Mainnet
})
};

await packageInstall(dappnodeInstaller, {
name: consClient,
userSettings
Expand Down
127 changes: 31 additions & 96 deletions packages/stakers/src/consensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DappnodeInstaller } from "@dappnode/installer";
import * as db from "@dappnode/db";
import { listPackageNoThrow } from "@dappnode/dockerapi";
import { params } from "@dappnode/params";
import { getConsensusUserSettings } from "@dappnode/utils";

// TODO: move ethereumClient logic here

Expand All @@ -30,13 +31,6 @@ export class Consensus extends StakerComponent {
[Network.Holesky]: db.consensusClientHolesky,
[Network.Lukso]: db.consensusClientLukso
};
protected static readonly DefaultCheckpointSync: Record<Network, string> = {
[Network.Mainnet]: "https://checkpoint-sync.dappnode.io",
[Network.Prater]: "https://checkpoint-sync-prater.dappnode.io",
[Network.Gnosis]: "https://checkpoint-sync-gnosis.dappnode.io",
[Network.Holesky]: "https://checkpoint-sync-holesky.dappnode.io",
[Network.Lukso]: "https://checkpoints.mainnet.lukso.network"
};
protected static readonly CompatibleConsensus: Record<Network, { dnpName: string; minVersion: string }[]> = {
[Network.Mainnet]: [
{ dnpName: ConsensusClientMainnet.Prysm, minVersion: "3.0.4" },
Expand Down Expand Up @@ -94,7 +88,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 @@ -103,57 +97,28 @@ export class Consensus extends StakerComponent {
async setNewConsensus(network: Network, newConsensusDnpName: string | null) {
const prevConsClientDnpName = this.DbHandlers[network].get();

const mustInstallPkg = !!newConsensusDnpName && !(await listPackageNoThrow({ dnpName: newConsensusDnpName }));
const userSettings = newConsensusDnpName ? this.getUserSettings(mustInstallPkg, network) : {};

await super.setNew({
newStakerDnpName: newConsensusDnpName,
dockerNetworkName: params.DOCKER_STAKER_NETWORKS[network],
compatibleClients: Consensus.CompatibleConsensus[network],
userSettings: newConsensusDnpName
? this.getUserSettings(
newConsensusDnpName,
!(await listPackageNoThrow({ dnpName: newConsensusDnpName })),
network
)
: {},
userSettings,
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);
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
},
private getUserSettings(shouldSetEnvironment: boolean, network: Network): UserSettings {
const validatorServiceName = "validator";
const beaconServiceName = "beacon-chain";

[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]
}
}
: {},
const consensusDefaultUserSettings = getConsensusUserSettings({ network });

return {
environment: shouldSetEnvironment ? consensusDefaultUserSettings.environment : {},
networks: {
rootNetworks: {
[params.DOCKER_STAKER_NETWORKS[network]]: {
Expand All @@ -163,55 +128,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: {
[beaconServiceName]: {
[params.DOCKER_STAKER_NETWORKS[network]]: {
aliases: [`${beaconServiceName}.${network}.staker.dappnode`]
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
aliases: [`${beaconServiceName}.${network}.dncore.dappnode`]
}
},
[validatorServiceName]: {
[params.DOCKER_STAKER_NETWORKS[network]]: {
aliases: [`${validatorServiceName}.${network}.staker.dappnode`]
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
aliases: [`${validatorServiceName}.${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
85 changes: 28 additions & 57 deletions packages/utils/src/stakerUtils.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,41 @@
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";
}
import { UserSettings, Network } from "@dappnode/types";

/**
* Get the user settings for the consensus client.
* It may be different depending if it is multiservice or monoservice and all the envs are
* set in the same service
*/
export function getConsensusUserSettings({
dnpName,
network
}: {
dnpName: string;
network: Network;
}): UserSettingsAllDnps {
const validatorServiceName = getValidatorServiceName(dnpName);
const beaconServiceName = getBeaconServiceName(dnpName);
export function getConsensusUserSettings({ network }: { network: Network }): UserSettings {
const validatorServiceName = "validator";
const beaconServiceName = "beacon-chain";
const beaconValidatorServiceName = "beacon-validator";
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: {
// TODO: Remove once Nimbus is split into 2 services
[beaconValidatorServiceName]: {
// Fee recipient is set as global env, keep this for backwards compatibility
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is okay to include it in all cases, because the applyUserSettings function will only take into account the existing services in the compose of the package to install/start:
image

["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
},

[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