Skip to content

Commit

Permalink
fix: make mirror node work
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Klick <[email protected]>
  • Loading branch information
nathanklick committed Feb 17, 2025
1 parent 53a7fa9 commit e60db0a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
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 @@ export class AccountManager {
}
} 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);
}
}

Expand Down Expand Up @@ -967,14 +967,25 @@ export class AccountManager {
/**
* 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);
}

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 @@ export class AccountManager {
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

0 comments on commit e60db0a

Please sign in to comment.