@aztec/prover-client 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240

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.
Files changed (130) hide show
  1. package/dest/config.d.ts +1 -1
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +16 -2
  4. package/dest/light/lightweight_checkpoint_builder.d.ts +16 -7
  5. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  6. package/dest/light/lightweight_checkpoint_builder.js +75 -27
  7. package/dest/mocks/fixtures.d.ts +1 -1
  8. package/dest/mocks/fixtures.d.ts.map +1 -1
  9. package/dest/mocks/fixtures.js +2 -1
  10. package/dest/mocks/test_context.d.ts +5 -2
  11. package/dest/mocks/test_context.d.ts.map +1 -1
  12. package/dest/mocks/test_context.js +23 -9
  13. package/dest/orchestrator/block-building-helpers.d.ts +5 -5
  14. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  15. package/dest/orchestrator/block-building-helpers.js +3 -3
  16. package/dest/orchestrator/block-proving-state.d.ts +4 -1
  17. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  18. package/dest/orchestrator/block-proving-state.js +7 -0
  19. package/dest/orchestrator/checkpoint-proving-state.d.ts +24 -4
  20. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/checkpoint-proving-state.js +47 -5
  22. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +107 -0
  23. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
  24. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +151 -0
  25. package/dest/orchestrator/epoch-proving-context.d.ts +51 -0
  26. package/dest/orchestrator/epoch-proving-context.d.ts.map +1 -0
  27. package/dest/orchestrator/epoch-proving-context.js +81 -0
  28. package/dest/orchestrator/epoch-proving-state.d.ts +7 -6
  29. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  30. package/dest/orchestrator/epoch-proving-state.js +37 -1
  31. package/dest/orchestrator/index.d.ts +4 -1
  32. package/dest/orchestrator/index.d.ts.map +1 -1
  33. package/dest/orchestrator/index.js +3 -0
  34. package/dest/orchestrator/orchestrator.d.ts +29 -24
  35. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  36. package/dest/orchestrator/orchestrator.js +137 -225
  37. package/dest/orchestrator/proving-scheduler.d.ts +72 -0
  38. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
  39. package/dest/orchestrator/proving-scheduler.js +117 -0
  40. package/dest/orchestrator/top-tree-orchestrator.d.ts +83 -0
  41. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
  42. package/dest/orchestrator/top-tree-orchestrator.js +182 -0
  43. package/dest/orchestrator/top-tree-proving-scheduler.d.ts +62 -0
  44. package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +1 -0
  45. package/dest/orchestrator/top-tree-proving-scheduler.js +73 -0
  46. package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
  47. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
  48. package/dest/orchestrator/top-tree-proving-state.js +185 -0
  49. package/dest/prover-client/prover-client.d.ts +64 -5
  50. package/dest/prover-client/prover-client.d.ts.map +1 -1
  51. package/dest/prover-client/prover-client.js +64 -11
  52. package/dest/proving_broker/broker_prover_facade.d.ts +4 -3
  53. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  54. package/dest/proving_broker/broker_prover_facade.js +16 -22
  55. package/dest/proving_broker/config.d.ts +12 -64
  56. package/dest/proving_broker/config.d.ts.map +1 -1
  57. package/dest/proving_broker/config.js +22 -5
  58. package/dest/proving_broker/index.d.ts +2 -1
  59. package/dest/proving_broker/index.d.ts.map +1 -1
  60. package/dest/proving_broker/index.js +1 -0
  61. package/dest/proving_broker/proof_store/factory.d.ts +2 -5
  62. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
  63. package/dest/proving_broker/proof_store/factory.js +7 -30
  64. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  65. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  66. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  67. package/dest/proving_broker/proof_store/index.d.ts +2 -2
  68. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  69. package/dest/proving_broker/proof_store/index.js +1 -1
  70. package/dest/proving_broker/proving_agent.d.ts +4 -3
  71. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  72. package/dest/proving_broker/proving_agent.js +4 -4
  73. package/dest/proving_broker/proving_broker.d.ts +8 -5
  74. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  75. package/dest/proving_broker/proving_broker.js +68 -11
  76. package/dest/proving_broker/proving_broker_database/persisted.js +2 -2
  77. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  78. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  79. package/dest/proving_broker/proving_broker_instrumentation.js +18 -7
  80. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  81. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  82. package/dest/proving_broker/proving_job_controller.js +6 -3
  83. package/dest/proving_broker/rpc.d.ts +6 -2
  84. package/dest/proving_broker/rpc.d.ts.map +1 -1
  85. package/dest/proving_broker/rpc.js +87 -23
  86. package/dest/test/mock_proof_store.d.ts +3 -3
  87. package/dest/test/mock_proof_store.d.ts.map +1 -1
  88. package/dest/test/mock_prover.d.ts +4 -4
  89. package/package.json +19 -21
  90. package/src/config.ts +18 -2
  91. package/src/light/lightweight_checkpoint_builder.ts +107 -36
  92. package/src/mocks/fixtures.ts +2 -1
  93. package/src/mocks/test_context.ts +18 -10
  94. package/src/orchestrator/block-building-helpers.ts +3 -3
  95. package/src/orchestrator/block-proving-state.ts +9 -0
  96. package/src/orchestrator/checkpoint-proving-state.ts +65 -6
  97. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +271 -0
  98. package/src/orchestrator/epoch-proving-context.ts +101 -0
  99. package/src/orchestrator/epoch-proving-state.ts +59 -9
  100. package/src/orchestrator/index.ts +8 -0
  101. package/src/orchestrator/orchestrator.ts +161 -290
  102. package/src/orchestrator/proving-scheduler.ts +156 -0
  103. package/src/orchestrator/top-tree-orchestrator.ts +314 -0
  104. package/src/orchestrator/top-tree-proving-scheduler.ts +154 -0
  105. package/src/orchestrator/top-tree-proving-state.ts +220 -0
  106. package/src/prover-client/prover-client.ts +155 -15
  107. package/src/proving_broker/broker_prover_facade.ts +23 -23
  108. package/src/proving_broker/config.ts +25 -2
  109. package/src/proving_broker/index.ts +1 -0
  110. package/src/proving_broker/proof_store/factory.ts +10 -32
  111. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  112. package/src/proving_broker/proof_store/index.ts +1 -1
  113. package/src/proving_broker/proving_agent.ts +5 -2
  114. package/src/proving_broker/proving_broker.ts +64 -8
  115. package/src/proving_broker/proving_broker_database/persisted.ts +2 -2
  116. package/src/proving_broker/proving_broker_instrumentation.ts +19 -6
  117. package/src/proving_broker/proving_job_controller.ts +9 -3
  118. package/src/proving_broker/rpc.ts +46 -20
  119. package/dest/block-factory/index.d.ts +0 -2
  120. package/dest/block-factory/index.d.ts.map +0 -1
  121. package/dest/block-factory/index.js +0 -1
  122. package/dest/block-factory/light.d.ts +0 -38
  123. package/dest/block-factory/light.d.ts.map +0 -1
  124. package/dest/block-factory/light.js +0 -106
  125. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  126. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  127. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
  128. package/src/block-factory/index.ts +0 -1
  129. package/src/block-factory/light.ts +0 -136
  130. 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,7 +1,9 @@
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
- import { createLogger } from '@aztec/foundation/log';
6
+ import { type Logger, createLogger } from '@aztec/foundation/log';
5
7
  import { NativeACVMSimulator } from '@aztec/simulator/server';
