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

feat: add option to pass custom photon db url to cli/test-validator #702

Merged
merged 3 commits into from
May 11, 2024
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
7 changes: 7 additions & 0 deletions cli/src/commands/test-validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class SetupCommand extends Command {
default: false,
exclusive: ["skip-indexer"],
}),
"indexer-db-url": Flags.string({
description:
"Custom indexer database URL to store indexing data. By default we use an in-memory SQLite database.",
required: false,
exclusive: ["skip-indexer"],
}),
};

async run() {
Expand All @@ -54,6 +60,7 @@ class SetupCommand extends Command {
proveCompressedAccounts: flags["prove-compressed-accounts"],
proveNewAddresses: flags["prove-new-addresses"],
checkPhotonVersion: !flags["relax-indexer-version-constraint"],
photonDatabaseUrl: flags["indexer-db-url"],
});

this.log("\nSetup tasks completed successfully \x1b[32m✔\x1b[0m");
Expand Down
4 changes: 3 additions & 1 deletion cli/src/utils/initTestEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function initTestEnv({
proveCompressedAccounts = true,
proveNewAddresses = false,
checkPhotonVersion = true,
photonDatabaseUrl,
}: {
additionalPrograms?: { address: string; path: string }[];
skipSystemAccounts?: boolean;
Expand All @@ -33,6 +34,7 @@ export async function initTestEnv({
proveCompressedAccounts?: boolean;
proveNewAddresses?: boolean;
checkPhotonVersion?: boolean;
photonDatabaseUrl?: string;
}) {
console.log("Performing setup tasks...\n");

Expand All @@ -52,7 +54,7 @@ export async function initTestEnv({
await initAccounts();

if (indexer) {
await startIndexer(checkPhotonVersion);
await startIndexer(checkPhotonVersion, photonDatabaseUrl);
}

if (prover) {
Expand Down
14 changes: 12 additions & 2 deletions cli/src/utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ const waitOn = require("wait-on");

export async function killProcess(processName: string) {
const processList = await find("name", processName);
for (const proc of processList) {
const targetProcesses = processList.filter(
(proc) => proc.cmd.split(" ")[0] === processName,
);
targetProcesses.forEach((proc) => {
process.kill(proc.pid);
}
});
}

export async function killProcessByPort(port: string) {
Expand Down Expand Up @@ -116,12 +119,19 @@ export async function execute(command: string): Promise<string> {
export function spawnBinary(command: string, args: string[] = []) {
const logDir = "test-ledger";
const binaryName = path.basename(command);

const dir = path.join(__dirname, logDir);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}

const out = fs.openSync(`${logDir}/${binaryName}.log`, "a");
const err = fs.openSync(`${logDir}/${binaryName}.log`, "a");

const spawnedProcess = spawn(command, args, {
stdio: ["ignore", out, err],
shell: false,
detached: true,
});

spawnedProcess.on("close", (code) => {
Expand Down
11 changes: 9 additions & 2 deletions cli/src/utils/processPhotonIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { INDEXER_PROCESS_NAME, PHOTON_VERSION } from "./constants";
import { exec } from "node:child_process";
import * as util from "node:util";

export async function startIndexer(checkPhotonVersion: boolean = true) {
export async function startIndexer(
checkPhotonVersion: boolean = true,
photonDatabaseUrl?: string,
) {
await killIndexer();
const resolvedOrNull = which.sync("photon", { nothrow: true });
if (
Expand All @@ -16,7 +19,11 @@ export async function startIndexer(checkPhotonVersion: boolean = true) {
throw new Error(message);
} else {
console.log("Starting indexer...");
spawnBinary(INDEXER_PROCESS_NAME);
let args: string[] = [];
if (photonDatabaseUrl) {
args = ["--db-url", photonDatabaseUrl];
}
spawnBinary(INDEXER_PROCESS_NAME, args);
await waitForServers([{ port: 8784, path: "/getIndexerHealth" }]);
console.log("Indexer started successfully!");
}
Expand Down
Loading