Skip to content

Commit

Permalink
Use the lighter status polling endpoint while waiting for compiling o…
Browse files Browse the repository at this point in the history
…r proving

This switches the client over from using the full proof/circuit detail
endpoints in favor of using the lighter status endpoints. This should improve
performance slightly for users and reduce bandwidth usage.

Merges #137

LGTM given by: @KPreisner
  • Loading branch information
sangaline authored Aug 22, 2024
1 parent 985f0ac commit 7b31cf4
Show file tree
Hide file tree
Showing 4 changed files with 41,886 additions and 10,877 deletions.
28 changes: 19 additions & 9 deletions src/cli/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from "node:assert";
import { Blob } from "buffer";
import { existsSync, readFileSync } from "fs";
import path from "path";
Expand All @@ -10,7 +11,7 @@ import tar from "tar";

import { collectMetaWithLogger, findFileUpwards } from "cli/utils";
import sindri from "lib";
import { ApiError } from "lib/api";
import { ApiError, CircuitInfoResponse, CircuitStatusResponse } from "lib/api";
import { getDefaultMeta } from "lib/utils";

interface CollectedTags extends Array<string> {
Expand Down Expand Up @@ -198,26 +199,35 @@ export const deployCommand = new Command()
while (true) {
try {
sindri.logger.debug("Polling for circuit compilation status.");
const response = await sindri._client.circuits.circuitDetail(
circuitId,
false,
);
// Get the fast status response first for performance.
const statusResponse: CircuitStatusResponse =
await sindri._client.internal.circuitStatus(circuitId);

// Get the full circuit response only if the compilation is complete or failed.
const response: CircuitInfoResponse | null = [
"Failed",
"Ready",
].includes(statusResponse.status)
? await sindri._client.circuits.circuitDetail(circuitId, false)
: null;

// Check the circuit status and log the appropriate message.
const elapsedSeconds = ((Date.now() - startTime) / 1000).toFixed(1);
if (response.status === "Ready") {
if (statusResponse.status === "Ready") {
sindri.logger.info(
`Circuit compiled successfully after ${elapsedSeconds} seconds.`,
);
break;
} else if (response.status === "Failed") {
} else if (statusResponse.status === "Failed") {
assert(response != null);
sindri.logger.error(
`Circuit compilation failed after ${elapsedSeconds} seconds: ` +
(response.error ?? "Unknown error."),
);
return process.exit(1);
} else if (response.status === "Queued") {
} else if (statusResponse.status === "Queued") {
sindri.logger.debug("Circuit compilation is queued.");
} else if (response.status === "In Progress") {
} else if (statusResponse.status === "In Progress") {
sindri.logger.debug("Circuit compilation is in progress.");
}
} catch (error) {
Expand Down
27 changes: 15 additions & 12 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { ApiClient, CircuitType, JobStatus, OpenAPIConfig } from "lib/api";
import type {
BoojumCircuitInfoResponse,
CircomCircuitInfoResponse,
CircuitStatusResponse,
GnarkCircuitInfoResponse,
Halo2CircuitInfoResponse,
NoirCircuitInfoResponse,
Plonky2CircuitInfoResponse,
ProofInfoResponse,
ProofStatusResponse,
} from "lib/api";
import { Config } from "lib/config";
import { createLogger, type Logger, type LogLevel } from "lib/logging";
Expand Down Expand Up @@ -556,16 +558,16 @@ export class SindriClient {
this._clientConfig.HEADERS = oldHeaders;
const circuitId = createResponse.circuit_id;

let response: CircuitInfoResponse;
while (true) {
response = await this._client.circuits.circuitDetail(circuitId, false);
const response: CircuitStatusResponse =
await this._client.internal.circuitStatus(circuitId);
if (response.status === "Ready" || response.status === "Failed") {
break;
}

await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
}
return response;
return this._client.circuits.circuitDetail(circuitId, false);
}

/**
Expand Down Expand Up @@ -689,21 +691,22 @@ export class SindriClient {
perform_verify: verify,
proof_input: proofInput,
});
let response: ProofInfoResponse;
const proofId: string = createResponse.proof_id;
while (true) {
response = await this._client.proofs.proofDetail(
createResponse.proof_id,
true, // includeProof
true, // includePublic
includeSmartContractCalldata, // includeSmartContractCalldata
true, // includeVerificationKey
);
const response: ProofStatusResponse =
await this._client.internal.proofStatus(proofId);
if (response.status === "Ready" || response.status === "Failed") {
break;
}

await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
}
return response;
return this._client.proofs.proofDetail(
proofId,
true, // includeProof
true, // includePublic
includeSmartContractCalldata, // includeSmartContractCalldata
true, // includeVerificationKey
);
}
}
Loading

0 comments on commit 7b31cf4

Please sign in to comment.