@aztec/prover-client 0.0.1-commit.e3c1de76 → 0.0.1-commit.e57c76e
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 +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -2
- package/dest/light/lightweight_checkpoint_builder.d.ts +10 -5
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +53 -22
- package/dest/mocks/test_context.d.ts +3 -1
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +18 -9
- package/dest/orchestrator/block-building-helpers.d.ts +4 -4
- 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 +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 +10 -3
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +13 -4
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +107 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +151 -0
- package/dest/orchestrator/epoch-proving-context.d.ts +51 -0
- package/dest/orchestrator/epoch-proving-context.d.ts.map +1 -0
- package/dest/orchestrator/epoch-proving-context.js +81 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +3 -3
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +5 -3
- package/dest/orchestrator/index.d.ts +4 -1
- package/dest/orchestrator/index.d.ts.map +1 -1
- package/dest/orchestrator/index.js +3 -0
- package/dest/orchestrator/orchestrator.d.ts +16 -26
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +76 -206
- package/dest/orchestrator/proving-scheduler.d.ts +72 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +117 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +83 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +182 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts +62 -0
- package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-scheduler.js +73 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-state.js +185 -0
- package/dest/prover-client/prover-client.d.ts +64 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +58 -8
- package/dest/proving_broker/broker_prover_facade.d.ts +1 -1
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +13 -19
- package/dest/proving_broker/config.d.ts +11 -67
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +16 -5
- package/dest/proving_broker/index.d.ts +2 -1
- package/dest/proving_broker/index.d.ts.map +1 -1
- package/dest/proving_broker/index.js +1 -0
- package/dest/proving_broker/proof_store/factory.d.ts +2 -5
- package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/factory.js +7 -30
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -2
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -1
- package/dest/proving_broker/proving_broker.d.ts +8 -5
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +68 -11
- package/dest/proving_broker/proving_broker_database/persisted.js +2 -2
- 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 +7 -0
- package/dest/proving_broker/rpc.d.ts +6 -2
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +87 -23
- package/dest/test/mock_prover.d.ts +4 -4
- package/package.json +18 -19
- package/src/config.ts +18 -2
- package/src/light/lightweight_checkpoint_builder.ts +56 -25
- package/src/mocks/test_context.ts +13 -10
- package/src/orchestrator/block-building-helpers.ts +2 -2
- package/src/orchestrator/block-proving-state.ts +9 -0
- package/src/orchestrator/checkpoint-proving-state.ts +18 -5
- package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +271 -0
- package/src/orchestrator/epoch-proving-context.ts +101 -0
- package/src/orchestrator/epoch-proving-state.ts +6 -4
- package/src/orchestrator/index.ts +8 -0
- package/src/orchestrator/orchestrator.ts +98 -268
- package/src/orchestrator/proving-scheduler.ts +156 -0
- package/src/orchestrator/top-tree-orchestrator.ts +314 -0
- package/src/orchestrator/top-tree-proving-scheduler.ts +154 -0
- package/src/orchestrator/top-tree-proving-state.ts +220 -0
- package/src/prover-client/prover-client.ts +132 -9
- package/src/proving_broker/broker_prover_facade.ts +17 -20
- package/src/proving_broker/config.ts +16 -2
- package/src/proving_broker/index.ts +1 -0
- package/src/proving_broker/proof_store/factory.ts +10 -32
- package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
- package/src/proving_broker/proof_store/index.ts +1 -1
- package/src/proving_broker/proving_broker.ts +64 -8
- package/src/proving_broker/proving_broker_database/persisted.ts +2 -2
- package/src/proving_broker/proving_broker_instrumentation.ts +9 -0
- package/src/proving_broker/rpc.ts +46 -20
- 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/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
|
@@ -3,14 +3,11 @@ import {
|
|
|
3
3
|
L1_TO_L2_MSG_SUBTREE_HEIGHT,
|
|
4
4
|
L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
5
|
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
6
|
-
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
7
6
|
NUM_BASE_PARITY_PER_ROOT_PARITY,
|
|
8
7
|
} from '@aztec/constants';
|
|
9
8
|
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
10
|
-
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
11
9
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
|
-
import {
|
|
13
|
-
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
10
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
14
11
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
15
12
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
16
13
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
@@ -25,6 +22,7 @@ import type {
|
|
|
25
22
|
ReadonlyWorldStateAccess,
|
|
26
23
|
ServerCircuitProver,
|
|
27
24
|
} from '@aztec/stdlib/interfaces/server';
|
|
25
|
+
import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
28
26
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
29
27
|
import {
|
|
30
28
|
type BaseRollupHints,
|
|
@@ -69,13 +67,9 @@ import type { BlockProvingState } from './block-proving-state.js';
|
|
|
69
67
|
import type { CheckpointProvingState } from './checkpoint-proving-state.js';
|
|
70
68
|
import { EpochProvingState, type ProvingResult, type TreeSnapshots } from './epoch-proving-state.js';
|
|
71
69
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
70
|
+
import { TopTreeProvingScheduler } from './top-tree-proving-scheduler.js';
|
|
72
71
|
import { TxProvingState } from './tx-proving-state.js';
|
|
73
72
|
|
|
74
|
-
type WorldStateFork = {
|
|
75
|
-
fork: MerkleTreeWriteOperations;
|
|
76
|
-
cleanupPromise: Promise<void> | undefined;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
73
|
/**
|
|
80
74
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
81
75
|
* 1. Transactions are provided to the scheduler post simulation.
|
|
@@ -90,25 +84,24 @@ type WorldStateFork = {
|
|
|
90
84
|
/**
|
|
91
85
|
* The orchestrator, managing the flow of recursive proving operations required to build the rollup proof tree.
|
|
92
86
|
*/
|
|
93
|
-
export class ProvingOrchestrator implements EpochProver {
|
|
94
|
-
|
|
95
|
-
private pendingProvingJobs: AbortController[] = [];
|
|
87
|
+
export class ProvingOrchestrator extends TopTreeProvingScheduler implements EpochProver {
|
|
88
|
+
protected provingState: EpochProvingState | undefined = undefined;
|
|
96
89
|
|
|
97
|
-
|
|
90
|
+
protected provingPromise: Promise<ProvingResult> | undefined = undefined;
|
|
98
91
|
private metrics: ProvingOrchestratorMetrics;
|
|
99
|
-
|
|
100
|
-
private dbs: Map<BlockNumber,
|
|
101
|
-
private logger: Logger;
|
|
92
|
+
|
|
93
|
+
private dbs: Map<BlockNumber, MerkleTreeWriteOperations> = new Map();
|
|
102
94
|
|
|
103
95
|
constructor(
|
|
104
96
|
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
105
|
-
|
|
97
|
+
prover: ServerCircuitProver,
|
|
106
98
|
private readonly proverId: EthAddress,
|
|
107
99
|
private readonly cancelJobsOnStop: boolean = false,
|
|
100
|
+
enqueueConcurrency: number,
|
|
108
101
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
109
102
|
bindings?: LoggerBindings,
|
|
110
103
|
) {
|
|
111
|
-
|
|
104
|
+
super(prover, enqueueConcurrency, 'prover-client:orchestrator', bindings);
|
|
112
105
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
113
106
|
}
|
|
114
107
|
|
|
@@ -124,9 +117,24 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
124
117
|
return this.dbs.size;
|
|
125
118
|
}
|
|
126
119
|
|
|
127
|
-
|
|
120
|
+
protected override cancelInternal(): void {
|
|
128
121
|
this.cancel();
|
|
129
|
-
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
protected override wrapCircuitCall<T>(
|
|
125
|
+
circuitName: string,
|
|
126
|
+
fn: (signal: AbortSignal) => Promise<T>,
|
|
127
|
+
): (signal: AbortSignal) => Promise<T> {
|
|
128
|
+
return wrapCallbackInSpan(
|
|
129
|
+
this.tracer,
|
|
130
|
+
`ProvingOrchestrator.prover.${circuitName}`,
|
|
131
|
+
{ [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName as CircuitName },
|
|
132
|
+
fn,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected override onRootRollupComplete(state: EpochProvingState) {
|
|
137
|
+
state.resolve({ status: 'success' });
|
|
130
138
|
}
|
|
131
139
|
|
|
132
140
|
public startNewEpoch(
|
|
@@ -182,7 +190,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
182
190
|
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
183
191
|
|
|
184
192
|
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
185
|
-
this.dbs.set(firstBlockNumber,
|
|
193
|
+
this.dbs.set(firstBlockNumber, db);
|
|
186
194
|
|
|
187
195
|
// Get archive sibling path before any block in this checkpoint lands.
|
|
188
196
|
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
@@ -240,9 +248,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
240
248
|
if (!this.dbs.has(blockNumber)) {
|
|
241
249
|
// Fork world state at the end of the immediately previous block
|
|
242
250
|
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
243
|
-
this.dbs.set(blockNumber,
|
|
251
|
+
this.dbs.set(blockNumber, db);
|
|
244
252
|
}
|
|
245
|
-
const db = this.
|
|
253
|
+
const db = this.getDbForBlock(blockNumber);
|
|
246
254
|
|
|
247
255
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
248
256
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
@@ -317,7 +325,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
317
325
|
|
|
318
326
|
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
319
327
|
|
|
320
|
-
const db = this.
|
|
328
|
+
const db = this.getDbForBlock(blockNumber);
|
|
321
329
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
322
330
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
323
331
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -445,14 +453,20 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
445
453
|
throw new Error('Block header mismatch');
|
|
446
454
|
}
|
|
447
455
|
|
|
448
|
-
// Get db for this block
|
|
449
|
-
const db = this.
|
|
456
|
+
// Get db for this block and remove from map — no other code should use it after this point.
|
|
457
|
+
const db = this.getDbForBlock(provingState.blockNumber);
|
|
458
|
+
this.dbs.delete(provingState.blockNumber);
|
|
450
459
|
|
|
451
|
-
// Update the archive tree,
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
460
|
+
// Update the archive tree, capture the snapshot, and close the fork deterministically.
|
|
461
|
+
try {
|
|
462
|
+
this.logger.verbose(
|
|
463
|
+
`Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`,
|
|
464
|
+
);
|
|
465
|
+
await db.updateArchive(header);
|
|
466
|
+
provingState.setBuiltArchive(await getTreeSnapshot(MerkleTreeId.ARCHIVE, db));
|
|
467
|
+
} finally {
|
|
468
|
+
await db.close();
|
|
469
|
+
}
|
|
456
470
|
|
|
457
471
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
458
472
|
|
|
@@ -472,6 +486,13 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
472
486
|
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
473
487
|
return;
|
|
474
488
|
}
|
|
489
|
+
|
|
490
|
+
const newArchive = provingState.getBuiltArchive();
|
|
491
|
+
if (!newArchive) {
|
|
492
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
|
|
475
496
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
476
497
|
|
|
477
498
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
@@ -480,11 +501,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
480
501
|
return;
|
|
481
502
|
}
|
|
482
503
|
|
|
483
|
-
// Get db for this block
|
|
484
504
|
const blockNumber = provingState.blockNumber;
|
|
485
|
-
const db = this.dbs.get(blockNumber)!.fork;
|
|
486
|
-
|
|
487
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
488
505
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
489
506
|
if (!syncedArchive.equals(newArchive)) {
|
|
490
507
|
this.logger.error(
|
|
@@ -502,12 +519,6 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
502
519
|
provingState.reject(`New archive mismatch.`);
|
|
503
520
|
return;
|
|
504
521
|
}
|
|
505
|
-
|
|
506
|
-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
|
|
507
|
-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
508
|
-
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
509
|
-
// will attempt to access the fork after it was closed.
|
|
510
|
-
void this.cleanupDBFork(blockNumber);
|
|
511
522
|
}
|
|
512
523
|
|
|
513
524
|
/**
|
|
@@ -516,13 +527,22 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
516
527
|
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
517
528
|
*/
|
|
518
529
|
public cancel() {
|
|
519
|
-
|
|
520
|
-
for (const controller of this.pendingProvingJobs) {
|
|
521
|
-
controller.abort();
|
|
522
|
-
}
|
|
523
|
-
}
|
|
530
|
+
this.resetSchedulerState(this.cancelJobsOnStop);
|
|
524
531
|
|
|
525
532
|
this.provingState?.cancel();
|
|
533
|
+
|
|
534
|
+
for (const [blockNumber, db] of this.dbs.entries()) {
|
|
535
|
+
void db.close().catch(err => this.logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
536
|
+
}
|
|
537
|
+
this.dbs.clear();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
private getDbForBlock(blockNumber: BlockNumber): MerkleTreeWriteOperations {
|
|
541
|
+
const db = this.dbs.get(blockNumber);
|
|
542
|
+
if (!db) {
|
|
543
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
544
|
+
}
|
|
545
|
+
return db;
|
|
526
546
|
}
|
|
527
547
|
|
|
528
548
|
/**
|
|
@@ -554,94 +574,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
554
574
|
return epochProofResult;
|
|
555
575
|
}
|
|
556
576
|
|
|
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
|
-
|
|
575
|
-
/**
|
|
576
|
-
* Enqueue a job to be scheduled
|
|
577
|
-
* @param provingState - The proving state object being operated on
|
|
578
|
-
* @param jobType - The type of job to be queued
|
|
579
|
-
* @param job - The actual job, returns a promise notifying of the job's completion
|
|
580
|
-
*/
|
|
581
|
-
private deferredProving<T>(
|
|
582
|
-
provingState: EpochProvingState | CheckpointProvingState | BlockProvingState,
|
|
583
|
-
request: (signal: AbortSignal) => Promise<T>,
|
|
584
|
-
callback: (result: T) => void | Promise<void>,
|
|
585
|
-
) {
|
|
586
|
-
if (!provingState.verifyState()) {
|
|
587
|
-
this.logger.debug(`Not enqueuing job, state no longer valid`);
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
const controller = new AbortController();
|
|
592
|
-
this.pendingProvingJobs.push(controller);
|
|
593
|
-
|
|
594
|
-
// We use a 'safeJob'. We don't want promise rejections in the proving pool, we want to capture the error here
|
|
595
|
-
// and reject the proving job whilst keeping the event loop free of rejections
|
|
596
|
-
const safeJob = async () => {
|
|
597
|
-
try {
|
|
598
|
-
// there's a delay between enqueueing this job and it actually running
|
|
599
|
-
if (controller.signal.aborted) {
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
const result = await request(controller.signal);
|
|
604
|
-
if (!provingState.verifyState()) {
|
|
605
|
-
this.logger.debug(`State no longer valid, discarding result`);
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
// we could have been cancelled whilst waiting for the result
|
|
610
|
-
// and the prover ignored the signal. Drop the result in that case
|
|
611
|
-
if (controller.signal.aborted) {
|
|
612
|
-
return;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
await callback(result);
|
|
616
|
-
} catch (err) {
|
|
617
|
-
if (err instanceof AbortError) {
|
|
618
|
-
// operation was cancelled, probably because the block was cancelled
|
|
619
|
-
// drop this result
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
this.logger.error(`Error thrown when proving job`, err);
|
|
624
|
-
provingState!.reject(`${err}`);
|
|
625
|
-
} finally {
|
|
626
|
-
const index = this.pendingProvingJobs.indexOf(controller);
|
|
627
|
-
if (index > -1) {
|
|
628
|
-
this.pendingProvingJobs.splice(index, 1);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
// let the callstack unwind before adding the job to the queue
|
|
634
|
-
setImmediate(() => void safeJob());
|
|
635
|
-
}
|
|
636
|
-
|
|
637
577
|
private async updateL1ToL2MessageTree(l1ToL2Messages: Fr[], db: MerkleTreeWriteOperations) {
|
|
638
|
-
const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(
|
|
639
|
-
l1ToL2Messages,
|
|
640
|
-
Fr.ZERO,
|
|
641
|
-
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
642
|
-
'Too many L1 to L2 messages',
|
|
643
|
-
);
|
|
644
|
-
|
|
645
578
|
const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
646
579
|
const lastL1ToL2MessageSubtreeRootSiblingPath = assertLength(
|
|
647
580
|
await getSubtreeSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, db),
|
|
@@ -649,7 +582,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
649
582
|
);
|
|
650
583
|
|
|
651
584
|
// Update the local trees to include the new l1 to l2 messages
|
|
652
|
-
await db
|
|
585
|
+
await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
|
|
653
586
|
|
|
654
587
|
const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
655
588
|
const newL1ToL2MessageSubtreeRootSiblingPath = assertLength(
|
|
@@ -756,7 +689,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
756
689
|
|
|
757
690
|
// Enqueues the public chonk verifier circuit for a given transaction index, or reuses the one already enqueued.
|
|
758
691
|
// Once completed, will enqueue the the public tx base rollup.
|
|
759
|
-
|
|
692
|
+
protected getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
|
|
760
693
|
if (!provingState.verifyState()) {
|
|
761
694
|
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
762
695
|
return;
|
|
@@ -764,7 +697,6 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
764
697
|
|
|
765
698
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
766
699
|
const txHash = txProvingState.processedTx.hash.toString();
|
|
767
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH;
|
|
768
700
|
const handleResult = (
|
|
769
701
|
result: PublicInputsAndRecursiveProof<
|
|
770
702
|
PublicChonkVerifierPublicInputs,
|
|
@@ -889,22 +821,24 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
889
821
|
},
|
|
890
822
|
),
|
|
891
823
|
async result => {
|
|
892
|
-
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}
|
|
824
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`, {
|
|
825
|
+
blockNumber: provingState.blockNumber,
|
|
826
|
+
checkpointIndex: provingState.parentCheckpoint.index,
|
|
827
|
+
...result.inputs.toInspect(),
|
|
828
|
+
});
|
|
893
829
|
|
|
894
830
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
895
831
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
896
832
|
|
|
897
|
-
//
|
|
833
|
+
// Verification is called from both here and setBlockCompleted. Whichever runs last
|
|
834
|
+
// will be the first to see all three pieces (header, proof output, archive) and run the checks.
|
|
898
835
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
899
836
|
|
|
900
837
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
901
|
-
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
838
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
902
839
|
} else {
|
|
903
|
-
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
840
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
904
841
|
}
|
|
905
|
-
|
|
906
|
-
// We are finished with the block at this point, ensure the fork is cleaned up
|
|
907
|
-
void this.cleanupDBFork(provingState.blockNumber);
|
|
908
842
|
},
|
|
909
843
|
);
|
|
910
844
|
}
|
|
@@ -1009,14 +943,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1009
943
|
},
|
|
1010
944
|
signal => this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1011
945
|
),
|
|
1012
|
-
result => {
|
|
946
|
+
async result => {
|
|
947
|
+
this.logger.debug(`Completed block merge rollup proof for checkpoint ${provingState.index}`, {
|
|
948
|
+
checkpointIndex: provingState.index,
|
|
949
|
+
mergeLocation: location,
|
|
950
|
+
...result.inputs.toInspect(),
|
|
951
|
+
});
|
|
1013
952
|
provingState.setBlockMergeRollupProof(location, result);
|
|
1014
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
953
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1015
954
|
},
|
|
1016
955
|
);
|
|
1017
956
|
}
|
|
1018
957
|
|
|
1019
|
-
private enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
958
|
+
private async enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1020
959
|
if (!provingState.verifyState()) {
|
|
1021
960
|
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1022
961
|
return;
|
|
@@ -1031,7 +970,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1031
970
|
|
|
1032
971
|
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1033
972
|
|
|
1034
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
973
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
1035
974
|
|
|
1036
975
|
this.deferredProving(
|
|
1037
976
|
provingState,
|
|
@@ -1062,7 +1001,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1062
1001
|
return;
|
|
1063
1002
|
}
|
|
1064
1003
|
|
|
1065
|
-
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}
|
|
1004
|
+
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}`, {
|
|
1005
|
+
checkpointIndex: provingState.index,
|
|
1006
|
+
...result.inputs.toInspect(),
|
|
1007
|
+
});
|
|
1066
1008
|
|
|
1067
1009
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1068
1010
|
const epochProvingState = provingState.parentEpoch;
|
|
@@ -1076,99 +1018,6 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1076
1018
|
);
|
|
1077
1019
|
}
|
|
1078
1020
|
|
|
1079
|
-
private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
|
|
1080
|
-
if (!provingState.verifyState()) {
|
|
1081
|
-
this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1082
|
-
return;
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1086
|
-
this.logger.debug('Checkpoint merge rollup already started.');
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
const inputs = provingState.getCheckpointMergeRollupInputs(location);
|
|
1091
|
-
|
|
1092
|
-
this.deferredProving(
|
|
1093
|
-
provingState,
|
|
1094
|
-
wrapCallbackInSpan(
|
|
1095
|
-
this.tracer,
|
|
1096
|
-
'ProvingOrchestrator.prover.getCheckpointMergeRollupProof',
|
|
1097
|
-
{
|
|
1098
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge' satisfies CircuitName,
|
|
1099
|
-
},
|
|
1100
|
-
signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1101
|
-
),
|
|
1102
|
-
result => {
|
|
1103
|
-
this.logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1104
|
-
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1105
|
-
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1106
|
-
},
|
|
1107
|
-
);
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
private enqueueEpochPadding(provingState: EpochProvingState) {
|
|
1111
|
-
if (!provingState.verifyState()) {
|
|
1112
|
-
this.logger.debug('Not running epoch padding. State no longer valid.');
|
|
1113
|
-
return;
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1117
|
-
this.logger.debug('Padding checkpoint already started.');
|
|
1118
|
-
return;
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
this.logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1122
|
-
|
|
1123
|
-
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1124
|
-
|
|
1125
|
-
this.deferredProving(
|
|
1126
|
-
provingState,
|
|
1127
|
-
wrapCallbackInSpan(
|
|
1128
|
-
this.tracer,
|
|
1129
|
-
'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof',
|
|
1130
|
-
{
|
|
1131
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding' satisfies CircuitName,
|
|
1132
|
-
},
|
|
1133
|
-
signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
|
|
1134
|
-
),
|
|
1135
|
-
result => {
|
|
1136
|
-
this.logger.debug('Completed proof for padding checkpoint.');
|
|
1137
|
-
provingState.setCheckpointPaddingProof(result);
|
|
1138
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1139
|
-
},
|
|
1140
|
-
);
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// Executes the root rollup circuit
|
|
1144
|
-
private enqueueRootRollup(provingState: EpochProvingState) {
|
|
1145
|
-
if (!provingState.verifyState()) {
|
|
1146
|
-
this.logger.debug('Not running root rollup, state no longer valid');
|
|
1147
|
-
return;
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
this.logger.debug(`Preparing root rollup`);
|
|
1151
|
-
|
|
1152
|
-
const inputs = provingState.getRootRollupInputs();
|
|
1153
|
-
|
|
1154
|
-
this.deferredProving(
|
|
1155
|
-
provingState,
|
|
1156
|
-
wrapCallbackInSpan(
|
|
1157
|
-
this.tracer,
|
|
1158
|
-
'ProvingOrchestrator.prover.getRootRollupProof',
|
|
1159
|
-
{
|
|
1160
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root' satisfies CircuitName,
|
|
1161
|
-
},
|
|
1162
|
-
signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
|
|
1163
|
-
),
|
|
1164
|
-
result => {
|
|
1165
|
-
this.logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1166
|
-
provingState.setRootRollupProof(result);
|
|
1167
|
-
provingState.resolve({ status: 'success' });
|
|
1168
|
-
},
|
|
1169
|
-
);
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
1021
|
private checkAndEnqueueNextMergeRollup(provingState: BlockProvingState, currentLocation: TreeNodeLocation) {
|
|
1173
1022
|
if (!provingState.isReadyForMergeRollup(currentLocation)) {
|
|
1174
1023
|
return;
|
|
@@ -1191,47 +1040,28 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1191
1040
|
this.enqueueBlockRootRollup(provingState);
|
|
1192
1041
|
}
|
|
1193
1042
|
|
|
1194
|
-
private checkAndEnqueueNextBlockMergeRollup(
|
|
1043
|
+
private async checkAndEnqueueNextBlockMergeRollup(
|
|
1044
|
+
provingState: CheckpointProvingState,
|
|
1045
|
+
currentLocation: TreeNodeLocation,
|
|
1046
|
+
) {
|
|
1195
1047
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
1196
1048
|
return;
|
|
1197
1049
|
}
|
|
1198
1050
|
|
|
1199
1051
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1200
1052
|
if (parentLocation.level === 0) {
|
|
1201
|
-
this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1053
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1202
1054
|
} else {
|
|
1203
1055
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1204
1056
|
}
|
|
1205
1057
|
}
|
|
1206
1058
|
|
|
1207
|
-
|
|
1059
|
+
protected async checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1208
1060
|
if (!provingState.isReadyForCheckpointRoot()) {
|
|
1209
1061
|
return;
|
|
1210
1062
|
}
|
|
1211
1063
|
|
|
1212
|
-
this.enqueueCheckpointRootRollup(provingState);
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
private checkAndEnqueueNextCheckpointMergeRollup(provingState: EpochProvingState, currentLocation: TreeNodeLocation) {
|
|
1216
|
-
if (!provingState.isReadyForCheckpointMerge(currentLocation)) {
|
|
1217
|
-
return;
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1221
|
-
if (parentLocation.level === 0) {
|
|
1222
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1223
|
-
} else {
|
|
1224
|
-
this.enqueueCheckpointMergeRollup(provingState, parentLocation);
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
|
|
1229
|
-
if (!provingState.isReadyForRootRollup()) {
|
|
1230
|
-
this.logger.debug('Not ready for root rollup');
|
|
1231
|
-
return;
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
this.enqueueRootRollup(provingState);
|
|
1064
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
1235
1065
|
}
|
|
1236
1066
|
|
|
1237
1067
|
/**
|
|
@@ -1267,7 +1097,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1267
1097
|
});
|
|
1268
1098
|
}
|
|
1269
1099
|
|
|
1270
|
-
|
|
1100
|
+
protected checkAndEnqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
1271
1101
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1272
1102
|
if (!txProvingState.ready()) {
|
|
1273
1103
|
return;
|