Skip to content

Commit ee1425b

Browse files
committed
refactor(verifier): fic VerificationResultId issue
1 parent f32b454 commit ee1425b

6 files changed

Lines changed: 63 additions & 29 deletions

File tree

node/src/app.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import { nodeKeys } from "./crypto/keyPair.js";
1414
import { fetchPeerInfo } from "./gossip/utils/fetchPeerInfo.js";
1515
import { nodeState } from "./state/nodeState.js";
1616
import { runGDV } from "./verifier/gdvVerifier.js";
17-
import { getVerificationResultId } from "./merkle/verificationMerkleTree.js";
1817
import { minePendingVerificationResults } from "./mining/blockMiner.js";
1918

2019
import type { MessageType, BaseMessage, PayloadByMessageType, NetworkMessageOf, NewPeerPayload, NetworkMessage} from "./types/messages.js";
2120
import type { ProofRecord } from "./types/proof.js";
22-
import type { VerificationResult } from "./types/verification.js";
21+
import { getVerificationResultId, type VerificationResult } from "./types/verification.js";
2322

2423
const app = express();
2524
app.use(express.json());
@@ -453,7 +452,7 @@ app.get("/mempool", (_req, res) => {
453452
res.json({
454453
size: nodeState.verificationMempool.size(),
455454
results: results.map((result) => ({
456-
resultId: getVerificationResultId(result),
455+
resultId: result.verificationResultId,
457456
proofId: result.proofId,
458457
verifierNodeId: result.verifierNodeId,
459458
verified: result.verified,

node/src/merkle/verificationMerkleTree.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,4 @@ export async function computeVerificationMerkleRoot(
2323
const tree = await generateMerkleTree(leaves);
2424

2525
return tree.root;
26-
}
27-
28-
export function getVerificationResultId(result: VerificationResult): VerificationResultId {
29-
return `${result.proofId}:${result.verifierNodeId}`;
3026
}

node/src/mining/blockMiner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createBlock } from "../block/block.js";
22
import { mineBlock } from "../PoW/proofOfWork.js";
3-
import { getVerificationResultId } from "../merkle/verificationMerkleTree.js";
3+
import { getVerificationResultId } from "../types/verification.js";
44

55
import type { Block, BlockInput } from "../types/block.js";
66
import type { MinePendingResultsInput } from "../types/mining.js";
@@ -31,7 +31,7 @@ export async function minePendingVerificationResults(input: MinePendingResultsIn
3131
return null;
3232

3333

34-
input.mempool.remove(selectedResults.map(getVerificationResultId));
34+
input.mempool.remove(selectedResults.map((result) => result.verificationResultId));
3535

3636
return minedBlock;
3737
}

node/src/state/verificationMempool.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import type { VerificationResult, VerificationResultId } from "../types/verification.js";
2-
import { getVerificationResultId } from "../merkle/verificationMerkleTree.js";
1+
import { type VerificationResult, type VerificationResultId, getVerificationResultId } from "../types/verification.js";
2+
33

44
export class VerificationMempool {
55
private results = new Map<VerificationResultId, VerificationResult>();
66

77
add(result: VerificationResult): void {
8-
const resultId = getVerificationResultId(result);
9-
this.results.set(resultId, result);
8+
this.results.set(result.verificationResultId, result);
109
}
1110

1211
getAll(): VerificationResult[] {

node/src/types/verification.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { NodeId } from "./peer.js";
22

33
export interface VerificationResult {
4+
verificationResultId: VerificationResultId;
45
proofId: string;
56
verifierNodeId: NodeId;
67
verified: boolean;
78
szsStatus: string | null;
89
gdvOutputHash: string;
9-
gdvRawOutput: string; // TODO: think gdvRawOutput?: string;
10+
gdvRawOutput?: string;
1011
verifiedAt: number;
1112
}
1213

@@ -20,3 +21,7 @@ export interface RunGDVInput {
2021
tptpRoot: string;
2122
dockerImage: string;
2223
}
24+
25+
export function getVerificationResultId(proofId: string, verifierNodeId: NodeId): VerificationResultId {
26+
return `${proofId}:${verifierNodeId}`;
27+
}

node/src/verifier/gdvVerifier.ts

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import { tmpdir } from "os";
55
import { join } from "path";
66
import { promisify } from "util";
77

8-
import type { VerificationResult, RunGDVInput } from "../types/verification.js";
8+
import {getVerificationResultId, type VerificationResult, type RunGDVInput } from "../types/verification.js";
99

1010
const execFileAsync = promisify(execFile);
1111

12-
1312
function extractSZSStatus(output: string): string | null {
1413
const match = output.match(/SZS status\s+([A-Za-z_]+)/i);
1514

@@ -32,11 +31,25 @@ function normalizeTPTPIncludes(problemContent: string): string {
3231
);
3332
}
3433

35-
export async function runGDV(input: RunGDVInput): Promise<VerificationResult> {
36-
const { proofId, verifierNodeId, problemContent, proofContent, tptpRoot, dockerImage } =
37-
input;
34+
export async function runGDV(
35+
input: RunGDVInput
36+
): Promise<VerificationResult> {
37+
const {
38+
proofId,
39+
verifierNodeId,
40+
problemContent,
41+
proofContent,
42+
tptpRoot,
43+
dockerImage,
44+
} = input;
45+
46+
const verificationResultId = getVerificationResultId(proofId, verifierNodeId);
47+
48+
const workDir = join(
49+
tmpdir(),
50+
`gdv-${proofId}-${randomUUID()}`
51+
);
3852

39-
const workDir = join(tmpdir(), `gdv-${proofId}-${randomUUID()}`);
4053
const problemFile = join(workDir, "problem.p");
4154
const proofFile = join(workDir, "proof.s");
4255

@@ -56,10 +69,21 @@ export async function runGDV(input: RunGDVInput): Promise<VerificationResult> {
5669
await mkdir(workDir, { recursive: true });
5770

5871
try {
59-
const normalizedProblemContent = normalizeTPTPIncludes(problemContent);
72+
const normalizedProblemContent =
73+
normalizeTPTPIncludes(problemContent);
74+
75+
await writeFile(
76+
problemFile,
77+
normalizedProblemContent,
78+
"utf8"
79+
);
80+
81+
await writeFile(
82+
proofFile,
83+
cleanedProofContent,
84+
"utf8"
85+
);
6086

61-
await writeFile(problemFile, normalizedProblemContent, "utf8");
62-
await writeFile(proofFile, cleanedProofContent, "utf8");
6387
const { stdout, stderr } = await execFileAsync("docker", [
6488
"run",
6589
"--rm",
@@ -83,22 +107,30 @@ export async function runGDV(input: RunGDVInput): Promise<VerificationResult> {
83107
const verified = gdvOutput.includes("SUCCESS") || szsStatus === "Verified";
84108

85109
return {
110+
verificationResultId,
86111
proofId,
87112
verifierNodeId,
88113
verified,
89114
szsStatus,
90-
gdvOutputHash: createHash("sha256").update(gdvOutput).digest("hex"),
115+
gdvOutputHash: createHash("sha256")
116+
.update(gdvOutput)
117+
.digest("hex"),
91118
gdvRawOutput: gdvOutput,
92119
verifiedAt: Date.now(),
93120
};
94121
} catch (error) {
95-
const err = error as { stdout?: string; stderr?: string; message?: string };
122+
const err = error as {
123+
stdout?: string;
124+
stderr?: string;
125+
message?: string;
126+
};
96127

97-
const gdvOutput = `${err.stdout ?? ""}\n${err.stderr ?? ""}\n${
98-
err.message ?? ""
99-
}`;
128+
const gdvOutput = `${err.stdout ?? ""}\n${
129+
err.stderr ?? ""
130+
}\n${err.message ?? ""}`;
100131

101132
return {
133+
verificationResultId,
102134
proofId,
103135
verifierNodeId,
104136
verified: false,
@@ -108,6 +140,9 @@ export async function runGDV(input: RunGDVInput): Promise<VerificationResult> {
108140
verifiedAt: Date.now(),
109141
};
110142
} finally {
111-
await rm(workDir, { recursive: true, force: true });
143+
await rm(workDir, {
144+
recursive: true,
145+
force: true,
146+
});
112147
}
113148
}

0 commit comments

Comments
 (0)