@aztec/prover-client 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
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 +22 -6
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +112 -28
- 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 +6 -2
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +31 -11
- 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 +24 -4
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +47 -5
- 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 +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/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 +30 -25
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +549 -255
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -6
- 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/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 +66 -7
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +64 -11
- 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 +16 -22
- package/dest/proving_broker/config.d.ts +12 -64
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +22 -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_agent.d.ts +5 -9
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -19
- package/dest/proving_broker/proving_broker.d.ts +8 -5
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +69 -21
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +391 -3
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
- package/dest/proving_broker/proving_job_controller.d.ts +4 -3
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +6 -3
- 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_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 +3 -3
- package/package.json +19 -21
- package/src/config.ts +18 -2
- package/src/light/lightweight_checkpoint_builder.ts +159 -37
- package/src/mocks/fixtures.ts +2 -1
- package/src/mocks/test_context.ts +24 -11
- 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 +65 -6
- 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 +59 -9
- package/src/orchestrator/index.ts +8 -0
- package/src/orchestrator/orchestrator.ts +165 -293
- package/src/orchestrator/orchestrator_metrics.ts +2 -6
- 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/orchestrator/tx-proving-state.ts +8 -11
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +157 -24
- package/src/proving_broker/broker_prover_facade.ts +25 -26
- package/src/proving_broker/config.ts +25 -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_agent.ts +6 -19
- package/src/proving_broker/proving_broker.ts +65 -16
- package/src/proving_broker/proving_broker_database/persisted.ts +17 -3
- package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
- package/src/proving_broker/proving_job_controller.ts +9 -3
- package/src/proving_broker/rpc.ts +46 -20
- package/src/test/mock_prover.ts +1 -8
- 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
|
@@ -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 { 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';
|
|
@@ -22,8 +19,10 @@ import type {
|
|
|
22
19
|
ForkMerkleTreeOperations,
|
|
23
20
|
MerkleTreeWriteOperations,
|
|
24
21
|
PublicInputsAndRecursiveProof,
|
|
22
|
+
ReadonlyWorldStateAccess,
|
|
25
23
|
ServerCircuitProver,
|
|
26
24
|
} from '@aztec/stdlib/interfaces/server';
|
|
25
|
+
import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
27
26
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
28
27
|
import {
|
|
29
28
|
type BaseRollupHints,
|
|
@@ -68,10 +67,9 @@ import type { BlockProvingState } from './block-proving-state.js';
|
|
|
68
67
|
import type { CheckpointProvingState } from './checkpoint-proving-state.js';
|
|
69
68
|
import { EpochProvingState, type ProvingResult, type TreeSnapshots } from './epoch-proving-state.js';
|
|
70
69
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
70
|
+
import { TopTreeProvingScheduler } from './top-tree-proving-scheduler.js';
|
|
71
71
|
import { TxProvingState } from './tx-proving-state.js';
|
|
72
72
|
|
|
73
|
-
const logger = createLogger('prover-client:orchestrator');
|
|
74
|
-
|
|
75
73
|
/**
|
|
76
74
|
* Implements an event driven proving scheduler to build the recursive proof tree. The idea being:
|
|
77
75
|
* 1. Transactions are provided to the scheduler post simulation.
|
|
@@ -86,21 +84,24 @@ const logger = createLogger('prover-client:orchestrator');
|
|
|
86
84
|
/**
|
|
87
85
|
* The orchestrator, managing the flow of recursive proving operations required to build the rollup proof tree.
|
|
88
86
|
*/
|
|
89
|
-
export class ProvingOrchestrator implements EpochProver {
|
|
90
|
-
|
|
91
|
-
private pendingProvingJobs: AbortController[] = [];
|
|
87
|
+
export class ProvingOrchestrator extends TopTreeProvingScheduler implements EpochProver {
|
|
88
|
+
protected provingState: EpochProvingState | undefined = undefined;
|
|
92
89
|
|
|
93
|
-
|
|
90
|
+
protected provingPromise: Promise<ProvingResult> | undefined = undefined;
|
|
94
91
|
private metrics: ProvingOrchestratorMetrics;
|
|
95
|
-
|
|
92
|
+
|
|
96
93
|
private dbs: Map<BlockNumber, MerkleTreeWriteOperations> = new Map();
|
|
97
94
|
|
|
98
95
|
constructor(
|
|
99
|
-
private dbProvider: ForkMerkleTreeOperations,
|
|
100
|
-
|
|
96
|
+
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
97
|
+
prover: ServerCircuitProver,
|
|
101
98
|
private readonly proverId: EthAddress,
|
|
99
|
+
private readonly cancelJobsOnStop: boolean = false,
|
|
100
|
+
enqueueConcurrency: number,
|
|
102
101
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
102
|
+
bindings?: LoggerBindings,
|
|
103
103
|
) {
|
|
104
|
+
super(prover, enqueueConcurrency, 'prover-client:orchestrator', bindings);
|
|
104
105
|
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'ProvingOrchestrator');
|
|
105
106
|
}
|
|
106
107
|
|
|
@@ -112,9 +113,28 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
112
113
|
return this.proverId;
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
public
|
|
116
|
+
public getNumActiveForks() {
|
|
117
|
+
return this.dbs.size;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
protected override cancelInternal(): void {
|
|
116
121
|
this.cancel();
|
|
117
|
-
|
|
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' });
|
|
118
138
|
}
|
|
119
139
|
|
|
120
140
|
public startNewEpoch(
|
|
@@ -130,7 +150,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
130
150
|
|
|
131
151
|
const { promise: _promise, resolve, reject } = promiseWithResolvers<ProvingResult>();
|
|
132
152
|
const promise = _promise.catch((reason): ProvingResult => ({ status: 'failure', reason }));
|
|
133
|
-
logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
153
|
+
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
134
154
|
this.provingState = new EpochProvingState(
|
|
135
155
|
epochNumber,
|
|
136
156
|
totalNumCheckpoints,
|
|
@@ -142,6 +162,14 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
142
162
|
this.provingPromise = promise;
|
|
143
163
|
}
|
|
144
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Starts a new checkpoint.
|
|
167
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
168
|
+
* @param constants - The constants for this checkpoint.
|
|
169
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
170
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
171
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
172
|
+
*/
|
|
145
173
|
public async startNewCheckpoint(
|
|
146
174
|
checkpointIndex: number,
|
|
147
175
|
constants: CheckpointConstantData,
|
|
@@ -214,7 +242,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
214
242
|
}
|
|
215
243
|
|
|
216
244
|
const constants = checkpointProvingState.constants;
|
|
217
|
-
logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
245
|
+
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
218
246
|
|
|
219
247
|
// Fork the db only when it's not already set. The db for the first block is set in `startNewCheckpoint`.
|
|
220
248
|
if (!this.dbs.has(blockNumber)) {
|
|
@@ -222,7 +250,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
222
250
|
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
223
251
|
this.dbs.set(blockNumber, db);
|
|
224
252
|
}
|
|
225
|
-
const db = this.
|
|
253
|
+
const db = this.getDbForBlock(blockNumber);
|
|
226
254
|
|
|
227
255
|
// Get archive snapshot and sibling path before any txs in this block lands.
|
|
228
256
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
@@ -254,7 +282,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
254
282
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
255
283
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
256
284
|
|
|
257
|
-
//
|
|
285
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
286
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
258
287
|
await this.provingState.setBlobAccumulators();
|
|
259
288
|
}
|
|
260
289
|
}
|
|
@@ -274,7 +303,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
274
303
|
if (!txs.length) {
|
|
275
304
|
// To avoid an ugly throw below. If we require an empty block, we can just call setBlockCompleted
|
|
276
305
|
// on a block with no txs. We cannot do that here because we cannot find the blockNumber without any txs.
|
|
277
|
-
logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
306
|
+
this.logger.warn(`Provided no txs to orchestrator addTxs.`);
|
|
278
307
|
return;
|
|
279
308
|
}
|
|
280
309
|
|
|
@@ -294,9 +323,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
294
323
|
throw new Error(`Block ${blockNumber} has been initialized with transactions.`);
|
|
295
324
|
}
|
|
296
325
|
|
|
297
|
-
logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
326
|
+
this.logger.info(`Adding ${txs.length} transactions to block ${blockNumber}`);
|
|
298
327
|
|
|
299
|
-
const db = this.
|
|
328
|
+
const db = this.getDbForBlock(blockNumber);
|
|
300
329
|
const lastArchive = provingState.lastArchiveTreeSnapshot;
|
|
301
330
|
const newL1ToL2MessageTreeSnapshot = provingState.newL1ToL2MessageTreeSnapshot;
|
|
302
331
|
const spongeBlobState = provingState.getStartSpongeBlob().clone();
|
|
@@ -309,7 +338,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
309
338
|
|
|
310
339
|
validateTx(tx);
|
|
311
340
|
|
|
312
|
-
logger.
|
|
341
|
+
this.logger.debug(`Received transaction: ${tx.hash}`);
|
|
313
342
|
|
|
314
343
|
const startSpongeBlob = spongeBlobState.clone();
|
|
315
344
|
const [hints, treeSnapshots] = await this.prepareBaseRollupInputs(
|
|
@@ -330,10 +359,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
330
359
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
331
360
|
if (txProvingState.requireAvmProof) {
|
|
332
361
|
this.getOrEnqueueChonkVerifier(provingState, txIndex);
|
|
333
|
-
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
362
|
+
this.logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
334
363
|
this.enqueueVM(provingState, txIndex);
|
|
335
364
|
} else {
|
|
336
|
-
logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
365
|
+
this.logger.debug(`Enqueueing base rollup for private-only tx ${txIndex}`);
|
|
337
366
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
338
367
|
}
|
|
339
368
|
} catch (err: any) {
|
|
@@ -351,7 +380,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
351
380
|
|
|
352
381
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
353
382
|
|
|
354
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
383
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
384
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
355
385
|
await this.provingState.setBlobAccumulators();
|
|
356
386
|
}
|
|
357
387
|
|
|
@@ -375,7 +405,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
375
405
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
376
406
|
>
|
|
377
407
|
>();
|
|
378
|
-
logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
408
|
+
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
379
409
|
this.doEnqueueChonkVerifier(txHash, privateInputs, proof => {
|
|
380
410
|
tubeProof.resolve(proof);
|
|
381
411
|
});
|
|
@@ -415,22 +445,28 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
415
445
|
}
|
|
416
446
|
|
|
417
447
|
// Given we've applied every change from this block, now assemble the block header:
|
|
418
|
-
logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
448
|
+
this.logger.verbose(`Block ${blockNumber} completed. Assembling header.`);
|
|
419
449
|
const header = await provingState.buildBlockHeader();
|
|
420
450
|
|
|
421
451
|
if (expectedHeader && !header.equals(expectedHeader)) {
|
|
422
|
-
logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
452
|
+
this.logger.error(`Block header mismatch: header=${header} expectedHeader=${expectedHeader}`);
|
|
423
453
|
throw new Error('Block header mismatch');
|
|
424
454
|
}
|
|
425
455
|
|
|
426
|
-
// Get db for this block
|
|
427
|
-
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);
|
|
428
459
|
|
|
429
|
-
// Update the archive tree,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
+
}
|
|
434
470
|
|
|
435
471
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
436
472
|
|
|
@@ -441,31 +477,34 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
441
477
|
protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
|
|
442
478
|
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
443
479
|
if (!builtBlockHeader) {
|
|
444
|
-
logger.debug('Block header not built yet, skipping header check.');
|
|
480
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
445
481
|
return;
|
|
446
482
|
}
|
|
447
483
|
|
|
448
484
|
const output = provingState.getBlockRootRollupOutput();
|
|
449
485
|
if (!output) {
|
|
450
|
-
logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
486
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
const newArchive = provingState.getBuiltArchive();
|
|
491
|
+
if (!newArchive) {
|
|
492
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
451
493
|
return;
|
|
452
494
|
}
|
|
495
|
+
|
|
453
496
|
const header = await buildHeaderFromCircuitOutputs(output);
|
|
454
497
|
|
|
455
498
|
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
456
|
-
logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
499
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
457
500
|
provingState.reject(`Block header hash mismatch.`);
|
|
458
501
|
return;
|
|
459
502
|
}
|
|
460
503
|
|
|
461
|
-
// Get db for this block
|
|
462
504
|
const blockNumber = provingState.blockNumber;
|
|
463
|
-
const db = this.dbs.get(blockNumber)!;
|
|
464
|
-
|
|
465
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
466
505
|
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
467
506
|
if (!syncedArchive.equals(newArchive)) {
|
|
468
|
-
logger.error(
|
|
507
|
+
this.logger.error(
|
|
469
508
|
`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
|
|
470
509
|
syncedArchive,
|
|
471
510
|
)} but built ${inspect(newArchive)}`,
|
|
@@ -476,32 +515,34 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
476
515
|
|
|
477
516
|
const circuitArchive = output.newArchive;
|
|
478
517
|
if (!newArchive.equals(circuitArchive)) {
|
|
479
|
-
logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
518
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
480
519
|
provingState.reject(`New archive mismatch.`);
|
|
481
520
|
return;
|
|
482
521
|
}
|
|
483
|
-
|
|
484
|
-
// TODO(palla/prover): This closes the fork only on the happy path. If this epoch orchestrator
|
|
485
|
-
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
486
|
-
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
487
|
-
// will attempt to access the fork after it was closed.
|
|
488
|
-
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
489
|
-
void this.dbs
|
|
490
|
-
.get(blockNumber)
|
|
491
|
-
?.close()
|
|
492
|
-
.then(() => this.dbs.delete(blockNumber))
|
|
493
|
-
.catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
494
522
|
}
|
|
495
523
|
|
|
496
524
|
/**
|
|
497
|
-
* Cancel any further proving
|
|
525
|
+
* Cancel any further proving.
|
|
526
|
+
* If cancelJobsOnStop is true, aborts all pending jobs with the broker (which marks them as 'Aborted').
|
|
527
|
+
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
498
528
|
*/
|
|
499
529
|
public cancel() {
|
|
500
|
-
|
|
501
|
-
controller.abort();
|
|
502
|
-
}
|
|
530
|
+
this.resetSchedulerState(this.cancelJobsOnStop);
|
|
503
531
|
|
|
504
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;
|
|
505
546
|
}
|
|
506
547
|
|
|
507
548
|
/**
|
|
@@ -533,76 +574,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
533
574
|
return epochProofResult;
|
|
534
575
|
}
|
|
535
576
|
|
|
536
|
-
/**
|
|
537
|
-
* Enqueue a job to be scheduled
|
|
538
|
-
* @param provingState - The proving state object being operated on
|
|
539
|
-
* @param jobType - The type of job to be queued
|
|
540
|
-
* @param job - The actual job, returns a promise notifying of the job's completion
|
|
541
|
-
*/
|
|
542
|
-
private deferredProving<T>(
|
|
543
|
-
provingState: EpochProvingState | CheckpointProvingState | BlockProvingState,
|
|
544
|
-
request: (signal: AbortSignal) => Promise<T>,
|
|
545
|
-
callback: (result: T) => void | Promise<void>,
|
|
546
|
-
) {
|
|
547
|
-
if (!provingState.verifyState()) {
|
|
548
|
-
logger.debug(`Not enqueuing job, state no longer valid`);
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
const controller = new AbortController();
|
|
553
|
-
this.pendingProvingJobs.push(controller);
|
|
554
|
-
|
|
555
|
-
// We use a 'safeJob'. We don't want promise rejections in the proving pool, we want to capture the error here
|
|
556
|
-
// and reject the proving job whilst keeping the event loop free of rejections
|
|
557
|
-
const safeJob = async () => {
|
|
558
|
-
try {
|
|
559
|
-
// there's a delay between enqueueing this job and it actually running
|
|
560
|
-
if (controller.signal.aborted) {
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
const result = await request(controller.signal);
|
|
565
|
-
if (!provingState.verifyState()) {
|
|
566
|
-
logger.debug(`State no longer valid, discarding result`);
|
|
567
|
-
return;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// we could have been cancelled whilst waiting for the result
|
|
571
|
-
// and the prover ignored the signal. Drop the result in that case
|
|
572
|
-
if (controller.signal.aborted) {
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
await callback(result);
|
|
577
|
-
} catch (err) {
|
|
578
|
-
if (err instanceof AbortError) {
|
|
579
|
-
// operation was cancelled, probably because the block was cancelled
|
|
580
|
-
// drop this result
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
logger.error(`Error thrown when proving job`, err);
|
|
585
|
-
provingState!.reject(`${err}`);
|
|
586
|
-
} finally {
|
|
587
|
-
const index = this.pendingProvingJobs.indexOf(controller);
|
|
588
|
-
if (index > -1) {
|
|
589
|
-
this.pendingProvingJobs.splice(index, 1);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
// let the callstack unwind before adding the job to the queue
|
|
595
|
-
setImmediate(() => void safeJob());
|
|
596
|
-
}
|
|
597
|
-
|
|
598
577
|
private async updateL1ToL2MessageTree(l1ToL2Messages: Fr[], db: MerkleTreeWriteOperations) {
|
|
599
|
-
const l1ToL2MessagesPadded = padArrayEnd<Fr, number>(
|
|
600
|
-
l1ToL2Messages,
|
|
601
|
-
Fr.ZERO,
|
|
602
|
-
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
603
|
-
'Too many L1 to L2 messages',
|
|
604
|
-
);
|
|
605
|
-
|
|
606
578
|
const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
607
579
|
const lastL1ToL2MessageSubtreeRootSiblingPath = assertLength(
|
|
608
580
|
await getSubtreeSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, db),
|
|
@@ -610,7 +582,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
610
582
|
);
|
|
611
583
|
|
|
612
584
|
// Update the local trees to include the new l1 to l2 messages
|
|
613
|
-
await db
|
|
585
|
+
await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
|
|
614
586
|
|
|
615
587
|
const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
616
588
|
const newL1ToL2MessageSubtreeRootSiblingPath = assertLength(
|
|
@@ -666,12 +638,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
666
638
|
// Executes the next level of merge if all inputs are available
|
|
667
639
|
private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
668
640
|
if (!provingState.verifyState()) {
|
|
669
|
-
logger.debug('Not running base rollup, state invalid');
|
|
641
|
+
this.logger.debug('Not running base rollup, state invalid');
|
|
670
642
|
return;
|
|
671
643
|
}
|
|
672
644
|
|
|
673
645
|
if (!provingState.tryStartProvingBase(txIndex)) {
|
|
674
|
-
logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
646
|
+
this.logger.debug(`Base rollup for tx ${txIndex} already started.`);
|
|
675
647
|
return;
|
|
676
648
|
}
|
|
677
649
|
|
|
@@ -679,7 +651,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
679
651
|
const { processedTx } = txProvingState;
|
|
680
652
|
const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
|
|
681
653
|
|
|
682
|
-
logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
654
|
+
this.logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
|
|
683
655
|
|
|
684
656
|
this.deferredProving(
|
|
685
657
|
provingState,
|
|
@@ -703,7 +675,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
703
675
|
},
|
|
704
676
|
),
|
|
705
677
|
result => {
|
|
706
|
-
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
678
|
+
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
707
679
|
validatePartialState(result.inputs.endTreeSnapshots, txProvingState.treeSnapshots);
|
|
708
680
|
const leafLocation = provingState.setBaseRollupProof(txIndex, result);
|
|
709
681
|
if (provingState.totalNumTxs === 1) {
|
|
@@ -717,34 +689,33 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
717
689
|
|
|
718
690
|
// Enqueues the public chonk verifier circuit for a given transaction index, or reuses the one already enqueued.
|
|
719
691
|
// Once completed, will enqueue the the public tx base rollup.
|
|
720
|
-
|
|
692
|
+
protected getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
|
|
721
693
|
if (!provingState.verifyState()) {
|
|
722
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
694
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
723
695
|
return;
|
|
724
696
|
}
|
|
725
697
|
|
|
726
698
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
727
699
|
const txHash = txProvingState.processedTx.hash.toString();
|
|
728
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH;
|
|
729
700
|
const handleResult = (
|
|
730
701
|
result: PublicInputsAndRecursiveProof<
|
|
731
702
|
PublicChonkVerifierPublicInputs,
|
|
732
703
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
733
704
|
>,
|
|
734
705
|
) => {
|
|
735
|
-
logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
706
|
+
this.logger.debug(`Got chonk verifier proof for tx index: ${txIndex}`, { txHash });
|
|
736
707
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
737
708
|
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
738
709
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
739
710
|
};
|
|
740
711
|
|
|
741
712
|
if (this.provingState?.cachedChonkVerifierProofs.has(txHash)) {
|
|
742
|
-
logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
713
|
+
this.logger.debug(`Chonk verifier proof already enqueued for tx index: ${txIndex}`, { txHash });
|
|
743
714
|
void this.provingState!.cachedChonkVerifierProofs.get(txHash)!.then(handleResult);
|
|
744
715
|
return;
|
|
745
716
|
}
|
|
746
717
|
|
|
747
|
-
logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
718
|
+
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
748
719
|
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
749
720
|
}
|
|
750
721
|
|
|
@@ -760,7 +731,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
760
731
|
provingState: EpochProvingState | BlockProvingState = this.provingState!,
|
|
761
732
|
) {
|
|
762
733
|
if (!provingState.verifyState()) {
|
|
763
|
-
logger.debug('Not running chonk verifier circuit, state invalid');
|
|
734
|
+
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
764
735
|
return;
|
|
765
736
|
}
|
|
766
737
|
|
|
@@ -783,12 +754,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
783
754
|
// Enqueues the next level of merge if all inputs are available
|
|
784
755
|
private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
|
|
785
756
|
if (!provingState.verifyState()) {
|
|
786
|
-
logger.debug('Not running merge rollup. State no longer valid.');
|
|
757
|
+
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
787
758
|
return;
|
|
788
759
|
}
|
|
789
760
|
|
|
790
761
|
if (!provingState.tryStartProvingMerge(location)) {
|
|
791
|
-
logger.debug('Merge rollup already started.');
|
|
762
|
+
this.logger.debug('Merge rollup already started.');
|
|
792
763
|
return;
|
|
793
764
|
}
|
|
794
765
|
|
|
@@ -814,18 +785,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
814
785
|
// Executes the block root rollup circuit
|
|
815
786
|
private enqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
816
787
|
if (!provingState.verifyState()) {
|
|
817
|
-
logger.debug('Not running block root rollup, state no longer valid');
|
|
788
|
+
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
818
789
|
return;
|
|
819
790
|
}
|
|
820
791
|
|
|
821
792
|
if (!provingState.tryStartProvingBlockRoot()) {
|
|
822
|
-
logger.debug('Block root rollup already started.');
|
|
793
|
+
this.logger.debug('Block root rollup already started.');
|
|
823
794
|
return;
|
|
824
795
|
}
|
|
825
796
|
|
|
826
797
|
const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs();
|
|
827
798
|
|
|
828
|
-
logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
799
|
+
this.logger.debug(`Enqueuing ${rollupType} for block ${provingState.blockNumber}.`);
|
|
829
800
|
|
|
830
801
|
this.deferredProving(
|
|
831
802
|
provingState,
|
|
@@ -850,18 +821,23 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
850
821
|
},
|
|
851
822
|
),
|
|
852
823
|
async result => {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
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
|
+
});
|
|
857
829
|
|
|
858
830
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
859
831
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
860
832
|
|
|
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.
|
|
835
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
836
|
+
|
|
861
837
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
862
|
-
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
838
|
+
await this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
863
839
|
} else {
|
|
864
|
-
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
840
|
+
await this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
865
841
|
}
|
|
866
842
|
},
|
|
867
843
|
);
|
|
@@ -875,12 +851,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
875
851
|
baseParityIndex: number,
|
|
876
852
|
) {
|
|
877
853
|
if (!provingState.verifyState()) {
|
|
878
|
-
logger.debug('Not running base parity. State no longer valid.');
|
|
854
|
+
this.logger.debug('Not running base parity. State no longer valid.');
|
|
879
855
|
return;
|
|
880
856
|
}
|
|
881
857
|
|
|
882
858
|
if (!provingState.tryStartProvingBaseParity(baseParityIndex)) {
|
|
883
|
-
logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
859
|
+
this.logger.warn(`Base parity ${baseParityIndex} already started.`);
|
|
884
860
|
return;
|
|
885
861
|
}
|
|
886
862
|
|
|
@@ -915,12 +891,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
915
891
|
// Enqueues the root rollup proof if all inputs are available
|
|
916
892
|
private enqueueRootParityCircuit(provingState: BlockProvingState) {
|
|
917
893
|
if (!provingState.verifyState()) {
|
|
918
|
-
logger.debug('Not running root parity. State no longer valid.');
|
|
894
|
+
this.logger.debug('Not running root parity. State no longer valid.');
|
|
919
895
|
return;
|
|
920
896
|
}
|
|
921
897
|
|
|
922
898
|
if (!provingState.tryStartProvingRootParity()) {
|
|
923
|
-
logger.debug('Root parity already started.');
|
|
899
|
+
this.logger.debug('Root parity already started.');
|
|
924
900
|
return;
|
|
925
901
|
}
|
|
926
902
|
|
|
@@ -947,12 +923,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
947
923
|
// Enqueues the next level of merge if all inputs are available
|
|
948
924
|
private enqueueBlockMergeRollup(provingState: CheckpointProvingState, location: TreeNodeLocation) {
|
|
949
925
|
if (!provingState.verifyState()) {
|
|
950
|
-
logger.debug('Not running block merge rollup. State no longer valid.');
|
|
926
|
+
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
951
927
|
return;
|
|
952
928
|
}
|
|
953
929
|
|
|
954
930
|
if (!provingState.tryStartProvingBlockMerge(location)) {
|
|
955
|
-
logger.debug('Block merge rollup already started.');
|
|
931
|
+
this.logger.debug('Block merge rollup already started.');
|
|
956
932
|
return;
|
|
957
933
|
}
|
|
958
934
|
|
|
@@ -967,29 +943,34 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
967
943
|
},
|
|
968
944
|
signal => this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
969
945
|
),
|
|
970
|
-
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
|
+
});
|
|
971
952
|
provingState.setBlockMergeRollupProof(location, result);
|
|
972
|
-
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
953
|
+
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
973
954
|
},
|
|
974
955
|
);
|
|
975
956
|
}
|
|
976
957
|
|
|
977
|
-
private enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
958
|
+
private async enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
978
959
|
if (!provingState.verifyState()) {
|
|
979
|
-
logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
960
|
+
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
980
961
|
return;
|
|
981
962
|
}
|
|
982
963
|
|
|
983
964
|
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
984
|
-
logger.debug('Checkpoint root rollup already started.');
|
|
965
|
+
this.logger.debug('Checkpoint root rollup already started.');
|
|
985
966
|
return;
|
|
986
967
|
}
|
|
987
968
|
|
|
988
969
|
const rollupType = provingState.getCheckpointRootRollupType();
|
|
989
970
|
|
|
990
|
-
logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
971
|
+
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
991
972
|
|
|
992
|
-
const inputs = provingState.getCheckpointRootRollupInputs();
|
|
973
|
+
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
993
974
|
|
|
994
975
|
this.deferredProving(
|
|
995
976
|
provingState,
|
|
@@ -1011,7 +992,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1011
992
|
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator()!.toBlobAccumulator();
|
|
1012
993
|
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1013
994
|
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1014
|
-
logger.error(
|
|
995
|
+
this.logger.error(
|
|
1015
996
|
`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(
|
|
1016
997
|
computedEndBlobAccumulatorState,
|
|
1017
998
|
)}`,
|
|
@@ -1020,7 +1001,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1020
1001
|
return;
|
|
1021
1002
|
}
|
|
1022
1003
|
|
|
1023
|
-
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
|
+
});
|
|
1024
1008
|
|
|
1025
1009
|
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1026
1010
|
const epochProvingState = provingState.parentEpoch;
|
|
@@ -1034,99 +1018,6 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1034
1018
|
);
|
|
1035
1019
|
}
|
|
1036
1020
|
|
|
1037
|
-
private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
|
|
1038
|
-
if (!provingState.verifyState()) {
|
|
1039
|
-
logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1040
|
-
return;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1044
|
-
logger.debug('Checkpoint merge rollup already started.');
|
|
1045
|
-
return;
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
const inputs = provingState.getCheckpointMergeRollupInputs(location);
|
|
1049
|
-
|
|
1050
|
-
this.deferredProving(
|
|
1051
|
-
provingState,
|
|
1052
|
-
wrapCallbackInSpan(
|
|
1053
|
-
this.tracer,
|
|
1054
|
-
'ProvingOrchestrator.prover.getCheckpointMergeRollupProof',
|
|
1055
|
-
{
|
|
1056
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge' satisfies CircuitName,
|
|
1057
|
-
},
|
|
1058
|
-
signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1059
|
-
),
|
|
1060
|
-
result => {
|
|
1061
|
-
logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1062
|
-
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1063
|
-
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1064
|
-
},
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
private enqueueEpochPadding(provingState: EpochProvingState) {
|
|
1069
|
-
if (!provingState.verifyState()) {
|
|
1070
|
-
logger.debug('Not running epoch padding. State no longer valid.');
|
|
1071
|
-
return;
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1075
|
-
logger.debug('Padding checkpoint already started.');
|
|
1076
|
-
return;
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1080
|
-
|
|
1081
|
-
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1082
|
-
|
|
1083
|
-
this.deferredProving(
|
|
1084
|
-
provingState,
|
|
1085
|
-
wrapCallbackInSpan(
|
|
1086
|
-
this.tracer,
|
|
1087
|
-
'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof',
|
|
1088
|
-
{
|
|
1089
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding' satisfies CircuitName,
|
|
1090
|
-
},
|
|
1091
|
-
signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
|
|
1092
|
-
),
|
|
1093
|
-
result => {
|
|
1094
|
-
logger.debug('Completed proof for padding checkpoint.');
|
|
1095
|
-
provingState.setCheckpointPaddingProof(result);
|
|
1096
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1097
|
-
},
|
|
1098
|
-
);
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
// Executes the root rollup circuit
|
|
1102
|
-
private enqueueRootRollup(provingState: EpochProvingState) {
|
|
1103
|
-
if (!provingState.verifyState()) {
|
|
1104
|
-
logger.debug('Not running root rollup, state no longer valid');
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
logger.debug(`Preparing root rollup`);
|
|
1109
|
-
|
|
1110
|
-
const inputs = provingState.getRootRollupInputs();
|
|
1111
|
-
|
|
1112
|
-
this.deferredProving(
|
|
1113
|
-
provingState,
|
|
1114
|
-
wrapCallbackInSpan(
|
|
1115
|
-
this.tracer,
|
|
1116
|
-
'ProvingOrchestrator.prover.getRootRollupProof',
|
|
1117
|
-
{
|
|
1118
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root' satisfies CircuitName,
|
|
1119
|
-
},
|
|
1120
|
-
signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
|
|
1121
|
-
),
|
|
1122
|
-
result => {
|
|
1123
|
-
logger.verbose(`Orchestrator completed root rollup for epoch ${provingState.epochNumber}`);
|
|
1124
|
-
provingState.setRootRollupProof(result);
|
|
1125
|
-
provingState.resolve({ status: 'success' });
|
|
1126
|
-
},
|
|
1127
|
-
);
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
1021
|
private checkAndEnqueueNextMergeRollup(provingState: BlockProvingState, currentLocation: TreeNodeLocation) {
|
|
1131
1022
|
if (!provingState.isReadyForMergeRollup(currentLocation)) {
|
|
1132
1023
|
return;
|
|
@@ -1142,54 +1033,35 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1142
1033
|
|
|
1143
1034
|
private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
1144
1035
|
if (!provingState.isReadyForBlockRootRollup()) {
|
|
1145
|
-
logger.debug('Not ready for block root rollup');
|
|
1036
|
+
this.logger.debug('Not ready for block root rollup');
|
|
1146
1037
|
return;
|
|
1147
1038
|
}
|
|
1148
1039
|
|
|
1149
1040
|
this.enqueueBlockRootRollup(provingState);
|
|
1150
1041
|
}
|
|
1151
1042
|
|
|
1152
|
-
private checkAndEnqueueNextBlockMergeRollup(
|
|
1043
|
+
private async checkAndEnqueueNextBlockMergeRollup(
|
|
1044
|
+
provingState: CheckpointProvingState,
|
|
1045
|
+
currentLocation: TreeNodeLocation,
|
|
1046
|
+
) {
|
|
1153
1047
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
1154
1048
|
return;
|
|
1155
1049
|
}
|
|
1156
1050
|
|
|
1157
1051
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1158
1052
|
if (parentLocation.level === 0) {
|
|
1159
|
-
this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1053
|
+
await this.checkAndEnqueueCheckpointRootRollup(provingState);
|
|
1160
1054
|
} else {
|
|
1161
1055
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1162
1056
|
}
|
|
1163
1057
|
}
|
|
1164
1058
|
|
|
1165
|
-
|
|
1059
|
+
protected async checkAndEnqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1166
1060
|
if (!provingState.isReadyForCheckpointRoot()) {
|
|
1167
1061
|
return;
|
|
1168
1062
|
}
|
|
1169
1063
|
|
|
1170
|
-
this.enqueueCheckpointRootRollup(provingState);
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
private checkAndEnqueueNextCheckpointMergeRollup(provingState: EpochProvingState, currentLocation: TreeNodeLocation) {
|
|
1174
|
-
if (!provingState.isReadyForCheckpointMerge(currentLocation)) {
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1179
|
-
if (parentLocation.level === 0) {
|
|
1180
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1181
|
-
} else {
|
|
1182
|
-
this.enqueueCheckpointMergeRollup(provingState, parentLocation);
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
|
|
1187
|
-
if (!provingState.isReadyForRootRollup()) {
|
|
1188
|
-
logger.debug('Not ready for root rollup');
|
|
1189
|
-
return;
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
this.enqueueRootRollup(provingState);
|
|
1064
|
+
await this.enqueueCheckpointRootRollup(provingState);
|
|
1193
1065
|
}
|
|
1194
1066
|
|
|
1195
1067
|
/**
|
|
@@ -1200,7 +1072,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1200
1072
|
*/
|
|
1201
1073
|
private enqueueVM(provingState: BlockProvingState, txIndex: number) {
|
|
1202
1074
|
if (!provingState.verifyState()) {
|
|
1203
|
-
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1075
|
+
this.logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1204
1076
|
return;
|
|
1205
1077
|
}
|
|
1206
1078
|
|
|
@@ -1218,21 +1090,21 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1218
1090
|
},
|
|
1219
1091
|
);
|
|
1220
1092
|
|
|
1221
|
-
this.deferredProving(provingState, doAvmProving,
|
|
1222
|
-
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1223
|
-
txProvingState.setAvmProof(
|
|
1093
|
+
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1094
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1095
|
+
txProvingState.setAvmProof(proof);
|
|
1224
1096
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1225
1097
|
});
|
|
1226
1098
|
}
|
|
1227
1099
|
|
|
1228
|
-
|
|
1100
|
+
protected checkAndEnqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
1229
1101
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1230
1102
|
if (!txProvingState.ready()) {
|
|
1231
1103
|
return;
|
|
1232
1104
|
}
|
|
1233
1105
|
|
|
1234
1106
|
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
1235
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1107
|
+
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1236
1108
|
|
|
1237
1109
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1238
1110
|
}
|