@aztec/prover-client 0.0.1-commit.96bb3f7 → 0.0.1-commit.a072138
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/lightweight_checkpoint_builder.d.ts +11 -7
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +28 -11
- 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 +3 -2
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +6 -1
- package/dest/orchestrator/block-building-helpers.d.ts +1 -1
- package/dest/orchestrator/block-building-helpers.js +1 -1
- package/dest/orchestrator/checkpoint-proving-state.d.ts +15 -2
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +34 -1
- 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 +18 -3
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +120 -78
- package/dest/prover-client/prover-client.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +7 -4
- 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 -3
- package/dest/proving_broker/config.d.ts +5 -1
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +7 -1
- package/dest/proving_broker/proving_agent.d.ts +4 -3
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -4
- 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 -7
- 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 +6 -3
- package/dest/test/mock_proof_store.d.ts +3 -3
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/package.json +16 -17
- package/src/light/lightweight_checkpoint_builder.ts +52 -12
- package/src/mocks/fixtures.ts +2 -1
- package/src/mocks/test_context.ts +5 -0
- package/src/orchestrator/block-building-helpers.ts +1 -1
- package/src/orchestrator/checkpoint-proving-state.ts +47 -1
- package/src/orchestrator/epoch-proving-state.ts +56 -8
- package/src/orchestrator/orchestrator.ts +124 -83
- package/src/prover-client/prover-client.ts +23 -6
- package/src/proving_broker/broker_prover_facade.ts +6 -3
- package/src/proving_broker/config.ts +9 -0
- package/src/proving_broker/proving_agent.ts +5 -2
- package/src/proving_broker/proving_broker_instrumentation.ts +10 -6
- package/src/proving_broker/proving_job_controller.ts +9 -3
- 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 -106
- package/src/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -136
|
@@ -10,7 +10,7 @@ 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
15
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
16
16
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
@@ -71,7 +71,10 @@ import { EpochProvingState, type ProvingResult, type TreeSnapshots } from './epo
|
|
|
71
71
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
72
72
|
import { TxProvingState } from './tx-proving-state.js';
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
type WorldStateFork = {
|
|
75
|
+
fork: MerkleTreeWriteOperations;
|
|
76
|
+
cleanupPromise: Promise<void> | undefined;
|
|
77
|
+
};
|
|
75
78
|
|
|
76
79
|
/**
|
|
77
80
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
@@ -94,14 +97,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
94
97
|
private provingPromise: Promise<ProvingResult> | undefined = undefined;
|
|
95
98
|
private metrics: ProvingOrchestratorMetrics;
|
|
96
99
|
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
97
|
-
private dbs: Map<BlockNumber,
|
|
100
|
+
private dbs: Map<BlockNumber, WorldStateFork> = new Map();
|
|
101
|
+
private logger: Logger;
|
|
98
102
|
|
|
99
103
|
constructor(
|
|
100
104
|
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
101
105
|
private prover: ServerCircuitProver,
|
|
102
106
|
private readonly proverId: EthAddress,
|
|
107
|
+
private readonly cancelJobsOnStop: boolean = false,
|
|
103
108
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
109
|
+
bindings?: LoggerBindings,
|
|
104
110
|
) {
|
|
111
|
+
this.logger = createLogger('prover-client:orchestrator', bindings);
|
|
105
112
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
106
113
|
}
|
|
107
114
|
|
|
@@ -113,6 +120,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
113
120
|
return this.proverId;
|
|
114
121
|
}
|
|
115
122
|
|
|
123
|
+
public getNumActiveForks() {
|
|
124
|
+
return this.dbs.size;
|
|
125
|
+
}
|
|
126
|
+
|
|
116
127
|
public stop(): Promise<void> {
|
|
117
128
|
this.cancel();
|
|
118
129
|
return Promise.resolve();
|
|
@@ -131,7 +142,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
131
142
|
|
|
132
143
|
const { promise: _promise, resolve, reject } = promiseWithResolvers<ProvingResult>();
|
|
133
144
|
const promise = _promise.catch((reason): ProvingResult => ({ status: 'failure', reason }));
|
|
134
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
145
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
135
146
|
this.provingState = new EpochProvingState(
|
|
136
147
|
epochNumber,
|
|
137
148
|
totalNumCheckpoints,
|
|
@@ -143,6 +154,14 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
143
154
|
this.provingPromise = promise;
|
|
144
155
|
}
|
|
145
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Starts a new checkpoint.
|
|
159
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
160
|
+
* @param constants - The constants for this checkpoint.
|
|
161
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
162
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
163
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
164
|
+
*/
|
|
146
165
|
public async startNewCheckpoint(
|
|
147
166
|
checkpointIndex: number,
|
|
148
167
|
constants: CheckpointConstantData,
|
|
@@ -163,7 +182,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
163
182
|
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
164
183
|
|
|
165
184
|
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
166
|
-
this.dbs.set(firstBlockNumber, db);
|
|
185
|
+
this.dbs.set(firstBlockNumber, { fork: db, cleanupPromise: undefined });
|
|
167
186
|
|
|
168
187
|
// Get archive sibling path before any block in this checkpoint lands.
|
|
169
188
|
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
@@ -215,15 +234,15 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
215
234
|
}
|
|
216
235
|
|
|
217
236
|
const constants = checkpointProvingState.constants;
|
|
218
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
237
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
219
238
|
|
|
220
239
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
221
240
|
if (!this.dbs.has(blockNumber)) {
|
|
222
241
|
// Fork world state at the end of the immediately previous block
|
|
223
242
|
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
224
|
-
this.dbs.set(blockNumber, db);
|
|
243
|
+
this.dbs.set(blockNumber, { fork: db, cleanupPromise: undefined });
|
|
225
244
|
}
|
|
226
|
-
const db = this.dbs.get(blockNumber)
|
|
245
|
+
const db = this.dbs.get(blockNumber)!.fork;
|
|
227
246
|
|
|
228
247
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
229
248
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
@@ -255,7 +274,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
255
274
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
256
275
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
257
276
|
|
|
258
|
-
//
|
|
277
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
278
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
259
279
|
await this.provingState.setBlobAccumulators();
|
|
260
280
|
}
|
|
261
281
|
}
|
|
@@ -275,7 +295,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
275
295
|
if (!txs.length) {
|
|
276
296
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
277
297
|
// 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.`);
|
|
298
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
279
299
|
return;
|
|
280
300
|
}
|
|
281
301
|
|
|
@@ -295,9 +315,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
295
315
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
296
316
|
}
|
|
297
317
|
|
|
298
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
318
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
299
319
|
|
|
300
|
-
const db = this.dbs.get(blockNumber)
|
|
320
|
+
const db = this.dbs.get(blockNumber)!.fork;
|
|
301
321
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
302
322
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
303
323
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -310,7 +330,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
310
330
|
|
|
311
331
|
validateTx(tx);
|
|
312
332
|
|
|
313
|
-
logger.debug(`Received transaction: ${tx.hash}`);
|
|
333
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
314
334
|
|
|
315
335
|
const startSpongeBlob = spongeBlobState.clone();
|
|
316
336
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(
|
|
@@ -331,10 +351,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
331
351
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
332
352
|
if (txProvingState.requireAvmProof) {
|
|
333
353
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
334
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
354
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
335
355
|
this.enqueueVM(provingState, txIndex);
|
|
336
356
|
} else {
|
|
337
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
357
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
338
358
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
339
359
|
}
|
|
340
360
|
} catch (err: any) {
|
|
@@ -352,7 +372,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
352
372
|
|
|
353
373
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
354
374
|
|
|
355
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
375
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
376
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
356
377
|
await this.provingState.setBlobAccumulators();
|
|
357
378
|
}
|
|
358
379
|
|
|
@@ -376,7 +397,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
376
397
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
377
398
|
>
|
|
378
399
|
>();
|
|
379
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
400
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
380
401
|
this.doEnqueueChonkVerifier(txHash, privateInputs, proof => {
|
|
381
402
|
tubeProof.resolve(proof);
|
|
382
403
|
});
|
|
@@ -416,19 +437,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
416
437
|
}
|
|
417
438
|
|
|
418
439
|
// Given we've applied every change from this block, now assemble the block header:
|
|
419
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
440
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
420
441
|
const header = await provingState.buildBlockHeader();
|
|
421
442
|
|
|
422
443
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
423
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
444
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
424
445
|
throw new Error('Block header mismatch');
|
|
425
446
|
}
|
|
426
447
|
|
|
427
448
|
// Get db for this block
|
|
428
|
-
const db = this.dbs.get(provingState.blockNumber)
|
|
449
|
+
const db = this.dbs.get(provingState.blockNumber)!.fork;
|
|
429
450
|
|
|
430
451
|
// Update the archive tree, so we're ready to start processing the next block:
|
|
431
|
-
logger.verbose(
|
|
452
|
+
this.logger.verbose(
|
|
432
453
|
`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`,
|
|
433
454
|
);
|
|
434
455
|
await db.updateArchive(header);
|
|
@@ -442,31 +463,31 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
442
463
|
protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
|
|
443
464
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
444
465
|
if (!builtBlockHeader) {
|
|
445
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
466
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
446
467
|
return;
|
|
447
468
|
}
|
|
448
469
|
|
|
449
470
|
const output = provingState.getBlockRootRollupOutput();
|
|
450
471
|
if (!output) {
|
|
451
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
472
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
452
473
|
return;
|
|
453
474
|
}
|
|
454
475
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
455
476
|
|
|
456
477
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
457
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
478
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
458
479
|
provingState.reject(`Block header hash mismatch.`);
|
|
459
480
|
return;
|
|
460
481
|
}
|
|
461
482
|
|
|
462
483
|
// Get db for this block
|
|
463
484
|
const blockNumber = provingState.blockNumber;
|
|
464
|
-
const db = this.dbs.get(blockNumber)
|
|
485
|
+
const db = this.dbs.get(blockNumber)!.fork;
|
|
465
486
|
|
|
466
487
|
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
467
488
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
468
489
|
if (!syncedArchive.equals(newArchive)) {
|
|
469
|
-
logger.error(
|
|
490
|
+
this.logger.error(
|
|
470
491
|
`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
|
|
471
492
|
syncedArchive,
|
|
472
493
|
)} but built ${inspect(newArchive)}`,
|
|
@@ -477,7 +498,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
477
498
|
|
|
478
499
|
const circuitArchive = output.newArchive;
|
|
479
500
|
if (!newArchive.equals(circuitArchive)) {
|
|
480
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
501
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
481
502
|
provingState.reject(`New archive mismatch.`);
|
|
482
503
|
return;
|
|
483
504
|
}
|
|
@@ -486,20 +507,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
486
507
|
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
487
508
|
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
488
509
|
// 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));
|
|
510
|
+
void this.cleanupDBFork(blockNumber);
|
|
495
511
|
}
|
|
496
512
|
|
|
497
513
|
/**
|
|
498
|
-
* Cancel any further proving
|
|
514
|
+
* Cancel any further proving.
|
|
515
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
516
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
499
517
|
*/
|
|
500
518
|
public cancel() {
|
|
501
|
-
|
|
502
|
-
controller.
|
|
519
|
+
if (this.cancelJobsOnStop) {
|
|
520
|
+
for (const controller of this.pendingProvingJobs) {
|
|
521
|
+
controller.abort();
|
|
522
|
+
}
|
|
503
523
|
}
|
|
504
524
|
|
|
505
525
|
this.provingState?.cancel();
|
|
@@ -534,6 +554,24 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
534
554
|
return epochProofResult;
|
|
535
555
|
}
|
|
536
556
|
|
|
557
|
+
private async cleanupDBFork(blockNumber: BlockNumber): Promise<void> {
|
|
558
|
+
this.logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
559
|
+
const fork = this.dbs.get(blockNumber);
|
|
560
|
+
if (!fork) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
try {
|
|
565
|
+
if (!fork.cleanupPromise) {
|
|
566
|
+
fork.cleanupPromise = fork.fork.close();
|
|
567
|
+
}
|
|
568
|
+
await fork.cleanupPromise;
|
|
569
|
+
this.dbs.delete(blockNumber);
|
|
570
|
+
} catch (err) {
|
|
571
|
+
this.logger.error(`Error closing db for block ${blockNumber}`, err);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
537
575
|
/**
|
|
538
576
|
* Enqueue a job to be scheduled
|
|
539
577
|
* @param provingState - The proving state object being operated on
|
|
@@ -546,7 +584,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
546
584
|
callback: (result: T) => void | Promise<void>,
|
|
547
585
|
) {
|
|
548
586
|
if (!provingState.verifyState()) {
|
|
549
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
587
|
+
this.logger.debug(`Not enqueuing job, state no longer valid`);
|
|
550
588
|
return;
|
|
551
589
|
}
|
|
552
590
|
|
|
@@ -564,7 +602,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
564
602
|
|
|
565
603
|
const result = await request(controller.signal);
|
|
566
604
|
if (!provingState.verifyState()) {
|
|
567
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
605
|
+
this.logger.debug(`State no longer valid, discarding result`);
|
|
568
606
|
return;
|
|
569
607
|
}
|
|
570
608
|
|
|
@@ -582,7 +620,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
582
620
|
return;
|
|
583
621
|
}
|
|
584
622
|
|
|
585
|
-
logger.error(`Error thrown when proving job`, err);
|
|
623
|
+
this.logger.error(`Error thrown when proving job`, err);
|
|
586
624
|
provingState!.reject(`${err}`);
|
|
587
625
|
} finally {
|
|
588
626
|
const index = this.pendingProvingJobs.indexOf(controller);
|
|
@@ -667,12 +705,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
667
705
|
// Executes the next level of merge if all inputs are available
|
|
668
706
|
private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
669
707
|
if (!provingState.verifyState()) {
|
|
670
|
-
logger.debug('Not running base rollup, state invalid');
|
|
708
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
671
709
|
return;
|
|
672
710
|
}
|
|
673
711
|
|
|
674
712
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
675
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
713
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
676
714
|
return;
|
|
677
715
|
}
|
|
678
716
|
|
|
@@ -680,7 +718,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
680
718
|
const { processedTx } = txProvingState;
|
|
681
719
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
682
720
|
|
|
683
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
721
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
684
722
|
|
|
685
723
|
this.deferredProving(
|
|
686
724
|
provingState,
|
|
@@ -704,7 +742,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
704
742
|
},
|
|
705
743
|
),
|
|
706
744
|
result => {
|
|
707
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
745
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
708
746
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
709
747
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
710
748
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -720,7 +758,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
720
758
|
// Once completed, will enqueue the the public tx base rollup.
|
|
721
759
|
private getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
|
|
722
760
|
if (!provingState.verifyState()) {
|
|
723
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
761
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
724
762
|
return;
|
|
725
763
|
}
|
|
726
764
|
|
|
@@ -733,19 +771,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
733
771
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
734
772
|
>,
|
|
735
773
|
) => {
|
|
736
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
774
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
737
775
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
738
776
|
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
739
777
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
740
778
|
};
|
|
741
779
|
|
|
742
780
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
743
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
781
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
744
782
|
void this.provingState!.cachedChonkVerifierProofs.get(txHash)!.then(handleResult);
|
|
745
783
|
return;
|
|
746
784
|
}
|
|
747
785
|
|
|
748
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
786
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
749
787
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
750
788
|
}
|
|
751
789
|
|
|
@@ -761,7 +799,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
761
799
|
provingState: EpochProvingState | BlockProvingState = this.provingState!,
|
|
762
800
|
) {
|
|
763
801
|
if (!provingState.verifyState()) {
|
|
764
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
802
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
765
803
|
return;
|
|
766
804
|
}
|
|
767
805
|
|
|
@@ -784,12 +822,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
784
822
|
// Enqueues the next level of merge if all inputs are available
|
|
785
823
|
private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
|
|
786
824
|
if (!provingState.verifyState()) {
|
|
787
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
825
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
788
826
|
return;
|
|
789
827
|
}
|
|
790
828
|
|
|
791
829
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
792
|
-
logger.debug('Merge rollup already started.');
|
|
830
|
+
this.logger.debug('Merge rollup already started.');
|
|
793
831
|
return;
|
|
794
832
|
}
|
|
795
833
|
|
|
@@ -815,18 +853,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
815
853
|
// Executes the block root rollup circuit
|
|
816
854
|
private enqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
817
855
|
if (!provingState.verifyState()) {
|
|
818
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
856
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
819
857
|
return;
|
|
820
858
|
}
|
|
821
859
|
|
|
822
860
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
823
|
-
logger.debug('Block root rollup already started.');
|
|
861
|
+
this.logger.debug('Block root rollup already started.');
|
|
824
862
|
return;
|
|
825
863
|
}
|
|
826
864
|
|
|
827
865
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
828
866
|
|
|
829
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
867
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
830
868
|
|
|
831
869
|
this.deferredProving(
|
|
832
870
|
provingState,
|
|
@@ -851,19 +889,22 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
851
889
|
},
|
|
852
890
|
),
|
|
853
891
|
async result => {
|
|
854
|
-
|
|
855
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
856
|
-
|
|
857
|
-
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
892
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
858
893
|
|
|
859
894
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
860
895
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
861
896
|
|
|
897
|
+
// If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
|
|
898
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
899
|
+
|
|
862
900
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
863
901
|
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
864
902
|
} else {
|
|
865
903
|
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
866
904
|
}
|
|
905
|
+
|
|
906
|
+
// We are finished with the block at this point, ensure the fork is cleaned up
|
|
907
|
+
void this.cleanupDBFork(provingState.blockNumber);
|
|
867
908
|
},
|
|
868
909
|
);
|
|
869
910
|
}
|
|
@@ -876,12 +917,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
876
917
|
baseParityIndex: number,
|
|
877
918
|
) {
|
|
878
919
|
if (!provingState.verifyState()) {
|
|
879
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
920
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
880
921
|
return;
|
|
881
922
|
}
|
|
882
923
|
|
|
883
924
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
884
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
925
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
885
926
|
return;
|
|
886
927
|
}
|
|
887
928
|
|
|
@@ -916,12 +957,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
916
957
|
// Enqueues the root rollup proof if all inputs are available
|
|
917
958
|
private enqueueRootParityCircuit(provingState: BlockProvingState) {
|
|
918
959
|
if (!provingState.verifyState()) {
|
|
919
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
960
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
920
961
|
return;
|
|
921
962
|
}
|
|
922
963
|
|
|
923
964
|
if (!provingState.tryStartProvingRootParity()) {
|
|
924
|
-
logger.debug('Root parity already started.');
|
|
965
|
+
this.logger.debug('Root parity already started.');
|
|
925
966
|
return;
|
|
926
967
|
}
|
|
927
968
|
|
|
@@ -948,12 +989,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
948
989
|
// Enqueues the next level of merge if all inputs are available
|
|
949
990
|
private enqueueBlockMergeRollup(provingState: CheckpointProvingState, location: TreeNodeLocation) {
|
|
950
991
|
if (!provingState.verifyState()) {
|
|
951
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
992
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
952
993
|
return;
|
|
953
994
|
}
|
|
954
995
|
|
|
955
996
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
956
|
-
logger.debug('Block merge rollup already started.');
|
|
997
|
+
this.logger.debug('Block merge rollup already started.');
|
|
957
998
|
return;
|
|
958
999
|
}
|
|
959
1000
|
|
|
@@ -977,18 +1018,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
977
1018
|
|
|
978
1019
|
private enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
979
1020
|
if (!provingState.verifyState()) {
|
|
980
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1021
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
981
1022
|
return;
|
|
982
1023
|
}
|
|
983
1024
|
|
|
984
1025
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
985
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
1026
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
986
1027
|
return;
|
|
987
1028
|
}
|
|
988
1029
|
|
|
989
1030
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
990
1031
|
|
|
991
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1032
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
992
1033
|
|
|
993
1034
|
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
994
1035
|
|
|
@@ -1012,7 +1053,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1012
1053
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator()!.toBlobAccumulator();
|
|
1013
1054
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1014
1055
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1015
|
-
logger.error(
|
|
1056
|
+
this.logger.error(
|
|
1016
1057
|
`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(
|
|
1017
1058
|
computedEndBlobAccumulatorState,
|
|
1018
1059
|
)}`,
|
|
@@ -1021,7 +1062,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1021
1062
|
return;
|
|
1022
1063
|
}
|
|
1023
1064
|
|
|
1024
|
-
logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1065
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1025
1066
|
|
|
1026
1067
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1027
1068
|
const epochProvingState = provingState.parentEpoch;
|
|
@@ -1037,12 +1078,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1037
1078
|
|
|
1038
1079
|
private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
|
|
1039
1080
|
if (!provingState.verifyState()) {
|
|
1040
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1081
|
+
this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1041
1082
|
return;
|
|
1042
1083
|
}
|
|
1043
1084
|
|
|
1044
1085
|
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1045
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1086
|
+
this.logger.debug('Checkpoint merge rollup already started.');
|
|
1046
1087
|
return;
|
|
1047
1088
|
}
|
|
1048
1089
|
|
|
@@ -1059,7 +1100,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1059
1100
|
signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1060
1101
|
),
|
|
1061
1102
|
result => {
|
|
1062
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1103
|
+
this.logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1063
1104
|
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1064
1105
|
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1065
1106
|
},
|
|
@@ -1068,16 +1109,16 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1068
1109
|
|
|
1069
1110
|
private enqueueEpochPadding(provingState: EpochProvingState) {
|
|
1070
1111
|
if (!provingState.verifyState()) {
|
|
1071
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1112
|
+
this.logger.debug('Not running epoch padding. State no longer valid.');
|
|
1072
1113
|
return;
|
|
1073
1114
|
}
|
|
1074
1115
|
|
|
1075
1116
|
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1076
|
-
logger.debug('Padding checkpoint already started.');
|
|
1117
|
+
this.logger.debug('Padding checkpoint already started.');
|
|
1077
1118
|
return;
|
|
1078
1119
|
}
|
|
1079
1120
|
|
|
1080
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1121
|
+
this.logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1081
1122
|
|
|
1082
1123
|
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1083
1124
|
|
|
@@ -1092,7 +1133,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1092
1133
|
signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
|
|
1093
1134
|
),
|
|
1094
1135
|
result => {
|
|
1095
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1136
|
+
this.logger.debug('Completed proof for padding checkpoint.');
|
|
1096
1137
|
provingState.setCheckpointPaddingProof(result);
|
|
1097
1138
|
this.checkAndEnqueueRootRollup(provingState);
|
|
1098
1139
|
},
|
|
@@ -1102,11 +1143,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1102
1143
|
// Executes the root rollup circuit
|
|
1103
1144
|
private enqueueRootRollup(provingState: EpochProvingState) {
|
|
1104
1145
|
if (!provingState.verifyState()) {
|
|
1105
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1146
|
+
this.logger.debug('Not running root rollup, state no longer valid');
|
|
1106
1147
|
return;
|
|
1107
1148
|
}
|
|
1108
1149
|
|
|
1109
|
-
logger.debug(`Preparing root rollup`);
|
|
1150
|
+
this.logger.debug(`Preparing root rollup`);
|
|
1110
1151
|
|
|
1111
1152
|
const inputs = provingState.getRootRollupInputs();
|
|
1112
1153
|
|
|
@@ -1121,7 +1162,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1121
1162
|
signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
|
|
1122
1163
|
),
|
|
1123
1164
|
result => {
|
|
1124
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1165
|
+
this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1125
1166
|
provingState.setRootRollupProof(result);
|
|
1126
1167
|
provingState.resolve({ status: 'success' });
|
|
1127
1168
|
},
|
|
@@ -1143,7 +1184,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1143
1184
|
|
|
1144
1185
|
private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
1145
1186
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1146
|
-
logger.debug('Not ready for block root rollup');
|
|
1187
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1147
1188
|
return;
|
|
1148
1189
|
}
|
|
1149
1190
|
|
|
@@ -1186,7 +1227,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1186
1227
|
|
|
1187
1228
|
private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
|
|
1188
1229
|
if (!provingState.isReadyForRootRollup()) {
|
|
1189
|
-
logger.debug('Not ready for root rollup');
|
|
1230
|
+
this.logger.debug('Not ready for root rollup');
|
|
1190
1231
|
return;
|
|
1191
1232
|
}
|
|
1192
1233
|
|
|
@@ -1201,7 +1242,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1201
1242
|
*/
|
|
1202
1243
|
private enqueueVM(provingState: BlockProvingState, txIndex: number) {
|
|
1203
1244
|
if (!provingState.verifyState()) {
|
|
1204
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1245
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1205
1246
|
return;
|
|
1206
1247
|
}
|
|
1207
1248
|
|
|
@@ -1220,7 +1261,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1220
1261
|
);
|
|
1221
1262
|
|
|
1222
1263
|
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1223
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1264
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1224
1265
|
txProvingState.setAvmProof(proof);
|
|
1225
1266
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1226
1267
|
});
|
|
@@ -1233,7 +1274,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1233
1274
|
}
|
|
1234
1275
|
|
|
1235
1276
|
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
1236
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1277
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1237
1278
|
|
|
1238
1279
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1239
1280
|
}
|