6
8
  import {
7
9
  type ActualProverConfig,
@@ -15,41 +17,166 @@ 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
- private proofStore: ProofStore;
33
- private failedProofStore: ProofStore | undefined;
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
- private log = createLogger('prover-client:tx-prover'),
42
- ) {
43
- this.proofStore = new InlineProofStore();
44
- this.failedProofStore = this.config.failedProofStore ? createProofStore(this.config.failedProofStore) : undefined;
87
+ private log: Logger = createLogger('prover-client:tx-prover'),
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
- const facade = new BrokerCircuitProverFacade(this.orchestratorClient, this.proofStore, this.failedProofStore);
49
- const orchestrator = new ProvingOrchestrator(this.worldState, facade, this.config.proverId, this.telemetry);
123
+ const bindings = this.log.getBindings();
124
+ const facade = new BrokerCircuitProverFacade(
125
+ this.orchestratorClient,
126
+ this.proofStore,
127
+ this.failedProofStore,
128
+ undefined,
129
+ bindings,
130
+ );
131
+ const orchestrator = new ProvingOrchestrator(
132
+ this.worldState,
133
+ facade,
134
+ this.config.proverId,
135
+ this.config.cancelJobsOnStop,
136
+ this.config.enqueueConcurrency,
137
+ this.telemetry,
138
+ bindings,
139
+ );
50
140
  return new ServerEpochProver(facade, orchestrator);
51
141
  }
