Skip to content

Commit f43870e

Browse files
authored
fix: mirror node command changes required for multi-cluster support (#1433)
Signed-off-by: Nathan Klick <[email protected]>
1 parent ef5435e commit f43870e

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/commands/mirror_node.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {BaseCommand, type Opts} from './base.js';
1111
import {Flags as flags} from './flags.js';
1212
import {resolveNamespaceFromDeployment} from '../core/resolvers.js';
1313
import * as helpers from '../core/helpers.js';
14-
import {type CommandBuilder} from '../types/aliases.js';
14+
import {type CommandBuilder, type NodeAlias} from '../types/aliases.js';
1515
import {PodName} from '../core/kube/resources/pod/pod_name.js';
1616
import {ListrLease} from '../core/lease/listr_lease.js';
1717
import {ComponentType} from '../core/config/remote/enumerations.js';
@@ -29,6 +29,8 @@ import {type CommandFlag} from '../types/flag_types.js';
2929
import {PvcRef} from '../core/kube/resources/pvc/pvc_ref.js';
3030
import {PvcName} from '../core/kube/resources/pvc/pvc_name.js';
3131
import {type DeploymentName} from '../core/config/remote/types.js';
32+
import {extractContextFromConsensusNodes} from '../core/helpers.js';
33+
import {node} from 'globals';
3234

3335
interface MirrorNodeDeployConfigClass {
3436
chartDirectory: string;
@@ -355,7 +357,20 @@ export class MirrorNodeCommand extends BaseCommand {
355357
{
356358
title: 'Prepare address book',
357359
task: async ctx => {
358-
ctx.addressBook = await self.accountManager.prepareAddressBookBase64();
360+
const deployment = this.configManager.getFlag<DeploymentName>(flags.deployment);
361+
const portForward = this.configManager.getFlag<boolean>(flags.forcePortForward);
362+
const consensusNodes = this.getConsensusNodes();
363+
const nodeAlias = `node${consensusNodes[0].nodeId}` as NodeAlias;
364+
const context = extractContextFromConsensusNodes(nodeAlias, consensusNodes);
365+
ctx.addressBook = await self.accountManager.prepareAddressBookBase64(
366+
ctx.config.namespace,
367+
this.getClusterRefs(),
368+
deployment,
369+
this.configManager.getFlag(flags.operatorId),
370+
this.configManager.getFlag(flags.operatorKey),
371+
portForward,
372+
context,
373+
);
359374
ctx.config.valuesArg += ` --set "importer.addressBook=${ctx.addressBook}"`;
360375
},
361376
},

src/core/account_manager.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class AccountManager {
196196
}
197197
} catch {
198198
this.logger.debug('node client ping failed, refreshing node client');
199-
await this.refreshNodeClient(namespace, undefined, clusterRefs, deployment, context);
199+
await this.refreshNodeClient(namespace, undefined, clusterRefs, deployment, context, forcePortForward);
200200
}
201201
}
202202

@@ -967,14 +967,25 @@ export class AccountManager {
967967
/**
968968
* Fetch and prepare address book as a base64 string
969969
*/
970-
async prepareAddressBookBase64() {
970+
async prepareAddressBookBase64(
971+
namespace: NamespaceName,
972+
clusterRefs?: ClusterRefs,
973+
deployment?: DeploymentName,
974+
operatorId?: string,
975+
operatorKey?: string,
976+
forcePortForward?: boolean,
977+
context?: string,
978+
) {
971979
// fetch AddressBook
972-
const fileQuery = new FileContentsQuery().setFileId(FileId.ADDRESS_BOOK);
973-
const addressBookBytes = await fileQuery.execute(this._nodeClient);
980+
await this.loadNodeClient(namespace, clusterRefs, deployment, forcePortForward, context);
981+
const client = this._nodeClient;
974982

975-
// convert addressBook into base64
976-
// @ts-ignore
977-
return Base64.encode(addressBookBytes);
983+
if (operatorId && operatorKey) {
984+
client.setOperator(operatorId, operatorKey);
985+
}
986+
987+
const query = new FileContentsQuery().setFileId(FileId.ADDRESS_BOOK);
988+
return Buffer.from(await query.execute(client)).toString('base64');
978989
}
979990

980991
async getFileContents(
@@ -983,8 +994,9 @@ export class AccountManager {
983994
clusterRefs?: ClusterRefs,
984995
deployment?: DeploymentName,
985996
forcePortForward?: boolean,
997+
context?: string,
986998
) {
987-
await this.loadNodeClient(namespace, clusterRefs, deployment, forcePortForward);
999+
await this.loadNodeClient(namespace, clusterRefs, deployment, forcePortForward, context);
9881000
const client = this._nodeClient;
9891001
const fileId = FileId.fromString(`0.0.${fileNum}`);
9901002
const queryFees = new FileContentsQuery().setFileId(fileId);

0 commit comments

Comments
 (0)