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

Remove fullnode alias from dncore network #2060

Merged
merged 2 commits into from
Dec 5, 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
1 change: 1 addition & 0 deletions packages/stakers/src/consensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class Consensus extends StakerComponent {
await super.setNew({
newStakerDnpName: newConsensusDnpName,
dockerNetworkName: params.DOCKER_STAKER_NETWORKS[network],
fullnodeAlias: `consensus.${network}.dncore.dappnode`,
compatibleClients: Consensus.CompatibleConsensus[network],
userSettings,
prevClient: prevConsClientDnpName
Expand Down
1 change: 1 addition & 0 deletions packages/stakers/src/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class Execution extends StakerComponent {
await super.setNew({
newStakerDnpName: newExecutionDnpName,
dockerNetworkName: params.DOCKER_STAKER_NETWORKS[network],
fullnodeAlias: `execution.${network}.dncore.dappnode`,
compatibleClients: Execution.CompatibleExecutions[network],
userSettings: await this.getUserSettings(network, newExecutionDnpName),
prevClient: prevExecClientDnpName
Expand Down
1 change: 1 addition & 0 deletions packages/stakers/src/mevBoost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class MevBoost extends StakerComponent {
await super.setNew({
newStakerDnpName: newMevBoostDnpName,
dockerNetworkName: params.DOCKER_STAKER_NETWORKS[network],
fullnodeAlias: `mev-boost.${network}.dncore.dappnode`,
compatibleClients: compatibleMevBoost ? [compatibleMevBoost] : null,
userSettings: newMevBoostDnpName ? this.getUserSettings(network, newRelays) : {},
prevClient: compatibleMevBoost ? compatibleMevBoost.dnpName : null
Expand Down
1 change: 1 addition & 0 deletions packages/stakers/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class Signer extends StakerComponent {
await super.setNew({
newStakerDnpName: newWeb3signerDnpName,
dockerNetworkName: params.DOCKER_STAKER_NETWORKS[network],
fullnodeAlias: `signer.${network}.dncore.dappnode`,
compatibleClients: [Signer.CompatibleSigners[network]],
userSettings: this.getUserSettings(network),
prevClient: Signer.CompatibleSigners[network].dnpName
Expand Down
36 changes: 34 additions & 2 deletions packages/stakers/src/stakerComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ export class StakerComponent {
protected async setNew({
newStakerDnpName,
dockerNetworkName,
fullnodeAlias,
compatibleClients,
userSettings,
prevClient
}: {
newStakerDnpName: string | null | undefined;
dockerNetworkName: string;
fullnodeAlias: string;
compatibleClients:
| {
dnpName: string;
Expand All @@ -83,7 +85,8 @@ export class StakerComponent {
if (currentPkg) {
if (prevClient && compatibleClients)
this.ensureCompatibilityRequirements(prevClient, compatibleClients, currentPkg.version);
if (prevClient !== newStakerDnpName) await this.unsetStakerPkgConfig(currentPkg, dockerNetworkName);
if (prevClient !== newStakerDnpName)
await this.unsetStakerPkgConfig({ pkg: currentPkg, dockerNetworkName, fullnodeAlias });
}

if (!newStakerDnpName) return;
Expand Down Expand Up @@ -178,8 +181,17 @@ export class StakerComponent {
* - stops the staker pkg
* - removes the staker network from the docker-compose file
*/
private async unsetStakerPkgConfig(pkg: InstalledPackageData, dockerNetworkName: string): Promise<void> {
private async unsetStakerPkgConfig({
pkg,
dockerNetworkName,
fullnodeAlias
}: {
pkg: InstalledPackageData;
dockerNetworkName: string;
fullnodeAlias: string;
}): Promise<void> {
this.removeStakerNetworkFromCompose(pkg.dnpName, dockerNetworkName);
this.removeFullnodeAliasFromDncoreNetwork(pkg.dnpName, fullnodeAlias);

// This recreates the package containers so that they include the recently added configuration
// The flag --no-start is added so that the containers remain stopped after recreation
Expand All @@ -190,6 +202,26 @@ export class StakerComponent {
});
}

private removeFullnodeAliasFromDncoreNetwork(dnpName: string, fullnodeAlias: string): void {
const composeEditor = new ComposeFileEditor(dnpName, false);
const services = composeEditor.compose.services;

for (const [, service] of Object.entries(services)) {
const serviceNetworks = service.networks;

if (!serviceNetworks || Array.isArray(serviceNetworks)) continue;

for (const [networkName, networkSettings] of Object.entries(serviceNetworks)) {
if (networkName === params.DOCKER_PRIVATE_NETWORK_NAME) {
const aliases = networkSettings.aliases;
if (aliases) networkSettings.aliases = aliases.filter((alias) => alias !== fullnodeAlias);
}
}
}

composeEditor.write();
}

private removeStakerNetworkFromCompose(dnpName: string, dockerNetworkName: string): void {
const composeEditor = new ComposeFileEditor(dnpName, false);
const services = composeEditor.compose.services;
Expand Down
Loading