52
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
+
53
180
  public getProverId(): EthAddress {
54
181
  return this.config.proverId;
55
182
  }
@@ -89,6 +216,14 @@ export class ProverClient implements EpochProverManager {
89
216
  }
90
217
  this.running = false;
91
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
+ }
92
227
  await tryStop(this.orchestratorClient);
93
228
  }
94
229
 
@@ -104,7 +239,9 @@ export class ProverClient implements EpochProverManager {
104
239
  broker: ProvingJobBroker,
105
240
  telemetry: TelemetryClient = getTelemetryClient(),
106
241
  ) {
107
- const prover = new ProverClient(config, worldState, broker, broker, telemetry);
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);
108
245
  await prover.start();
109
246
  return prover;
110
247
  }
@@ -128,9 +265,11 @@ export class ProverClient implements EpochProverManager {
128
265
 
129
266
  const proofStore = new InlineProofStore();
130
267
  const prover = await buildServerCircuitProver(this.config, this.telemetry);
268
+ const bindings = this.log.getBindings();
131
269
  this.agents = times(
132
270
  this.config.proverAgentCount,
133
- () => new ProvingAgent(this.agentClient!, proofStore, prover, [], this.config.proverAgentPollIntervalMs),
271
+ () =>
272
+ new ProvingAgent(this.agentClient!, proofStore, prover, [], this.config.proverAgentPollIntervalMs, bindings),
134
273
  );
135
274
 
136
275
  await Promise.all(this.agents.map(agent => agent.start()));
@@ -142,15 +281,16 @@ export class ProverClient implements EpochProverManager {
142
281
  }
143
282
 
144
283
  export function buildServerCircuitProver(
145
- config: ActualProverConfig & ACVMConfig & BBConfig,
284
+ config: Omit<ActualProverConfig, 'enqueueConcurrency'> & ACVMConfig & BBConfig,
146
285
  telemetry: TelemetryClient,
147
286
  ): Promise<ServerCircuitProver> {
148
287
  if (config.realProofs) {
149
288
  return BBNativeRollupProver.new(config, telemetry);
150
289
  }
151
290
 
291
+ const logger = createLogger('prover-client:acvm-native');
152
292
  const simulator = config.acvmBinaryPath
153
- ? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath)
293
+ ? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath, undefined, logger)
154
294
  : undefined;
155
295
 
156
296
  return Promise.resolve(new TestCircuitProver(simulator, config, telemetry));
@@ -4,9 +4,10 @@ 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 { sha256 } from '@aztec/foundation/crypto/sha256';
9
- import { createLogger } from '@aztec/foundation/log';
9
+ import { chunk } from '@aztec/foundation/collection';
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';
12
13
  import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
@@ -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
@@ -68,14 +71,17 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
68
71
  private runningPromise?: RunningPromise;
69
72
  private timeOfLastSnapshotSync = Date.now();
70
73
  private jobsToRetrieve: Set<ProvingJobId> = new Set();
74
+ private log: Logger;
71
75
 
72
76
  constructor(
73
77
  private broker: ProvingJobProducer,
74
78
  private proofStore: ProofStore = new InlineProofStore(),
75
79
  private failedProofStore?: ProofStore,
76
80
  private pollIntervalMs = 1000,
77
- private log = createLogger('prover-client:broker-circuit-prover-facade'),
78
- ) {}
81
+ bindings?: LoggerBindings,
82
+ ) {
83
+ this.log = createLogger('prover-client:broker-circuit-prover-facade', bindings);
84
+ }
79
85
 
