Skip to content

Commit 7974ade

Browse files
fix: update config to work with new version of hedera-json-rpc-relay (#316)
Signed-off-by: Jeffrey Tang <[email protected]>
1 parent 37d44f3 commit 7974ade

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

src/commands/flags.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ export const releaseTag = {
189189
export const relayReleaseTag = {
190190
name: 'relay-release',
191191
definition: {
192-
describe: 'Relay release tag to be used (e.g. v0.43.0)',
193-
defaultValue: 'v0.43.0',
192+
describe: 'Relay release tag to be used (e.g. v0.48.0)',
193+
defaultValue: 'v0.48.1',
194194
type: 'string'
195195
}
196196
}

src/commands/relay.mjs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { constants } from '../core/index.mjs'
2121
import { BaseCommand } from './base.mjs'
2222
import * as flags from './flags.mjs'
2323
import * as prompts from './prompts.mjs'
24+
import { getNodeAccountMap } from '../core/constants.mjs'
2425

2526
export class RelayCommand extends BaseCommand {
2627
constructor (opts) {
@@ -29,9 +30,10 @@ export class RelayCommand extends BaseCommand {
2930
if (!opts || !opts.profileManager) throw new MissingArgumentError('An instance of core/ProfileManager is required', opts.downloader)
3031

3132
this.profileManager = opts.profileManager
33+
this.accountManager = opts.accountManager
3234
}
3335

34-
async prepareValuesArg (valuesFile, nodeIDs, chainID, relayRelease, replicaCount, operatorID, operatorKey) {
36+
async prepareValuesArg (valuesFile, nodeIDs, chainID, relayRelease, replicaCount, operatorID, operatorKey, namespace) {
3537
let valuesArg = ''
3638
if (valuesFile) {
3739
valuesArg += this.prepareValuesFiles(valuesFile)
@@ -43,7 +45,11 @@ export class RelayCommand extends BaseCommand {
4345
valuesArg += this.prepareValuesFiles(profileValuesFile)
4446
}
4547

46-
valuesArg += ` --set config.MIRROR_NODE_URL=${constants.FULLSTACK_DEPLOYMENT_CHART}-rest`
48+
valuesArg += ` --set config.MIRROR_NODE_URL=http://${constants.FULLSTACK_DEPLOYMENT_CHART}-rest`
49+
valuesArg += ` --set config.MIRROR_NODE_URL_WEB3=http://${constants.FULLSTACK_DEPLOYMENT_CHART}-web3`
50+
valuesArg += ' --set config.MIRROR_NODE_AGENT_CACHEABLE_DNS=false'
51+
valuesArg += ' --set config.MIRROR_NODE_RETRY_DELAY=2001'
52+
valuesArg += ' --set config.MIRROR_NODE_GET_CONTRACT_RESULTS_DEFAULT_RETRIES=21'
4753

4854
if (chainID) {
4955
valuesArg += ` --set config.CHAIN_ID=${chainID}`
@@ -69,12 +75,30 @@ export class RelayCommand extends BaseCommand {
6975
throw new MissingArgumentError('Node IDs must be specified')
7076
}
7177

78+
const networkJsonString = await this.prepareNetworkJsonString(nodeIDs, namespace)
79+
valuesArg += ` --set config.HEDERA_NETWORK='${networkJsonString}'`
80+
return valuesArg
81+
}
82+
83+
// created a json string to represent the map between the node keys and their ids
84+
// output example '{"node-1": "0.0.3", "node-2": "0.004"}'
85+
async prepareNetworkJsonString (nodeIDs = [], namespace) {
86+
if (!nodeIDs) {
87+
throw new MissingArgumentError('Node IDs must be specified')
88+
}
89+
90+
const networkIds = {}
91+
const accountMap = getNodeAccountMap(nodeIDs)
92+
93+
const networkNodeServicesMap = await this.accountManager.getNodeServiceMap(namespace)
7294
nodeIDs.forEach(nodeID => {
73-
const networkKey = `network-${nodeID.trim()}-0:50211`
74-
valuesArg += ` --set config.HEDERA_NETWORK.${networkKey}=0.0.3`
95+
const nodeName = networkNodeServicesMap.get(nodeID).nodeName
96+
const haProxyGrpcPort = networkNodeServicesMap.get(nodeID).haProxyGrpcPort
97+
const networkKey = `network-${nodeName}:${haProxyGrpcPort}`
98+
networkIds[networkKey] = accountMap.get(nodeID)
7599
})
76100

77-
return valuesArg
101+
return JSON.stringify(networkIds)
78102
}
79103

80104
prepareReleaseName (nodeIDs = []) {
@@ -145,7 +169,8 @@ export class RelayCommand extends BaseCommand {
145169
ctx.config.relayRelease,
146170
ctx.config.replicaCount,
147171
ctx.config.operatorId,
148-
ctx.config.operatorKey
172+
ctx.config.operatorKey,
173+
ctx.config.namespace
149174
)
150175
}
151176
},

src/core/constants.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { color, PRESET_TIMER } from 'listr2'
1919
import { dirname, normalize } from 'path'
2020
import { fileURLToPath } from 'url'
2121
import chalk from 'chalk'
22+
import { constants } from './index.mjs'
2223

2324
// -------------------- solo related constants ---------------------------------------------------------------------
2425
export const CUR_FILE_DIR = dirname(fileURLToPath(import.meta.url))
@@ -147,6 +148,20 @@ export const PROFILE_LOCAL = 'local'
147148
export const ALL_PROFILES = [PROFILE_LOCAL, PROFILE_TINY, PROFILE_SMALL, PROFILE_MEDIUM, PROFILE_LARGE]
148149
export const DEFAULT_PROFILE_FILE = `${SOLO_CACHE_DIR}/profiles/custom-spec.yaml`
149150

151+
// a function generate map between the nodeId and their account ids
152+
export function getNodeAccountMap (nodeIDs) {
153+
const accountMap = new Map()
154+
const realm = constants.HEDERA_NODE_ACCOUNT_ID_START.realm
155+
const shard = constants.HEDERA_NODE_ACCOUNT_ID_START.shard
156+
let accountId = constants.HEDERA_NODE_ACCOUNT_ID_START.num
157+
158+
nodeIDs.forEach(nodeID => {
159+
const nodeAccount = `${realm}.${shard}.${accountId++}`
160+
accountMap.set(nodeID, nodeAccount)
161+
})
162+
return accountMap
163+
}
164+
150165
// ------ Hedera SDK Related ------
151166
export const NODE_CLIENT_MAX_ATTEMPTS = process.env.NODE_CLIENT_MAX_ATTEMPTS || 60
152167
export const NODE_CLIENT_MIN_BACKOFF = process.env.NODE_CLIENT_MIN_BACKOFF || 1000

src/core/profile_manager.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as yaml from 'js-yaml'
2121
import { flags } from '../commands/index.mjs'
2222
import { constants, helpers } from './index.mjs'
2323
import dot from 'dot-object'
24+
import { getNodeAccountMap } from './constants.mjs'
2425

2526
const consensusSidecars = [
2627
'recordStreamUploader', 'eventStreamUploader', 'backupUploader', 'accountBalanceUploader', 'otelCollector']
@@ -148,15 +149,12 @@ export class ProfileManager {
148149
resourcesForConsensusPod (profile, nodeIds, yamlRoot) {
149150
if (!profile) throw new MissingArgumentError('profile is required')
150151

151-
// prepare name and account IDs for nodes
152-
const realm = constants.HEDERA_NODE_ACCOUNT_ID_START.realm
153-
const shard = constants.HEDERA_NODE_ACCOUNT_ID_START.shard
154-
let accountId = constants.HEDERA_NODE_ACCOUNT_ID_START.num
152+
const accountMap = getNodeAccountMap(nodeIds)
155153

156154
// set consensus pod level resources
157155
for (let nodeIndex = 0; nodeIndex < nodeIds.length; nodeIndex++) {
158156
this._setValue(`hedera.nodes.${nodeIndex}.name`, nodeIds[nodeIndex], yamlRoot)
159-
this._setValue(`hedera.nodes.${nodeIndex}.accountId`, `${realm}.${shard}.${accountId++}`, yamlRoot)
157+
this._setValue(`hedera.nodes.${nodeIndex}.accountId`, accountMap.get(nodeIds[nodeIndex]), yamlRoot)
160158
this._setChartItems(`hedera.nodes.${nodeIndex}`, profile.consensus, yamlRoot)
161159
}
162160

0 commit comments

Comments
 (0)