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

feat: create the v059x node-override.yaml via solo #1192

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
67ad483
implemented copying mechanism and created the initial data wrapper fo…
instamenta Jan 20, 2025
82d0a8f
apply recommended changes
instamenta Jan 21, 2025
0ca31f0
updated to latest version of hedera-service main branch
jeromy-cannon Jan 21, 2025
0441417
Merge remote-tracking branch 'origin/main' into 01151-create-the-v059…
instamenta Jan 22, 2025
74d1c16
merge with main and ran npm i
instamenta Jan 23, 2025
401ebac
Merge remote-tracking branch 'origin/main' into 01151-create-the-v059…
instamenta Jan 24, 2025
91329f1
Merge remote-tracking branch 'origin/main' into 01151-create-the-v059…
instamenta Jan 27, 2025
03f86ba
Merge branch 'main' into 01151-create-the-v059x-network-overrideyml-v…
jeromy-cannon Jan 27, 2025
0dccc4d
switch to new structure for the NetworkOverridesModel.toYaml() method…
instamenta Jan 28, 2025
d4511e6
add functionality to turn json string inside the node overrides to js…
instamenta Jan 29, 2025
bef5aa0
Merge remote-tracking branch 'origin/main' into 01151-create-the-v059…
instamenta Jan 31, 2025
ff069c8
swith all calls to the setupNetworkNode method to true on the isGenes…
instamenta Feb 3, 2025
ea50860
fix lint errors
instamenta Feb 3, 2025
219af9a
add try catch when trying to get the admin pub key fromStringED25519 …
instamenta Feb 3, 2025
941af82
revert to stable hedera platform version
instamenta Feb 3, 2025
294256e
rename from NetworkOverridesModel to NodeOverridesModel
instamenta Feb 3, 2025
8fc07f5
Merge commit '04b616e16ee224772ac5a1d181d814713400984d' into 01151-cr…
JeffreyDallas Feb 5, 2025
fab250b
Update src/commands/node/handlers.ts
JeffreyDallas Feb 5, 2025
444614a
Update src/commands/node/handlers.ts
JeffreyDallas Feb 5, 2025
f87b07c
Update src/commands/node/handlers.ts
JeffreyDallas Feb 5, 2025
f1035e9
add constant
JeffreyDallas Feb 5, 2025
218eddf
generate new key if not found
JeffreyDallas Feb 5, 2025
badbaaf
fix constructor
JeffreyDallas Feb 5, 2025
8a6bfbf
save
JeffreyDallas Feb 5, 2025
1f53f30
Merge branch 'main' into 01151-create-the-v059x-network-overrideyml-v…
JeffreyDallas Feb 5, 2025
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
11 changes: 5 additions & 6 deletions src/commands/node/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class NodeCommandHandlers implements CommandHandlers {
this.tasks.checkNodePodsAreRunning(),
this.tasks.populateServiceMap(),
this.tasks.fetchPlatformSoftware('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases', false),
this.tasks.startNodes('allNodeAliases'),
this.tasks.enablePortForwarding(),
this.tasks.checkAllNodesAreActive('allNodeAliases'),
Expand Down Expand Up @@ -172,7 +172,7 @@ export class NodeCommandHandlers implements CommandHandlers {
this.tasks.fetchPlatformSoftware('allNodeAliases'),
this.tasks.downloadLastState(),
this.tasks.uploadStateToNewNode(),
this.tasks.setupNetworkNodes('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases', false),
this.tasks.startNodes('allNodeAliases'),
this.tasks.enablePortForwarding(),
this.tasks.checkAllNodesAreActive('allNodeAliases'),
Expand Down Expand Up @@ -217,7 +217,7 @@ export class NodeCommandHandlers implements CommandHandlers {
this.tasks.killNodesAndUpdateConfigMap(),
this.tasks.checkNodePodsAreRunning(),
this.tasks.fetchPlatformSoftware('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases', false),
this.tasks.startNodes('allNodeAliases'),
this.tasks.enablePortForwarding(),
this.tasks.checkAllNodesAreActive('allNodeAliases'),
Expand Down Expand Up @@ -716,7 +716,7 @@ export class NodeCommandHandlers implements CommandHandlers {
this.tasks.identifyNetworkPods(),
this.tasks.dumpNetworkNodesSaveState(),
this.tasks.fetchPlatformSoftware('nodeAliases'),
this.tasks.setupNetworkNodes('nodeAliases'),
this.tasks.setupNetworkNodes('nodeAliases', true),
this.tasks.startNodes('nodeAliases'),
this.tasks.checkAllNodesAreActive('nodeAliases'),
this.tasks.checkNodeProxiesAreActive(),
Expand Down Expand Up @@ -825,8 +825,7 @@ export class NodeCommandHandlers implements CommandHandlers {
}),
this.tasks.identifyNetworkPods(),
this.tasks.fetchPlatformSoftware('nodeAliases'),
// TODO: change to isGenesis: true once we are ready to use genesis-network.json: this.tasks.setupNetworkNodes('nodeAliases', true),
this.tasks.setupNetworkNodes('nodeAliases', false),
this.tasks.setupNetworkNodes('nodeAliases', true),
this.changeAllNodeStates(ConsensusNodeStates.SETUP),
],
{
Expand Down
15 changes: 14 additions & 1 deletion src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import {type BaseCommand} from '../base.js';
import {type NodeAddConfigClass} from './node_add_config.js';
import {GenesisNetworkDataConstructor} from '../../core/genesis_network_models/genesis_network_data_constructor.js';
import {NodeOverridesModel} from '../../core/network_overrides_model.js';
import {type NamespaceName} from '../../core/kube/namespace_name.js';
import {PodRef} from '../../core/kube/pod_ref.js';
import {Container} from '../../core/container_init.js';
Expand Down Expand Up @@ -903,7 +904,7 @@
});
}

