@aztec/prover-client 0.0.1-commit.e3c1de76 → 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 +64 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +58 -8
- 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 +11 -67
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +16 -5
- 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/proof_store/factory.d.ts +2 -5
- package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/factory.js +7 -30
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -2
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -1
- package/dest/proving_broker/proving_broker.d.ts +8 -5
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +68 -11
- 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 +6 -2
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +87 -23
- 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 +132 -9
- package/src/proving_broker/broker_prover_facade.ts +17 -20
- package/src/proving_broker/config.ts +16 -2
- package/src/proving_broker/index.ts +1 -0
- package/src/proving_broker/proof_store/factory.ts +10 -32
- package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
- package/src/proving_broker/proof_store/index.ts +1 -1
- package/src/proving_broker/proving_broker.ts +64 -8
- 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 +46 -20
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
|
@@ -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,35 +17,108 @@ 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[] = [];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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;
|
|
34
78
|
|
|
35
79
|
private constructor(
|
|
36
80
|
private config: ProverClientConfig,
|
|
37
81
|
private worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
|
|
38
82
|
private orchestratorClient: ProvingJobProducer,
|
|
83
|
+
private proofStore: ProofStore,
|
|
84
|
+
private failedProofStore: ProofStore | undefined,
|
|
39
85
|
private agentClient?: ProvingJobConsumer,
|
|
40
86
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
41
87
|
private log: Logger = createLogger('prover-client:tx-prover'),
|
|
42
|
-
) {
|
|
43
|
-
|
|
44
|
-
|
|
88
|
+
) {}
|
|
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;
|
|
45
113
|
}
|
|
46
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
|
+
*/
|
|
47
122
|
public createEpochProver(): EpochProver {
|
|
48
123
|
const bindings = this.log.getBindings();
|
|
49
124
|
const facade = new BrokerCircuitProverFacade(
|
|
@@ -58,12 +133,50 @@ export class ProverClient implements EpochProverManager {
|
|
|
58
133
|
facade,
|
|
59
134
|
this.config.proverId,
|
|
60
135
|
this.config.cancelJobsOnStop,
|
|
136
|
+
this.config.enqueueConcurrency,
|
|
61
137
|
this.telemetry,
|
|
62
138
|
bindings,
|
|
63
139
|
);
|
|
64
140
|
return new ServerEpochProver(facade, orchestrator);
|
|
65
141
|
}
|
|
66
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
|
+
|
|
67
180
|
public getProverId(): EthAddress {
|
|
68
181
|
return this.config.proverId;
|
|
69
182
|
}
|
|
@@ -103,6 +216,14 @@ export class ProverClient implements EpochProverManager {
|
|
|
103
216
|
}
|
|
104
217
|
this.running = false;
|
|
105
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
|
+
}
|
|
106
227
|
await tryStop(this.orchestratorClient);
|
|
107
228
|
}
|
|
108
229
|
|
|
@@ -118,7 +239,9 @@ export class ProverClient implements EpochProverManager {
|
|
|
118
239
|
broker: ProvingJobBroker,
|
|
119
240
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
120
241
|
) {
|
|
121
|
-
const
|
|
242
|
+
const proofStore = await createProofStore(config.proofStore);
|
|
243
|
+
const failedProofStore = config.failedProofStore ? await createProofStore(config.failedProofStore) : undefined;
|
|
244
|
+
const prover = new ProverClient(config, worldState, broker, proofStore, failedProofStore, broker, telemetry);
|
|
122
245
|
await prover.start();
|
|
123
246
|
return prover;
|
|
124
247
|
}
|
|
@@ -158,7 +281,7 @@ export class ProverClient implements EpochProverManager {
|
|
|
158
281
|
}
|
|
159
282
|
|
|
160
283
|
export function buildServerCircuitProver(
|
|
161
|
-
config: ActualProverConfig & ACVMConfig & BBConfig,
|
|
284
|
+
config: Omit<ActualProverConfig, 'enqueueConcurrency'> & ACVMConfig & BBConfig,
|
|
162
285
|
telemetry: TelemetryClient,
|
|
163
286
|
): Promise<ServerCircuitProver> {
|
|
164
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';
|
|
@@ -31,6 +32,8 @@ export const ProverBrokerConfig = z.object({
|
|
|
31
32
|
proverBrokerBatchIntervalMs: z.number().int().nonnegative(),
|
|
32
33
|
/** The maximum number of epochs to keep results for */
|
|
33
34
|
proverBrokerMaxEpochsToKeepResultsFor: z.number().int().nonnegative(),
|
|
35
|
+
/** Enable debug replay mode for replaying proving jobs from stored inputs */
|
|
36
|
+
proverBrokerDebugReplayEnabled: z.boolean(),
|
|
34
37
|
});
|
|
35
38
|
|
|
36
39
|
export type ProverBrokerConfig = z.infer<typeof ProverBrokerConfig> &
|
|
@@ -71,9 +74,14 @@ export const proverBrokerConfigMappings: ConfigMappingsType<ProverBrokerConfig>
|
|
|
71
74
|
},
|
|
72
75
|
proverBrokerStoreMapSizeKb: {
|
|
73
76
|
env: 'PROVER_BROKER_STORE_MAP_SIZE_KB',
|
|
74
|
-
|
|
77
|
+
...optionalNumberConfigHelper(),
|
|
75
78
|
description: "The size of the prover broker's database. Will override the dataStoreMapSizeKb if set.",
|
|
76
79
|
},
|
|
80
|
+
proverBrokerDebugReplayEnabled: {
|
|
81
|
+
env: 'PROVER_BROKER_DEBUG_REPLAY_ENABLED',
|
|
82
|
+
description: 'Enable debug replay mode for replaying proving jobs from stored inputs',
|
|
83
|
+
...booleanConfigHelper(false),
|
|
84
|
+
},
|
|
77
85
|
...dataConfigMappings,
|
|
78
86
|
...l1ReaderConfigMappings,
|
|
79
87
|
...pickConfigMappings(chainConfigMappings, ['rollupVersion']),
|
|
@@ -102,6 +110,8 @@ export const ProverAgentConfig = z.object({
|
|
|
102
110
|
proverTestVerificationDelayMs: z.number().optional(),
|
|
103
111
|
/** Whether to abort pending proving jobs when the orchestrator is cancelled */
|
|
104
112
|
cancelJobsOnStop: z.boolean(),
|
|
113
|
+
/** Where to store proving results. Must be accessible to both prover node and agents. If not set will inline-encode the parameters */
|
|
114
|
+
proofStore: z.string().optional(),
|
|
105
115
|
});
|
|
106
116
|
|
|
107
117
|
export type ProverAgentConfig = z.infer<typeof ProverAgentConfig>;
|
|
@@ -162,4 +172,8 @@ export const proverAgentConfigMappings: ConfigMappingsType<ProverAgentConfig> =
|
|
|
162
172
|
'When false (default), jobs remain in the broker queue and can be reused on restart/reorg.',
|
|
163
173
|
...booleanConfigHelper(false),
|
|
164
174
|
},
|
|
175
|
+
proofStore: {
|
|
176
|
+
env: 'PROVER_PROOF_STORE',
|
|
177
|
+
description: 'Optional proof input store for the prover',
|
|
178
|
+
},
|
|
165
179
|
};
|
|
@@ -1,42 +1,20 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { createFileStore } from '@aztec/stdlib/file-store';
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import { FileStoreProofStore } from './file_store_proof_store.js';
|
|
4
5
|
import { InlineProofStore } from './inline_proof_store.js';
|
|
5
6
|
import type { ProofStore } from './proof_store.js';
|
|
6
7
|
|
|
7
|
-
export function createProofStore(
|
|
8
|
-
|
|
8
|
+
export async function createProofStore(
|
|
9
|
+
config: string | undefined,
|
|
10
|
+
logger = createLogger('prover-client:proof-store'),
|
|
11
|
+
): Promise<ProofStore> {
|
|
12
|
+
if (!config) {
|
|
9
13
|
logger.info('Creating inline proof store');
|
|
10
14
|
return new InlineProofStore();
|
|
11
|
-
} else if (config.startsWith('gs://')) {
|
|
12
|
-
try {
|
|
13
|
-
const url = new URL(config);
|
|
14
|
-
const bucket = url.host;
|
|
15
|
-
const path = url.pathname.replace(/^\/+/, '');
|
|
16
|
-
logger.info(`Creating google cloud proof store at ${bucket}`, { bucket, path });
|
|
17
|
-
return new GoogleCloudStorageProofStore(bucket, path);
|
|
18
|
-
} catch {
|
|
19
|
-
throw new Error(
|
|
20
|
-
`Invalid google cloud proof store definition: '${config}'. Supported values are 'gs://bucket-name/path/to/store'.`,
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
} else {
|
|
24
|
-
throw new Error(`Unknown proof store config: '${config}'. Supported values are 'gs://bucket-name/path/to/store'.`);
|
|
25
15
|
}
|
|
26
|
-
}
|
|
27
16
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
): Pick<ProofStore, 'getProofInput' | 'getProofOutput'> {
|
|
32
|
-
if (uri.startsWith('data://')) {
|
|
33
|
-
return createProofStore(undefined, logger);
|
|
34
|
-
} else if (uri.startsWith('gs://')) {
|
|
35
|
-
const url = new URL(uri);
|
|
36
|
-
const basePath = url.pathname.replace(/^\/+/, '').split('/').slice(0, -3);
|
|
37
|
-
url.pathname = basePath.join('/');
|
|
38
|
-
return createProofStore(uri, logger);
|
|
39
|
-
} else {
|
|
40
|
-
throw new Error(`Unknown proof store config: '${uri}'. Supported protocols are 'data://' and 'gs://'.`);
|
|
41
|
-
}
|
|
17
|
+
const fileStore = await createFileStore(config, logger);
|
|
18
|
+
logger.info(`Creating file store proof store at ${config}`);
|
|
19
|
+
return new FileStoreProofStore(fileStore);
|
|
42
20
|
}
|