Skip to content

Commit

Permalink
changes load, but nodes don't start due to incorrect signature
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Jan 6, 2025
1 parent 6e73f57 commit c604fd7
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 35 deletions.
1 change: 1 addition & 0 deletions resources/templates/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ staking.periodMins=1
nodes.updateAccountIdAllowed=true
# TODO: remove once we have the uploader enabled, required for current p0 deadline
blockStream.streamMode=RECORDS
addressBook.useRosterLifecycle=true
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
*/
import crypto from 'node:crypto';
import {PrivateKey} from '@hashgraph/sdk';
import {Templates} from '../templates.js';
import {GenesisNetworkNodeDataWrapper} from './genesis_network_node_data_wrapper.js';
import * as x509 from '@peculiar/x509';
import * as constants from '../constants.js';

import type {KeyManager} from '../key_manager.js';
import type {ToJSON} from '../../types/index.js';
import type {JsonString, NodeAlias, NodeAliases} from '../../types/aliases.js';
import {GenesisNetworkRosterEntryDataWrapper} from './genesis_network_roster_entry_data_wrapper.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 constructor(
private readonly nodeAliases: NodeAliases,
Expand All @@ -42,6 +43,7 @@ export class GenesisNetworkDataConstructor implements ToJSON {
const adminPubKey = adminPrivateKey.publicKey;

this.nodes[nodeAlias] = new GenesisNetworkNodeDataWrapper(nodeId, adminPubKey, nodeAlias);
this.rosters[nodeAlias] = new GenesisNetworkRosterEntryDataWrapper(nodeId);
});
}

Expand Down Expand Up @@ -69,7 +71,8 @@ export class GenesisNetworkDataConstructor implements ToJSON {
const certPem = nodeKeys.certificate.toString();

//* Assign the PEM certificate
this.nodes[nodeAlias].gossipCaCertificate = nodeKeys.certificate.toString('base64');
this.rosters[nodeAlias].gossipCaCertificate = this.nodes[nodeAlias].gossipCaCertificate =
nodeKeys.certificate.toString('base64');

//* Decode the PEM to DER format
const tlsCertDer = new Uint8Array(x509.PemConverter.decode(certPem)[0]);
Expand All @@ -81,6 +84,14 @@ export class GenesisNetworkDataConstructor implements ToJSON {
}

public toJSON(): JsonString {
return JSON.stringify({nodeMetadata: Object.values(this.nodes).map(node => node.toObject())});
const nodeMetadata = [];
Object.keys(this.nodes).forEach(nodeAlias => {
nodeMetadata.push({
node: this.nodes[nodeAlias].toObject(),
rosterEntry: this.rosters[nodeAlias].toObject(),
});
});

return JSON.stringify({nodeMetadata: nodeMetadata});
}
}
34 changes: 34 additions & 0 deletions src/core/genesis_network_models/genesis_network_data_wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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 {NodeId} from '../../types/aliases.js';
import type {ServiceEndpoint} from '../../types/index.js';

