Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
**/*.js.map
**/node_modules
target
*plan*
21 changes: 16 additions & 5 deletions ts/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import { verifySign, LeHexBN, sign, PlayerConvention, ZKWasmAppRpc, createComman
import { Queue, Worker, Job } from 'bullmq';
import IORedis from 'ioredis';
import express, {Express} from 'express';
import { submitProofWithRetry, has_uncomplete_task, TxWitness, get_latest_proof, has_task } from "./prover.js";
import { has_uncomplete_task, TxWitness, get_latest_proof, has_task } from "./prover.js";
import cors from "cors";
import { get_mongoose_db, modelBundle, modelJob, modelRand, get_service_port, get_server_admin_key, modelTx, get_contract_addr, get_chain_id } from "./config.js";
import { get_mongoose_db, modelBundle, modelJob, modelRand, get_service_port, get_server_admin_key, modelTx, get_contract_addr, get_chain_id, endpoint } from "./config.js";
import { getMerkleArray } from "./contract.js";
import { ZkWasmUtil } from "zkwasm-service-helper";
import { ZkWasmUtil, ZkWasmServiceHelper } from "zkwasm-service-helper";
import dotenv from 'dotenv';
import mongoose from 'mongoose';
import {hexStringToMerkleRoot, merkleRootToBeHexString} from "./lib.js";
import {sha256} from "ethers";
import {TxStateManager} from "./commit.js";
import {queryAccounts, storeAccount} from "./account.js";
import {ProofSubmissionService, handleNullTaskIdBundles} from "./service/proof-submission-service.js";
import { get_image_md5 } from "./config.js";

// Load environment variables from .env file
dotenv.config();
Expand Down Expand Up @@ -99,6 +101,7 @@ export class Service {
preMerkleRoot: BigUint64Array | null;
txManager: TxStateManager;
blocklist: Map<string, number>;
proofService!: ProofSubmissionService;

constructor(
cb: (arg: TxWitness, events: BigUint64Array) => Promise<void> = async (arg: TxWitness, events: BigUint64Array) => {},
Expand Down Expand Up @@ -173,7 +176,7 @@ export class Service {
}
}

async trackBundle(taskId: string) {
async trackBundle(taskId: string | null) {
console.log("track bundle:", this.bundleIndex);
let preMerkleRootStr = "";
if (this.preMerkleRoot != null) {
Expand Down Expand Up @@ -248,7 +251,7 @@ export class Service {
let task_id = null;
if (deploymode) {
try {
task_id = await submitProofWithRetry(this.merkleRoot, transactions_witness, txdata);
await this.proofService.addTaskToStack(this.merkleRoot, transactions_witness, txdata);
} catch (e) {
console.log(e);
process.exit(1); // this should never happen and we stop the whole process
Expand Down Expand Up @@ -313,6 +316,14 @@ export class Service {
}
);

// Initialize ProofSubmissionService
const helper = new ZkWasmServiceHelper(endpoint, "", "");
this.proofService = new ProofSubmissionService(connection, get_image_md5(), helper);

// Handle null taskId bundles and recover tasks
await handleNullTaskIdBundles(this.proofService);
await this.proofService.recoverTasks();

connection.on('end', () => {
console.log("fatal: redis disconnected unexpected ...");
process.exit(1);
Expand Down
Loading