Skip to content
Open
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
35 changes: 7 additions & 28 deletions .github/workflows/js-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,15 @@ jobs:
npx nx build @lightprotocol/zk-compression-cli

- name: Run stateless.js tests with V2
run: |
echo "Running stateless.js tests with retry logic (max 2 attempts)..."
attempt=1
max_attempts=2
until npx nx test @lightprotocol/stateless.js; do
attempt=$((attempt + 1))
if [ $attempt -gt $max_attempts ]; then
echo "Tests failed after $max_attempts attempts"
exit 1
fi
echo "Attempt $attempt/$max_attempts failed, retrying..."
sleep 5
done
echo "Tests passed on attempt $attempt"
run: npx nx test @lightprotocol/stateless.js

- name: Run compressed-token legacy tests with V2
run: npx nx test @lightprotocol/compressed-token

- name: Run compressed-token tests with V2
- name: Run compressed-token ctoken tests with V2
run: |
echo "Running compressed-token tests with retry logic (max 2 attempts)..."
attempt=1
max_attempts=2
until npx nx test @lightprotocol/compressed-token; do
attempt=$((attempt + 1))
if [ $attempt -gt $max_attempts ]; then
echo "Tests failed after $max_attempts attempts"
exit 1
fi
echo "Attempt $attempt/$max_attempts failed, retrying..."
sleep 5
done
echo "Tests passed on attempt $attempt"
cd js/compressed-token
LIGHT_PROTOCOL_VERSION=V2 pnpm test:e2e:ctoken:all

- name: Run sdk-anchor-test TypeScript tests with V2
run: |
Expand Down
30 changes: 2 additions & 28 deletions .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,7 @@ jobs:
npx nx build @lightprotocol/zk-compression-cli

- name: Run stateless.js tests with V1
run: |
echo "Running stateless.js tests with retry logic (max 2 attempts)..."
attempt=1
max_attempts=2
until npx nx test @lightprotocol/stateless.js; do
attempt=$((attempt + 1))
if [ $attempt -gt $max_attempts ]; then
echo "Tests failed after $max_attempts attempts"
exit 1
fi
echo "Attempt $attempt/$max_attempts failed, retrying..."
sleep 5
done
echo "Tests passed on attempt $attempt"
run: npx nx test @lightprotocol/stateless.js

- name: Run compressed-token tests with V1
run: |
echo "Running compressed-token tests with retry logic (max 2 attempts)..."
attempt=1
max_attempts=2
until npx nx test @lightprotocol/compressed-token; do
attempt=$((attempt + 1))
if [ $attempt -gt $max_attempts ]; then
echo "Tests failed after $max_attempts attempts"
exit 1
fi
echo "Attempt $attempt/$max_attempts failed, retrying..."
sleep 5
done
echo "Tests passed on attempt $attempt"
run: npx nx test @lightprotocol/compressed-token
55 changes: 55 additions & 0 deletions cli/src/utils/processPhotonIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { exec } from "node:child_process";
import * as util from "node:util";
import { exit } from "node:process";
import axios from "axios";

const execAsync = util.promisify(exec);

Expand All @@ -36,6 +37,59 @@ function getPhotonInstallMessage(): string {
}
}

async function waitForIndexerSync(
rpcUrl: string,
indexerPort: number,
timeoutMs: number = 60000,
): Promise<void> {
const startTime = Date.now();
const interval = 500;

while (Date.now() - startTime < timeoutMs) {
try {
const [validatorSlotRes, indexerSlotRes] = await Promise.all([
axios.post(
rpcUrl,
{ jsonrpc: "2.0", id: 1, method: "getSlot", params: [] },
{ timeout: 5000 },
),
axios.post(
`http://127.0.0.1:${indexerPort}`,
{ jsonrpc: "2.0", id: 1, method: "getIndexerSlot", params: [] },
{ timeout: 5000 },
),
]);

const validatorSlot = validatorSlotRes.data?.result;
const indexerSlot = indexerSlotRes.data?.result;

if (
typeof validatorSlot === "number" &&
typeof indexerSlot === "number"
) {
const slotDiff = validatorSlot - indexerSlot;
if (slotDiff <= 5) {
console.log(
`Indexer synced (validator: ${validatorSlot}, indexer: ${indexerSlot})`,
);
return;
}
console.log(
`Waiting for indexer sync... (validator: ${validatorSlot}, indexer: ${indexerSlot}, diff: ${slotDiff})`,
);
}
} catch {
// Ignore errors during sync check, just retry
}

await new Promise((resolve) => setTimeout(resolve, interval));
}

throw new Error(
`Indexer failed to sync with validator within ${timeoutMs / 1000}s`,
);
}

export async function startIndexer(
rpcUrl: string,
indexerPort: number,
Expand Down Expand Up @@ -63,6 +117,7 @@ export async function startIndexer(
}
spawnBinary(INDEXER_PROCESS_NAME, args);
await waitForServers([{ port: indexerPort, path: "/getIndexerHealth" }]);
await waitForIndexerSync(rpcUrl, indexerPort);
console.log("Indexer started successfully!");
}
}
Expand Down
Loading