export abstract class GenesisNetworkDataWrapper {
public gossipEndpoint: ServiceEndpoint[] = [];
public weight: number;
public gossipCaCertificate: string;

protected constructor(public readonly nodeId: NodeId) {}

/**
* @param domainName - a fully qualified domain name
* @param port
*/
public addGossipEndpoint(domainName: string, port: number): void {
this.gossipEndpoint.push({domainName, port, ipAddressV4: ''});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@
*
*/
import type {AccountId, PublicKey} from '@hashgraph/sdk';
import type {GenesisNetworkNodeStructure, ServiceEndpoint, ToObject} from '../../types/index.js';
import type {GenesisNetworkNodeStructure, NodeAccountId, ServiceEndpoint, ToObject} from '../../types/index.js';
import {GenesisNetworkDataWrapper} from './genesis_network_data_wrapper.js';

export class GenesisNetworkNodeDataWrapper
implements GenesisNetworkNodeStructure, ToObject<{node: GenesisNetworkNodeStructure}>
extends GenesisNetworkDataWrapper
implements ToObject<GenesisNetworkNodeStructure>
{
public accountId: AccountId;
public gossipEndpoint: ServiceEndpoint[] = [];
public serviceEndpoint: ServiceEndpoint[] = [];
public gossipCaCertificate: string;
public grpcCertificateHash: string;
public weight: number;
public readonly deleted = false;

constructor(
public readonly nodeId: number,
public readonly adminKey: PublicKey,
public readonly description: string,
) {}
) {
super(nodeId);
}

/**
* @param domainName - a fully qualified domain name
Expand All @@ -42,28 +43,18 @@ export class GenesisNetworkNodeDataWrapper
this.serviceEndpoint.push({domainName, port, ipAddressV4: ''});
}

/**
* @param domainName - a fully qualified domain name
* @param port
*/
public addGossipEndpoint(domainName: string, port: number): void {
this.gossipEndpoint.push({domainName, port, ipAddressV4: ''});
}

public toObject() {
return {
node: {
nodeId: this.nodeId,
accountId: this.accountId,
description: this.description,
gossipEndpoint: this.gossipEndpoint,
serviceEndpoint: this.serviceEndpoint,
gossipCaCertificate: this.gossipCaCertificate,
grpcCertificateHash: this.grpcCertificateHash,
weight: this.weight,
deleted: this.deleted,
adminKey: this.adminKey,
},
nodeId: this.nodeId,
accountId: {accountNum: `${this.accountId.num}`} as unknown as NodeAccountId,
description: this.description,
gossipEndpoint: this.gossipEndpoint,
serviceEndpoint: this.serviceEndpoint,
gossipCaCertificate: this.gossipCaCertificate,
grpcCertificateHash: this.grpcCertificateHash,
weight: this.weight,
deleted: this.deleted,
adminKey: this.adminKey,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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 {GenesisNetworkDataWrapper} from './genesis_network_data_wrapper.js';
import type {NodeId} from '../../types/aliases.js';
import type {GenesisNetworkRosterStructure, ToObject} from '../../types/index.js';

export class GenesisNetworkRosterEntryDataWrapper
extends GenesisNetworkDataWrapper
implements GenesisNetworkRosterStructure, ToObject<GenesisNetworkRosterStructure>
{
constructor(public readonly nodeId: NodeId) {
super(nodeId);
}

public toObject() {
return {
nodeId: this.nodeId,
gossipEndpoint: this.gossipEndpoint,
gossipCaCertificate: this.gossipCaCertificate,
weight: this.weight,
};
}
}
12 changes: 7 additions & 5 deletions src/core/profile_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export class ProfileManager {
* @param namespace - namespace where the network is deployed
* @param nodeAccountMap - the map of node aliases to account IDs
* @param destPath - path to the destination directory to write the config.txt file
* @param releaseTag - release tag e.g. v0.42.0
* @param releaseTagOverride - release tag override
* @param [appName] - the app name (default: HederaNode.jar)
* @param [chainId] - chain ID (298 for local network)
* @param genesisNetworkData
Expand Down Expand Up @@ -508,7 +508,7 @@ export class ProfileManager {
const externalPort = +constants.HEDERA_NODE_EXTERNAL_GOSSIP_PORT;
const nodeStakeAmount = constants.HEDERA_NODE_DEFAULT_STAKE_AMOUNT;

// @ts-ignore
// @ts-expect-error - TS2353: Object literal may only specify known properties, and includePrerelease does not exist in type Options
const releaseVersion = semver.parse(releaseTag, {includePrerelease: true}) as SemVer;

try {
Expand All @@ -526,16 +526,18 @@ export class ProfileManager {
// TODO: Use the "nodeSeq"

const nodeDataWrapper = genesisNetworkData.nodes[nodeAlias];
const rosterDataWrapper = genesisNetworkData.rosters[nodeAlias];

nodeDataWrapper.weight = nodeStakeAmount;
rosterDataWrapper.weight = nodeDataWrapper.weight = nodeStakeAmount;
nodeDataWrapper.accountId = AccountId.fromString(account);

//? Add gossip endpoints
// Add gossip endpoints
nodeDataWrapper.addGossipEndpoint(externalIP, externalPort);
rosterDataWrapper.addGossipEndpoint(externalIP, externalPort);

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

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

Expand Down
15 changes: 14 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ export interface ServiceEndpoint {
domainName: string;
}

export interface NodeAccountId {
accountId: {
accountNum: string;
};
}

export interface GenesisNetworkNodeStructure {
nodeId: number;
accountId: AccountId;
accountId: NodeAccountId;
description: string;
gossipEndpoint: ServiceEndpoint[];
serviceEndpoint: ServiceEndpoint[];
Expand All @@ -115,3 +121,10 @@ export interface GenesisNetworkNodeStructure {
deleted: boolean;
adminKey: PublicKey;
}

export interface GenesisNetworkRosterStructure {
nodeId: number;
weight: number;
gossipEndpoint: ServiceEndpoint[];
gossipCaCertificate: string;
}

0 comments on commit c604fd7

Please sign in to comment.