@aztec/prover-client 0.0.1-commit.e558bd1c → 0.0.1-commit.e57c76e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -2
- package/dest/light/lightweight_checkpoint_builder.d.ts +10 -5
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +53 -22
- package/dest/mocks/test_context.d.ts +3 -1
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +18 -9
- package/dest/orchestrator/block-building-helpers.d.ts +4 -4
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +2 -2
- package/dest/orchestrator/block-proving-state.d.ts +4 -1
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +7 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts +10 -3
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +13 -4
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +107 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +151 -0
- package/dest/orchestrator/epoch-proving-context.d.ts +51 -0
- package/dest/orchestrator/epoch-proving-context.d.ts.map +1 -0
- package/dest/orchestrator/epoch-proving-context.js +81 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +3 -3
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +5 -3
- package/dest/orchestrator/index.d.ts +4 -1
- package/dest/orchestrator/index.d.ts.map +1 -1
- package/dest/orchestrator/index.js +3 -0
- package/dest/orchestrator/orchestrator.d.ts +16 -26
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +76 -206
- package/dest/orchestrator/proving-scheduler.d.ts +72 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +117 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +83 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +182 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts +62 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-scheduler.js +73 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-state.js +185 -0
- package/dest/prover-client/prover-client.d.ts +62 -3
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +50 -2
- package/dest/proving_broker/broker_prover_facade.d.ts +1 -1
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +13 -19
- package/dest/proving_broker/config.d.ts +9 -73
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +3 -3
- package/dest/proving_broker/index.d.ts +2 -1
- package/dest/proving_broker/index.d.ts.map +1 -1
- package/dest/proving_broker/index.js +1 -0
- package/dest/proving_broker/proving_broker.d.ts +2 -2
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +39 -10
- package/dest/proving_broker/proving_broker_database/persisted.js +2 -2
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +7 -0
- package/dest/proving_broker/rpc.d.ts +3 -1
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +80 -24
- package/dest/test/mock_prover.d.ts +4 -4
- package/package.json +18 -19
- package/src/config.ts +18 -2
- package/src/light/lightweight_checkpoint_builder.ts +56 -25
- package/src/mocks/test_context.ts +13 -10
- package/src/orchestrator/block-building-helpers.ts +2 -2
- package/src/orchestrator/block-proving-state.ts +9 -0
- package/src/orchestrator/checkpoint-proving-state.ts +18 -5
- package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +271 -0
- package/src/orchestrator/epoch-proving-context.ts +101 -0
- package/src/orchestrator/epoch-proving-state.ts +6 -4
- package/src/orchestrator/index.ts +8 -0
- package/src/orchestrator/orchestrator.ts +98 -268
- package/src/orchestrator/proving-scheduler.ts +156 -0
- package/src/orchestrator/top-tree-orchestrator.ts +314 -0
- package/src/orchestrator/top-tree-proving-scheduler.ts +154 -0
- package/src/orchestrator/top-tree-proving-state.ts +220 -0
- package/src/prover-client/prover-client.ts +127 -2
- package/src/proving_broker/broker_prover_facade.ts +17 -20
- package/src/proving_broker/config.ts +3 -2
- package/src/proving_broker/index.ts +1 -0
- package/src/proving_broker/proving_broker.ts +34 -7
- package/src/proving_broker/proving_broker_database/persisted.ts +2 -2
- package/src/proving_broker/proving_broker_instrumentation.ts +9 -0
- package/src/proving_broker/rpc.ts +36 -24
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { BatchedBlob, BatchedBlobAccumulator, FinalBlobBatchingChallenges } from '@aztec/blob-lib';
|
|
2
|
+
import type { NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
|
|
3
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
|
|
5
|
+
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import type { Proof } from '@aztec/stdlib/proofs';
|
|
7
|
+
import {
|
|
8
|
+
CheckpointMergeRollupPrivateInputs,
|
|
9
|
+
CheckpointPaddingRollupPrivateInputs,
|
|
10
|
+
CheckpointRollupPublicInputs,
|
|
11
|
+
RootRollupPrivateInputs,
|
|
12
|
+
type RootRollupPublicInputs,
|
|
13
|
+
} from '@aztec/stdlib/rollup';
|
|
14
|
+
|
|
15
|
+
import { toProofData } from './block-building-helpers.js';
|
|
16
|
+
import type { ProofState } from './block-proving-state.js';
|
|
17
|
+
|
|
18
|
+
enum TOP_TREE_LIFECYCLE {
|
|
19
|
+
CREATED,
|
|
20
|
+
RESOLVED,
|
|
21
|
+
REJECTED,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Lean top-tree-only state. Owns the merge tree of checkpoint root proofs, the
|
|
26
|
+
* single-checkpoint padding proof slot, the final root rollup proof, and the blob
|
|
27
|
+
* accumulator endpoints needed to finalise the epoch's batched blob proof.
|
|
28
|
+
*
|
|
29
|
+
* Constructed with `totalNumCheckpoints` and `finalBlobBatchingChallenges` upfront —
|
|
30
|
+
* by the time the top tree starts, all checkpoints are known and the challenges are
|
|
31
|
+
* derivable from their blob fields.
|
|
32
|
+
*/
|
|
33
|
+
export class TopTreeProvingState {
|
|
34
|
+
private checkpointProofs: UnbalancedTreeStore<
|
|
35
|
+
ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
36
|
+
>;
|
|
37
|
+
private checkpointPaddingProof:
|
|
38
|
+
| ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
39
|
+
| undefined;
|
|
40
|
+
private rootRollupProof: ProofState<RootRollupPublicInputs, typeof NESTED_RECURSIVE_PROOF_LENGTH> | undefined;
|
|
41
|
+
private endBlobAccumulator: BatchedBlobAccumulator | undefined;
|
|
42
|
+
private finalBatchedBlob: BatchedBlob | undefined;
|
|
43
|
+
private lifecycle = TOP_TREE_LIFECYCLE.CREATED;
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
public readonly epochNumber: EpochNumber,
|
|
47
|
+
public readonly totalNumCheckpoints: number,
|
|
48
|
+
public readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
|
|
49
|
+
public readonly startBlobAccumulator: BatchedBlobAccumulator,
|
|
50
|
+
private readonly completionCallback: () => void,
|
|
51
|
+
private readonly rejectionCallback: (reason: string) => void,
|
|
52
|
+
) {
|
|
53
|
+
if (totalNumCheckpoints < 1) {
|
|
54
|
+
throw new Error(`TopTreeProvingState requires at least one checkpoint; got ${totalNumCheckpoints}.`);
|
|
55
|
+
}
|
|
56
|
+
this.checkpointProofs = new UnbalancedTreeStore(totalNumCheckpoints);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// --- checkpoint root rollup ---
|
|
60
|
+
|
|
61
|
+
public setCheckpointRootRollupProof(
|
|
62
|
+
checkpointIndex: number,
|
|
63
|
+
provingOutput: PublicInputsAndRecursiveProof<
|
|
64
|
+
CheckpointRollupPublicInputs,
|
|
65
|
+
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
66
|
+
>,
|
|
67
|
+
): TreeNodeLocation {
|
|
68
|
+
return this.checkpointProofs.setLeaf(checkpointIndex, { provingOutput });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// --- checkpoint merge rollup ---
|
|
72
|
+
|
|
73
|
+
public tryStartProvingCheckpointMerge(location: TreeNodeLocation) {
|
|
74
|
+
if (this.checkpointProofs.getNode(location)?.isProving) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
this.checkpointProofs.setNode(location, { isProving: true });
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public setCheckpointMergeRollupProof(
|
|
82
|
+
location: TreeNodeLocation,
|
|
83
|
+
provingOutput: PublicInputsAndRecursiveProof<
|
|
84
|
+
CheckpointRollupPublicInputs,
|
|
85
|
+
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
86
|
+
>,
|
|
87
|
+
) {
|
|
88
|
+
this.checkpointProofs.setNode(location, { provingOutput });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public isReadyForCheckpointMerge(location: TreeNodeLocation) {
|
|
92
|
+
return !!this.checkpointProofs.getSibling(location)?.provingOutput;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public getParentLocation(location: TreeNodeLocation) {
|
|
96
|
+
return this.checkpointProofs.getParentLocation(location);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public getCheckpointMergeRollupInputs(mergeLocation: TreeNodeLocation) {
|
|
100
|
+
const [left, right] = this.checkpointProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
|
|
101
|
+
if (!left || !right) {
|
|
102
|
+
throw new Error('At least one child is not ready for the checkpoint merge rollup.');
|
|
103
|
+
}
|
|
104
|
+
return new CheckpointMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// --- padding (single-checkpoint case) ---
|
|
108
|
+
|
|
109
|
+
public tryStartProvingPaddingCheckpoint() {
|
|
110
|
+
if (this.checkpointPaddingProof?.isProving) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
this.checkpointPaddingProof = { isProving: true };
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public setCheckpointPaddingProof(
|
|
118
|
+
provingOutput: PublicInputsAndRecursiveProof<
|
|
119
|
+
CheckpointRollupPublicInputs,
|
|
120
|
+
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
121
|
+
>,
|
|
122
|
+
) {
|
|
123
|
+
this.checkpointPaddingProof = { provingOutput };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public getPaddingCheckpointInputs() {
|
|
127
|
+
return new CheckpointPaddingRollupPrivateInputs();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// --- root rollup ---
|
|
131
|
+
|
|
132
|
+
public tryStartProvingRootRollup() {
|
|
133
|
+
if (this.rootRollupProof?.isProving) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
this.rootRollupProof = { isProving: true };
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public setRootRollupProof(provingOutput: PublicInputsAndRecursiveProof<RootRollupPublicInputs>) {
|
|
141
|
+
this.rootRollupProof = { provingOutput };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public isReadyForRootRollup() {
|
|
145
|
+
const childProofs = this.#getChildProofsForRoot();
|
|
146
|
+
return childProofs.every(p => !!p);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public getRootRollupInputs() {
|
|
150
|
+
const [left, right] = this.#getChildProofsForRoot();
|
|
151
|
+
if (!left || !right) {
|
|
152
|
+
throw new Error('At least one child is not ready for the root rollup.');
|
|
153
|
+
}
|
|
154
|
+
return RootRollupPrivateInputs.from({
|
|
155
|
+
previousRollups: [toProofData(left), toProofData(right)],
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// --- blob accumulator finalisation ---
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Sets the end-of-epoch blob accumulator, computed by the top-tree orchestrator
|
|
163
|
+
* from the surviving checkpoints' blob fields. Required before `finalizeBatchedBlob`.
|
|
164
|
+
*/
|
|
165
|
+
public setEndBlobAccumulator(accumulator: BatchedBlobAccumulator) {
|
|
166
|
+
this.endBlobAccumulator = accumulator;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public async finalizeBatchedBlob() {
|
|
170
|
+
if (!this.endBlobAccumulator) {
|
|
171
|
+
throw new Error('End blob accumulator not set; call setEndBlobAccumulator before finalize.');
|
|
172
|
+
}
|
|
173
|
+
this.finalBatchedBlob = await this.endBlobAccumulator.finalize(true /* verifyProof */);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs; batchedBlobInputs: BatchedBlob } {
|
|
177
|
+
const provingOutput = this.rootRollupProof?.provingOutput;
|
|
178
|
+
if (!provingOutput || !this.finalBatchedBlob) {
|
|
179
|
+
throw new Error('Top-tree proof not ready; root rollup or batched blob missing.');
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
proof: provingOutput.proof.binaryProof,
|
|
183
|
+
publicInputs: provingOutput.inputs,
|
|
184
|
+
batchedBlobInputs: this.finalBatchedBlob,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// --- lifecycle ---
|
|
189
|
+
|
|
190
|
+
public verifyState() {
|
|
191
|
+
return this.lifecycle === TOP_TREE_LIFECYCLE.CREATED;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public resolve() {
|
|
195
|
+
if (!this.verifyState()) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
this.lifecycle = TOP_TREE_LIFECYCLE.RESOLVED;
|
|
199
|
+
this.completionCallback();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public reject(reason: string) {
|
|
203
|
+
if (!this.verifyState()) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
this.lifecycle = TOP_TREE_LIFECYCLE.REJECTED;
|
|
207
|
+
this.rejectionCallback(reason);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public cancel() {
|
|
211
|
+
this.reject('Top-tree proving cancelled');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
#getChildProofsForRoot() {
|
|
215
|
+
const rootLocation = { level: 0, index: 0 };
|
|
216
|
+
return this.totalNumCheckpoints === 1
|
|
217
|
+
? [this.checkpointProofs.getNode(rootLocation)?.provingOutput, this.checkpointPaddingProof?.provingOutput]
|
|
218
|
+
: this.checkpointProofs.getChildren(rootLocation).map(c => c?.provingOutput);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ACVMConfig, type BBConfig, BBNativeRollupProver, TestCircuitProver } from '@aztec/bb-prover';
|
|
2
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { times } from '@aztec/foundation/collection';
|
|
4
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
5
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
6
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
7
|
import { NativeACVMSimulator } from '@aztec/simulator/server';
|
|
@@ -15,19 +17,64 @@ import {
|
|
|
15
17
|
type ServerCircuitProver,
|
|
16
18
|
tryStop,
|
|
17
19
|
} from '@aztec/stdlib/interfaces/server';
|
|
20
|
+
import type { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
21
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
18
22
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
19
23
|
|
|
20
24
|
import type { ProverClientConfig } from '../config.js';
|
|
25
|
+
import { CheckpointSubTreeOrchestrator } from '../orchestrator/checkpoint-sub-tree-orchestrator.js';
|
|
26
|
+
import { EpochProvingContext } from '../orchestrator/epoch-proving-context.js';
|
|
21
27
|
import { ProvingOrchestrator } from '../orchestrator/orchestrator.js';
|
|
28
|
+
import { TopTreeOrchestrator } from '../orchestrator/top-tree-orchestrator.js';
|
|
22
29
|
import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
|
|
23
30
|
import { InlineProofStore, type ProofStore, createProofStore } from '../proving_broker/proof_store/index.js';
|
|
24
31
|
import { ProvingAgent } from '../proving_broker/proving_agent.js';
|
|
25
32
|
import { ServerEpochProver } from './server-epoch-prover.js';
|
|
26
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The factory surface that `EpochProvingJob` (in `prover-node`) depends on. Implemented
|
|
36
|
+
* by `ProverClient`. Defined here rather than in stdlib because the return types
|
|
37
|
+
* (`CheckpointSubTreeOrchestrator`, `TopTreeOrchestrator`) are concrete classes from
|
|
38
|
+
* this package.
|
|
39
|
+
*
|
|
40
|
+
* A single `BrokerCircuitProverFacade` is owned by `ProverClient` and shared across
|
|
41
|
+
* every orchestrator (every sub-tree and every top-tree across every concurrent epoch
|
|
42
|
+
* job). The broker delivers each completed-job notification exactly once (drained on
|
|
43
|
+
* the first `getCompletedJobs` poll), so multiple facades polling the same broker
|
|
44
|
+
* race and lose notifications
|
|
45
|
+
*
|
|
46
|
+
* The facade's job map cleans up entries on resolve/reject, and the prover-node
|
|
47
|
+
* keeps `ProverClient` alive for its whole lifetime
|
|
48
|
+
*/
|
|
49
|
+
export interface EpochProverFactory {
|
|
50
|
+
getProverId(): EthAddress;
|
|
51
|
+
/**
|
|
52
|
+
* Constructs a per-epoch shared context for the caching of e.g. chonk verifier results
|
|
53
|
+
*/
|
|
54
|
+
createEpochProvingContext(epochNumber: EpochNumber): EpochProvingContext;
|
|
55
|
+
/**
|
|
56
|
+
* Constructs and starts a `CheckpointSubTreeOrchestrator` for a single checkpoint.
|
|
57
|
+
*/
|
|
58
|
+
createCheckpointSubTreeOrchestrator(
|
|
59
|
+
epochContext: EpochProvingContext,
|
|
60
|
+
checkpointConstants: CheckpointConstantData,
|
|
61
|
+
l1ToL2Messages: Fr[],
|
|
62
|
+
totalNumBlocks: number,
|
|
63
|
+
headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
64
|
+
): Promise<CheckpointSubTreeOrchestrator>;
|
|
65
|
+
createTopTreeOrchestrator(): TopTreeOrchestrator;
|
|
66
|
+
}
|
|
67
|
+
|
|
27
68
|
/** Manages proving of epochs by orchestrating the proving of individual blocks relying on a pool of prover agents. */
|
|
28
|
-
export class ProverClient implements EpochProverManager {
|
|
69
|
+
export class ProverClient implements EpochProverManager, EpochProverFactory {
|
|
29
70
|
private running = false;
|
|
30
71
|
private agents: ProvingAgent[] = [];
|
|
72
|
+
/**
|
|
73
|
+
* The single broker facade shared by every orchestrator created from this client.
|
|
74
|
+
* Constructed lazily on `start()` and torn down on `stop()` — see the comment on
|
|
75
|
+
* `EpochProverFactory` for why a single shared facade is required.
|
|
76
|
+
*/
|
|
77
|
+
private facade: BrokerCircuitProverFacade | undefined;
|
|
31
78
|
|
|
32
79
|
private constructor(
|
|
33
80
|
private config: ProverClientConfig,
|
|
@@ -40,6 +87,38 @@ export class ProverClient implements EpochProverManager {
|
|
|
40
87
|
private log: Logger = createLogger('prover-client:tx-prover'),
|
|
41
88
|
) {}
|
|
42
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Lazy-init the shared facade. The broker delivers each completed-job notification
|
|
92
|
+
* exactly once (drained on the first `getCompletedJobs` poll), so we cannot start
|
|
93
|
+
* a shared facade alongside the per-call facades that `createEpochProver` builds —
|
|
94
|
+
* they would race for notifications and one side would silently drop them. Starting
|
|
95
|
+
* the shared facade only on first use of one of the new factory methods keeps the
|
|
96
|
+
* legacy `createEpochProver` path race-free.
|
|
97
|
+
*/
|
|
98
|
+
private getFacade(): BrokerCircuitProverFacade {
|
|
99
|
+
if (!this.running) {
|
|
100
|
+
throw new Error('ProverClient is not running; call start() before constructing orchestrators.');
|
|
101
|
+
}
|
|
102
|
+
if (!this.facade) {
|
|
103
|
+
this.facade = new BrokerCircuitProverFacade(
|
|
104
|
+
this.orchestratorClient,
|
|
105
|
+
this.proofStore,
|
|
106
|
+
this.failedProofStore,
|
|
107
|
+
undefined,
|
|
108
|
+
this.log.getBindings(),
|
|
109
|
+
);
|
|
110
|
+
this.facade.start();
|
|
111
|
+
}
|
|
112
|
+
return this.facade;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Legacy single-class epoch prover. Each call constructs its own
|
|
117
|
+
* `BrokerCircuitProverFacade`; the new factory methods (`createCheckpointSubTreeOrchestrator`,
|
|
118
|
+
* `createTopTreeOrchestrator`, `createEpochProvingContext`) share a single facade
|
|
119
|
+
* owned by `ProverClient`. Both APIs coexist while the prover-node migrates onto
|
|
120
|
+
* the new pair.
|
|
121
|
+
*/
|
|
43
122
|
public createEpochProver(): EpochProver {
|
|
44
123
|
const bindings = this.log.getBindings();
|
|
45
124
|
const facade = new BrokerCircuitProverFacade(
|
|
@@ -54,12 +133,50 @@ export class ProverClient implements EpochProverManager {
|
|
|
54
133
|
facade,
|
|
55
134
|
this.config.proverId,
|
|
56
135
|
this.config.cancelJobsOnStop,
|
|
136
|
+
this.config.enqueueConcurrency,
|
|
57
137
|
this.telemetry,
|
|
58
138
|
bindings,
|
|
59
139
|
);
|
|
60
140
|
return new ServerEpochProver(facade, orchestrator);
|
|
61
141
|
}
|
|
62
142
|
|
|
143
|
+
public createEpochProvingContext(epochNumber: EpochNumber): EpochProvingContext {
|
|
144
|
+
return new EpochProvingContext(this.getFacade(), epochNumber, this.log.getBindings());
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public createCheckpointSubTreeOrchestrator(
|
|
148
|
+
epochContext: EpochProvingContext,
|
|
149
|
+
checkpointConstants: CheckpointConstantData,
|
|
150
|
+
l1ToL2Messages: Fr[],
|
|
151
|
+
totalNumBlocks: number,
|
|
152
|
+
headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
153
|
+
): Promise<CheckpointSubTreeOrchestrator> {
|
|
154
|
+
return CheckpointSubTreeOrchestrator.start(
|
|
155
|
+
this.worldState,
|
|
156
|
+
this.getFacade(),
|
|
157
|
+
this.config.proverId,
|
|
158
|
+
epochContext,
|
|
159
|
+
this.config.cancelJobsOnStop,
|
|
160
|
+
this.config.enqueueConcurrency,
|
|
161
|
+
checkpointConstants,
|
|
162
|
+
l1ToL2Messages,
|
|
163
|
+
totalNumBlocks,
|
|
164
|
+
headerOfLastBlockInPreviousCheckpoint,
|
|
165
|
+
this.telemetry,
|
|
166
|
+
this.log.getBindings(),
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public createTopTreeOrchestrator(): TopTreeOrchestrator {
|
|
171
|
+
return new TopTreeOrchestrator(
|
|
172
|
+
this.getFacade(),
|
|
173
|
+
this.config.proverId,
|
|
174
|
+
this.config.enqueueConcurrency,
|
|
175
|
+
this.telemetry,
|
|
176
|
+
this.log.getBindings(),
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
63
180
|
public getProverId(): EthAddress {
|
|
64
181
|
return this.config.proverId;
|
|
65
182
|
}
|
|
@@ -99,6 +216,14 @@ export class ProverClient implements EpochProverManager {
|
|
|
99
216
|
}
|
|
100
217
|
this.running = false;
|
|
101
218
|
await this.stopAgents();
|
|
219
|
+
if (this.facade) {
|
|
220
|
+
try {
|
|
221
|
+
await this.facade.stop();
|
|
222
|
+
} catch (err) {
|
|
223
|
+
this.log.error('Error stopping shared broker facade', err);
|
|
224
|
+
}
|
|
225
|
+
this.facade = undefined;
|
|
226
|
+
}
|
|
102
227
|
await tryStop(this.orchestratorClient);
|
|
103
228
|
}
|
|
104
229
|
|
|
@@ -156,7 +281,7 @@ export class ProverClient implements EpochProverManager {
|
|
|
156
281
|
}
|
|
157
282
|
|
|
158
283
|
export function buildServerCircuitProver(
|
|
159
|
-
config: ActualProverConfig & ACVMConfig & BBConfig,
|
|
284
|
+
config: Omit<ActualProverConfig, 'enqueueConcurrency'> & ACVMConfig & BBConfig,
|
|
160
285
|
telemetry: TelemetryClient,
|
|
161
286
|
): Promise<ServerCircuitProver> {
|
|
162
287
|
if (config.realProofs) {
|
|
@@ -4,8 +4,9 @@ import type {
|
|
|
4
4
|
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
5
5
|
RECURSIVE_PROOF_LENGTH,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
+
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
7
8
|
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
8
|
-
import {
|
|
9
|
+
import { chunk } from '@aztec/foundation/collection';
|
|
9
10
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
10
11
|
import { type PromiseWithResolvers, RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
11
12
|
import { truncate } from '@aztec/foundation/string';
|
|
@@ -46,6 +47,8 @@ import type {
|
|
|
46
47
|
TxRollupPublicInputs,
|
|
47
48
|
} from '@aztec/stdlib/rollup';
|
|
48
49
|
|
|
50
|
+
import { createHash } from 'node:crypto';
|
|
51
|
+
|
|
49
52
|
import { InlineProofStore, type ProofStore } from './proof_store/index.js';
|
|
50
53
|
|
|
51
54
|
// Perform a snapshot sync every 30 seconds
|
|
@@ -225,17 +228,11 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
225
228
|
// We collect all returned notifications and return them
|
|
226
229
|
const allCompleted = new Set<ProvingJobId>();
|
|
227
230
|
try {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
const completed = await this.broker.getCompletedJobs(slice);
|
|
231
|
+
const batches = ids.length > 0 ? chunk(ids, SNAPSHOT_SYNC_CHECK_MAX_REQUEST_SIZE) : [[]];
|
|
232
|
+
await asyncPool(1, batches, async batch => {
|
|
233
|
+
const completed = await this.broker.getCompletedJobs(batch);
|
|
232
234
|
completed.forEach(id => allCompleted.add(id));
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
if (numRequests === 0) {
|
|
236
|
-
const final = await this.broker.getCompletedJobs([]);
|
|
237
|
-
final.forEach(id => allCompleted.add(id));
|
|
238
|
-
}
|
|
235
|
+
});
|
|
239
236
|
} catch (err) {
|
|
240
237
|
this.log.error(`Error thrown when requesting completed job notifications from the broker`, err);
|
|
241
238
|
}
|
|
@@ -351,12 +348,8 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
351
348
|
.map(id => this.jobs.get(id)!)
|
|
352
349
|
.filter(x => x !== undefined);
|
|
353
350
|
const totalJobsToRetrieve = toBeRetrieved.length;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const slice = toBeRetrieved.splice(0, MAX_CONCURRENT_JOB_SETTLED_REQUESTS);
|
|
357
|
-
const results = await Promise.all(slice.map(job => processJob(job!)));
|
|
358
|
-
totalJobsRetrieved += results.filter(x => x).length;
|
|
359
|
-
}
|
|
351
|
+
const results = await asyncPool(MAX_CONCURRENT_JOB_SETTLED_REQUESTS, toBeRetrieved, job => processJob(job));
|
|
352
|
+
const totalJobsRetrieved = results.filter(x => x).length;
|
|
360
353
|
if (totalJobsToRetrieve > 0) {
|
|
361
354
|
this.log.verbose(
|
|
362
355
|
`Successfully retrieved ${totalJobsRetrieved} of ${totalJobsToRetrieve} jobs that should be ready, total ready jobs is now: ${this.jobsToRetrieve.size}`,
|
|
@@ -659,8 +652,12 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
659
652
|
);
|
|
660
653
|
}
|
|
661
654
|
|
|
662
|
-
private generateId(
|
|
663
|
-
|
|
664
|
-
|
|
655
|
+
private generateId(
|
|
656
|
+
type: ProvingRequestType,
|
|
657
|
+
inputs: { toBuffer(): Buffer },
|
|
658
|
+
epochNumber = EpochNumber.ZERO,
|
|
659
|
+
): ProvingJobId {
|
|
660
|
+
const inputsHash = createHash('sha256').update(inputs.toBuffer()).digest('hex');
|
|
661
|
+
return makeProvingJobId(epochNumber, type, inputsHash);
|
|
665
662
|
}
|
|
666
663
|
}
|
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
booleanConfigHelper,
|
|
5
5
|
getDefaultConfig,
|
|
6
6
|
numberConfigHelper,
|
|
7
|
+
optionalNumberConfigHelper,
|
|
7
8
|
} from '@aztec/foundation/config';
|
|
8
9
|
import { pickConfigMappings } from '@aztec/foundation/config';
|
|
9
|
-
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
|
|
10
10
|
import { type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
|
|
11
|
+
import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
|
|
11
12
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
12
13
|
|
|
13
14
|
import { z } from 'zod';
|
|
@@ -73,7 +74,7 @@ export const proverBrokerConfigMappings: ConfigMappingsType<ProverBrokerConfig>
|
|
|
73
74
|
},
|
|
74
75
|
proverBrokerStoreMapSizeKb: {
|
|
75
76
|
env: 'PROVER_BROKER_STORE_MAP_SIZE_KB',
|
|
76
|
-
|
|
77
|
+
...optionalNumberConfigHelper(),
|
|
77
78
|
description: "The size of the prover broker's database. Will override the dataStoreMapSizeKb if set.",
|
|
78
79
|
},
|
|
79
80
|
proverBrokerDebugReplayEnabled: {
|
|
@@ -314,19 +314,25 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Pr
|
|
|
314
314
|
// notify listeners of the cancellation
|
|
315
315
|
if (!this.resultsCache.has(id)) {
|
|
316
316
|
this.logger.info(`Cancelling job id=${id}`, { provingJobId: id });
|
|
317
|
-
await this.#reportProvingJobError(id, 'Aborted', false);
|
|
317
|
+
await this.#reportProvingJobError(id, 'Aborted', false, undefined, true);
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
private cleanUpProvingJobState(ids: ProvingJobId[]) {
|
|
322
|
+
const idsToClean = new Set(ids);
|
|
322
323
|
for (const id of ids) {
|
|
323
324
|
this.jobsCache.delete(id);
|
|
325
|
+
const deferred = this.promises.get(id);
|
|
326
|
+
if (deferred) {
|
|
327
|
+
deferred.resolve({ status: 'rejected', reason: 'Proving job cleaned up' });
|
|
328
|
+
}
|
|
324
329
|
this.promises.delete(id);
|
|
325
330
|
this.resultsCache.delete(id);
|
|
326
331
|
this.inProgress.delete(id);
|
|
327
332
|
this.retries.delete(id);
|
|
328
333
|
this.enqueuedAt.delete(id);
|
|
329
334
|
}
|
|
335
|
+
this.completedJobNotifications = this.completedJobNotifications.filter(id => !idsToClean.has(id));
|
|
330
336
|
}
|
|
331
337
|
|
|
332
338
|
#getProvingJobStatus(id: ProvingJobId): ProvingJobStatus {
|
|
@@ -395,6 +401,7 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Pr
|
|
|
395
401
|
err: string,
|
|
396
402
|
retry = false,
|
|
397
403
|
filter?: ProvingJobFilter,
|
|
404
|
+
aborted = false,
|
|
398
405
|
): Promise<GetProvingJobResponse | undefined> {
|
|
399
406
|
const info = this.inProgress.get(id);
|
|
400
407
|
const item = this.jobsCache.get(id);
|
|
@@ -455,7 +462,11 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Pr
|
|
|
455
462
|
this.promises.get(id)!.resolve(result);
|
|
456
463
|
this.completedJobNotifications.push(id);
|
|
457
464
|
|
|
458
|
-
|
|
465
|
+
if (aborted) {
|
|
466
|
+
this.instrumentation.incAbortedJobs(item.type);
|
|
467
|
+
} else {
|
|
468
|
+
this.instrumentation.incRejectedJobs(item.type);
|
|
469
|
+
}
|
|
459
470
|
if (info) {
|
|
460
471
|
const duration = this.msTimeSource() - info.startedAt;
|
|
461
472
|
this.instrumentation.recordJobDuration(item.type, duration);
|
|
@@ -589,21 +600,21 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Pr
|
|
|
589
600
|
}
|
|
590
601
|
|
|
591
602
|
private async cleanupPass() {
|
|
592
|
-
this.cleanupStaleJobs();
|
|
593
603
|
this.reEnqueueExpiredJobs();
|
|
594
604
|
const oldestEpochToKeep = this.oldestEpochToKeep();
|
|
595
605
|
if (oldestEpochToKeep > 0) {
|
|
606
|
+
this.cleanupJobsOlderThanEpoch(EpochNumber(oldestEpochToKeep));
|
|
596
607
|
await this.database.deleteAllProvingJobsOlderThanEpoch(EpochNumber(oldestEpochToKeep));
|
|
597
608
|
this.logger.trace(`Deleted all epochs older than ${oldestEpochToKeep}`);
|
|
598
609
|
}
|
|
599
610
|
}
|
|
600
611
|
|
|
601
|
-
private
|
|
612
|
+
private cleanupJobsOlderThanEpoch(epochNumber: EpochNumber) {
|
|
602
613
|
const jobIds = Array.from(this.jobsCache.keys());
|
|
603
614
|
const jobsToClean: ProvingJobId[] = [];
|
|
604
615
|
for (const id of jobIds) {
|
|
605
616
|
const job = this.jobsCache.get(id)!;
|
|
606
|
-
if (
|
|
617
|
+
if (job.epochNumber < epochNumber) {
|
|
607
618
|
jobsToClean.push(id);
|
|
608
619
|
}
|
|
609
620
|
}
|
|
@@ -627,10 +638,26 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Pr
|
|
|
627
638
|
const now = this.msTimeSource();
|
|
628
639
|
const msSinceLastUpdate = now - metadata.lastUpdatedAt;
|
|
629
640
|
if (msSinceLastUpdate >= this.jobTimeoutMs) {
|
|
630
|
-
this.logger.warn(`Proving job id=${id} timed out. Adding it back to the queue.`, { provingJobId: id });
|
|
631
641
|
this.inProgress.delete(id);
|
|
632
|
-
this.enqueueJobInternal(item);
|
|
633
642
|
this.instrumentation.incTimedOutJobs(item.type);
|
|
643
|
+
|
|
644
|
+
const retries = this.retries.get(id) ?? 0;
|
|
645
|
+
if (retries + 1 < this.maxRetries && !this.isJobStale(item)) {
|
|
646
|
+
this.logger.warn(`Proving job id=${id} timed out. Re-enqueueing (retry ${retries + 1}/${this.maxRetries}).`, {
|
|
647
|
+
provingJobId: id,
|
|
648
|
+
});
|
|
649
|
+
this.retries.set(id, retries + 1);
|
|
650
|
+
this.enqueueJobInternal(item);
|
|
651
|
+
} else {
|
|
652
|
+
this.logger.error(`Proving job id=${id} timed out after ${retries + 1} attempts. Marking as failed.`, {
|
|
653
|
+
provingJobId: id,
|
|
654
|
+
});
|
|
655
|
+
const result: ProvingJobSettledResult = { status: 'rejected', reason: 'Timed out' };
|
|
656
|
+
this.resultsCache.set(id, result);
|
|
657
|
+
this.promises.get(id)?.resolve(result);
|
|
658
|
+
this.completedJobNotifications.push(id);
|
|
659
|
+
this.instrumentation.incRejectedJobs(item.type);
|
|
660
|
+
}
|
|
634
661
|
}
|
|
635
662
|
}
|
|
636
663
|
}
|
|
@@ -154,7 +154,7 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
154
154
|
const db = await openVersionedStoreAt(
|
|
155
155
|
fullDirectory,
|
|
156
156
|
SingleEpochDatabase.SCHEMA_VERSION,
|
|
157
|
-
config.
|
|
157
|
+
config.rollupAddress,
|
|
158
158
|
config.dataStoreMapSizeKb,
|
|
159
159
|
);
|
|
160
160
|
const epochDb = new SingleEpochDatabase(db);
|
|
@@ -222,7 +222,7 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
222
222
|
const db = await openVersionedStoreAt(
|
|
223
223
|
newEpochDirectory,
|
|
224
224
|
SingleEpochDatabase.SCHEMA_VERSION,
|
|
225
|
-
this.config.
|
|
225
|
+
this.config.rollupAddress,
|
|
226
226
|
this.config.dataStoreMapSizeKb,
|
|
227
227
|
);
|
|
228
228
|
epochDb = new SingleEpochDatabase(db);
|
|
@@ -18,6 +18,7 @@ export class ProvingBrokerInstrumentation {
|
|
|
18
18
|
private activeJobs: ObservableGauge;
|
|
19
19
|
private resolvedJobs: UpDownCounter;
|
|
20
20
|
private rejectedJobs: UpDownCounter;
|
|
21
|
+
private abortedJobs: UpDownCounter;
|
|
21
22
|
private timedOutJobs: UpDownCounter;
|
|
22
23
|
private cachedJobs: UpDownCounter;
|
|
23
24
|
private totalJobs: UpDownCounter;
|
|
@@ -39,6 +40,8 @@ export class ProvingBrokerInstrumentation {
|
|
|
39
40
|
|
|
40
41
|
this.rejectedJobs = createUpDownCounterWithDefault(meter, Metrics.PROVING_QUEUE_REJECTED_JOBS, provingJobAttrs);
|
|
41
42
|
|
|
43
|
+
this.abortedJobs = createUpDownCounterWithDefault(meter, Metrics.PROVING_QUEUE_ABORTED_JOBS, provingJobAttrs);
|
|
44
|
+
|
|
42
45
|
this.retriedJobs = createUpDownCounterWithDefault(meter, Metrics.PROVING_QUEUE_RETRIED_JOBS, provingJobAttrs);
|
|
43
46
|
|
|
44
47
|
this.timedOutJobs = createUpDownCounterWithDefault(meter, Metrics.PROVING_QUEUE_TIMED_OUT_JOBS, provingJobAttrs);
|
|
@@ -72,6 +75,12 @@ export class ProvingBrokerInstrumentation {
|
|
|
72
75
|
});
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
incAbortedJobs(proofType: ProvingRequestType) {
|
|
79
|
+
this.abortedJobs.add(1, {
|
|
80
|
+
[Attributes.PROVING_JOB_TYPE]: ProvingRequestType[proofType],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
75
84
|
incRetriedJobs(proofType: ProvingRequestType) {
|
|
76
85
|
this.retriedJobs.add(1, {
|
|
77
86
|
[Attributes.PROVING_JOB_TYPE]: ProvingRequestType[proofType],
|