@aztec/prover-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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 +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +17 -3
- package/dest/light/index.d.ts +2 -0
- package/dest/light/index.d.ts.map +1 -0
- package/dest/light/index.js +1 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts +38 -15
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +162 -36
- package/dest/mocks/fixtures.d.ts +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +4 -3
- package/dest/mocks/test_context.d.ts +15 -13
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +50 -36
- package/dest/orchestrator/block-building-helpers.d.ts +6 -6
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +5 -5
- package/dest/orchestrator/block-proving-state.d.ts +5 -2
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +8 -1
- package/dest/orchestrator/checkpoint-proving-state.d.ts +20 -23
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +23 -87
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +161 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +1066 -0
- package/dest/orchestrator/chonk-cache.d.ts +39 -0
- package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
- package/dest/orchestrator/chonk-cache.js +80 -0
- package/dest/orchestrator/index.d.ts +4 -2
- package/dest/orchestrator/index.d.ts.map +1 -1
- package/dest/orchestrator/index.js +3 -1
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -15
- package/dest/orchestrator/proving-scheduler.d.ts +81 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +120 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +88 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +232 -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/orchestrator/tx-proving-state.d.ts +7 -6
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +8 -8
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/prover-client.d.ts +65 -8
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +66 -14
- package/dest/proving_broker/broker_prover_facade.d.ts +8 -6
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +18 -31
- package/dest/proving_broker/config.d.ts +13 -65
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +23 -6
- package/dest/proving_broker/fixtures.js +1 -1
- 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_agent.d.ts +5 -9
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -19
- 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 +72 -21
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +391 -3
- 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 +22 -35
- package/dest/proving_broker/proving_job_controller.d.ts +4 -3
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +8 -6
- 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/epoch_settlement.d.ts +36 -0
- package/dest/test/epoch_settlement.d.ts.map +1 -0
- package/dest/test/epoch_settlement.js +52 -0
- package/dest/test/index.d.ts +2 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/dest/test/mock_proof_store.d.ts +3 -3
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/dest/test/mock_prover.d.ts +5 -5
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +4 -4
- package/package.json +23 -22
- package/src/config.ts +19 -3
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +229 -50
- package/src/mocks/fixtures.ts +4 -3
- package/src/mocks/test_context.ts +44 -48
- package/src/orchestrator/block-building-helpers.ts +5 -5
- package/src/orchestrator/block-proving-state.ts +10 -1
- package/src/orchestrator/checkpoint-proving-state.ts +22 -116
- package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +1044 -0
- package/src/orchestrator/chonk-cache.ts +99 -0
- package/src/orchestrator/index.ts +8 -1
- package/src/orchestrator/orchestrator_metrics.ts +2 -25
- package/src/orchestrator/proving-scheduler.ts +160 -0
- package/src/orchestrator/top-tree-orchestrator.ts +384 -0
- package/src/orchestrator/top-tree-proving-state.ts +219 -0
- package/src/orchestrator/tx-proving-state.ts +11 -15
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +148 -29
- package/src/proving_broker/broker_prover_facade.ts +27 -37
- package/src/proving_broker/config.ts +26 -3
- package/src/proving_broker/fixtures.ts +1 -1
- 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_agent.ts +6 -19
- package/src/proving_broker/proving_broker.ts +68 -16
- package/src/proving_broker/proving_broker_database/persisted.ts +17 -3
- package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
- package/src/proving_broker/proving_job_controller.ts +11 -6
- package/src/proving_broker/rpc.ts +46 -20
- package/src/test/epoch_settlement.ts +82 -0
- package/src/test/index.ts +1 -0
- package/src/test/mock_prover.ts +3 -15
- package/dest/block-factory/index.d.ts +0 -2
- package/dest/block-factory/index.d.ts.map +0 -1
- package/dest/block-factory/index.js +0 -1
- package/dest/block-factory/light.d.ts +0 -38
- package/dest/block-factory/light.d.ts.map +0 -1
- package/dest/block-factory/light.js +0 -108
- package/dest/orchestrator/epoch-proving-state.d.ts +0 -74
- package/dest/orchestrator/epoch-proving-state.d.ts.map +0 -1
- package/dest/orchestrator/epoch-proving-state.js +0 -233
- package/dest/orchestrator/orchestrator.d.ts +0 -113
- package/dest/orchestrator/orchestrator.d.ts.map +0 -1
- package/dest/orchestrator/orchestrator.js +0 -842
- package/dest/prover-client/server-epoch-prover.d.ts +0 -32
- package/dest/prover-client/server-epoch-prover.d.ts.map +0 -1
- package/dest/prover-client/server-epoch-prover.js +0 -40
- 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/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
- package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
- package/src/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -137
- package/src/orchestrator/epoch-proving-state.ts +0 -330
- package/src/orchestrator/orchestrator.ts +0 -1265
- package/src/prover-client/server-epoch-prover.ts +0 -69
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,52 +1,166 @@
|
|
|
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';
|
|
7
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
5
8
|
import { NativeACVMSimulator } from '@aztec/simulator/server';
|
|
6
9
|
import {
|
|
7
10
|
type ActualProverConfig,
|
|
8
|
-
type EpochProver,
|
|
9
11
|
type EpochProverManager,
|
|
10
12
|
type ForkMerkleTreeOperations,
|
|
11
13
|
type ProvingJobBroker,
|
|
12
14
|
type ProvingJobConsumer,
|
|
13
15
|
type ProvingJobProducer,
|
|
16
|
+
type ReadonlyWorldStateAccess,
|
|
14
17
|
type ServerCircuitProver,
|
|
15
18
|
tryStop,
|
|
16
19
|
} from '@aztec/stdlib/interfaces/server';
|
|
20
|
+
import type { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
21
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
17
22
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
18
23
|
|
|
19
24
|
import type { ProverClientConfig } from '../config.js';
|
|
20
|
-
import {
|
|
25
|
+
import { CheckpointSubTreeOrchestrator } from '../orchestrator/checkpoint-sub-tree-orchestrator.js';
|
|
26
|
+
import type { ChonkCache } from '../orchestrator/chonk-cache.js';
|
|
27
|
+
import { TopTreeOrchestrator } from '../orchestrator/top-tree-orchestrator.js';
|
|
21
28
|
import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
|
|
22
29
|
import { InlineProofStore, type ProofStore, createProofStore } from '../proving_broker/proof_store/index.js';
|
|
23
30
|
import { ProvingAgent } from '../proving_broker/proving_agent.js';
|
|
24
|
-
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The factory surface that `EpochProvingJob` (in `prover-node`) depends on. Implemented
|
|
34
|
+
* by `ProverClient`. Defined here rather than in stdlib because the return types
|
|
35
|
+
* (`CheckpointSubTreeOrchestrator`, `TopTreeOrchestrator`) are concrete classes from
|
|
36
|
+
* this package.
|
|
37
|
+
*
|
|
38
|
+
* A single `BrokerCircuitProverFacade` is owned by `ProverClient` and shared across
|
|
39
|
+
* every orchestrator (every sub-tree and every top-tree across every concurrent epoch
|
|
40
|
+
* job). The broker delivers each completed-job notification exactly once (drained on
|
|
41
|
+
* the first `getCompletedJobs` poll), so multiple facades polling the same broker
|
|
42
|
+
* race and lose notifications
|
|
43
|
+
*
|
|
44
|
+
* The facade's job map cleans up entries on resolve/reject, and the prover-node
|
|
45
|
+
* keeps `ProverClient` alive for its whole lifetime
|
|
46
|
+
*/
|
|
47
|
+
export interface EpochProverFactory {
|
|
48
|
+
getProverId(): EthAddress;
|
|
49
|
+
/**
|
|
50
|
+
* Constructs and starts a `CheckpointSubTreeOrchestrator` for a single checkpoint
|
|
51
|
+
* against the supplied shared `chonkCache`. The cache is owned by the prover-node
|
|
52
|
+
* and survives across epochs / sessions.
|
|
53
|
+
*/
|
|
54
|
+
createCheckpointSubTreeOrchestrator(
|
|
55
|
+
chonkCache: ChonkCache,
|
|
56
|
+
epochNumber: EpochNumber,
|
|
57
|
+
checkpointConstants: CheckpointConstantData,
|
|
58
|
+
l1ToL2Messages: Fr[],
|
|
59
|
+
totalNumBlocks: number,
|
|
60
|
+
headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
61
|
+
): Promise<CheckpointSubTreeOrchestrator>;
|
|
62
|
+
createTopTreeOrchestrator(): TopTreeOrchestrator;
|
|
63
|
+
}
|
|
25
64
|
|
|
26
65
|
/** Manages proving of epochs by orchestrating the proving of individual blocks relying on a pool of prover agents. */
|
|
27
|
-
export class ProverClient implements EpochProverManager {
|
|
66
|
+
export class ProverClient implements EpochProverManager, EpochProverFactory {
|
|
28
67
|
private running = false;
|
|
29
68
|
private agents: ProvingAgent[] = [];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The single broker facade shared by every orchestrator created from this client.
|
|
71
|
+
* Constructed lazily on `start()` and torn down on `stop()` — see the comment on
|
|
72
|
+
* `EpochProverFactory` for why a single shared facade is required.
|
|
73
|
+
*/
|
|
74
|
+
private facade: BrokerCircuitProverFacade | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Single deferred-proving-job queue shared across every orchestrator (sub-trees and
|
|
77
|
+
* top-trees, across every concurrent epoch session). Throttles the total rate of job
|
|
78
|
+
* submission to the broker once, rather than once per orchestrator. Started lazily
|
|
79
|
+
* alongside the facade and cancelled on `stop()`.
|
|
80
|
+
*/
|
|
81
|
+
private deferredJobQueue: SerialQueue | undefined;
|
|
33
82
|
|
|
34
83
|
private constructor(
|
|
35
84
|
private config: ProverClientConfig,
|
|
36
|
-
private worldState: ForkMerkleTreeOperations,
|
|
85
|
+
private worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
|
|
37
86
|
private orchestratorClient: ProvingJobProducer,
|
|
87
|
+
private proofStore: ProofStore,
|
|
88
|
+
private failedProofStore: ProofStore | undefined,
|
|
38
89
|
private agentClient?: ProvingJobConsumer,
|
|
39
90
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
40
|
-
private log = createLogger('prover-client:tx-prover'),
|
|
41
|
-
) {
|
|
42
|
-
|
|
43
|
-
|
|
91
|
+
private log: Logger = createLogger('prover-client:tx-prover'),
|
|
92
|
+
) {}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Lazy-init the shared facade. The broker delivers each completed-job notification
|
|
96
|
+
* exactly once (drained on the first `getCompletedJobs` poll), so we cannot start
|
|
97
|
+
* a shared facade alongside the per-call facades that `createEpochProver` builds —
|
|
98
|
+
* they would race for notifications and one side would silently drop them. Starting
|
|
99
|
+
* the shared facade only on first use of one of the new factory methods keeps the
|
|
100
|
+
* legacy `createEpochProver` path race-free.
|
|
101
|
+
*/
|
|
102
|
+
private getFacade(): BrokerCircuitProverFacade {
|
|
103
|
+
if (!this.running) {
|
|
104
|
+
throw new Error('ProverClient is not running; call start() before constructing orchestrators.');
|
|
105
|
+
}
|
|
106
|
+
if (!this.facade) {
|
|
107
|
+
this.facade = new BrokerCircuitProverFacade(
|
|
108
|
+
this.orchestratorClient,
|
|
109
|
+
this.proofStore,
|
|
110
|
+
this.failedProofStore,
|
|
111
|
+
undefined,
|
|
112
|
+
this.log.getBindings(),
|
|
113
|
+
);
|
|
114
|
+
this.facade.start();
|
|
115
|
+
}
|
|
116
|
+
return this.facade;
|
|
44
117
|
}
|
|
45
118
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
119
|
+
/** Lazy-init the shared deferred-job queue, started with the configured enqueue concurrency. */
|
|
120
|
+
private getDeferredJobQueue(): SerialQueue {
|
|
121
|
+
if (!this.running) {
|
|
122
|
+
throw new Error('ProverClient is not running; call start() before constructing orchestrators.');
|
|
123
|
+
}
|
|
124
|
+
if (!this.deferredJobQueue) {
|
|
125
|
+
this.deferredJobQueue = new SerialQueue();
|
|
126
|
+
this.deferredJobQueue.start(this.config.enqueueConcurrency);
|
|
127
|
+
}
|
|
128
|
+
return this.deferredJobQueue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public createCheckpointSubTreeOrchestrator(
|
|
132
|
+
chonkCache: ChonkCache,
|
|
133
|
+
epochNumber: EpochNumber,
|
|
134
|
+
checkpointConstants: CheckpointConstantData,
|
|
135
|
+
l1ToL2Messages: Fr[],
|
|
136
|
+
totalNumBlocks: number,
|
|
137
|
+
headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
138
|
+
): Promise<CheckpointSubTreeOrchestrator> {
|
|
139
|
+
return CheckpointSubTreeOrchestrator.start(
|
|
140
|
+
this.worldState,
|
|
141
|
+
this.getFacade(),
|
|
142
|
+
this.config.proverId,
|
|
143
|
+
chonkCache,
|
|
144
|
+
epochNumber,
|
|
145
|
+
this.config.cancelJobsOnStop,
|
|
146
|
+
this.getDeferredJobQueue(),
|
|
147
|
+
checkpointConstants,
|
|
148
|
+
l1ToL2Messages,
|
|
149
|
+
totalNumBlocks,
|
|
150
|
+
headerOfLastBlockInPreviousCheckpoint,
|
|
151
|
+
this.telemetry,
|
|
152
|
+
this.log.getBindings(),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public createTopTreeOrchestrator(): TopTreeOrchestrator {
|
|
157
|
+
return new TopTreeOrchestrator(
|
|
158
|
+
this.getFacade(),
|
|
159
|
+
this.config.proverId,
|
|
160
|
+
this.getDeferredJobQueue(),
|
|
161
|
+
this.telemetry,
|
|
162
|
+
this.log.getBindings(),
|
|
163
|
+
);
|
|
50
164
|
}
|
|
51
165
|
|
|
52
166
|
public getProverId(): EthAddress {
|
|
@@ -88,6 +202,14 @@ export class ProverClient implements EpochProverManager {
|
|
|
88
202
|
}
|
|
89
203
|
this.running = false;
|
|
90
204
|
await this.stopAgents();
|
|
205
|
+
if (this.deferredJobQueue) {
|
|
206
|
+
await this.deferredJobQueue.cancel();
|
|
207
|
+
this.deferredJobQueue = undefined;
|
|
208
|
+
}
|
|
209
|
+
if (this.facade) {
|
|
210
|
+
await tryStop(this.facade, this.log);
|
|
211
|
+
this.facade = undefined;
|
|
212
|
+
}
|
|
91
213
|
await tryStop(this.orchestratorClient);
|
|
92
214
|
}
|
|
93
215
|
|
|
@@ -99,11 +221,13 @@ export class ProverClient implements EpochProverManager {
|
|
|
99
221
|
*/
|
|
100
222
|
public static async new(
|
|
101
223
|
config: ProverClientConfig,
|
|
102
|
-
worldState: ForkMerkleTreeOperations,
|
|
224
|
+
worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
|
|
103
225
|
broker: ProvingJobBroker,
|
|
104
226
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
105
227
|
) {
|
|
106
|
-
const
|
|
228
|
+
const proofStore = await createProofStore(config.proofStore);
|
|
229
|
+
const failedProofStore = config.failedProofStore ? await createProofStore(config.failedProofStore) : undefined;
|
|
230
|
+
const prover = new ProverClient(config, worldState, broker, proofStore, failedProofStore, broker, telemetry);
|
|
107
231
|
await prover.start();
|
|
108
232
|
return prover;
|
|
109
233
|
}
|
|
@@ -127,17 +251,11 @@ export class ProverClient implements EpochProverManager {
|
|
|
127
251
|
|
|
128
252
|
const proofStore = new InlineProofStore();
|
|
129
253
|
const prover = await buildServerCircuitProver(this.config, this.telemetry);
|
|
254
|
+
const bindings = this.log.getBindings();
|
|
130
255
|
this.agents = times(
|
|
131
256
|
this.config.proverAgentCount,
|
|
132
257
|
() =>
|
|
133
|
-
new ProvingAgent(
|
|
134
|
-
this.agentClient!,
|
|
135
|
-
proofStore,
|
|
136
|
-
prover,
|
|
137
|
-
[],
|
|
138
|
-
this.config.proverAgentPollIntervalMs,
|
|
139
|
-
this.telemetry,
|
|
140
|
-
),
|
|
258
|
+
new ProvingAgent(this.agentClient!, proofStore, prover, [], this.config.proverAgentPollIntervalMs, bindings),
|
|
141
259
|
);
|
|
142
260
|
|
|
143
261
|
await Promise.all(this.agents.map(agent => agent.start()));
|
|
@@ -149,15 +267,16 @@ export class ProverClient implements EpochProverManager {
|
|
|
149
267
|
}
|
|
150
268
|
|
|
151
269
|
export function buildServerCircuitProver(
|
|
152
|
-
config: ActualProverConfig & ACVMConfig & BBConfig,
|
|
270
|
+
config: Omit<ActualProverConfig, 'enqueueConcurrency'> & ACVMConfig & BBConfig,
|
|
153
271
|
telemetry: TelemetryClient,
|
|
154
272
|
): Promise<ServerCircuitProver> {
|
|
155
273
|
if (config.realProofs) {
|
|
156
274
|
return BBNativeRollupProver.new(config, telemetry);
|
|
157
275
|
}
|
|
158
276
|
|
|
277
|
+
const logger = createLogger('prover-client:acvm-native');
|
|
159
278
|
const simulator = config.acvmBinaryPath
|
|
160
|
-
? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath)
|
|
279
|
+
? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath, undefined, logger)
|
|
161
280
|
: undefined;
|
|
162
281
|
|
|
163
282
|
return Promise.resolve(new TestCircuitProver(simulator, config, telemetry));
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
AVM_V2_PROOF_LENGTH_IN_FIELDS,
|
|
3
3
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
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 {
|
|
10
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
9
|
+
import { chunk } from '@aztec/foundation/collection';
|
|
10
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
11
11
|
import { type PromiseWithResolvers, RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
12
12
|
import { truncate } from '@aztec/foundation/string';
|
|
13
13
|
import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
|
|
14
14
|
import {
|
|
15
|
-
type ProofAndVerificationKey,
|
|
16
15
|
type ProofUri,
|
|
17
16
|
type ProvingJobId,
|
|
18
17
|
type ProvingJobInputsMap,
|
|
@@ -24,7 +23,7 @@ import {
|
|
|
24
23
|
makeProvingJobId,
|
|
25
24
|
} from '@aztec/stdlib/interfaces/server';
|
|
26
25
|
import type { ParityBasePrivateInputs, ParityPublicInputs, ParityRootPrivateInputs } from '@aztec/stdlib/parity';
|
|
27
|
-
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
26
|
+
import { ProvingRequestType, RecursiveProof } from '@aztec/stdlib/proofs';
|
|
28
27
|
import type {
|
|
29
28
|
BlockMergeRollupPrivateInputs,
|
|
30
29
|
BlockRollupPublicInputs,
|
|
@@ -48,6 +47,8 @@ import type {
|
|
|
48
47
|
TxRollupPublicInputs,
|
|
49
48
|
} from '@aztec/stdlib/rollup';
|
|
50
49
|
|
|
50
|
+
import { createHash } from 'node:crypto';
|
|
51
|
+
|
|
51
52
|
import { InlineProofStore, type ProofStore } from './proof_store/index.js';
|
|
52
53
|
|
|
53
54
|
// Perform a snapshot sync every 30 seconds
|
|
@@ -70,14 +71,17 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
70
71
|
private runningPromise?: RunningPromise;
|
|
71
72
|
private timeOfLastSnapshotSync = Date.now();
|
|
72
73
|
private jobsToRetrieve: Set<ProvingJobId> = new Set();
|
|
74
|
+
private log: Logger;
|
|
73
75
|
|
|
74
76
|
constructor(
|
|
75
77
|
private broker: ProvingJobProducer,
|
|
76
78
|
private proofStore: ProofStore = new InlineProofStore(),
|
|
77
79
|
private failedProofStore?: ProofStore,
|
|
78
80
|
private pollIntervalMs = 1000,
|
|
79
|
-
|
|
80
|
-
) {
|
|
81
|
+
bindings?: LoggerBindings,
|
|
82
|
+
) {
|
|
83
|
+
this.log = createLogger('prover-client:broker-circuit-prover-facade', bindings);
|
|
84
|
+
}
|
|
81
85
|
|
|
82
86
|
/**
|
|
83
87
|
* This is a critical section. This function can not be async since it writes
|
|
@@ -224,17 +228,11 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
224
228
|
// We collect all returned notifications and return them
|
|
225
229
|
const allCompleted = new Set<ProvingJobId>();
|
|
226
230
|
try {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
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);
|
|
231
234
|
completed.forEach(id => allCompleted.add(id));
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
if (numRequests === 0) {
|
|
235
|
-
const final = await this.broker.getCompletedJobs([]);
|
|
236
|
-
final.forEach(id => allCompleted.add(id));
|
|
237
|
-
}
|
|
235
|
+
});
|
|
238
236
|
} catch (err) {
|
|
239
237
|
this.log.error(`Error thrown when requesting completed job notifications from the broker`, err);
|
|
240
238
|
}
|
|
@@ -350,12 +348,8 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
350
348
|
.map(id => this.jobs.get(id)!)
|
|
351
349
|
.filter(x => x !== undefined);
|
|
352
350
|
const totalJobsToRetrieve = toBeRetrieved.length;
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const slice = toBeRetrieved.splice(0, MAX_CONCURRENT_JOB_SETTLED_REQUESTS);
|
|
356
|
-
const results = await Promise.all(slice.map(job => processJob(job!)));
|
|
357
|
-
totalJobsRetrieved += results.filter(x => x).length;
|
|
358
|
-
}
|
|
351
|
+
const results = await asyncPool(MAX_CONCURRENT_JOB_SETTLED_REQUESTS, toBeRetrieved, job => processJob(job));
|
|
352
|
+
const totalJobsRetrieved = results.filter(x => x).length;
|
|
359
353
|
if (totalJobsToRetrieve > 0) {
|
|
360
354
|
this.log.verbose(
|
|
361
355
|
`Successfully retrieved ${totalJobsRetrieved} of ${totalJobsToRetrieve} jobs that should be ready, total ready jobs is now: ${this.jobsToRetrieve.size}`,
|
|
@@ -398,24 +392,16 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
398
392
|
|
|
399
393
|
getAvmProof(
|
|
400
394
|
inputs: AvmCircuitInputs,
|
|
401
|
-
skipPublicInputsValidation?: boolean, // TODO(#14234)[Unconditional PIs validation]: remove this argument
|
|
402
395
|
signal?: AbortSignal,
|
|
403
396
|
epochNumber?: EpochNumber,
|
|
404
|
-
): Promise<
|
|
405
|
-
this.log.info(`getAvmProof() called with skipPublicInputsValidation: ${skipPublicInputsValidation}`);
|
|
406
|
-
|
|
397
|
+
): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>> {
|
|
407
398
|
return this.enqueueJob(
|
|
408
399
|
this.generateId(ProvingRequestType.PUBLIC_VM, inputs, epochNumber),
|
|
409
400
|
ProvingRequestType.PUBLIC_VM,
|
|
410
401
|
inputs,
|
|
411
402
|
epochNumber,
|
|
412
403
|
signal,
|
|
413
|
-
)
|
|
414
|
-
// TODO(#14234)[Unconditional PIs validation]: Remove ".then()".
|
|
415
|
-
// Override the default value of skipPublicInputsValidation potentially set in BBNativeRollupProver.getAvmProof().
|
|
416
|
-
result.proof.proof[0] = skipPublicInputsValidation ? new Fr(1) : new Fr(0);
|
|
417
|
-
return result;
|
|
418
|
-
});
|
|
404
|
+
);
|
|
419
405
|
}
|
|
420
406
|
|
|
421
407
|
getBaseParityProof(
|
|
@@ -666,8 +652,12 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
666
652
|
);
|
|
667
653
|
}
|
|
668
654
|
|
|
669
|
-
private generateId(
|
|
670
|
-
|
|
671
|
-
|
|
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);
|
|
672
662
|
}
|
|
673
663
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum';
|
|
1
|
+
import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
|
|
2
2
|
import {
|
|
3
3
|
type ConfigMappingsType,
|
|
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']),
|
|
@@ -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
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { randomBytes } from '@aztec/foundation/crypto';
|
|
2
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
3
3
|
import { type ProofUri, type ProvingJobId, makeProvingJobId } from '@aztec/stdlib/interfaces/server';
|
|
4
4
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
5
5
|
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
|
|
2
|
+
import type { FileStore } from '@aztec/stdlib/file-store';
|
|
3
|
+
import {
|
|
4
|
+
type ProofUri,
|
|
5
|
+
type ProvingJobId,
|
|
6
|
+
type ProvingJobInputs,
|
|
7
|
+
type ProvingJobInputsMap,
|
|
8
|
+
ProvingJobResult,
|
|
9
|
+
type ProvingJobResultsMap,
|
|
10
|
+
getProvingJobInputClassFor,
|
|
11
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
12
|
+
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
13
|
+
|
|
14
|
+
import type { ProofStore } from './proof_store.js';
|
|
15
|
+
|
|
16
|
+
const INPUTS_PATH = 'inputs';
|
|
17
|
+
const OUTPUTS_PATH = 'outputs';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A proof store implementation backed by a generic FileStore.
|
|
21
|
+
* Supports any storage backend (GCS, S3, local filesystem) via the FileStore abstraction.
|
|
22
|
+
*/
|
|
23
|
+
export class FileStoreProofStore implements ProofStore {
|
|
24
|
+
constructor(private readonly fileStore: FileStore) {}
|
|
25
|
+
|
|
26
|
+
async saveProofInput<T extends ProvingRequestType>(
|
|
27
|
+
id: ProvingJobId,
|
|
28
|
+
type: T,
|
|
29
|
+
inputs: ProvingJobInputsMap[T],
|
|
30
|
+
): Promise<ProofUri> {
|
|
31
|
+
const path = `${INPUTS_PATH}/${ProvingRequestType[type]}/${id}`;
|
|
32
|
+
const uri = await this.fileStore.save(path, inputs.toBuffer());
|
|
33
|
+
return uri as ProofUri;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async saveProofOutput<T extends ProvingRequestType>(
|
|
37
|
+
id: ProvingJobId,
|
|
38
|
+
type: T,
|
|
39
|
+
result: ProvingJobResultsMap[T],
|
|
40
|
+
): Promise<ProofUri> {
|
|
41
|
+
const jobResult = { type, result } as ProvingJobResult;
|
|
42
|
+
const json = jsonStringify(jobResult);
|
|
43
|
+
const path = `${OUTPUTS_PATH}/${ProvingRequestType[type]}/${id}.json`;
|
|
44
|
+
const uri = await this.fileStore.save(path, Buffer.from(json, 'utf-8'));
|
|
45
|
+
return uri as ProofUri;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getProofInput(uri: ProofUri): Promise<ProvingJobInputs> {
|
|
49
|
+
try {
|
|
50
|
+
const buffer = await this.fileStore.read(uri);
|
|
51
|
+
const type = this.extractTypeFromUri(uri);
|
|
52
|
+
const inputs = getProvingJobInputClassFor(type).fromBuffer(buffer);
|
|
53
|
+
return { inputs, type } as ProvingJobInputs;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
throw new Error(`Error getting proof input at ${uri}: ${err}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getProofOutput(uri: ProofUri): Promise<ProvingJobResult> {
|
|
60
|
+
try {
|
|
61
|
+
const buffer = await this.fileStore.read(uri);
|
|
62
|
+
return jsonParseWithSchema(buffer.toString('utf-8'), ProvingJobResult);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
throw new Error(`Error getting proof output at ${uri}: ${err}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private extractTypeFromUri(uri: string): ProvingRequestType {
|
|
69
|
+
const url = new URL(uri);
|
|
70
|
+
const pathParts = url.pathname.split('/').filter(Boolean);
|
|
71
|
+
const typeString = pathParts.at(-2);
|
|
72
|
+
const type = typeString ? ProvingRequestType[typeString as keyof typeof ProvingRequestType] : undefined;
|
|
73
|
+
if (type === undefined) {
|
|
74
|
+
throw new Error(`Unrecognized proof type ${typeString} in URI ${uri}`);
|
|
75
|
+
}
|
|
76
|
+
return type;
|
|
77
|
+
}
|
|
78
|
+
}
|