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

Merge consensus aliases #1982

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 22 additions & 3 deletions packages/dockerCompose/src/userSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import path from "path";
import { mapValues, pick, omitBy, isObject, merge } from "lodash-es";
import {
mapValues,
pick,
omitBy,
isObject,
merge,
mergeWith,
isArray,
union,
} from "lodash-es";
import {
parsePortMappings,
stringifyPortMappings,
Expand Down Expand Up @@ -181,8 +190,18 @@ export function applyUserSettings(
})
);

// use lodash to merge networks and userSetNetworks with merge
const nextNetworks = merge(networks, userSetNetworks);
// docker aliases must be uinique
// TODO: use docker compose merge to automatically merge these dappnode docker compose properties
// see https://github.com/dappnode/DNP_DAPPMANAGER/issues/1983
const nextNetworks = mergeWith(
networks,
userSetNetworks,
(value1, value2) => {
return mergeWith(value1, value2, (subvalue1, subvalue2) => {
return union(subvalue1, subvalue2);
});
}
);

// ##### <DEPRECATED> Kept for legacy compatibility
const nextServiceVolumes = stringifyVolumeMappings(
Expand Down
58 changes: 26 additions & 32 deletions packages/stakers/src/consensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ export class Consensus extends StakerComponent {
this.DbHandlers[network].set(undefined);
return;
}
await this.persistSelectedIfInstalled(
currentConsensusDnpName,
this.getUserSettings(currentConsensusDnpName, isInstalled, network)
);
await this.persistSelectedIfInstalled({
dnpName: currentConsensusDnpName,
userSettings: this.getUserSettings(
currentConsensusDnpName,
isInstalled,
network
),
});
await this.DbHandlers[network].set(currentConsensusDnpName);
}
}
Expand Down Expand Up @@ -173,19 +177,19 @@ export class Consensus extends StakerComponent {
},
}
: {},
networks:
beaconServiceName === validatorServiceName
? {
rootNetworks: {
[params.DOCKER_STAKER_NETWORKS[network]]: {
external: true,
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
external: true,
},
},
serviceNetworks: {
["beacon-validator"]: {
networks: {
rootNetworks: {
[params.DOCKER_STAKER_NETWORKS[network]]: {
external: true,
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
external: true,
},
},
serviceNetworks:
beaconServiceName === validatorServiceName
? {
"beacon-validator": {
[params.DOCKER_STAKER_NETWORKS[network]]: {
aliases: [
`beacon-chain.${network}.staker.dappnode`,
Expand All @@ -199,27 +203,17 @@ export class Consensus extends StakerComponent {
],
},
},
},
}
: {
rootNetworks: {
[params.DOCKER_STAKER_NETWORKS[network]]: {
external: true,
},
[params.DOCKER_PRIVATE_NETWORK_NAME]: {
external: true,
},
},
serviceNetworks: {
["beacon-chain"]: {
}
: {
"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"]: {
validator: {
[params.DOCKER_STAKER_NETWORKS[network]]: {
aliases: [`validator.${network}.staker.dappnode`],
},
Expand All @@ -228,7 +222,7 @@ export class Consensus extends StakerComponent {
},
},
},
},
},
};
}

Expand Down
8 changes: 4 additions & 4 deletions packages/stakers/src/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export class Execution extends StakerComponent {
this.DbHandlers[network].set(undefined);
return;
}
await this.persistSelectedIfInstalled(
currentExecutionDnpName,
this.getUserSettings(network, currentExecutionDnpName)
);
await this.persistSelectedIfInstalled({
dnpName: currentExecutionDnpName,
userSettings: this.getUserSettings(network, currentExecutionDnpName),
});
await this.DbHandlers[network].set(currentExecutionDnpName);
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/stakers/src/mevBoost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ export class MevBoost extends StakerComponent {
this.DbHandlers[network].set(false);
return;
}
await this.persistSelectedIfInstalled(
currentMevBoostDnpName,
this.getUserSettings([], false, network)
);
await this.persistSelectedIfInstalled({
dnpName: currentMevBoostDnpName,
userSettings: this.getUserSettings([], false, network),
});
this.DbHandlers[network].set(true);
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/stakers/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export class Signer extends StakerComponent {
})
)?.containers.some((container) => container.running)
)
await this.persistSelectedIfInstalled(
Signer.CompatibleSigners[network].dnpName,
this.getUserSettings(network)
);
await this.persistSelectedIfInstalled({
dnpName: Signer.CompatibleSigners[network].dnpName,
userSettings: this.getUserSettings(network),
});
}

async setNewSigner(network: Network, newWeb3signerDnpName: string | null) {
Expand Down
36 changes: 25 additions & 11 deletions packages/stakers/src/stakerComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ export class StakerComponent {
);
}

protected async persistSelectedIfInstalled(
dnpName: string,
userSettings: UserSettings
): Promise<void> {
protected async persistSelectedIfInstalled({
dnpName,
userSettings,
}: {
dnpName: string;
userSettings: UserSettings;
}): Promise<void> {
logs.info(`Persisting ${dnpName}`);
await this.setStakerPkgConfig(dnpName, userSettings);
await this.setStakerPkgConfig({ dnpName, isInstalled: true, userSettings });
}

protected async setNew({
Expand Down Expand Up @@ -122,7 +125,13 @@ export class StakerComponent {

if (!newStakerDnpName) return;
// set staker config
await this.setStakerPkgConfig(newStakerDnpName, userSettings);
await this.setStakerPkgConfig({
dnpName: newStakerDnpName,
isInstalled: Boolean(
await listPackageNoThrow({ dnpName: newStakerDnpName })
),
userSettings,
});
}

/**
Expand All @@ -132,12 +141,17 @@ export class StakerComponent {
* - adds the staker network to the docker-compose file
* - starts the staker pkg
*/
private async setStakerPkgConfig(
dnpName: string,
userSettings: UserSettings
): Promise<void> {
private async setStakerPkgConfig({
dnpName,
isInstalled,
userSettings,
}: {
dnpName: string;
isInstalled: boolean;
userSettings: UserSettings;
}): Promise<void> {
// ensure pkg installed
if (!(await listPackageNoThrow({ dnpName })))
if (!isInstalled)
await packageInstall(this.dappnodeInstaller, {
name: dnpName,
userSettings: userSettings ? { [dnpName]: userSettings } : {},
Expand Down
Loading