setupNetworkNodes(nodeAliasesProperty: string, isGenesis: boolean = false) {
setupNetworkNodes(nodeAliasesProperty: string, isGenesis: boolean) {
return new Task('Setup network nodes', async (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
if (isGenesis) {
await this.generateGenesisNetworkJson(
Expand All @@ -914,6 +915,8 @@
);
}

await this.generateNetworksOverridesJson(ctx.config.namespace, ctx.config.nodeAliases, ctx.config.stagingDir);

const subTasks = [];
for (const nodeAlias of ctx.config[nodeAliasesProperty]) {
const podRef = ctx.config.podRefs[nodeAlias];
Expand All @@ -931,6 +934,15 @@
});
}

private async generateNetworksOverridesJson(namespace: NamespaceName, nodeAliases: NodeAliases, stagingDir: string) {
const networkNodeServiceMap = await this.accountManager.getNodeServiceMap(namespace);

const networkOverridesModel = new NodeOverridesModel(nodeAliases, networkNodeServiceMap);

const genesisNetworkJson = path.join(stagingDir, constants.NODE_OVERRIDE_FILE);

Check warning on line 942 in src/commands/node/tasks.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/node/tasks.ts#L942

Detected possible user input going into a `path.join` or `path.resolve` function.
fs.writeFileSync(genesisNetworkJson, networkOverridesModel.toYAML());

Check warning on line 943 in src/commands/node/tasks.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/node/tasks.ts#L943

The application dynamically constructs file or path information.
}

/**
* Generate genesis network json file
* @private
Expand All @@ -951,6 +963,7 @@
const genesisNetworkData = await GenesisNetworkDataConstructor.initialize(
nodeAliases,
this.keyManager,
this.accountManager,
keysDir,
networkNodeServiceMap,
adminPublicKeys,
Expand Down
1 change: 1 addition & 0 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export const GRPC_PORT = +process.env.GRPC_PORT || 50_211;
export const NETWORK_DESTROY_WAIT_TIMEOUT = +process.env.NETWORK_DESTROY_WAIT_TIMEOUT || 120;

export const DEFAULT_LOCAL_CONFIG_FILE = 'local-config.yaml';
export const NODE_OVERRIDE_FILE = 'node-overrides.yaml';
export const IGNORED_NODE_ACCOUNT_ID = '0.0.0';

export const UPLOADER_SECRET_NAME = 'uploader-mirror-secrets';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,78 @@ import path from 'path';
import {type NetworkNodeServices} from '../network_node_services.js';
import {SoloError} from '../errors.js';
import {Flags as flags} from '../../commands/flags.js';
import {type AccountManager} from '../account_manager.js';

/**
* Used to construct the nodes data and convert them to JSON
*/
export class GenesisNetworkDataConstructor implements ToJSON {
public readonly nodes: Record<NodeAlias, GenesisNetworkNodeDataWrapper> = {};
public readonly rosters: Record<NodeAlias, GenesisNetworkRosterEntryDataWrapper> = {};

private readonly initializationPromise: Promise<void>;
private constructor(
private readonly nodeAliases: NodeAliases,
private readonly keyManager: KeyManager,
private readonly accountManager: AccountManager,
private readonly keysDir: string,
private readonly networkNodeServiceMap: Map<string, NetworkNodeServices>,
adminPublicKeyMap: Map<NodeAlias, string>,
) {
nodeAliases.forEach(nodeAlias => {
const genesisPrivateKey = PrivateKey.fromStringED25519(constants.GENESIS_KEY);
const adminPubKey = PublicKey.fromStringED25519(adminPublicKeyMap[nodeAlias])
? adminPublicKeyMap[nodeAlias]
: genesisPrivateKey.publicKey;

const nodeDataWrapper = new GenesisNetworkNodeDataWrapper(
+networkNodeServiceMap.get(nodeAlias).nodeId,
adminPubKey,
nodeAlias,
);
this.nodes[nodeAlias] = nodeDataWrapper;
nodeDataWrapper.accountId = AccountId.fromString(networkNodeServiceMap.get(nodeAlias).accountId);

const rosterDataWrapper = new GenesisNetworkRosterEntryDataWrapper(+networkNodeServiceMap.get(nodeAlias).nodeId);
this.rosters[nodeAlias] = rosterDataWrapper;
rosterDataWrapper.weight = this.nodes[nodeAlias].weight = constants.HEDERA_NODE_DEFAULT_STAKE_AMOUNT;

const externalPort = +constants.HEDERA_NODE_EXTERNAL_GOSSIP_PORT;
const namespace = networkNodeServiceMap.get(nodeAlias).namespace;
const externalIP = Templates.renderFullyQualifiedNetworkSvcName(namespace, nodeAlias);
// Add gossip endpoints
nodeDataWrapper.addGossipEndpoint(externalIP, externalPort);
rosterDataWrapper.addGossipEndpoint(externalIP, externalPort);

const haProxyFqdn = Templates.renderFullyQualifiedHaProxyName(nodeAlias, namespace);

// Add service endpoints
nodeDataWrapper.addServiceEndpoint(haProxyFqdn, constants.GRPC_PORT);
});
this.initializationPromise = (async () => {
nodeAliases.forEach(nodeAlias => {
let adminPubKey: PublicKey;
const accountId = AccountId.fromString(networkNodeServiceMap.get(nodeAlias).accountId);
const namespace = networkNodeServiceMap.get(nodeAlias).namespace;

if (adminPublicKeyMap.has(nodeAlias)) {
try {
if (PublicKey.fromStringED25519(adminPublicKeyMap[nodeAlias])) {
adminPubKey = adminPublicKeyMap[nodeAlias];
}
} catch {
// Ignore error
}
}

// not found existing one, generate a new key, and save to k8 secret
if (!adminPubKey) {
const newKey = PrivateKey.generate();
adminPubKey = newKey.publicKey;
this.accountManager.updateAccountKeys(namespace, accountId, newKey, true);
}

const nodeDataWrapper = new GenesisNetworkNodeDataWrapper(
+networkNodeServiceMap.get(nodeAlias).nodeId,
adminPubKey,
nodeAlias,
);
this.nodes[nodeAlias] = nodeDataWrapper;
nodeDataWrapper.accountId = accountId;

const rosterDataWrapper = new GenesisNetworkRosterEntryDataWrapper(
+networkNodeServiceMap.get(nodeAlias).nodeId,
);
this.rosters[nodeAlias] = rosterDataWrapper;
rosterDataWrapper.weight = this.nodes[nodeAlias].weight = constants.HEDERA_NODE_DEFAULT_STAKE_AMOUNT;

const externalPort = +constants.HEDERA_NODE_EXTERNAL_GOSSIP_PORT;
const externalIP = Templates.renderFullyQualifiedNetworkSvcName(namespace, nodeAlias);
// Add gossip endpoints
nodeDataWrapper.addGossipEndpoint(externalIP, externalPort);
rosterDataWrapper.addGossipEndpoint(externalIP, externalPort);

const haProxyFqdn = Templates.renderFullyQualifiedHaProxyName(nodeAlias, namespace);

// Add service endpoints
nodeDataWrapper.addServiceEndpoint(haProxyFqdn, constants.GRPC_PORT);
});
})();
}

public static async initialize(
nodeAliases: NodeAliases,
keyManager: KeyManager,
accountManager: AccountManager,
keysDir: string,
networkNodeServiceMap: Map<string, NetworkNodeServices>,
adminPublicKeys: string[],
Expand All @@ -86,6 +108,7 @@ export class GenesisNetworkDataConstructor implements ToJSON {
const instance = new GenesisNetworkDataConstructor(
nodeAliases,
keyManager,
accountManager,
keysDir,
networkNodeServiceMap,
adminPublicKeyMap,
Expand All @@ -100,6 +123,7 @@ export class GenesisNetworkDataConstructor implements ToJSON {
* Loads the gossipCaCertificate and grpcCertificateHash
*/
private async load() {
await this.initializationPromise;
await Promise.all(
this.nodeAliases.map(async nodeAlias => {
const signingCertFile = Templates.renderGossipPemPublicKeyFile(nodeAlias);
Expand Down
54 changes: 54 additions & 0 deletions src/core/network_overrides_model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* SPDX-License-Identifier: Apache-2.0
*/
import * as yaml from 'yaml';
import * as constants from './constants.js';
import {Templates} from './templates.js';
import {type NodeAliases} from '../types/aliases.js';
import {type NetworkNodeServices} from './network_node_services.js';
import {type GossipEndpoint} from '../types/index.js';

export class NodeOverridesModel {
private readonly interfaceBindings: GossipEndpoint[] = [];
private readonly endpointOverrides: GossipEndpoint[] = [];

public constructor(nodeAliases: NodeAliases, networkNodeServiceMap: Map<string, NetworkNodeServices>) {
nodeAliases.forEach(nodeAlias => {
const namespace = networkNodeServiceMap.get(nodeAlias).namespace;
const nodeId = +networkNodeServiceMap.get(nodeAlias).nodeId;

const localClusterPort = +constants.HEDERA_NODE_EXTERNAL_GOSSIP_PORT;
const localClusterHostName = Templates.renderFullyQualifiedNetworkSvcName(namespace, nodeAlias);

this.interfaceBindings.push({nodeId, hostname: localClusterHostName, port: localClusterPort});
// TODO future, add endpointOverrides for addresses external to cluster in multi-cluster support situation
// this.endpointOverrides.push({nodeId, hostname: externalHostname, port: externalPort});
});
}

/**
* Converts the model to YAML as expected to be consumed inside node
* @returns the raw YAML as string
*
* @example
* gossip:
* interfaceBindings:
* - { "nodeId": 0, "hostname": "10.10.10.1", "port": 1234 }
* - { "nodeId": 3, "hostname": "2001:db8:3333:4444:5555:6666:7777:8888", "port": 1237 }
* endpointOverrides:
* - { "nodeId": 5, "hostname": "10.10.10.11", "port": 1238 }
*/
public toYAML(): string {
const gossipData: {interfaceBindings?: string[]; endpointOverrides?: string[]} = {};

if (this.interfaceBindings.length) {
gossipData.interfaceBindings = this.interfaceBindings.map(d => JSON.stringify(d));
}

if (this.endpointOverrides.length) {
gossipData.endpointOverrides = this.endpointOverrides.map(d => JSON.stringify(d));
}

return yaml.stringify({gossip: gossipData}).replaceAll(/'/g, '');
}
}
3 changes: 3 additions & 0 deletions src/core/platform_installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@
const genesisNetworkJson = [path.join(stagingDir, 'genesis-network.json')];
await this.copyFiles(podRef, genesisNetworkJson, `${constants.HEDERA_HAPI_PATH}/data/config`);
}

const networkOverridesYaml = [path.join(stagingDir, constants.NODE_OVERRIDE_FILE)];

Check warning on line 309 in src/core/platform_installer.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/core/platform_installer.ts#L309

Detected possible user input going into a `path.join` or `path.resolve` function.
await this.copyFiles(podRef, networkOverridesYaml, `${constants.HEDERA_HAPI_PATH}/data/config`);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,14 @@ export interface GenesisNetworkRosterStructure {
gossipEndpoint: ServiceEndpoint[];
gossipCaCertificate: string;
}

export interface GossipEndpoint {
nodeId: number;
hostname: string;
port: number;
}

export interface NetworkOverridesStructure {
interfaceBindings: GossipEndpoint[];
endpointOverrides: GossipEndpoint[];
}
Loading