@aztec/prover-client 0.0.1-commit.d3ec352c → 0.0.1-commit.f295ac2
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 +1 -1
- 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 +29 -14
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +108 -21
- package/dest/mocks/fixtures.js +2 -2
- package/dest/mocks/test_context.d.ts +5 -3
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +21 -8
- package/dest/orchestrator/block-building-helpers.d.ts +3 -3
- 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 +2 -2
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +1 -1
- package/dest/orchestrator/checkpoint-proving-state.d.ts +16 -3
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +36 -2
- package/dest/orchestrator/epoch-proving-state.d.ts +5 -4
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +35 -1
- package/dest/orchestrator/orchestrator.d.ts +14 -4
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +449 -64
- 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/tx-proving-state.d.ts +6 -5
- 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 +3 -3
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +1 -1
- package/dest/prover-client/server-epoch-prover.d.ts +2 -2
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.d.ts +4 -3
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +3 -10
- package/dest/proving_broker/config.d.ts +2 -2
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +1 -1
- package/dest/proving_broker/fixtures.js +1 -1
- package/dest/proving_broker/proving_agent.d.ts +3 -8
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +1 -16
- package/dest/proving_broker/proving_broker.d.ts +1 -1
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +4 -10
- 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 +389 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +11 -35
- package/dest/proving_broker/proving_job_controller.d.ts +1 -1
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +2 -3
- 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 +2 -2
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +4 -4
- package/package.json +18 -17
- package/src/config.ts +1 -1
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +158 -27
- package/src/mocks/fixtures.ts +2 -2
- package/src/mocks/test_context.ts +18 -6
- package/src/orchestrator/block-building-helpers.ts +2 -2
- package/src/orchestrator/block-proving-state.ts +1 -1
- package/src/orchestrator/checkpoint-proving-state.ts +49 -2
- package/src/orchestrator/epoch-proving-state.ts +56 -8
- package/src/orchestrator/orchestrator.ts +45 -43
- package/src/orchestrator/orchestrator_metrics.ts +2 -25
- package/src/orchestrator/tx-proving-state.ts +10 -14
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +4 -11
- package/src/prover-client/server-epoch-prover.ts +1 -1
- package/src/proving_broker/broker_prover_facade.ts +4 -14
- package/src/proving_broker/config.ts +1 -1
- package/src/proving_broker/fixtures.ts +1 -1
- package/src/proving_broker/proving_agent.ts +1 -17
- package/src/proving_broker/proving_broker.ts +4 -8
- package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +10 -35
- package/src/proving_broker/proving_job_controller.ts +2 -3
- package/src/test/mock_prover.ts +2 -14
- 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/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/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { BatchedBlob, BatchedBlobAccumulator, type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
|
|
2
|
-
import
|
|
3
|
-
ARCHIVE_HEIGHT,
|
|
4
|
-
L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
|
-
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
6
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
2
|
+
import {
|
|
3
|
+
type ARCHIVE_HEIGHT,
|
|
4
|
+
type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
|
+
type NESTED_RECURSIVE_PROOF_LENGTH,
|
|
6
|
+
type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
7
|
+
OUT_HASH_TREE_HEIGHT,
|
|
7
8
|
} from '@aztec/constants';
|
|
8
9
|
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
9
|
-
import
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
11
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
11
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
MerkleTreeCalculator,
|
|
14
|
+
type TreeNodeLocation,
|
|
15
|
+
UnbalancedTreeStore,
|
|
16
|
+
shaMerkleHash,
|
|
17
|
+
} from '@aztec/foundation/trees';
|
|
12
18
|
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
13
19
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
14
20
|
import {
|
|
@@ -20,7 +26,7 @@ import {
|
|
|
20
26
|
RootRollupPrivateInputs,
|
|
21
27
|
type RootRollupPublicInputs,
|
|
22
28
|
} from '@aztec/stdlib/rollup';
|
|
23
|
-
import
|
|
29
|
+
import { AppendOnlyTreeSnapshot, type MerkleTreeId } from '@aztec/stdlib/trees';
|
|
24
30
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
25
31
|
|
|
26
32
|
import { toProofData } from './block-building-helpers.js';
|
|
@@ -212,6 +218,48 @@ export class EpochProvingState {
|
|
|
212
218
|
this.checkpointPaddingProof = { provingOutput };
|
|
213
219
|
}
|
|
214
220
|
|
|
221
|
+
public async accumulateCheckpointOutHashes() {
|
|
222
|
+
const treeCalculator = await MerkleTreeCalculator.create(OUT_HASH_TREE_HEIGHT, undefined, (left, right) =>
|
|
223
|
+
Promise.resolve(shaMerkleHash(left, right)),
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const computeOutHashHint = async (leaves: Fr[]) => {
|
|
227
|
+
const tree = await treeCalculator.computeTree(leaves.map(l => l.toBuffer()));
|
|
228
|
+
const nextAvailableLeafIndex = leaves.length;
|
|
229
|
+
return {
|
|
230
|
+
treeSnapshot: new AppendOnlyTreeSnapshot(Fr.fromBuffer(tree.root), nextAvailableLeafIndex),
|
|
231
|
+
siblingPath: tree.getSiblingPath(nextAvailableLeafIndex).map(Fr.fromBuffer) as Tuple<
|
|
232
|
+
Fr,
|
|
233
|
+
typeof OUT_HASH_TREE_HEIGHT
|
|
234
|
+
>,
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
let hint = this.checkpoints[0]?.getOutHashHint();
|
|
239
|
+
const outHashes = [];
|
|
240
|
+
for (let i = 0; i < this.totalNumCheckpoints; i++) {
|
|
241
|
+
const checkpoint = this.checkpoints[i];
|
|
242
|
+
if (!checkpoint) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// If hints are not set yet, it must be the first checkpoint. Compute the hints with an empty tree.
|
|
247
|
+
hint ??= await computeOutHashHint([]);
|
|
248
|
+
checkpoint.setOutHashHint(hint);
|
|
249
|
+
|
|
250
|
+
// Get the out hash for this checkpoint.
|
|
251
|
+
const outHash = checkpoint.accumulateBlockOutHashes();
|
|
252
|
+
if (!outHash) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
outHashes.push(outHash);
|
|
256
|
+
|
|
257
|
+
// Get or create hints for the next checkpoint.
|
|
258
|
+
hint = checkpoint.getOutHashHintForNextCheckpoint() ?? (await computeOutHashHint(outHashes));
|
|
259
|
+
checkpoint.setOutHashHintForNextCheckpoint(hint);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
215
263
|
public async setBlobAccumulators() {
|
|
216
264
|
let previousAccumulator = this.startBlobAccumulator;
|
|
217
265
|
// Accumulate blobs as far as we can for this epoch.
|
|
@@ -8,21 +8,21 @@ import {
|
|
|
8
8
|
} from '@aztec/constants';
|
|
9
9
|
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
10
10
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
11
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
12
|
import { AbortError } from '@aztec/foundation/error';
|
|
12
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
13
13
|
import { createLogger } from '@aztec/foundation/log';
|
|
14
14
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
15
15
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
16
16
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
17
17
|
import { elapsed } from '@aztec/foundation/timer';
|
|
18
18
|
import type { TreeNodeLocation } from '@aztec/foundation/trees';
|
|
19
|
-
import { readAvmMinimalPublicTxInputsFromFile } from '@aztec/simulator/public/fixtures';
|
|
20
19
|
import { EthAddress } from '@aztec/stdlib/block';
|
|
21
20
|
import type {
|
|
22
21
|
EpochProver,
|
|
23
22
|
ForkMerkleTreeOperations,
|
|
24
23
|
MerkleTreeWriteOperations,
|
|
25
24
|
PublicInputsAndRecursiveProof,
|
|
25
|
+
ReadonlyWorldStateAccess,
|
|
26
26
|
ServerCircuitProver,
|
|
27
27
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
28
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
@@ -97,7 +97,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
97
97
|
private dbs: Map<BlockNumber, MerkleTreeWriteOperations> = new Map();
|
|
98
98
|
|
|
99
99
|
constructor(
|
|
100
|
-
private dbProvider: ForkMerkleTreeOperations,
|
|
100
|
+
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
101
101
|
private prover: ServerCircuitProver,
|
|
102
102
|
private readonly proverId: EthAddress,
|
|
103
103
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
@@ -113,6 +113,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
113
113
|
return this.proverId;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
public getNumActiveForks() {
|
|
117
|
+
return this.dbs.size;
|
|
118
|
+
}
|
|
119
|
+
|
|
116
120
|
public stop(): Promise<void> {
|
|
117
121
|
this.cancel();
|
|
118
122
|
return Promise.resolve();
|
|
@@ -143,6 +147,14 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
143
147
|
this.provingPromise = promise;
|
|
144
148
|
}
|
|
145
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Starts a new checkpoint.
|
|
152
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
153
|
+
* @param constants - The constants for this checkpoint.
|
|
154
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
155
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
156
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
157
|
+
*/
|
|
146
158
|
public async startNewCheckpoint(
|
|
147
159
|
checkpointIndex: number,
|
|
148
160
|
constants: CheckpointConstantData,
|
|
@@ -255,7 +267,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
255
267
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
256
268
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
257
269
|
|
|
258
|
-
//
|
|
270
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
271
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
259
272
|
await this.provingState.setBlobAccumulators();
|
|
260
273
|
}
|
|
261
274
|
}
|
|
@@ -310,7 +323,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
310
323
|
|
|
311
324
|
validateTx(tx);
|
|
312
325
|
|
|
313
|
-
logger.
|
|
326
|
+
logger.debug(`Received transaction: ${tx.hash}`);
|
|
314
327
|
|
|
315
328
|
const startSpongeBlob = spongeBlobState.clone();
|
|
316
329
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(
|
|
@@ -352,7 +365,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
352
365
|
|
|
353
366
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
354
367
|
|
|
355
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
368
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
369
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
356
370
|
await this.provingState.setBlobAccumulators();
|
|
357
371
|
}
|
|
358
372
|
|
|
@@ -486,12 +500,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
486
500
|
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
487
501
|
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
488
502
|
// will attempt to access the fork after it was closed.
|
|
489
|
-
|
|
490
|
-
void this.dbs
|
|
491
|
-
.get(blockNumber)
|
|
492
|
-
?.close()
|
|
493
|
-
.then(() => this.dbs.delete(blockNumber))
|
|
494
|
-
.catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
503
|
+
void this.cleanupDBFork(blockNumber);
|
|
495
504
|
}
|
|
496
505
|
|
|
497
506
|
/**
|
|
@@ -534,6 +543,21 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
534
543
|
return epochProofResult;
|
|
535
544
|
}
|
|
536
545
|
|
|
546
|
+
private async cleanupDBFork(blockNumber: BlockNumber): Promise<void> {
|
|
547
|
+
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
548
|
+
const fork = this.dbs.get(blockNumber);
|
|
549
|
+
if (!fork) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
try {
|
|
554
|
+
await fork.close();
|
|
555
|
+
this.dbs.delete(blockNumber);
|
|
556
|
+
} catch (err) {
|
|
557
|
+
logger.error(`Error closing db for block ${blockNumber}`, err);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
537
561
|
/**
|
|
538
562
|
* Enqueue a job to be scheduled
|
|
539
563
|
* @param provingState - The proving state object being operated on
|
|
@@ -851,19 +875,22 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
851
875
|
},
|
|
852
876
|
),
|
|
853
877
|
async result => {
|
|
854
|
-
// If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
|
|
855
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
856
|
-
|
|
857
878
|
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
858
879
|
|
|
859
880
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
860
881
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
861
882
|
|
|
883
|
+
// If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
|
|
884
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
885
|
+
|
|
862
886
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
863
887
|
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
864
888
|
} else {
|
|
865
889
|
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
866
890
|
}
|
|
891
|
+
|
|
892
|
+
// We are finished with the block at this point, ensure the fork is cleaned up
|
|
893
|
+
void this.cleanupDBFork(provingState.blockNumber);
|
|
867
894
|
},
|
|
868
895
|
);
|
|
869
896
|
}
|
|
@@ -1207,8 +1234,6 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1207
1234
|
|
|
1208
1235
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1209
1236
|
|
|
1210
|
-
// This function tries to do AVM proving. If there is a failure, it fakes the proof unless AVM_PROVING_STRICT is defined.
|
|
1211
|
-
// Nothing downstream depends on the AVM proof yet. So having this mode lets us incrementally build the AVM circuit.
|
|
1212
1237
|
const doAvmProving = wrapCallbackInSpan(
|
|
1213
1238
|
this.tracer,
|
|
1214
1239
|
'ProvingOrchestrator.prover.getAvmProof',
|
|
@@ -1217,36 +1242,13 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1217
1242
|
},
|
|
1218
1243
|
async (signal: AbortSignal) => {
|
|
1219
1244
|
const inputs = txProvingState.getAvmInputs();
|
|
1220
|
-
|
|
1221
|
-
// TODO(#14234)[Unconditional PIs validation]: Remove the whole try-catch logic and
|
|
1222
|
-
// just keep the next line but removing the second argument (false).
|
|
1223
|
-
return await this.prover.getAvmProof(inputs, false, signal, provingState.epochNumber);
|
|
1224
|
-
} catch (err) {
|
|
1225
|
-
if (process.env.AVM_PROVING_STRICT) {
|
|
1226
|
-
logger.error(`Error thrown when proving AVM circuit with AVM_PROVING_STRICT on`, err);
|
|
1227
|
-
throw err;
|
|
1228
|
-
} else {
|
|
1229
|
-
logger.warn(
|
|
1230
|
-
`Error thrown when proving AVM circuit but AVM_PROVING_STRICT is off. Use snapshotted
|
|
1231
|
-
AVM inputs and carrying on. ${inspect(err)}.`,
|
|
1232
|
-
);
|
|
1233
|
-
|
|
1234
|
-
try {
|
|
1235
|
-
this.metrics.incAvmFallback();
|
|
1236
|
-
const snapshotAvmPrivateInputs = readAvmMinimalPublicTxInputsFromFile();
|
|
1237
|
-
return await this.prover.getAvmProof(snapshotAvmPrivateInputs, true, signal, provingState.epochNumber);
|
|
1238
|
-
} catch (err) {
|
|
1239
|
-
logger.error(`Error thrown when proving snapshotted AVM inputs.`, err);
|
|
1240
|
-
throw err;
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1245
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1244
1246
|
},
|
|
1245
1247
|
);
|
|
1246
1248
|
|
|
1247
|
-
this.deferredProving(provingState, doAvmProving,
|
|
1249
|
+
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1248
1250
|
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1249
|
-
txProvingState.setAvmProof(
|
|
1251
|
+
txProvingState.setAvmProof(proof);
|
|
1250
1252
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1251
1253
|
});
|
|
1252
1254
|
}
|
|
@@ -1,41 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Histogram,
|
|
3
|
-
Metrics,
|
|
4
|
-
type TelemetryClient,
|
|
5
|
-
type Tracer,
|
|
6
|
-
type UpDownCounter,
|
|
7
|
-
ValueType,
|
|
8
|
-
} from '@aztec/telemetry-client';
|
|
1
|
+
import { type Histogram, Metrics, type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
|
|
9
2
|
|
|
10
3
|
export class ProvingOrchestratorMetrics {
|
|
11
4
|
public readonly tracer: Tracer;
|
|
12
5
|
|
|
13
6
|
private baseRollupInputsDuration: Histogram;
|
|
14
|
-
private avmFallbackCount: UpDownCounter;
|
|
15
7
|
|
|
16
8
|
constructor(client: TelemetryClient, name = 'ProvingOrchestrator') {
|
|
17
9
|
this.tracer = client.getTracer(name);
|
|
18
10
|
const meter = client.getMeter(name);
|
|
19
11
|
|
|
20
|
-
this.baseRollupInputsDuration = meter.createHistogram(Metrics.PROVING_ORCHESTRATOR_BASE_ROLLUP_INPUTS_DURATION
|
|
21
|
-
unit: 'ms',
|
|
22
|
-
description: 'Duration to build base rollup inputs',
|
|
23
|
-
valueType: ValueType.INT,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
this.avmFallbackCount = meter.createUpDownCounter(Metrics.PROVING_ORCHESTRATOR_AVM_FALLBACK_COUNT, {
|
|
27
|
-
description: 'How many times the AVM fallback was used',
|
|
28
|
-
valueType: ValueType.INT,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
this.avmFallbackCount.add(0);
|
|
12
|
+
this.baseRollupInputsDuration = meter.createHistogram(Metrics.PROVING_ORCHESTRATOR_BASE_ROLLUP_INPUTS_DURATION);
|
|
32
13
|
}
|
|
33
14
|
|
|
34
15
|
recordBaseRollupInputs(durationMs: number) {
|
|
35
16
|
this.baseRollupInputsDuration.record(Math.ceil(durationMs));
|
|
36
17
|
}
|
|
37
|
-
|
|
38
|
-
incAvmFallback() {
|
|
39
|
-
this.avmFallbackCount.add(1);
|
|
40
|
-
}
|
|
41
18
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
|
|
2
|
-
import type { Fr } from '@aztec/foundation/
|
|
3
|
-
import {
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { getVkData } from '@aztec/noir-protocol-circuits-types/server/vks';
|
|
4
4
|
import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
|
|
5
|
-
import type {
|
|
6
|
-
import { ProofData } from '@aztec/stdlib/proofs';
|
|
5
|
+
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import { ProofData, ProofDataForFixedVk, RecursiveProof } from '@aztec/stdlib/proofs';
|
|
7
7
|
import {
|
|
8
8
|
type BaseRollupHints,
|
|
9
9
|
PrivateBaseRollupHints,
|
|
@@ -32,7 +32,7 @@ export class TxProvingState {
|
|
|
32
32
|
PublicChonkVerifierPublicInputs,
|
|
33
33
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
34
34
|
>;
|
|
35
|
-
private
|
|
35
|
+
private avmProof?: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>;
|
|
36
36
|
|
|
37
37
|
constructor(
|
|
38
38
|
public readonly processedTx: ProcessedTx,
|
|
@@ -46,7 +46,7 @@ export class TxProvingState {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
public ready() {
|
|
49
|
-
return !this.requireAvmProof || (!!this.
|
|
49
|
+
return !this.requireAvmProof || (!!this.avmProof && !!this.publicChonkVerifier);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
public getAvmInputs(): AvmCircuitInputs {
|
|
@@ -80,8 +80,8 @@ export class TxProvingState {
|
|
|
80
80
|
this.publicChonkVerifier = publicChonkVerifierProofAndVk;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
public setAvmProof(
|
|
84
|
-
this.
|
|
83
|
+
public setAvmProof(avmProof: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>) {
|
|
84
|
+
this.avmProof = avmProof;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
#getPrivateBaseInputs() {
|
|
@@ -105,7 +105,7 @@ export class TxProvingState {
|
|
|
105
105
|
if (!this.publicChonkVerifier) {
|
|
106
106
|
throw new Error('Tx not ready for proving base rollup: public chonk verifier proof undefined');
|
|
107
107
|
}
|
|
108
|
-
if (!this.
|
|
108
|
+
if (!this.avmProof) {
|
|
109
109
|
throw new Error('Tx not ready for proving base rollup: avm proof undefined');
|
|
110
110
|
}
|
|
111
111
|
if (!(this.baseRollupHints instanceof PublicBaseRollupHints)) {
|
|
@@ -114,11 +114,7 @@ export class TxProvingState {
|
|
|
114
114
|
|
|
115
115
|
const publicChonkVerifierProofData = toProofData(this.publicChonkVerifier);
|
|
116
116
|
|
|
117
|
-
const avmProofData = new
|
|
118
|
-
this.processedTx.avmProvingRequest.inputs.publicInputs,
|
|
119
|
-
this.avm.proof,
|
|
120
|
-
getAvmVkData(),
|
|
121
|
-
);
|
|
117
|
+
const avmProofData = new ProofDataForFixedVk(this.processedTx.avmProvingRequest.inputs.publicInputs, this.avmProof);
|
|
122
118
|
|
|
123
119
|
return new PublicTxBaseRollupPrivateInputs(publicChonkVerifierProofData, avmProofData, this.baseRollupHints);
|
|
124
120
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ForkMerkleTreeOperations,
|
|
3
|
+
ProvingJobBroker,
|
|
4
|
+
ReadonlyWorldStateAccess,
|
|
5
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
2
6
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
3
7
|
|
|
4
8
|
import type { ProverClientConfig } from '../config.js';
|
|
@@ -6,7 +10,7 @@ import { ProverClient } from './prover-client.js';
|
|
|
6
10
|
|
|
7
11
|
export function createProverClient(
|
|
8
12
|
config: ProverClientConfig,
|
|
9
|
-
worldState: ForkMerkleTreeOperations,
|
|
13
|
+
worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
|
|
10
14
|
broker: ProvingJobBroker,
|
|
11
15
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
12
16
|
) {
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type ProvingJobBroker,
|
|
12
12
|
type ProvingJobConsumer,
|
|
13
13
|
type ProvingJobProducer,
|
|
14
|
+
type ReadonlyWorldStateAccess,
|
|
14
15
|
type ServerCircuitProver,
|
|
15
16
|
tryStop,
|
|
16
17
|
} from '@aztec/stdlib/interfaces/server';
|
|
@@ -33,7 +34,7 @@ export class ProverClient implements EpochProverManager {
|
|
|
33
34
|
|
|
34
35
|
private constructor(
|
|
35
36
|
private config: ProverClientConfig,
|
|
36
|
-
private worldState: ForkMerkleTreeOperations,
|
|
37
|
+
private worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
|
|
37
38
|
private orchestratorClient: ProvingJobProducer,
|
|
38
39
|
private agentClient?: ProvingJobConsumer,
|
|
39
40
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
@@ -99,7 +100,7 @@ export class ProverClient implements EpochProverManager {
|
|
|
99
100
|
*/
|
|
100
101
|
public static async new(
|
|
101
102
|
config: ProverClientConfig,
|
|
102
|
-
worldState: ForkMerkleTreeOperations,
|
|
103
|
+
worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
|
|
103
104
|
broker: ProvingJobBroker,
|
|
104
105
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
105
106
|
) {
|
|
@@ -129,15 +130,7 @@ export class ProverClient implements EpochProverManager {
|
|
|
129
130
|
const prover = await buildServerCircuitProver(this.config, this.telemetry);
|
|
130
131
|
this.agents = times(
|
|
131
132
|
this.config.proverAgentCount,
|
|
132
|
-
() =>
|
|
133
|
-
new ProvingAgent(
|
|
134
|
-
this.agentClient!,
|
|
135
|
-
proofStore,
|
|
136
|
-
prover,
|
|
137
|
-
[],
|
|
138
|
-
this.config.proverAgentPollIntervalMs,
|
|
139
|
-
this.telemetry,
|
|
140
|
-
),
|
|
133
|
+
() => new ProvingAgent(this.agentClient!, proofStore, prover, [], this.config.proverAgentPollIntervalMs),
|
|
141
134
|
);
|
|
142
135
|
|
|
143
136
|
await Promise.all(this.agents.map(agent => agent.start()));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BatchedBlob, FinalBlobBatchingChallenges } from '@aztec/blob-lib/types';
|
|
2
2
|
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import type { Fr } from '@aztec/foundation/
|
|
3
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import type { EthAddress } from '@aztec/stdlib/block';
|
|
5
5
|
import type { EpochProver } from '@aztec/stdlib/interfaces/server';
|
|
6
6
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
@@ -5,14 +5,12 @@ import type {
|
|
|
5
5
|
RECURSIVE_PROOF_LENGTH,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
7
|
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
8
|
-
import { sha256 } from '@aztec/foundation/crypto';
|
|
9
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
8
|
+
import { sha256 } from '@aztec/foundation/crypto/sha256';
|
|
10
9
|
import { createLogger } from '@aztec/foundation/log';
|
|
11
10
|
import { type PromiseWithResolvers, RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
12
11
|
import { truncate } from '@aztec/foundation/string';
|
|
13
12
|
import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
|
|
14
13
|
import {
|
|
15
|
-
type ProofAndVerificationKey,
|
|
16
14
|
type ProofUri,
|
|
17
15
|
type ProvingJobId,
|
|
18
16
|
type ProvingJobInputsMap,
|
|
@@ -24,7 +22,7 @@ import {
|
|
|
24
22
|
makeProvingJobId,
|
|
25
23
|
} from '@aztec/stdlib/interfaces/server';
|
|
26
24
|
import type { ParityBasePrivateInputs, ParityPublicInputs, ParityRootPrivateInputs } from '@aztec/stdlib/parity';
|
|
27
|
-
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
25
|
+
import { ProvingRequestType, RecursiveProof } from '@aztec/stdlib/proofs';
|
|
28
26
|
import type {
|
|
29
27
|
BlockMergeRollupPrivateInputs,
|
|
30
28
|
BlockRollupPublicInputs,
|
|
@@ -398,24 +396,16 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
398
396
|
|
|
399
397
|
getAvmProof(
|
|
400
398
|
inputs: AvmCircuitInputs,
|
|
401
|
-
skipPublicInputsValidation?: boolean, // TODO(#14234)[Unconditional PIs validation]: remove this argument
|
|
402
399
|
signal?: AbortSignal,
|
|
403
400
|
epochNumber?: EpochNumber,
|
|
404
|
-
): Promise<
|
|
405
|
-
this.log.info(`getAvmProof() called with skipPublicInputsValidation: ${skipPublicInputsValidation}`);
|
|
406
|
-
|
|
401
|
+
): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
|
|
407
402
|
return this.enqueueJob(
|
|
408
403
|
this.generateId(ProvingRequestType.PUBLIC_VM, inputs, epochNumber),
|
|
409
404
|
ProvingRequestType.PUBLIC_VM,
|
|
410
405
|
inputs,
|
|
411
406
|
epochNumber,
|
|
412
407
|
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
|
-
});
|
|
408
|
+
);
|
|
419
409
|
}
|
|
420
410
|
|
|
421
411
|
getBaseParityProof(
|
|
@@ -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
|
|
|
@@ -13,27 +13,16 @@ import type {
|
|
|
13
13
|
ServerCircuitProver,
|
|
14
14
|
} from '@aztec/stdlib/interfaces/server';
|
|
15
15
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
16
|
-
import {
|
|
17
|
-
type TelemetryClient,
|
|
18
|
-
type Traceable,
|
|
19
|
-
type Tracer,
|
|
20
|
-
getTelemetryClient,
|
|
21
|
-
trackSpan,
|
|
22
|
-
} from '@aztec/telemetry-client';
|
|
23
16
|
|
|
24
17
|
import type { ProofStore } from './proof_store/index.js';
|
|
25
|
-
import { ProvingAgentInstrumentation } from './proving_agent_instrumentation.js';
|
|
26
18
|
import { ProvingJobController, ProvingJobControllerStatus } from './proving_job_controller.js';
|
|
27
19
|
|
|
28
20
|
/**
|
|
29
21
|
* A helper class that encapsulates a circuit prover and connects it to a job source.
|
|
30
22
|
*/
|
|
31
|
-
export class ProvingAgent
|
|
23
|
+
export class ProvingAgent {
|
|
32
24
|
private currentJobController?: ProvingJobController;
|
|
33
25
|
private runningPromise: RunningPromise;
|
|
34
|
-
private instrumentation: ProvingAgentInstrumentation;
|
|
35
|
-
|
|
36
|
-
public readonly tracer: Tracer;
|
|
37
26
|
|
|
38
27
|
constructor(
|
|
39
28
|
/** The source of proving jobs */
|
|
@@ -46,12 +35,8 @@ export class ProvingAgent implements Traceable {
|
|
|
46
35
|
private proofAllowList: Array<ProvingRequestType> = [],
|
|
47
36
|
/** How long to wait between jobs */
|
|
48
37
|
private pollIntervalMs = 1000,
|
|
49
|
-
/** A telemetry client through which to emit metrics */
|
|
50
|
-
client: TelemetryClient = getTelemetryClient(),
|
|
51
38
|
private log = createLogger('prover-client:proving-agent'),
|
|
52
39
|
) {
|
|
53
|
-
this.tracer = client.getTracer('ProvingAgent');
|
|
54
|
-
this.instrumentation = new ProvingAgentInstrumentation(client);
|
|
55
40
|
this.runningPromise = new RunningPromise(this.work.bind(this), this.log, this.pollIntervalMs);
|
|
56
41
|
}
|
|
57
42
|
|
|
@@ -85,7 +70,6 @@ export class ProvingAgent implements Traceable {
|
|
|
85
70
|
return this.runningPromise.isRunning() ? { status: 'running' } : { status: 'stopped' };
|
|
86
71
|
}
|
|
87
72
|
|
|
88
|
-
@trackSpan('ProvingAgent.safeWork')
|
|
89
73
|
private async work() {
|
|
90
74
|
// every tick we need to take one of the following actions:
|
|
91
75
|
// 1. send a hearbeat to the broker that we're working on some job
|
|
@@ -16,13 +16,7 @@ import {
|
|
|
16
16
|
tryStop,
|
|
17
17
|
} from '@aztec/stdlib/interfaces/server';
|
|
18
18
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
19
|
-
import {
|
|
20
|
-
type TelemetryClient,
|
|
21
|
-
type Traceable,
|
|
22
|
-
type Tracer,
|
|
23
|
-
getTelemetryClient,
|
|
24
|
-
trackSpan,
|
|
25
|
-
} from '@aztec/telemetry-client';
|
|
19
|
+
import { type TelemetryClient, type Traceable, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
26
20
|
|
|
27
21
|
import assert from 'assert';
|
|
28
22
|
|
|
@@ -302,6 +296,7 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
302
296
|
this.resultsCache.delete(id);
|
|
303
297
|
this.inProgress.delete(id);
|
|
304
298
|
this.retries.delete(id);
|
|
299
|
+
this.enqueuedAt.delete(id);
|
|
305
300
|
}
|
|
306
301
|
}
|
|
307
302
|
|
|
@@ -354,6 +349,8 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
354
349
|
const enqueuedAt = this.enqueuedAt.get(job.id);
|
|
355
350
|
if (enqueuedAt) {
|
|
356
351
|
this.instrumentation.recordJobWait(job.type, enqueuedAt);
|
|
352
|
+
// we can clear this flag now.
|
|
353
|
+
this.enqueuedAt.delete(job.id);
|
|
357
354
|
}
|
|
358
355
|
|
|
359
356
|
return { job, time };
|
|
@@ -562,7 +559,6 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
|
|
|
562
559
|
return this.#getProvingJob(filter);
|
|
563
560
|
}
|
|
564
561
|
|
|
565
|
-
@trackSpan('ProvingBroker.cleanupPass')
|
|
566
562
|
private async cleanupPass() {
|
|
567
563
|
this.cleanupStaleJobs();
|
|
568
564
|
this.reEnqueueExpiredJobs();
|
|
@@ -11,7 +11,14 @@ import {
|
|
|
11
11
|
ProvingJobSettledResult,
|
|
12
12
|
getEpochFromProvingJobId,
|
|
13
13
|
} from '@aztec/stdlib/interfaces/server';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
Attributes,
|
|
16
|
+
LmdbMetrics,
|
|
17
|
+
type TelemetryClient,
|
|
18
|
+
type Tracer,
|
|
19
|
+
getTelemetryClient,
|
|
20
|
+
trackSpan,
|
|
21
|
+
} from '@aztec/telemetry-client';
|
|
15
22
|
|
|
16
23
|
import { mkdir, readdir } from 'fs/promises';
|
|
17
24
|
import { join } from 'path';
|
|
@@ -78,6 +85,8 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
78
85
|
|
|
79
86
|
private batchQueue: BatchQueue<ProvingJob | [ProvingJobId, ProvingJobSettledResult], number>;
|
|
80
87
|
|
|
88
|
+
public readonly tracer: Tracer;
|
|
89
|
+
|
|
81
90
|
private constructor(
|
|
82
91
|
private epochs: Map<number, SingleEpochDatabase>,
|
|
83
92
|
private config: ProverBrokerConfig,
|
|
@@ -92,6 +101,8 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
92
101
|
() => this.estimateSize(),
|
|
93
102
|
);
|
|
94
103
|
|
|
104
|
+
this.tracer = client.getTracer('KVBrokerDatabase');
|
|
105
|
+
|
|
95
106
|
this.batchQueue = new BatchQueue(
|
|
96
107
|
(items, key) => this.commitWrites(items, key),
|
|
97
108
|
config.proverBrokerBatchSize,
|
|
@@ -165,6 +176,9 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
|
|
|
165
176
|
}
|
|
166
177
|
}
|
|
167
178
|
|
|
179
|
+
@trackSpan('KVBrokerDatabase.deleteAllProvingJobsOlderThanEpoch', epochNumber => ({
|
|
180
|
+
[Attributes.EPOCH_NUMBER]: epochNumber,
|
|
181
|
+
}))
|
|
168
182
|
async deleteAllProvingJobsOlderThanEpoch(epochNumber: EpochNumber): Promise<void> {
|
|
169
183
|
const oldEpochs = Array.from(this.epochs.keys()).filter(e => e < Number(epochNumber));
|
|
170
184
|
for (const old of oldEpochs) {
|