80
86
  /**
81
87
  * This is a critical section. This function can not be async since it writes
@@ -222,17 +228,11 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
222
228
  // We collect all returned notifications and return them
223
229
  const allCompleted = new Set<ProvingJobId>();
224
230
  try {
225
- let numRequests = 0;
226
- while (ids.length > 0) {
227
- const slice = ids.splice(0, SNAPSHOT_SYNC_CHECK_MAX_REQUEST_SIZE);
228
- 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);
229
234
  completed.forEach(id => allCompleted.add(id));
230
- ++numRequests;
231
- }
232
- if (numRequests === 0) {
233
- const final = await this.broker.getCompletedJobs([]);
234
- final.forEach(id => allCompleted.add(id));
235
- }
235
+ });
236
236
  } catch (err) {
237
237
  this.log.error(`Error thrown when requesting completed job notifications from the broker`, err);
238
238
  }
@@ -348,12 +348,8 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
348
348
  .map(id => this.jobs.get(id)!)
349
349
  .filter(x => x !== undefined);
350
350
  const totalJobsToRetrieve = toBeRetrieved.length;
351
- let totalJobsRetrieved = 0;
352
- while (toBeRetrieved.length > 0) {
353
- const slice = toBeRetrieved.splice(0, MAX_CONCURRENT_JOB_SETTLED_REQUESTS);
354
- const results = await Promise.all(slice.map(job => processJob(job!)));
355
- totalJobsRetrieved += results.filter(x => x).length;
356
- }
351
+ const results = await asyncPool(MAX_CONCURRENT_JOB_SETTLED_REQUESTS, toBeRetrieved, job => processJob(job));
352
+ const totalJobsRetrieved = results.filter(x => x).length;
357
353
  if (totalJobsToRetrieve > 0) {
358
354
  this.log.verbose(
359
355
  `Successfully retrieved ${totalJobsRetrieved} of ${totalJobsToRetrieve} jobs that should be ready, total ready jobs is now: ${this.jobsToRetrieve.size}`,
@@ -656,8 +652,12 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
656
652
  );
657
653
  }
658
654
 
659
- private generateId(type: ProvingRequestType, inputs: { toBuffer(): Buffer }, epochNumber = EpochNumber.ZERO) {
660
- const inputsHash = sha256(inputs.toBuffer());
661
- return makeProvingJobId(epochNumber, type, inputsHash.toString('hex'));
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);
662
662
  }
663
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
- parseEnv: (val: string | undefined) => (val ? +val : undefined),
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']),
@@ -100,6 +108,10 @@ export const ProverAgentConfig = z.object({
100
108
  proverTestDelayFactor: z.number(),
101
109
  /** The delay (ms) to inject during fake proof verification */
102
110
  proverTestVerificationDelayMs: z.number().optional(),
111
+ /** Whether to abort pending proving jobs when the orchestrator is cancelled */
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(),
103
115
  });
104
116
 
105
117
  export type ProverAgentConfig = z.infer<typeof ProverAgentConfig>;
@@ -153,4 +165,15 @@ export const proverAgentConfigMappings: ConfigMappingsType<ProverAgentConfig> =
153
165
  description: 'The delay (ms) to inject during fake proof verification',
154
166
  ...numberConfigHelper(10),
155
167
  },
168
+ cancelJobsOnStop: {
169
+ env: 'PROVER_CANCEL_JOBS_ON_STOP',
170
+ description:
171
+ 'Whether to abort pending proving jobs when the orchestrator is cancelled. ' +
172
+ 'When false (default), jobs remain in the broker queue and can be reused on restart/reorg.',
173
+ ...booleanConfigHelper(false),
174
+ },
175
+ proofStore: {
176
+ env: 'PROVER_PROOF_STORE',
177
+ description: 'Optional proof input store for the prover',
178
+ },
156
179
  };
@@ -7,3 +7,4 @@ export * from './proving_broker_database/persisted.js';
7
7
  export * from './proof_store/index.js';
8
8
  export * from './factory.js';
9
9
  export * from './config.js';
10
+ export { BrokerCircuitProverFacade } from './broker_prover_facade.js';
@@ -1,42 +1,20 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
+ import { createFileStore } from '@aztec/stdlib/file-store';
2
3
 
3
- import { GoogleCloudStorageProofStore } from './gcs_proof_store.js';
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(config: string | undefined, logger = createLogger('prover-client:proof-store')) {
8
- if (config === undefined) {
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
- export function createProofStoreForUri(
29
- uri: string,
30
- logger = createLogger('prover-client:proof-store'),
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
  }