Skip to content

Commit

Permalink
feat: dynamically construct the genesis-network.json and add it to th…
Browse files Browse the repository at this point in the history
…e values file to be used during network deploy (#982)

Signed-off-by: Jeromy Cannon <jeromy@swirldslabs.com>
Co-authored-by: Jeromy Cannon <jeromy@swirldslabs.com>
  • Loading branch information
instamenta and jeromy-cannon authored Dec 23, 2024
1 parent 3c3673a commit 1b9b7e6
Show file tree
Hide file tree
Showing 24 changed files with 450 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/zxc-e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:
if: ${{ runner.os == 'linux' && (inputs.npm-test-script == 'test-e2e-node-local-hedera' || inputs.npm-test-script == 'test-e2e-node-local-ptt' || inputs.npm-test-script == 'test-e2e-node-add-local') && !cancelled() && !failure() }}
run: |
cd ..
git clone https://github.com/hashgraph/hedera-services.git --depth 1 --branch v0.57.3
git clone https://github.com/hashgraph/hedera-services.git --depth 1 --branch v0.58.0
cd hedera-services
ls -ltr
${{ env.CG_EXEC }} ./gradlew assemble --stacktrace --info
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
SOLO_NETWORK_SIZE: 2
SOLO_NAMESPACE: solo-e2e
SOLO_CHART_VERSION: 0.36.3
CONSENSUS_NODE_VERSION: v0.57.3
CONSENSUS_NODE_VERSION: v0.58.0
vars:
use_port_forwards: "true"

Expand Down
2 changes: 1 addition & 1 deletion examples/custom-network-config/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
SOLO_NETWORK_SIZE: 10
SOLO_NAMESPACE: solo-alex-kuzmin-n4
SOLO_CHART_VERSION: 0.36.3
CONSENSUS_NODE_VERSION: v0.57.3
CONSENSUS_NODE_VERSION: v0.58.0
VALUES_FLAG: "--values-file {{.USER_WORKING_DIR}}/init-containers-values.yaml"
SETTINGS_FLAG: "--settings-txt {{.USER_WORKING_DIR}}/settings.txt"
SOLO_HOME: "/Users/user/.solo-alex-kuzmin-n4"
Expand Down
2 changes: 1 addition & 1 deletion examples/performance-tuning/Latitude/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
SOLO_NETWORK_SIZE: 10
SOLO_NAMESPACE: solo-perf-lat
SOLO_CHART_VERSION: 0.36.3
CONSENSUS_NODE_VERSION: v0.57.3
CONSENSUS_NODE_VERSION: v0.58.0
VALUES_FLAG: "--values-file {{.USER_WORKING_DIR}}/init-containers-values.yaml"
SETTINGS_FLAG: "--settings-txt {{.USER_WORKING_DIR}}/settings.txt"
SOLO_HOME: "/Users/user/.solo-perf-lat"
Expand Down
2 changes: 1 addition & 1 deletion examples/performance-tuning/solo-perf-test/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
SOLO_NETWORK_SIZE: 7
SOLO_NAMESPACE: solo-perf-test
SOLO_CHART_VERSION: 0.36.3
CONSENSUS_NODE_VERSION: v0.57.3
CONSENSUS_NODE_VERSION: v0.58.0
VALUES_FLAG: "--values-file {{.USER_WORKING_DIR}}/init-containers-values.yaml"
SETTINGS_FLAG: "--settings-txt {{.USER_WORKING_DIR}}/settings.txt"
SOLO_HOME: "/Users/user/.solo-perf-test"
Expand Down
2 changes: 1 addition & 1 deletion examples/solo-gke-test/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
SOLO_NETWORK_SIZE: 5
SOLO_NAMESPACE: solo-gke-test
SOLO_CHART_VERSION: 0.36.3
CONSENSUS_NODE_VERSION: v0.57.3
CONSENSUS_NODE_VERSION: v0.58.0
VALUES_FLAG: "--values-file {{.USER_WORKING_DIR}}/init-containers-values.yaml"
SETTINGS_FLAG: "--settings-txt {{.USER_WORKING_DIR}}/settings.txt"
SOLO_HOME: "{{.solo_home_override_dir}}"
Expand Down
3 changes: 2 additions & 1 deletion resources/templates/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ hedera.profiles.active=TEST
# TODO: this is a workaround until prepareUpgrade freeze will recalculate the weight prior to writing the config.txt
staking.periodMins=1
nodes.updateAccountIdAllowed=true

# TODO: remove once we have the uploader enabled, required for current p0 deadline
blockStream.streamMode=RECORDS
55 changes: 33 additions & 22 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {ConsensusNodeComponent} from '../core/config/remote/components/consensus
import {ConsensusNodeStates} from '../core/config/remote/enumerations.js';
import {EnvoyProxyComponent} from '../core/config/remote/components/envoy_proxy_component.js';
import {HaProxyComponent} from '../core/config/remote/components/ha_proxy_component.js';
import {GenesisNetworkDataConstructor} from '../core/genesis_network_models/genesis_network_data_constructor.js';

export interface NetworkDeployConfigClass {
applicationEnv: string;
Expand All @@ -61,6 +62,7 @@ export interface NetworkDeployConfigClass {
grpcWebTlsCertificatePath: string;
grpcTlsKeyPath: string;
grpcWebTlsKeyPath: string;
genesisNetworkData: GenesisNetworkDataConstructor;
getUnusedConfigs: () => string[];
haproxyIps: string;
envoyIps: string;
Expand Down Expand Up @@ -130,20 +132,19 @@ export class NetworkCommand extends BaseCommand {
];
}

async prepareValuesArg(
config: {
chartDirectory?: string;
app?: string;
nodeAliases?: string[];
debugNodeAlias?: NodeAlias;
enablePrometheusSvcMonitor?: boolean;
releaseTag?: string;
persistentVolumeClaims?: string;
valuesFile?: string;
haproxyIpsParsed?: Record<NodeAlias, IP>;
envoyIpsParsed?: Record<NodeAlias, IP>;
} = {},
) {
async prepareValuesArg(config: {
chartDirectory?: string;
app?: string;
nodeAliases: string[];
debugNodeAlias?: NodeAlias;
enablePrometheusSvcMonitor?: boolean;
releaseTag?: string;
persistentVolumeClaims?: string;
valuesFile?: string;
haproxyIpsParsed?: Record<NodeAlias, IP>;
envoyIpsParsed?: Record<NodeAlias, IP>;
genesisNetworkData: GenesisNetworkDataConstructor;
}) {
let valuesArg = config.chartDirectory
? `-f ${path.join(config.chartDirectory, 'solo-deployment', 'values.yaml')}`
: '';
Expand All @@ -160,7 +161,10 @@ export class NetworkCommand extends BaseCommand {
}

const profileName = this.configManager.getFlag<string>(flags.profileName) as string;
this.profileValuesFile = await this.profileManager.prepareValuesForSoloChart(profileName);
this.profileValuesFile = await this.profileManager.prepareValuesForSoloChart(
profileName,
config.genesisNetworkData,
);
if (this.profileValuesFile) {
valuesArg += this.prepareValuesFiles(this.profileValuesFile);
}
Expand All @@ -172,7 +176,7 @@ export class NetworkCommand extends BaseCommand {

// Iterate over each node and set static IPs for HAProxy
if (config.haproxyIpsParsed) {
config.nodeAliases?.forEach((nodeAlias, index) => {
config.nodeAliases.forEach((nodeAlias, index) => {
const ip = config.haproxyIpsParsed?.[nodeAlias];

if (ip) valuesArg += ` --set "hedera.nodes[${index}].haproxyStaticIP=${ip}"`;
Expand All @@ -181,7 +185,7 @@ export class NetworkCommand extends BaseCommand {

// Iterate over each node and set static IPs for Envoy Proxy
if (config.envoyIpsParsed) {
config.nodeAliases?.forEach((nodeAlias, index) => {
config.nodeAliases.forEach((nodeAlias, index) => {
const ip = config.envoyIpsParsed?.[nodeAlias];

if (ip) valuesArg += ` --set "hedera.nodes[${index}].envoyProxyStaticIP=${ip}"`;
Expand Down Expand Up @@ -253,13 +257,19 @@ export class NetworkCommand extends BaseCommand {
constants.SOLO_DEPLOYMENT_CHART,
);

config.valuesArg = await this.prepareValuesArg(config);

// compute other config parameters
config.keysDir = path.join(validatePath(config.cacheDir), 'keys');
config.stagingDir = Templates.renderStagingDir(config.cacheDir, config.releaseTag);
config.stagingKeysDir = path.join(validatePath(config.stagingDir), 'keys');

config.genesisNetworkData = await GenesisNetworkDataConstructor.initialize(
config.nodeAliases,
this.keyManager,
config.keysDir,
);

config.valuesArg = await this.prepareValuesArg(config);

if (!(await this.k8.hasNamespace(config.namespace))) {
await this.k8.createNamespace(config.namespace);
}
Expand Down Expand Up @@ -341,7 +351,7 @@ export class NetworkCommand extends BaseCommand {
},
{
title: 'Check if cluster setup chart is installed',
task: async (ctx, task) => {
task: async () => {
const isChartInstalled = await this.chartManager.isChartInstalled('', constants.SOLO_CLUSTER_SETUP_CHART);
if (!isChartInstalled) {
throw new SoloError(
Expand Down Expand Up @@ -386,7 +396,7 @@ export class NetworkCommand extends BaseCommand {
task: (ctx, parentTask) => {
const config = ctx.config;

// set up the sub-tasks
// set up the subtasks
return parentTask.newListr(self.platformInstaller.copyNodeKeys(config.stagingDir, config.nodeAliases), {
concurrent: true,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
Expand Down Expand Up @@ -502,7 +512,7 @@ export class NetworkCommand extends BaseCommand {
),
});

// set up the sub-tasks
// set up the subtasks
return task.newListr(subTasks, {
concurrent: false, // no need to run concurrently since if one node is up, the rest should be up by then
rendererOptions: {
Expand Down Expand Up @@ -754,6 +764,7 @@ export class NetworkCommand extends BaseCommand {
},
};
}

/** Adds the consensus node, envoy and haproxy components to remote config. */
public addNodesAndProxies(): ListrTask<any, any, any> {
return {
Expand Down
45 changes: 3 additions & 42 deletions src/commands/node/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import path from 'path';
import fs from 'fs';
import {validatePath} from '../../core/helpers.js';
import {Flags as flags} from '../flags.js';
import {type NodeAlias, type NodeAliases, type PodName} from '../../types/aliases.js';
import {type NetworkNodeServices} from '../../core/network_node_services.js';
import type {NodeAlias, NodeAliases, PodName} from '../../types/aliases.js';
import type {NetworkNodeServices} from '../../core/network_node_services.js';
import {type NodeAddConfigClass} from './node_add_config.js';

export const PREPARE_UPGRADE_CONFIGS_NAME = 'prepareUpgradeConfig';
export const DOWNLOAD_GENERATED_FILES_CONFIGS_NAME = 'downloadGeneratedFilesConfig';
Expand Down Expand Up @@ -357,46 +358,6 @@ export interface NodeStartConfigClass {
nodeAliasesUnparsed: string;
}

export interface NodeAddConfigClass {
app: string;
cacheDir: string;
chainId: string;
chartDirectory: string;
devMode: boolean;
debugNodeAlias: NodeAlias;
endpointType: string;
soloChartVersion: string;
generateGossipKeys: boolean;
generateTlsKeys: boolean;
gossipEndpoints: string;
grpcEndpoints: string;
localBuildPath: string;
namespace: string;
nodeAlias: NodeAlias;
releaseTag: string;
adminKey: PrivateKey;
allNodeAliases: NodeAliases;
chartPath: string;
curDate: Date;
existingNodeAliases: NodeAliases;
freezeAdminPrivateKey: string;
keysDir: string;
lastStateZipPath: string;
nodeClient: any;
podNames: Record<NodeAlias, PodName>;
serviceMap: Map<string, NetworkNodeServices>;
treasuryKey: PrivateKey;
stagingDir: string;
stagingKeysDir: string;
grpcTlsCertificatePath: string;
grpcWebTlsCertificatePath: string;
grpcTlsKeyPath: string;
grpcWebTlsKeyPath: string;
haproxyIps: string;
envoyIps: string;
getUnusedConfigs: () => string[];
}

export interface NodeDeleteConfigClass {
app: string;
cacheDir: string;
Expand Down
59 changes: 59 additions & 0 deletions src/commands/node/node_add_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the ""License"");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an ""AS IS"" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import type {NodeAlias, NodeAliases, PodName} from '../../types/aliases.js';
import type {NetworkNodeServices} from '../../core/network_node_services.js';
import {type PrivateKey} from '@hashgraph/sdk';

export interface NodeAddConfigClass {
app: string;
cacheDir: string;
chainId: string;
chartDirectory: string;
devMode: boolean;
debugNodeAlias: NodeAlias;
endpointType: string;
soloChartVersion: string;
generateGossipKeys: boolean;
generateTlsKeys: boolean;
gossipEndpoints: string;
grpcEndpoints: string;
localBuildPath: string;
namespace: string;
nodeAlias: NodeAlias;
releaseTag: string;
adminKey: PrivateKey;
allNodeAliases: NodeAliases;
chartPath: string;
curDate: Date;
existingNodeAliases: NodeAliases;
freezeAdminPrivateKey: string;
keysDir: string;
lastStateZipPath: string;
nodeClient: any;
podNames: Record<NodeAlias, PodName>;
serviceMap: Map<string, NetworkNodeServices>;
treasuryKey: PrivateKey;
stagingDir: string;
stagingKeysDir: string;
grpcTlsCertificatePath: string;
grpcWebTlsCertificatePath: string;
grpcTlsKeyPath: string;
grpcWebTlsKeyPath: string;
haproxyIps: string;
envoyIps: string;
getUnusedConfigs: () => string[];
}
12 changes: 4 additions & 8 deletions src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
FREEZE_ADMIN_ACCOUNT,
HEDERA_NODE_DEFAULT_STAKE_AMOUNT,
IGNORED_NODE_ACCOUNT_ID,
LOCAL_HOST,
TREASURY_ACCOUNT_ID,
} from '../../core/constants.js';
import {
Expand Down Expand Up @@ -75,16 +74,12 @@ import {
} from '../../types/aliases.js';
import {NodeStatusCodes, NodeStatusEnums, NodeSubcommandType} from '../../core/enumerations.js';
import * as x509 from '@peculiar/x509';
import type {
NodeAddConfigClass,
NodeDeleteConfigClass,
NodeRefreshConfigClass,
NodeUpdateConfigClass,
} from './configs.js';
import type {NodeDeleteConfigClass, NodeRefreshConfigClass, NodeUpdateConfigClass} from './configs.js';
import {type Lease} from '../../core/lease/lease.js';
import {ListrLease} from '../../core/lease/listr_lease.js';
import {Duration} from '../../core/time/duration.js';
import {type BaseCommand} from '../base.js';
import {type NodeAddConfigClass} from './node_add_config.js';

export class NodeCommandTasks {
private readonly accountManager: AccountManager;
Expand Down Expand Up @@ -455,6 +450,7 @@ export class NodeCommandTasks {
*/
_generateGossipKeys(generateMultiple: boolean) {
const self = this;

return new Task(
'Generate gossip keys',
(ctx: any, task: ListrTaskWrapper<any, any, any>) => {
Expand Down Expand Up @@ -701,7 +697,7 @@ export class NodeCommandTasks {
config.stagingDir,
);

// if directory data/upgrade/current/data/keys does not exist then use data/upgrade/current
// if directory data/upgrade/current/data/keys does not exist, then use data/upgrade/current
let keyDir = `${constants.HEDERA_HAPI_PATH}/data/upgrade/current/data/keys`;
if (!(await self.k8.hasDir(nodeFullyQualifiedPodName, constants.ROOT_CONTAINER, keyDir))) {
keyDir = `${constants.HEDERA_HAPI_PATH}/data/upgrade/current`;
Expand Down
3 changes: 0 additions & 3 deletions src/core/account_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ export class AccountManager {
const host = networkNodeService.haProxyLoadBalancerIp as string;
const targetPort = port;
try {
await this.k8.testSocketConnection(host, targetPort);
obj[`${host}:${targetPort}`] = accountId;
await this.pingNetworkNode(obj, accountId);
this.logger.debug(`using load balancer IP: ${host}:${targetPort}`);
Expand All @@ -312,8 +311,6 @@ export class AccountManager {
this._portForwards.push(await this.k8.portForward(networkNodeService.haProxyPodName, localPort, port));
}

await this.k8.testSocketConnection(host, targetPort);

this.logger.debug(`using local host port forward: ${host}:${targetPort}`);
obj[`${host}:${targetPort}`] = accountId;

Expand Down
1 change: 1 addition & 0 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export const RELAY_PODS_RUNNING_MAX_ATTEMPTS = +process.env.RELAY_PODS_RUNNING_M
export const RELAY_PODS_RUNNING_DELAY = +process.env.RELAY_PODS_RUNNING_DELAY || 1_000;
export const RELAY_PODS_READY_MAX_ATTEMPTS = +process.env.RELAY_PODS_READY_MAX_ATTEMPTS || 100;
export const RELAY_PODS_READY_DELAY = +process.env.RELAY_PODS_READY_DELAY || 1_000;
export const GRPC_PORT = +process.env.GRPC_PORT || 50_211;

export const NETWORK_DESTROY_WAIT_TIMEOUT = +process.env.NETWORK_DESTROY_WAIT_TIMEOUT || 120;

Expand Down
Loading

0 comments on commit 1b9b7e6

Please sign in to comment.