@aztec/prover-client 3.0.3 → 3.9.9-nightly.20260312
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/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 +34 -14
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +124 -27
- package/dest/mocks/fixtures.d.ts +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +2 -1
- package/dest/mocks/test_context.d.ts +4 -2
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +22 -5
- package/dest/orchestrator/block-building-helpers.d.ts +5 -5
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +4 -4
- package/dest/orchestrator/block-proving-state.d.ts +4 -1
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +7 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts +17 -4
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +37 -4
- package/dest/orchestrator/epoch-proving-state.d.ts +7 -6
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +37 -1
- package/dest/orchestrator/orchestrator.d.ts +21 -4
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +559 -154
- 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 +5 -4
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +6 -6
- 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 +6 -6
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +15 -10
- package/dest/proving_broker/broker_prover_facade.d.ts +7 -5
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +8 -15
- package/dest/proving_broker/config.d.ts +13 -1
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +19 -2
- 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 +7 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +40 -14
- 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 +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 +7 -5
- package/dest/proving_broker/rpc.d.ts +4 -2
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +8 -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 +17 -18
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +188 -34
- package/src/mocks/fixtures.ts +2 -1
- package/src/mocks/test_context.ts +17 -4
- package/src/orchestrator/block-building-helpers.ts +4 -4
- package/src/orchestrator/block-proving-state.ts +9 -0
- package/src/orchestrator/checkpoint-proving-state.ts +51 -5
- package/src/orchestrator/epoch-proving-state.ts +59 -9
- package/src/orchestrator/orchestrator.ts +160 -138
- package/src/orchestrator/orchestrator_metrics.ts +2 -25
- package/src/orchestrator/tx-proving-state.ts +8 -11
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +33 -24
- package/src/proving_broker/broker_prover_facade.ts +18 -20
- package/src/proving_broker/config.ts +22 -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 +41 -11
- package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
- package/src/proving_broker/proving_job_controller.ts +10 -5
- package/src/proving_broker/rpc.ts +14 -0
- 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/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/proving_broker/proof_store/gcs_proof_store.ts +0 -76
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -10,19 +10,20 @@ import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
|
10
10
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
11
11
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
12
|
import { AbortError } from '@aztec/foundation/error';
|
|
13
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
13
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
14
14
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
15
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
15
16
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
16
17
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
17
18
|
import { elapsed } from '@aztec/foundation/timer';
|
|
18
19
|
import type { TreeNodeLocation } from '@aztec/foundation/trees';
|
|
19
|
-
import { readAvmMinimalPublicTxInputsFromFile } from '@aztec/simulator/public/fixtures';
|
|
20
20
|
import { EthAddress } from '@aztec/stdlib/block';
|
|
21
21
|
import type {
|
|
22
22
|
EpochProver,
|
|
23
23
|
ForkMerkleTreeOperations,
|
|
24
24
|
MerkleTreeWriteOperations,
|
|
25
25
|
PublicInputsAndRecursiveProof,
|
|
26
|
+
ReadonlyWorldStateAccess,
|
|
26
27
|
ServerCircuitProver,
|
|
27
28
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
29
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
@@ -71,8 +72,6 @@ import { EpochProvingState, type ProvingResult, type TreeSnapshots } from './epo
|
|
|
71
72
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
72
73
|
import { TxProvingState } from './tx-proving-state.js';
|
|
73
74
|
|
|
74
|
-
const logger = createLogger('prover-client:orchestrator');
|
|
75
|
-
|
|
76
75
|
/**
|
|
77
76
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
78
77
|
* 1. Transactions are provided to the scheduler post simulation.
|
|
@@ -95,14 +94,21 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
95
94
|
private metrics: ProvingOrchestratorMetrics;
|
|
96
95
|
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
97
96
|
private dbs: Map<BlockNumber, MerkleTreeWriteOperations> = new Map();
|
|
97
|
+
private logger: Logger;
|
|
98
|
+
private deferredJobQueue = new SerialQueue();
|
|
98
99
|
|
|
99
100
|
constructor(
|
|
100
|
-
private dbProvider: ForkMerkleTreeOperations,
|
|
101
|
+
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
101
102
|
private prover: ServerCircuitProver,
|
|
102
103
|
private readonly proverId: EthAddress,
|
|
104
|
+
private readonly cancelJobsOnStop: boolean = false,
|
|
105
|
+
private readonly enqueueConcurrency: number,
|
|
103
106
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
107
|
+
bindings?: LoggerBindings,
|
|
104
108
|
) {
|
|
109
|
+
this.logger = createLogger('prover-client:orchestrator', bindings);
|
|
105
110
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
111
|
+
this.deferredJobQueue.start(this.enqueueConcurrency);
|
|
106
112
|
}
|
|
107
113
|
|
|
108
114
|
get tracer(): Tracer {
|
|
@@ -113,9 +119,15 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
113
119
|
return this.proverId;
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
public
|
|
122
|
+
public getNumActiveForks() {
|
|
123
|
+
return this.dbs.size;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public async stop(): Promise<void> {
|
|
127
|
+
// Grab the old queue before cancel() replaces it, so we can await its draining.
|
|
128
|
+
const oldQueue = this.deferredJobQueue;
|
|
117
129
|
this.cancel();
|
|
118
|
-
|
|
130
|
+
await oldQueue.cancel();
|
|
119
131
|
}
|
|
120
132
|
|
|
121
133
|
public startNewEpoch(
|
|
@@ -131,7 +143,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
131
143
|
|
|
132
144
|
const { promise: _promise, resolve, reject } = promiseWithResolvers<ProvingResult>();
|
|
133
145
|
const promise = _promise.catch((reason): ProvingResult => ({ status: 'failure', reason }));
|
|
134
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
146
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
135
147
|
this.provingState = new EpochProvingState(
|
|
136
148
|
epochNumber,
|
|
137
149
|
totalNumCheckpoints,
|
|
@@ -143,6 +155,14 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
143
155
|
this.provingPromise = promise;
|
|
144
156
|
}
|
|
145
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Starts a new checkpoint.
|
|
160
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
161
|
+
* @param constants - The constants for this checkpoint.
|
|
162
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
163
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
164
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
165
|
+
*/
|
|
146
166
|
public async startNewCheckpoint(
|
|
147
167
|
checkpointIndex: number,
|
|
148
168
|
constants: CheckpointConstantData,
|
|
@@ -215,7 +235,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
215
235
|
}
|
|
216
236
|
|
|
217
237
|
const constants = checkpointProvingState.constants;
|
|
218
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
238
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
219
239
|
|
|
220
240
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
221
241
|
if (!this.dbs.has(blockNumber)) {
|
|
@@ -223,7 +243,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
223
243
|
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
224
244
|
this.dbs.set(blockNumber, db);
|
|
225
245
|
}
|
|
226
|
-
const db = this.
|
|
246
|
+
const db = this.getDbForBlock(blockNumber);
|
|
227
247
|
|
|
228
248
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
229
249
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
@@ -255,7 +275,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
255
275
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
256
276
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
257
277
|
|
|
258
|
-
//
|
|
278
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
279
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
259
280
|
await this.provingState.setBlobAccumulators();
|
|
260
281
|
}
|
|
261
282
|
}
|
|
@@ -275,7 +296,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
275
296
|
if (!txs.length) {
|
|
276
297
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
277
298
|
// on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
|
|
278
|
-
logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
299
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
279
300
|
return;
|
|
280
301
|
}
|
|
281
302
|
|
|
@@ -295,9 +316,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
295
316
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
296
317
|
}
|
|
297
318
|
|
|
298
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
319
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
299
320
|
|
|
300
|
-
const db = this.
|
|
321
|
+
const db = this.getDbForBlock(blockNumber);
|
|
301
322
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
302
323
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
303
324
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -310,7 +331,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
310
331
|
|
|
311
332
|
validateTx(tx);
|
|
312
333
|
|
|
313
|
-
logger.
|
|
334
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
314
335
|
|
|
315
336
|
const startSpongeBlob = spongeBlobState.clone();
|
|
316
337
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(
|
|
@@ -331,10 +352,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
331
352
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
332
353
|
if (txProvingState.requireAvmProof) {
|
|
333
354
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
334
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
355
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
335
356
|
this.enqueueVM(provingState, txIndex);
|
|
336
357
|
} else {
|
|
337
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
358
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
338
359
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
339
360
|
}
|
|
340
361
|
} catch (err: any) {
|
|
@@ -352,7 +373,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
352
373
|
|
|
353
374
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
354
375
|
|
|
355
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
376
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
377
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
356
378
|
await this.provingState.setBlobAccumulators();
|
|
357
379
|
}
|
|
358
380
|
|
|
@@ -376,7 +398,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
376
398
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
377
399
|
>
|
|
378
400
|
>();
|
|
379
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
401
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
380
402
|
this.doEnqueueChonkVerifier(txHash, privateInputs, proof => {
|
|
381
403
|
tubeProof.resolve(proof);
|
|
382
404
|
});
|
|
@@ -416,22 +438,28 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
416
438
|
}
|
|
417
439
|
|
|
418
440
|
// Given we've applied every change from this block, now assemble the block header:
|
|
419
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
441
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
420
442
|
const header = await provingState.buildBlockHeader();
|
|
421
443
|
|
|
422
444
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
423
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
445
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
424
446
|
throw new Error('Block header mismatch');
|
|
425
447
|
}
|
|
426
448
|
|
|
427
|
-
// Get db for this block
|
|
428
|
-
const db = this.
|
|
449
|
+
// Get db for this block and remove from map — no other code should use it after this point.
|
|
450
|
+
const db = this.getDbForBlock(provingState.blockNumber);
|
|
451
|
+
this.dbs.delete(provingState.blockNumber);
|
|
429
452
|
|
|
430
|
-
// Update the archive tree,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
453
|
+
// Update the archive tree, capture the snapshot, and close the fork deterministically.
|
|
454
|
+
try {
|
|
455
|
+
this.logger.verbose(
|
|
456
|
+
`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`,
|
|
457
|
+
);
|
|
458
|
+
await db.updateArchive(header);
|
|
459
|
+
provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
|
|
460
|
+
} finally {
|
|
461
|
+
await db.close();
|
|
462
|
+
}
|
|
435
463
|
|
|
436
464
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
437
465
|
|
|
@@ -442,31 +470,34 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
442
470
|
protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
|
|
443
471
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
444
472
|
if (!builtBlockHeader) {
|
|
445
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
473
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
446
474
|
return;
|
|
447
475
|
}
|
|
448
476
|
|
|
449
477
|
const output = provingState.getBlockRootRollupOutput();
|
|
450
478
|
if (!output) {
|
|
451
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
479
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const newArchive = provingState.getBuiltArchive();
|
|
484
|
+
if (!newArchive) {
|
|
485
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
452
486
|
return;
|
|
453
487
|
}
|
|
488
|
+
|
|
454
489
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
455
490
|
|
|
456
491
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
457
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
492
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
458
493
|
provingState.reject(`Block header hash mismatch.`);
|
|
459
494
|
return;
|
|
460
495
|
}
|
|
461
496
|
|
|
462
|
-
// Get db for this block
|
|
463
497
|
const blockNumber = provingState.blockNumber;
|
|
464
|
-
const db = this.dbs.get(blockNumber)!;
|
|
465
|
-
|
|
466
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
467
498
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
468
499
|
if (!syncedArchive.equals(newArchive)) {
|
|
469
|
-
logger.error(
|
|
500
|
+
this.logger.error(
|
|
470
501
|
`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
|
|
471
502
|
syncedArchive,
|
|
472
503
|
)} but built ${inspect(newArchive)}`,
|
|
@@ -477,32 +508,43 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
477
508
|
|
|
478
509
|
const circuitArchive = output.newArchive;
|
|
479
510
|
if (!newArchive.equals(circuitArchive)) {
|
|
480
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
511
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
481
512
|
provingState.reject(`New archive mismatch.`);
|
|
482
513
|
return;
|
|
483
514
|
}
|
|
484
|
-
|
|
485
|
-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
|
|
486
|
-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
487
|
-
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
488
|
-
// will attempt to access the fork after it was closed.
|
|
489
|
-
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
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));
|
|
495
515
|
}
|
|
496
516
|
|
|
497
517
|
/**
|
|
498
|
-
* Cancel any further proving
|
|
518
|
+
* Cancel any further proving.
|
|
519
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
520
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
499
521
|
*/
|
|
500
522
|
public cancel() {
|
|
501
|
-
|
|
502
|
-
|
|
523
|
+
void this.deferredJobQueue.cancel();
|
|
524
|
+
// Recreate the queue so it can accept jobs for subsequent epochs.
|
|
525
|
+
this.deferredJobQueue = new SerialQueue();
|
|
526
|
+
this.deferredJobQueue.start(this.enqueueConcurrency);
|
|
527
|
+
|
|
528
|
+
if (this.cancelJobsOnStop) {
|
|
529
|
+
for (const controller of this.pendingProvingJobs) {
|
|
530
|
+
controller.abort();
|
|
531
|
+
}
|
|
503
532
|
}
|
|
504
533
|
|
|
505
534
|
this.provingState?.cancel();
|
|
535
|
+
|
|
536
|
+
for (const [blockNumber, db] of this.dbs.entries()) {
|
|
537
|
+
void db.close().catch(err => this.logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
538
|
+
}
|
|
539
|
+
this.dbs.clear();
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
private getDbForBlock(blockNumber: BlockNumber): MerkleTreeWriteOperations {
|
|
543
|
+
const db = this.dbs.get(blockNumber);
|
|
544
|
+
if (!db) {
|
|
545
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
546
|
+
}
|
|
547
|
+
return db;
|
|
506
548
|
}
|
|
507
549
|
|
|
508
550
|
/**
|
|
@@ -546,7 +588,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
546
588
|
callback: (result: T) => void | Promise<void>,
|
|
547
589
|
) {
|
|
548
590
|
if (!provingState.verifyState()) {
|
|
549
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
591
|
+
this.logger.debug(`Not enqueuing job, state no longer valid`);
|
|
550
592
|
return;
|
|
551
593
|
}
|
|
552
594
|
|
|
@@ -564,7 +606,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
564
606
|
|
|
565
607
|
const result = await request(controller.signal);
|
|
566
608
|
if (!provingState.verifyState()) {
|
|
567
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
609
|
+
this.logger.debug(`State no longer valid, discarding result`);
|
|
568
610
|
return;
|
|
569
611
|
}
|
|
570
612
|
|
|
@@ -582,7 +624,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
582
624
|
return;
|
|
583
625
|
}
|
|
584
626
|
|
|
585
|
-
logger.error(`Error thrown when proving job`, err);
|
|
627
|
+
this.logger.error(`Error thrown when proving job`, err);
|
|
586
628
|
provingState!.reject(`${err}`);
|
|
587
629
|
} finally {
|
|
588
630
|
const index = this.pendingProvingJobs.indexOf(controller);
|
|
@@ -592,8 +634,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
592
634
|
}
|
|
593
635
|
};
|
|
594
636
|
|
|
595
|
-
//
|
|
596
|
-
|
|
637
|
+
// Enqueue onto the serial queue with limited workers to avoid starving the event loop.
|
|
638
|
+
// Workers yield between jobs via await, allowing I/O callbacks to process.
|
|
639
|
+
void this.deferredJobQueue.put(() => safeJob());
|
|
597
640
|
}
|
|
598
641
|
|
|
599
642
|
private async updateL1ToL2MessageTree(l1ToL2Messages: Fr[], db: MerkleTreeWriteOperations) {
|
|
@@ -667,12 +710,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
667
710
|
// Executes the next level of merge if all inputs are available
|
|
668
711
|
private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
669
712
|
if (!provingState.verifyState()) {
|
|
670
|
-
logger.debug('Not running base rollup, state invalid');
|
|
713
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
671
714
|
return;
|
|
672
715
|
}
|
|
673
716
|
|
|
674
717
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
675
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
718
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
676
719
|
return;
|
|
677
720
|
}
|
|
678
721
|
|
|
@@ -680,7 +723,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
680
723
|
const { processedTx } = txProvingState;
|
|
681
724
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
682
725
|
|
|
683
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
726
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
684
727
|
|
|
685
728
|
this.deferredProving(
|
|
686
729
|
provingState,
|
|
@@ -704,7 +747,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
704
747
|
},
|
|
705
748
|
),
|
|
706
749
|
result => {
|
|
707
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
750
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
708
751
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
709
752
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
710
753
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -720,7 +763,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
720
763
|
// Once completed, will enqueue the the public tx base rollup.
|
|
721
764
|
private getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
|
|
722
765
|
if (!provingState.verifyState()) {
|
|
723
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
766
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
724
767
|
return;
|
|
725
768
|
}
|
|
726
769
|
|
|
@@ -733,19 +776,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
733
776
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
734
777
|
>,
|
|
735
778
|
) => {
|
|
736
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
779
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
737
780
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
738
781
|
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
739
782
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
740
783
|
};
|
|
741
784
|
|
|
742
785
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
743
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
786
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
744
787
|
void this.provingState!.cachedChonkVerifierProofs.get(txHash)!.then(handleResult);
|
|
745
788
|
return;
|
|
746
789
|
}
|
|
747
790
|
|
|
748
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
791
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
749
792
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
750
793
|
}
|
|
751
794
|
|
|
@@ -761,7 +804,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
761
804
|
provingState: EpochProvingState | BlockProvingState = this.provingState!,
|
|
762
805
|
) {
|
|
763
806
|
if (!provingState.verifyState()) {
|
|
764
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
807
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
765
808
|
return;
|
|
766
809
|
}
|
|
767
810
|
|
|
@@ -784,12 +827,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
784
827
|
// Enqueues the next level of merge if all inputs are available
|
|
785
828
|
private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
|
|
786
829
|
if (!provingState.verifyState()) {
|
|
787
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
830
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
788
831
|
return;
|
|
789
832
|
}
|
|
790
833
|
|
|
791
834
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
792
|
-
logger.debug('Merge rollup already started.');
|
|
835
|
+
this.logger.debug('Merge rollup already started.');
|
|
793
836
|
return;
|
|
794
837
|
}
|
|
795
838
|
|
|
@@ -815,18 +858,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
815
858
|
// Executes the block root rollup circuit
|
|
816
859
|
private enqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
817
860
|
if (!provingState.verifyState()) {
|
|
818
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
861
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
819
862
|
return;
|
|
820
863
|
}
|
|
821
864
|
|
|
822
865
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
823
|
-
logger.debug('Block root rollup already started.');
|
|
866
|
+
this.logger.debug('Block root rollup already started.');
|
|
824
867
|
return;
|
|
825
868
|
}
|
|
826
869
|
|
|
827
870
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
828
871
|
|
|
829
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
872
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
830
873
|
|
|
831
874
|
this.deferredProving(
|
|
832
875
|
provingState,
|
|
@@ -851,18 +894,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
851
894
|
},
|
|
852
895
|
),
|
|
853
896
|
async result => {
|
|
854
|
-
|
|
855
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
856
|
-
|
|
857
|
-
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
897
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
858
898
|
|
|
859
899
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
860
900
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
861
901
|
|
|
902
|
+
// Verification is called from both here and setBlockCompleted. Whichever runs last
|
|
903
|
+
// will be the first to see all three pieces (header, proof output, archive) and run the checks.
|
|
904
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
905
|
+
|
|
862
906
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
863
|
-
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
907
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
864
908
|
} else {
|
|
865
|
-
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
909
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
866
910
|
}
|
|
867
911
|
},
|
|
868
912
|
);
|
|
@@ -876,12 +920,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
876
920
|
baseParityIndex: number,
|
|
877
921
|
) {
|
|
878
922
|
if (!provingState.verifyState()) {
|
|
879
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
923
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
880
924
|
return;
|
|
881
925
|
}
|
|
882
926
|
|
|
883
927
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
884
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
928
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
885
929
|
return;
|
|
886
930
|
}
|
|
887
931
|
|
|
@@ -916,12 +960,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
916
960
|
// Enqueues the root rollup proof if all inputs are available
|
|
917
961
|
private enqueueRootParityCircuit(provingState: BlockProvingState) {
|
|
918
962
|
if (!provingState.verifyState()) {
|
|
919
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
963
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
920
964
|
return;
|
|
921
965
|
}
|
|
922
966
|
|
|
923
967
|
if (!provingState.tryStartProvingRootParity()) {
|
|
924
|
-
logger.debug('Root parity already started.');
|
|
968
|
+
this.logger.debug('Root parity already started.');
|
|
925
969
|
return;
|
|
926
970
|
}
|
|
927
971
|
|
|
@@ -948,12 +992,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
948
992
|
// Enqueues the next level of merge if all inputs are available
|
|
949
993
|
private enqueueBlockMergeRollup(provingState: CheckpointProvingState, location: TreeNodeLocation) {
|
|
950
994
|
if (!provingState.verifyState()) {
|
|
951
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
995
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
952
996
|
return;
|
|
953
997
|
}
|
|
954
998
|
|
|
955
999
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
956
|
-
logger.debug('Block merge rollup already started.');
|
|
1000
|
+
this.logger.debug('Block merge rollup already started.');
|
|
957
1001
|
return;
|
|
958
1002
|
}
|
|
959
1003
|
|
|
@@ -968,29 +1012,29 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
968
1012
|
},
|
|
969
1013
|
signal => this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
970
1014
|
),
|
|
971
|
-
result => {
|
|
1015
|
+
async result => {
|
|
972
1016
|
provingState.setBlockMergeRollupProof(location, result);
|
|
973
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1017
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
974
1018
|
},
|
|
975
1019
|
);
|
|
976
1020
|
}
|
|
977
1021
|
|
|
978
|
-
private enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1022
|
+
private async enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
979
1023
|
if (!provingState.verifyState()) {
|
|
980
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1024
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
981
1025
|
return;
|
|
982
1026
|
}
|
|
983
1027
|
|
|
984
1028
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
985
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1029
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
986
1030
|
return;
|
|
987
1031
|
}
|
|
988
1032
|
|
|
989
1033
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
990
1034
|
|
|
991
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1035
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
992
1036
|
|
|
993
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
1037
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
994
1038
|
|
|
995
1039
|
this.deferredProving(
|
|
996
1040
|
provingState,
|
|
@@ -1012,7 +1056,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1012
1056
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator()!.toBlobAccumulator();
|
|
1013
1057
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1014
1058
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1015
|
-
logger.error(
|
|
1059
|
+
this.logger.error(
|
|
1016
1060
|
`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(
|
|
1017
1061
|
computedEndBlobAccumulatorState,
|
|
1018
1062
|
)}`,
|
|
@@ -1021,7 +1065,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1021
1065
|
return;
|
|
1022
1066
|
}
|
|
1023
1067
|
|
|
1024
|
-
logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1068
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1025
1069
|
|
|
1026
1070
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1027
1071
|
const epochProvingState = provingState.parentEpoch;
|
|
@@ -1037,12 +1081,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1037
1081
|
|
|
1038
1082
|
private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
|
|
1039
1083
|
if (!provingState.verifyState()) {
|
|
1040
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1084
|
+
this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1041
1085
|
return;
|
|
1042
1086
|
}
|
|
1043
1087
|
|
|
1044
1088
|
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1045
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1089
|
+
this.logger.debug('Checkpoint merge rollup already started.');
|
|
1046
1090
|
return;
|
|
1047
1091
|
}
|
|
1048
1092
|
|
|
@@ -1059,7 +1103,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1059
1103
|
signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1060
1104
|
),
|
|
1061
1105
|
result => {
|
|
1062
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1106
|
+
this.logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1063
1107
|
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1064
1108
|
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1065
1109
|
},
|
|
@@ -1068,16 +1112,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1068
1112
|
|
|
1069
1113
|
private enqueueEpochPadding(provingState: EpochProvingState) {
|
|
1070
1114
|
if (!provingState.verifyState()) {
|
|
1071
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1115
|
+
this.logger.debug('Not running epoch padding. State no longer valid.');
|
|
1072
1116
|
return;
|
|
1073
1117
|
}
|
|
1074
1118
|
|
|
1075
1119
|
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1076
|
-
logger.debug('Padding checkpoint already started.');
|
|
1120
|
+
this.logger.debug('Padding checkpoint already started.');
|
|
1077
1121
|
return;
|
|
1078
1122
|
}
|
|
1079
1123
|
|
|
1080
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1124
|
+
this.logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1081
1125
|
|
|
1082
1126
|
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1083
1127
|
|
|
@@ -1092,7 +1136,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1092
1136
|
signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
|
|
1093
1137
|
),
|
|
1094
1138
|
result => {
|
|
1095
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1139
|
+
this.logger.debug('Completed proof for padding checkpoint.');
|
|
1096
1140
|
provingState.setCheckpointPaddingProof(result);
|
|
1097
1141
|
this.checkAndEnqueueRootRollup(provingState);
|
|
1098
1142
|
},
|
|
@@ -1102,11 +1146,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1102
1146
|
// Executes the root rollup circuit
|
|
1103
1147
|
private enqueueRootRollup(provingState: EpochProvingState) {
|
|
1104
1148
|
if (!provingState.verifyState()) {
|
|
1105
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1149
|
+
this.logger.debug('Not running root rollup, state no longer valid');
|
|
1106
1150
|
return;
|
|
1107
1151
|
}
|
|
1108
1152
|
|
|
1109
|
-
logger.debug(`Preparing root rollup`);
|
|
1153
|
+
this.logger.debug(`Preparing root rollup`);
|
|
1110
1154
|
|
|
1111
1155
|
const inputs = provingState.getRootRollupInputs();
|
|
1112
1156
|
|
|
@@ -1121,7 +1165,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1121
1165
|
signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
|
|
1122
1166
|
),
|
|
1123
1167
|
result => {
|
|
1124
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1168
|
+
this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1125
1169
|
provingState.setRootRollupProof(result);
|
|
1126
1170
|
provingState.resolve({ status: 'success' });
|
|
1127
1171
|
},
|
|
@@ -1143,32 +1187,35 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1143
1187
|
|
|
1144
1188
|
private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
1145
1189
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1146
|
-
logger.debug('Not ready for block root rollup');
|
|
1190
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1147
1191
|
return;
|
|
1148
1192
|
}
|
|
1149
1193
|
|
|
1150
1194
|
this.enqueueBlockRootRollup(provingState);
|
|
1151
1195
|
}
|
|
1152
1196
|
|
|
1153
|
-
private checkAndEnqueueNextBlockMergeRollup(
|
|
1197
|
+
private async checkAndEnqueueNextBlockMergeRollup(
|
|
1198
|
+
provingState: CheckpointProvingState,
|
|
1199
|
+
currentLocation: TreeNodeLocation,
|
|
1200
|
+
) {
|
|
1154
1201
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
1155
1202
|
return;
|
|
1156
1203
|
}
|
|
1157
1204
|
|
|
1158
1205
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1159
1206
|
if (parentLocation.level === 0) {
|
|
1160
|
-
this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1207
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1161
1208
|
} else {
|
|
1162
1209
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1163
1210
|
}
|
|
1164
1211
|
}
|
|
1165
1212
|
|
|
1166
|
-
private checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1213
|
+
private async checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1167
1214
|
if (!provingState.isReadyForCheckpointRoot()) {
|
|
1168
1215
|
return;
|
|
1169
1216
|
}
|
|
1170
1217
|
|
|
1171
|
-
this.enqueueCheckpointRootRollup(provingState);
|
|
1218
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
1172
1219
|
}
|
|
1173
1220
|
|
|
1174
1221
|
private checkAndEnqueueNextCheckpointMergeRollup(provingState: EpochProvingState, currentLocation: TreeNodeLocation) {
|
|
@@ -1186,7 +1233,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1186
1233
|
|
|
1187
1234
|
private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
|
|
1188
1235
|
if (!provingState.isReadyForRootRollup()) {
|
|
1189
|
-
logger.debug('Not ready for root rollup');
|
|
1236
|
+
this.logger.debug('Not ready for root rollup');
|
|
1190
1237
|
return;
|
|
1191
1238
|
}
|
|
1192
1239
|
|
|
@@ -1201,14 +1248,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1201
1248
|
*/
|
|
1202
1249
|
private enqueueVM(provingState: BlockProvingState, txIndex: number) {
|
|
1203
1250
|
if (!provingState.verifyState()) {
|
|
1204
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1251
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1205
1252
|
return;
|
|
1206
1253
|
}
|
|
1207
1254
|
|
|
1208
1255
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1209
1256
|
|
|
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
1257
|
const doAvmProving = wrapCallbackInSpan(
|
|
1213
1258
|
this.tracer,
|
|
1214
1259
|
'ProvingOrchestrator.prover.getAvmProof',
|
|
@@ -1217,36 +1262,13 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1217
1262
|
},
|
|
1218
1263
|
async (signal: AbortSignal) => {
|
|
1219
1264
|
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
|
-
}
|
|
1265
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1244
1266
|
},
|
|
1245
1267
|
);
|
|
1246
1268
|
|
|
1247
|
-
this.deferredProving(provingState, doAvmProving,
|
|
1248
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1249
|
-
txProvingState.setAvmProof(
|
|
1269
|
+
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1270
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1271
|
+
txProvingState.setAvmProof(proof);
|
|
1250
1272
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1251
1273
|
});
|
|
1252
1274
|
}
|
|
@@ -1258,7 +1280,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1258
1280
|
}
|
|
1259
1281
|
|
|
1260
1282
|
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
1261
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1283
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1262
1284
|
|
|
1263
1285
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1264
1286
|
}
|