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

fix: mirror node command changes required for multi-cluster support #1433

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 17 additions & 2 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {BaseCommand, type Opts} from './base.js';
import {Flags as flags} from './flags.js';
import {resolveNamespaceFromDeployment} from '../core/resolvers.js';
import * as helpers from '../core/helpers.js';
import {type CommandBuilder} from '../types/aliases.js';
import {type CommandBuilder, type NodeAlias} from '../types/aliases.js';
import {PodName} from '../core/kube/resources/pod/pod_name.js';
import {ListrLease} from '../core/lease/listr_lease.js';
import {ComponentType} from '../core/config/remote/enumerations.js';
Expand All @@ -29,6 +29,8 @@ import {type CommandFlag} from '../types/flag_types.js';
import {PvcRef} from '../core/kube/resources/pvc/pvc_ref.js';
import {PvcName} from '../core/kube/resources/pvc/pvc_name.js';
import {type DeploymentName} from '../core/config/remote/types.js';
import {extractContextFromConsensusNodes} from '../core/helpers.js';
import {node} from 'globals';

interface MirrorNodeDeployConfigClass {
chartDirectory: string;
Expand Down Expand Up @@ -355,7 +357,20 @@ export class MirrorNodeCommand extends BaseCommand {
{
title: 'Prepare address book',
task: async ctx => {
ctx.addressBook = await self.accountManager.prepareAddressBookBase64();
const deployment = this.configManager.getFlag<DeploymentName>(flags.deployment);
const portForward = this.configManager.getFlag<boolean>(flags.forcePortForward);
const consensusNodes = this.getConsensusNodes();
const nodeAlias = `node${consensusNodes[0].nodeId}` as NodeAlias;
const context = extractContextFromConsensusNodes(nodeAlias, consensusNodes);
ctx.addressBook = await self.accountManager.prepareAddressBookBase64(
ctx.config.namespace,
this.getClusterRefs(),
deployment,
this.configManager.getFlag(flags.operatorId),
this.configManager.getFlag(flags.operatorKey),
portForward,
context,
);
ctx.config.valuesArg += ` --set "importer.addressBook=${ctx.addressBook}"`;
},
},
Expand Down
28 changes: 20 additions & 8 deletions src/core/account_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
}
} catch {
this.logger.debug('node client ping failed, refreshing node client');
await this.refreshNodeClient(namespace, undefined, clusterRefs, deployment, context);
await this.refreshNodeClient(namespace, undefined, clusterRefs, deployment, context, forcePortForward);

Check warning on line 199 in src/core/account_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/core/account_manager.ts#L199

Added line #L199 was not covered by tests
}
}

Expand Down Expand Up @@ -967,14 +967,25 @@
/**
* Fetch and prepare address book as a base64 string
*/
async prepareAddressBookBase64() {
async prepareAddressBookBase64(
namespace: NamespaceName,
clusterRefs?: ClusterRefs,
deployment?: DeploymentName,
operatorId?: string,
operatorKey?: string,
forcePortForward?: boolean,
context?: string,
) {
// fetch AddressBook
const fileQuery = new FileContentsQuery().setFileId(FileId.ADDRESS_BOOK);
const addressBookBytes = await fileQuery.execute(this._nodeClient);
await this.loadNodeClient(namespace, clusterRefs, deployment, forcePortForward, context);
const client = this._nodeClient;

// convert addressBook into base64
// @ts-ignore
return Base64.encode(addressBookBytes);
if (operatorId && operatorKey) {
client.setOperator(operatorId, operatorKey);
}

Check warning on line 985 in src/core/account_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/core/account_manager.ts#L984-L985

Added lines #L984 - L985 were not covered by tests

const query = new FileContentsQuery().setFileId(FileId.ADDRESS_BOOK);
return Buffer.from(await query.execute(client)).toString('base64');
}

async getFileContents(
Expand All @@ -983,8 +994,9 @@
clusterRefs?: ClusterRefs,
deployment?: DeploymentName,
forcePortForward?: boolean,
context?: string,
) {
await this.loadNodeClient(namespace, clusterRefs, deployment, forcePortForward);
await this.loadNodeClient(namespace, clusterRefs, deployment, forcePortForward, context);
const client = this._nodeClient;
const fileId = FileId.fromString(`0.0.${fileNum}`);
const queryFees = new FileContentsQuery().setFileId(fileId);
Expand Down
Loading